How do I get a Git change set ID from the Maven SCM abstraction
I have a Maven Mojo plugin that interrogates the SCM to produce a report. It collects the comment, author and date entries fine. I now need the actual commit ID. So, given the following log statement...
commit 0559a4f75eaabb978cd880ae921ea7737b974580
Author: John Smith <jsmith@example.com>
Date: Tue Jan 18 13:08:57 2011 -0500
Fixed port numbers for JMX
I want to extract 055开发者_StackOverflow9a4f75eaabb978cd880ae921ea7737b974580
There doesn't seem to be an obvious way to do this. Any help would be appreciated. Here's how I'm getting ChangeSet in the first place.
SimpleDateFormat localFormat = new SimpleDateFormat(userDateFormat);
ScmRepository repository = getScmRepository();
ScmProvider provider = getScmManager().getProviderByRepository(repository);
ChangeLogScmResult result = provider.changeLog(repository, getFileSet(), this.parseDate(localFormat, this.startDate), this.parseDate(localFormat, this.endDate), 0, (ScmBranch) getScmVersion(scmVersionType, scmVersion), dateFormat);
checkResult(result);
ChangeLogSet changeLogSet = result.getChangeLog();
ChangeSet[] changeSets = (ChangeSet[]) changeLogSet.getChangeSets().toArray(new ChangeSet[changeLogSet.getChangeSets().size()]);
GitChangeSet changeSet = (GitChangeSet)changeSets[0];
String gitID = ???????????????????????????????
Here's the API docs for the GitChangeSet http://maven.apache.org/scm/apidocs/org/apache/maven/scm/provider/git/GitChangeSet.html from which you can get most of the rest of the stuff I'm doing.
Older versions of the maven-scm providers do not have this functionality. Upgrade to the newer versions and the "getRevision()" method on ChangeSet should do you well.
精彩评论