Giter VIP home page Giter VIP logo

ant-git-tasks's Introduction

Ant tasks for Git using JGit

https://img.shields.io/hexpm/l/plug.svg https://travis-ci.org/rimerosolutions/ant-git-tasks.png https://img.shields.io/maven-central/v/com.rimerosolutions.ant/ant-git-tasks.svg

IMPORTANT: This project is officially retired

  • I haven’t updated this for a while and there have been couple of issues created
    • It often takes many years to get some community involvement (issues or useful pull requests)
    • The same happened many years ago with XPontus XML editor (active efforts between 2004-2008)
  • I don’t program “that much” professionally anymore
    • I haven’t used Apache Ant since 2014-2015 or so
    • For my Open Source projects, I’ve been “playing around” mostly with Rust lately

Summary

This is a set of basic Apache Ant tasks for Git to automate release processes, using the Eclipse JGit API. The goal is to leverage release management processes for Apache Ant based projects that use Git for revision control. This set of Ant tasks is currently used by the Ant Command Line Wrapper project and by the ant-git-tasks project itself!

Below is one possible workflow:

  • Create a branch for a fix, feature or major change.
  • Merge the branch after some testing.
  • Update the documentation/changelog and/or other notes.
  • Prepare a release settings with ideally semantic versioning by updating a release properties file.
  • Commit the changes after updating the application version.
  • Tag the release and push the changes to a Git repository.
  • Push the code to a repository (Maven/Ivy).

Apache Maven/Apache Ivy repository hosting is provided via Sonatype OSS repositories.

The best way to contribute is via pull requests after running tests. Please also check the Developer Notes Wiki page.

Tasks description and documentation

Apache Ant tasks documentation.

  • The available ant tasks documentation is available for online browsing via the project wiki pages.
  • You can also generate the Ant tasks documentation locally by running the javadoc target (ant javadoc). This generates both the API javadocs and the Ant tasks documentation (generated via a custom Doclet).

The docs are more up to date via build vs. looking at the wiki.

Code samples

The available Apache AntUnit tests give a good overview of the intended usage. The ant-git-tasks project is tested with Apache Ant itself, to have a feel of what’s working and how usable the tasks are.

General information

Overview

The expectation is that you create a git tasks container where you nest commands as needed. The initial step would be to setup the Git user information and credentials prior to running git commands.

<git:settings refId="gitSettingsReference"
              username="me" password="pwd"
              name="me" email="[email protected]"/>
<git:git directory="." settingsRef="gitSettingsReference">
 <git:clone uri="someuri"/>
</git:git>

User identify and credentials

The Git settings tasks allows specifying reusable credentials and identity settings. You typically first setup settings prior to running tasks unless you’re not doing any commits’. For now if you attempt a commit without settings, a null pointer exception is thrown, TBD fix it.

<git:settings refId="git.testing"
 username="xxxtesting"
 password="xxxtesting"
 name="xxxtesting"
 email="[email protected]"/>

Usage

Once the settings are initialize, you just reference them in your root git tasks container. The git user information is require to commit to a repository and sometimes to push to remote repositories.

<git:git directory="repositoryCloneFolder" verbose="true" settingsRef="git.testing">
 <git:clone uri="https://github.com/rimerosolutions/playground-repo.git"/>
 <git:checkout branchName="dummyBranch" createBranch="true"/>
</git:git>

Integration

Git namespace

You’ll need to add a reference to the git namespace to handle git related tasks.

<project name="myproject"
        xmlns:git="antlib:com.rimerosolutions.ant.git"
 // other build.xml elements
</project>

As noticed in the above lines, ant-git-tasks use Antlib to define tasks.

Inside the target(s) where you intend to call git, you’ll need to setup the classpath and initialize the custom task.

See the section below for dependency management strategies and classpath handling.

Dependency Management

You can either use Apache Ivy as dependency manager, or you can put manually files where you want.

Apache Ivy (preferred)

You’ll need the following dependencies in your ivy.xml file.

<dependency org="org.eclipse.jgit" 
            name="org.eclipse.jgit.ant" 
            rev="3.0.0.201306101825-r" conf="YOUR_IVY_CONFIGURATION"/>
<dependency org="org.eclipse.jgit" 
            name="org.eclipse.jgit" 
            rev="3.0.0.201306101825-r" conf="YOUR_IVY_CONFIGURATION"/>
<dependency org="com.jcraft" 
            name="jsch" 
            rev="0.1.50" conf="YOUR_IVY_CONFIGURATION"/>
<dependency org="com.rimerosolutions.ant" 
            name="ant-git-tasks"
            rev="0.0.1-SNAPSHOT" 
            changing="true" conf="YOUR_IVY_CONFIGURATION"/>

The versions mentionned above could be obsolete, please use the information from a site such as mvnrepository.

In your ivysettings.xml file, you need a reference to two repositories:

  • Maven Central for general dependencies
  • Sonatype snapshot repositories for ant-git-tasks
<url name="sonatype-snapshots" m2compatible="true">
 <artifact pattern="https://oss.sonatype.org/content/repositories/snapshots/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
</url>
<ibiblio name="central" m2compatible="true"/>

In your build.xml, initialize the task definition and its classpath.

<ivy:cachepath pathid="ant.git.tasks.classpath" conf="YOUR_IVY_CONFIGURATION"/>

:

<taskdef uri="antlib:com.rimerosolutions.ant.git"
         resource="com/rimerosolutions/ant/git/jgit-ant-lib.xml">
  <classpath>
    <path refid="ant.git.tasks.classpath"/>
  </classpath>
</taskdef>

Manual download (‘quicker’, but not recommended)

You can grab the files below from the Maven central and Sonatype OSS repositories:

In your build.xml, initialize the task definition and its classpath.

<taskdef uri="antlib:com.rimerosolutions.ant.git"
         resource="com/rimerosolutions/ant/git/jgit-ant-lib.xml">
 <classpath>
  <pathelement location="path/to/org.eclipse.jgit.ant-3.0.0.201306101825-r.jar"/>
  <pathelement location="path/to/org.eclipse.jgit-3.0.0.201306101825-r.jar"/>
  <pathelement location="path/to/jsch-0.1.50.jar"/>
  <pathelement location="path/to/ant-git-tasks-0.0.1.jar"/>
 </classpath>
</taskdef>

Building from source

  • You need JDK7 to build the code from source. While it may also work for JDK8, it hasn’t been tested.
  • If you don’t want to use the ant wrapper antw script at the root of this folder, you’ll need Apache Ant 1.8.0+.
  • JAVA_HOME is to be set for the custom Doclet compilation so that the tools.jar file can be found.

Building with Apache Ant 1.7.1 leads to some intermittent errors when deleting temporary test folders. It looks like some kind of race condition is happening.

To list available Apache Ant targets, please run ./antw -p for Unix/Linux or antw -p for Windows.

If you use an IDE, take a look at Apache Ivy IDE Integration section on the Apache Ivy website.

Maven integration

The pom.xml file at the root of this project is only meant to illustrate Maven integration:

  • Apache AntUnit integration tests are run as part of the test phase.
  • A simple Apache Ant Git task is executed to showcase integration.

Notes about Apache Ant versions:

  • Apache Ant 1.8.2 doesn’t seem to create any weird issues (NoSuchMethodError, ClassNotFoundException, etc.).
  • Apache Ant 1.7.x leads to unpredictable builds as well as possible incompatibilities, version conflicts.

License

Source Copyright 2013-2014 Rimero Solutions, Yves Zoundi and contributors.

Distributed under the Apache License version 2.0. See the file LICENSE at the root of the project.

ant-git-tasks's People

Contributors

fafriat avatar jkutzfla avatar mirvnillith avatar stephencdaly avatar verycrazydog avatar will-clark avatar yveszoundi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ant-git-tasks's Issues

Allow creating a branch from a custom origin.

From email:

I have a real quick question regarding how to checkout branch tags from an exisiting repository using your custom ant task.

<git:git directory="${library.directory}" verbose="true" settingsRef="git.refID">
  <git:clone uri="<url>.git"/>
  <git:checkout branchName="origin/master" createBranch="true"/>
</git:git>

From reading the wiki this seems to be correct for checking out a remote branch, but I need to be able to checkout a particular branch tag.

Answer/Possible workaround:
I think that I should expose the setStartPoint method from JGit:
http://download.eclipse.org/jgit/docs/jgit-2.3.1.201302201838-r/apidocs/org/eclipse/jgit/api/CheckoutCommand.html#setStartPoint(java.lang.String)

Alternatively, you should be might able to get away with it by doing the following:

<git:git ...>
  <git checkout yourtag/>
 <git checkout your branch create=true/>
   </git:git>

Tagger and push rejection

Tagger was not set from git:settings (same as with committer previously) and I added detection of "Push rejected." in the push messages to fail the push (it's what we see in Stash when a server-side hook fails and for some reason the returned result does not trigger a fail by itself).

Enhance the commit command for multiple specific paths

Summary
It is not possible to commit a specific set of changes among all possible git tree changes.

Details
The JGit API supports adding multiple specific paths by calling the setOnly method multiple times. http://download.eclipse.org/jgit/docs/jgit-3.2.0.201312181205-r/apidocs/org/eclipse/jgit/api/CommitCommand.html#setOnly(java.lang.String)

However, there's no fileset like support in the Ant Git tasks commit task. Fileset support should be implement in a similar way than in the AddCommand task.

Sample use case

  • For a snapshot release(no git tagging, snapshot artifacts deployment) , the tree must be clean, as your previous commits should have provided all required improvements and bug fixes.
  • For an official release(git tagging + staging artifacts deployment), you EXPECT the Git tree to be dirty with only changes related to bumping the version number. For a clean release, you only want to commit files impacted by the version number increase.

[taskdef] Could not load definitions from resource com/rimerosolutions/ant/git/jgit-ant-lib.xml. It could not be found.

I don't know if this issue tracker is still active, but I'm getting the error from the title. This is my config

<project name="Test" default="init" basedir="."
	xmlns:ivy="antlib:org.apache.ivy.ant"
	xmlns:git="antlib:com.rimerosolutions.ant.git">

	<target name="init">
		<ivy:cachepath pathid="ant.git.tasks.classpath" conf="compile"/>
		<taskdef uri="antlib:com.rimerosolutions.ant.git"
        resource="com/rimerosolutions/ant/git/jgit-ant-lib.xml">
        	<classpath>
        		<path refid="ant.git.tasks.classpath"/>
        	</classpath>
	    </taskdef>

		<!-- Install repositories -->
		<git:git directory=".">
 			<git:clone uri="someuri"/>
		</git:git>
	</target>
</project>
<ivy-module version="2.0">
	<info organisation="Test GmbH" module="Test"/>
	<configurations>
		<conf name="compile"/>		
	</configurations>
	<dependencies>
		<dependency org="org.eclipse.jgit"
			name="org.eclipse.jgit.ant" 
            rev="4.7.0.201704051617-r" conf="compile"/>
		<dependency org="org.eclipse.jgit" 
            name="org.eclipse.jgit" 
            rev="4.7.0.201704051617-r" conf="compile"/>
		<dependency org="com.jcraft" 
            name="jsch" 
            rev="0.1.54" conf="compile"/>
		<dependency org="com.rimerosolutions.ant" 
            name="ant-git-tasks"
            rev="1.3.2" 
            changing="true" conf="compile"/>
	</dependencies>
</ivy-module>
<ivysettings>
	<settings defaultResolver="central"/>
	<resolvers>
		<url name="sonatype-snapshots" m2compatible="true">
			<artifact pattern="https://oss.sonatype.org/content/repositories/snapshots/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"/>
		</url>
		<ibiblio name="central" m2compatible="true"/>
	</resolvers>
</ivysettings>

And this is the error output

Buildfile: /home/tzfrs/dev/Test/TestAnt/build.xml

init:
[ivy:cachepath] :: Apache Ivy 2.4.0 - 20141213170938 :: http://ant.apache.org/ivy/ ::
[ivy:cachepath] :: loading settings :: file = /home/tzfrs/dev/Test/TestAnt/ivysettings.xml
[ivy:cachepath] :: resolving dependencies :: Test GmbH#Test;working@tzfrs-home
[ivy:cachepath] 	confs: [compile]
[ivy:cachepath] 	found org.eclipse.jgit#org.eclipse.jgit.ant;4.7.0.201704051617-r in central
[ivy:cachepath] 	found org.eclipse.jgit#org.eclipse.jgit;4.7.0.201704051617-r in central
[ivy:cachepath] 	found com.jcraft#jsch;0.1.54 in central
[ivy:cachepath] 	found com.googlecode.javaewah#JavaEWAH;1.1.6 in central
[ivy:cachepath] 	found org.apache.httpcomponents#httpclient;4.3.6 in central
[ivy:cachepath] 	found org.apache.httpcomponents#httpcore;4.3.3 in central
[ivy:cachepath] 	found commons-logging#commons-logging;1.1.3 in central
[ivy:cachepath] 	found commons-codec#commons-codec;1.6 in central
[ivy:cachepath] 	found org.slf4j#slf4j-api;1.7.2 in central
[ivy:cachepath] 	found org.apache.ant#ant;1.9.6 in central
[ivy:cachepath] 	found org.apache.ant#ant-launcher;1.9.6 in central
[ivy:cachepath] 	found com.rimerosolutions.ant#ant-git-tasks;1.3.2 in central
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/eclipse/jgit/org.eclipse.jgit.ant/4.7.0.201704051617-r/org.eclipse.jgit.ant-4.7.0.201704051617-r.jar ...
[ivy:cachepath] ......... (18kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit.ant;4.7.0.201704051617-r!org.eclipse.jgit.ant.jar (58ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/eclipse/jgit/org.eclipse.jgit/4.7.0.201704051617-r/org.eclipse.jgit-4.7.0.201704051617-r.jar ...
[ivy:cachepath] .................................................................................................................................................................. (2397kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.eclipse.jgit#org.eclipse.jgit;4.7.0.201704051617-r!org.eclipse.jgit.jar (298ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/com/jcraft/jsch/0.1.54/jsch-0.1.54.jar ...
[ivy:cachepath] ............................. (273kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] com.jcraft#jsch;0.1.54!jsch.jar (71ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/apache/ant/ant/1.9.6/ant-1.9.6.jar ...
[ivy:cachepath] ........................................................................................................................................ (1982kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.apache.ant#ant;1.9.6!ant.jar (208ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/com/googlecode/javaewah/JavaEWAH/1.1.6/JavaEWAH-1.1.6.jar ...
[ivy:cachepath] ...................... (161kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] com.googlecode.javaewah#JavaEWAH;1.1.6!JavaEWAH.jar(bundle) (68ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar ...
[ivy:cachepath] ................................................ (578kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.apache.httpcomponents#httpclient;4.3.6!httpclient.jar (96ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar ...
[ivy:cachepath] ............... (25kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.slf4j#slf4j-api;1.7.2!slf4j-api.jar (59ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar ...
[ivy:cachepath] ............................. (276kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.apache.httpcomponents#httpcore;4.3.3!httpcore.jar (69ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar ...
[ivy:cachepath] ............... (60kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] commons-logging#commons-logging;1.1.3!commons-logging.jar (82ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/commons-codec/commons-codec/1.6/commons-codec-1.6.jar ...
[ivy:cachepath] .......................... (227kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] commons-codec#commons-codec;1.6!commons-codec.jar (80ms)
[ivy:cachepath] downloading https://repo1.maven.org/maven2/org/apache/ant/ant-launcher/1.9.6/ant-launcher-1.9.6.jar ...
[ivy:cachepath] ........ (17kB)
[ivy:cachepath] .. (0kB)
[ivy:cachepath] 	[SUCCESSFUL ] org.apache.ant#ant-launcher;1.9.6!ant-launcher.jar (67ms)
[ivy:cachepath] :: resolution report :: resolve 2941ms :: artifacts dl 1170ms
[ivy:cachepath] 	:: evicted modules:
[ivy:cachepath] 	org.eclipse.jgit#org.eclipse.jgit.ant;3.0.0.201306101825-r by [org.eclipse.jgit#org.eclipse.jgit.ant;4.7.0.201704051617-r] in [compile]
[ivy:cachepath] 	org.eclipse.jgit#org.eclipse.jgit;3.0.0.201306101825-r by [org.eclipse.jgit#org.eclipse.jgit;4.7.0.201704051617-r] in [compile]
[ivy:cachepath] 	com.jcraft#jsch;0.1.50 by [com.jcraft#jsch;0.1.54] in [compile]
	---------------------------------------------------------------------
	|                  |            modules            ||   artifacts   |
	|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
	---------------------------------------------------------------------
	|      compile     |   15  |   12  |   12  |   3   ||   11  |   11  |
	---------------------------------------------------------------------
  [taskdef] Could not load definitions from resource com/rimerosolutions/ant/git/jgit-ant-lib.xml. It could not be found.

BUILD FAILED
/home/tzfrs/dev/Test/TestAnt/build.xml:15: Problem: failed to create task or type antlib:com.rimerosolutions.ant.git:git
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/home/tzfrs/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 4 seconds

Vague error on git clone

Trying to get pull / push / clone working. Local repo work seems to be running fine.

However, remote raises vague error about that it failed. Unclear whether it is due to authorization issues (tried ssh, https, key, user/pwd combination) or something else:

For instance:
<git:clone uri="https://github.com/rimerosolutions/playground-repo.git"/>

BUILD FAILED
E:\ws\itgen\build-itgen.xml:5246: Could not clone URL 'https://github.com/rimerosolutions/playground-repo.git'.

Suggested change:
Improve clarity of error message with a cause and maybe even a recommended action.

git describe support

Suggestion for an enhancement: as far as I can see there is no support for git describe with its variants. That would help us in our automated builds.

Improve merge task error reporting

I've found the merge task to fail without any reason being logged. There must be more information in MergeResult that we're not looking at.

Package as Eclipse Plugin

Would it be possible to package this library as an Eclipse plugin using the Task extension point and dependencies to the other plugins (JGit is already part of eclipse). Anything else could go to the Extra Classpath-Entry extension point.

Maybe you could even publish a feature and a site to marketplace?

This would really ease the use from within Eclipse itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.