Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #582 - update-properties does not work across parent-child pom #616

Merged
merged 1 commit into from Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>/
82 changes: 46 additions & 36 deletions src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
Expand Up @@ -875,7 +875,7 @@ public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHel
throws ExpressionEvaluationException, IOException
{
ExpressionEvaluator expressionEvaluator = helper.getExpressionEvaluator( project );
Model model = getRawModel( project );
Model projectModel = getRawModel( project );
Map<String, PropertyVersionsBuilder> result = new TreeMap<>();

Set<String> activeProfiles = new TreeSet<>();
Expand All @@ -885,7 +885,7 @@ public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHel
}

// add any properties from profiles first (as they override properties from the project
for ( Profile profile : model.getProfiles() )
for ( Profile profile : projectModel.getProfiles() )
{
if ( !activeProfiles.contains( profile.getId() ) )
{
Expand Down Expand Up @@ -914,52 +914,62 @@ public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHel
}

// second, we add all the properties in the pom
addProperties( helper, result, null, model.getProperties() );
if ( model.getDependencyManagement() != null )
addProperties( helper, result, null, projectModel.getProperties() );
Model model = projectModel;
MavenProject currentPrj = project;
while ( currentPrj != 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 )
if ( model.getDependencyManagement() != null )
{
addPluginAssociations( helper, expressionEvaluator, result,
model.getBuild().getPluginManagement().getPlugins() );
addDependencyAssocations( helper, expressionEvaluator, result,
model.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() ) )
addDependencyAssocations( helper, expressionEvaluator, result, model.getDependencies(), false );
if ( model.getBuild() != null )
{
continue;
if ( model.getBuild().getPluginManagement() != null )
{
addPluginAssociations( helper, expressionEvaluator, result,
model.getBuild().getPluginManagement().getPlugins() );
}
addPluginAssociations( helper, expressionEvaluator, result, model.getBuild().getPlugins() );
}
if ( profile.getDependencyManagement() != null )
if ( model.getReporting() != null )
{
addDependencyAssocations( helper, expressionEvaluator, result,
profile.getDependencyManagement().getDependencies(), false );
addReportPluginAssociations( helper, expressionEvaluator, result, model.getReporting().getPlugins() );
}
addDependencyAssocations( helper, expressionEvaluator, result, profile.getDependencies(), false );
if ( profile.getBuild() != null )

// third, we add any associations from the active profiles
for ( Profile profile : model.getProfiles() )
{
if ( profile.getBuild().getPluginManagement() != null )
if ( !activeProfiles.contains( profile.getId() ) )
{
addPluginAssociations( helper, expressionEvaluator, result,
profile.getBuild().getPluginManagement().getPlugins() );
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 )
currentPrj = currentPrj.getParent();
if ( currentPrj != null )
{
addReportPluginAssociations( helper, expressionEvaluator, result, profile.getReporting().getPlugins() );
model = currentPrj.getOriginalModel();
}
}

Expand Down