commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang project.xml
Date Fri, 12 Nov 2004 00:48:42 GMT
scolebourne    2004/11/11 16:48:41

  Modified:    lang/src/java/org/apache/commons/lang SystemUtils.java
               lang/src/test/org/apache/commons/lang SystemUtilsTest.java
               lang     project.xml
  Log:
  Handle Java version with text prefix, as found on HP-UX
  bug 32123, from Jason Gritman
  
  Revision  Changes    Path
  1.38      +48 -16    jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java
  
  Index: SystemUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- SystemUtils.java	6 Nov 2004 01:27:59 -0000	1.37
  +++ SystemUtils.java	12 Nov 2004 00:48:41 -0000	1.38
  @@ -32,6 +32,7 @@
    * @author Michael Becke
    * @author Tetsuya Kaneuchi
    * @author Rafal Krupinski
  + * @author Jason Gritman
    * @since 1.0
    * @version $Id$
    */
  @@ -782,9 +783,23 @@
   
       // Java version
       //-----------------------------------------------------------------------
  -    // These MUST be declared after those above as they depend on the
  +    // This MUST be declared after those above as it depends on the
       // values being set up
  -    
  +
  +    /**
  +     * <p>Gets the Java version as a <code>String</code> trimming leading
letters.</p>
  +     *
  +     * <p>The field will return <code>null</code> if {@link #JAVA_VERSION}
is <code>null</code>.</p>
  +     * 
  +     * @since 2.1
  +     */
  +    public static final String JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
  +
  +    // Java version values
  +    //-----------------------------------------------------------------------
  +    // These MUST be declared after the trim above as they depend on the
  +    // value being set up
  +
       /**
        * <p>Gets the Java version as a <code>float</code>.</p>
        *
  @@ -1086,17 +1101,17 @@
        * </ul>
        * 
        * <p>Patch releases are not reported.
  -     * Zero is returned if {@link #JAVA_VERSION} is <code>null</code>.</p>
  +     * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
        * 
        * @return the version, for example 1.31f for JDK 1.3.1
        */
       private static float getJavaVersionAsFloat() {
  -        if (JAVA_VERSION == null) {
  +        if (JAVA_VERSION_TRIMMED == null) {
               return 0f;
           }
  -        String str = JAVA_VERSION.substring(0, 3);
  -        if (JAVA_VERSION.length() >= 5) {
  -            str = str + JAVA_VERSION.substring(4, 5);
  +        String str = JAVA_VERSION_TRIMMED.substring(0, 3);
  +        if (JAVA_VERSION_TRIMMED.length() >= 5) {
  +            str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
           }
           return Float.parseFloat(str);
       }
  @@ -1111,18 +1126,18 @@
        * </ul>
        * 
        * <p>Patch releases are not reported.
  -     * Zero is returned if {@link #JAVA_VERSION} is <code>null</code>.</p>
  +     * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
        * 
        * @return the version, for example 131 for JDK 1.3.1
        */
       private static int getJavaVersionAsInt() {
  -        if (JAVA_VERSION == null) {
  +        if (JAVA_VERSION_TRIMMED == null) {
               return 0;
           }
  -        String str = JAVA_VERSION.substring(0, 1);
  -        str = str + JAVA_VERSION.substring(2, 3);
  -        if (JAVA_VERSION.length() >= 5) {
  -            str = str + JAVA_VERSION.substring(4, 5);
  +        String str = JAVA_VERSION_TRIMMED.substring(0, 1);
  +        str = str + JAVA_VERSION_TRIMMED.substring(2, 3);
  +        if (JAVA_VERSION_TRIMMED.length() >= 5) {
  +            str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
           } else {
               str = str + "0";
           }
  @@ -1130,16 +1145,33 @@
       }
   
       /**
  +     * Trims the text of the java version to start with numbers.
  +     * 
  +     * @return the trimmed java version
  +     */
  +    private static String getJavaVersionTrimmed() {
  +        if (JAVA_VERSION != null) {
  +            for (int i = 0; i < JAVA_VERSION.length(); i++) {
  +                char ch = JAVA_VERSION.charAt(i);
  +                if (ch >= '0' && ch <= '9') {
  +                    return JAVA_VERSION.substring(i);
  +                }
  +            }
  +        }
  +        return null;
  +    }
  +
  +    /**
        * <p>Decides if the java version matches.</p>
        * 
        * @param versionPrefix  the prefix for the java version
        * @return true if matches, or false if not or can't determine
        */
       private static boolean getJavaVersionMatches(String versionPrefix) {
  -        if (JAVA_VERSION == null) {
  +        if (JAVA_VERSION_TRIMMED == null) {
               return false;
           }
  -        return JAVA_VERSION.startsWith(versionPrefix);
  +        return JAVA_VERSION_TRIMMED.startsWith(versionPrefix);
       }    
       
       /**
  
  
  
  1.11      +77 -35    jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java
  
  Index: SystemUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SystemUtilsTest.java	25 Feb 2004 00:25:29 -0000	1.10
  +++ SystemUtilsTest.java	12 Nov 2004 00:48:41 -0000	1.11
  @@ -51,6 +51,8 @@
       //-----------------------------------------------------------------------
       private String JAVA_VERSION;
   
  +    private String JAVA_VERSION_TRIMMED;
  +
       private String OS_NAME;
   
       private String OS_VERSION;
  @@ -60,51 +62,41 @@
       }
   
       /**
  -     * <p>
  -     * Get the Java version number as a <code>float</code>.
  -     * </p>
  -     * 
  -     * <p>
  -     * Example output:
  -     * </p>
  +     * <p>Gets the Java version number as a <code>float</code>.</p>
  +     *
  +     * <p>Example return values:</p>
        * <ul>
  -     * <li><code>1.2f</code> for JDK 1.2
  -     * <li><code>1.31f</code> for JDK 1.3.1
  +     *  <li><code>1.2f</code> for JDK 1.2
  +     *  <li><code>1.31f</code> for JDK 1.3.1
        * </ul>
        * 
  -     * <p>
  -     * Patch releases are not reported. Zero is returned if JAVA_VERSION is <code>null</code>.
  -     * </p>
  +     * <p>Patch releases are not reported.
  +     * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
        * 
        * @return the version, for example 1.31f for JDK 1.3.1
        */
       private float getJavaVersionAsFloat() {
  -        if (JAVA_VERSION == null) {
  +        if (JAVA_VERSION_TRIMMED == null) {
               return 0f;
           }
  -        String str = JAVA_VERSION.substring(0, 3);
  -        if (JAVA_VERSION.length() >= 5) {
  -            str = str + JAVA_VERSION.substring(4, 5);
  +        String str = JAVA_VERSION_TRIMMED.substring(0, 3);
  +        if (JAVA_VERSION_TRIMMED.length() >= 5) {
  +            str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
           }
           return Float.parseFloat(str);
       }
   
       /**
  -     * <p>
  -     * Get the Java version number as an <code>int</code>.
  -     * </p>
  -     * 
  -     * <p>
  -     * Example output:
  -     * </p>
  +     * <p>Gets the Java version number as an <code>int</code>.</p>
  +     *
  +     * <p>Example return values:</p>
        * <ul>
  -     * <li><code>120</code> for JDK 1.2
  -     * <li><code>131</code> for JDK 1.3.1
  +     *  <li><code>120</code> for JDK 1.2
  +     *  <li><code>131</code> for JDK 1.3.1
        * </ul>
        * 
  -     * <p>
  -     * Patch releases are not reported. Zero is returned if JAVA_VERSION is <code>null</code>.
  -     * </p>
  +     * <p>Patch releases are not reported.
  +     * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
        * 
        * @return the version, for example 131 for JDK 1.3.1
        */
  @@ -112,10 +104,10 @@
           if (JAVA_VERSION == null) {
               return 0;
           }
  -        String str = JAVA_VERSION.substring(0, 1);
  -        str = str + JAVA_VERSION.substring(2, 3);
  -        if (JAVA_VERSION.length() >= 5) {
  -            str = str + JAVA_VERSION.substring(4, 5);
  +        String str = JAVA_VERSION_TRIMMED.substring(0, 1);
  +        str = str + JAVA_VERSION_TRIMMED.substring(2, 3);
  +        if (JAVA_VERSION_TRIMMED.length() >= 5) {
  +            str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
           } else {
               str = str + "0";
           }
  @@ -123,6 +115,23 @@
       }
   
       /**
  +     * Trims the text of the java version to start with numbers.
  +     * 
  +     * @return the trimmed java version
  +     */
  +    private String getJavaVersionTrimmed() {
  +        if (JAVA_VERSION != null) {
  +            for (int i = 0; i < JAVA_VERSION.length(); i++) {
  +                char ch = JAVA_VERSION.charAt(i);
  +                if (ch >= '0' && ch <= '9') {
  +                    return JAVA_VERSION.substring(i);
  +                }
  +            }
  +        }
  +        return null;
  +    }
  +
  +    /**
        * Decides if the java version matches.
        * 
        * @param versionPrefix
  @@ -130,10 +139,10 @@
        * @return true if matches, or false if not or can't determine
        */
       private boolean getJavaVersionMatches(String versionPrefix) {
  -        if (JAVA_VERSION == null) {
  +        if (JAVA_VERSION_TRIMMED == null) {
               return false;
           }
  -        return JAVA_VERSION.startsWith(versionPrefix);
  +        return JAVA_VERSION_TRIMMED.startsWith(versionPrefix);
       }
   
       /**
  @@ -286,44 +295,68 @@
   
       public void testJavaVersionAsFloat() {
           JAVA_VERSION = null;
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(0f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.1f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.2";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.2f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.3.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.3f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.3.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.4.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.4f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.4.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.41f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.5.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.5f, getJavaVersionAsFloat(), 0.000001f);
           JAVA_VERSION = "1.6.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(1.6f, getJavaVersionAsFloat(), 0.000001f);
  +        JAVA_VERSION = "JavaVM-1.3.1";  //HP-UX
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
  +        assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
       }
   
       public void testJavaVersionAsInt() {
           JAVA_VERSION = null;
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(0, getJavaVersionAsInt());
           JAVA_VERSION = "1.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(110, getJavaVersionAsInt());
           JAVA_VERSION = "1.2";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(120, getJavaVersionAsInt());
           JAVA_VERSION = "1.3.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(130, getJavaVersionAsInt());
           JAVA_VERSION = "1.3.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(131, getJavaVersionAsInt());
           JAVA_VERSION = "1.4.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(140, getJavaVersionAsInt());
           JAVA_VERSION = "1.4.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(141, getJavaVersionAsInt());
           JAVA_VERSION = "1.5.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(150, getJavaVersionAsInt());
           JAVA_VERSION = "1.6.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(160, getJavaVersionAsInt());
  +        JAVA_VERSION = "JavaVM-1.3.1";  //HP-UX
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
  +        assertEquals(131, getJavaVersionAsInt());
       }
   
       public void testJavaVersionAtLeastFloat() {
  @@ -347,54 +380,63 @@
       //-----------------------------------------------------------------------
       public void testJavaVersionMatches() {
           JAVA_VERSION = null;
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(true, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.2";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(true, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.3.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(true, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.3.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(true, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.4.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(true, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.4.1";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(true, getJavaVersionMatches("1.4"));
           assertEquals(false, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.5.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
           assertEquals(false, getJavaVersionMatches("1.4"));
           assertEquals(true, getJavaVersionMatches("1.5"));
           JAVA_VERSION = "1.6.0";
  +        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
           assertEquals(false, getJavaVersionMatches("1.1"));
           assertEquals(false, getJavaVersionMatches("1.2"));
           assertEquals(false, getJavaVersionMatches("1.3"));
  
  
  
  1.37      +3 -0      jakarta-commons/lang/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/project.xml,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- project.xml	13 Jul 2004 12:46:02 -0000	1.36
  +++ project.xml	12 Nov 2004 00:48:41 -0000	1.37
  @@ -222,6 +222,9 @@
         <name>Pete Gieser</name>
       </contributor>
       <contributor>
  +      <name>Jason Gritman</name>
  +    </contributor>
  +    <contributor>
         <name>Matthew Hawthorne</name>
       </contributor>
       <contributor>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message