]> source.dussan.org Git - aspectj.git/commitdiff
251277: making asmmanager non-singleton
authoraclement <aclement>
Mon, 20 Oct 2008 04:43:09 +0000 (04:43 +0000)
committeraclement <aclement>
Mon, 20 Oct 2008 04:43:09 +0000 (04:43 +0000)
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java

index 6cf279f49838c9b918ae17e130f4e7f1edd41988..3799b4cdab4cf96ecdd805d2e66fbeb619a733bb 100644 (file)
 package org.aspectj.ajdt.internal.core.builder;
 
 import java.io.File;
-//import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.aspectj.ajdt.StreamPrintWriter;
-import org.aspectj.ajdt.ajc.*;
-import org.aspectj.asm.AsmManager;
+import org.aspectj.ajdt.ajc.AjdtAjcTests;
+import org.aspectj.ajdt.ajc.BuildArgParser;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.MessageHandler;
 import org.aspectj.bridge.MessageWriter;
@@ -29,350 +29,334 @@ import org.aspectj.tools.ajc.Ajc;
 
 public class AjBuildManagerTest extends TestCase {
 
-       private StreamPrintWriter outputWriter = new StreamPrintWriter(new PrintWriter(System.out));    
-       private MessageWriter messageWriter = new MessageWriter(outputWriter, false);
+       private final StreamPrintWriter outputWriter = new StreamPrintWriter(new PrintWriter(System.out));
+       private final MessageWriter messageWriter = new MessageWriter(outputWriter, false);
        public static File source1 = new File(AjdtAjcTests.TESTDATA_DIR, "src1/A.java");
        public static File source2 = new File(AjdtAjcTests.TESTDATA_DIR, "src1/Hello.java");
        public static File source3 = new File(AjdtAjcTests.TESTDATA_DIR, "src1/X.java");
 
-    
-    /**
-     * @throws AssertionFailedError unless handler has 0 messages
-     * worse than warning, or the one message is 
-     * a warning about aspectjrt.jar
-     */
-    public static void assertCompileMessagesValid(MessageHandler handler) {
-        assertTrue("null handler", null != handler);
-        final int numMessages = handler.numMessages(IMessage.WARNING, true);
-        if (1 == numMessages) { // permit aspectjrt.jar warning
-            IMessage m = handler.getMessages(IMessage.WARNING, true)[0];            
-            if (!(m.isWarning() && (-1 != m.getMessage().indexOf("aspectjrt.jar")))) {
-                assertTrue(handler.toString(), false);
-            }            
-        } else if (0 != numMessages) {
-            assertTrue(handler.toString(), false);
-        }
-    }
+       /**
+        * @throws AssertionFailedError unless handler has 0 messages worse than warning, or the one message is a warning about
+        *         aspectjrt.jar
+        */
+       public static void assertCompileMessagesValid(MessageHandler handler) {
+               assertTrue("null handler", null != handler);
+               final int numMessages = handler.numMessages(IMessage.WARNING, true);
+               if (1 == numMessages) { // permit aspectjrt.jar warning
+                       IMessage m = handler.getMessages(IMessage.WARNING, true)[0];
+                       if (!(m.isWarning() && (-1 != m.getMessage().indexOf("aspectjrt.jar")))) {
+                               assertTrue(handler.toString(), false);
+                       }
+               } else if (0 != numMessages) {
+                       assertTrue(handler.toString(), false);
+               }
+       }
 
        public AjBuildManagerTest(String name) {
                super(name);
        }
-       
-       public void testSimpleStructure() throws IOException /*, CoreException */ {
-               
+
+       public void testSimpleStructure() throws IOException /* , CoreException */{
+
                AjBuildManager manager = new AjBuildManager(messageWriter);
                BuildArgParser parser = new BuildArgParser(messageWriter);
                String javaClassPath = System.getProperty("java.class.path");
                String sandboxName = Ajc.createEmptySandbox().getAbsolutePath();
-        AjBuildConfig buildConfig = 
-                       parser.genBuildConfig(new String[] { 
-                               "-d", sandboxName, 
-                               "-classpath",
-                               javaClassPath,
-                               AjdtAjcTests.TESTDATA_PATH 
-                + "/src1/A.java",
-//                             EajcModuleTests.TESTDATA_PATH + "/src1/Hello.java",
-                                });
-        String err = parser.getOtherMessages(true);            
-        assertTrue(err, null == err);
-        manager.setStructureModel(AsmManager.getDefault().getHierarchy());
+               AjBuildConfig buildConfig = parser.genBuildConfig(new String[] { "-d", sandboxName, "-classpath", javaClassPath,
+                               AjdtAjcTests.TESTDATA_PATH + "/src1/A.java",
+               // EajcModuleTests.TESTDATA_PATH + "/src1/Hello.java",
+                               });
+               String err = parser.getOtherMessages(true);
+               assertTrue(err, null == err);
+               // manager.setStructureModel(AsmManager.getDefault().getHierarchy());
                MessageHandler handler = new MessageHandler();
-        manager.batchBuild(buildConfig, handler);
-        assertCompileMessagesValid(handler);   
-//             System.out.println(
-//                     ">> model: \n" + 
-//                     StructureModelManager.INSTANCE.getStructureModel().getRoot().toLongString()
-//             );
-//             
-//             System.out.println(
-//                     ">> children: \n" + 
-//                     ((StructureNode)StructureModelManager.INSTANCE.getStructureModel().getRoot().getChildren().get(0)).getChildren()
-//             );
+               manager.batchBuild(buildConfig, handler);
+               assertCompileMessagesValid(handler);
+               // System.out.println(
+               // ">> model: \n" +
+               // StructureModelManager.INSTANCE.getStructureModel().getRoot().toLongString()
+               // );
+               //              
+               // System.out.println(
+               // ">> children: \n" +
+               // ((StructureNode)StructureModelManager.INSTANCE.getStructureModel().getRoot().getChildren().get(0)).getChildren()
+               // );
        }
-               
-         
-       
 
-       //XXX add test for resource deltas
-//
-//     public void testUpdateBuildConfig() {
-//             final File FILE_1 = new File("testdata/testclasses/Temp1.java");
-//             final File FILE_2 = new File("testdata/testclasses/Temp2.java");
-//             final File FILE_3 = new File("testdata/testclasses/Temp3.java");
-//             List files = new ArrayList();
-//             files.add(FILE_1);
-//             files.add(FILE_2);
-//             
-//             AjBuildManager manager = new AjBuildManager(messageWriter);
-//             AjBuildConfig buildConfig = new AjBuildConfig();
-//             manager.buildConfig = buildConfig;
-//             buildConfig.setFiles(files);
-//             
-//             manager.updateBuildConfig(buildConfig);
-//             assertTrue("no change", manager.deletedFiles.isEmpty());
-//             
-//             AjBuildConfig newConfig = new AjBuildConfig();
-//             newConfig.getFiles().add(FILE_1);
-//             newConfig.getFiles().add(FILE_2);
-//             newConfig.getFiles().add(FILE_3);
-//             manager.updateBuildConfig(newConfig);
-//             assertTrue("added file", manager.deletedFiles.isEmpty());
-//             assertTrue(manager.addedFiles.size() == 1);
-//             assertTrue(manager.addedFiles.contains(FILE_3));
-//             
-//             newConfig = new AjBuildConfig();
-//             newConfig.getFiles().add(FILE_3);
-//             manager.updateBuildConfig(newConfig);
-//             assertTrue("deleted 2 files", manager.addedFiles.isEmpty());
-//             assertTrue(manager.deletedFiles.size() == 2);
-//             assertTrue(manager.deletedFiles.contains(FILE_1));              
-//
-//             newConfig = new AjBuildConfig();
-//             newConfig.getFiles().add(FILE_2);
-//             manager.updateBuildConfig(newConfig);
-//             assertTrue("added file", manager.addedFiles.size() == 1);
-//             assertTrue("deleted file", manager.deletedFiles.size() == 1);
-//             assertTrue(manager.deletedFiles.size() == 1);
-//             assertTrue(manager.addedFiles.contains(FILE_2));        
-//             assertTrue(manager.deletedFiles.contains(FILE_3));
-//     }       
-//
-//     /**
-//      * Pretends that the files 'have been' modified in the future and waits.  
-//      * Tests:
-//      * 1) no change, 
-//      * 2) added file, 
-//      * 3) removed file 
-//      * 
-//      * XXX should just test modified
-//      */ 
-//     public void testGetModifiedFiles() throws IOException, InterruptedException {
-//             final File TEMP_1 = new File("testdata/testclasses/TempChanged.java");
-//             final File EXISTS_2 = new File("testdata/testclasses/p1/Foo.java");
-//             final File NEW = new File("testdata/testclasses/TempNew.java");
-//             NEW.delete();
-//             touch(TEMP_1, false);
-//             List files = new ArrayList();
-//             files.add(TEMP_1);
-//             files.add(EXISTS_2);
-//             
-//             assertTrue("input files", TEMP_1.exists() && EXISTS_2.exists());
-//             assertTrue("new file", !NEW.exists());
-//
-//             Thread.sleep(100);
-//             long lastBuildTime = System.currentTimeMillis();
-//             
-//             AjBuildManager manager = new AjBuildManager(messageWriter);
-//             manager.buildConfig = new AjBuildConfig();
-//             manager.buildConfig.setFiles(files);
-//             Collection changedFiles = manager.getModifiedFiles(lastBuildTime);
-//             assertTrue("nothing changed: " + changedFiles, changedFiles.isEmpty());
-//
-//             lastBuildTime = System.currentTimeMillis();
-//             Thread.sleep(100);
-//     
-//             touch(NEW, false);
-//
-//             //NEW.createNewFile();
-//             files.add(NEW);
-//             changedFiles = manager.getModifiedFiles(lastBuildTime);
-//             assertTrue("new file: " + changedFiles, changedFiles.contains(NEW));
-//               
-//             lastBuildTime = System.currentTimeMillis();
-//             Thread.sleep(100);
-//
-//             files.remove(NEW);
-//             changedFiles = manager.getModifiedFiles(lastBuildTime);
-//             assertTrue("nothing changed", changedFiles.isEmpty());
-//             
-//             lastBuildTime = System.currentTimeMillis();
-//             Thread.sleep(100);
-//             
-//             touch(TEMP_1, true);
-//             changedFiles = manager.getModifiedFiles(lastBuildTime);
-//             assertTrue("touched file: " + changedFiles, changedFiles.contains(TEMP_1));
-//             
-//             lastBuildTime = System.currentTimeMillis();
-//             Thread.sleep(100);
-//
-//             files.remove(NEW);
-//             changedFiles = manager.getModifiedFiles(lastBuildTime);
-//             assertTrue("nothing changed", changedFiles.isEmpty());
-//             
-//             TEMP_1.delete();
-//             NEW.delete();
-//     }
-       
+       // XXX add test for resource deltas
+       //
+       // public void testUpdateBuildConfig() {
+       // final File FILE_1 = new File("testdata/testclasses/Temp1.java");
+       // final File FILE_2 = new File("testdata/testclasses/Temp2.java");
+       // final File FILE_3 = new File("testdata/testclasses/Temp3.java");
+       // List files = new ArrayList();
+       // files.add(FILE_1);
+       // files.add(FILE_2);
+       //              
+       // AjBuildManager manager = new AjBuildManager(messageWriter);
+       // AjBuildConfig buildConfig = new AjBuildConfig();
+       // manager.buildConfig = buildConfig;
+       // buildConfig.setFiles(files);
+       //              
+       // manager.updateBuildConfig(buildConfig);
+       // assertTrue("no change", manager.deletedFiles.isEmpty());
+       //              
+       // AjBuildConfig newConfig = new AjBuildConfig();
+       // newConfig.getFiles().add(FILE_1);
+       // newConfig.getFiles().add(FILE_2);
+       // newConfig.getFiles().add(FILE_3);
+       // manager.updateBuildConfig(newConfig);
+       // assertTrue("added file", manager.deletedFiles.isEmpty());
+       // assertTrue(manager.addedFiles.size() == 1);
+       // assertTrue(manager.addedFiles.contains(FILE_3));
+       //              
+       // newConfig = new AjBuildConfig();
+       // newConfig.getFiles().add(FILE_3);
+       // manager.updateBuildConfig(newConfig);
+       // assertTrue("deleted 2 files", manager.addedFiles.isEmpty());
+       // assertTrue(manager.deletedFiles.size() == 2);
+       // assertTrue(manager.deletedFiles.contains(FILE_1));
+       //
+       // newConfig = new AjBuildConfig();
+       // newConfig.getFiles().add(FILE_2);
+       // manager.updateBuildConfig(newConfig);
+       // assertTrue("added file", manager.addedFiles.size() == 1);
+       // assertTrue("deleted file", manager.deletedFiles.size() == 1);
+       // assertTrue(manager.deletedFiles.size() == 1);
+       // assertTrue(manager.addedFiles.contains(FILE_2));
+       // assertTrue(manager.deletedFiles.contains(FILE_3));
+       // }
+       //
+       // /**
+       // * Pretends that the files 'have been' modified in the future and waits.
+       // * Tests:
+       // * 1) no change,
+       // * 2) added file,
+       // * 3) removed file
+       // *
+       // * XXX should just test modified
+       // */
+       // public void testGetModifiedFiles() throws IOException, InterruptedException {
+       // final File TEMP_1 = new File("testdata/testclasses/TempChanged.java");
+       // final File EXISTS_2 = new File("testdata/testclasses/p1/Foo.java");
+       // final File NEW = new File("testdata/testclasses/TempNew.java");
+       // NEW.delete();
+       // touch(TEMP_1, false);
+       // List files = new ArrayList();
+       // files.add(TEMP_1);
+       // files.add(EXISTS_2);
+       //              
+       // assertTrue("input files", TEMP_1.exists() && EXISTS_2.exists());
+       // assertTrue("new file", !NEW.exists());
+       //
+       // Thread.sleep(100);
+       // long lastBuildTime = System.currentTimeMillis();
+       //              
+       // AjBuildManager manager = new AjBuildManager(messageWriter);
+       // manager.buildConfig = new AjBuildConfig();
+       // manager.buildConfig.setFiles(files);
+       // Collection changedFiles = manager.getModifiedFiles(lastBuildTime);
+       // assertTrue("nothing changed: " + changedFiles, changedFiles.isEmpty());
+       //
+       // lastBuildTime = System.currentTimeMillis();
+       // Thread.sleep(100);
+       //      
+       // touch(NEW, false);
+       //
+       // //NEW.createNewFile();
+       // files.add(NEW);
+       // changedFiles = manager.getModifiedFiles(lastBuildTime);
+       // assertTrue("new file: " + changedFiles, changedFiles.contains(NEW));
+       //                
+       // lastBuildTime = System.currentTimeMillis();
+       // Thread.sleep(100);
+       //
+       // files.remove(NEW);
+       // changedFiles = manager.getModifiedFiles(lastBuildTime);
+       // assertTrue("nothing changed", changedFiles.isEmpty());
+       //              
+       // lastBuildTime = System.currentTimeMillis();
+       // Thread.sleep(100);
+       //              
+       // touch(TEMP_1, true);
+       // changedFiles = manager.getModifiedFiles(lastBuildTime);
+       // assertTrue("touched file: " + changedFiles, changedFiles.contains(TEMP_1));
+       //              
+       // lastBuildTime = System.currentTimeMillis();
+       // Thread.sleep(100);
+       //
+       // files.remove(NEW);
+       // changedFiles = manager.getModifiedFiles(lastBuildTime);
+       // assertTrue("nothing changed", changedFiles.isEmpty());
+       //              
+       // TEMP_1.delete();
+       // NEW.delete();
+       // }
+
        // don't do delta's anymore
-//     public void testMakeDeltas() throws IOException, InterruptedException {
-//             AjBuildManager manager = new AjBuildManager(messageWriter);
-//             manager.buildConfig = new AjBuildConfig();
-//             List sourceRoots = new ArrayList();
-//             sourceRoots.add(new File("out"));
-//             manager.buildConfig.setSourceRoots(sourceRoots);
-//             assertTrue(manager.testInit(messageWriter));
-//             List modified = Arrays.asList(new File[] { new File("A.java"), new File("B.java") });
-//             List deleted = Arrays.asList(new File[] { new File("X.java") });
-//             SimpleLookupTable deltas = new SimpleLookupTable();
-//             manager.makeDeltas(
-//                     deltas,
-//                     modified, 
-//                     deleted, 
-//                     ((File)manager.buildConfig.getSourceRoots().get(0)).getPath());
-//             
-//             ResourceDelta d = (ResourceDelta)deltas.get(manager.getJavaBuilder().currentProject);
-//             assertNotNull(d);
-//             
-//             assertEquals(d.getAffectedChildren().length, 3);
-//             //XXX do more testing of children
-//     }
-//     
-//     // XXX should this be working??
-//     public void testDeleteRealFiles() throws CoreException, IOException {
-//             AjBuildManager manager = new AjBuildManager(messageWriter);
-//             manager.buildConfig = new AjBuildConfig();
-//             List sourceRoots = new ArrayList();
-//             sourceRoots.add(new File("testdata/src1"));
-//             manager.buildConfig.setSourceRoots(sourceRoots);
-//             manager.buildConfig.setOutputDir(new File("out"));
-//             assertTrue(manager.testInit(messageWriter));
-//             
-//             File realClassFile = new File("out/X.class");
-//             touch(realClassFile, false);
-//             
-//             assertTrue(realClassFile.exists());
-//             
-//             IFile classfile = manager.classFileCache.getFile(new Path("X.class"));
-//             classfile.create(FileUtil.getStreamFromZip("testdata/testclasses.jar", "Hello.class"), true, null);
-//             assertTrue(classfile.exists());
-//             
-//             manager.addAspectClassFilesToWeaver();
-//             
-//             classfile.delete(true, false, null);
-//             assertTrue(realClassFile.exists());
-//             
-//             manager.addAspectClassFilesToWeaver();
-//             
-//             assertTrue(!realClassFile.exists());    
-//             
-//     }
-       
-       //!!!
-//     public void testIncrementalCompilerCall() throws IOException, InterruptedException, CoreException {
-//             AjBuildManager manager = new AjBuildManager(messageWriter);
-//
-//             manager.buildConfig = new AjBuildConfig();
-//             List roots = new ArrayList();
-//             roots.add(new File("testdata/src1"));
-//        manager.testInit(messageWriter);
-//             manager.buildConfig.setSourceRoots(roots);
-//             assertTrue(manager.testInit(messageWriter));
-//             List modified = Arrays.asList(new File[] { source1, source2 });
-//             List deleted = Arrays.asList(new File[] { source3 });
-//             SimpleLookupTable deltas = new SimpleLookupTable();
-//             manager.makeDeltas(
-//                     deltas,
-//                     modified, 
-//                     deleted, 
-//                     ((File)manager.buildConfig.getSourceRoots().get(0)).getAbsolutePath());
-//             
-//             JavaBuilder jbuilder = manager.getJavaBuilder();
-//             jbuilder.lastState = new State(jbuilder);
-//             jbuilder.binaryLocationsPerProject = new SimpleLookupTable();
-//
-//        AjBuildManager.IncrementalBuilder builder 
-//            = manager.getIncrementalBuilder(messageWriter); // XXX trap errors
-//             TestNotifier testNotifier =  new TestNotifier(builder, jbuilder.currentProject);
-//             jbuilder.notifier = testNotifier;
-//                
-//             IContainer[] sourceFolders = new IContainer[] { 
-//                     new FilesystemFolder(((File)manager.buildConfig.getSourceRoots().get(0)).getAbsolutePath())
-//             };
-//             builder.setSourceFolders(sourceFolders);
-//             testNotifier.builder = builder;
-//             
-//             IFile classfile = manager.classFileCache.getFile(new Path("X.class"));
-//             classfile.create(new ByteArrayInputStream(new byte[] {1,2,3}), true, null);
-//             
-//             assertTrue(classfile.exists());
-//             
-//             
-//             try {
-//            manager.testSetHandler(messageWriter);
-//                     boolean succeeded = builder.build(deltas);
-//             } catch (NonLocalExit nle) {
-//                     assertEquals(nle.getExitCode(), 0);
-//             } finally {
-//            manager.testSetHandler(null);
-//        }
-//             
-//             assertTrue(!classfile.exists());
-//     }
-//     
-//     static class TestNotifier extends BuildNotifier {
-//             int state = 0;
-//             AjBuildManager.IncrementalBuilder builder;
-//             
-//             public TestNotifier(AjBuildManager.IncrementalBuilder builder, IProject project) {
-//                     super(null, project);
-//                     this.builder = builder;
-//             }
-//
-//
-//             public void updateProgressDelta(float percentWorked) {
-//                     switch(state) {
-//                             case 0:
-//                                     checkInitialConfig();
-//                                     break;
-//                             case 1:
-//                                     checkBinaryResources();
-//                                     break;
-//                             case 2:
-//                                     checkAffectedFiles();
-//                                     break;
-//                     }       
-//                     state += 1;
-//             }
-//
-//             private void checkBinaryResources() {
-//             }
-//
-//
-//             private void checkInitialConfig() {
-//                     Collection files = builder.getLocations();
-//                     //System.out.println("initial: " + files);
-//             }
-//
-//             private void checkAffectedFiles() {
-//                     Collection files = builder.getLocations();
-//                     TestUtil.assertSetEquals(Arrays.asList(new String[] { 
-//                             source1.getAbsolutePath().replace(File.separatorChar, '/'),
-//                             source2.getAbsolutePath().replace(File.separatorChar, '/') }), files);
-//                     throw new NonLocalExit(0);
-//             }
-//     }
+       // public void testMakeDeltas() throws IOException, InterruptedException {
+       // AjBuildManager manager = new AjBuildManager(messageWriter);
+       // manager.buildConfig = new AjBuildConfig();
+       // List sourceRoots = new ArrayList();
+       // sourceRoots.add(new File("out"));
+       // manager.buildConfig.setSourceRoots(sourceRoots);
+       // assertTrue(manager.testInit(messageWriter));
+       // List modified = Arrays.asList(new File[] { new File("A.java"), new File("B.java") });
+       // List deleted = Arrays.asList(new File[] { new File("X.java") });
+       // SimpleLookupTable deltas = new SimpleLookupTable();
+       // manager.makeDeltas(
+       // deltas,
+       // modified,
+       // deleted,
+       // ((File)manager.buildConfig.getSourceRoots().get(0)).getPath());
+       //              
+       // ResourceDelta d = (ResourceDelta)deltas.get(manager.getJavaBuilder().currentProject);
+       // assertNotNull(d);
+       //              
+       // assertEquals(d.getAffectedChildren().length, 3);
+       // //XXX do more testing of children
+       // }
+       //      
+       // // XXX should this be working??
+       // public void testDeleteRealFiles() throws CoreException, IOException {
+       // AjBuildManager manager = new AjBuildManager(messageWriter);
+       // manager.buildConfig = new AjBuildConfig();
+       // List sourceRoots = new ArrayList();
+       // sourceRoots.add(new File("testdata/src1"));
+       // manager.buildConfig.setSourceRoots(sourceRoots);
+       // manager.buildConfig.setOutputDir(new File("out"));
+       // assertTrue(manager.testInit(messageWriter));
+       //              
+       // File realClassFile = new File("out/X.class");
+       // touch(realClassFile, false);
+       //              
+       // assertTrue(realClassFile.exists());
+       //              
+       // IFile classfile = manager.classFileCache.getFile(new Path("X.class"));
+       // classfile.create(FileUtil.getStreamFromZip("testdata/testclasses.jar", "Hello.class"), true, null);
+       // assertTrue(classfile.exists());
+       //              
+       // manager.addAspectClassFilesToWeaver();
+       //              
+       // classfile.delete(true, false, null);
+       // assertTrue(realClassFile.exists());
+       //              
+       // manager.addAspectClassFilesToWeaver();
+       //              
+       // assertTrue(!realClassFile.exists());
+       //              
+       // }
 
-//     private void touch(File file, boolean isAppend) throws IOException {
-//             FileOutputStream s = new FileOutputStream(file.getAbsolutePath(), isAppend);
-//             s.write(new byte[] {1,2,3});
-//             s.close();
-//     }
+       // !!!
+       // public void testIncrementalCompilerCall() throws IOException, InterruptedException, CoreException {
+       // AjBuildManager manager = new AjBuildManager(messageWriter);
+       //
+       // manager.buildConfig = new AjBuildConfig();
+       // List roots = new ArrayList();
+       // roots.add(new File("testdata/src1"));
+       // manager.testInit(messageWriter);
+       // manager.buildConfig.setSourceRoots(roots);
+       // assertTrue(manager.testInit(messageWriter));
+       // List modified = Arrays.asList(new File[] { source1, source2 });
+       // List deleted = Arrays.asList(new File[] { source3 });
+       // SimpleLookupTable deltas = new SimpleLookupTable();
+       // manager.makeDeltas(
+       // deltas,
+       // modified,
+       // deleted,
+       // ((File)manager.buildConfig.getSourceRoots().get(0)).getAbsolutePath());
+       //              
+       // JavaBuilder jbuilder = manager.getJavaBuilder();
+       // jbuilder.lastState = new State(jbuilder);
+       // jbuilder.binaryLocationsPerProject = new SimpleLookupTable();
+       //
+       // AjBuildManager.IncrementalBuilder builder
+       // = manager.getIncrementalBuilder(messageWriter); // XXX trap errors
+       // TestNotifier testNotifier = new TestNotifier(builder, jbuilder.currentProject);
+       // jbuilder.notifier = testNotifier;
+       //                
+       // IContainer[] sourceFolders = new IContainer[] {
+       // new FilesystemFolder(((File)manager.buildConfig.getSourceRoots().get(0)).getAbsolutePath())
+       // };
+       // builder.setSourceFolders(sourceFolders);
+       // testNotifier.builder = builder;
+       //              
+       // IFile classfile = manager.classFileCache.getFile(new Path("X.class"));
+       // classfile.create(new ByteArrayInputStream(new byte[] {1,2,3}), true, null);
+       //              
+       // assertTrue(classfile.exists());
+       //              
+       //              
+       // try {
+       // manager.testSetHandler(messageWriter);
+       // boolean succeeded = builder.build(deltas);
+       // } catch (NonLocalExit nle) {
+       // assertEquals(nle.getExitCode(), 0);
+       // } finally {
+       // manager.testSetHandler(null);
+       // }
+       //              
+       // assertTrue(!classfile.exists());
+       // }
+       //      
+       // static class TestNotifier extends BuildNotifier {
+       // int state = 0;
+       // AjBuildManager.IncrementalBuilder builder;
+       //              
+       // public TestNotifier(AjBuildManager.IncrementalBuilder builder, IProject project) {
+       // super(null, project);
+       // this.builder = builder;
+       // }
+       //
+       //
+       // public void updateProgressDelta(float percentWorked) {
+       // switch(state) {
+       // case 0:
+       // checkInitialConfig();
+       // break;
+       // case 1:
+       // checkBinaryResources();
+       // break;
+       // case 2:
+       // checkAffectedFiles();
+       // break;
+       // }
+       // state += 1;
+       // }
+       //
+       // private void checkBinaryResources() {
+       // }
+       //
+       //
+       // private void checkInitialConfig() {
+       // Collection files = builder.getLocations();
+       // //System.out.println("initial: " + files);
+       // }
+       //
+       // private void checkAffectedFiles() {
+       // Collection files = builder.getLocations();
+       // TestUtil.assertSetEquals(Arrays.asList(new String[] {
+       // source1.getAbsolutePath().replace(File.separatorChar, '/'),
+       // source2.getAbsolutePath().replace(File.separatorChar, '/') }), files);
+       // throw new NonLocalExit(0);
+       // }
+       // }
 
+       // private void touch(File file, boolean isAppend) throws IOException {
+       // FileOutputStream s = new FileOutputStream(file.getAbsolutePath(), isAppend);
+       // s.write(new byte[] {1,2,3});
+       // s.close();
+       // }
 
        /*
-        * jar
-        * directory
-        * source directory
-        * container
+        * jar directory source directory container
         */
-//     public void testMakeClasspathLocations() {
-//             List classpath = new ArrayList();
-//             classpath.add(
-//             
-//             AjBuildConfig config = new AjBuildConfig();
-//             config.setClasspath()
-//     }
-       
-//     private void testClasspathLocation(String loca
-
+       // public void testMakeClasspathLocations() {
+       // List classpath = new ArrayList();
+       // classpath.add(
+       //              
+       // AjBuildConfig config = new AjBuildConfig();
+       // config.setClasspath()
+       // }
+       // private void testClasspathLocation(String loca
 }
index 5f4d217ec9e22b6fa1cdc8cfcc7d5da7043adbc0..7330108d719ea0726d1ad07cae6c630c0ae3e185 100644 (file)
@@ -23,7 +23,6 @@ import java.util.StringTokenizer;
 
 import junit.framework.AssertionFailedError;
 
-
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IProgramElement;
 import org.aspectj.asm.IRelationshipMap;
@@ -38,103 +37,104 @@ import org.aspectj.bridge.context.CompilationAndWeavingContext;
 import org.aspectj.util.FileUtil;
 
 /**
- * The Ajc class is intended for use as part of a unit-test suite, it drives
- * the AspectJ compiler and lets you check the compilation results. Compilations
- * run in a sandbox that is created in C:\temp\ajcSandbox or /tmp/ajcSandbox
- * depending on your platform.
+ * The Ajc class is intended for use as part of a unit-test suite, it drives the AspectJ compiler and lets you check the compilation
+ * results. Compilations run in a sandbox that is created in C:\temp\ajcSandbox or /tmp/ajcSandbox depending on your platform.
  * <p>
- * The expected usage of Ajc is through the TestCase superclass,
- * AjcTestCase, which provides helper methods that conveniently 
- * drive the base functions exposed by this class.
+ * The expected usage of Ajc is through the TestCase superclass, AjcTestCase, which provides helper methods that conveniently drive
+ * the base functions exposed by this class.
  * </p>
+ * 
  * @see org.aspectj.tools.ajc.AjcTestCase
  */
 public class Ajc {
 
        private static final String SANDBOX_NAME = "ajcSandbox";
 
-       private static final String TESTER_PATH = 
-               ".."+File.separator+"testing-client"+File.separator+"bin"
-           + File.pathSeparator+".."+File.separator+"runtime"   +File.separator+"bin"
-               + File.pathSeparator+".."+File.separator+"aspectj5rt"+File.separator+"bin"
-        + File.pathSeparator+".."+File.separator+"lib"       +File.separator+"junit"+File.separator+"junit.jar"
-        + File.pathSeparator+".."+File.separator+"bridge"    +File.separator+"bin" 
-        + File.pathSeparator+".."+File.separator+"loadtime"  +File.separator+"bin"
-        + File.pathSeparator+".."+File.separator+"weaver"    +File.separator+"bin"
-        + File.pathSeparator+".."+File.separator+"weaver5"   +File.separator+"bin"
-        
-        // When the build machine executes the tests, it is using code built into jars rather than code build into
-        // bin directories.  This means for the necessary types to be found we have to put these jars on the classpath:
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"bridge.jar"
-        + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"util.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"loadtime.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver5.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"asm.jar"
-               + File.pathSeparator+".."+File.separator+"lib"     +File.separator+"test"+File.separator+"testing-client.jar"
-               // hmmm, this next one should perhaps point to an aj-build jar...
-               + File.pathSeparator+".."+File.separator+"lib"     +File.separator+"test"+File.separator+"aspectjrt.jar"
-               ;
-
+       private static final String TESTER_PATH = ".." + File.separator + "testing-client" + File.separator + "bin"
+                       + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + "bin" + File.pathSeparator + ".."
+                       + File.separator + "aspectj5rt" + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "lib"
+                       + File.separator + "junit" + File.separator + "junit.jar" + File.pathSeparator + ".." + File.separator + "bridge"
+                       + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "loadtime" + File.separator
+                       + "bin"
+                       + File.pathSeparator
+                       + ".."
+                       + File.separator
+                       + "weaver"
+                       + File.separator
+                       + "bin"
+                       + File.pathSeparator
+                       + ".."
+                       + File.separator
+                       + "weaver5"
+                       + File.separator
+                       + "bin"
 
+                       // When the build machine executes the tests, it is using code built into jars rather than code build into
+                       // bin directories. This means for the necessary types to be found we have to put these jars on the classpath:
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "bridge.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "util.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "loadtime.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver5.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "asm.jar"
+                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "testing-client.jar"
+                       // hmmm, this next one should perhaps point to an aj-build jar...
+                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar";
 
        private CompilationResult result;
        private File sandbox;
        private File baseDir;
-       private Main main;
+       private final Main main;
        private String[] ajcArgs;
        private int incrementalStage = 10;
        private boolean shouldEmptySandbox = true;
-       private AjcCommandController controller;
-       private static boolean verbose = System.getProperty("org.aspectj.tools.ajc.Ajc.verbose","true").equals("true");
+       private final AjcCommandController controller;
+       private static boolean verbose = System.getProperty("org.aspectj.tools.ajc.Ajc.verbose", "true").equals("true");
 
        /**
-        * Constructs a new Ajc instance, with a new AspectJ compiler
-        * inside. 
+        * Constructs a new Ajc instance, with a new AspectJ compiler inside.
         */
        public Ajc() {
                main = new Main();
                controller = new AjcCommandController();
                main.setController(controller);
        }
-       
+
        /**
-        * By default, each call to <code>compile</code> creates a new
-        * sandbox (C:\temp\ajcSandbox\ajtTestxxx.tmp, or /tmp/ajcSandbox/ajcTestxxx.tmp
-        * depending on your platform). To write a test that performs multiple
-        * (non-incremental) compiles, building on the results of previous
-        * compilations, set 'should empty sandbox' to false after the first
-        * compile, which will cause subsequent compiles in the test to use the
-        * same directory and contents.
+        * By default, each call to <code>compile</code> creates a new sandbox (C:\temp\ajcSandbox\ajtTestxxx.tmp, or
+        * /tmp/ajcSandbox/ajcTestxxx.tmp depending on your platform). To write a test that performs multiple (non-incremental)
+        * compiles, building on the results of previous compilations, set 'should empty sandbox' to false after the first compile,
+        * which will cause subsequent compiles in the test to use the same directory and contents.
         */
        public void setShouldEmptySandbox(boolean empty) {
                this.shouldEmptySandbox = empty;
        }
-       
+
        /**
-        * Call the compiler with the given arguments (args are exactly the same
-        * as you would pass to ajc on the command-line). The results of the 
-        * compile are returned in a <code>CompilationResult</code>, which
-        * provides for easy testing of results.
-        * <p>The compilation happens in a sandbox (C:\temp\ajcSandbox\ajTestxxx.tmp or
-        * /tmp/ajcSandbox/ajcTestxxx.tmp depending on platform). Compiler arguments are
-        * adapted to the sandbox as follows.</p>
-        * <p>For every file or directory listed in an argument (source file, or component
-        * of inpath, aspectpath, sourceroots, classpath,...), if the file is specified
-        * using an absolute path then it is left unchanged, but if the file is specified
-        * using a relative path, and a base directory (see setBaseDir) has been provided,
-        * then files/directories are copied from the base directory to the sandbox, and the
-        * compiler arguments adjusted to reflect their new location. 
+        * Call the compiler with the given arguments (args are exactly the same as you would pass to ajc on the command-line). The
+        * results of the compile are returned in a <code>CompilationResult</code>, which provides for easy testing of results.
+        * <p>
+        * The compilation happens in a sandbox (C:\temp\ajcSandbox\ajTestxxx.tmp or /tmp/ajcSandbox/ajcTestxxx.tmp depending on
+        * platform). Compiler arguments are adapted to the sandbox as follows.
         * </p>
-        * <p>For example, given a baseDir of "tests/pr12345" and a compile command: 
-        * "ajc src/A.java src/B.java", the files in 
+        * <p>
+        * For every file or directory listed in an argument (source file, or component of inpath, aspectpath, sourceroots,
+        * classpath,...), if the file is specified using an absolute path then it is left unchanged, but if the file is specified using
+        * a relative path, and a base directory (see setBaseDir) has been provided, then files/directories are copied from the base
+        * directory to the sandbox, and the compiler arguments adjusted to reflect their new location.
+        * </p>
+        * <p>
+        * For example, given a baseDir of "tests/pr12345" and a compile command: "ajc src/A.java src/B.java", the files in
+        * 
         * <pre>
         *    tests/pr12345/
         *                  src/
         *                      A.java
         *                      B.java
         * </pre>
+        * 
         * are copied to:
+        * 
         * <pre>
         *     ajcSandbox/ajcTestxxx.tmp/
         *                               src/
@@ -142,34 +142,31 @@ public class Ajc {
         *                                   B.java
         * </pre>
         * <p>
-        * If no classpath is specified (no -classpath in the arguments) the classpath will
-        * be set to include the sandbox directory, testing-client/bin (for the Tester class), 
-        * and runtime/bin (for the AspectJ runtime). If a classpath <i>is</i> specified,
-        * then any relative directories in it will be made relative to the sandbox, and
-        * the testing-client and runtime bin directories are also added.
+        * If no classpath is specified (no -classpath in the arguments) the classpath will be set to include the sandbox directory,
+        * testing-client/bin (for the Tester class), and runtime/bin (for the AspectJ runtime). If a classpath <i>is</i> specified,
+        * then any relative directories in it will be made relative to the sandbox, and the testing-client and runtime bin directories
+        * are also added.
         * </p>
         * <p>
-        * If no output directory is specified (no -d in the arguments), the output directory
-        * is set to the sandbox. If a directory is specified, and the path is relative, it
-        * will be made relative to the sandbox.
+        * If no output directory is specified (no -d in the arguments), the output directory is set to the sandbox. If a directory is
+        * specified, and the path is relative, it will be made relative to the sandbox.
         * </p>
         * <ul>
         * </ul>
         * </p>
-        * @param args The compiler arguments. 
-        * @return a CompilationResult object with all the messages produced by
-        * the compiler, a description of the ajc command that was issued,
-        * and the standard output and error of the compile (excluding messages
-        * which are provided separately)
+        * 
+        * @param args The compiler arguments.
+        * @return a CompilationResult object with all the messages produced by the compiler, a description of the ajc command that was
+        *         issued, and the standard output and error of the compile (excluding messages which are provided separately)
         * @throws IOException
         * @see org.aspectj.tools.ajc.CompilationResult
         */
        public CompilationResult compile(String[] args) throws IOException {
                incrementalStage = 10;
-               return compile(args,false);
+               return compile(args, false);
        }
-       
-       private CompilationResult compile(String[] args,boolean isIncremental) throws IOException {
+
+       private CompilationResult compile(String[] args, boolean isIncremental) throws IOException {
                result = null;
                ajcArgs = args;
                ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -186,32 +183,35 @@ public class Ajc {
                List warnings = new ArrayList();
                List infos = new ArrayList();
                List weaves = new ArrayList();
-               
+
                try {
                        if (!isIncremental && shouldEmptySandbox) {
                                sandbox = createEmptySandbox();
                        }
-                       args = adjustToSandbox(args,!isIncremental);
+                       args = adjustToSandbox(args, !isIncremental);
                        MessageHandler holder = new MessageHandler();
                        holder.setInterceptor(new AbortInterceptor());
                        main.setHolder(holder);
-                       if (incrementalStage==10 && hasSpecifiedIncremental(args)) {
-                         // important to sleep after preparing the sandbox on first incremental stage (see notes in pr90806)
-                         try { Thread.sleep(1000); } catch (Exception e) {}
+                       if (incrementalStage == 10 && hasSpecifiedIncremental(args)) {
+                               // important to sleep after preparing the sandbox on first incremental stage (see notes in pr90806)
+                               try {
+                                       Thread.sleep(1000);
+                               } catch (Exception e) {
+                               }
                        }
                        if (isIncremental) {
                                controller.doIncremental(holder);
                        } else {
-                               main.runMain(args,false);
+                               main.runMain(args, false);
                        }
-                       addMessagesTo(infos,holder.getMessages(IMessage.INFO,false));
-                       addMessagesTo(warnings,holder.getWarnings());
-                       addMessagesTo(errors,holder.getErrors());
-                       addMessagesTo(fails,holder.getMessages(IMessage.FAIL,true));
-                       addMessagesTo(weaves,holder.getMessages(IMessage.WEAVEINFO,false));
+                       addMessagesTo(infos, holder.getMessages(IMessage.INFO, false));
+                       addMessagesTo(warnings, holder.getWarnings());
+                       addMessagesTo(errors, holder.getErrors());
+                       addMessagesTo(fails, holder.getMessages(IMessage.FAIL, true));
+                       addMessagesTo(weaves, holder.getMessages(IMessage.WEAVEINFO, false));
                        String stdOut = new String(out.toByteArray());
                        String stdErr = new String(err.toByteArray());
-                       result = new CompilationResult(args,stdOut,stdErr,infos,errors,warnings,fails,weaves);
+                       result = new CompilationResult(args, stdOut, stdErr, infos, errors, warnings, fails, weaves);
                } finally {
                        System.setOut(systemOut);
                        System.setErr(systemErr);
@@ -223,119 +223,126 @@ public class Ajc {
                }
                return result;
        }
-       
+
        private boolean hasSpecifiedIncremental(String[] args) {
-               if (args==null) return false;
+               if (args == null)
+                       return false;
                for (int i = 0; i < args.length; i++) {
-                       if (args[i].equals("-incremental")) return true;
+                       if (args[i].equals("-incremental"))
+                               return true;
                }
                return false;
        }
 
        /**
-        * After compiling for the first time with compile(), if the -incremental option was specified
-        * you can do as many subsequent incremental compiles as you like by calling this method.
+        * After compiling for the first time with compile(), if the -incremental option was specified you can do as many subsequent
+        * incremental compiles as you like by calling this method.
         * <p>
-        * Throws an IllegalStateException if you try and call this method without first doing a compile
-        * that specified the -incremental option.
+        * Throws an IllegalStateException if you try and call this method without first doing a compile that specified the -incremental
+        * option.
         * </p>
+        * 
         * @return A CompilationResult giving the results of the most recent increment.
         * @throws IOException
         */
        public CompilationResult doIncrementalCompile() throws IOException {
                if ((ajcArgs == null) || !isIncremental(ajcArgs)) {
-                       throw new IllegalStateException("Can't do incremental compile unless -incremental specified and first compile has taken place");
+                       throw new IllegalStateException(
+                                       "Can't do incremental compile unless -incremental specified and first compile has taken place");
                }
                incrementalStage += 10;
-               return compile(ajcArgs,true);
+               return compile(ajcArgs, true);
        }
-       
+
        /**
-        * Return the result of the last compile or incremental compile. This is the same as the 
-        * return value from the compile() or doIncrementalCompile() methods.
+        * Return the result of the last compile or incremental compile. This is the same as the return value from the compile() or
+        * doIncrementalCompile() methods.
         */
-       public CompilationResult getLastCompilationResult() { 
+       public CompilationResult getLastCompilationResult() {
                return result;
        }
-       
+
        /**
         * Get the sandbox directory used for the compilation.
         */
        public File getSandboxDirectory() {
-               if (sandbox == null) {sandbox = createEmptySandbox();}
+               if (sandbox == null) {
+                       sandbox = createEmptySandbox();
+               }
                return sandbox;
        }
-       
+
        /**
-        * Set the base directory relative to which all relative paths specified in the arguments to a compile will be
-        * interpreted.
+        * Set the base directory relative to which all relative paths specified in the arguments to a compile will be interpreted.
         */
        public void setBaseDir(File dir) {
-               if ((dir != null) && !dir.isDirectory()) throw new IllegalArgumentException(dir.getPath() + " is not a directory");
+               if ((dir != null) && !dir.isDirectory())
+                       throw new IllegalArgumentException(dir.getPath() + " is not a directory");
                baseDir = dir;
        }
-       
+
        private void addMessagesTo(List aList, IMessage[] messages) {
                for (int i = 0; i < messages.length; i++) {
                        aList.add(messages[i]);
                }
        }
-       
+
        private boolean isIncremental(String[] args) {
                for (int i = 0; i < args.length; i++) {
-                       if (args[i].trim().equals("-incremental")) return true;
+                       if (args[i].trim().equals("-incremental"))
+                               return true;
                }
                return false;
        }
 
        public static File createEmptySandbox() {
                File sandbox;
-               
+
                String os = System.getProperty("os.name");
                File tempDir = null;
                // AMC - I did this rather than use the JDK default as I hate having to go look
                // in c:\documents and settings\......... for the results of a failed test.
                if (os.startsWith("Windows")) {
                        tempDir = new File("C:\\temp");
-                       if (!tempDir.exists()) {tempDir.mkdir();}
+                       if (!tempDir.exists()) {
+                               tempDir.mkdir();
+                       }
                } else {
-                       tempDir = new File("/tmp");
+                       tempDir = new File("/tmp");
                }
-               File sandboxRoot = new File(tempDir,SANDBOX_NAME);
+               File sandboxRoot = new File(tempDir, SANDBOX_NAME);
                if (!sandboxRoot.exists()) {
                        sandboxRoot.mkdir();
                }
-       
-       
+
                try {
                        File workspace = new File(".." + File.separator);
                        String workspaceName = workspace.getCanonicalPath();
                        int index = workspaceName.lastIndexOf(File.separator);
-                       workspaceName = workspaceName.substring(index+1);
-       
-                       File workspaceRoot = new File(sandboxRoot,workspaceName);
+                       workspaceName = workspaceName.substring(index + 1);
+
+                       File workspaceRoot = new File(sandboxRoot, workspaceName);
                        if (!workspaceRoot.exists()) {
                                workspaceRoot.mkdir();
                        }
-                       
+
                        FileUtil.deleteContents(workspaceRoot);
-       
-                       sandbox = File.createTempFile("ajcTest",".tmp",workspaceRoot);
+
+                       sandbox = File.createTempFile("ajcTest", ".tmp", workspaceRoot);
                        sandbox.delete();
                        sandbox.mkdir();
-       
+
                } catch (IOException ioEx) {
                        throw new AssertionFailedError("Unable to create sandbox directory for test");
                }
-               
+
                return sandbox;
        }
 
        /**
-        * Make every relative file name and dir be absolute under sandbox
-        * Add TESTER_PATH to classpath
+        * Make every relative file name and dir be absolute under sandbox Add TESTER_PATH to classpath
         */
-       private String[] adjustToSandbox(String[] args,boolean doCopy) throws IOException {
+       private String[] adjustToSandbox(String[] args, boolean doCopy) throws IOException {
                String[] newArgs = new String[args.length];
                boolean hasClasspath = false;
                boolean hasOutdir = false;
@@ -343,118 +350,114 @@ public class Ajc {
                        newArgs[i] = args[i];
                        if (FileUtil.hasSourceSuffix(args[i])) {
                                File f = new File(args[i]);
-                               //newArgs[i] = new File(baseDir,args[i]).getAbsolutePath(); // might be quicker?
-                               newArgs[i] = adjustFileOrDir(f,doCopy).getAbsolutePath();
+                               // newArgs[i] = new File(baseDir,args[i]).getAbsolutePath(); // might be quicker?
+                               newArgs[i] = adjustFileOrDir(f, doCopy).getAbsolutePath();
                        } else {
-                               if ((args[i].equals("-aspectpath") ||
-                                    args[i].equals("-inpath") ||
-                                        args[i].equals("-injars") ||
-                                        args[i].equals("-outjar") ||
-                                        args[i].equals("-classpath") ||
-                                        args[i].equals("-sourceroots") ||
-                                        args[i].equals("-Xlintfile") ||
-                                        args[i].equals("-extdirs") ||
-                                        args[i].equals("-d")) &&
-                                       args.length > (i+1)) {
+                               if ((args[i].equals("-aspectpath") || args[i].equals("-inpath") || args[i].equals("-injars")
+                                               || args[i].equals("-outjar") || args[i].equals("-classpath") || args[i].equals("-sourceroots")
+                                               || args[i].equals("-Xlintfile") || args[i].equals("-extdirs") || args[i].equals("-d"))
+                                               && args.length > (i + 1)) {
                                        newArgs[i] = args[i];
                                        StringBuffer buff = new StringBuffer();
                                        boolean copyThisTime = doCopy;
-                                       if (args[i].equals("-d")) { 
+                                       if (args[i].equals("-d")) {
                                                copyThisTime = false;
                                                hasOutdir = true;
                                        }
-                                   StringTokenizer strTok = new StringTokenizer(args[++i],File.pathSeparator);
-                                   while (strTok.hasMoreTokens()) {
-                                       File f = new File(strTok.nextToken());
-                                       buff.append(adjustFileOrDir(f,copyThisTime).getAbsolutePath());
-                                       if (strTok.hasMoreTokens()) buff.append(File.pathSeparator);
-                                   }
-                                   newArgs[i] = buff.toString();
-                                   if (args[i-1].equals("-classpath")) {
-                                       hasClasspath = true;
-                                       newArgs[i] = newArgs[i] + File.pathSeparator + TESTER_PATH + File.pathSeparator + getSandboxDirectory().getAbsolutePath();
-                                   }
+                                       StringTokenizer strTok = new StringTokenizer(args[++i], File.pathSeparator);
+                                       while (strTok.hasMoreTokens()) {
+                                               File f = new File(strTok.nextToken());
+                                               buff.append(adjustFileOrDir(f, copyThisTime).getAbsolutePath());
+                                               if (strTok.hasMoreTokens())
+                                                       buff.append(File.pathSeparator);
+                                       }
+                                       newArgs[i] = buff.toString();
+                                       if (args[i - 1].equals("-classpath")) {
+                                               hasClasspath = true;
+                                               newArgs[i] = newArgs[i] + File.pathSeparator + TESTER_PATH + File.pathSeparator
+                                                               + getSandboxDirectory().getAbsolutePath();
+                                       }
                                } else {
                                        // could be resource file
                                        File f = new File(args[i]);
                                        if (f.exists()) {
-                                               newArgs[i] = adjustFileOrDir(f,doCopy).getAbsolutePath();
+                                               newArgs[i] = adjustFileOrDir(f, doCopy).getAbsolutePath();
                                        }
                                }
-                       } 
+                       }
                }
                if (!hasClasspath) {
                        String[] oldArgs = newArgs;
                        newArgs = new String[oldArgs.length + 2];
-                       System.arraycopy(oldArgs,0,newArgs,0,oldArgs.length);
+                       System.arraycopy(oldArgs, 0, newArgs, 0, oldArgs.length);
                        newArgs[oldArgs.length] = "-classpath";
                        newArgs[oldArgs.length + 1] = TESTER_PATH + File.pathSeparator + getSandboxDirectory().getAbsolutePath();
                }
                if (!hasOutdir) {
                        String[] oldArgs = newArgs;
                        newArgs = new String[oldArgs.length + 2];
-                       System.arraycopy(oldArgs,0,newArgs,0,oldArgs.length);
+                       System.arraycopy(oldArgs, 0, newArgs, 0, oldArgs.length);
                        newArgs[oldArgs.length] = "-d";
-                       newArgs[oldArgs.length + 1] = getSandboxDirectory().getPath();                  
+                       newArgs[oldArgs.length + 1] = getSandboxDirectory().getPath();
                }
                return newArgs;
        }
-       
-       private File adjustFileOrDir(File from,boolean doCopy) throws IOException {
+
+       private File adjustFileOrDir(File from, boolean doCopy) throws IOException {
                File to = from;
                File ret = from;
                if (!from.isAbsolute()) {
-                       ret = new File(sandbox,from.getPath());
+                       ret = new File(sandbox, from.getPath());
                        File fromParent = from.getParentFile();
                        String relativeToPath = (fromParent != null) ? (fromParent.getPath() + File.separator) : "";
                        if (baseDir != null) {
-                               from = new File(baseDir,from.getPath());
+                               from = new File(baseDir, from.getPath());
                        }
-                       if (!from.exists()) return ret;
+                       if (!from.exists())
+                               return ret;
                        if (doCopy) {
                                // harness requires that any files with the same name, and a different extension,
                                // get copied too (e.g. .out, .err, .event files)
                                if (from.isFile()) {
-                                       final String prefix = from.getName().substring(0,from.getName().lastIndexOf('.'));
+                                       final String prefix = from.getName().substring(0, from.getName().lastIndexOf('.'));
                                        String[] toCopy = from.getParentFile().list(new FilenameFilter() {
                                                public boolean accept(File dir, String name) {
-                                                       if (name.indexOf('.') == -1) return false;
-                                                       String toMatch = name.substring(0,name.lastIndexOf('.'));
+                                                       if (name.indexOf('.') == -1)
+                                                               return false;
+                                                       String toMatch = name.substring(0, name.lastIndexOf('.'));
                                                        return (toMatch.equals(prefix));
                                                }
-                                               });
+                                       });
                                        for (int i = 0; i < toCopy.length; i++) {
                                                String toPath = relativeToPath + toCopy[i];
-                                               to = new File(sandbox,toPath);
-                                               FileUtil.copyFile(new File(from.getParentFile(),toCopy[i]),
-                                                                         to);                                  
+                                               to = new File(sandbox, toPath);
+                                               FileUtil.copyFile(new File(from.getParentFile(), toCopy[i]), to);
                                        }
                                } else {
-                                       FileUtil.copyFile(from,ret);
+                                       FileUtil.copyFile(from, ret);
                                }
                        }
                }
                return ret;
        }
-       
-       public static void dumpAJDEStructureModel(String prefix) {
-               dumpAJDEStructureModel(prefix, false);
+
+       public static void dumpAJDEStructureModel(AsmManager model, String prefix) {
+               dumpAJDEStructureModel(model, prefix, false);
        }
-       
-       public static void dumpAJDEStructureModel(String prefix, boolean useHandles) {
+
+       public static void dumpAJDEStructureModel(AsmManager model, String prefix, boolean useHandles) {
                System.out.println("======================================");//$NON-NLS-1$
-               System.out.println("start of AJDE structure model:"+prefix); //$NON-NLS-1$
+               System.out.println("start of AJDE structure model:" + prefix); //$NON-NLS-1$
 
-               IRelationshipMap asmRelMap = AsmManager.getDefault().getRelationshipMap();
+               IRelationshipMap asmRelMap = model.getRelationshipMap();
                for (Iterator iter = asmRelMap.getEntries().iterator(); iter.hasNext();) {
                        String sourceOfRelationship = (String) iter.next();
-                       System.err.println("Examining source relationship handle: "+sourceOfRelationship);
+                       System.err.println("Examining source relationship handle: " + sourceOfRelationship);
                        List relationships = null;
                        if (useHandles) {
                                relationships = asmRelMap.get(sourceOfRelationship);
                        } else {
-                               IProgramElement ipe = AsmManager.getDefault().getHierarchy()
-                                                                               .findElementForHandle(sourceOfRelationship);
+                               IProgramElement ipe = model.getHierarchy().findElementForHandle(sourceOfRelationship);
                                relationships = asmRelMap.get(ipe);
                        }
                        if (relationships != null) {
@@ -463,14 +466,14 @@ public class Ajc {
                                        List targets = rel.getTargets();
                                        for (Iterator iterator2 = targets.iterator(); iterator2.hasNext();) {
                                                String t = (String) iterator2.next();
-                                               IProgramElement link = AsmManager.getDefault().getHierarchy().findElementForHandle(t);
+                                               IProgramElement link = model.getHierarchy().findElementForHandle(t);
                                                System.out.println(""); //$NON-NLS-1$
                                                System.out.println("      sourceOfRelationship " + sourceOfRelationship); //$NON-NLS-1$
                                                System.out.println("          relationship " + rel.getName()); //$NON-NLS-1$
                                                System.out.println("              target " + link.getName()); //$NON-NLS-1$
                                        }
                                }
-                               
+
                        }
                }
                System.out.println("End of AJDE structure model"); //$NON-NLS-1$
@@ -479,30 +482,34 @@ public class Ajc {
 }
 
 /*
- * So that we can drive incremental compilation easily from a unit
- * test.
+ * So that we can drive incremental compilation easily from a unit test.
  */
 class AjcCommandController extends Main.CommandController {
-       
+
        private ICommand command;
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.tools.ajc.Main.CommandController#doRepeatCommand()
         */
        boolean doRepeatCommand(ICommand command) {
                this.command = command;
-               return false;  // ensure that control returns to caller
+               return false; // ensure that control returns to caller
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see org.aspectj.tools.ajc.Main.CommandController#running()
         */
        public boolean running() {
-               return false;  // so that we can come back for more...
+               return false; // so that we can come back for more...
        }
-       
+
        public void doIncremental(IMessageHandler handler) {
-               if (command == null) throw new IllegalArgumentException("Can't repeat command until it has executed at least once!");
+               if (command == null)
+                       throw new IllegalArgumentException("Can't repeat command until it has executed at least once!");
                command.repeatCommand(handler);
        }
 }
@@ -517,13 +524,14 @@ class AbortInterceptor implements IMessageHandler {
                        if (message.getThrown() != null) {
                                System.err.println("caused by " + message.getThrown().toString());
                        }
-                       
-               }  // allow message to accumulate... 
+
+               } // allow message to accumulate...
                return false;
        }
 
        public boolean isIgnoring(Kind kind) {
-               if (kind != IMessage.ABORT) return true;
+               if (kind != IMessage.ABORT)
+                       return true;
                return false;
        }
 
index 2abb07d85a7c0998841ba1beb00279fe763a2546..1a8da29741aa36d0a3535fc4ec7de9cb99adc5e0 100644 (file)
@@ -34,17 +34,16 @@ import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.testing.util.TestUtil;
 
 /**
- * A TestCase class that acts as the superclass for all test cases wishing
- * to drive the ajc compiler.
+ * A TestCase class that acts as the superclass for all test cases wishing to drive the ajc compiler.
  * <p>
- * This class provides a number of utility methods that make programmatic 
- * testing of the compiler easy. See AjcTestCaseTest for a couple of simple
- * tests written using this class.
+ * This class provides a number of utility methods that make programmatic testing of the compiler easy. See AjcTestCaseTest for a
+ * couple of simple tests written using this class.
  * </p>
  * <p>
- * See the XMLBasedAjcTestCase subclass for TestCase class that can be 
- * used to drive compiler tests based on an ajcTests.xml format test
- * specification file.</p>
+ * See the XMLBasedAjcTestCase subclass for TestCase class that can be used to drive compiler tests based on an ajcTests.xml format
+ * test specification file.
+ * </p>
+ * 
  * @see org.aspectj.tools.ajc.AjcTestCase.Message
  * @see org.aspectj.tools.ajc.AjcTestCase.MessageSpec
  * @see org.aspectj.tools.ajc.AjcTestCase.RunResult
@@ -52,51 +51,56 @@ import org.aspectj.testing.util.TestUtil;
  * @see org.aspectj.testing.XMLBasedAjcTestCase
  */
 public class AjcTestCase extends TestCase {
-       
+
        private RunResult lastRunResult;
-       
+
        /**
-        * The Ajc (compiler) instance used for thet test. Created afresh
-        * during the test setup.
+        * The Ajc (compiler) instance used for the test. Created afresh during the test setup.
         */
        protected Ajc ajc;
-       
-       public static final String DEFAULT_CLASSPATH_ENTRIES = 
-               File.pathSeparator + ".." + File.separator + "bridge" + File.separator + "bin"
-               + File.pathSeparator + ".." + File.separator + "util" + File.separator + "bin"
-        + File.pathSeparator+ ".."+File.separator+"loadtime"+File.separator+"bin" 
-        + File.pathSeparator+ ".."+File.separator+"weaver"+File.separator+"bin" 
-        + File.pathSeparator+ ".."+File.separator+"weaver5"+File.separator+"bin" 
-        + File.pathSeparator+ ".."+File.separator+"asm"+File.separator+"bin" 
-               + File.pathSeparator + ".." + File.separator + "testing-client" + File.separator + "bin"
-        + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + "bin"
-               + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin"
-               + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"junit"+File.separator+"junit.jar"
-        + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"bcel"+File.separator+"bcel.jar" 
-        + File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"bcel"+File.separator+"bcel-verifier.jar" 
-        
-        // When the build machine executes the tests, it is using code built into jars rather than code build into
-        // bin directories.  This means for the necessary types to be found we have to put these jars on the classpath:
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"bridge.jar"
-        + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"util.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"loadtime.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver5.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"asm.jar"
-               + File.pathSeparator+".."+File.separator+"lib"     +File.separator+"test"+File.separator+"testing-client.jar"
-               // hmmm, this next one should perhaps point to an aj-build jar...
-               + File.pathSeparator+".."+File.separator+"lib"     +File.separator+"test"+File.separator+"aspectjrt.jar"
-        ;
-       
-       public static final String JAVA5_CLASSPATH_ENTRIES = 
-               File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin"
-        + File.pathSeparator+ ".."+File.separator+"loadtime5"+File.separator+"bin" 
-        + File.pathSeparator+ ".."+File.separator+"weaver5"+File.separator+"bin" 
-
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"aspectj5rt.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"loadtime5.jar"
-               + File.pathSeparator+".."+File.separator+"aj-build"+File.separator+"jars"+File.separator+"weaver5.jar";
-        
+
+       public static final String DEFAULT_CLASSPATH_ENTRIES = File.pathSeparator + ".." + File.separator + "bridge" + File.separator
+                       + "bin" + File.pathSeparator + ".." + File.separator + "util" + File.separator + "bin" + File.pathSeparator + ".."
+                       + File.separator + "loadtime" + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "weaver"
+                       + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "weaver5" + File.separator + "bin"
+                       + File.pathSeparator + ".." + File.separator + "asm" + File.separator + "bin" + File.pathSeparator + ".."
+                       + File.separator + "testing-client" + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "runtime"
+                       + File.separator + "bin" + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + "bin"
+                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar"
+                       + File.pathSeparator + ".." + File.separator + "lib"
+                       + File.separator
+                       + "bcel"
+                       + File.separator
+                       + "bcel.jar"
+                       + File.pathSeparator
+                       + ".."
+                       + File.separator
+                       + "lib"
+                       + File.separator
+                       + "bcel"
+                       + File.separator
+                       + "bcel-verifier.jar"
+
+                       // When the build machine executes the tests, it is using code built into jars rather than code build into
+                       // bin directories. This means for the necessary types to be found we have to put these jars on the classpath:
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "bridge.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "util.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "loadtime.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver5.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "asm.jar"
+                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "testing-client.jar"
+                       // hmmm, this next one should perhaps point to an aj-build jar...
+                       + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar";
+
+       public static final String JAVA5_CLASSPATH_ENTRIES = File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator
+                       + "bin" + File.pathSeparator + ".." + File.separator + "loadtime5" + File.separator + "bin" + File.pathSeparator + ".."
+                       + File.separator + "weaver5" + File.separator + "bin"
+
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "aspectj5rt.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "loadtime5.jar"
+                       + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "weaver5.jar";
+
        /*
         * Save reference to real stderr and stdout before starting redirection
         */
@@ -104,16 +108,16 @@ public class AjcTestCase extends TestCase {
        public final static PrintStream out = System.out;
        private final static DelegatingOutputStream delegatingErr;
        private final static DelegatingOutputStream delegatingOut;
-       public final static boolean DEFAULT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose",true); 
-       public final static boolean DEFAULT_ERR_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.err",DEFAULT_VERBOSE); 
-       public final static boolean DEFAULT_OUT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.out",DEFAULT_VERBOSE); 
+       public final static boolean DEFAULT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose", true);
+       public final static boolean DEFAULT_ERR_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.err", DEFAULT_VERBOSE);
+       public final static boolean DEFAULT_OUT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.out", DEFAULT_VERBOSE);
 
        /**
-        * Helper class that represents the specification of an individual
-        * message expected to be produced during a compilation run.
+        * Helper class that represents the specification of an individual message expected to be produced during a compilation run.
         * <p>
-        * Message objects are combined in a MessageSpec which can then be 
-        * passed to the various assertMessage methods.</p>
+        * Message objects are combined in a MessageSpec which can then be passed to the various assertMessage methods.
+        * </p>
+        * 
         * @see org.aspectj.tools.ajc.AjcTestCase.MessageSpec
         */
        public static class Message {
@@ -121,34 +125,32 @@ public class AjcTestCase extends TestCase {
                private String text;
                private String sourceFileName;
                private ISourceLocation[] seeAlsos;
-               
+
                /**
-                * Create a message that will match any compiler message on
-                * the given line.
+                * Create a message that will match any compiler message on the given line.
                 */
                public Message(int line) {
                        this.line = line;
                }
-               
+
                /**
-                * Create a message that will match any compiler message on
-                * the given line, where the message text contains <code>text</code>.
+                * Create a message that will match any compiler message on the given line, where the message text contains
+                * <code>text</code>.
                 */
                public Message(int line, String text) {
                        this.line = line;
                        this.text = text;
                }
-               
+
                /**
-                * Create a message that will match any compiler message on
-                * the given line, where the message text contains <code>text</code>.
+                * Create a message that will match any compiler message on the given line, where the message text contains
+                * <code>text</code>.
                 * <p>
-                * If srcFile is non-null, the source file location of the message must
-                * end with <code>srcFile</code>.
+                * If srcFile is non-null, the source file location of the message must end with <code>srcFile</code>.
                 * </p>
                 * <p>
-                * If <code>seeAlso</code> is non-null, each source location in seeAlso
-                * must be matched by an extraSourceLocation in the message.
+                * If <code>seeAlso</code> is non-null, each source location in seeAlso must be matched by an extraSourceLocation in the
+                * message.
                 * </p>
                 */
                public Message(int line, String srcFile, String text, ISourceLocation[] seeAlso) {
@@ -163,15 +165,14 @@ public class AjcTestCase extends TestCase {
                                                srcFileName.append(chars[i]);
                                        }
                                }
-                               this.sourceFileName = srcFileName.toString();                   
+                               this.sourceFileName = srcFileName.toString();
                        }
                        this.text = text;
                        this.seeAlsos = seeAlso;
                }
-               
+
                /**
-                * Create a message spec that will match any compiler message where
-                * the message text includes <code>text</code>.
+                * Create a message spec that will match any compiler message where the message text includes <code>text</code>.
                 */
                public Message(String text) {
                        this.text = text;
@@ -206,22 +207,22 @@ public class AjcTestCase extends TestCase {
                                        return false;
                                }
                                for (int i = 0; i < seeAlsos.length; i++) {
-                                       if (!hasAMatch(extraLocations,seeAlsos[i])) {
+                                       if (!hasAMatch(extraLocations, seeAlsos[i])) {
                                                return false;
                                        }
                                }
                        }
                        return true;
                }
-               
-               private boolean hasAMatch(List srcLocations,ISourceLocation sLoc) {
+
+               private boolean hasAMatch(List srcLocations, ISourceLocation sLoc) {
                        for (Iterator iter = srcLocations.iterator(); iter.hasNext();) {
                                ISourceLocation thisLoc = (ISourceLocation) iter.next();
                                if (thisLoc.getLine() == sLoc.getLine()) {
                                        if (thisLoc.getSourceFile().getPath().equals(sLoc.getSourceFile().getPath())) {
                                                return true;
                                        }
-                               }                               
+                               }
                        }
                        return false;
                }
@@ -259,60 +260,49 @@ public class AjcTestCase extends TestCase {
                        return buff.toString();
                }
        }
-       
+
        /**
-        * Helper class that represents the specification of a set of
-        * messages expected to be produced from a compiler run.
+        * Helper class that represents the specification of a set of messages expected to be produced from a compiler run.
         * <p>
-        * Instances of MessageSpec are passed to the assertMessage methods
-        * to validate <code>CompilationResult</code>s.
+        * Instances of MessageSpec are passed to the assertMessage methods to validate <code>CompilationResult</code>s.
         */
        public static class MessageSpec {
-               
+
                /**
-                * Convenience constant that matches a CompilationResult with
-                * any number of information messages, but no others.
+                * Convenience constant that matches a CompilationResult with any number of information messages, but no others.
                 */
-               public static final MessageSpec EMPTY_MESSAGE_SET = 
-                       new MessageSpec(
-                                       null,
-                                       Collections.EMPTY_LIST,
-                                       Collections.EMPTY_LIST,
-                                       Collections.EMPTY_LIST,
-                                       Collections.EMPTY_LIST);
-               
+               public static final MessageSpec EMPTY_MESSAGE_SET = new MessageSpec(null, Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+                               Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+
                boolean ignoreInfos = true;
                public List fails;
                public List infos;
                public List warnings;
                public List errors;
                public List weaves;
-               
+
                /**
-                * Set to true to enable or disable comparison of information messages. 
+                * Set to true to enable or disable comparison of information messages.
                 */
                public void setInfoComparison(boolean enabled) {
                        this.ignoreInfos = !enabled;
                }
-               
+
                /**
-                * True if information messages are not being included in matching. 
+                * True if information messages are not being included in matching.
                 */
                public boolean isIgnoringInfoMessages() {
                        return ignoreInfos;
                }
-               
+
                /**
-                * Create a message specification to test a CompilationResult for a 
-                * given set of info, warning, error, and fail messages.
-                * @param infos The set of info messages to test for. Specifying a non-null value
-                * for this parameter enables info message comparison.
-                * @param warnings The set of warning messages to test for - can pass null to indicate
-                * empty set.
-                * @param errors The set of error messages to test for - can pass null to indicate
-                * empty set.
-                * @param fails The set of fail or abort messages to test for - can pass null to indicate
-                * empty set.
+                * Create a message specification to test a CompilationResult for a given set of info, warning, error, and fail messages.
+                * 
+                * @param infos The set of info messages to test for. Specifying a non-null value for this parameter enables info message
+                *        comparison.
+                * @param warnings The set of warning messages to test for - can pass null to indicate empty set.
+                * @param errors The set of error messages to test for - can pass null to indicate empty set.
+                * @param fails The set of fail or abort messages to test for - can pass null to indicate empty set.
                 */
                public MessageSpec(List infos, List warnings, List errors, List fails, List weaves) {
                        if (infos != null) {
@@ -326,96 +316,101 @@ public class AjcTestCase extends TestCase {
                        this.fails = ((fails == null) ? Collections.EMPTY_LIST : fails);
                        this.weaves = ((weaves == null) ? Collections.EMPTY_LIST : weaves);
                }
-               
+
                /**
-                * Create a message specification to test a CompilationResult for a given
-                * set of info, warning, and error messages. The presence of any fail or
-                * abort messages in a CompilationResult will be a test failure.
+                * Create a message specification to test a CompilationResult for a given set of info, warning, and error messages. The
+                * presence of any fail or abort messages in a CompilationResult will be a test failure.
                 */
                public MessageSpec(List infos, List warnings, List errors) {
-                       this(infos,warnings,errors,null,null);
+                       this(infos, warnings, errors, null, null);
                }
 
                /**
-                * Create a message specification to test a CompilationResult for a given
-                * set of warning, and error messages. The presence of any fail or
-                * abort messages in a CompilationResult will be a test failure. Informational
-                * messages will be ignored.
+                * Create a message specification to test a CompilationResult for a given set of warning, and error messages. The presence
+                * of any fail or abort messages in a CompilationResult will be a test failure. Informational messages will be ignored.
                 */
                public MessageSpec(List warnings, List errors) {
-                       this(null,warnings,errors,null,null);
+                       this(null, warnings, errors, null, null);
                }
        }
-       
+
        public static class EmptyMessageSpec extends MessageSpec {
                public EmptyMessageSpec() {
-                       super(null,null);
+                       super(null, null);
                }
        }
-       
+
        /**
-        * Helper class representing the results of running a test program built
-        * by the compiler. Provides access to the standard out and error of the
-        * program, and the actual command that was executed.
+        * Helper class representing the results of running a test program built by the compiler. Provides access to the standard out
+        * and error of the program, and the actual command that was executed.
         */
        public static class RunResult {
-               private String command;
-               private String stdOut;
-               private String stdErr;
-               
+               private final String command;
+               private final String stdOut;
+               private final String stdErr;
+
                protected RunResult(String command, String stdOut, String stdErr) {
                        this.command = command;
                        this.stdOut = stdOut;
                        this.stdErr = stdErr;
                }
-               
+
                /**
                 * Return the command that was executed, e.g. "java Driver".
                 */
-               public String getCommand() { return command; }
+               public String getCommand() {
+                       return command;
+               }
+
                /**
                 * The standard output from the run.
                 */
-               public String getStdOut() {return stdOut;}
+               public String getStdOut() {
+                       return stdOut;
+               }
+
                /**
                 * The standard error from the run.
                 */
-               public String getStdErr() {return stdErr;}
-               
+               public String getStdErr() {
+                       return stdErr;
+               }
+
                /**
                 * Returns the command that was executed to produce this result.
                 */
-               public String toString() { return command; }
+               public String toString() {
+                       return command;
+               }
        }
-       
+
        /**
         * Assert that no (non-informational) messages where produced during a compiler run.
         */
        public void assertNoMessages(CompilationResult result) {
-               assertNoMessages(result,"Not expecting any compiler messages to be produced");
+               assertNoMessages(result, "Not expecting any compiler messages to be produced");
        }
-       
+
        /**
         * Assert that no (non-informational) messages where produced during a compiler run.
         */
        public void assertNoMessages(CompilationResult result, String message) {
-               assertMessages(result, message,MessageSpec.EMPTY_MESSAGE_SET);
+               assertMessages(result, message, MessageSpec.EMPTY_MESSAGE_SET);
        }
 
        /**
-        * Assert that messages in accordance with the <code>expected</code> message specification
-        * where produced during a compiler run.
+        * Assert that messages in accordance with the <code>expected</code> message specification where produced during a compiler run.
         */
        public void assertMessages(CompilationResult result, MessageSpec expected) {
-               assertMessages(result, "Compilation results did not meet expected messages specification",expected);
+               assertMessages(result, "Compilation results did not meet expected messages specification", expected);
        }
-       
+
        /**
-        * Assert that messages in accordance with the <code>expected</code> message specification
-        * where produced during a compiler run.
+        * Assert that messages in accordance with the <code>expected</code> message specification where produced during a compiler run.
         */
        public void assertMessages(CompilationResult result, String message, MessageSpec expected) {
-               if (result == null) fail("Attempt to compare null compilation results against expected.");
+               if (result == null)
+                       fail("Attempt to compare null compilation results against expected.");
                List missingFails = copyAll(expected.fails);
                List missingInfos = copyAll(expected.infos);
                List missingWarnings = copyAll(expected.warnings);
@@ -426,33 +421,33 @@ public class AjcTestCase extends TestCase {
                List extraWarnings = copyAll(result.getWarningMessages());
                List extraErrors = copyAll(result.getErrorMessages());
                List extraWeaves = copyAll(result.getWeaveMessages());
-               compare(expected.fails,result.getFailMessages(),missingFails,extraFails);
-               compare(expected.warnings,result.getWarningMessages(),missingWarnings,extraWarnings);
-               compare(expected.errors,result.getErrorMessages(),missingErrors,extraErrors);
+               compare(expected.fails, result.getFailMessages(), missingFails, extraFails);
+               compare(expected.warnings, result.getWarningMessages(), missingWarnings, extraWarnings);
+               compare(expected.errors, result.getErrorMessages(), missingErrors, extraErrors);
                if (!expected.isIgnoringInfoMessages()) {
-                       compare(expected.infos,result.getInfoMessages(),missingInfos,extraInfos);
+                       compare(expected.infos, result.getInfoMessages(), missingInfos, extraInfos);
                }
-               compare(expected.weaves,result.getWeaveMessages(),missingWeaves,extraWeaves);
+               compare(expected.weaves, result.getWeaveMessages(), missingWeaves, extraWeaves);
 
-               boolean infosEmpty = expected.isIgnoringInfoMessages() ? true: (missingInfos.isEmpty() && extraInfos.isEmpty());
-               if ( !(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty() &&
-                          extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) {
+               boolean infosEmpty = expected.isIgnoringInfoMessages() ? true : (missingInfos.isEmpty() && extraInfos.isEmpty());
+               if (!(missingFails.isEmpty() && missingWarnings.isEmpty() && missingErrors.isEmpty() && missingWeaves.isEmpty()
+                               && extraFails.isEmpty() && extraWarnings.isEmpty() && extraErrors.isEmpty() && extraWeaves.isEmpty() && infosEmpty)) {
                        StringBuffer failureReport = new StringBuffer(message);
                        failureReport.append("\n");
                        if (!expected.isIgnoringInfoMessages()) {
-                               addMissing(failureReport,"info",missingInfos);
+                               addMissing(failureReport, "info", missingInfos);
                        }
-                       addMissing(failureReport,"warning",missingWarnings);
-                       addMissing(failureReport,"error",missingErrors);
-                       addMissing(failureReport,"fail",missingFails);
-                       addMissing(failureReport,"weaveInfo",missingWeaves);
+                       addMissing(failureReport, "warning", missingWarnings);
+                       addMissing(failureReport, "error", missingErrors);
+                       addMissing(failureReport, "fail", missingFails);
+                       addMissing(failureReport, "weaveInfo", missingWeaves);
                        if (!expected.isIgnoringInfoMessages()) {
-                               addExtra(failureReport,"info",extraInfos);
+                               addExtra(failureReport, "info", extraInfos);
                        }
-                       addExtra(failureReport,"warning",extraWarnings);
-                       addExtra(failureReport,"error",extraErrors);
-                       addExtra(failureReport,"fail",extraFails);
-                       addExtra(failureReport,"weaveInfo",extraWeaves);
+                       addExtra(failureReport, "warning", extraWarnings);
+                       addExtra(failureReport, "error", extraErrors);
+                       addExtra(failureReport, "fail", extraFails);
+                       addExtra(failureReport, "weaveInfo", extraWeaves);
                        failureReport.append("\ncommand was: ajc");
                        String[] args = result.getArgs();
                        for (int i = 0; i < args.length; i++) {
@@ -473,7 +468,7 @@ public class AjcTestCase extends TestCase {
                ret.add(m1);
                return ret;
        }
-       
+
        /**
         * Helper method to build a new message list for passing to a MessageSpec.
         */
@@ -481,9 +476,9 @@ public class AjcTestCase extends TestCase {
                List ret = new ArrayList();
                ret.add(m1);
                ret.add(m2);
-               return ret;             
+               return ret;
        }
-       
+
        /**
         * Helper method to build a new message list for passing to a MessageSpec.
         */
@@ -492,9 +487,9 @@ public class AjcTestCase extends TestCase {
                ret.add(m1);
                ret.add(m2);
                ret.add(m3);
-               return ret;                             
+               return ret;
        }
-       
+
        /**
         * Helper method to build a new message list for passing to a MessageSpec.
         */
@@ -508,30 +503,30 @@ public class AjcTestCase extends TestCase {
 
        /**
         * Perform a compilation and return the result.
-        * @param baseDir the base directory relative to which all relative paths and
-        * directories in the arguments will be interpreted.
-        * @param args the compiler arguments, as you would specify on the command-line. 
-        * See the Ajc class for a description of the argument processing done in
-        * order to run the compilation in a sandbox.
-        * @see org.aspectj.tools.ajc.Ajc  
+        * 
+        * @param baseDir the base directory relative to which all relative paths and directories in the arguments will be interpreted.
+        * @param args the compiler arguments, as you would specify on the command-line. See the Ajc class for a description of the
+        *        argument processing done in order to run the compilation in a sandbox.
+        * @see org.aspectj.tools.ajc.Ajc
         */
        public CompilationResult ajc(File baseDir, String[] args) {
                try {
                        ajc.setBaseDir(baseDir);
-            args = fixupArgs(args);
+                       args = fixupArgs(args);
                        return ajc.compile(args);
-               } catch(IOException ioEx ) {
+               } catch (IOException ioEx) {
                        fail("IOException thrown during compilation: " + ioEx);
                }
                return null;
        }
-       
+
        public File getSandboxDirectory() {
                return ajc.getSandboxDirectory();
        }
-       
+
        /**
         * Indicate whether or not the sandbox should be emptied before the next compile.
+        * 
         * @see org.aspectj.tools.ajc.Ajc#setShouldEmptySandbox(boolean)
         */
        public void setShouldEmptySandbox(boolean empty) {
@@ -541,37 +536,37 @@ public class AjcTestCase extends TestCase {
        public RunResult getLastRunResult() {
                return lastRunResult;
        }
-    public void testNothingForAntJUnit() {}
-    
+
+       public void testNothingForAntJUnit() {
+       }
+
        /**
-        * Run the given class (main method), and return the result in a RunResult. The program runs with
-        * a classpath containing the sandbox directory, runtime, testing-client, bridge, and
-        * util projects (all used by the Tester class), and any jars in the sandbox.
+        * Run the given class (main method), and return the result in a RunResult. The program runs with a classpath containing the
+        * sandbox directory, runtime, testing-client, bridge, and util projects (all used by the Tester class), and any jars in the
+        * sandbox.
         */
-       public RunResult run(String className){
-               return run(className,new String[0],null);
+       public RunResult run(String className) {
+               return run(className, new String[0], null);
        }
 
-       public RunResult run(String className, String[] args, String classpath)  {
-               return run(className,args,null,false);
+       public RunResult run(String className, String[] args, String classpath) {
+               return run(className, args, null, false);
        }
 
-       
        /**
-        * Run the given class, and return the result in a RunResult. The program runs with
-        * a classpath containing the sandbox directory, runtime, testing-client, bridge, and
-        * util projects (all used by the Tester class), and any jars in the sandbox.
+        * Run the given class, and return the result in a RunResult. The program runs with a classpath containing the sandbox
+        * directory, runtime, testing-client, bridge, and util projects (all used by the Tester class), and any jars in the sandbox.
+        * 
         * @param args the arguments to pass to the program.
-        * @param classpath the execution classpath, the sandbox directory, runtime, testing-client,
-        * bridge, and util projects will all be appended to the classpath, as will any jars in
-        * the sandbox.
+        * @param classpath the execution classpath, the sandbox directory, runtime, testing-client, bridge, and util projects will all
+        *        be appended to the classpath, as will any jars in the sandbox.
         */
-       public RunResult run(String className, String[] args, final String classpath, boolean useLTW)  {
-           if (args != null) {
-            for (int i = 0; i < args.length; i++) {
-                args[i] = substituteSandbox(args[i]);
-            }
-        }
+       public RunResult run(String className, String[] args, final String classpath, boolean useLTW) {
+               if (args != null) {
+                       for (int i = 0; i < args.length; i++) {
+                               args[i] = substituteSandbox(args[i]);
+                       }
+               }
                lastRunResult = null;
                StringBuffer cp = new StringBuffer();
                if (classpath != null) {
@@ -580,36 +575,35 @@ public class AjcTestCase extends TestCase {
                        cp.append(File.pathSeparator);
                }
                cp.append(ajc.getSandboxDirectory().getAbsolutePath());
-               getAnyJars(ajc.getSandboxDirectory(),cp);
-               
+               getAnyJars(ajc.getSandboxDirectory(), cp);
+
                URLClassLoader sandboxLoader;
-               URLClassLoader testLoader = (URLClassLoader)getClass().getClassLoader();
+               URLClassLoader testLoader = (URLClassLoader) getClass().getClassLoader();
                ClassLoader parentLoader = testLoader.getParent();
-               
+
                /* Sandbox -> AspectJ -> Extension -> Bootstrap */
                if (useLTW) {
-                       
+
                        /*
-                        * Create a new AspectJ class loader using the existing test CLASSPATH 
-                        * and any missing Java 5 projects 
+                        * Create a new AspectJ class loader using the existing test CLASSPATH and any missing Java 5 projects
                         */
                        URL[] testUrls = testLoader.getURLs();
                        URL[] java5Urls = getURLs(JAVA5_CLASSPATH_ENTRIES);
                        URL[] urls = new URL[testUrls.length + java5Urls.length];
-                       System.arraycopy(testUrls,0,urls,0,testUrls.length);
-                       System.arraycopy(java5Urls,0,urls,testUrls.length,java5Urls.length);
-//                     ClassLoader aspectjLoader = new URLClassLoader(getURLs(DEFAULT_CLASSPATH_ENTRIES),parent);
-                       ClassLoader aspectjLoader = new URLClassLoader(urls,parentLoader);
+                       System.arraycopy(testUrls, 0, urls, 0, testUrls.length);
+                       System.arraycopy(java5Urls, 0, urls, testUrls.length, java5Urls.length);
+                       // ClassLoader aspectjLoader = new URLClassLoader(getURLs(DEFAULT_CLASSPATH_ENTRIES),parent);
+                       ClassLoader aspectjLoader = new URLClassLoader(urls, parentLoader);
                        URL[] sandboxUrls = getURLs(cp.toString());
-                       sandboxLoader = createWeavingClassLoader(sandboxUrls,aspectjLoader);
-//                     sandboxLoader = createWeavingClassLoader(sandboxUrls,testLoader);
+                       sandboxLoader = createWeavingClassLoader(sandboxUrls, aspectjLoader);
+                       // sandboxLoader = createWeavingClassLoader(sandboxUrls,testLoader);
                }
 
                /* Sandbox + AspectJ -> Extension -> Bootstrap */
                else {
                        cp.append(DEFAULT_CLASSPATH_ENTRIES);
                        URL[] urls = getURLs(cp.toString());
-                       sandboxLoader = new URLClassLoader(urls,parentLoader);
+                       sandboxLoader = new URLClassLoader(urls, parentLoader);
                }
 
                StringBuffer command = new StringBuffer("java -classpath ");
@@ -627,67 +621,64 @@ public class AjcTestCase extends TestCase {
                try {
                        try {
                                Class testerClass = sandboxLoader.loadClass("org.aspectj.testing.Tester");
-                               Method setBaseDir = testerClass.getDeclaredMethod("setBASEDIR",new Class[] {File.class});
-                               setBaseDir.invoke(null,new Object[] {ajc.getSandboxDirectory()});
+                               Method setBaseDir = testerClass.getDeclaredMethod("setBASEDIR", new Class[] { File.class });
+                               setBaseDir.invoke(null, new Object[] { ajc.getSandboxDirectory() });
                        } catch (InvocationTargetException itEx) {
-                               fail ("Unable to prepare org.aspectj.testing.Tester for test run: " + itEx.getTargetException());
+                               fail("Unable to prepare org.aspectj.testing.Tester for test run: " + itEx.getTargetException());
                        } catch (Exception ex) {
-                               fail ("Unable to prepare org.aspectj.testing.Tester for test run: " + ex);
+                               fail("Unable to prepare org.aspectj.testing.Tester for test run: " + ex);
                        }
-                       startCapture(baosErr,baosOut);
-                       
+                       startCapture(baosErr, baosOut);
+
                        /* Frameworks like XML use context class loader for dynamic loading */
                        Thread.currentThread().setContextClassLoader(sandboxLoader);
-                       
+
                        Class toRun = sandboxLoader.loadClass(className);
-                       Method mainMethod = toRun.getMethod("main",new Class[] {String[].class});
-                       mainMethod.invoke(null,new Object[] {args});
-               } catch(ClassNotFoundException cnf) {
+                       Method mainMethod = toRun.getMethod("main", new Class[] { String[].class });
+                       mainMethod.invoke(null, new Object[] { args });
+               } catch (ClassNotFoundException cnf) {
                        fail("Can't find class: " + className);
-               } catch(NoSuchMethodException nsm) {
+               } catch (NoSuchMethodException nsm) {
                        fail(className + " does not have a main method");
                } catch (IllegalAccessException illEx) {
                        fail("main method in class " + className + " is not public");
                } catch (InvocationTargetException invTgt) {
                        // the main method threw an exception...
-            fail("Exception thrown by " + className + ".main(String[]) :" + invTgt.getTargetException());
+                       fail("Exception thrown by " + className + ".main(String[]) :" + invTgt.getTargetException());
                } finally {
                        Thread.currentThread().setContextClassLoader(contexClassLoader);
-                       stopCapture(baosErr,baosOut);
-                       lastRunResult = new RunResult(command.toString(),new String(baosOut.toByteArray()),new String(baosErr.toByteArray()));
+                       stopCapture(baosErr, baosOut);
+                       lastRunResult = new RunResult(command.toString(), new String(baosOut.toByteArray()), new String(baosErr.toByteArray()));
                }
                return lastRunResult;
        }
-       
-       /* Must create weaving class loader reflectively using new parent so we 
-        * don't have a reference to a World loaded from CLASSPATH which won't
-        * be able to resolve Java 5 specific extensions and may cause
-        * ClassCastExceptions
-        */  
-       private URLClassLoader createWeavingClassLoader (URL[] urls, ClassLoader parent) {
+
+       /*
+        * Must create weaving class loader reflectively using new parent so we don't have a reference to a World loaded from CLASSPATH
+        * which won't be able to resolve Java 5 specific extensions and may cause ClassCastExceptions
+        */
+       private URLClassLoader createWeavingClassLoader(URL[] urls, ClassLoader parent) {
                URLClassLoader loader = null;
-               
+
                try {
-                       Class loaderClazz = Class.forName("org.aspectj.weaver.loadtime.WeavingURLClassLoader",false,parent);
+                       Class loaderClazz = Class.forName("org.aspectj.weaver.loadtime.WeavingURLClassLoader", false, parent);
                        Class[] parameterTypes = new Class[] { urls.getClass(), ClassLoader.class };
                        Object[] parameters = new Object[] { urls, parent };
                        Constructor constructor = loaderClazz.getConstructor(parameterTypes);
-                       loader = (URLClassLoader)constructor.newInstance(parameters);
-               }
-               catch (InvocationTargetException ex) {
+                       loader = (URLClassLoader) constructor.newInstance(parameters);
+               } catch (InvocationTargetException ex) {
                        ex.printStackTrace();
                        fail("Cannot create weaving class loader: " + ex.getTargetException());
-               }
-               catch (Exception ex) {
+               } catch (Exception ex) {
                        ex.printStackTrace();
                        fail("Cannot create weaving class loader: " + ex.toString());
                }
-               
+
                return loader;
        }
-       
-       private URL[] getURLs (String classpath) {
-               StringTokenizer strTok = new StringTokenizer(classpath,File.pathSeparator);
+
+       private URL[] getURLs(String classpath) {
+               StringTokenizer strTok = new StringTokenizer(classpath, File.pathSeparator);
                URL[] urls = new URL[strTok.countTokens()];
                try {
                        for (int i = 0; i < urls.length; i++) {
@@ -696,84 +687,82 @@ public class AjcTestCase extends TestCase {
                } catch (Exception malEx) {
                        fail("Bad classpath specification: " + classpath);
                }
-               
+
                return urls;
        }
 
        private String substituteSandbox(String classpath) {
                // the longhand form of the non 1.3 API: classpath.replace("$sandbox", ajc.getSandboxDirectory().getAbsolutePath());
-               while (classpath.indexOf("$sandbox")!=-1) {
+               while (classpath.indexOf("$sandbox") != -1) {
                        int pos = classpath.indexOf("$sandbox");
-                       String firstbit = classpath.substring(0,pos);
-                       String endbit = classpath.substring(pos+8);
-                       classpath = firstbit+ ajc.getSandboxDirectory().getAbsolutePath()+endbit;
+                       String firstbit = classpath.substring(0, pos);
+                       String endbit = classpath.substring(pos + 8);
+                       classpath = firstbit + ajc.getSandboxDirectory().getAbsolutePath() + endbit;
                }
                return classpath;
        }
-    
-    /**
-     * Any central pre-processing of args.
-     * This supplies aspectjrt.jar if available and classpath not set.
-     * @param args the String[] args to fix up
-     * @return the String[] args to use
-     */
+
+       /**
+        * Any central pre-processing of args. This supplies aspectjrt.jar if available and classpath not set.
+        * 
+        * @param args the String[] args to fix up
+        * @return the String[] args to use
+        */
        protected String[] fixupArgs(String[] args) {
-        if (null == args) {
-            return null;
-        }
-        int cpIndex = -1;
-        boolean hasruntime = false;      
-        for (int i = 0; i < args.length-1; i++) {
-                       args[i] = adaptToPlatform(args[i]);
-            if ("-classpath".equals(args[i])) {
-                cpIndex = i;
-                args[i+1] = substituteSandbox(args[i+1]);
-                String next = args[i+1];
-                hasruntime = ((null != next) 
-                        && (-1 != next.indexOf("aspectjrt.jar")));
-            }
-        }
-        if (-1 == cpIndex) {
-            String[] newargs = new String[args.length + 2];
-            newargs[0] = "-classpath";
-            newargs[1] = TestUtil.aspectjrtPath().getPath();
-            System.arraycopy(args, 0, newargs, 2, args.length);
-            args = newargs;
-        } else {
-            if (!hasruntime) {
-                cpIndex++;
-                String[] newargs = new String[args.length];
-                System.arraycopy(args, 0, newargs, 0, args.length);
-                newargs[cpIndex] = args[cpIndex] + File.pathSeparator
-                + TestUtil.aspectjrtPath().getPath();
-                args = newargs;
-            }
-        }
-        return args;
-    }
-       
+               if (null == args) {
+                       return null;
+               }
+               int cpIndex = -1;
+               boolean hasruntime = false;
+               for (int i = 0; i < args.length - 1; i++) {
+                       args[i] = adaptToPlatform(args[i]);
+                       if ("-classpath".equals(args[i])) {
+                               cpIndex = i;
+                               args[i + 1] = substituteSandbox(args[i + 1]);
+                               String next = args[i + 1];
+                               hasruntime = ((null != next) && (-1 != next.indexOf("aspectjrt.jar")));
+                       }
+               }
+               if (-1 == cpIndex) {
+                       String[] newargs = new String[args.length + 2];
+                       newargs[0] = "-classpath";
+                       newargs[1] = TestUtil.aspectjrtPath().getPath();
+                       System.arraycopy(args, 0, newargs, 2, args.length);
+                       args = newargs;
+               } else {
+                       if (!hasruntime) {
+                               cpIndex++;
+                               String[] newargs = new String[args.length];
+                               System.arraycopy(args, 0, newargs, 0, args.length);
+                               newargs[cpIndex] = args[cpIndex] + File.pathSeparator + TestUtil.aspectjrtPath().getPath();
+                               args = newargs;
+                       }
+               }
+               return args;
+       }
+
        private String adaptToPlatform(String s) {
-               String ret = s.replace(';',File.pathSeparatorChar);
-               //ret = ret.replace(':',File.pathSeparatorChar);
+               String ret = s.replace(';', File.pathSeparatorChar);
+               // ret = ret.replace(':',File.pathSeparatorChar);
                return ret;
        }
-    
+
        private List copyAll(List in) {
-               if (in == Collections.EMPTY_LIST) return in;
-               
+               if (in == Collections.EMPTY_LIST)
+                       return in;
+
                List out = new ArrayList();
                for (Iterator iter = in.iterator(); iter.hasNext();) {
-                       out.add(iter.next());                   
+                       out.add(iter.next());
                }
                return out;
        }
-       
+
        /**
-        * Compare the set of expected messages against the set of actual messages,
-        * leaving in missingElements the set of messages that were expected but did not
-        * occur, and in extraElements the set of messages that occured but were not 
-        * excpected
-        * @param expected  the expected messages
+        * Compare the set of expected messages against the set of actual messages, leaving in missingElements the set of messages that
+        * were expected but did not occur, and in extraElements the set of messages that occured but were not excpected
+        * 
+        * @param expected the expected messages
         * @param actual the actual messages
         * @param missingElements the missing messages, when passed in must contain all of the expected messages
         * @param extraElements the additional messages, when passed in must contain all of the actual messages
@@ -791,7 +780,7 @@ public class AjcTestCase extends TestCase {
                }
        }
 
-       private void addMissing(StringBuffer buff,String type, List messages) {
+       private void addMissing(StringBuffer buff, String type, List messages) {
                if (!messages.isEmpty()) {
                        buff.append("Missing expected ");
                        buff.append(type);
@@ -803,7 +792,7 @@ public class AjcTestCase extends TestCase {
                        }
                }
        }
-       
+
        private void addExtra(StringBuffer buff, String type, List messages) {
                if (!messages.isEmpty()) {
                        buff.append("Unexpected ");
@@ -814,61 +803,66 @@ public class AjcTestCase extends TestCase {
                                buff.append(iter.next().toString());
                                buff.append("\n");
                        }
-               }               
+               }
        }
-       
+
        // add any jars in the directory to the classpath
-       private void getAnyJars(File dir,StringBuffer buff) {
+       private void getAnyJars(File dir, StringBuffer buff) {
                File[] files = dir.listFiles();
                for (int i = 0; i < files.length; i++) {
                        if (files[i].getName().endsWith(".jar")) {
                                buff.append(File.pathSeparator);
                                buff.append(files[i].getAbsolutePath());
                        } else if (files[i].isDirectory()) {
-                               getAnyJars(files[i],buff);
+                               getAnyJars(files[i], buff);
                        }
                }
        }
-       
-       private static void startCapture (OutputStream errOS, OutputStream outOS) {
+
+       private static void startCapture(OutputStream errOS, OutputStream outOS) {
                delegatingErr.add(errOS);
                delegatingOut.add(outOS);
 
                delegatingErr.setVerbose(DEFAULT_ERR_VERBOSE);
                delegatingOut.setVerbose(DEFAULT_OUT_VERBOSE);
        }
-       
-       private static void stopCapture (OutputStream errOS, OutputStream outOS) {
+
+       private static void stopCapture(OutputStream errOS, OutputStream outOS) {
                delegatingErr.setVerbose(true);
                delegatingOut.setVerbose(true);
 
                delegatingErr.remove(errOS);
                delegatingOut.remove(outOS);
        }
-       
-       private static boolean getBoolean (String name, boolean def) {
+
+       private static boolean getBoolean(String name, boolean def) {
                String defaultValue = String.valueOf(def);
-               String value = System.getProperty(name,defaultValue);
+               String value = System.getProperty(name, defaultValue);
                return Boolean.valueOf(value).booleanValue();
        }
-       
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see junit.framework.TestCase#setUp()
         */
        protected void setUp() throws Exception {
                super.setUp();
                ajc = new Ajc();
        }
-       /* (non-Javadoc)
+
+       /*
+        * (non-Javadoc)
+        * 
         * @see junit.framework.TestCase#tearDown()
         */
        protected void tearDown() throws Exception {
                super.tearDown();
-        //ajc = null;
+               // ajc = null;
        }
-       
+
        static {
-//             new RuntimeException("*** AjcTestCase.<clinit>()").printStackTrace();
+               // new RuntimeException("*** AjcTestCase.<clinit>()").printStackTrace();
                delegatingErr = new DelegatingOutputStream(err);
                System.setErr(new PrintStream(delegatingErr));
                delegatingOut = new DelegatingOutputStream(out);