From 77c02cf18002f5520a85265c55116ccaf52da596 Mon Sep 17 00:00:00 2001 From: allo Date: Tue, 2 Jan 2007 23:33:19 +0000 Subject: [PATCH] build the svnRevNr helper, too. (needed for a clean .deb) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3154 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- build.xml | 12 +++- lib/svnRevNr/svnRevNrParser.java | 96 ++++++++++++++++++++++++++ lib/svnRevNr/svnRevNrParser.properties | 1 + 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 lib/svnRevNr/svnRevNrParser.java create mode 100644 lib/svnRevNr/svnRevNrParser.properties diff --git a/build.xml b/build.xml index 577e032eb..034cf5a6e 100644 --- a/build.xml +++ b/build.xml @@ -92,7 +92,17 @@ if the .svn directory exists we try to determine the real svn revision number of the working base now --> - + + + + + + + + + + + diff --git a/lib/svnRevNr/svnRevNrParser.java b/lib/svnRevNr/svnRevNrParser.java new file mode 100644 index 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("]*(?: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.properties new file mode 100644 index 000000000..ac577405d --- /dev/null +++ b/lib/svnRevNr/svnRevNrParser.properties @@ -0,0 +1 @@ +svnrevnr=svnRevNrParser \ No newline at end of file