From 9f59925bbd5dc77ba3ac65f277f7e5810a3ec517 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 10 Nov 2010 16:53:35 +0000 Subject: [PATCH] detect Apache Harmony git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1033587 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/Diagnostics.java | 2 ++ .../apache/tools/ant/util/JavaEnvUtils.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index ecdf7e4ae..5c1be28e4 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -399,6 +399,8 @@ public final class Diagnostics { out.println(MagicNames.ANT_VERSION + ": " + p.getProperty(MagicNames.ANT_VERSION)); out.println(MagicNames.ANT_JAVA_VERSION + ": " + p.getProperty(MagicNames.ANT_JAVA_VERSION)); + out.println("Is this the Apache Harmony VM? " + + (JavaEnvUtils.isApacheHarmony() ? "yes" : "no")); out.println("Is this the Kaffe VM? " + (JavaEnvUtils.isKaffe() ? "yes" : "no")); out.println("Is this gij/gcj? " diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index f34d7a721..5c83a15ce 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -94,6 +94,9 @@ public final class JavaEnvUtils { /** Whether this is the GNU VM (gcj/gij) */ private static boolean gijDetected; + /** Whether this is Apache Harmony */ + private static boolean harmonyDetected; + /** array of packages in the runtime */ private static Vector jrePackages; @@ -147,6 +150,13 @@ public final class JavaEnvUtils { } catch (Throwable t) { // swallow as this simply doesn't seem to be gcj/gij } + harmonyDetected = false; + try { + Class.forName("org.apache.harmony.luni.util.Base64"); + harmonyDetected = true; + } catch (Throwable t) { + // swallow as this simply doesn't seem to be Apache Harmony + } } /** @@ -217,6 +227,15 @@ public final class JavaEnvUtils { return gijDetected; } + /** + * Checks whether the current VM is Apache Harmony. + * @since Ant 1.8.2 + * @return true if the current VM is Apache Harmony. + */ + public static boolean isApacheHarmony() { + return harmonyDetected; + } + /** * Finds an executable that is part of a JRE installation based on * the java.home system property.