All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.concerteza.util.buildnumber.JGitBuildNumberAntTask Maven / Gradle / Ivy

Go to download

Ant task, extracts buildnumbers from project's Git repository without Git command line tool

There is a newer version: 1.2.10
Show newest version
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()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy