Skip to content

Commit

Permalink
Resolves mojohaus#793: Added includeParent to DisplayPropertyUpdates …
Browse files Browse the repository at this point in the history
…and PropertyUpdatesReport
  • Loading branch information
andrzejj0 committed Oct 25, 2022
1 parent 1826b64 commit d57784c
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 108 deletions.

This file was deleted.

88 changes: 0 additions & 88 deletions src/it/it-property-updates-report-issue-684-001/pom.xml

This file was deleted.

6 changes: 0 additions & 6 deletions src/it/it-property-updates-report-issue-684-001/verify.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ protected void update( ModifiedPomXMLEventReader pom )
if ( updatePropertyVersions )
{
Map<Property, PropertyVersions> versionProperties =
this.getHelper().getVersionPropertiesMap( getProject(), null, null, null, true );
this.getHelper().getVersionPropertiesMap( getProject(), null, null, null,
true, true );
List<String> diff = updatePropertyVersions( pom, versionProperties, remoteDepsMap );
propertyDiffs.addAll( diff );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public class DisplayPropertyUpdatesMojo
@Parameter( property = "allowIncrementalUpdates", defaultValue = "true" )
private boolean allowIncrementalUpdates;

/**
* <p>Whether to include property updates from parent.</p>
*
* @since 2.14.0
*/
@Parameter( property = "includeParent", defaultValue = "true" )
protected boolean includeParent = true;

// -------------------------- STATIC METHODS --------------------------

// -------------------------- OTHER METHODS --------------------------
Expand All @@ -151,7 +159,7 @@ public void execute()

Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), properties, includeProperties, excludeProperties,
autoLinkItems );
includeParent, autoLinkItems );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public class PropertyUpdatesReportMojo extends AbstractVersionsReport<PropertyUp
@Parameter( property = "autoLinkItems", defaultValue = "true" )
private boolean autoLinkItems;

/**
* <p>Whether to include property updates from parent.</p>
*
* @since 2.14.0
*/
@Parameter( property = "includeParent", defaultValue = "true" )
private boolean includeParent = true;

@Inject
protected PropertyUpdatesReportMojo( I18N i18n, RepositorySystem repositorySystem,
ArtifactResolver artifactResolver,
Expand Down Expand Up @@ -121,7 +129,7 @@ protected void doGenerateReport( Locale locale, Sink sink )
try
{
updateSet.putAll( getHelper().getVersionPropertiesMap( getProject(), properties, includeProperties,
excludeProperties, autoLinkItems ) );
excludeProperties, includeParent, autoLinkItems ) );
}
catch ( MojoExecutionException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ private void resolvePropertyRanges( ModifiedPomXMLEventReader pom )
{

Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), null, includeProperties, excludeProperties, true );
this.getHelper().getVersionPropertiesMap( getProject(), null, includeProperties, excludeProperties,
true, true );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void update( ModifiedPomXMLEventReader pom, Property[] propertiesConfig,
{
Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), propertiesConfig, properties, "",
autoLinkItems );
true, autoLinkItems );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property currentProperty = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ protected void update( ModifiedPomXMLEventReader pom )
properties,
includeProperties,
excludeProperties,
true,
autoLinkItems );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected void update( ModifiedPomXMLEventReader pom )
propertyConfig.setVersion( newVersion );
Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), new Property[] {propertyConfig}, property, "",
autoLinkItems );
true, autoLinkItems );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,9 @@ public ExpressionEvaluator getExpressionEvaluator( MavenProject project )
@Override
public Map<Property, PropertyVersions> getVersionPropertiesMap( MavenProject project,
Property[] propertyDefinitions,
String includeProperties, String excludeProperties,
String includeProperties,
String excludeProperties,
boolean includeParent,
boolean autoLinkItems )
throws MojoExecutionException
{
Expand All @@ -803,7 +805,7 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap( MavenProject pro
final PropertyVersionsBuilder[] propertyVersionsBuilders;
try
{
propertyVersionsBuilders = PomHelper.getPropertyVersionsBuilders( this, project );
propertyVersionsBuilders = PomHelper.getPropertyVersionsBuilders( this, project, includeParent );
}
catch ( ExpressionEvaluationException | IOException e )
{
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import static java.util.Collections.singletonMap;
import static java.util.stream.IntStream.range;

/**
Expand Down Expand Up @@ -1018,16 +1019,20 @@ private static Map<MavenProject, Model> getRawModelWithParents( MavenProject pro
*
* @param helper Our versions helper.
* @param project The project to examine.
* @param includeParent whether parent POMs should be included
* @return An array of properties that are associated within the project.
* @throws ExpressionEvaluationException if an expression cannot be evaluated.
* @throws IOException if the project's pom file cannot be parsed.
* @since 1.0-alpha-3
*/
public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHelper helper, MavenProject project )
public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHelper helper, MavenProject project,
boolean includeParent )
throws ExpressionEvaluationException, IOException
{
ExpressionEvaluator expressionEvaluator = helper.getExpressionEvaluator( project );
Map<MavenProject, Model> reactorModels = getRawModelWithParents( project );
Map<MavenProject, Model> reactorModels = includeParent
? getRawModelWithParents( project )
: singletonMap( project, getRawModel( project ) );

Map<String, PropertyVersionsBuilder> propertiesMap = new TreeMap<>();

Expand Down Expand Up @@ -1081,7 +1086,9 @@ public static PropertyVersionsBuilder[] getPropertyVersionsBuilders( VersionsHel
reactorModels.values().forEach( model -> addProperties( helper, propertiesMap, null, model.getProperties() ) );


for ( MavenProject currentPrj = project; currentPrj != null; currentPrj = currentPrj.getParent() )
for ( MavenProject currentPrj = project; currentPrj != null; currentPrj = includeParent
? currentPrj.getParent()
: null )
{
Model model = reactorModels.get( currentPrj );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots
* @param propertyDefinitions Any extra hints about properties.
* @param includeProperties A comma separated list of properties to include.
* @param excludeProperties A comma separated list of properties to exclude.
* @param includeParent whether to include parent POMs
* @param autoLinkItems whether to automatically infer associations
* @return a map of {@link org.codehaus.mojo.versions.api.PropertyVersions} values keyed by
* {@link org.codehaus.mojo.versions.Property} instances.
* @throws MojoExecutionException if something goes wrong.
*/
Map<Property, PropertyVersions> getVersionPropertiesMap( MavenProject project, Property[] propertyDefinitions,
String includeProperties, String excludeProperties,
boolean autoLinkItems )
boolean includeParent, boolean autoLinkItems )
throws MojoExecutionException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.apache.commons.codec.CharEncoding.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.Matchers.not;

/**
* Unit tests for {@link DisplayPropertyUpdatesMojo}
Expand Down Expand Up @@ -85,4 +86,25 @@ public void testPropertiesFromParent() throws Exception
assertThat( String.join( "", Files.readAllLines( tempFile ) ),
matchesPattern( ".*\\$\\{ver} \\.* 1\\.0\\.0 -> 2\\.0\\.0.*" ) );
}

@Test
public void testDisablePropertiesFromParent() throws Exception
{
Path tempFile = Files.createTempFile( tempDir, "output", "" );

TestUtils.copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/display-property-updates/issue-367" ),
tempDir );
DisplayPropertyUpdatesMojo mojo =
(DisplayPropertyUpdatesMojo) mojoRule.lookupConfiguredMojo( tempDir.resolve( "child" ).toFile(),
"display-property-updates" );
mojo.outputEncoding = UTF_8;
mojo.outputFile = tempFile.toFile();
mojo.setPluginContext( new HashMap<>() );
mojo.artifactMetadataSource = MockUtils.mockArtifactMetadataSource();
mojo.includeParent = false;
mojo.execute();

assertThat( String.join( "", Files.readAllLines( tempFile ) ),
not( matchesPattern( ".*\\$\\{ver} \\.* 1\\.0\\.0 -> 2\\.0\\.0.*" ) ) );
}
}
Loading

0 comments on commit d57784c

Please sign in to comment.