Skip to content

Commit

Permalink
Adding new parameter rather then producing 2 extra properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembisz committed Jul 17, 2016
1 parent d740c92 commit 380141f
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public class HgChangeSetMojo
@Parameter( property = "maven.changeSet.scmDirectory", defaultValue = "${basedir}" )
private File scmDirectory;


/**
* Forces to use last logged changeset/changesetDate from scmDirectory and not current repository
* changeset/changesetDate.
*
* @since 1.5
*/
@Parameter( property = "maven.buildNumber.useLastChangeSetInDirectory", defaultValue = "false" )
private Boolean useLastChangeSetInDirectory;

private void checkResult( ScmResult result )
throws MojoExecutionException
{
Expand Down Expand Up @@ -96,23 +106,14 @@ public void execute()
{
String previousChangeSet = getChangeSetProperty();
String previousChangeSetDate = getChangeSetDateProperty();
String previousLastChangeSetInFolder = getLastChangeSetInFolderProperty();
String previousLastChangeSetDateInFolder = getLastChangeSetDateInFolderProperty();
if ( previousChangeSet == null || previousChangeSetDate == null
|| previousLastChangeSetInFolder == null || previousLastChangeSetDateInFolder == null)
if ( previousChangeSet == null || previousChangeSetDate == null)
{
String changeSet = getChangeSet();
String changeSetDate = getChangeSetDate();
String lastChangeSetInFolder = getLastChangeSetInFolder();
String lastChangeSetDateInFolder = getLastChangeSetDateInFolder();
getLog().info( "Setting Mercurial Changeset: " + changeSet );
getLog().info( "Setting Mercurial Changeset Date: " + changeSetDate );
getLog().info( "Setting Mercurial Last Changeset in Folder: " + lastChangeSetInFolder );
getLog().info( "Setting Mercurial Last Changeset Date in Folder: " + lastChangeSetDateInFolder );
setChangeSetProperty( changeSet );
setChangeSetDateProperty( changeSetDate );
setLastChangeSetInFolderProperty( lastChangeSetInFolder );
setLastChangeSetDateInFolderProperty( lastChangeSetDateInFolder );
}
}
catch ( ScmException e )
Expand All @@ -133,29 +134,19 @@ protected String getHgCommandOutput(String[] command)
protected String getChangeSet()
throws ScmException, MojoExecutionException
{
return getHgCommandOutput(new String[] { "id", "-i" });
return getHgCommandOutput(useLastChangeSetInDirectory
? new String[] { "log", "-l1", "--template", "\"{node|short}\"", "." }
: new String[] { "id", "-i" });
}

protected String getChangeSetDate()
throws ScmException, MojoExecutionException
{
return getHgCommandOutput(new String[] { "log", "-r", ".", "--template",
"\"{date|isodate}\"" } );
}

protected String getLastChangeSetInFolder()
throws ScmException, MojoExecutionException
{
return getHgCommandOutput(new String[] { "log", "-l1", "--template", "\"{node|short}\"", "." });
}

protected String getLastChangeSetDateInFolder()
throws ScmException, MojoExecutionException
{
return getHgCommandOutput(new String[] { "log", "-l1", "--template", "\"{date|isodate}\"", "." });
return getHgCommandOutput(useLastChangeSetInDirectory
? new String[] { "log", "-l1", "--template", "\"{date|isodate}\"", "." }
: new String[] { "log", "-r", ".", "--template", "\"{date|isodate}\"" } );
}


protected String getChangeSetDateProperty()
{
return getProperty( "changeSetDate" );
Expand All @@ -166,16 +157,6 @@ protected String getChangeSetProperty()
return getProperty( "changeSet" );
}

protected String getLastChangeSetDateInFolderProperty()
{
return getProperty( "lastChangeSetDateInFolder" );
}

protected String getLastChangeSetInFolderProperty()
{
return getProperty( "lastChangeSetInFolder" );
}

protected String getProperty( String property )
{
return project.getProperties().getProperty( property );
Expand All @@ -191,16 +172,6 @@ private void setChangeSetProperty( String changeSet )
setProperty( "changeSet", changeSet );
}

private void setLastChangeSetDateInFolderProperty( String changeSetDate )
{
setProperty( "lastChangeSetDateInFolder", changeSetDate );
}

private void setLastChangeSetInFolderProperty( String changeSet )
{
setProperty( "lastChangeSetInFolder", changeSet );
}

private void setProperty( String property, String value )
{
if ( value != null )
Expand Down

0 comments on commit 380141f

Please sign in to comment.