Author: carlos
Date: Wed Apr  5 17:24:09 2006
New Revision: 391866

URL: http://svn.apache.org/viewcvs?rev=391866&view=rev
Log:
[MSUREFIRE-86] Make surefire compile under Java 1.3, merged in r391731, 
r391781, r391783, r391863 from trunk

Added:
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
   (with props)
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
   (with props)
Modified:
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/assertion/SurefireAssertionFailedException.java
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
    
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSetFailedException.java

Modified: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/assertion/SurefireAssertionFailedException.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/assertion/SurefireAssertionFailedException.java?rev=391866&r1=391865&r2=391866&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/assertion/SurefireAssertionFailedException.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/assertion/SurefireAssertionFailedException.java
 Wed Apr  5 17:24:09 2006
@@ -1,5 +1,7 @@
 package org.apache.maven.surefire.assertion;
 
+import org.apache.maven.surefire.testset.NestedRuntimeException;
+
 /*
  * Copyright 2001-2006 The Apache Software Foundation.
  *
@@ -20,7 +22,7 @@
  * @noinspection UncheckedExceptionClass
  */
 public class SurefireAssertionFailedException
-    extends RuntimeException
+    extends NestedRuntimeException
 {
     public SurefireAssertionFailedException()
     {

Modified: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java?rev=391866&r1=391865&r2=391866&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterException.java
 Wed Apr  5 17:24:09 2006
@@ -1,5 +1,7 @@
 package org.apache.maven.surefire.report;
 
+import org.apache.maven.surefire.testset.NestedCheckedException;
+
 /*
  * Copyright 2001-2006 The Apache Software Foundation.
  *
@@ -22,7 +24,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
  */
 public class ReporterException
-    extends Exception
+    extends NestedCheckedException
 {
     public ReporterException( String message, Exception nested )
     {

Modified: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=391866&r1=391865&r2=391866&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 Wed Apr  5 17:24:09 2006
@@ -266,6 +266,42 @@
     private static String escapeAttribute( String attribute )
     {
         // Shouldn't Xpp3Dom do this itself?
-        return attribute.replaceAll( "<", "&lt;" ).replaceAll( ">", "&gt;" );
+        String s = replaceAll( attribute, "<", "&lt;" );
+        s = replaceAll( s, ">", "&gt;" );
+        return s;
+
     }
+
+    /**
+     * Replace all ocurrences of a value in a string. Same as Java 1.4 
String.replaceAll( String, String )
+     * 
+     * @param s the string to search into
+     * @param from original String to look for
+     * @param to String to change for
+     * @return the modified String
+     */
+    public static String replaceAll( String source, String pattern, String 
replace )
+    {
+        if ( ( source != null ) && ( pattern.length() > 0 ) )
+        {
+            final int len = pattern.length();
+            StringBuffer sb = new StringBuffer();
+            int found = -1;
+            int start = 0;
+
+            while ( ( found = source.indexOf( pattern, start ) ) != -1 )
+            {
+                sb.append( source.substring( start, found ) );
+                sb.append( replace );
+                start = found + len;
+            }
+
+            sb.append( source.substring( start ) );
+
+            return sb.toString();
+        }
+        else
+            return "";
+    }
+
 }

Modified: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java?rev=391866&r1=391865&r2=391866&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/suite/AbstractDirectoryTestSuite.java
 Wed Apr  5 17:24:09 2006
@@ -29,8 +29,8 @@
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -70,7 +70,7 @@
         {
             throw new IllegalStateException( "You can't call locateTestSets 
twice" );
         }
-        testSets = new LinkedHashMap();
+        testSets = new HashMap();
 
         String[] tests = collectTests( basedir, includes, excludes );
 

Added: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java?rev=391866&view=auto
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
 (added)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
 Wed Apr  5 17:24:09 2006
@@ -0,0 +1,193 @@
+package org.apache.maven.surefire.testset;
+
+/*
+ * 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 no message or 
exception
+     */
+    public NestedCheckedException() {
+        super();
+    }
+
+    /**
+     * 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/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedCheckedException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java?rev=391866&view=auto
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
 (added)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
 Wed Apr  5 17:24:09 2006
@@ -0,0 +1,192 @@
+package org.apache.maven.surefire.testset;
+
+/*
+ * 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 parts 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 runtime Exceptions with a root cause.</p>
+ *
+ * <p>This time-honoured 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 NestedCheckedException 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 NestedCheckedException
+ */
+public abstract class NestedRuntimeException extends RuntimeException {
+
+    /** Root cause of this nested exception */
+    private Throwable cause;
+
+    /**
+     * Construct a <code>NestedRuntimeException</code> with no message or 
exception
+     */
+    public NestedRuntimeException() {
+        super();
+    }
+
+    /**
+     * Construct a <code>NestedRuntimeException</code> with the specified 
detail message.
+     * @param msg the detail message
+     */
+    public NestedRuntimeException(String msg) {
+        super(msg);
+    }
+
+    /**
+     * Construct a <code>NestedRuntimeException</code> with the specified 
nested exception and no message.
+     * @param ex the nested exception
+     */
+    public NestedRuntimeException(Throwable ex) {
+        this();
+        this.cause = ex;
+    }
+
+    /**
+     * Construct a <code>NestedRuntimeException</code> with the specified 
detail message
+     * and nested exception.
+     * @param msg the detail message
+     * @param ex the nested exception
+     */
+    public NestedRuntimeException(String msg, Throwable ex) {
+        this(msg);
+        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 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 NestedRuntimeException 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 NestedRuntimeException) {
+                // Cast is necessary on JDK 1.3, where Throwable does not
+                // provide a "getCause" method itself.
+                ex = ((NestedRuntimeException) ex).getCause();
+            }
+            else {
+                ex = null;
+            }
+        }
+        return false;
+    }
+
+}

Propchange: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/NestedRuntimeException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSetFailedException.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSetFailedException.java?rev=391866&r1=391865&r2=391866&view=diff
==============================================================================
--- 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSetFailedException.java
 (original)
+++ 
maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/testset/TestSetFailedException.java
 Wed Apr  5 17:24:09 2006
@@ -22,7 +22,7 @@
  * @author Bill Venners
  */
 public class TestSetFailedException
-    extends Exception
+    extends NestedCheckedException
 {
     /**
      * Create a <code>TestFailedException</code> with no detail message.


Reply via email to