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 2011/04/11 23:09:04 UTC
svn commit: r1091215 - in /commons/sandbox/runtime/trunk/src:
build/org/apache/commons/runtime/ant/SystemIdTask.java
main/java/org/apache/commons/runtime/SystemId.java
main/java/org/apache/commons/runtime/util/Utils.java
Author: mturk
Date: Mon Apr 11 21:09:03 2011
New Revision: 1091215
URL: http://svn.apache.org/viewvc?rev=1091215&view=rev
Log:
Catch const properties
Modified:
commons/sandbox/runtime/trunk/src/build/org/apache/commons/runtime/ant/SystemIdTask.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
Modified: commons/sandbox/runtime/trunk/src/build/org/apache/commons/runtime/ant/SystemIdTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/build/org/apache/commons/runtime/ant/SystemIdTask.java?rev=1091215&r1=1091214&r2=1091215&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/build/org/apache/commons/runtime/ant/SystemIdTask.java (original)
+++ commons/sandbox/runtime/trunk/src/build/org/apache/commons/runtime/ant/SystemIdTask.java Mon Apr 11 21:09:03 2011
@@ -36,6 +36,9 @@ public class SystemIdTask extends Task i
private String arch;
private String cpu;
private static Properties props;
+ private static String platform = null;
+ private static String model = null;
+ private static String syscpu = null;
static {
props = System.getProperties();
@@ -46,8 +49,9 @@ public class SystemIdTask extends Task i
*/
private static String getSysname()
{
+ if (platform != null)
+ return platform;
String name = props.getProperty("os.name");
- String platform = "unknown";
if (name.startsWith("Windows"))
platform = "windows";
@@ -65,6 +69,8 @@ public class SystemIdTask extends Task i
platform = "hpux";
else if (name.equals("AIX"))
platform = "aix";
+ else
+ platform = "unknown";
return platform;
}
@@ -74,24 +80,26 @@ public class SystemIdTask extends Task i
*/
private static String getDataModel()
{
- String data = props.getProperty("sun.arch.data.model");
+ if (model != null)
+ return model;
+ model = props.getProperty("sun.arch.data.model");
- if (data == null) {
- data = props.getProperty("com.ibm.vm.bitmode");
+ if (model == null) {
+ model = props.getProperty("com.ibm.vm.bitmode");
}
- if (data == null) {
+ if (model == null) {
String arch = props.getProperty("os.arch");
if (arch.indexOf("64") < 0) {
/* TODO: Investigate other JVM's property for
* figuring the data model (32 or 64)
*/
- data = "32";
+ model = "32";
}
else {
- data = "64";
+ model = "64";
}
}
- return data;
+ return model;
}
/* Copy of the {@code SystemId.getProcessor} method.
@@ -99,43 +107,44 @@ public class SystemIdTask extends Task i
*/
private static String getProcessor()
{
- String cpu;
+ if (syscpu != null)
+ return syscpu;
String name = props.getProperty("os.name");
String arch = props.getProperty("os.arch");
String data = getDataModel();
if (arch.endsWith("86")) {
- cpu = "x86";
+ syscpu = "x86";
if (name.startsWith("Mac OS")) {
if (data.equals("64"))
- cpu = "x86_64";
+ syscpu = "x86_64";
}
}
else if (arch.startsWith("PA_RISC")) {
if (data.equals("64"))
- cpu = "parisc64";
+ syscpu = "parisc64";
else
- cpu = "parisc";
+ syscpu = "parisc";
}
else if (arch.startsWith("IA64"))
- cpu = "ia64";
+ syscpu = "ia64";
else if (arch.startsWith("sparc")) {
if (data.equals("64"))
- cpu = "sparc64";
+ syscpu = "sparc64";
else
- cpu = "sparc";
+ syscpu = "sparc";
}
else if (arch.startsWith("ppc")) {
if (data.equals("64"))
- cpu = "ppc64";
+ syscpu = "ppc64";
else
- cpu = "ppc";
+ syscpu = "ppc";
}
else if (arch.equals("amd64"))
- cpu = "x86_64";
+ syscpu = "x86_64";
else
- cpu = arch;
- return cpu;
+ syscpu = arch;
+ return syscpu;
}
/* Copy of the {@code SystemId.getSoExtension} method.
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java?rev=1091215&r1=1091214&r2=1091215&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/SystemId.java Mon Apr 11 21:09:03 2011
@@ -34,6 +34,11 @@ public final class SystemId
{
private static Properties props;
+ private static String sys = null;
+ private static String cpu = null;
+ private static String ext = null;
+ private static String sdm = null;
+ private static int pid = 0;
private SystemId() {
// No instance
}
@@ -49,27 +54,30 @@ public final class SystemId
*/
public static String getSysname()
{
+ if (sys != null)
+ return sys;
String name = props.getProperty("os.name");
- String platform = "unknown";
if (name.startsWith("Windows"))
- platform = "windows";
+ sys = "windows";
else if (name.startsWith("Mac OS"))
- platform = "darwin";
+ sys = "darwin";
else if (name.endsWith("BSD"))
- platform = "bsd";
+ sys = "bsd";
else if (name.equals("Linux"))
- platform = "linux";
+ sys = "linux";
else if (name.equals("Solaris"))
- platform = "solaris";
+ sys = "solaris";
else if (name.equals("SunOS"))
- platform = "solaris";
+ sys = "solaris";
else if (name.equals("HP-UX"))
- platform = "hpux";
+ sys = "hpux";
else if (name.equals("AIX"))
- platform = "aix";
+ sys = "aix";
+ else
+ sys = "unknown";
- return platform;
+ return sys;
}
/**
@@ -79,24 +87,26 @@ public final class SystemId
*/
public static String getDataModel()
{
- String data = props.getProperty("sun.arch.data.model");
+ if (sdm != null)
+ return sdm;
+ sdm = props.getProperty("sun.arch.data.model");
- if (data == null) {
- data = props.getProperty("com.ibm.vm.bitmode");
+ if (sdm == null) {
+ sdm = props.getProperty("com.ibm.vm.bitmode");
}
- if (data == null) {
+ if (sdm == null) {
String arch = props.getProperty("os.arch");
if (arch.indexOf("64") < 0) {
/* TODO: Investigate other JVM's property for
* figuring the data model (32 or 64)
*/
- data = "32";
+ sdm = "32";
}
else {
- data = "64";
+ sdm = "64";
}
}
- return data;
+ return sdm;
}
/**
@@ -106,20 +116,21 @@ public final class SystemId
*/
public static String getProcessor()
{
- String cpu;
- String name = props.getProperty("os.name");
+ if (cpu != null)
+ return cpu;
String arch = props.getProperty("os.arch");
- String data = getDataModel();
+ getSysname();
+ getDataModel();
if (arch.endsWith("86")) {
cpu = "x86";
- if (name.startsWith("Mac OS")) {
- if (data.equals("64"))
+ if (sys.equals("darwin")) {
+ if (sdm.equals("64"))
cpu = "x86_64";
}
}
else if (arch.startsWith("PA_RISC")) {
- if (data.equals("64"))
+ if (sdm.equals("64"))
cpu = "parisc64";
else
cpu = "parisc";
@@ -127,13 +138,13 @@ public final class SystemId
else if (arch.startsWith("IA64"))
cpu = "ia64";
else if (arch.startsWith("sparc")) {
- if (data.equals("64"))
+ if (sdm.equals("64"))
cpu = "sparc64";
else
cpu = "sparc";
}
else if (arch.startsWith("ppc")) {
- if (data.equals("64"))
+ if (sdm.equals("64"))
cpu = "ppc64";
else
cpu = "ppc";
@@ -147,9 +158,10 @@ public final class SystemId
private static int platformId()
{
- String sys = getSysname();
- String cpu = getProcessor();
- int pid = 0;
+ if (pid != 0)
+ return pid;
+ getSysname();
+ getProcessor();
if (sys.equals("windows")) {
if (cpu.equals("x86"))
@@ -219,8 +231,9 @@ public final class SystemId
*/
public static String getSoExtension()
{
- String sys = getSysname();
- String ext;
+ if (ext != null)
+ return ext;
+ getSysname();
if (sys.equals("windows")) {
ext = "dll";
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java?rev=1091215&r1=1091214&r2=1091215&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Utils.java Mon Apr 11 21:09:03 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.File;
import java.io.PrintStream;
import java.util.Random;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.runtime.SystemId;
/**
@@ -35,11 +36,11 @@ public final class Utils
// Private to prevent creation.
}
- private static long counter = 1024L;
- private static long timer = System.currentTimeMillis();
- private static Random rnd = new Random(timer);
- private static File tmpdir = null;
- private static Object lock = new Object();
+ private static AtomicLong counter = new AtomicLong(1024L);
+ private static long timer = System.currentTimeMillis();
+ private static Random rnd = new Random(timer);
+ private static File tmpdir = null;
+ private static Object lock = new Object();
private static final char[] hc = {
'0', '1', '2', '3', '4', '5', '6', '7',
@@ -51,11 +52,7 @@ public final class Utils
*/
public static long Id()
{
- long id;
- synchronized (Utils.class) {
- id = counter++;
- }
- return id;
+ return counter.incrementAndGet();
}
public static void generateRandom(byte[] dst)