maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r391731 - in /maven/surefire/trunk/surefire-booter/src: main/java/org/apache/maven/surefire/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/maven/ test/java/org/apache/maven/surefire/
Date Wed, 05 Apr 2006 19:17:49 GMT
Author: carlos
Date: Wed Apr  5 12:17:46 2006
New Revision: 391731

URL: http://svn.apache.org/viewcvs?rev=391731&view=rev
Log:
[MSUREFIRE-86] Make surefire booter compile under Java 1.3

Added:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
  (with props)
    maven/surefire/trunk/surefire-booter/src/test/
    maven/surefire/trunk/surefire-booter/src/test/java/
    maven/surefire/trunk/surefire-booter/src/test/java/org/
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/
    maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
  (with props)
Modified:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java

Added: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java?rev=391731&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
(added)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
Wed Apr  5 12:17:46 2006
@@ -0,0 +1,186 @@
+package org.apache.maven.surefire;
+
+/*
+ * Copyright 2002-2005 the original author or authors.
+ * 
+ * Licensed 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.
+ */
+
+/*
+ * Some portions are
+ * 
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+/**
+ * <p>Copied from Spring framework to keep Java 1.3 compatability.</p>
+ * 
+ * <p>Handy class for wrapping checked Exceptions with a root cause.</p>
+ *
+ * <p>This time-honored technique is no longer necessary in Java 1.4, which
+ * finally provides built-in support for exception nesting. Thus exceptions in
+ * applications written to use Java 1.4 need not extend this class. To ease
+ * migration, this class mirrors Java 1.4's nested exceptions as closely as possible.
+ *
+ * <p>Abstract to force the programmer to extend the class. <code>getMessage</code>
+ * will include nested exception information; <code>printStackTrace</code> etc
will
+ * delegate to the wrapped exception, if any.
+ *
+ * <p>The similarity between this class and the NestedRuntimeException class is
+ * unavoidable, as Java forces these two classes to have different superclasses
+ * (ah, the inflexibility of concrete inheritance!).
+ *
+ * <p>As discussed in
+ * <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0764543857/">Expert One-On-One
J2EE Design and Development</a>,
+ * runtime exceptions are often a better alternative to checked exceptions.
+ * However, all exceptions should preserve their stack trace, if caused by a
+ * lower-level exception.
+ *
+ * @author Rod Johnson
+ * @author Juergen Hoeller
+ * @see #getMessage
+ * @see #printStackTrace
+ * @see NestedRuntimeException
+ */
+public class NestedCheckedException extends Exception {
+
+    /** Root cause of this nested exception */
+    private Throwable cause;
+
+
+    /**
+     * Construct a <code>NestedCheckedException</code> with the specified detail
message.
+     * @param msg the detail message
+     */
+    public NestedCheckedException(String msg) {
+        super(msg);
+    }
+
+    /**
+     * Construct a <code>NestedCheckedException</code> with the specified detail
message
+     * and nested exception.
+     * @param msg the detail message
+     * @param ex the nested exception
+     */
+    public NestedCheckedException(String msg, Throwable ex) {
+        super(msg);
+        this.cause = ex;
+    }
+
+    /**
+     * Construct a <code>NestedCheckedException</code> with the specified nested
exception.
+     * @param ex the nested exception
+     */
+    public NestedCheckedException(Throwable ex) {
+        super();
+        this.cause = ex;
+    }
+
+    /**
+     * Return the nested cause, or <code>null</code> if none.
+     */
+    public Throwable getCause() {
+        // Even if you cannot set the cause of this exception other than through
+        // the constructor, we check for the cause being "this" here, as the cause
+        // could still be set to "this" via reflection: for example, by a remoting
+        // deserializer like Hessian's.
+        return (this.cause == this ? null : this.cause);
+    }
+
+    /**
+     * Return the detail message, including the message from the nested exception
+     * if there is one.
+     */
+    public String getMessage() {
+        if (getCause() == null) {
+            return super.getMessage();
+        }
+        else {
+            return super.getMessage() + "; nested exception is " + getCause().getClass().getName()
+
+                    ": " + getCause().getMessage();
+        }
+    }
+
+    /**
+     * Print the composite message and the embedded stack trace to the specified stream.
+     * @param ps the print stream
+     */
+    public void printStackTrace(PrintStream ps) {
+        if (getCause() == null) {
+            super.printStackTrace(ps);
+        }
+        else {
+            ps.println(this);
+            getCause().printStackTrace(ps);
+        }
+    }
+
+    /**
+     * Print the composite message and the embedded stack trace to the specified print writer.
+     * @param pw the print writer
+     */
+    public void printStackTrace(PrintWriter pw) {
+        if (getCause() == null) {
+            super.printStackTrace(pw);
+        }
+        else {
+            pw.println(this);
+            getCause().printStackTrace(pw);
+        }
+    }
+
+    /**
+     * Check whether this exception contains an exception of the given class:
+     * either it is of the given class itself or it contains a nested cause
+     * of the given class.
+     * <p>Currently just traverses NestedCheckedException causes. Will use
+     * the JDK 1.4 exception cause mechanism once Spring requires JDK 1.4.
+     * @param exClass the exception class to look for
+     */
+    public boolean contains(Class exClass) {
+        if (exClass == null) {
+            return false;
+        }
+        Throwable ex = this;
+        while (ex != null) {
+            if (exClass.isInstance(ex)) {
+                return true;
+            }
+            if (ex instanceof NestedCheckedException) {
+                // Cast is necessary on JDK 1.3, where Throwable does not
+                // provide a "getCause" method itself.
+                ex = ((NestedCheckedException) ex).getCause();
+            }
+            else {
+                ex = null;
+            }
+        }
+        return false;
+    }
+
+}

Propchange: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/NestedCheckedException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java?rev=391731&r1=391730&r2=391731&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
Wed Apr  5 12:17:46 2006
@@ -32,7 +32,6 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -288,7 +287,7 @@
         }
         else
         {
-            urls = Arrays.asList( cp.split( PS ) );
+            urls = split( cp, PS );
         }
 
         return createClassLoader( urls, childDelegation );
@@ -420,7 +419,7 @@
         }
         catch ( CommandLineException e )
         {
-            throw new Exception( "Error while executing forked tests.", e );
+            throw new NestedCheckedException( "Error while executing forked tests.", e );
         }
         catch ( Exception e )
         {
@@ -705,15 +704,13 @@
 
         String reports = p.getProperty( "reportClassNames" );
 
-        String[] reportClasses = reports.split( "," );
-
-        List reportList = Arrays.asList( reportClasses );
+        List reportList = split( reports, "," );
 
         String batteryConfig = p.getProperty( "batteryConfig" );
 
-        String[] batteryParts = batteryConfig.split( "\\|" );
+        List batteryParts = split( batteryConfig, "\\|" );
 
-        String batteryClassName = batteryParts[0];
+        String batteryClassName = (String) batteryParts.get( 0 );
 
         Object[] batteryParms;
 
@@ -721,11 +718,11 @@
 
         if ( forkMode.equals( FORK_ONCE ) )
         {
-            batteryParms = new Object[batteryParts.length - 1];
+            batteryParms = new Object[batteryParts.size() - 1];
 
-            batteryParms[0] = new File( batteryParts[1] );
+            batteryParms[0] = new File( (String) batteryParts.get( 1 ) );
 
-            String stringList = batteryParts[2];
+            String stringList = (String) batteryParts.get( 2 );
 
             if ( stringList.startsWith( "[" ) && stringList.endsWith( "]" ) )
             {
@@ -734,16 +731,18 @@
 
             ArrayList includesList = new ArrayList();
 
-            String[] stringArray = stringList.split( "," );
+            List stringArray = split( stringList, "," );
 
-            for ( int i = 0; i < stringArray.length; i++ )
+            Iterator it = stringArray.iterator();
+            while ( it.hasNext() )
             {
-                includesList.add( stringArray[i].trim() );
+                String s = (String) it.next();
+                includesList.add( s.trim() );
             }
 
             batteryParms[1] = includesList;
 
-            stringList = batteryParts[3];
+            stringList = (String) batteryParts.get( 3 );
 
             ArrayList excludesList = new ArrayList();
 
@@ -752,11 +751,13 @@
                 stringList = stringList.substring( 1, stringList.length() - 1 );
             }
 
-            stringArray = stringList.split( "," );
+            stringArray = split( stringList, "," );
 
-            for ( int i = 0; i < stringArray.length; i++ )
+            it = stringArray.iterator();
+            while ( it.hasNext() )
             {
-                excludesList.add( stringArray[i].trim() );
+                String s = (String) it.next();
+                excludesList.add( s.trim() );
             }
 
             batteryParms[2] = excludesList;
@@ -765,7 +766,7 @@
         {
             batteryParms = new Object[1];
 
-            batteryParms[0] = batteryParts[1];
+            batteryParms[0] = batteryParts.get( 1 );
         }
 
         List batteryHolders = new ArrayList();
@@ -829,6 +830,31 @@
         {
             System.out.println( "ClassLoader: type" + classLoader.getClass() + ", value="
+ classLoader );
         }
+    }
+    
+    /**
+     * Split a string in a List of Strings using a delimiter. Same as Java 1.4 String.split(
String )
+     * 
+     * @param s the string to be splitted
+     * @param delim the delimiter to be used
+     * @return a List with the Strings between the delimiters
+     */
+    static List split( String s, String delim )
+    {
+        List tokens = new ArrayList();
+        int i = 0;
+        int j = s.indexOf( delim, i );
+        while ( j > -1 )
+        {
+            tokens.add( s.substring( i, j ) );
+            i = j + delim.length();
+            j = s.indexOf( delim, i );
+        }
+        if ( i < s.length() )
+        {
+            tokens.add( s.substring( i ) );
+        }
+        return tokens;
     }
 }
 

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java?rev=391731&r1=391730&r2=391731&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooterForkException.java
Wed Apr  5 12:17:46 2006
@@ -16,7 +16,12 @@
  * limitations under the License.
  */
 
-public class SurefireBooterForkException extends Exception
+/**
+ * Encapsulates exceptions thrown during Surefire forking.
+ * 
+ * @version $Id$ 
+ */
+public class SurefireBooterForkException extends NestedCheckedException
 {
   public SurefireBooterForkException(String message)
   {

Added: maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java?rev=391731&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
(added)
+++ maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
Wed Apr  5 12:17:46 2006
@@ -0,0 +1,52 @@
+package org.apache.maven.surefire;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class SurefireBooterTest
+    extends TestCase
+{
+
+    /*
+     * Test method for 'org.apache.maven.surefire.SurefireBooter.split(String, String)'
+     */
+    public void testSplit()
+    {
+        List list = SurefireBooter.split( "x1:y2:z;j:f", ":" );
+        assertEquals( Arrays.asList( new String[] { "x1", "y2", "z;j", "f" } ), list );
+        list = SurefireBooter.split( "x1", ":" );
+        assertEquals( Arrays.asList( new String[] { "x1" } ), list );
+        list = SurefireBooter.split( "x1:", ":" );
+        assertEquals( Arrays.asList( new String[] { "x1" } ), list );
+
+        list = SurefireBooter.split( "x1::y2::z;j::f", "::" );
+        assertEquals( Arrays.asList( new String[] { "x1", "y2", "z;j", "f" } ), list );
+        list = SurefireBooter.split( "x1", "::" );
+        assertEquals( Arrays.asList( new String[] { "x1" } ), list );
+        list = SurefireBooter.split( "x1::", "::" );
+        assertEquals( Arrays.asList( new String[] { "x1" } ), list );
+    }
+
+}

Propchange: maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/trunk/surefire-booter/src/test/java/org/apache/maven/surefire/SurefireBooterTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message