/
GitBranchMojo.java
43 lines (37 loc) · 1.25 KB
/
GitBranchMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* This code is free software; you can redistribute it and/or modify it under
* the terms of the new BSD License.
*
* Copyright (c) 2011, Sebastian Staudt
*/
package com.github.koraktor.mavanagaiata;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
/**
* This goal provides the currently checked out Git branch in the
* "mavanagaiata.branch" and "mvngit.branch" properties.
*
* @author Sebastian Staudt
* @goal branch
* @phase initialize
* @requiresProject
*/
public class GitBranchMojo extends AbstractGitMojo {
/**
* Information about the currently checked out Git branch is retrieved
* using a JGit Repository instance
*
* @see org.eclipse.jgit.lib.Repository#getBranch()
* @throws MojoExecutionException if retrieving information from the Git
* repository fails
*/
public void execute() throws MojoExecutionException {
this.initRepository();
try {
project.getProperties().put("mavanagaiata.branch", this.repository.getBranch());
project.getProperties().put("mvngit.branch", this.repository.getBranch());
} catch(IOException e) {
throw new MojoExecutionException("Unable to read Git branch", e);
}
}
}