Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branch name support to info-class goal #38

Merged
merged 1 commit into from
Jul 30, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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