Skip to content

Commit

Permalink
update-properties does not work across parent-child pom
Browse files Browse the repository at this point in the history
Fixes mojohaus#582
 o Updated PomHelper to validate version properties also across parents.
  • Loading branch information
bzamfir committed Jul 25, 2022
1 parent a5d2ca8 commit 2b00dce
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
23 changes: 23 additions & 0 deletions src/it-repo/dummy-parent-issue-582-1.0.pom
@@ -0,0 +1,23 @@
<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>localhost</groupId>
<artifactId>dummy-parent-issue-582</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<api>1.0</api>
</properties>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${api}</version>
</dependency>
</dependencies>


</project>
1 change: 1 addition & 0 deletions src/it/it-update-properties-issue-582/invoker.properties
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:update-properties
20 changes: 20 additions & 0 deletions src/it/it-update-properties-issue-582/pom.xml
@@ -0,0 +1,20 @@
<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>
<parent>
<groupId>localhost</groupId>
<artifactId>dummy-parent-issue-582</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-update-properties-issue-582</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>update-properties with one property, with dependency in parent</name>

<properties>
<api>1.0</api>
</properties>

</project>
3 changes: 3 additions & 0 deletions src/it/it-update-properties-issue-582/verify.groovy
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text;

assert pom =~ /<api>3.0<\/api>/
78 changes: 38 additions & 40 deletions src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
Expand Up @@ -915,51 +915,49 @@ public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHel

// second, we add all the properties in the pom
addProperties( helper, result, null, model.getProperties() );
if ( model.getDependencyManagement() != null )
{
addDependencyAssocations( helper, expressionEvaluator, result,
model.getDependencyManagement().getDependencies(), false );
}
addDependencyAssocations( helper, expressionEvaluator, result, model.getDependencies(), false );
if ( model.getBuild() != null )
{
if ( model.getBuild().getPluginManagement() != null )
{
addPluginAssociations( helper, expressionEvaluator, result,
model.getBuild().getPluginManagement().getPlugins() );
Model currentModel = model;
MavenProject currentPrj = project;
while (currentPrj != null) {
if (currentModel.getDependencyManagement() != null) {
addDependencyAssocations(helper, expressionEvaluator, result,
currentModel.getDependencyManagement().getDependencies(), false);
}
addPluginAssociations( helper, expressionEvaluator, result, model.getBuild().getPlugins() );
}
if ( model.getReporting() != null )
{
addReportPluginAssociations( helper, expressionEvaluator, result, model.getReporting().getPlugins() );
}

// third, we add any associations from the active profiles
for ( Profile profile : model.getProfiles() )
{
if ( !activeProfiles.contains( profile.getId() ) )
{
continue;
addDependencyAssocations(helper, expressionEvaluator, result, currentModel.getDependencies(), false);
if (currentModel.getBuild() != null) {
if (currentModel.getBuild().getPluginManagement() != null) {
addPluginAssociations(helper, expressionEvaluator, result,
currentModel.getBuild().getPluginManagement().getPlugins());
}
addPluginAssociations(helper, expressionEvaluator, result, currentModel.getBuild().getPlugins());
}
if ( profile.getDependencyManagement() != null )
{
addDependencyAssocations( helper, expressionEvaluator, result,
profile.getDependencyManagement().getDependencies(), false );
if (currentModel.getReporting() != null) {
addReportPluginAssociations(helper, expressionEvaluator, result, currentModel.getReporting().getPlugins());
}
addDependencyAssocations( helper, expressionEvaluator, result, profile.getDependencies(), false );
if ( profile.getBuild() != null )
{
if ( profile.getBuild().getPluginManagement() != null )
{
addPluginAssociations( helper, expressionEvaluator, result,
profile.getBuild().getPluginManagement().getPlugins() );

// third, we add any associations from the active profiles
for (Profile profile : currentModel.getProfiles()) {
if (!activeProfiles.contains(profile.getId())) {
continue;
}
if (profile.getDependencyManagement() != null) {
addDependencyAssocations(helper, expressionEvaluator, result,
profile.getDependencyManagement().getDependencies(), false);
}
addDependencyAssocations(helper, expressionEvaluator, result, profile.getDependencies(), false);
if (profile.getBuild() != null) {
if (profile.getBuild().getPluginManagement() != null) {
addPluginAssociations(helper, expressionEvaluator, result,
profile.getBuild().getPluginManagement().getPlugins());
}
addPluginAssociations(helper, expressionEvaluator, result, profile.getBuild().getPlugins());
}
if (profile.getReporting() != null) {
addReportPluginAssociations(helper, expressionEvaluator, result, profile.getReporting().getPlugins());
}
addPluginAssociations( helper, expressionEvaluator, result, profile.getBuild().getPlugins() );
}
if ( profile.getReporting() != null )
{
addReportPluginAssociations( helper, expressionEvaluator, result, profile.getReporting().getPlugins() );
currentPrj = currentPrj.getParent();
if (currentPrj != null) {
currentModel = currentPrj.getOriginalModel();
}
}

Expand Down

0 comments on commit 2b00dce

Please sign in to comment.