]> source.dussan.org Git - aspectj.git/commitdiff
implementing clone() for test specifications
authorwisberg <wisberg>
Thu, 28 Aug 2003 18:28:43 +0000 (18:28 +0000)
committerwisberg <wisberg>
Thu, 28 Aug 2003 18:28:43 +0000 (18:28 +0000)
testing/src/org/aspectj/testing/harness/bridge/AbstractRunSpec.java
testing/src/org/aspectj/testing/harness/bridge/AjcTest.java
testing/src/org/aspectj/testing/harness/bridge/CompilerRun.java
testing/src/org/aspectj/testing/harness/bridge/IncCompilerRun.java
testing/src/org/aspectj/testing/harness/bridge/JavaRun.java

index 3eef0679e6657b2c3ff1e6f28d98defe052af318..c14f53aa7af7644efafecdb2dde63b1ff9e07b6f 100644 (file)
@@ -92,7 +92,7 @@ abstract public class AbstractRunSpec implements IRunSpec { // XXX use MessageHa
     private BitSet skipSet;
     private boolean skipAll;
     
-    protected final String xmlElementName;
+    protected String xmlElementName; // nonfinal only for clone()
     protected final ArrayList /*String*/ keywords; 
     protected final IMessageHolder /*IMessage*/ messages;
     protected final ArrayList /*String*/ options;
@@ -107,7 +107,7 @@ abstract public class AbstractRunSpec implements IRunSpec { // XXX use MessageHa
     public final RT runtime;
 
     /** if true, then any child skip causes this to skip */
-       protected final boolean skipIfAnyChildSkipped;
+       protected boolean skipIfAnyChildSkipped; // nonfinal only for cloning
 
     public AbstractRunSpec(String xmlElementName) {
         this(xmlElementName, true);
@@ -735,6 +735,50 @@ abstract public class AbstractRunSpec implements IRunSpec { // XXX use MessageHa
         return result.toString();
     }
 
+    protected void initClone(AbstractRunSpec spec) 
+            throws CloneNotSupportedException {
+        /*
+         * clone associated objects only if not (used as?) read-only.
+         */
+        spec.badInput = badInput;
+        spec.children.clear();
+        for (Iterator iter = children.iterator(); iter.hasNext();) {
+            // clone these...
+            IRunSpec child = (IRunSpec) iter.next();
+            // require all child classes to support clone?
+            if (child instanceof AbstractRunSpec) {
+                spec.addChild((AbstractRunSpec) ((AbstractRunSpec) child).clone());
+            } else {
+                throw new Error("unable to clone " + child);
+            }
+        }
+        spec.comment = comment;
+        spec.description = description;
+        spec.dirChanges.clear();
+        spec.dirChanges.addAll(dirChanges);
+        spec.isStaging = spec.isStaging;
+        spec.keywords.clear();
+        spec.keywords.addAll(keywords);
+        spec.messages.clearMessages();
+        MessageUtil.handleAll(spec.messages, messages, false);
+        spec.options.clear();
+        spec.options.addAll(options);
+        spec.paths.clear();
+        spec.paths.addAll(paths);
+        spec.runtime.copy(runtime);
+        spec.skipAll = skipAll;
+        spec.skipIfAnyChildSkipped = skipIfAnyChildSkipped;
+        if (null != skipSet) {
+            spec.skipSet = new BitSet();
+            spec.skipSet.or(skipSet);
+        }
+        spec.sourceLocation = sourceLocation;
+        spec.sourceLocations.clear();
+        spec.sourceLocations.addAll(sourceLocations);
+        spec.xmlElementName = xmlElementName;
+        spec.xmlNames = ((AbstractRunSpec.XMLNames) xmlNames.clone());
+    }
+
     private static void addListCount(String name, List list, StringBuffer sink) {
         int size = list.size();
         if ((null != list) && (0 < size)) {
@@ -780,6 +824,22 @@ abstract public class AbstractRunSpec implements IRunSpec { // XXX use MessageHa
         final boolean skipDirChanges;
         final boolean skipMessages;
         final boolean skipChildren;
+        protected Object clone() {
+            return new XMLNames(
+                null,
+                descriptionName,
+                sourceLocationName,
+                keywordsName,
+                optionsName,
+                pathsName,
+                commentName,
+                stagingName,
+                badInputName,
+                skipDirChanges,
+                skipMessages,
+                skipChildren);
+        }
+        
         // not runtime, skipAll, skipIfAnyChildSkipped, skipSet
         //     sourceLocations
         /** reset all names/behavior or pass defaultNames 
index 4a521d890134f78972d8aee3313ae76e8254ce96..e359389bf995dcc5429f3e550e15fa54083ed77a 100644 (file)
@@ -247,6 +247,20 @@ public class AjcTest extends RunSpecIterator {
             setXMLNames(NAMES);
         }
         
+        protected void initClone(Spec spec) 
+                throws CloneNotSupportedException {
+            super.initClone(spec);
+            spec.bugId = bugId;
+            spec.suiteDir = suiteDir;
+            spec.testDirOffset = testDirOffset;
+        }
+        
+        public Object clone() throws CloneNotSupportedException {
+            Spec result = new Spec();
+            initClone(result);
+            return result;    
+        }
+        
         public void setSuiteDir(File suiteDir) {
             this.suiteDir = suiteDir;
         }
@@ -518,6 +532,13 @@ public class AjcTest extends RunSpecIterator {
                 super(XMLNAME, false); // do not skip this even if children skip
             }
             
+            public Object clone() throws CloneNotSupportedException {
+                Spec spec = new Spec();
+                super.initClone(spec);
+                spec.suiteDir = suiteDir;                
+                return spec;
+            }
+            
             /** @param suiteDirPath the String path to the base suite dir */
             public void setSuiteDir(String suiteDirPath) {
                 if (!LangUtil.isEmpty(suiteDirPath)) {
index 680ecbea9965b3ae895252aa552dfc283c8552ff..37d5ba9b5eba564fce3a5924a5feccb4af3d9596 100644 (file)
@@ -312,7 +312,7 @@ public class CompilerRun implements IAjcRun {
      *     {@link setupArgs(ArrayList, IMessageHandler}.</li>
      * <li>construct a command line, using as classpath 
      *     {@link Sandbox.classpathToString()}<li>
-     * <li>construct a compiler using {@link Spec#compilerName}
+     * <li>construct a compiler using {@link Spec#compiler}
      *     or any overriding value set in TestSetup.<li>
      * <li>Just before running, set the compiler in the sandbox using 
      *     {@link Sandbox.setCompiler(ICommand)}.<li>
@@ -528,6 +528,38 @@ public class CompilerRun implements IAjcRun {
             compiler = DEFAULT_COMPILER;
         }
         
+        private static String[] copy(String[] input) {
+            if (null == input) {
+                return null;
+            }
+            String[] result = new String[input.length];
+            System.arraycopy(input, 0, result, 0, input.length);
+            return result;
+        }
+
+        protected void initClone(Spec spec) 
+                throws CloneNotSupportedException {
+            super.initClone(spec);
+            spec.argfiles = copy(argfiles);
+            spec.aspectpath = copy(aspectpath);
+            spec.classpath = copy(classpath);
+            spec.compiler = compiler;
+            spec.includeClassesDir = includeClassesDir;
+            spec.reuseCompiler = reuseCompiler;
+            spec.sourceroots = copy(sourceroots);
+            spec.testSetup = null;
+            if (null != testSetup) {
+                spec.testSetup = (TestSetup) testSetup.clone();
+            }
+            spec.testSrcDirOffset = testSrcDirOffset;
+        }
+        
+        public Object clone() throws CloneNotSupportedException {
+            Spec result = new Spec();
+            initClone(result);
+            return result;    
+        }
+
         public void setIncludeClassesDir(boolean include) {
             this.includeClassesDir = include;
         }
@@ -1065,6 +1097,20 @@ public class CompilerRun implements IAjcRun {
             /** if setup completed, this has the combined global/local options */
             ArrayList commandOptions;
             
+            public Object clone() {
+                TestSetup testSetup = new TestSetup();
+                testSetup.compilerName = compilerName;
+                testSetup.ignoreWarnings = ignoreWarnings;
+                testSetup.ignoreWarningsSet = ignoreWarningsSet;
+                testSetup.result = result;
+                testSetup.failureReason = failureReason;
+                testSetup.seek = seek;
+                if (null != commandOptions) {
+                    testSetup.commandOptions = new ArrayList();
+                    testSetup.commandOptions.addAll(commandOptions);
+                }
+                return testSetup;
+            }
             public String toString() {
                 return "TestSetup("
                     + (null == compilerName ? "" : compilerName + " ")
index b4302ac633647135125b1141831e4568fb93e065..b06430e61025f300f48bc0156f7729b52e802e85 100644 (file)
@@ -299,6 +299,26 @@ public class IncCompilerRun implements IAjcRun {
             classesUpdated = new ArrayList();
                }
         
+        protected void initClone(Spec spec) 
+                throws CloneNotSupportedException {
+            super.initClone(spec);
+            spec.fresh = fresh;
+            spec.tag = tag;
+            spec.classesAdded.clear();
+            spec.classesAdded.addAll(classesAdded);
+            spec.classesRemoved.clear();
+            spec.classesRemoved.addAll(classesRemoved);
+            spec.classesUpdated.clear();
+            spec.classesUpdated.addAll(classesUpdated);
+        }
+        
+        public Object clone() throws CloneNotSupportedException {
+            Spec result = new Spec();
+            initClone(result);
+            return result;    
+        }
+
+
         public void setFresh(boolean fresh) {
             this.fresh = fresh;
         }
index 76785b464151a423c7fcbded35e2a6f89dc34fb2..21a67986c56c266ec20d5452a4c74fc8117b69ff 100644 (file)
@@ -444,6 +444,22 @@ public class JavaRun implements IAjcRun {
             setXMLNames(NAMES);
         }
         
+        protected void initClone(Spec spec) 
+                throws CloneNotSupportedException {
+            super.initClone(spec);
+            spec.className = className;            
+            spec.errStreamIsError = errStreamIsError;
+            spec.javaVersion = javaVersion;
+            spec.outStreamIsError = outStreamIsError;
+            spec.skipTester = skipTester;
+        }
+        
+        public Object clone() throws CloneNotSupportedException {
+            Spec result = new Spec();
+            initClone(result);
+            return result;    
+        }
+
         /**
          * @param version "1.1", "1.2", "1.3", "1.4"
          * @throws IllegalArgumentException if version is not recognized