ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r960931 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit: FailureRecorder.java FormatterElement.java JUnit4TestMethodAdapter.java JUnitTask.java JUnitTest.java JUnitTestRunner.java
Date Tue, 06 Jul 2010 16:16:28 GMT
Author: jglick
Date: Tue Jul  6 16:16:27 2010
New Revision: 960931

URL: http://svn.apache.org/viewvc?rev=960931&view=rev
Log:
Fixing various dependencies, mostly from FindBugs, some from the NetBeans editor.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
Tue Jul  6 16:16:27 2010
@@ -249,7 +249,9 @@ public class FailureRecorder extends Pro
             File sourceFile = new File((getLocationName() + ".java"));
             verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");
 
-            sourceFile.delete();
+            if (!sourceFile.delete()) {
+                throw new IOException("could not delete " + sourceFile);
+            }
             writer = new BufferedWriter(new FileWriter(sourceFile));
 
             createClassHeader();
@@ -334,13 +336,13 @@ public class FailureRecorder extends Pro
     /**
      * TestInfos holds information about a given test for later use.
      */
-    public class TestInfos implements Comparable {
+    public static class TestInfos implements Comparable {
 
         /** The class name of the test. */
-        private String className;
+        private final String className;
 
         /** The method name of the testcase. */
-        private String methodName;
+        private final String methodName;
 
         /**
          * This constructor extracts the needed information from the given test.
@@ -348,8 +350,8 @@ public class FailureRecorder extends Pro
          */
         public TestInfos(Test test) {
             className = test.getClass().getName();
-            methodName = test.toString();
-            methodName = methodName.substring(0, methodName.indexOf('('));
+            String _methodName = test.toString();
+            methodName = _methodName.substring(0, _methodName.indexOf('('));
         }
 
         /**
@@ -378,6 +380,12 @@ public class FailureRecorder extends Pro
                 return -1;
             }
         }
+        public boolean equals(Object obj) {
+            return obj instanceof TestInfos && toString().equals(obj.toString());
+        }
+        public int hashCode() {
+            return toString().hashCode();
+        }
     }
 
     // ===== BuildListener =====

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
Tue Jul  6 16:16:27 2010
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
 import java.io.OutputStream;
 import java.io.BufferedOutputStream;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.apache.tools.ant.BuildException;
@@ -326,8 +327,10 @@ public class FormatterElement {
                 // there is already a project reference so dont overwrite this
                 needToSetProjectReference = false;
             }
-        } catch (Exception e) {
+        } catch (NoSuchFieldException e) {
             // no field present, so no previous reference exists
+        } catch (IllegalAccessException e) {
+            throw new BuildException(e);
         }
 
         if (needToSetProjectReference) {
@@ -335,8 +338,12 @@ public class FormatterElement {
             try {
                 setter = r.getClass().getMethod("setProject", new Class[] {Project.class});
                 setter.invoke(r, new Object[] {project});
-            } catch (Exception e) {
+            } catch (NoSuchMethodException e) {
                 // no setProject to invoke; just ignore
+            } catch (IllegalAccessException e) {
+                throw new BuildException(e);
+            } catch (InvocationTargetException e) {
+                throw new BuildException(e);
             }
         }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java
Tue Jul  6 16:16:27 2010
@@ -74,7 +74,7 @@ public class JUnit4TestMethodAdapter imp
             }
         }
         this.testClass = testClass;
-        this.methodNames = methodNames;
+        this.methodNames = (String[]) methodNames.clone();
         this.cache = Cache.instance;
 
         // Warning: If 'testClass' is an old-style (pre-JUnit-4) class,
@@ -194,6 +194,8 @@ public class JUnit4TestMethodAdapter imp
      * of type {@code JUnit4TestAdapter}.
      */
     private static final class Cache extends JUnit4TestAdapterCache {
+        
+        private static final long serialVersionUID = 8454901854293461610L;
 
 	private static final Cache instance = new Cache();
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java Tue
Jul  6 16:16:27 2010
@@ -29,6 +29,8 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -652,8 +654,6 @@ public class JUnitTask extends Task {
      * @since Ant 1.2
      */
     public JUnitTask() throws Exception {
-        getCommandline()
-            .setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
     }
 
     /**
@@ -716,16 +716,17 @@ public class JUnitTask extends Task {
      * @since Ant 1.7.1
      */
     protected void setupJUnitDelegate() {
-        ClassLoader myLoader = JUnitTask.class.getClassLoader();
+        final ClassLoader myLoader = JUnitTask.class.getClassLoader();
         if (splitJunit) {
-            Path path = new Path(getProject());
+            final Path path = new Path(getProject());
             path.add(antRuntimeClasses);
             Path extra = getCommandline().getClasspath();
             if (extra != null) {
                 path.add(extra);
             }
-            mirrorLoader =
-                new SplitClassLoader(myLoader, path, getProject(),
+            mirrorLoader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction()
{
+                public Object run() {
+                    return new SplitClassLoader(myLoader, path, getProject(),
                                      new String[] {
                                          "BriefJUnitResultFormatter",
                                          "JUnit4TestMethodAdapter",
@@ -739,6 +740,8 @@ public class JUnitTask extends Task {
                                          "TearDownOnVmCrash",
                                          "XMLJUnitResultFormatter",
                                      });
+                }
+            });
         } else {
             mirrorLoader = myLoader;
         }
@@ -884,7 +887,7 @@ public class JUnitTask extends Task {
             log(e.toString(), Project.MSG_ERR);
             throw new BuildException(e);
         } finally {
-            FILE_UTILS.close(writer);
+            FileUtils.close(writer);
 
             try {
                 FILE_UTILS.tryHardToDelete(casesFile);
@@ -925,7 +928,6 @@ public class JUnitTask extends Task {
         } catch (CloneNotSupportedException e) {
             throw new BuildException("This shouldn't happen", e, getLocation());
         }
-        cmd.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
         if (casesFile == null) {
             cmd.createArgument().setValue(test.getName());
             if (test.getMethods() != null) {
@@ -1177,13 +1179,13 @@ public class JUnitTask extends Task {
             return new File(FILE_UTILS.fromURI(url1))
                 .equals(new File(FILE_UTILS.fromURI(url2)));
         }
-        return u1.equals(u2);
+        return url1.equals(url2);
     }
 
     private static String maybeStripJarAndClass(URL u) {
         String s = u.toString();
         if (s.startsWith("jar:")) {
-            int pling = s.indexOf("!");
+            int pling = s.indexOf('!');
             s = s.substring(4, pling == -1 ? s.length() : pling);
         }
         return s;
@@ -1723,6 +1725,7 @@ public class JUnitTask extends Task {
     protected CommandlineJava getCommandline() {
         if (commandline == null) {
             commandline = new CommandlineJava();
+            commandline.setClassname("org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner");
         }
         return commandline;
     }
@@ -1940,7 +1943,7 @@ public class JUnitTask extends Task {
     /**
      * A value class that contains the result of a test.
      */
-    protected class TestResultHolder {
+    protected static class TestResultHolder {
         // CheckStyle:VisibilityModifier OFF - bc
         /** the exit code of the test. */
         public int exitCode = JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS;
@@ -2019,7 +2022,7 @@ public class JUnitTask extends Task {
      */
     private static JUnitTest createDummyTestForBatchTest(JUnitTest test) {
         JUnitTest t = (JUnitTest) test.clone();
-        int index = test.getName().indexOf(".");
+        int index = test.getName().indexOf('.');
         // make sure test looks as if it was in the same "package" as
         // the last test of the batch
         String pack = index > 0 ? test.getName().substring(0, index + 1) : "";

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java Tue
Jul  6 16:16:27 2010
@@ -97,8 +97,7 @@ public class JUnitTest extends BaseTest 
      * @param haltOnError if true halt the tests if there is an error.
      * @param haltOnFailure if true halt the tests if there is a failure.
      * @param filtertrace if true filter stack traces.
-     * @param methods if true run only test methods that failed during the
-     *                previous run of the test suite
+     * @param methods if non-null run only these test methods
      * @since 1.8.2
      */
     public JUnitTest(String name, boolean haltOnError, boolean haltOnFailure,
@@ -107,8 +106,8 @@ public class JUnitTest extends BaseTest 
         this.haltOnError = haltOnError;
         this.haltOnFail = haltOnFailure;
         this.filtertrace = filtertrace;
-        this.methods = methods;
-        this.methodsSpecified = (methods != null);
+        this.methodsSpecified = methods != null;
+        this.methods = methodsSpecified ? (String[]) methods.clone() : null;
     }
 
     /**
@@ -298,10 +297,10 @@ public class JUnitTest extends BaseTest 
                     break;
                 case stateInsideWord:
                     if (c == ',') {
-                        result[wordIndex++] = new String(methodNames.substring(wordStartIndex,
i));
+                        result[wordIndex++] = methodNames.substring(wordStartIndex, i);
                         state = stateBeforeWord;
                     } else if (c == ' ') {
-                        result[wordIndex++] = new String(methodNames.substring(wordStartIndex,
i));
+                        result[wordIndex++] = methodNames.substring(wordStartIndex, i);
                         state = stateAfterWord;
                     } else if (Character.isJavaIdentifierPart(c)) {
                         // remain in the same state
@@ -327,7 +326,7 @@ public class JUnitTest extends BaseTest 
             case stateAfterWord:
                 break;
             case stateInsideWord:
-                result[wordIndex++] = new String(methodNames.substring(wordStartIndex, chars.length));
+                result[wordIndex++] = methodNames.substring(wordStartIndex, chars.length);
                 break;
             default:
                 // this should never happen

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java?rev=960931&r1=960930&r2=960931&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
Tue Jul  6 16:16:27 2010
@@ -289,13 +289,13 @@ public class JUnitTestRunner implements 
                            boolean filtertrace, boolean haltOnFailure,
                            boolean showOutput, boolean logTestListenerEvents,
                            ClassLoader loader) {
-        JUnitTestRunner.filtertrace = filtertrace;
+        JUnitTestRunner.filtertrace = filtertrace; // XXX clumsy, should use instance field
somehow
         this.junitTest = test;
         this.haltOnError = haltOnError;
         this.haltOnFailure = haltOnFailure;
         this.showOutput = showOutput;
         this.logTestListenerEvents = logTestListenerEvents;
-        this.methods = methods;
+        this.methods = methods != null ? (String[]) methods.clone() : null;
         this.loader = loader;
     }
 



Mime
View raw message