Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsbasjes committed May 31, 2022
1 parent cf0cbe2 commit bafce99
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private String resolveSuggestedVersion( String baseVersion, ReleaseDescriptor re
}
catch ( ScmRepositoryException | NoSuchScmProviderException e )
{
getLogger().warn( "Next Version will NOT be based on the version control: " + e.getMessage() );
getLogger().warn( "Next Version will NOT be based on the version control: {}", e.getMessage() );
}
}
return convertToSnapshot ? policy.getDevelopmentVersion( request ).getVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<projectVersionPolicyId>CCSemVerVersionPolicy</projectVersionPolicyId>

<!-- projectVersionPolicyConfig is an XML structure: -->
<!-- projectVersionPolicyConfig for the CCSemVerVersionPolicy is an XML structure: -->
<!-- versionTag: A regex with 1 capture group that MUST extract the project.version from the SCM tag. -->
<!-- minorRules: A list regexes that will be matched against all lines in each commit message since -->
<!-- the last tag. If matched the next version is at least a MINOR update. -->
Expand All @@ -55,7 +55,7 @@
<!-- instead of only a patch increase. -->
<projectVersionPolicyConfig>
<![CDATA[
<cCSemverConfig>
<cCSemverVersionPolicyConfig>
<versionTag>^v([0-9]+(?:\.[0-9]+(?:\.[0-9]+)?)?)$</versionTag>
<majorRules>
<majorRule>^[a-zA-Z]+!(?:\([a-zA-Z0-9_-]+\))?: .*$</majorRule>
Expand All @@ -64,7 +64,7 @@
<minorRules>
<minorRule>^feat(?:\([a-zA-Z0-9_-]+\))?: .*$</minorRule>
</minorRules>
</cCSemverConfig>
</cCSemverVersionPolicyConfig>
]]>
</projectVersionPolicyConfig>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public VersionPolicyResult getReleaseVersion( VersionPolicyRequest request,
logger.debug( "VersionRules: \n{}", versionRules );
logger.debug( "Pom version : {}", versionString );

logger.debug( "Commit History : \n" + commitHistory );
logger.debug( "Commit History : \n{}", commitHistory );

Element maxElementSinceLastVersionTag = versionRules.getMaxElementSinceLastVersionTag( commitHistory );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ public CommitHistory( VersionPolicyRequest request, VersionRules versionRules )
{
ScmRepository scmRepository = request.getScmRepository();
ScmProvider scmProvider = request.getScmProvider();
String workingDirectory = request.getWorkingDirectory();

if ( scmRepository == null || scmProvider == null || workingDirectory == null )
{
// We do not have a commit history so the changes and tags will remain empty
return;
}

ChangeLogScmRequest changeLogRequest = new ChangeLogScmRequest(
scmRepository,
new ScmFileSet( new File( request.getWorkingDirectory() ) )
new ScmFileSet( new File( workingDirectory ) )
);

List<String> logLines = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* under the License.
*/

import org.apache.maven.shared.release.policy.ccsemver.config.CCSemverConfig;
import org.apache.maven.shared.release.policy.ccsemver.config.io.xpp3.CCSemverConfigXpp3Reader;
import org.apache.maven.shared.release.policy.ccsemver.config.CCSemverVersionPolicyConfig;
import org.apache.maven.shared.release.policy.ccsemver.config.io.xpp3.CCSemverVersionPolicyConfigXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.semver.Version;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,23 +52,23 @@ public VersionRules( String config )
int patternFlags = Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNIX_LINES;

// The default assumes then entire tag is what we need
String tagRegex = "^([0-9]+(?:\\.[0-9]+(?:\\.[0-9]+)?)?)$";
String tagRegex = "^(\\d+(?:\\.\\d+(?:\\.\\d+)?)?)$";

// https://www.conventionalcommits.org/en/v1.0.0/
majorUpdatePatterns.add( Pattern.compile( "^[a-zA-Z]+!(?:\\([a-zA-Z0-9_-]+\\))?: .*$", patternFlags ) );
majorUpdatePatterns.add( Pattern.compile( "^[a-zA-Z]+!(?:\\([a-zA-Z\\d_-]+\\))?: .*$", patternFlags ) );
majorUpdatePatterns.add( Pattern.compile( "^BREAKING CHANGE:.*$", patternFlags ) );
minorUpdatePatterns.add( Pattern.compile( "^feat(?:\\([a-zA-Z0-9_-]+\\))?: .*$", patternFlags ) );
minorUpdatePatterns.add( Pattern.compile( "^feat(?:\\([a-zA-Z\\d_-]+\\))?: .*$", patternFlags ) );

if ( config != null && !config.trim().isEmpty() )
{
ByteArrayInputStream inputStream = new ByteArrayInputStream( config.getBytes( UTF_8 ) );
CCSemverConfigXpp3Reader configReader = new CCSemverConfigXpp3Reader();
CCSemverVersionPolicyConfigXpp3Reader configReader = new CCSemverVersionPolicyConfigXpp3Reader();
try
{
CCSemverConfig semverConfig = configReader.read( inputStream );
CCSemverVersionPolicyConfig semverConfig = configReader.read( inputStream );

String semverConfigVersionTag = semverConfig.getVersionTag();
if ( semverConfigVersionTag != null && ! semverConfigVersionTag.trim().isEmpty() )
if ( semverConfigVersionTag != null && !semverConfigVersionTag.trim().isEmpty() )
{
tagRegex = semverConfigVersionTag;
}
Expand All @@ -89,7 +89,7 @@ public VersionRules( String config )
}
catch ( IOException | XmlPullParserException e )
{
throw new IllegalArgumentException( "Unable to load the CCSemverConfig: ", e );
throw new IllegalArgumentException( "Unable to load the CCSemverVersionPolicyConfig: ", e );
}
}
tagPattern = Pattern.compile( tagRegex, Pattern.MULTILINE );
Expand Down Expand Up @@ -119,7 +119,7 @@ public Version.Element getMaxElementSinceLastVersionTag( CommitHistory commitHis
}
if ( commitHistory.getLastVersionTag() != null )
{
LOGGER.debug( "PATCH: Tag " + commitHistory.getLastVersionTag() );
LOGGER.debug( "PATCH: Tag {}", commitHistory.getLastVersionTag() );
return Version.Element.PATCH;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<model xmlns="https://codehaus-plexus.github.io/MODELLO/1.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://codehaus-plexus.github.io/MODELLO/1.4.0 https://codehaus-plexus.github.io/modello/xsd/modello-1.4.0.xsd">
<id>ccsemver-config</id>
<name>CCSemverConfig</name>
<name>CCSemverVersionPolicyConfig</name>
<description>
The config for the CCSemverVersionPolicy.
</description>
Expand All @@ -33,7 +33,7 @@
</defaults>
<classes>
<class rootElement="true">
<name>CCSemverConfig</name>
<name>CCSemverVersionPolicyConfig</name>
<version>1.0.0+</version>
<fields>
<!-- Descriptive Information -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ private void verifyNextVersion(
) throws VersionParseException
{
VersionPolicyRequest request = new VersionPolicyRequest();
request.setScmProvider( FakeSCM.getSCMProvider( comment, tags ) );
request.setScmRepository( FakeSCM.getScmRepository() );
MockScmProvider provider = new MockScmProvider(comment, tags);
request.setScmProvider( provider );
request.setScmRepository( new MockScmRepository( provider ) );
request.setWorkingDirectory( "/tmp" );
request.setConfig( versionRulesConfig );
request.setVersion( pomVersion );
Expand Down Expand Up @@ -98,9 +99,9 @@ public void testCustomTagPattern() throws VersionParseException {
String major = "fix!(core): Breaking improvement";

String versionRulesConfig = ""
+ "<cCSemverConfig>"
+ "<cCSemverVersionPolicyConfig>"
+ "<versionTag>^v([0-9]+(?:\\.[0-9]+(?:\\.[0-9]+)?)?)$</versionTag>"
+ "</cCSemverConfig>" +
+ "</cCSemverVersionPolicyConfig>" +
"";

verifyNextVersion( versionRulesConfig, "2.2.2-SNAPSHOT", "2.2.2", normal ); // No Tag - No Comments
Expand All @@ -124,15 +125,15 @@ public void testCustomVersionRules() throws VersionParseException {
String major = "This is a Big Change commit.";

String versionRulesConfig = ""
+ "<cCSemverConfig>"
+ "<cCSemverVersionPolicyConfig>"
+ "<versionTag>^The awesome ([0-9]+(?:\\.[0-9]+(?:\\.[0-9]+)?)?) release$</versionTag>"
+ "<majorRules>"
+ "<majorRule>^.*Big Change.*$</majorRule>"
+ "</majorRules>"
+ "<minorRules>"
+ "<minorRule>^.*Nice Change.*$</minorRule>"
+ "</minorRules>"
+ "</cCSemverConfig>" +
+ "</cCSemverVersionPolicyConfig>" +
"";

verifyNextVersion( versionRulesConfig, "2.2.2-SNAPSHOT", "2.2.2", normal ); // No Tag - No Comments
Expand Down

This file was deleted.

Loading

0 comments on commit bafce99

Please sign in to comment.