Permalink
Browse files

Upgraded jgit build library to version 4.5.0

This is the latest Java 7 compatible jgit release.

Properly support GitHub tags marked as "Pre-release". 
With the previous venerable jgit version 1.1.0, a YaCy repository clone
having such a tag made GitRevTask and GitRevMavenTask crash.
  • Loading branch information...
luccioman committed Jan 4, 2017
1 parent 9cfe8dd commit b55cf16dadd46a4ae049a805f1176e01672157ca
@@ -84,7 +84,12 @@
<delete file="${libbuild}/GitRevTask.jar" failonerror="false" />
<javac srcdir="${libbuild}/GitRevTask" includeantruntime="true" encoding="UTF-8">
<classpath>
<pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" />
<pathelement location="${libbuild}/org.eclipse.jgit-4.5.0.201609210915-r.jar" />
<!-- Next are the jgit dependencies -->
<pathelement location="${libbuild}/httpclient-4.3.6.jar" />
<pathelement location="${libbuild}/JavaEWAH-0.7.9.jar" />
<pathelement location="${libbuild}/jsch-0.1.53.jar" />
<pathelement location="${libbuild}/slf4j-api-1.7.2.jar" />
</classpath>
</javac>
<jar destfile="${libbuild}/GitRevTask.jar" basedir="${libbuild}/GitRevTask">
@@ -98,7 +103,12 @@
<taskdef resource="GitRevTask.properties">
<classpath>
<pathelement location="${libbuild}/GitRevTask.jar" />
<pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" />
<pathelement location="${libbuild}/org.eclipse.jgit-4.5.0.201609210915-r.jar" />
<!-- Next are the jgit dependencies -->
<pathelement location="${libbuild}/httpclient-4.3.6.jar" />
<pathelement location="${libbuild}/JavaEWAH-0.7.9.jar" />
<pathelement location="${libbuild}/jsch-0.1.53.jar" />
<pathelement location="${libbuild}/slf4j-api-1.7.2.jar" />
</classpath>
</taskdef>
<gitRev repoPath="${yacyroot}" branchprop="branch" revprop="releaseNr" dateprop="DSTAMP" />
@@ -4,7 +4,7 @@
<groupId>net.yacy</groupId>
<artifactId>maven-plugin-gitrevisionnumber</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>maven-plugin</packaging>
<name>YaCy - Build Number Maven Plugin</name>
<description>This plugin gives you a Git repository release number. in the format 9000 as maven property "releaseNr" and a Git repository timestamp as Maven property "DSTAMP" in the format yyyymmdd </description>
@@ -36,8 +36,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
@@ -115,7 +115,7 @@
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>1.3.0.201202151440-r</version>
<version>4.5.0.201609210915-r</version>
<type>jar</type>
</dependency>
<dependency>
@@ -2,20 +2,22 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
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;
@@ -61,29 +63,40 @@ public void execute() throws MojoExecutionException {
String lastTag = null;
String commitDate = null;
Repository repo = null;
Git git = null;
RevWalk walk = null;
try {
final File src = project.getBasedir(); // set Git root path to project root
final Repository repo = new FileRepositoryBuilder().readEnvironment()
repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build();
branch = repo.getBranch();
branch = "master".equals(branch) ? "" : "_" + branch;
final ObjectId head = repo.resolve("HEAD");
final Git git = new Git(repo);
git = new Git(repo);
final List<RevTag> tags = git.tagList().call();
final List<Ref> tags = git.tagList().call();
final RevWalk walk = new RevWalk(repo);
walk = new RevWalk(repo);
final RevCommit headCommit = walk.parseCommit(head);
final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
commitDate = df.format(headCommit.getAuthorIdent().getWhen());
walk.markStart(headCommit);
int distance = 0;
for (final RevCommit commit : walk) {
for (final RevTag tag : tags) {
if (commit.equals(tag.getObject())) {
lastTag = tag.getShortMessage();
/* Peel known tags */
final List<Ref> peeledTags = new ArrayList<>();
for (final Ref tag : tags) {
peeledTags.add(repo.peel(tag));
}
/* Look for the last tag commit and calculate distance with the HEAD commit */
for (final RevCommit commit : walk) {
for (final Ref tag : peeledTags) {
if (commit.equals(tag.getPeeledObjectId()) || commit.equals(tag.getObjectId())) {
lastTag = commit.getShortMessage();
break;
}
}
@@ -99,7 +112,21 @@ public void execute() throws MojoExecutionException {
}
} catch (final IOException e) {
e.printStackTrace();
}
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
/* In all cases, properly release resources */
if(walk != null) {
walk.close();
}
if(git != null) {
git.close();
}
if(repo != null) {
repo.close();
}
}
if (project != null) {
project.getProperties().put(this.branchPropertyName, branch);
log.info("GitrevMavenTask: set property " + this.branchPropertyName + "='" + branch + "'");
@@ -2,18 +2,17 @@
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
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;
@@ -55,31 +54,45 @@ public void execute() {
String revision = null;
String lastTag = null;
String commitDate = null;
Repository repo = null;
Git git = null;
RevWalk walk = null;
try {
final File src = new File(repoPath);
final Repository repo = new FileRepositoryBuilder().readEnvironment()
repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build();
branch = repo.getBranch();
branch = "master".equals(branch)? "" : "_" + branch;
final ObjectId head = repo.resolve("HEAD");
final Git git = new Git(repo);
final List<RevTag> tags = git.tagList().call();
git = new Git(repo);
final List<Ref> tags = git.tagList().call();
final RevWalk walk = new RevWalk(repo);
walk = new RevWalk(repo);
final RevCommit headCommit = walk.parseCommit(head);
final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
commitDate = df.format(headCommit.getAuthorIdent().getWhen());
walk.markStart(headCommit);
int distance = 0;
/* Peel known tags */
final List<Ref> peeledTags = new ArrayList<>();
for(final Ref tag : tags) {
peeledTags.add(repo.peel(tag));
}
/* Look for the last tag commit and calculate distance with the HEAD commit */
for (final RevCommit commit : walk) {
for (final RevTag tag : tags) {
if (commit.equals(tag.getObject())) {
lastTag = tag.getShortMessage();
for (final Ref tag : peeledTags) {
if (commit.equals(tag.getPeeledObjectId()) || commit.equals(tag.getObjectId())) {
lastTag = commit.getShortMessage();
break;
}
}
if (lastTag != null || distance++ > 90999) break;
if (lastTag != null || distance++ > 90999) {
break;
}
}
walk.dispose();
if (lastTag == null) {
@@ -90,6 +103,20 @@ public void execute() {
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
/* In all cases, properly release resources */
if(walk != null) {
walk.close();
}
if(git != null) {
git.close();
}
if(repo != null) {
repo.close();
}
}
Project theProject = getProject();
Oops, something went wrong.

0 comments on commit b55cf16

Please sign in to comment.