SF.net SVN: jython:[7250] trunk/jython

[email protected] Sun, 20 Mar 2011 06:07:17 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7250
          http://jython.svn.sourceforge.net/jython/?rev=7250&view=rev
Author:   pjenvey
Date:     2011-03-20 06:07:17 +0000 (Sun, 20 Mar 2011)

Log Message:
-----------
hg version support

Modified Paths:
--------------
    trunk/jython/build.xml
    trunk/jython/src/org/python/Version.java
    trunk/jython/src/org/python/core/PySystemState.java

Modified: trunk/jython/build.xml
===================================================================
--- trunk/jython/build.xml	2011-03-19 23:41:41 UTC (rev 7249)
+++ trunk/jython/build.xml	2011-03-20 06:07:17 UTC (rev 7250)
@@ -398,10 +398,33 @@
         <exec executable="svnversion" failifexecutionfails="false" outputproperty="build.svn.revision"/>
     </target>
 
+    <!-- XXX: Might this work on Windows? -->
+    <target name="hg-branch" if="os.family.unix">
+        <exec executable="hg" failifexecutionfails="false" outputproperty="build.hg.branch">
+          <arg line="id -b"/>
+        </exec>
+    </target>
+    <target name="hg-tag" if="os.family.unix">
+        <exec executable="hg" failifexecutionfails="false" outputproperty="build.hg.tag">
+          <arg line="id -t"/>
+        </exec>
+    </target>
+    <target name="hg-version" if="os.family.unix">
+        <exec executable="hg" failifexecutionfails="false" outputproperty="build.hg.version">
+          <arg line="id -i"/>
+        </exec>
+    </target>
+    <target name="hg-id" depends="hg-branch, hg-tag, hg-version"/>
+
     <!-- skip-brand can be set in ant.properties or as a system property to keep from updating the
          version.properties file and making the jar on every developer build. -->
+    <!-- when hg:
+    <target name="brand-version" depends="init, hg-id" unless="skip-brand">-->
     <target name="brand-version" depends="init, svnversion" unless="skip-brand">
         <property name="build.svn.revision" value=""/>
+        <property name="build.hg.branch" value=""/>
+        <property name="build.hg.tag" value=""/>
+        <property name="build.hg.version" value=""/>
         <tstamp>
             <format property="build.date" pattern="MMM d yyyy" offset="0"/>
             <format property="build.time" pattern="HH:mm:ss" offset="0"/>
@@ -416,7 +439,10 @@
 jython.release_serial=${jython.release_serial}
 jython.build.date=${build.date}
 jython.build.time=${build.time}
-jython.build.svn_revision=${build.svn.revision}</echo>
+jython.build.svn_revision=${build.svn.revision}
+jython.build.hg_branch=${build.hg.branch}
+jython.build.hg_tag=${build.hg.tag}
+jython.build.hg_version=${build.hg.version}</echo>
     </target>
 
     <target name="brand-readme-version" depends="checkout" if="do.snapshot.build">

Modified: trunk/jython/src/org/python/Version.java
===================================================================
--- trunk/jython/src/org/python/Version.java	2011-03-19 23:41:41 UTC (rev 7249)
+++ trunk/jython/src/org/python/Version.java	2011-03-20 06:07:17 UTC (rev 7250)
@@ -34,6 +34,8 @@
     public static String DATE;
     public static String TIME;
     public static String SVN_REVISION;
+    /** Current hg global revision id (hg id -i). */
+    public static String HG_VERSION;
 
     /** Determined from headURL, branch is the path under the
      * subversion root, e.g. branches/asm. */
@@ -42,6 +44,12 @@
     /** Short version of branch, e.g. asm. */
     public static String SHORT_BRANCH;
 
+    /** Current hg branch (hg id -b). */
+    public static String HG_BRANCH;
+
+    /** Current hg tag (hg id -t), e.g. 'tip'. */
+    public static String HG_TAG;
+
     /** The flags that are set by default in a code object. */
     private static final Collection<CodeFlag> defaultCodeFlags = Arrays.asList(
             CodeFlag.CO_NESTED, CodeFlag.CO_GENERATOR_ALLOWED, CodeFlag.CO_FUTURE_WITH_STATEMENT);
@@ -103,6 +111,9 @@
                 DATE = properties.getProperty("jython.build.date");
                 TIME = properties.getProperty("jython.build.time");
                 SVN_REVISION = properties.getProperty("jython.build.svn_revision");
+                HG_BRANCH = properties.getProperty("jython.build.hg_branch");
+                HG_TAG = properties.getProperty("jython.build.hg_tag");
+                HG_VERSION = properties.getProperty("jython.build.hg_version");
             } catch (IOException ioe) {
                 System.err.println("There was a problem loading ".concat(versionProperties)
                         .concat(":"));
@@ -137,6 +148,21 @@
     }
 
     /**
+     * Return the current hg version number. May be an empty string on environments that
+     * can't determine it.
+     */
+    public static String getHGVersion() {
+        return HG_VERSION;
+    }
+
+    /**
+     * Return the current hg identifier name, either the current branch or tag.
+     */
+    public static String getHGIdentifier() {
+        return "".equals(HG_TAG) || "tip".equals(HG_TAG) ? HG_BRANCH : HG_TAG;
+    }
+
+    /**
      * Return the current build information, including revision and
      * timestamp.
      */
@@ -148,6 +174,16 @@
     }
 
     /**
+     * Return the current build information, including revision and timestamp.
+     */
+    public static String getBuildInfoHG() {
+        String revision = getHGVersion();
+        String sep = "".equals(revision) ? "" : ":";
+        String hgId = getHGIdentifier();
+        return String.format("%s%s%s, %.20s, %.9s", hgId, sep, revision, DATE, TIME);
+    }
+
+    /**
      * Describe the current Java VM.
      */
     public static String getVM() {

Modified: trunk/jython/src/org/python/core/PySystemState.java
===================================================================
--- trunk/jython/src/org/python/core/PySystemState.java	2011-03-19 23:41:41 UTC (rev 7249)
+++ trunk/jython/src/org/python/core/PySystemState.java	2011-03-20 06:07:17 UTC (rev 7250)
@@ -75,6 +75,8 @@
     public final static Class flags = Options.class;
     
     public static PyTuple subversion;
+
+    public static PyTuple _mercurial;
     /**
      * The copyright notice for this release.
      */
@@ -956,6 +958,8 @@
                                    Py.newInteger(Version.PY_RELEASE_SERIAL));
         subversion = new PyTuple(Py.newString("Jython"), Py.newString(Version.BRANCH),
                                  Py.newString(Version.SVN_REVISION));
+        _mercurial = new PyTuple(Py.newString("Jython"), Py.newString(Version.getHGIdentifier()),
+                                 Py.newString(Version.getHGVersion()));
     }
 
     public static boolean isPackageCacheEnabled() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d