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

Add version prefixes option to released-version goal #159

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions src/it/released-version-version-prefix/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals = test
invoker.buildResult = success
invoker.settingsFile = src/it/released-version-existing-asset/settings-maven-central.xml
68 changes: 68 additions & 0 deletions src/it/released-version-version-prefix/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<!--
We use by intention an existing artifact here, an artifact that exists in maven central to detect it's released version
-->
<groupId>org.apache.continuum</groupId>
<artifactId>continuum</artifactId>
<version>1.0-SNAPSHOT</version>
<name>build-helper-maven-plugin-released-version-it-mojo-parent</name>

<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>released-version</id>
<goals>
<goal>released-version</goal>
</goals>
<configuration>
<versionPrefix>1.3</versionPrefix>
<propertyPrefix>myReleasedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>mk-target-dir</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}" />
</tasks>
</configuration>
</execution>

<execution>
<id>echo-released-version</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>myReleasedVersion.version=${myReleasedVersion.version}</echo>
<echo>myReleasedVersion.majorVersion=${myReleasedVersion.majorVersion}</echo>
<echo>myReleasedVersion.minorVersion=${myReleasedVersion.minorVersion}</echo>
<echo>myReleasedVersion.incrementalVersion=${myReleasedVersion.incrementalVersion}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
27 changes: 27 additions & 0 deletions src/it/released-version-version-prefix/settings-maven-central.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings>
12 changes: 12 additions & 0 deletions src/it/released-version-version-prefix/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
File file = new File( basedir, "build.log" );
assert file.exists();

String text = file.getText("utf-8");

// assert latest release of org.apache.continuum:continuum - it's in apache attic, there will be no new releases any more
assert text.contains("myReleasedVersion.version=1.3.8")
assert text.contains("myReleasedVersion.majorVersion=1")
assert text.contains("myReleasedVersion.minorVersion=3")
assert text.contains("myReleasedVersion.incrementalVersion=8")

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public class ReleasedVersionMojo
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
private List<ArtifactRepository> remoteArtifactRepositories;

/**
* Returned version must before with the version prefix. Allows searching for maximum minor version given a major
* version, or maximum increment version given a minor version.
*/
@Parameter( property = "releasedVersion.versionPrefix" )
private String versionPrefix = "";

/**
* Prefix string to use for the set of version properties.
*/
Expand Down Expand Up @@ -111,7 +118,8 @@ public void execute()
remoteArtifactRepositories );
for ( ArtifactVersion version : versions )
{
if ( !ArtifactUtils.isSnapshot( version.toString() )
if ( version.toString().startsWith(versionPrefix)
&& !ArtifactUtils.isSnapshot( version.toString() )
&& ( releasedVersion == null || version.compareTo( releasedVersion ) > 0 ) )
{
releasedVersion = version;
Expand Down