You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Oliver Deakin <ol...@googlemail.com> on 2009/06/15 17:36:13 UTC

Re: svn commit: r784747 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/util/Version.java native/launcher/shared/main.c

Thanks Mark - just back from holiday now and catching up on mail. I've 
just committed (r784811) a further patch so -version gives us the 
correct copyright and revision number info. It also moves the handling 
of -showversion (and -showversion:extended) to the Version class. You 
should now see:

 >java -version
 Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software 
Foundation or its licensors, as applicable.
 java version "1.5.0"
 Apache Harmony (1.5.0)
 DRLVM (11.2.0)
 pre-alpha : not complete or compatible
 svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
 http://harmony.apache.org

 >java -showversion HelloWorld
 Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software 
Foundation or its licensors, as applicable.
 java version "1.5.0"
 Apache Harmony (1.5.0)
 DRLVM (11.2.0)
 pre-alpha : not complete or compatible
 svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
 http://harmony.apache.org
 Hello World!

which I think looks about right, if a little verbose. The :extended 
option gives the full classlib module breakdowns, and works with both 
-version and -showversion.
What do you think?

Regards,
Oliver

hindessm@apache.org wrote:
> 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 */
>
>
>
>   

-- 
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Re: svn commit: r784747 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/util/Version.java native/launcher/shared/main.c

Posted by sebb <se...@gmail.com>.
On 15/06/2009, Mark Hindess <ma...@googlemail.com> wrote:
>
>  In message <4A...@googlemail.com>, Oliver Deakin writes:
>  >
>  > Thanks Mark - just back from holiday now and catching up on mail. I've
>  > just committed (r784811) a further patch so -version gives us the
>  > correct copyright and revision number info. It also moves the handling
>  > of -showversion (and -showversion:extended) to the Version class. You
>  > should now see:
>  >
>  >  >java -version
>  >  Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software
>  > Foundation or its licensors, as applicable.
>  >  java version "1.5.0"
>  >  Apache Harmony (1.5.0)
>  >  DRLVM (11.2.0)
>  >  pre-alpha : not complete or compatible
>  >  svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
>  >  http://harmony.apache.org
>  >
>  >  >java -showversion HelloWorld
>  >  Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software
>  > Foundation or its licensors, as applicable.
>  >  java version "1.5.0"
>  >  Apache Harmony (1.5.0)
>  >  DRLVM (11.2.0)
>  >  pre-alpha : not complete or compatible
>  >  svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
>  >  http://harmony.apache.org
>  >  Hello World!
>  >
>  > which I think looks about right, if a little verbose. The :extended
>  > option gives the full classlib module breakdowns, and works with both
>  > -version and -showversion.
>  > What do you think?
>
>
> Excellent.  I've added some trivial checks in r784993 to try to make
>  sure we don't break it again.
>
>  One thing I wondered about while trying to fix this for M10 was that it
>  would be nice if it actually said "Milestone 10" in the "java -version"
>  output (probably as well as the svn revision).

Good idea; it would be nice if the "java.version" and
"java.runtime.version" properties also included the build details, as
is done for the Sun JVM, for example:

java.runtime.version=1.5.0_18-b02
java.version=1.5.0_18

>  Regards,
>
>  Mark
>
>
>

Re: svn commit: r784747 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/util/Version.java native/launcher/shared/main.c

Posted by Mark Hindess <ma...@googlemail.com>.
In message <4A...@googlemail.com>, Oliver Deakin writes:
>
> Thanks Mark - just back from holiday now and catching up on mail. I've 
> just committed (r784811) a further patch so -version gives us the 
> correct copyright and revision number info. It also moves the handling 
> of -showversion (and -showversion:extended) to the Version class. You 
> should now see:
> 
>  >java -version
>  Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software 
> Foundation or its licensors, as applicable.
>  java version "1.5.0"
>  Apache Harmony (1.5.0)
>  DRLVM (11.2.0)
>  pre-alpha : not complete or compatible
>  svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
>  http://harmony.apache.org
> 
>  >java -showversion HelloWorld
>  Apache Harmony Launcher : (c) Copyright 1991, 2009 The Apache Software 
> Foundation or its licensors, as applicable.
>  java version "1.5.0"
>  Apache Harmony (1.5.0)
>  DRLVM (11.2.0)
>  pre-alpha : not complete or compatible
>  svn = r784759, (Jun 15 2009), Windows/ia32/msvc 1310, release build
>  http://harmony.apache.org
>  Hello World!
> 
> which I think looks about right, if a little verbose. The :extended 
> option gives the full classlib module breakdowns, and works with both 
> -version and -showversion.
> What do you think?

Excellent.  I've added some trivial checks in r784993 to try to make
sure we don't break it again.

One thing I wondered about while trying to fix this for M10 was that it
would be nice if it actually said "Milestone 10" in the "java -version"
output (probably as well as the svn revision).

Regards,
 Mark