diff options
| author | sixcooler <sgaebel@sixcooler.de> | 2011-11-24 15:51:25 +0100 |
|---|---|---|
| committer | sixcooler <sgaebel@sixcooler.de> | 2011-11-24 15:51:25 +0100 |
| commit | d9c56aa37acbd30965776ceafb188d49c0fbb20f (patch) | |
| tree | 4e9d700c7aa5fe90437e34c69c02806edf61b11c | |
| parent | 0349a96b4db5e969522a457559c6f2e4a7654671 (diff) | |
Ant-Task for getting version from git
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | build.properties | 2 | ||||
| -rw-r--r-- | build.xml | 46 | ||||
| -rw-r--r-- | libbuild/GitRevTask/GitRevTask.java | 96 | ||||
| -rw-r--r-- | libbuild/GitRevTask/GitRevTask.properties | 1 | ||||
| -rw-r--r-- | libbuild/org.eclipse.jgit-1.1.0.201109151100-r.jar | bin | 0 -> 1379238 bytes | |||
| -rw-r--r-- | libbuild/org.eclipse.jgit-1.1.0.201109151100-r.license | 37 |
7 files changed, 181 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index 38d477034..9fa982899 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.class lib/yacycore.jar libbuild/svnRevNr.jar +libbuild/GitRevTask.jar gen/** DATA/ classes/ diff --git a/build.properties b/build.properties index 678872126..9325ef6f9 100644 --- a/build.properties +++ b/build.properties @@ -7,7 +7,7 @@ releaseVersion=0.99 stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
releaseFileParentDir=yacy
-releaseNr=$Revision$
+releaseNr=$Revision: 8091 $
privateKeyFile=private.key
# defining some file/directory access rights
@@ -57,6 +57,7 @@ <property name="release_windows" location="${release}/WINDOWS"/> <property name="release_mac" location="${release}/MAC"/> <property name="svnEntriesFile" location=".svn/entries"/> + <property name="git" location=".git"/> <property name="defaults" location="defaults"/> <!-- defining all needed directory names for packing search widget--> @@ -69,6 +70,47 @@ <property name="PKGMANAGER" value="false"/> <property name="RESTARTCMD" value="/etc/init.d/yacy restart"/> + <!-- determining if the .git directory exists --> + <condition property="isGit"> + <available file="${git}" /> + </condition> + + <target name="buildGitRevTask"> + <delete file="${libbuild}/GitRevTask.jar" failonerror="false" /> + <javac srcdir="${libbuild}/GitRevTask"> + <classpath> + <pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" /> + </classpath> + </javac> + <jar destfile="${libbuild}/GitRevTask.jar" basedir="${libbuild}/GitRevTask"> + <manifest> + <attribute name="Main-Class" value="GitRevTask"/> + </manifest> + </jar> + </target> + + <target name="determineGitRevision" if="isGit" depends="buildGitRevTask"> + <taskdef resource="GitRevTask.properties"> + <classpath> + <pathelement location="${libbuild}/GitRevTask.jar" /> + <pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" /> + </classpath> + </taskdef> + <gitRev repoPath="${yacyroot}" property="baseRevisionNr" /> + + <!-- replacing the old with the new revision number --> + <copy file="build.properties" tofile="build.properties.new"> + <filterchain> + <tokenfilter> + <replaceregex pattern="^releaseNr=(.*)" + replace="releaseNr=$Revision: ${baseRevisionNr} $" /> + </tokenfilter> + </filterchain> + </copy> + <delete file="build.properties"/> + <move file="build.properties.new" tofile="build.properties"/> + </target> + <!-- determining if the .svn directory exists --> <condition property="svnEntriesFileExists"> <available file="${svnEntriesFile}" /> @@ -111,7 +153,7 @@ </target> <!-- reading the build properties from file --> - <target name="readBuildProperties" depends="determineRevisionNr"> + <target name="readBuildProperties" depends="determineGitRevision,determineRevisionNr"> <!-- loading some property values from file --> <loadproperties srcFile="build.properties"> <filterchain> @@ -510,12 +552,14 @@ <delete file="${lib}/yacycore.jar" failonerror="false"/> <delete file="${lib}/svnRevNr.jar" failonerror="false"/> <delete file="${libbuild}/svnRevNr.jar" failonerror="false"/> + <delete file="${libbuild}/GitRevTask.jar" failonerror="false"/> <delete failonerror="false"> <fileset dir="${src}" includes="**/*.class" /> <fileset dir="${build}" includes="**/*.class" /> <fileset dir="${htroot}" includes="**/*.class" /> <fileset dir="test/" includes="**/*.class" /> <fileset dir="${libbuild}/svnRevNr" includes="**/*.class" /> + <fileset dir="${libbuild}/GitRevTask" includes="**/*.class" /> <fileset dir="." includes="TEST-*" /> </delete> </target> diff --git a/libbuild/GitRevTask/GitRevTask.java b/libbuild/GitRevTask/GitRevTask.java new file mode 100644 index 000000000..3d9302d98 --- /dev/null +++ b/libbuild/GitRevTask/GitRevTask.java @@ -0,0 +1,96 @@ +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevTag; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; + + +public class GitRevTask extends org.apache.tools.ant.Task { + + private String repoPath; + private String property; + + public void setRepoPath(final String repoPath) { + this.repoPath = repoPath; + } + + public void setProperty(String property) { + this.property = property; + } + + public void execute() { + if (this.property==null || this.property.length() == 0) { + log("svn entries file name property was not set properly",Project.MSG_ERR); + return; + } + + String revision = null; + String lastTag = null; + try { + final File src = new File(repoPath); + final Repository repo = new FileRepositoryBuilder().readEnvironment() + .findGitDir(src).build(); + final ObjectId head = repo.resolve("HEAD"); + final String gitrev = head.getName().substring(0, 8); + + final Git git = new Git(repo); + final List<RevTag> tags = git.tagList().call(); + + final RevWalk walk = new RevWalk(repo); + walk.markStart(walk.parseCommit(head)); + int distance = 0; + for (final RevCommit commit : walk) { + for (final RevTag tag : tags) { + if (commit.equals(tag.getObject())) { + lastTag = tag.getShortMessage(); + break; + } + } + if (lastTag == null) lastTag = findRev(commit.getFullMessage()); + if (lastTag != null || distance++ > 99) break; + } + walk.dispose(); + if (lastTag == null) { + revision = "dev" + "-" + gitrev; + } else { + revision = lastTag + "-" + distance + "-" + gitrev; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Project theProject = getProject(); + if (theProject != null) { + theProject.setProperty(this.property, lastTag); + log("Property '" + this.property + "' set to '" + revision + "'", Project.MSG_VERBOSE); + } + } + + private String findRev(final String message) { + final Pattern pattern = Pattern.compile("trunk@(\\d{4})\\s+"); + final Matcher matcher = pattern.matcher(message); + if (matcher.find()) { + return matcher.group(1); + } + return null; + } + + public static void main(String[] args) { + GitRevTask gitRevTask = new GitRevTask(); + gitRevTask.setRepoPath("/home/sgaebel/git/yacy.rc1"); + + gitRevTask.execute(); + } +} diff --git a/libbuild/GitRevTask/GitRevTask.properties b/libbuild/GitRevTask/GitRevTask.properties new file mode 100644 index 000000000..13effd982 --- /dev/null +++ b/libbuild/GitRevTask/GitRevTask.properties @@ -0,0 +1 @@ +gitRev=GitRevTask
\ No newline at end of file diff --git a/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.jar b/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.jar Binary files differnew file mode 100644 index 000000000..40d5c0c50 --- /dev/null +++ b/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.jar diff --git a/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.license b/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.license new file mode 100644 index 000000000..1b85c6466 --- /dev/null +++ b/libbuild/org.eclipse.jgit-1.1.0.201109151100-r.license @@ -0,0 +1,37 @@ +This program and the accompanying materials are made available +under the terms of the Eclipse Distribution License v1.0 which +accompanies this distribution, is reproduced below, and is +available at http://www.eclipse.org/org/documents/edl-v10.php + +All rights reserved. + +Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following +conditions are met: + +- Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + +- Neither the name of the Eclipse Foundation, Inc. nor the + names of its contributors may be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
