]> source.dussan.org Git - aspectj.git/commitdiff
polish. vmargs added (now obeys dtd) but unused
authoraclement <aclement>
Mon, 2 May 2011 18:42:15 +0000 (18:42 +0000)
committeraclement <aclement>
Mon, 2 May 2011 18:42:15 +0000 (18:42 +0000)
testing/newsrc/org/aspectj/testing/RunSpec.java

index 12de57268e82d47baa405cb9bd419062e8199666..7a58425486be92e593bbc02cb6b576d4004c957f 100644 (file)
@@ -23,14 +23,11 @@ import org.aspectj.tools.ajc.AjcTestCase;
 import org.aspectj.util.FileUtil;
 
 /**
- * @author colyer
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * @author Adrian Colyer
  */
 public class RunSpec implements ITestStep {
 
-       private List expected = new ArrayList();
+       private List<ExpectedMessageSpec> expected = new ArrayList<ExpectedMessageSpec>();
        private String classToRun;
        private String baseDir;
        private String options;
@@ -41,28 +38,26 @@ public class RunSpec implements ITestStep {
        private OutputSpec stdOutSpec;
        private String ltwFile;
        private String xlintFile;
-       
+       private String vmargs;
+
        public RunSpec() {
        }
-       
-       /* (non-Javadoc)
-        * @see org.aspectj.testing.ITestStep#execute(org.aspectj.tools.ajc.AjcTestCase)
-        */
+
        public void execute(AjcTestCase inTestCase) {
                if (!expected.isEmpty()) {
                        System.err.println("Warning, message spec for run command is currently ignored (org.aspectj.testing.RunSpec)");
                }
                String[] args = buildArgs();
-//             System.err.println("? execute() inTestCase='" + inTestCase + "', ltwFile=" + ltwFile);
+               // System.err.println("? execute() inTestCase='" + inTestCase + "', ltwFile=" + ltwFile);
                boolean useLtw = copyLtwFile(inTestCase.getSandboxDirectory());
                copyXlintFile(inTestCase.getSandboxDirectory());
                try {
                        setSystemProperty("test.base.dir", inTestCase.getSandboxDirectory().getAbsolutePath());
-                       
-                       AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,getClasspath(),useLtw);
-                       
+
+                       AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(), args, getClasspath(), useLtw);
+
                        if (stdErrSpec != null) {
-                               stdErrSpec.matchAgainst(rr.getStdErr(),orderedStderr);
+                               stdErrSpec.matchAgainst(rr.getStdErr(), orderedStderr);
                        }
                        if (stdOutSpec != null) {
                                stdOutSpec.matchAgainst(rr.getStdOut());
@@ -71,34 +66,35 @@ public class RunSpec implements ITestStep {
                        restoreProperties();
                }
        }
-       
-       /* 
-        * Logic to save/restore system properties. Copied from LTWTests.
-        * As Matthew noted, need to refactor LTWTests to use this 
-        */
+
+       /*
+        * Logic to save/restore system properties. Copied from LTWTests. As Matthew noted, need to refactor LTWTests to use this
+        */
 
        private Properties savedProperties = new Properties();
-               
-       public void setSystemProperty (String key, String value) {
+
+       public void setSystemProperty(String key, String value) {
                Properties systemProperties = System.getProperties();
-               copyProperty(key,systemProperties,savedProperties);
-               systemProperties.setProperty(key,value);
+               copyProperty(key, systemProperties, savedProperties);
+               systemProperties.setProperty(key, value);
        }
-       
-       private static void copyProperty (String key, Properties from, Properties to) {
-               String value = from.getProperty(key,NULL);
-               to.setProperty(key,value);
+
+       private static void copyProperty(String key, Properties from, Properties to) {
+               String value = from.getProperty(key, NULL);
+               to.setProperty(key, value);
        }
-       
+
        private final static String NULL = "null";
 
        protected void restoreProperties() {
                Properties systemProperties = System.getProperties();
-               for (Enumeration enu = savedProperties.keys(); enu.hasMoreElements(); ) {
-                       String key = (String)enu.nextElement();
+               for (Enumeration<Object> enu = savedProperties.keys(); enu.hasMoreElements();) {
+                       String key = (String) enu.nextElement();
                        String value = savedProperties.getProperty(key);
-                       if (value == NULL) systemProperties.remove(key);
-                       else systemProperties.setProperty(key,value);
+                       if (value == NULL)
+                               systemProperties.remove(key);
+                       else
+                               systemProperties.setProperty(key, value);
                }
        }
 
@@ -113,39 +109,44 @@ public class RunSpec implements ITestStep {
        public void setTest(AjcTest test) {
                this.myTest = test;
        }
-       
+
        public String getOptions() {
                return options;
        }
-       
+
        public void setOptions(String options) {
                this.options = options;
        }
-       
+
        public String getClasspath() {
-               if (cpath == null) return null;
+               if (cpath == null)
+                       return null;
                return this.cpath.replace('/', File.separatorChar).replace(',', File.pathSeparatorChar);
        }
-       
+
        public void setClasspath(String cpath) {
                this.cpath = cpath;
        }
-       
+
        public void addStdErrSpec(OutputSpec spec) {
                this.stdErrSpec = spec;
        }
+
        public void addStdOutSpec(OutputSpec spec) {
                this.stdOutSpec = spec;
        }
+
        public void setOrderedStderr(String orderedStderr) {
                this.orderedStderr = orderedStderr;
        }
+
        /**
         * @return Returns the classToRun.
         */
        public String getClassToRun() {
                return classToRun;
        }
+
        /**
         * @param classToRun The classToRun to set.
         */
@@ -160,36 +161,37 @@ public class RunSpec implements ITestStep {
        public void setLtwFile(String ltwFile) {
                this.ltwFile = ltwFile;
        }
-       
+
        private String[] buildArgs() {
-               if (options == null) return new String[0];
-               StringTokenizer strTok = new StringTokenizer(options,",");
+               if (options == null)
+                       return new String[0];
+               StringTokenizer strTok = new StringTokenizer(options, ",");
                String[] ret = new String[strTok.countTokens()];
                for (int i = 0; i < ret.length; i++) {
                        ret[i] = strTok.nextToken();
                }
                return ret;
        }
-       
-       private boolean copyLtwFile (File sandboxDirectory) {
+
+       private boolean copyLtwFile(File sandboxDirectory) {
                boolean useLtw = false;
-               
+
                if (ltwFile != null) {
-            // TODO maw use flag rather than empty file name
-                       if (ltwFile.trim().length() == 0) return true;
-                       
-                       File from = new File(baseDir,ltwFile);
-                       File to = new File(sandboxDirectory,"META-INF" + File.separator + "aop.xml");
-//                     System.out.println("RunSpec.copyLtwFile() from=" + from.getAbsolutePath() + " to=" + to.getAbsolutePath());
+                       // TODO maw use flag rather than empty file name
+                       if (ltwFile.trim().length() == 0)
+                               return true;
+
+                       File from = new File(baseDir, ltwFile);
+                       File to = new File(sandboxDirectory, "META-INF" + File.separator + "aop.xml");
+                       // System.out.println("RunSpec.copyLtwFile() from=" + from.getAbsolutePath() + " to=" + to.getAbsolutePath());
                        try {
-                               FileUtil.copyFile(from,to);
+                               FileUtil.copyFile(from, to);
                                useLtw = true;
-                       }
-                       catch (IOException ex) {
+                       } catch (IOException ex) {
                                AjcTestCase.fail(ex.toString());
                        }
                }
-               
+
                return useLtw;
        }
 
@@ -201,14 +203,21 @@ public class RunSpec implements ITestStep {
                this.xlintFile = xlintFile;
        }
 
-       private void copyXlintFile (File sandboxDirectory) {
+       public void setVmargs(String vmargs) {
+               this.vmargs = vmargs;
+       }
+
+       public String getVmargs() {
+               return vmargs;
+       }
+
+       private void copyXlintFile(File sandboxDirectory) {
                if (xlintFile != null) {
-                       File from = new File(baseDir,xlintFile);
+                       File from = new File(baseDir, xlintFile);
                        File to = new File(sandboxDirectory, File.separator + xlintFile);
                        try {
-                               FileUtil.copyFile(from,to);
-                       }
-                       catch (IOException ex) {
+                               FileUtil.copyFile(from, to);
+                       } catch (IOException ex) {
                                AjcTestCase.fail(ex.toString());
                        }
                }