Skip to content

Commit

Permalink
[maven] Include parent properties when doing late replacement of `arg…
Browse files Browse the repository at this point in the history
…Line`

PR#1976

GitOrigin-RevId: 7e9de711226d707cdfb912d97c7414d54c739b71
  • Loading branch information
basil authored and intellij-monorepo-bot committed Apr 4, 2022
1 parent 1112f14 commit 5dcd922
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private static UnaryOperator<String> getDynamicConfigurationProperties(Module mo
return s -> s;
}
Properties staticProperties = MavenPropertyResolver.collectPropertiesFromDOM(mavenProject, domModel);
Properties modelProperties = mavenProject.getProperties();
String jaCoCoConfigProperty = getJaCoCoArgLineProperty(mavenProject);
ParametersList vmParameters = javaParameters.getVMParametersList();
return name -> {
Expand All @@ -99,6 +100,10 @@ private static UnaryOperator<String> getDynamicConfigurationProperties(Module mo
if (staticPropertyValue != null) {
return MavenPropertyResolver.resolve(staticPropertyValue, domModel);
}
String modelPropertyValue = modelProperties.getProperty(name);
if (modelPropertyValue != null) {
return modelPropertyValue;
}
if (name.equals(jaCoCoConfigProperty)) {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,58 @@ public void ArgLineLateReplacement() {
javaParameters.getVMParametersList().getList());
}

@Test
public void ArgLineLateReplacementParentProperty() {
createProjectPom(
"<groupId>test</groupId>\n"
+ "<artifactId>project</artifactId>\n"
+ "<version>1</version>\n"
+ "<packaging>pom</packaging>\n"
+ "<properties>\n"
+ " <parentProp>parent.value</parentProp>\n"
+ "</properties>\n"
+ "<modules>\n"
+ " <module>m1</module>\n"
+ "</modules>\n");

createModulePom(
"m1",
"<groupId>test</groupId>\n"
+ "<artifactId>m1</artifactId>\n"
+ "<version>1</version>\n"
+ "<properties>\n"
+ " <moduleProp>module.value</moduleProp>\n"
+ "</properties>\n"
+ "<parent>\n"
+ " <groupId>test</groupId>\n"
+ " <artifactId>project</artifactId>\n"
+ " <version>1</version>\n"
+ "</parent>\n"
+ "<build>\n"
+ " <plugins>\n"
+ " <plugin>\n"
+ " <groupId>org.apache.maven.plugins</groupId>\n"
+ " <artifactId>maven-surefire-plugin</artifactId>\n"
+ " <version>2.16</version>\n"
+ " <configuration>\n"
+ " <argLine>@{moduleProp} @{parentProp}</argLine>\n"
+ " </configuration>\n"
+ " </plugin>\n"
+ " </plugins>\n"
+ "</build>\n");

importProject();
Module module = getModule("m1");

MavenJUnitPatcher mavenJUnitPatcher = new MavenJUnitPatcher();
JavaParameters javaParameters = new JavaParameters();
javaParameters.getVMParametersList().add("-ea");
mavenJUnitPatcher.patchJavaParameters(module, javaParameters);
assertEquals(
asList("-ea", "module.value", "parent.value"),
javaParameters.getVMParametersList().getList());
}

@Test
public void ArgLineRefersAnotherProperty() {
VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" +
Expand Down

0 comments on commit 5dcd922

Please sign in to comment.