Skip to content

Commit

Permalink
[MNG-8402] System properties can take precedence over builtin express…
Browse files Browse the repository at this point in the history
…ions (#1947)
  • Loading branch information
gnodet authored Dec 4, 2024
1 parent 794efae commit 73e30c5
Show file tree
Hide file tree
Showing 10 changed files with 1,054 additions and 945 deletions.
1 change: 0 additions & 1 deletion compat/maven-embedder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ under the License.
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 0 additions & 1 deletion impl/maven-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ under the License.
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
5 changes: 5 additions & 0 deletions impl/maven-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ under the License.
<artifactId>maven-resolver-transport-apache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ String doCallback(
}
}
}
// un-prefixed model reflection
String value = projectProperty(model, projectDir, expression, false);
// user properties
String value = request.getUserProperties().get(expression);
if (value == null) {
value = request.getUserProperties().get(expression);
}
// model properties
if (value == null) {
value = model.getProperties().get(expression);
Expand All @@ -198,11 +202,7 @@ String doCallback(
if (value == null) {
value = request.getSystemProperties().get("env." + expression);
}
if (value != null) {
return value;
}
// model reflection
return projectProperty(model, projectDir, expression, false);
return value;
}

String projectProperty(Model model, Path projectDir, String subExpr, boolean prefixed) {
Expand All @@ -223,7 +223,7 @@ String projectProperty(Model model, Path projectDir, String subExpr, boolean pre
} else if (prefixed && subExpr.startsWith("baseUri.")) {
try {
Object value = ReflectionValueExtractor.evaluate(
subExpr, projectDir.toAbsolutePath().toUri(), false);
subExpr, projectDir.toAbsolutePath().toUri(), true);
if (value != null) {
return value.toString();
}
Expand All @@ -234,8 +234,8 @@ String projectProperty(Model model, Path projectDir, String subExpr, boolean pre
return rootLocator.findMandatoryRoot(projectDir).toString();
} else if (prefixed && subExpr.startsWith("rootDirectory.")) {
try {
Object value = ReflectionValueExtractor.evaluate(
subExpr, projectDir.toAbsolutePath().toUri(), false);
Object value =
ReflectionValueExtractor.evaluate(subExpr, rootLocator.findMandatoryRoot(projectDir), true);
if (value != null) {
return value.toString();
}
Expand Down
Loading

0 comments on commit 73e30c5

Please sign in to comment.