Merge branch 'sigar-1.6'

This commit is contained in:
Doug MacEachern 2010-04-03 12:42:53 -07:00
commit ccbd22fad6
2 changed files with 52 additions and 50 deletions

View File

@ -14,6 +14,7 @@
<property name="jni.define.name" value="SIGAR"/>
<property name="sigar-bin" location="sigar-bin"/>
<property name="sigar-bin-dir" location="${sigar-bin}"/>
<property name="jni.git" location="../../.git"/>
<property name="jni.bin" location="${sigar-bin}"/>
<property name="jni.source.dir" location="../.."/>
<property name="jni.src.java" value="hyperic_jni/src"/>
@ -116,7 +117,7 @@
<replace file="${version.tofile}">
<replacefilter token="@@BUILD_DATE@@" value="${BUILD_DATE}"/>
<replacefilter token="@@VERSION_STRING@@" value="${sigar.version}.${version.build}"/>
<replacefilter token="@@SCM_REVISION@@" value="${sigar.scmrev}"/>
<replacefilter token="@@SCM_REVISION@@" value="${jni.scmrev}"/>
<replacefilter token="@@ARCHNAME@@" value="${jni.libarch}"/>
<replacefilter token="@@ARCHLIB@@" value="${jni.libname.full}"/>
<replacefilter token="@@BINNAME@@" value="${jni.project.archname}"/>
@ -128,59 +129,12 @@
</replace>
</target>
<target name="check-svn">
<condition property="svn.available">
<and>
<available file=".svn" type="dir"/>
<available file="svn" type="file">
<filepath>
<pathelement path="${env.PATH}"/>
</filepath>
</available>
</and>
</condition>
</target>
<target name="svn-revision" if="svn.available">
<exec executable="svnversion" dir="."
outputproperty="sigar.scmrev"
failifexecutionfails="false">
<arg value="."/>
</exec>
<echo message="SIGAR svn revision #${sigar.scmrev}"/>
</target>
<target name="check-git">
<condition property="git.available">
<and>
<available file="../../.git" type="dir"/>
<available file="git" type="file">
<filepath>
<pathelement path="${env.PATH}"/>
</filepath>
</available>
</and>
</condition>
</target>
<target name="git-revision" if="git.available">
<exec executable="git" dir="."
outputproperty="sigar.scmrev"
failifexecutionfails="false">
<arg value="rev-parse"/>
<arg value="--short"/>
<arg value="HEAD"/>
</exec>
<echo message="SIGAR git revision #${sigar.scmrev}"/>
</target>
<target name="sigar-version" depends="check-svn,svn-revision,check-git,git-revision">
<target name="sigar-version">
<tstamp>
<format property="BUILD_DATE" pattern="MM/dd/yyyy hh:mm aa"/>
</tstamp>
<!-- in the case of release source builds -->
<property name="sigar.scmrev" value="exported"/>
<echo message="SIGAR git revision ${jni.scmrev}"/>
<antcall target="version-file">
<param name="version.file"

View File

@ -18,8 +18,11 @@
package org.hyperic.jni;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.Reader;
import java.util.Arrays;
import org.apache.tools.ant.Task;
@ -134,5 +137,50 @@ public class ArchNameTask extends Task {
System.out.println("Using -mmacosx-version-min=" + min);
}
}
getProject().setProperty("jni.scmrev", getSourceRevision());
}
//XXX source rev stuff should be in another task
private String readLine(String filename) {
Reader reader = null;
try {
reader = new FileReader(filename);
return new BufferedReader(reader).readLine();
} catch (Exception e) {
} finally {
if (reader != null) {
try { reader.close(); } catch (Exception e) {}
}
}
return null;
}
private String getSourceRevision() {
final String exported = "exported";
String sha1 = getGitSourceRevision();
if (sha1 == null) {
return exported;
}
else {
return sha1;
}
}
//same as: git rev-parse --short HEAD
//same as: (cd .git && cat HEAD | awk '{print $2}' | xargs cat | cut -b 1-7)
private String getGitSourceRevision() {
String git = getProject().getProperty("jni.git");
if (git == null) {
git = ".git";
}
if (new File(git).exists()) {
String head = readLine(git + "/HEAD");
if (head != null) {
String ref = head.substring(5).trim(); //'ref: '
return readLine(git + "/" + ref).substring(0, 7);
}
}
return null;
}
}