ru.concerteza.util.buildnumber.JGitBuildNumberAntTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgit-buildnumber-ant-task Show documentation
Show all versions of jgit-buildnumber-ant-task Show documentation
Ant task, extracts buildnumbers from project's Git repository without Git command line tool
package ru.concerteza.util.buildnumber;
import org.apache.tools.ant.Project;
import java.io.File;
import java.io.IOException;
/**
* Ant task, extracts buildnumber fields from git repository and publishes them as ant properties
*
* @author alexey
* Date: 11/16/11
* @see BuildNumber
* @see BuildNumberExtractor
*/
public class JGitBuildNumberAntTask {
private Project project;
/**
* @param project ant project setter
*/
public void setProject(Project project) {
this.project = project;
}
/**
* Reads {@code git.repositoryDirectory} property that should contain '.git' directory
* or be a subdirectory of such directory. If property wasn't set current work directory is used instead.
* Extracted properties names:
*
* - {@code git.revision}
* - {@code git.shortRevision}
* - {@code git.branch}
* - {@code git.tag}
* - {@code git.commitsCount}
* - {@code git.buildnumber}
*
*
* @throws IOException
*/
public void execute() throws IOException {
String repoDirString = project.getProperty("git.repositoryDirectory");
File repoDir = null != repoDirString ? new File(repoDirString) : new File(".");
BuildNumber bn = BuildNumberExtractor.extract(repoDir);
project.setProperty("git.revision", bn.getRevision());
project.setProperty("git.shortRevision", bn.getShortRevision());
project.setProperty("git.branch", bn.getBranch());
project.setProperty("git.tag", bn.getTag());
project.setProperty("git.commitsCount", bn.getCommitsCountAsString());
project.setProperty("git.buildnumber", bn.defaultBuildnumber());
}
}