Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-latest-plugin-releases
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<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>it-use-latest-plugin-releases-001</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<description>Test use-latest-plugin-releases goal</description>

<build>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "pom.xml" );
String buf = FileUtils.fileRead( file, "UTF-8" );

// Check that dummy-maven-plugin version was updated from 1.0 to 3.0
if ( !buf.contains( "<version>3.0</version>" ) )
{
System.out.println( "Plugin version was not updated to 3.0" );
return false;
}

// Verify that maven-clean-plugin in pluginManagement was also updated
// Look for the pattern after clean-plugin definition
int cleanPluginIndex = buf.indexOf( "maven-clean-plugin" );
if ( cleanPluginIndex < 0 )
{
System.out.println( "Could not find maven-clean-plugin" );
return false;
}

// Check for version update in pluginManagement section
// The exact version may vary, but it should be higher than 2.2
String afterCleanPlugin = buf.substring( cleanPluginIndex );
if ( afterCleanPlugin.contains( "<version>2.2</version>" ) )
{
System.out.println( "maven-clean-plugin version was not updated from 2.2" );
return false;
}

System.out.println( "Plugin versions were updated successfully" );
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-latest-plugin-releases -DallowMajorUpdates=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<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>it-use-latest-plugin-releases-002</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<description>Test use-latest-plugin-releases with allowMajorUpdates=false</description>

<build>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "pom.xml" );
String buf = FileUtils.fileRead( file, "UTF-8" );

// Check that dummy-maven-plugin version was NOT updated to 3.0 (major version change)
// It should still be at 1.x
if ( buf.contains( "<version>3.0</version>" ) )
{
System.out.println( "Plugin version was incorrectly updated to 3.0 (major version change not allowed)" );
return false;
}

// The version should have been updated within major version 1.x
if ( buf.contains( "<version>1.0</version>" ) )
{
System.out.println( "Plugin version was not updated at all" );
return false;
}

// Check that we got an update to 1.x (e.g., 1.1, 1.2, etc.)
if ( !buf.contains( "<artifactId>dummy-maven-plugin</artifactId>" ) )
{
System.out.println( "Could not find dummy-maven-plugin" );
return false;
}

System.out.println( "Plugin version was correctly updated within major version constraints" );
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-latest-plugin-releases -DprocessPlugins=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<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>it-use-latest-plugin-releases-003</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<description>Test use-latest-plugin-releases with processPlugins=false</description>

<build>
<plugins>
<plugin>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "pom.xml" );
String buf = FileUtils.fileRead( file, "UTF-8" );

// Check that dummy-maven-plugin version was NOT updated (processPlugins=false)
if ( !buf.contains( "<version>1.0</version>" ) )
{
System.out.println( "dummy-maven-plugin version was incorrectly updated when processPlugins=false" );
return false;
}

// Verify that maven-clean-plugin in pluginManagement WAS updated (processPluginManagement defaults to true)
int cleanPluginIndex = buf.indexOf( "maven-clean-plugin" );
if ( cleanPluginIndex < 0 )
{
System.out.println( "Could not find maven-clean-plugin" );
return false;
}

// Check that version was updated from 2.2
String afterCleanPlugin = buf.substring( cleanPluginIndex );
if ( afterCleanPlugin.contains( "<version>2.2</version>" ) )
{
System.out.println( "maven-clean-plugin version was not updated from 2.2" );
return false;
}

System.out.println( "Plugin update correctly skipped plugins section and updated pluginManagement section" );
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package org.codehaus.mojo.versions;

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import javax.inject.Inject;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.Wagon;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.Segment;
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.utils.ArtifactFactory;
import org.eclipse.aether.RepositorySystem;

/**
* Replaces any plugin versions with the latest release versions, ignoring snapshots.
*
* @since 2.20.0
*/
@Mojo(name = "use-latest-plugin-releases", threadSafe = true)
public class UseLatestPluginReleasesMojo extends UsePluginVersionsMojoBase {

/**
* Whether to allow the major version number to be changed.
*
* @since 2.20.0
*/
@Parameter(property = "allowMajorUpdates", defaultValue = "true")
protected boolean allowMajorUpdates = true;

/**
* <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.20.0
*/
@Parameter(property = "allowMinorUpdates", defaultValue = "true")
protected boolean allowMinorUpdates = true;

/**
* <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.20.0
*/
@Parameter(property = "allowIncrementalUpdates", defaultValue = "true")
protected boolean allowIncrementalUpdates = true;

/**
* Creates a new instance.
*
* @param artifactFactory the artifact factory
* @param repositorySystem the repository system
* @param wagonMap the map of wagon implementations
* @param changeRecorders the change recorders
* @throws MojoExecutionException when things go wrong
*/
@Inject
public UseLatestPluginReleasesMojo(
ArtifactFactory artifactFactory,
RepositorySystem repositorySystem,
Map<String, Wagon> wagonMap,
Map<String, ChangeRecorder> changeRecorders)
throws MojoExecutionException {
super(artifactFactory, repositorySystem, wagonMap, changeRecorders);
}

@Override
protected boolean getAllowMajorUpdates() {
return allowMajorUpdates;
}

@Override
protected boolean getAllowMinorUpdates() {
return allowMinorUpdates;
}

@Override
protected boolean getAllowIncrementalUpdates() {
return allowIncrementalUpdates;
}

@Override
protected Optional<ArtifactVersion> selectVersionForPlugin(
Artifact artifact, String currentVersion, Optional<Segment> unchangedSegment)
throws VersionRetrievalException, InvalidSegmentException, MojoExecutionException {
ArtifactVersions versions = getHelper().lookupArtifactVersions(artifact, true);
// Get newer versions: (currentVersion, unchangedSegment, includeSnapshots, allowDowngrade)
// We don't allow snapshots (false) and don't allow downgrades (false)
ArtifactVersion[] newerVersions = versions.getNewerVersions(currentVersion, unchangedSegment, false, false);

return Arrays.stream(newerVersions).max(ArtifactVersion::compareTo);
}

@Override
protected boolean getAllowSnapshots() {
return false;
}
}
Loading
Loading