Author: hindessm
Date: Mon Jun 15 12:14:13 2009
New Revision: 784747
URL: http://svn.apache.org/viewvc?rev=784747&view=rev
Log:
Reverting r782693 - which reverted r763589 - which was:
Commit Version class to handle -version command line option in a uniform
way across VMs (as discussed on the dev list).
Added:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java
(with props)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
Added:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java
URL:
http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java?rev=784747&view=auto
==============================================================================
---
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java
(added)
+++
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java
Mon Jun 15 12:14:13 2009
@@ -0,0 +1,103 @@
+/*
+ * 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.harmony.luni.util;
+
+import java.util.StringTokenizer;
+import java.util.Iterator;
+import java.util.jar.*;
+import java.io.IOException;
+
+class Version {
+ /*
+ * Display VM and runtime version information
+ */
+ private static void displayVMVersion() {
+ String version = System.getProperty("java.version");
+ if (version != null) System.out.println("java version \"" + version +
"\"");
+
+ String name = System.getProperty("java.runtime.name");
+ version = System.getProperty("java.runtime.version");
+
+ if (name != null) {
+ if (version != null) name = name + " (" + version + ")";
+ System.out.println(name);
+ }
+
+ name = System.getProperty("java.vm.name");
+ version = System.getProperty("java.vm.version");
+ if (name != null) {
+ if (version != null) name = name + " (" + version + ")";
+ System.out.println(name);
+ }
+
+ name = System.getProperty("java.fullversion");
+ if (name != null) System.out.println(name);
+ }
+
+ /*
+ * Display extended class library version information
+ */
+ private static void displayClasslibVersion() {
+ // Get the bootclasspath and tokenise for each jar file
+ String bootclasspath =
System.getProperty("org.apache.harmony.boot.class.path");
+ if (bootclasspath == null) return;
+
+ StringTokenizer tokenizer = new StringTokenizer(bootclasspath,
System.getProperty("path.separator"));
+
+ while (tokenizer.hasMoreTokens()) {
+ String jarPath = tokenizer.nextToken();
+
+ // If the current path is not a jar file, then continue iteration
through tokens
+ if (!jarPath.endsWith(".jar")) continue;
+
+ // Get the jar manifest and find it's name and version info
+ JarFile jarFile;
+ Manifest manifest;
+ try {
+ jarFile = new JarFile(jarPath);
+ manifest = jarFile.getManifest();
+ } catch (IOException e) {
+ // We have hit an exception - just carry onto the next jar file
+ continue;
+ }
+
+ // Get the manifest attributes and output those we are interested
in
+ Attributes attributes = manifest.getMainAttributes();
+ if (attributes == null) continue;
+
+ String bundleName = attributes.getValue("Bundle-Name");
+ if (bundleName == null) continue;
+ String bundleVersion = attributes.getValue("Bundle-Version");
+ if (bundleVersion == null) continue;
+
+ System.out.println(jarPath + " " + bundleName + " " +
bundleVersion);
+ }
+
+ }
+
+ public static void version(String versionOpt) {
+ if (versionOpt.equals("-version")) {
+ displayVMVersion();
+ } else if (versionOpt.equals("-version:extended")) {
+ displayVMVersion();
+ displayClasslibVersion();
+ } else {
+ System.out.println("Option " + versionOpt + " unrecognised - please use
-version or -version:extended");
+ }
+ }
+}
Propchange:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Version.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
URL:
http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c?rev=784747&r1=784746&r2=784747&view=diff
==============================================================================
---
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
(original)
+++
harmony/enhanced/classlib/trunk/modules/luni/src/main/native/launcher/shared/main.c
Mon Jun 15 12:14:13 2009
@@ -58,7 +58,7 @@
PROTOTYPE ((HyPortLibrary * portLibrary, int argc, char **argv, UDATA handle,
jint version, jboolean ignoreUnrecognized, char *mainClass,
UDATA classArg, char *propertiesFileName,
- int isStandaloneJar, char *vmdllsubdir));
+ int isStandaloneJar, char *vmdllsubdir, int versionFlag));
static int createVMArgs
PROTOTYPE ((HyPortLibrary * portLibrary, int argc, char **argv,
jint version, jboolean ignoreUnrecognized,
@@ -227,8 +227,9 @@
/* The arg is a JAR file to run */
isStandaloneJar = 1;
}
- if (0 == strcmp ("-version", argv[i])) {
- versionFlag = 1;
+ if (0 == strncmp ("-version", argv[i], 8)) {
+ /* Display version information */
+ versionFlag = i;
}
if (0 == strcmp ("-showversion", argv[i])) {
/* We are being asked to print our version and continue
*/
@@ -363,12 +364,6 @@
}
}
- if (versionFlag == 1) {
- /*
- * We are being asked to print our version, and quit
- */
- hyfile_printf (PORTLIB, HYPORT_TTY_OUT, HY_COPYRIGHT_STRING "\n");
- }
/* set up the properties file */
propertiesFileName = hymem_allocate_memory (strlen (vmiPath) + 12);
if (propertiesFileName == NULL)
@@ -392,7 +387,7 @@
/* main launcher processing in this function */
rc = invocation
(PORTLIB, argc, argv, handle, JNI_VERSION_1_4, JNI_TRUE, mainClass,
- classArg, propertiesFileName, isStandaloneJar, vmdllsubdir);
+ classArg, propertiesFileName, isStandaloneJar, vmdllsubdir,
versionFlag);
if (rc)
{
/* Print an error message except in the case where an uncaught Exception
@@ -642,7 +637,7 @@
invocation (HyPortLibrary * portLibrary, int argc, char **argv, UDATA handle,
jint version, jboolean ignoreUnrecognized, char *mainClass,
UDATA classArg, char *propertiesFileName,
- int isStandaloneJar, char *vmdllsubdir)
+ int isStandaloneJar, char *vmdllsubdir, int versionFlag)
{
JavaVMInitArgs vm_args;
JavaVM *jvm;
@@ -678,6 +673,27 @@
}
rc = 0;
+
+ if (versionFlag) {
+ jclass clazz;
+ jmethodID mID;
+ jstring jStrObject;
+
+ jStrObject = (*env)->NewStringUTF (env, argv[versionFlag]);
+ if (!jStrObject) return 3;
+
+ clazz = (*env)->FindClass (env, "org/apache/harmony/luni/util/Version");
+ if (!clazz) return 3;
+
+ mID = (*env)->GetStaticMethodID (env, clazz, "version",
+ "(Ljava/lang/String;)V");
+ if (!mID) return 3;
+
+ (*env)->CallStaticVoidMethod(env, clazz, mID, jStrObject);
+
+ return 0;
+ }
+
if (mainClass)
{
if (isStandaloneJar)
@@ -952,7 +968,8 @@
{
if ( (strcmp (argv[i], "-jar") != 0)
&& (strncmp (argv[i], "-vmdir:", 7) != 0)
- && (strncmp (argv[i], "-vm:", 4) != 0) )
+ && (strncmp (argv[i], "-vm:", 4) != 0)
+ && (strncmp (argv[i], "-version", 8) != 0))
{
/* special coding for -classpath and -cp */
/* they get passed to the vm as -Djava.class.path */