Revision 9000+ hack

do not handle the revision in build.properties anymore
(9000 as fallback)
build-date from git-HEAD (instead when build is fired)
(orginal build-date as fallback)
pull/1/head
sixcooler 13 years ago
parent 752b092b8a
commit d14ee8e464

@ -7,7 +7,6 @@ releaseVersion=1.01
stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz stdReleaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz sourceReleaseFile=yacy_src_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
releaseFileParentDir=yacy releaseFileParentDir=yacy
releaseNr=$Revision: 9000 $
privateKeyFile=private.key privateKeyFile=private.key
# defining some file/directory access rights # defining some file/directory access rights

@ -58,6 +58,9 @@
<property name="release_mac" location="${release}/MAC"/> <property name="release_mac" location="${release}/MAC"/>
<property name="git" location=".git"/> <property name="git" location=".git"/>
<property name="defaults" location="defaults"/> <property name="defaults" location="defaults"/>
<!-- pseudo default releaseNr as fallback -->
<property name="releaseNr" value="9000" />
<!-- defining all needed directory names for packing search widget--> <!-- defining all needed directory names for packing search widget-->
<property name="jquery" location="htroot/jquery/"/> <property name="jquery" location="htroot/jquery/"/>
@ -95,33 +98,13 @@
<pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" /> <pathelement location="${libbuild}/org.eclipse.jgit-1.1.0.201109151100-r.jar" />
</classpath> </classpath>
</taskdef> </taskdef>
<gitRev repoPath="${yacyroot}" property="baseRevisionNr" /> <gitRev repoPath="${yacyroot}" revprop="releaseNr" dateprop="DSTAMP" />
<!-- 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> </target>
<!-- reading the build properties from file --> <!-- reading the build properties from file -->
<!-- <target name="readBuildProperties" depends="determineGitRevision"> --> <target name="readBuildProperties" depends="determineGitRevision">
<target name="readBuildProperties">
<!-- loading some property values from file --> <!-- loading some property values from file -->
<loadproperties srcFile="build.properties"> <loadproperties srcFile="build.properties" />
<filterchain>
<tokenfilter>
<replaceregex pattern="^releaseNr=\$Revision:\s(.*)\s\$"
replace="releaseNr=\1"/>
</tokenfilter>
</filterchain>
</loadproperties>
</target> </target>
<!-- initializing all needed variables --> <!-- initializing all needed variables -->

@ -1,8 +1,7 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List; 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.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@ -19,36 +18,48 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
public class GitRevTask extends org.apache.tools.ant.Task { public class GitRevTask extends org.apache.tools.ant.Task {
private String repoPath; private String repoPath;
private String property; private String revprop;
private String dateprop;
public void setRepoPath(final String repoPath) { public void setRepoPath(final String repoPath) {
this.repoPath = repoPath; this.repoPath = repoPath;
} }
public void setProperty(String property) { public void setRevprop(String revprop) {
this.property = property; this.revprop = revprop;
}
public void setDateprop(String dateprop) {
this.dateprop = dateprop;
} }
public void execute() { public void execute() {
if (this.property==null || this.property.length() == 0) { if (this.revprop==null || this.revprop.length() == 0) {
log("svn entries file name property was not set properly",Project.MSG_ERR); log("git entries file name revprop was not set properly",Project.MSG_ERR);
return;
}
if (this.dateprop==null || this.dateprop.length() == 0) {
log("git entries file name dateprop was not set properly",Project.MSG_ERR);
return; return;
} }
String revision = null; String revision = null;
String lastTag = null; String lastTag = null;
String commitDate = null;
try { try {
final File src = new File(repoPath); final File src = new File(repoPath);
final Repository repo = new FileRepositoryBuilder().readEnvironment() final Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build(); .findGitDir(src).build();
final ObjectId head = repo.resolve("HEAD"); final ObjectId head = repo.resolve("HEAD");
final String gitrev = head.getName().substring(0, 8);
final Git git = new Git(repo); final Git git = new Git(repo);
final List<RevTag> tags = git.tagList().call(); final List<RevTag> tags = git.tagList().call();
final RevWalk walk = new RevWalk(repo); final RevWalk walk = new RevWalk(repo);
walk.markStart(walk.parseCommit(head)); final RevCommit headCommit = walk.parseCommit(head);
final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
commitDate = df.format(headCommit.getAuthorIdent().getWhen());
walk.markStart(headCommit);
int distance = 0; int distance = 0;
for (final RevCommit commit : walk) { for (final RevCommit commit : walk) {
for (final RevTag tag : tags) { for (final RevTag tag : tags) {
@ -57,39 +68,33 @@ public class GitRevTask extends org.apache.tools.ant.Task {
break; break;
} }
} }
if (lastTag == null) lastTag = findRev(commit.getFullMessage()); if (lastTag != null || distance++ > 999) break;
if (lastTag != null || distance++ > 99) break;
} }
walk.dispose(); walk.dispose();
if (lastTag == null) { if (lastTag == null) {
revision = "dev" + "-" + gitrev; revision = "0000";
} else { } else {
revision = lastTag + "-" + distance + "-" + gitrev; revision = Integer.toString(distance + 9000);
} }
} catch (IOException e) { } catch (final IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
Project theProject = getProject(); Project theProject = getProject();
if (theProject != null) { if (theProject != null) {
theProject.setProperty(this.property, lastTag); theProject.setProperty(this.revprop, revision);
log("Property '" + this.property + "' set to '" + revision + "'", Project.MSG_VERBOSE); log("Property '" + this.revprop + "' set to '" + revision + "'", Project.MSG_VERBOSE);
theProject.setProperty(this.dateprop, commitDate);
log("Property '" + this.dateprop + "' set to '" + commitDate + "'", 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) { public static void main(String[] args) {
GitRevTask gitRevTask = new GitRevTask(); GitRevTask gitRevTask = new GitRevTask();
gitRevTask.setRepoPath("/home/sgaebel/git/yacy.rc1"); gitRevTask.setRepoPath("/home/sgaebel/git/yacy.rc1");
gitRevTask.setRevprop("baseRevisionNr");
gitRevTask.setDateprop("DSTAMP");
gitRevTask.execute(); gitRevTask.execute();
} }

Loading…
Cancel
Save