Skip to content

Commit

Permalink
Merge pull request #38 from efalive/#2_branch_name_support_info_class
Browse files Browse the repository at this point in the history
Add branch name support to info-class goal
  • Loading branch information
koraktor committed Jul 30, 2015
2 parents c948c80 + cbfe8c8 commit 572d9b2
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.apache.commons.io.IOUtils;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.apache.maven.shared.filtering.MavenFilteringException;

import com.github.koraktor.mavanagaiata.git.GitRepositoryException;
import com.github.koraktor.mavanagaiata.git.GitTagDescription;
import org.codehaus.plexus.interpolation.InterpolatorFilterReader;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.util.FileUtils;

import com.github.koraktor.mavanagaiata.git.GitRepositoryException;
import com.github.koraktor.mavanagaiata.git.GitTagDescription;

/**
* This goal generates the source code for a Java class with Git information
* like commit ID and tag name.
Expand Down Expand Up @@ -94,6 +94,7 @@ public class GitInfoClassMojo extends AbstractGitMojo {
*
* @throws MavanagaiataMojoException if the info class cannot be generated
*/
@Override
public void run() throws MavanagaiataMojoException {
this.addProperty("info-class.className", this.className);
this.addProperty("info-class.packageName", this.packageName);
Expand Down Expand Up @@ -128,6 +129,7 @@ public void run() throws MavanagaiataMojoException {

final MapBasedValueSource valueSource = this.getValueSource();
FileUtils.FilterWrapper filterWrapper = new FileUtils.FilterWrapper() {
@Override
public Reader getReader(Reader fileReader) {
RegexBasedInterpolator regexInterpolator = new RegexBasedInterpolator();
regexInterpolator.addValueSource(valueSource);
Expand Down Expand Up @@ -177,6 +179,7 @@ protected MapBasedValueSource getValueSource()
String shaId = this.repository.getHeadCommit().getId();
String describe = description.toString();
boolean isDirty = this.repository.isDirty(this.dirtyIgnoreUntracked);
String branch = this.repository.getBranch();

if (isDirty && this.dirtyFlag != null) {
abbrevId += this.dirtyFlag;
Expand All @@ -186,6 +189,7 @@ protected MapBasedValueSource getValueSource()

SimpleDateFormat dateFormat = new SimpleDateFormat(this.dateFormat);
HashMap<String, String> values = new HashMap<String, String>();
values.put("BRANCH", branch);
values.put("CLASS_NAME", this.className);
values.put("COMMIT_ABBREV", abbrevId);
values.put("COMMIT_SHA", shaId);
Expand Down

0 comments on commit 572d9b2

Please sign in to comment.