Skip to content

Commit

Permalink
Renamed #execute to #initRepository in AbstractGitMojo
Browse files Browse the repository at this point in the history
This allows a bit more fine-grained access and doesn't suggest that
AbstractGitMojo itself does something when executing.

Additionally AbstractGitMojo#getHead will now initialize the repository if
not already done.
  • Loading branch information
koraktor committed May 2, 2011
1 parent d0517ed commit 3de9f98
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
Expand Up @@ -54,7 +54,7 @@ public abstract class AbstractGitMojo extends AbstractMojo {
* @throws MojoExecutionException if retrieving information from the Git
* repository fails
*/
public void execute() throws MojoExecutionException {
protected void initRepository() throws MojoExecutionException {
try {
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
this.repository = repositoryBuilder
Expand All @@ -74,7 +74,11 @@ public void execute() throws MojoExecutionException {
* @see RevCommit
* @throws IOException if the repository HEAD could not be retrieved
*/
protected RevCommit getHead() throws IOException {
protected RevCommit getHead() throws IOException, MojoExecutionException {
if(this.repository == null) {
this.initRepository();
}

RevWalk revWalk = new RevWalk(this.repository);
ObjectId head = this.repository.getRef("HEAD").getObjectId();
return revWalk.parseCommit(head);
Expand Down
Expand Up @@ -39,10 +39,7 @@ public class GitActorsMojo extends AbstractGitMojo {
* @throws MojoExecutionException if retrieving information from the Git
* repository fails
*/
@Override
public void execute() throws MojoExecutionException {
super.execute();

try {
RevCommit commit = this.getHead();
PersonIdent author = commit.getAuthorIdent();
Expand Down
Expand Up @@ -30,9 +30,8 @@ public class GitBranchMojo extends AbstractGitMojo {
* @throws MojoExecutionException if retrieving information from the Git
* repository fails
*/
@Override
public void execute() throws MojoExecutionException {
super.execute();
this.initRepository();

try {
project.getProperties().put("mavanagaiata.branch", this.repository.getBranch());
Expand Down
Expand Up @@ -35,10 +35,7 @@ public class GitCommitMojo extends AbstractGitMojo {
* @throws MojoExecutionException if retrieving information from the Git
* repository fails
*/
@Override
public void execute() throws MojoExecutionException {
super.execute();

try {
RevCommit commit = this.getHead();
String abbrevId = this.repository.getObjectDatabase().newReader()
Expand Down

0 comments on commit 3de9f98

Please sign in to comment.