diff --git a/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java b/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java index 2a65954..2a4c0ae 100644 --- a/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java +++ b/src/main/java/org/codehaus/mojo/build/HgChangeSetMojo.java @@ -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 { @@ -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(); @@ -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()