Browse Source

251277: making asmmanager non-singleton

tags/V1_6_3rc1
aclement 15 years ago
parent
commit
35cde06f2c

+ 312
- 328
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java View File

@@ -13,15 +13,15 @@
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
}

+ 203
- 195
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java View 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;
}


+ 317
- 323
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
File diff suppressed because it is too large
View File


Loading…
Cancel
Save