Skip to content

Commit

Permalink
[MRELEASE-1078] Conventional Commits Version Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed May 27, 2022
1 parent a32681c commit 9c15a71
Show file tree
Hide file tree
Showing 32 changed files with 1,649 additions and 13 deletions.
4 changes: 4 additions & 0 deletions maven-release-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ public interface ReleaseDescriptor
*/
String getProjectVersionPolicyId();

/**
* Get the (optional) config for the VersionPolicy implementation used to calculate the project versions.
*
* @return String
*/
String getProjectVersionPolicyConfig();

/**
* Get the role-hint for the release Strategy implementation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/

import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.scm.provider.ScmProvider;
import org.apache.maven.scm.repository.ScmRepository;

/**
* <p>VersionPolicyRequest class.</p>
Expand All @@ -33,6 +35,12 @@ public class VersionPolicyRequest

private Metadata metaData;

private ScmRepository scmRepository;
private ScmProvider scmProvider;
private String workingDirectory;

private String config;

/**
* <p>Getter for the field <code>version</code>.</p>
*
Expand Down Expand Up @@ -76,5 +84,93 @@ public VersionPolicyRequest setMetaData( Metadata metaData )
this.metaData = metaData;
return this;
}


/**
* <p>Getter for the field <code>scmRepository</code>.</p>
*
* @return a {@link ScmRepository} object
*/
public ScmRepository getScmRepository()
{
return scmRepository;
}

/**
* <p>Setter for the field <code>scmRepository</code>.</p>
*
* @param scmRepository The {@link ScmRepository} where the history can be retrieved.
* @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object
*/
public VersionPolicyRequest setScmRepository( ScmRepository scmRepository )
{
this.scmRepository = scmRepository;
return this;
}

/**
* <p>Getter for the field <code>scmProvider</code>.</p>
*
* @return a {@link ScmProvider} object
*/
public ScmProvider getScmProvider()
{
return scmProvider;
}

/**
* <p>Setter for the field <code>scmProvider</code>.</p>
*
* @param scmProvider The {@link ScmProvider} where the history can be retrieved.
* @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object
*/
public VersionPolicyRequest setScmProvider( ScmProvider scmProvider )
{
this.scmProvider = scmProvider;
return this;
}

/**
* <p>Getter for the field <code>workingDirectory</code>.</p>
*
* @return the {@link String} that contains the workingDirectory (can be null or empty).
*/
public String getWorkingDirectory()
{
return workingDirectory;
}

/**
* <p>Setter for the field <code>workingDirectory</code>.</p>
*
* @param workingDirectory The {@link String} that contains the workingDirectory (can be null or empty).
* @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object
*/
public VersionPolicyRequest setWorkingDirectory( String workingDirectory )
{
this.workingDirectory = workingDirectory;
return this;
}

/**
* <p>Getter for the field <code>config</code>.</p>
*
* @return the {@link String} that contains the config (can be null or empty).
*/
public String getConfig()
{
return config;
}

/**
* <p>Setter for the field <code>config</code>.</p>
*
* @param config The {@link String} that contains the config (can be null or empty).
* @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object
*/
public VersionPolicyRequest setConfig( String config )
{
this.config = config;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ public VersionParseException( String message )
{
super( message );
}

/**
* <p>Constructor for VersionParseException.</p>
*
* @param message a {@link java.lang.String} object
*/
public VersionParseException( String message, Exception e )
{
super( message, e );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ public void write( BuilderReleaseDescriptor config, File file )
{
properties.setProperty( "projectVersionPolicyId", config.getProjectVersionPolicyId() );
}
if ( config.getProjectVersionPolicyConfig() != null )
{
properties.setProperty( "projectVersionPolicyConfig", config.getProjectVersionPolicyConfig() );
}
if ( config.getProjectNamingPolicyId() != null )
{
properties.setProperty( "projectNamingPolicyId", config.getProjectNamingPolicyId() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ public ReleaseDescriptorBuilder setProjectVersionPolicyId( String projectVersion
return this;
}

/**
* <p>setProjectVersionPolicyConfig.</p>
*
* @param setProjectVersionPolicyConfig a {@link java.lang.String} object
* @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object
*/
public ReleaseDescriptorBuilder setProjectVersionPolicyConfig( String setProjectVersionPolicyConfig )
{
releaseDescriptor.setProjectVersionPolicyConfig( setProjectVersionPolicyConfig );
return this;
}

/**
* <p>setPushChanges.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public static void copyPropertiesToReleaseDescriptor( Properties properties, Rel
{
builder.setProjectVersionPolicyId( properties.getProperty( "projectVersionPolicyId" ) );
}
if ( properties.containsKey( "projectVersionPolicyConfig" ) )
{
builder.setProjectVersionPolicyConfig( properties.getProperty( "projectVersionPolicyConfig" ) );
}
if ( properties.containsKey( "projectNamingPolicyId" ) )
{
builder.setProjectNamingPolicyId( properties.getProperty( "projectNamingPolicyId" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@

import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.manager.NoSuchScmProviderException;
import org.apache.maven.scm.provider.ScmProvider;
import org.apache.maven.scm.repository.ScmRepository;
import org.apache.maven.scm.repository.ScmRepositoryException;
import org.apache.maven.settings.Settings;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseResult;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.apache.maven.shared.release.policy.PolicyException;
import org.apache.maven.shared.release.policy.version.VersionPolicy;
import org.apache.maven.shared.release.policy.version.VersionPolicyRequest;
import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
import org.apache.maven.shared.release.util.ReleaseUtil;
import org.apache.maven.shared.release.versions.VersionParseException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.components.interactivity.PrompterException;
import org.codehaus.plexus.util.StringUtils;
Expand Down Expand Up @@ -69,9 +77,16 @@
* @author <a href="mailto:[email protected]">Brett Porter</a>
* @author Robert Scholte
*/
@Component( role = ReleasePhase.class, hint = "map-release-versions" )
public abstract class AbstractMapVersionsPhase
extends AbstractReleasePhase
{
/**
* Tool that gets a configured SCM repository from release configuration.
*/
@Requirement
private ScmRepositoryConfigurator scmRepositoryConfigurator;

/**
* Component used to prompt for input.
*/
Expand Down Expand Up @@ -280,14 +295,14 @@ else if ( releaseDescriptor.isBranchCreation() )
{
suggestedVersion =
resolveSuggestedVersion( baseVersion,
releaseDescriptor.getProjectVersionPolicyId() );
releaseDescriptor );
}
catch ( VersionParseException e )
{
if ( releaseDescriptor.isInteractive() )
{
suggestedVersion =
resolveSuggestedVersion( "1.0", releaseDescriptor.getProjectVersionPolicyId() );
resolveSuggestedVersion( "1.0", releaseDescriptor );
}
else
{
Expand Down Expand Up @@ -336,16 +351,39 @@ else if ( convertToSnapshot )
return nextVersion;
}

private String resolveSuggestedVersion( String baseVersion, String policyId )
private String resolveSuggestedVersion( String baseVersion, ReleaseDescriptor releaseDescriptor )
throws PolicyException, VersionParseException
{
String policyId = releaseDescriptor.getProjectVersionPolicyId();
VersionPolicy policy = versionPolicies.get( policyId );
if ( policy == null )
{
throw new PolicyException( "Policy '" + policyId + "' is unknown, available: " + versionPolicies.keySet() );
}

VersionPolicyRequest request = new VersionPolicyRequest().setVersion( baseVersion );

request.setConfig( releaseDescriptor.getProjectVersionPolicyConfig() );
request.setWorkingDirectory( releaseDescriptor.getWorkingDirectory() );

if ( scmRepositoryConfigurator != null && releaseDescriptor.getScmSourceUrl() != null )
{
try
{
ScmRepository repository = scmRepositoryConfigurator
.getConfiguredRepository( releaseDescriptor, new Settings() );

ScmProvider provider = scmRepositoryConfigurator
.getRepositoryProvider( repository );

request.setScmRepository( repository );
request.setScmProvider( provider );
}
catch ( ScmRepositoryException | NoSuchScmProviderException e )
{
getLogger().warn( "Next Version will NOT be based on the version control: " + e.getMessage() );
}
}
return convertToSnapshot ? policy.getDevelopmentVersion( request ).getVersion()
: policy.getReleaseVersion( request ).getVersion();
}
Expand Down
9 changes: 9 additions & 0 deletions maven-release-manager/src/main/mdo/release-descriptor.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,15 @@
The role-hint for the VersionPolicy implementation used to calculate the project versions.
</description>
</field>
<field>
<name>projectVersionPolicyConfig</name>
<version>3.0.0+</version>
<type>String</type>
<description>
The optional config string for the VersionPolicy implementation used to calculate the project versions.
The format of this string depends on the specific VersionPolicy that is used.
</description>
</field>
<field>
<name>projectNamingPolicyId</name>
<version>3.0.0+</version>
Expand Down
6 changes: 6 additions & 0 deletions maven-release-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.maven.release</groupId>
<artifactId>maven-release-ccsemver-policy</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Loading

0 comments on commit 9c15a71

Please sign in to comment.