You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/23 09:28:11 UTC

svn commit: r817991 - in /commons/sandbox/runtime/trunk: ./ src/ant/org/apache/commons/runtime/ src/main/java/org/apache/commons/runtime/

Author: mturk
Date: Wed Sep 23 07:28:11 2009
New Revision: 817991

URL: http://svn.apache.org/viewvc?rev=817991&view=rev
Log:
Add Uuid ant task and remove task dependency on ACR so task can be build before ACR classes

Added:
    commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java   (with props)
Modified:
    commons/sandbox/runtime/trunk/build.xml
    commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/SystemIdTask.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java

Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=817991&r1=817990&r2=817991&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Wed Sep 23 07:28:11 2009
@@ -71,7 +71,6 @@
 
     <!-- Ant tasks classpath -->
     <path id="task.classpath">
-        <pathelement location="${build.dest}/java"/>
         <pathelement location="${build.dest}/ant"/>
     </path>
 
@@ -128,21 +127,53 @@
     </target>
 
     <!-- =================================================================== -->
+    <!-- Compiles the ant task directory                                     -->
+    <!-- =================================================================== -->
+    <target name="tasks" depends="prepare">
+        <mkdir dir="${build.dest}/ant"/>
+        <mkdir dir="${build.src}/ant"/>
+        <copy todir="${build.src}/ant" filtering="yes">
+            <fileset dir="${src.dir}/ant">
+                <include name="**/*.java"/>
+                <include name="**/*.xml"/>
+                <include name="**/*.properties"/>
+            </fileset>
+        </copy>
+        <javac srcdir="${build.src}/ant"
+            destdir="${build.dest}/ant"
+            debug="${compile.debug}"
+            source="${compile.source}"
+            target="${compile.target}"
+            deprecation="${compile.deprecation}"
+            optimize="${compile.optimize}">
+            <classpath refid="task.classpath"/>
+        </javac>
+        <taskdef name="systemid"
+            classname="org.apache.commons.runtime.SystemIdTask">
+            <classpath refid="task.classpath"/>
+        </taskdef>
+        <taskdef name="uuid"
+            classname="org.apache.commons.runtime.UuidTask">
+            <classpath refid="task.classpath"/>
+        </taskdef>
+        <uuid property="build.uuid" />
+    </target>
+
+    <!-- =================================================================== -->
     <!-- Compiles the source directory                                       -->
     <!-- =================================================================== -->
-    <target name="compile" depends="prepare">
+    <target name="compile" depends="tasks">
         <mkdir dir="${build.dest}"/>
         <mkdir dir="${build.dest}/java"/>
         <mkdir dir="${build.src}"/>
         <mkdir dir="${build.src}/java"/>
         <delete>
             <!-- Delete *.properties so that we always get the correct stamp -->
-            <fileset dir="${build.dest}/java" includes="**/*.properties"/>
+            <fileset dir="${build.src}/java" includes="**/*.properties"/>
         </delete>
         <tstamp>
             <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
             <format property="TSTAMP" pattern="HH:mm:ss"/>
-            <format property="BSTAMP" pattern="yyyyMMddHHmmssSSS" timezone="GMT"/>
         </tstamp>
         <!-- Copy static resource files -->
         <filter token="VERSION" value="${version}"/>
@@ -152,7 +183,7 @@
         <filter token="VERSION_NUMBER" value="${version.number}"/>
         <filter token="VERSION_PNAME" value="${final.name}"/>
         <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
-        <filter token="VERSION_STAMP" value="${BSTAMP}"/>
+        <filter token="VERSION_STAMP" value="${build.uuid}"/>
         <copy todir="${build.src}/java" filtering="yes">
             <fileset dir="${src.dir}/main/java">
                 <include name="**/*.java"/>
@@ -198,37 +229,9 @@
       </target>
 
     <!-- =================================================================== -->
-    <!-- Compiles the task directory                                         -->
-    <!-- =================================================================== -->
-    <target name="tasks" depends="compile">
-        <mkdir dir="${build.dest}/ant"/>
-        <mkdir dir="${build.src}/ant"/>
-        <copy todir="${build.src}/ant" filtering="yes">
-            <fileset dir="${src.dir}/ant">
-                <include name="**/*.java"/>
-                <include name="**/*.xml"/>
-                <include name="**/*.properties"/>
-            </fileset>
-        </copy>
-        <javac srcdir="${build.src}/ant"
-            destdir="${build.dest}/ant"
-            debug="${compile.debug}"
-            source="${compile.source}"
-            target="${compile.target}"
-            deprecation="${compile.deprecation}"
-            optimize="${compile.optimize}">
-            <classpath refid="task.classpath"/>
-        </javac>
-        <taskdef name="systemid"
-            classname="org.apache.commons.runtime.SystemIdTask">
-            <classpath refid="task.classpath"/>
-        </taskdef>
-    </target>
-
-    <!-- =================================================================== -->
     <!-- Compiles the examples directory                                     -->
     <!-- =================================================================== -->
-    <target name="examples" depends="tasks">
+    <target name="examples" depends="compile">
         <mkdir dir="${build.dest}"/>
         <mkdir dir="${build.dest}/examples"/>
         <mkdir dir="${build.src}"/>
@@ -273,7 +276,7 @@
     <!-- ================================================================== -->
     <!-- Make the library jar                                               -->
     <!-- ================================================================== -->
-    <target name="jar" depends="tasks"
+    <target name="jar" depends="compile"
         description="Generates the Jar file">
         <systemid prefix="system" />
         <jar
@@ -297,7 +300,7 @@
     <!-- ================================================================== -->
     <!-- Make the native library jar                                        -->
     <!-- ================================================================== -->
-    <target name="native-jar" depends="tasks"
+    <target name="native-jar" depends="compile"
         description="Generates the Jar file">
         <systemid prefix="system" />
         <copy todir="${build.dest}/java/${runtime.attributes.base}/platform/${system.os}">
@@ -330,7 +333,7 @@
     <!-- =================================================================== -->
     <!-- Compiles the test directory                                         -->
     <!-- =================================================================== -->
-    <target name="tests" depends="tasks">
+    <target name="tests" depends="compile">
         <mkdir dir="${build.dest}/test"/>
         <mkdir dir="${build.src}/test"/>
         <copy todir="${build.src}/test" filtering="yes">

Modified: commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/SystemIdTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/SystemIdTask.java?rev=817991&r1=817990&r2=817991&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/SystemIdTask.java (original)
+++ commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/SystemIdTask.java Wed Sep 23 07:28:11 2009
@@ -1,14 +1,131 @@
-
-
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.commons.runtime;
 
+import java.util.Properties;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 
+/**
+ * Apache Ant task for setting the {@code SystemId} properties.
+ * <p>
+ * The task is used in {@code build.xml} for setting the same
+ * names later used for extracting the native libraries.
+ * </p>
+ */
 public class SystemIdTask extends Task
 {
-    private String prefix;
+    private String            prefix;
+    private static Properties props;
+
+    static {
+        props = System.getProperties();
+    }
+
+    /* Copy of the {@code SystemId.getSysname} method.
+     * Make sure those methods are in sync!
+     */
+    private static String getSysname() {
+        String name = props.getProperty("os.name");
+        String platform = "unknown";
+
+        if (name.startsWith("Windows"))
+            platform = "windows";
+        else if (name.startsWith("Mac OS"))
+            platform = "darwin";
+        else if (name.endsWith("BSD"))
+            platform = "bsd";
+        else if (name.equals("Linux"))
+            platform = "linux";
+        else if (name.equals("Solaris"))
+            platform = "solaris";
+        else if (name.equals("SunOS"))
+            platform = "solaris";
+        else if (name.equals("HP-UX"))
+            platform = "hpux";
+        else if (name.equals("AIX"))
+            platform = "aix";
+
+        return platform;
+    }
+
+    /* Copy of the {@code SystemId.getProcessor} method.
+     * Make sure those methods are in sync!
+     */
+    private static String getProcessor()
+    {
+        String cpu;
+        String name = props.getProperty("os.name");
+        String arch = props.getProperty("os.arch");
+        String data = props.getProperty("sun.arch.data.model");
+
+        if (data == null) {
+            data = props.getProperty("com.ibm.vm.bitmode");
+        }
+        if (data == null) {
+            data = "32";
+        }
+        if (arch.endsWith("86")) {
+            cpu = "x86";
+            if (name.startsWith("Mac OS")) {
+                if (data.equals("64"))
+                    cpu = "x86_64";
+            }
+        }
+        else if (arch.startsWith("PA_RISC"))
+            cpu = "parisc" + data;
+        else if (arch.startsWith("IA64"))
+            cpu = "ia64";
+        else if (arch.startsWith("sparc"))
+            cpu = "sparc" + data;
+        else if (arch.equals("amd64"))
+            cpu = "x86_64";
+        else
+            cpu = arch;
+        return cpu;
+    }
+
+    /* Copy of the {@code SystemId.getSoExtension} method.
+     * Make sure those methods are in sync!
+     */
+    private static String getSoExtension()
+    {
+        String sys = getSysname();
+        String ext;
+
+        if (sys.equals("windows")) {
+            ext = "dll";
+        }
+        else if (sys.equals("darwin")) {
+            ext = "jnilib";
+        }
+        else if (sys.equals("hpux")) {
+            if (getProcessor().startsWith("parisc"))
+                ext = "sl";
+            else
+                ext = "so";
+        }
+        else {
+            ext = "so";
+        }
+        /* TODO: Check if this matches the System.mapLibraryName()
+         */
+        return ext;
+    }
 
     public void setPrefix(String prefix)
     {
@@ -19,10 +136,10 @@
         throws BuildException
     {
         if (prefix == null)
-            throw new BuildException("Missing system prefix");
-        getProject().setNewProperty(prefix + ".so",  SystemId.getSoExtension());
-        getProject().setNewProperty(prefix + ".cpu", SystemId.getProcessor());
-        getProject().setNewProperty(prefix + ".os",  SystemId.getSysname());        
+            throw new BuildException("Missing prefix attribute");
+        getProject().setNewProperty(prefix + ".so",  getSoExtension());
+        getProject().setNewProperty(prefix + ".cpu", getProcessor());
+        getProject().setNewProperty(prefix + ".os",  getSysname());
     }
 
 }

Added: commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java?rev=817991&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java (added)
+++ commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java Wed Sep 23 07:28:11 2009
@@ -0,0 +1,78 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.runtime;
+
+import java.util.Random;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+/**
+ * Apache Ant task for setting the {@code UUID} property.
+ */
+public class UuidTask extends Task
+{
+    private String property;
+
+    public void setProperty(String property)
+    {
+        this.property = property;
+    }
+
+    private String hex(byte val)
+    {
+        String h = Integer.toHexString(val);
+        if (h.length() == 1)
+            h = "0" + h;
+        return h.substring(h.length() - 2);
+    }
+
+    public void execute()
+        throws BuildException
+    {
+        if (property == null)
+            throw new BuildException("Missing property attribute");
+        byte [] uuid  = new byte[16];
+        Random random = new Random(System.currentTimeMillis());
+        random.nextBytes(uuid);
+
+        // "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
+        StringBuffer sb = new StringBuffer();
+        sb.append(hex(uuid[0]));
+        sb.append(hex(uuid[1]));
+        sb.append(hex(uuid[2]));
+        sb.append(hex(uuid[3]));
+        sb.append('-');
+        sb.append(hex(uuid[4]));
+        sb.append(hex(uuid[5]));
+        sb.append('-');
+        sb.append(hex(uuid[6]));
+        sb.append(hex(uuid[7]));
+        sb.append('-');
+        sb.append(hex(uuid[8]));
+        sb.append(hex(uuid[9]));
+        sb.append('-');
+        sb.append(hex(uuid[10]));
+        sb.append(hex(uuid[11]));
+        sb.append(hex(uuid[12]));
+        sb.append(hex(uuid[13]));
+        sb.append(hex(uuid[14]));
+        sb.append(hex(uuid[15]));
+
+        getProject().setNewProperty(property,  sb.toString());
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/ant/org/apache/commons/runtime/UuidTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties?rev=817991&r1=817990&r2=817991&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties Wed Sep 23 07:28:11 2009
@@ -29,7 +29,7 @@
 runtime.version.minor = @VERSION_MINOR@
 runtime.version.patch = @VERSION_PATCH@
 runtime.version.pname = @VERSION_PNAME@
-# Build stamp.
+# Build UUID.
 runtime.version.build = @VERSION_STAMP@
 
 # Indicates the caching policy for lookups on cpu object.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java?rev=817991&r1=817990&r2=817991&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java Wed Sep 23 07:28:11 2009
@@ -18,10 +18,8 @@
 
 import org.apache.commons.runtime.exception.UnsupportedOperatingSystemException;
 import org.apache.commons.runtime.util.Utils;
-import org.apache.commons.runtime.util.UUID;
 import java.io.File;
 import java.io.IOException;
-import java.security.MessageDigest;
 import java.util.HashMap;
 
 /**
@@ -58,16 +56,7 @@
             if (path == null) {
                 try {
                     if (SystemId.getSysname().equals("windows")) {
-                        String acr;
-                        try {
-                            MessageDigest md = MessageDigest.getInstance("MD5");
-                            String sig = Properties.VERSION_BUILD + SystemId.getProcessor();
-                            md.update(sig.getBytes());
-                            UUID uuid = new UUID(md.digest());
-                            acr = "_acr-" + uuid.toString();
-                        } catch (Exception ex) {
-                            acr = "_acr-" + Properties.VERSION_BUILD;
-                        }
+                        String acr = "_acr-" + Properties.VERSION_BUILD;
                         path = new File(Utils.getTempPath(), acr);
                         if (path.mkdir()) {
                             /* Delete on exit will work only if library load
@@ -78,7 +67,7 @@
                         }
                     }
                     else {
-                        path = Utils.createTempDirectory("loader-");
+                        path = Utils.createTempDirectory("_acr-");
                         path.deleteOnExit();
                     }
                 } catch (Exception io) {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java?rev=817991&r1=817990&r2=817991&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java Wed Sep 23 07:28:11 2009
@@ -197,7 +197,7 @@
     /** Product name of the runtime library
      */
     public static final String   VERSION_PNAME = getS("runtime.version.pname");
-    /** Build timestamp
+    /** Build UUID
      */
     public static final String   VERSION_BUILD = getS("runtime.version.build");