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

Resolves #793: Added includeParent to DisplayPropertyUpdates and PropertyUpdatesReport #795

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
Expand Up @@ -47,6 +47,7 @@
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;

Expand Down Expand Up @@ -206,7 +207,8 @@ protected void update( ModifiedPomXMLEventReader pom )
if ( updatePropertyVersions )
{
Map<Property, PropertyVersions> versionProperties =
this.getHelper().getVersionPropertiesMap( getProject(), null, null, null, true );
this.getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() ).build() );
List<String> diff = updatePropertyVersions( pom, versionProperties, remoteDepsMap );
propertyDiffs.addAll( diff );
}
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;
Expand Down Expand Up @@ -128,6 +129,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 @@ -150,8 +159,14 @@ public void execute()
List<String> updates = new ArrayList<>();

Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), properties, includeProperties, excludeProperties,
autoLinkItems );
this.getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withPropertyDefinitions( properties )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.withIncludeParent( includeParent )
.withAutoLinkItems( autoLinkItems )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.reporting.ReportRendererFactory;
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesModel;
import org.codehaus.mojo.versions.utils.PropertyComparator;
Expand Down Expand Up @@ -84,6 +85,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 @@ -120,8 +129,14 @@ protected void doGenerateReport( Locale locale, Sink sink )
final Map<Property, PropertyVersions> updateSet = new TreeMap<>( PropertyComparator.INSTANCE );
try
{
updateSet.putAll( getHelper().getVersionPropertiesMap( getProject(), properties, includeProperties,
excludeProperties, autoLinkItems ) );
updateSet.putAll( getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withPropertyDefinitions( properties )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.withIncludeParent( includeParent )
.withAutoLinkItems( autoLinkItems )
.build() ) );
}
catch ( MojoExecutionException e )
{
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;
Expand Down Expand Up @@ -304,7 +305,11 @@ private void resolvePropertyRanges( ModifiedPomXMLEventReader pom )
{

Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), null, includeProperties, excludeProperties, true );
this.getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
Expand Up @@ -37,6 +37,7 @@
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.PropertiesVersionsFileReader;

Expand Down Expand Up @@ -154,8 +155,12 @@ private void update( ModifiedPomXMLEventReader pom, Property[] propertiesConfig,
throws MojoExecutionException, XMLStreamException
{
Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), propertiesConfig, properties, "",
autoLinkItems );
this.getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withPropertyDefinitions( propertiesConfig )
.withIncludeProperties( properties )
.withAutoLinkItems( autoLinkItems )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property currentProperty = entry.getKey();
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

Expand Down Expand Up @@ -156,11 +157,14 @@ public UpdatePropertiesMojo( RepositorySystem repositorySystem,
protected void update( ModifiedPomXMLEventReader pom )
throws MojoExecutionException, MojoFailureException, XMLStreamException
{
Map<Property, PropertyVersions> propertyVersions = this.getHelper().getVersionPropertiesMap( getProject(),
properties,
includeProperties,
excludeProperties,
autoLinkItems );
Map<Property, PropertyVersions> propertyVersions = getHelper().getVersionPropertiesMap(
VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withPropertyDefinitions( properties )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.withAutoLinkItems( autoLinkItems )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
Expand Up @@ -39,6 +39,7 @@
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;
Expand Down Expand Up @@ -158,8 +159,13 @@ protected void update( ModifiedPomXMLEventReader pom )
Property propertyConfig = new Property( property );
propertyConfig.setVersion( newVersion );
Map<Property, PropertyVersions> propertyVersions =
this.getHelper().getVersionPropertiesMap( getProject(), new Property[] {propertyConfig}, property, "",
autoLinkItems );
this.getHelper().getVersionPropertiesMap(
VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject( getProject() )
.withPropertyDefinitions( new Property[] {propertyConfig} )
.withIncludeProperties( property )
.withAutoLinkItems( autoLinkItems )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Property property = entry.getKey();
Expand Down
Expand Up @@ -783,27 +783,22 @@ public ExpressionEvaluator getExpressionEvaluator( MavenProject project )
}

@Override
public Map<Property, PropertyVersions> getVersionPropertiesMap( MavenProject project,
Property[] propertyDefinitions,
String includeProperties, String excludeProperties,
boolean autoLinkItems )
public Map<Property, PropertyVersions> getVersionPropertiesMap( VersionPropertiesMapRequest request )
throws MojoExecutionException
{
Map<String, Property> properties = new HashMap<>();
if ( propertyDefinitions != null )
if ( request.getPropertyDefinitions() != null )
{
for ( Property propertyDefinition : propertyDefinitions )
{
properties.put( propertyDefinition.getName(), propertyDefinition );
}
Arrays.stream( request.getPropertyDefinitions() ).forEach( p -> properties.put( p.getName(), p ) );
}
Map<String, PropertyVersionsBuilder> builders = new HashMap<>();
if ( autoLinkItems )
if ( request.isAutoLinkItems() )
{
final PropertyVersionsBuilder[] propertyVersionsBuilders;
try
{
propertyVersionsBuilders = PomHelper.getPropertyVersionsBuilders( this, project );
propertyVersionsBuilders = PomHelper.getPropertyVersionsBuilders( this, request.getMavenProject(),
request.isIncludeParent() );
}
catch ( ExpressionEvaluationException | IOException e )
{
Expand All @@ -825,8 +820,12 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap( MavenProject pro
}
}

List<String> includePropertiesList = getSplitProperties( includeProperties );
List<String> excludePropertiesList = getSplitProperties( excludeProperties );
List<String> includePropertiesList = request.getIncludeProperties() != null
? Arrays.asList( request.getIncludeProperties().split( "\\s*,\\s*" ) )
: Collections.emptyList();
List<String> excludePropertiesList = request.getExcludeProperties() != null
? Arrays.asList( request.getExcludeProperties().split( "\\s*,\\s*" ) )
: Collections.emptyList();

getLog().debug( "Searching for properties associated with builders" );
Iterator<Property> i = properties.values().iterator();
Expand Down Expand Up @@ -884,7 +883,8 @@ else if ( !excludePropertiesList.isEmpty() && excludePropertiesList.contains( pr
+ builder.getVersionRange() );
property.setVersion( builder.getVersionRange() );
}
versions.setCurrentVersion( project.getProperties().getProperty( property.getName() ) );
versions.setCurrentVersion( request.getMavenProject().getProperties()
.getProperty( property.getName() ) );
propertyVersions.put( property, versions );
}
catch ( ArtifactMetadataRetrievalException e )
Expand All @@ -895,17 +895,6 @@ else if ( !excludePropertiesList.isEmpty() && excludePropertiesList.contains( pr
return propertyVersions;
}

private List<String> getSplitProperties( String commaSeparatedProperties )
{
List<String> propertiesList = Collections.emptyList();
if ( StringUtils.isNotEmpty( commaSeparatedProperties ) )
{
String[] splittedProps = StringUtils.split( commaSeparatedProperties, "," );
propertiesList = Arrays.asList( StringUtils.stripAll( splittedProps ) );
}
return propertiesList;
}

/**
* Builder class for {@linkplain DefaultVersionsHelper}
*/
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/codehaus/mojo/versions/api/PomHelper.java
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