Skip to content

Commit

Permalink
Merge pull request #47 from gnembisz/master
Browse files Browse the repository at this point in the history
HGChangeset goal
  • Loading branch information
olamy authored Nov 28, 2016
2 parents 7b2231f + 380141f commit 762b179
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 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,7 +106,7 @@ public void execute()
{
String previousChangeSet = getChangeSetProperty();
String previousChangeSetDate = getChangeSetDateProperty();
if ( previousChangeSet == null || previousChangeSetDate == null )
if ( previousChangeSet == null || previousChangeSetDate == null)
{
String changeSet = getChangeSet();
String changeSetDate = getChangeSetDate();
Expand All @@ -112,24 +122,29 @@ public void execute()
}
}

protected String getChangeSet()
throws ScmException, MojoExecutionException
protected String getHgCommandOutput(String[] command)
throws ScmException, MojoExecutionException
{
HgOutputConsumer consumer = new HgOutputConsumer( logger );
ScmResult result = HgUtils.execute( consumer, logger, scmDirectory, new String[] { "id", "-i" } );
ScmResult result = HgUtils.execute( consumer, logger, scmDirectory, command );
checkResult( result );
return consumer.getOutput();
}

protected String getChangeSet()
throws ScmException, MojoExecutionException
{
return getHgCommandOutput(useLastChangeSetInDirectory
? new String[] { "log", "-l1", "--template", "\"{node|short}\"", "." }
: new String[] { "id", "-i" });
}

protected String getChangeSetDate()
throws ScmException, MojoExecutionException
throws ScmException, MojoExecutionException
{
HgOutputConsumer consumer = new HgOutputConsumer( logger );
ScmResult result =
HgUtils.execute( consumer, logger, scmDirectory, new String[] { "log", "-r", ".", "--template",
"\"{date|isodate}\"" } );
checkResult( result );
return consumer.getOutput();
return getHgCommandOutput(useLastChangeSetInDirectory
? new String[] { "log", "-l1", "--template", "\"{date|isodate}\"", "." }
: new String[] { "log", "-r", ".", "--template", "\"{date|isodate}\"" } );
}

protected String getChangeSetDateProperty()
Expand Down

0 comments on commit 762b179

Please sign in to comment.