Skip to content

Commit

Permalink
ChangeParentPom will no longer try to preserve "global" properties wh…
Browse files Browse the repository at this point in the history
…ich didn't actually come from the old parent; see https://maven.apache.org/pom.html#Properties
  • Loading branch information
nmck257 committed Jun 5, 2024
1 parent 85a4cce commit 3528009
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,18 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
resolvedPom = getResolutionResult().getPom();
}
String propertyName = m.group(1).trim();
if (resolvedPom.getProperties().containsKey(propertyName)) {
if (resolvedPom.getProperties().containsKey(propertyName) && !isGlobalProperty(propertyName)) {
properties.put(m.group(1).trim(), resolvedPom.getProperties().get(propertyName));
}
}
}
return t;
}

private boolean isGlobalProperty(String propertyName) {
return propertyName.startsWith("project.") || propertyName.startsWith("env.")
|| propertyName.startsWith("settings.") || propertyName.equals("basedir");
}
}.visit(pomXml, ctx);
return properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1468,4 +1468,61 @@ void doesNotAddGrandparentProperties() {
)
);
}

@Test
void doesNotAddGlobalProperties() {
rewriteRun(
spec -> spec.recipe(new ChangeParentPom("org.springframework.boot", null, "spring-boot-starter-parent", null, "2.7.18", null, null, null, null)),
pomXml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.17</version>
</parent>
<properties>
<my-basedir>${basedir}</my-basedir>
<my-project-basedir>${project.basedir}</my-project-basedir>
<my-project-build-directory>${project.build.directory}</my-project-build-directory>
<my-project-version>${project.version}</my-project-version>
<my-env-prop>${env.GIT_HOME}</my-env-prop>
<my-settings-prop>${settings.offline}</my-settings-prop>
</properties>
</project>
""",
"""
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
</parent>
<properties>
<my-basedir>${basedir}</my-basedir>
<my-project-basedir>${project.basedir}</my-project-basedir>
<my-project-build-directory>${project.build.directory}</my-project-build-directory>
<my-project-version>${project.version}</my-project-version>
<my-env-prop>${env.GIT_HOME}</my-env-prop>
<my-settings-prop>${settings.offline}</my-settings-prop>
</properties>
</project>
"""
)
);
}
}

0 comments on commit 3528009

Please sign in to comment.