Skip to content

Commit

Permalink
build the svnRevNr helper, too.
Browse files Browse the repository at this point in the history
(needed for a clean .deb)


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3154 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
allo committed Jan 2, 2007
1 parent a27e884 commit 77c02cf
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
12 changes: 11 additions & 1 deletion build.xml
Expand Up @@ -92,7 +92,17 @@
if the .svn directory exists we try to determine the real
svn 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"/>

Expand Down
96 changes: 96 additions & 0 deletions 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();
}
}
1 change: 1 addition & 0 deletions lib/svnRevNr/svnRevNrParser.properties
@@ -0,0 +1 @@
svnrevnr=svnRevNrParser

0 comments on commit 77c02cf

Please sign in to comment.