-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOJO-1199 - Build number plugin to support GIT SCM
The build number plugin assumes that SVN is being used. It would be nice to support GIT as this creates SHA1 revision numbers. Attached is a patch to do this - the pom.xml will need to be adjusted to use the GIT SCM revision from maven when it is released.
- Loading branch information
Showing
4 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/org/codehaus/mojo/build/GitRevParseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.codehaus.mojo.build; | ||
|
||
import org.apache.maven.scm.CommandParameters; | ||
import org.apache.maven.scm.ScmException; | ||
import org.apache.maven.scm.ScmFileSet; | ||
import org.apache.maven.scm.ScmResult; | ||
import org.apache.maven.scm.command.AbstractCommand; | ||
import org.apache.maven.scm.provider.ScmProviderRepository; | ||
import org.apache.maven.scm.provider.git.command.GitCommand; | ||
import org.apache.maven.scm.provider.git.command.info.GitInfoScmResult; | ||
import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils; | ||
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; | ||
import org.codehaus.plexus.util.cli.CommandLineUtils; | ||
import org.codehaus.plexus.util.cli.Commandline; | ||
|
||
public class GitRevParseCommand extends AbstractCommand implements GitCommand | ||
{ | ||
|
||
String rev; | ||
|
||
|
||
|
||
protected ScmResult executeCommand(ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet, | ||
CommandParameters commandParameters) throws ScmException | ||
{ | ||
return executeRevParseCommand(scmProviderRepository, scmFileSet, commandParameters); | ||
} | ||
|
||
protected GitInfoScmResult executeRevParseCommand(ScmProviderRepository repo, ScmFileSet fileSet, | ||
CommandParameters commandParameters) | ||
throws ScmException | ||
{ | ||
|
||
Commandline cl = createCommandLine((GitScmProviderRepository) repo, fileSet); | ||
|
||
cl.createArg().setValue(getRev()); | ||
|
||
GitRevParseConsumer stdin = new GitRevParseConsumer(getLogger()); | ||
|
||
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); | ||
|
||
int exitCode; | ||
|
||
exitCode = GitCommandLineUtils.execute(cl, stdin, stderr, getLogger()); | ||
if (exitCode != 0) | ||
{ | ||
// git-status returns non-zero if nothing to do | ||
getLogger().info("Not a git revision"); | ||
return null; | ||
} | ||
|
||
return new GitInfoScmResult(cl.toString(), null, stdin.getCommandOutput(), true); | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// | ||
// ---------------------------------------------------------------------- | ||
|
||
public static Commandline createCommandLine(GitScmProviderRepository repository, ScmFileSet fileSet) | ||
{ | ||
Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "rev-parse"); | ||
|
||
return cl; | ||
} | ||
|
||
public String getRev() | ||
{ | ||
return rev; | ||
} | ||
|
||
public void setRev(String rev) | ||
{ | ||
this.rev = rev; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/codehaus/mojo/build/GitRevParseConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.codehaus.mojo.build; | ||
|
||
import org.apache.maven.scm.log.ScmLogger; | ||
import org.codehaus.plexus.util.cli.StreamConsumer; | ||
|
||
public class GitRevParseConsumer | ||
implements StreamConsumer | ||
{ | ||
private ScmLogger logger; | ||
|
||
// private Map properties = new HashMap(); | ||
|
||
private StringBuffer commandOutput = new StringBuffer(); | ||
|
||
// ---------------------------------------------------------------------- | ||
// | ||
// ---------------------------------------------------------------------- | ||
|
||
public GitRevParseConsumer(ScmLogger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// StreamConsumer Implementation | ||
// ---------------------------------------------------------------------- | ||
|
||
public void consumeLine(String line) { | ||
commandOutput.append(line); | ||
} | ||
|
||
/** | ||
* The raw output from the command. | ||
* | ||
* @return the raw output from the command | ||
*/ | ||
public String getCommandOutput() { | ||
return commandOutput.toString(); | ||
} | ||
|
||
|
||
} |