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

[SCM-977] Support for retrieving tags from the changelog #135

Merged
merged 2 commits into from
May 26, 2022
Merged
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
67 changes: 67 additions & 0 deletions maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public class ChangeSet
*/
private List<ChangeFile> files;

/**
* List of tags
*/
private List<String> tags;

/**
* The SCM revision id for this changeset.
* @since 1.3
Expand Down Expand Up @@ -414,6 +419,53 @@ public String getTimeFormatted()
return TIME_FORMAT.format( getDate() );
}

/**
* Getter for property tags.
*
* @return Value of property author.
*/
public List<String> getTags()
{
if ( tags == null )
{
return new ArrayList<>();
}
return tags;
}

/**
* Setter for property tags.
*
* @param tags New value of property tags. This replaces the existing list (if any).
*/
public void setTags( List<String> tags )
{
this.tags = tags;
}

/**
* Setter for property tags.
*
* @param tag New tag to add to the list of tags.
*/
public void addTag( String tag )
{
if ( tag == null )
{
return;
}
tag = tag.trim();
if ( tag.isEmpty() )
{
return;
}
if ( tags == null )
{
tags = new ArrayList<>();
}
tags.add( tag );
}

/**
* @return TODO
* @since 1.3
Expand Down Expand Up @@ -466,6 +518,11 @@ public String toString()
{
StringBuilder result = new StringBuilder( author == null ? " null " : author );
result.append( "\n" ).append( date == null ? "null " : date.toString() ).append( "\n" );
List<String> tags = getTags();
if ( !tags.isEmpty() )
{
result.append( "tags:" ).append( tags ).append( "\n" );
}
// parent(s)
if ( parentRevision != null )
{
Expand Down Expand Up @@ -552,6 +609,16 @@ public String toXML()
buffer.append( "\t\t<msg><![CDATA[" )
.append( removeCDataEnd( comment ) )
.append( "]]></msg>\n" );
List<String> tags = getTags();
if ( !tags.isEmpty() )
{
buffer.append( "\t\t<tags>\n" );
for ( String tag: tags )
{
buffer.append( "\t\t\t<tag>" ).append( escapeValue( tag ) ).append( "</tag>\n" );
}
buffer.append( "\t\t</tags>\n" );
}
buffer.append( "\t</changelog-entry>\n" );

return buffer.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

Expand Down Expand Up @@ -59,6 +60,7 @@ private static ChangeSet createInstance()
instance.setAuthor( "dion" );
instance.setComment( "comment" );
instance.setDate( "2002/04/01 00:00:00" );
instance.setTags( Arrays.asList( "v3.14", "v2<bla>.7]]1828", "<![CDATA[NastyTag" ) );
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ protected void setUp()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, "setUp" );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public void testSkipCheckoutWithConnectionUrl()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

CheckoutMojo mojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
mojo.setWorkingDirectory( new File( getBasedir() ) );
Expand Down Expand Up @@ -119,6 +125,12 @@ public void testSkipCheckoutWithoutConnectionUrl()
public void testUseExport()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

FileUtils.forceDelete( checkoutDir );

checkoutDir.mkdirs();
Expand All @@ -137,12 +149,24 @@ public void testUseExport()
public void testExcludeInclude()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

FileUtils.forceDelete( checkoutDir );

checkoutDir.mkdirs();

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

CheckoutMojo mojo = (CheckoutMojo) lookupMojo(
"checkout",
getTestFile( "src/test/resources/mojos/checkout/checkoutWithExcludesIncludes.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* copyright ownership. The ASF licenses this file to you 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
Expand All @@ -18,6 +18,7 @@
import java.io.File;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;

Expand Down Expand Up @@ -46,8 +47,20 @@ protected void setUp()
public void testExport()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

ExportMojo mojo = (ExportMojo) lookupMojo( "export", getTestFile( "src/test/resources/mojos/export/export.xml" ) );

mojo.setExportDirectory( exportDir.getAbsoluteFile() );
Expand Down Expand Up @@ -77,10 +90,22 @@ public void testSkipExportIfExists()
public void testExcludeInclude()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, getName() );
return;
}

SvnScmTestUtils.initializeRepository( repository );

exportDir.mkdirs();

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

ExportMojo mojo = (ExportMojo) lookupMojo(
"export",
getTestFile( "src/test/resources/mojos/export/exportWithExcludesIncludes.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Assume;
Expand Down Expand Up @@ -51,10 +52,20 @@ protected void setUp()

FileUtils.forceDelete( repository );

Assume.assumeTrue( ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) );
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp" );
return;
}

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, "setUp" );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
Expand All @@ -77,6 +88,11 @@ private static void setupConnectionUrl( AbstractScmMojo mojo )
public void testTag()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

TagMojo mojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tag.xml" ) );
mojo.setWorkingDirectory( checkoutDir );
Expand Down Expand Up @@ -106,6 +122,11 @@ public void testTag()
public void testTagWithTimestamp()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

TagMojo mojo =
(TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tagWithTimestamp.xml" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.scm.ScmTestCase;
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
Expand All @@ -43,6 +44,11 @@ protected void setUp()

repository = getTestFile( "target/repository" );

if ( !ScmTestCase.isSystemCmd( GitScmTestUtils.GIT_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( GitScmTestUtils.GIT_COMMAND_LINE, "setUp" );
return;
}

GitScmTestUtils.initRepo( "src/test/resources/git", repository, checkoutDir );

Expand All @@ -66,6 +72,12 @@ protected void setUp()
public void testUntag()
throws Exception
{
if ( !ScmTestCase.isSystemCmd( GitScmTestUtils.GIT_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( GitScmTestUtils.GIT_COMMAND_LINE, getName() );
return;
}

TagMojo tagMojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/untag/tag.xml" ) );
tagMojo.setWorkingDirectory( checkoutDir );
tagMojo.setConnectionUrl( getConnectionLocalAddress( tagMojo ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public void testSkipCheckoutWithConnectionUrl()

SvnScmTestUtils.initializeRepository( repository );

if ( !ScmTestCase.isSystemCmd( SvnScmTestUtils.SVN_COMMAND_LINE ) )
{
ScmTestCase.printSystemCmdUnavail( SvnScmTestUtils.SVN_COMMAND_LINE, getName() );
return;
}

CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
"src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public class HgChangeLogConsumer

private String currentRevision;

@SuppressWarnings( "unused" )
private String currentTag; // don't know what to do with this

@SuppressWarnings( "unused" )
private String currentBranch; // don't know what to do with this

Expand Down Expand Up @@ -127,7 +124,7 @@ else if ( line.startsWith( TIME_STAMP_TOKEN ) )
else if ( line.startsWith( TAG_TAG ) )
{
tmpLine = line.substring( TAG_TAG.length() ).trim();
currentTag = tmpLine;
currentChange.addTag( tmpLine );
}
else if ( line.startsWith( FILES_TOKEN ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public void initRepo()
{
HgRepoUtils.initRepo();
}

@Override
public boolean isTagAnExtraCommit()
{
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ static Commandline createCommandLine( GitScmProviderRepository repository, File

Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "whatchanged" );
cl.createArg().setValue( "--format=medium" );
cl.createArg().setValue( "--decorate=short" );
cl.createArg().setValue( "--raw" );
cl.createArg().setValue( "--no-merges" );

if ( startDate != null || endDate != null )
{
Expand Down
Loading