From 2b00dce25c570ae336ed4a87a13b23b1ebb287d7 Mon Sep 17 00:00:00 2001 From: bzamfir Date: Mon, 25 Jul 2022 23:06:22 +0300 Subject: [PATCH] update-properties does not work across parent-child pom Fixes #582 o Updated PomHelper to validate version properties also across parents. --- src/it-repo/dummy-parent-issue-582-1.0.pom | 23 ++++++ .../invoker.properties | 1 + src/it/it-update-properties-issue-582/pom.xml | 20 +++++ .../verify.groovy | 3 + .../codehaus/mojo/versions/api/PomHelper.java | 78 +++++++++---------- 5 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 src/it-repo/dummy-parent-issue-582-1.0.pom create mode 100644 src/it/it-update-properties-issue-582/invoker.properties create mode 100644 src/it/it-update-properties-issue-582/pom.xml create mode 100644 src/it/it-update-properties-issue-582/verify.groovy diff --git a/src/it-repo/dummy-parent-issue-582-1.0.pom b/src/it-repo/dummy-parent-issue-582-1.0.pom new file mode 100644 index 0000000000..65fc001b6d --- /dev/null +++ b/src/it-repo/dummy-parent-issue-582-1.0.pom @@ -0,0 +1,23 @@ + + 4.0.0 + + localhost + dummy-parent-issue-582 + 1.0 + pom + + + 1.0 + + + + + localhost + dummy-api + ${api} + + + + + diff --git a/src/it/it-update-properties-issue-582/invoker.properties b/src/it/it-update-properties-issue-582/invoker.properties new file mode 100644 index 0000000000..9b9e55e13f --- /dev/null +++ b/src/it/it-update-properties-issue-582/invoker.properties @@ -0,0 +1 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:update-properties \ No newline at end of file diff --git a/src/it/it-update-properties-issue-582/pom.xml b/src/it/it-update-properties-issue-582/pom.xml new file mode 100644 index 0000000000..68203983f2 --- /dev/null +++ b/src/it/it-update-properties-issue-582/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + localhost + dummy-parent-issue-582 + 1.0 + + + localhost + it-update-properties-issue-582 + 1.0 + pom + update-properties with one property, with dependency in parent + + + 1.0 + + + diff --git a/src/it/it-update-properties-issue-582/verify.groovy b/src/it/it-update-properties-issue-582/verify.groovy new file mode 100644 index 0000000000..ab001bf4cc --- /dev/null +++ b/src/it/it-update-properties-issue-582/verify.groovy @@ -0,0 +1,3 @@ +pom = new File( basedir, "pom.xml" ).text; + +assert pom =~ /3.0<\/api>/ diff --git a/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java b/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java index ab727488a6..d50b43b19a 100644 --- a/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java +++ b/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java @@ -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(); } }