Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mojohaus/versions-maven-plugin in…
Browse files Browse the repository at this point in the history
…to issue-454-update-properties

� Conflicts:
�	src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
  • Loading branch information
jarmoniuk committed Oct 14, 2022
2 parents 5b15832 + c206f78 commit 58be362
Show file tree
Hide file tree
Showing 33 changed files with 614 additions and 618 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</parent>

<artifactId>versions-maven-plugin</artifactId>
<version>2.12.1-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Versions Maven Plugin</name>
Expand Down Expand Up @@ -115,7 +115,7 @@
<doxia-sitetoolsVersion>1.11.1</doxia-sitetoolsVersion>
<pluginVersion>${project.version}</pluginVersion>
<sitePluginVersion>3.7</sitePluginVersion>
<project.build.outputTimestamp>2022-09-06T06:39:51Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2022-10-10T21:19:23Z</project.build.outputTimestamp>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Optional;
import java.util.Set;

import org.apache.commons.text.CaseUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
Expand Down Expand Up @@ -70,12 +69,6 @@
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.stax2.XMLInputFactory2;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
import static org.codehaus.mojo.versions.api.Segment.MINOR;

/**
* Abstract base class for Versions Mojos.
*
Expand Down Expand Up @@ -539,41 +532,6 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
return true;
}

/**
* <p>Based on the passed flags, determines which segment (0-based), which is not to be changed.</p>
* <p>The method will return, depending on the first parameter on the list to be true:
* <ul>
* <li>{@code allowMajorUpdates}: -1</li>
* <li>{@code allowMinorUpdates}: 0</li>
* <li>{@code allowIncrementalUpdates}: 1</li>
* <li>(none): 2</li>
* </ul>
*
* This can be used when determining an upper
* bound for the "latest" version.
*
* @param allowMajorUpdates Allow major updates
* @param allowMinorUpdates Allow minor updates
* @param allowIncrementalUpdates Allow incremental updates
* @return Returns the segment (0-based) that is unchangeable. If any segment can change, returns -1.
*/
protected Optional<Segment> determineUnchangedSegment( boolean allowMajorUpdates, boolean allowMinorUpdates,
boolean allowIncrementalUpdates )
{
Optional<Segment> unchangedSegment = allowMajorUpdates ? empty()
: allowMinorUpdates ? of( MAJOR )
: allowIncrementalUpdates ? of( MINOR )
: of( INCREMENTAL );
if ( getLog().isInfoEnabled() )
{
getLog().info(
unchangedSegment.map( s ->
CaseUtils.toCamelCase( Segment.of( s.value() + 1 ).toString(), true ) )
.orElse( "All" ) + " version changes allowed" );
}
return unchangedSegment;
}

protected ArtifactVersion updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property,
PropertyVersions version, String currentVersion,
boolean allowDowngrade,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@
import org.codehaus.mojo.versions.filtering.WildcardMatcher;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.mojo.versions.utils.SegmentUtils;
import org.codehaus.plexus.util.StringUtils;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.apache.commons.lang3.StringUtils.countMatches;
import static org.codehaus.mojo.versions.api.Segment.INCREMENTAL;
import static org.codehaus.mojo.versions.api.Segment.MAJOR;
import static org.codehaus.mojo.versions.api.Segment.MINOR;

/**
* Displays all dependencies that have newer versions available.
Expand Down Expand Up @@ -220,28 +219,32 @@ public class DisplayDependencyUpdatesMojo

/**
* Whether to allow the major version number to be changed.
* You need to set {@link #allowAnyUpdates} to <code>false</code> to
* get this configuration gets control.
*
* <p><b>Note: {@code false} also implies {@linkplain #allowAnyUpdates}
* to be {@code false}</b></p>
*
* @since 2.5
*/
@Parameter( property = "allowMajorUpdates", defaultValue = "true" )
private boolean allowMajorUpdates;

/**
* Whether to allow the minor version number to be changed.
* You need to set {@link #allowMajorUpdates} to <code>false</code> to
* get this configuration gets control.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowAnyUpdates}
* and {@linkplain #allowMajorUpdates} to be {@code false}</b></p>
*
* @since 2.5
*/
@Parameter( property = "allowMinorUpdates", defaultValue = "true" )
private boolean allowMinorUpdates;

/**
* Whether to allow the incremental version number to be changed.
* You need to set {@link #allowMinorUpdates} to <code>false</code> to
* get this configuration gets control.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowAnyUpdates},
* {@linkplain #allowMajorUpdates}, and {@linkplain #allowMinorUpdates}
* to be {@code false}</b></p>
*
* @since 2.5
*/
Expand Down Expand Up @@ -691,28 +694,11 @@ private DependencyManagement getProjectDependencyManagement( MavenProject projec

private Optional<Segment> calculateUpdateScope()
{
if ( !allowIncrementalUpdates && !allowMinorUpdates && !allowMajorUpdates && !allowAnyUpdates )
{
throw new IllegalArgumentException( "One of: allowAnyUpdates, allowMajorUpdates, allowMinorUpdates, "
+ "allowIncrementalUpdates must be true" );
}

if ( allowAnyUpdates && allowMajorUpdates && allowMinorUpdates )
{
return empty();
}

if ( allowMajorUpdates && allowMinorUpdates )
{
return of( MAJOR );
}

if ( allowMinorUpdates )
{
return of( MINOR );
}

return of( INCREMENTAL );
return allowAnyUpdates
? empty()
: of( SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates, getLog() ).map( s -> Segment.of( s.value() - 1 ) )
.orElse( MAJOR ) );
}

private void logUpdates( Map<Dependency, ArtifactVersions> updates, String section )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;

/**
* Displays properties that are linked to artifact versions and have updates available.
Expand Down Expand Up @@ -107,15 +108,20 @@ public class DisplayPropertyUpdatesMojo
private boolean allowMajorUpdates;

/**
* Whether to allow the minor version number to be changed.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}</b></p>
*
* @since 2.5
*/
@Parameter( property = "allowMinorUpdates", defaultValue = "true" )
private boolean allowMinorUpdates;

/**
* Whether to allow the incremental version number to be changed.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates}
* and {@linkplain #allowMinorUpdates} {@code false}</b></p>
*
* @since 2.5
*/
Expand Down Expand Up @@ -158,7 +164,8 @@ public void execute()
}

Optional<Segment> unchangedSegment =
determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates );
SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates, getLog() );
try
{
ArtifactVersion winner = version.getNewestVersion( currentVersion, property, this.allowSnapshots,
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;

/**
* Attempts to resolve dependency version ranges to the specific version being used in the build. For example a version
Expand Down Expand Up @@ -94,15 +95,20 @@ public class ResolveRangesMojo
private boolean allowMajorUpdates;

/**
* Whether to allow the minor version number to be changed.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}</b></p>
*
* @since 2.5
*/
@Parameter( property = "allowMinorUpdates", defaultValue = "true" )
private boolean allowMinorUpdates;

/**
* Whether to allow the incremental version number to be changed.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates}
* and {@linkplain #allowMinorUpdates} {@code false}</b></p>
*
* @since 2.5
*/
Expand Down Expand Up @@ -312,8 +318,8 @@ private void resolvePropertyRanges( ModifiedPomXMLEventReader pom )

property.setVersion( currentVersion );

Optional<Segment> unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates );
Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
allowMinorUpdates, allowIncrementalUpdates, getLog() );
// TODO: Check if we could add allowDowngrade ?
try
{
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.SegmentUtils;

import static org.apache.maven.shared.utils.StringUtils.isBlank;

Expand Down Expand Up @@ -112,15 +113,20 @@ public class UpdateParentMojo extends AbstractVersionsUpdaterMojo
protected boolean allowMajorUpdates = true;

/**
* Whether to allow the minor version number to be changed.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}</b></p>
*
* @since 2.13.0
*/
@Parameter( property = "allowMinorUpdates", defaultValue = "true" )
protected boolean allowMinorUpdates = true;

/**
* Whether to allow the incremental version number to be changed.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates}
* and {@linkplain #allowMinorUpdates} {@code false}</b></p>
*
* @since 2.13.0
*/
Expand Down Expand Up @@ -227,8 +233,8 @@ protected ArtifactVersion resolveTargetVersion( String initialVersion )
}

final ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false );
Optional<Segment> unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates );
Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
allowMinorUpdates, allowIncrementalUpdates, getLog() );

// currentVersion (set to parentVersion here) is not included in the version range for searching upgrades
// unless we set allowDowngrade to true
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;

/**
* Sets properties to the latest versions of specific artifacts.
Expand Down Expand Up @@ -107,7 +108,9 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo
protected boolean allowMajorUpdates = true;

/**
* Whether to allow the minor version number to be changed.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}</b></p>
*
* @since 2.4
*/
Expand All @@ -116,7 +119,10 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo
protected boolean allowMinorUpdates = true;

/**
* Whether to allow the incremental version number to be changed.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates}
* and {@linkplain #allowMinorUpdates} {@code false}</b></p>
*
* @since 2.4
*/
Expand Down Expand Up @@ -181,8 +187,8 @@ protected void update( ModifiedPomXMLEventReader pom )

if ( canUpdateProperty )
{
Optional<Segment> unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates );
Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
allowMinorUpdates, allowIncrementalUpdates, getLog() );
try
{
ArtifactVersion targetVersion =
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.SegmentUtils;

/**
* Sets a property to the latest version in a given range of associated artifacts.
Expand Down Expand Up @@ -109,15 +110,20 @@ public class UpdatePropertyMojo
protected boolean allowMajorUpdates;

/**
* Whether to allow the minor version number to be changed.
* <p>Whether to allow the minor version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}</b></p>
*
* @since 2.4
*/
@Parameter( property = "allowMinorUpdates", defaultValue = "true" )
protected boolean allowMinorUpdates;

/**
* Whether to allow the incremental version number to be changed.
* <p>Whether to allow the incremental version number to be changed.</p>
*
* <p><b>Note: {@code false} also implies {@linkplain #allowMajorUpdates}
* and {@linkplain #allowMinorUpdates} {@code false}</b></p>
*
* @since 2.4
*/
Expand Down Expand Up @@ -166,7 +172,8 @@ protected void update( ModifiedPomXMLEventReader pom )
}

Optional<Segment> unchangedSegment =
determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates );
SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates,
allowIncrementalUpdates, getLog() );
try
{
ArtifactVersion targetVersion = updatePropertyToNewestVersion( pom, property, version, currentVersion,
Expand Down

0 comments on commit 58be362

Please sign in to comment.