Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
build the svnRevNr helper, too. (needed for a clean .deb)
allo77c02cf18002
diff --git a/build.xml b/build.xmlindex 577e032eb..034cf5a6e 100644--- a/build.xml+++ b/build.xml@@ -92,7 +92,17 @@if the .svn directory exists we try to determine the realsvn revision number of the working base now-->-<target name="determineRevisionNr" if="svnEntriesFileExists">++<target name="buildSvnRevNr">+ <delete file="lib/svnRevNr.jar" />+ <jar destfile="lib/svnRevNr.jar" basedir="${lib}/svnRevNr">+ <manifest>+ <attribute name="Main-Class" value="svnRevNrParser"/>+ </manifest>+ </jar>+</target>++<target name="determineRevisionNr" if="svnEntriesFileExists" depends="buildSvnRevNr"><!-- define a custom ant task to read the revision number from file --><taskdef resource="svnRevNrParser.properties" classpath="${lib}/svnRevNr.jar"/>diff --git a/lib/svnRevNr/svnRevNrParser.java b/lib/svnRevNr/svnRevNrParser.javanew file mode 100644index 000000000..4dd154531--- /dev/null+++ b/lib/svnRevNr/svnRevNrParser.java@@ -0,0 +1,96 @@+++import java.io.File;+import java.io.FileInputStream;+import java.util.regex.Matcher;+import java.util.regex.Pattern;++import org.apache.tools.ant.BuildException;+import org.apache.tools.ant.Project;++public class svnRevNrParser extends org.apache.tools.ant.Task{++ private String fileName=null;+ private String property=null;++ public void setFile(String name) {+ this.fileName = name;+ }++ public String getFile() {+ return this.fileName;+ }++ public void setProperty(String property) {+ this.property = property;+ }++ public String getProperty() {+ return this.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;+ }++ if (this.fileName != null && this.fileName.length() > 0) {+ File entriesFile = new File(this.fileName);+ if (!entriesFile.exists()) throw new BuildException("SVN entries file '" + this.fileName + "' does not exist.");+ if (!entriesFile.canRead()) throw new BuildException("SVN entries file '" + this.fileName + "' is not readable.");++ // read the content of the file into memory+ String dataStr;+ try {+ byte[] data = new byte[(int) entriesFile.length()];+ FileInputStream input = new FileInputStream(entriesFile);+ input.read(data);+ dataStr = new String(data);+ } catch (Exception e) {+ throw new BuildException("Unable to read the SVN entries file '" + this.fileName + "'");+ }++ // parse the content+ Pattern pattern;+ if (dataStr.startsWith("<?xml")) {+ pattern = Pattern.compile("<entry[^>]*(?:name=\"\"[^>]*revision=\"(\\d*)\"|revision=\"(\\d*)\"[^>]*name=\"\")[^>]*/>");+ } else {+ pattern = Pattern.compile("\\s\\sdir\\s*(\\d*)\\s*svn(\\+ssh)?://");+ }++ Matcher matcher = pattern.matcher(dataStr);+ String revNr;+ if (matcher.find()) {+ revNr = matcher.group(1);+ if (revNr == null) revNr = matcher.group(2);++ System.out.println(revNr);+ log("SVN revision number found: " + revNr, Project.MSG_VERBOSE);+ } else {+ log("Unable to determine the SVN revision number", Project.MSG_WARN);+ revNr = "0000";+ }++ Project theProject = getProject();+ if (theProject != null) {+ theProject.setProperty(this.property, revNr);+ log("Property '" + this.property + "' set to '" + revNr + "'", Project.MSG_VERBOSE);+ }+ } else {+ throw new BuildException("File name attribute is required.");+ }++ }++ public static void main(String[] args) {+ svnRevNrParser parser = new svnRevNrParser();+// parser.setFile(".svn/entries");+// parser.setProperty("test");+// parser.execute();++ parser.setFile("/home/theli/.eclipse/yacy/.svn/entries");+ parser.setProperty("test");+ parser.execute();+ }+}diff --git a/lib/svnRevNr/svnRevNrParser.properties b/lib/svnRevNr/svnRevNrParser.propertiesnew file mode 100644index 000000000..ac577405d--- /dev/null+++ b/lib/svnRevNr/svnRevNrParser.properties@@ -0,0 +1 @@+svnrevnr=svnRevNrParser\ No newline at end of file