@@ -336,12 +336,11 @@ public class AjdeCoreBuildManager { | |||
return config; | |||
} | |||
private void mergeInto(Collection target, Collection source) { | |||
private <T> void mergeInto(Collection<T> target, Collection<T> source) { | |||
if ((null == target) || (null == source)) { | |||
return; | |||
} | |||
for (Iterator iter = source.iterator(); iter.hasNext();) { | |||
Object next = iter.next(); | |||
for (T next : source) { | |||
if (!target.contains(next)) { | |||
target.add(next); | |||
} |
@@ -33,13 +33,13 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
private String projectPath; | |||
private Set aspectpath; | |||
private Set inpath; | |||
private Set<File> aspectpath; | |||
private Set<File> inpath; | |||
private String outjar; | |||
private Map javaOptions; | |||
private Map<String, String> javaOptions; | |||
private String nonStandardOptions; | |||
private List projectSourceFiles = new ArrayList(); | |||
private Map sourcePathResources; | |||
private List<String> projectSourceFiles = new ArrayList<String>(); | |||
private Map<String, File> sourcePathResources; | |||
private String srcDirName = "src"; | |||
@@ -49,12 +49,12 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
this.projectPath = projectPath; | |||
} | |||
public Set getAspectPath() { | |||
public Set<File> getAspectPath() { | |||
return aspectpath; | |||
} | |||
public List getProjectXmlConfigFiles() { | |||
return Collections.EMPTY_LIST; | |||
public List<String> getProjectXmlConfigFiles() { | |||
return Collections.emptyList(); | |||
} | |||
public String getClasspath() { | |||
@@ -62,13 +62,13 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
+ AjcTests.aspectjrtClasspath(); | |||
} | |||
public Set getInpath() { | |||
public Set<File> getInpath() { | |||
return inpath; | |||
} | |||
public Map getJavaOptionsMap() { | |||
public Map<String, String> getJavaOptionsMap() { | |||
if (javaOptions == null) { | |||
javaOptions = new Hashtable(); | |||
javaOptions = new Hashtable<String, String>(); | |||
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13); | |||
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13); | |||
} | |||
@@ -90,7 +90,7 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
return outputLoc; | |||
} | |||
public List getProjectSourceFiles() { | |||
public List<String> getProjectSourceFiles() { | |||
return projectSourceFiles; | |||
} | |||
@@ -101,9 +101,9 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
public void configurationRead() { | |||
} | |||
public Map getSourcePathResources() { | |||
public Map<String, File> getSourcePathResources() { | |||
if (sourcePathResources == null) { | |||
sourcePathResources = new HashMap(); | |||
sourcePathResources = new HashMap<String, File>(); | |||
/* Allow the user to override the testProjectPath by using sourceRoots */ | |||
File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | |||
@@ -127,11 +127,11 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
} | |||
// -------------------- setter methods useful for testing --------------- | |||
public void setAspectPath(Set aspectPath) { | |||
public void setAspectPath(Set<File> aspectPath) { | |||
this.aspectpath = aspectPath; | |||
} | |||
public void setInpath(Set inpath) { | |||
public void setInpath(Set<File> inpath) { | |||
this.inpath = inpath; | |||
} | |||
@@ -147,11 +147,11 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { | |||
this.nonStandardOptions = options; | |||
} | |||
public void setProjectSourceFiles(List projectSourceFiles) { | |||
public void setProjectSourceFiles(List<String> projectSourceFiles) { | |||
this.projectSourceFiles = projectSourceFiles; | |||
} | |||
public void setSourcePathResources(Map sourcePathResources) { | |||
public void setSourcePathResources(Map<String, File> sourcePathResources) { | |||
this.sourcePathResources = sourcePathResources; | |||
} | |||
@@ -30,26 +30,22 @@ import org.aspectj.util.FileUtil; | |||
public class InpathTests extends AjdeCoreTestCase { | |||
public static final FileFilter aspectjResourceFileFilter = | |||
new FileFilter() { | |||
public static final FileFilter aspectjResourceFileFilter = new FileFilter() { | |||
public boolean accept(File pathname) { | |||
String name = pathname.getName().toLowerCase(); | |||
return ( | |||
!name.endsWith(".class") | |||
&& !name.endsWith(".java") | |||
&& !name.endsWith(".aj")); | |||
return (!name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj")); | |||
} | |||
}; | |||
public static final String indir1Name = "indir1"; | |||
public static final String indir2Name = "indir2"; | |||
public static final String injarName = "injar.jar"; | |||
public static final String injarName = "injar.jar"; | |||
public static final String outjarName = "/bin/output.jar"; | |||
private String[] build1 = new String[]{"src1" + File.separator + "Main.java"}; | |||
private String[] build2 = new String[]{"src2" + File.separator + "Aspect.java"}; | |||
private String[] build1 = new String[] { "src1" + File.separator + "Main.java" }; | |||
private String[] build2 = new String[] { "src2" + File.separator + "Aspect.java" }; | |||
private TestMessageHandler handler; | |||
private TestCompilerConfiguration compilerConfig; | |||
@@ -57,8 +53,7 @@ public class InpathTests extends AjdeCoreTestCase { | |||
super.setUp(); | |||
initialiseProject("InpathTest"); | |||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | |||
compilerConfig = (TestCompilerConfiguration) getCompiler() | |||
.getCompilerConfiguration(); | |||
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration(); | |||
} | |||
protected void tearDown() throws Exception { | |||
@@ -66,36 +61,31 @@ public class InpathTests extends AjdeCoreTestCase { | |||
handler = null; | |||
compilerConfig = null; | |||
} | |||
/** | |||
* Inputs to the compiler: | |||
* inpath = 'indir1/' | |||
* source = 'src' | |||
* output = a jar file | |||
* Inputs to the compiler: inpath = 'indir1/' source = 'src' output = a jar file | |||
* | |||
* Expected result = output jar file contains contents of indir1 and | |||
* class file for source that was in src | |||
* Expected result = output jar file contains contents of indir1 and class file for source that was in src | |||
*/ | |||
public void testInpathToOutjar() { | |||
Set inpath = new HashSet(); | |||
Set<File> inpath = new HashSet<File>(); | |||
File indir1 = openFile(indir1Name); | |||
inpath.add(indir1); | |||
compilerConfig.setInpath(inpath); | |||
File outjar = openFile(outjarName); | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(build1)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set expectedOutputJarContents = new HashSet(); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set<String> expectedOutputJarContents = new HashSet<String>(); | |||
// From indir1 | |||
// If we don't copy resources, these next three files won't make it. | |||
// expectedOutputJarContents.add("META-INF/MANIFEST.MF"); | |||
// expectedOutputJarContents.add("META-INF/test.xml"); | |||
// expectedOutputJarContents.add("test/test.props"); | |||
// If we don't copy resources, these next three files won't make it. | |||
// expectedOutputJarContents.add("META-INF/MANIFEST.MF"); | |||
// expectedOutputJarContents.add("META-INF/test.xml"); | |||
// expectedOutputJarContents.add("test/test.props"); | |||
expectedOutputJarContents.add("test/TestProperties.class"); | |||
// From src | |||
expectedOutputJarContents.add("Main.class"); | |||
@@ -103,9 +93,8 @@ public class InpathTests extends AjdeCoreTestCase { | |||
} | |||
/** | |||
* Similar to the first test but outputs to a directory rather than | |||
* a jar. | |||
* | |||
* Similar to the first test but outputs to a directory rather than a jar. | |||
* | |||
*/ | |||
public void testInpathToBin() { | |||
Set inpath = new HashSet(); | |||
@@ -113,17 +102,16 @@ public class InpathTests extends AjdeCoreTestCase { | |||
inpath.add(indir1); | |||
compilerConfig.setInpath(inpath); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(build1)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set expectedBindirContents = new HashSet(); | |||
// From indir1 | |||
// If we don't copy resources, these next three files won't make it | |||
// expectedBindirContents.add("META-INF/MANIFEST.MF"); | |||
// expectedBindirContents.add("META-INF/test.xml"); | |||
// expectedBindirContents.add("test/test.props"); | |||
// If we don't copy resources, these next three files won't make it | |||
// expectedBindirContents.add("META-INF/MANIFEST.MF"); | |||
// expectedBindirContents.add("META-INF/test.xml"); | |||
// expectedBindirContents.add("test/test.props"); | |||
expectedBindirContents.add("test/TestProperties.class"); | |||
// From src | |||
expectedBindirContents.add("Main.class"); | |||
@@ -132,98 +120,88 @@ public class InpathTests extends AjdeCoreTestCase { | |||
} | |||
/** | |||
* Inputs to the compiler: | |||
* inpath is 'indir2' that contains a helloworld source file and class file. | |||
* source is 'src2' which contains Aspect.java which weaves before advice into the HelloWorld code from 'indir2' | |||
* Inputs to the compiler: inpath is 'indir2' that contains a helloworld source file and class file. source is 'src2' which | |||
* contains Aspect.java which weaves before advice into the HelloWorld code from 'indir2' | |||
* | |||
* Expected result: HelloWorld copied through to output jar and 'weaved'. Compiled version of Aspect.java put into | |||
* the output jar. The HelloWorld.java source file is also copied through to the output jar. | |||
* Expected result: HelloWorld copied through to output jar and 'weaved'. Compiled version of Aspect.java put into the output | |||
* jar. The HelloWorld.java source file is also copied through to the output jar. | |||
* | |||
* An extra check is done at the end of this test to verify that HelloWorld has changed size (due to the weaving). | |||
*/ | |||
public void testInpathToOutjar2() { | |||
Set inpath = new HashSet(); | |||
Set<File> inpath = new HashSet<File>(); | |||
File indir2 = openFile(indir2Name); | |||
inpath.add(indir2); | |||
compilerConfig.setInpath(inpath); | |||
File outjar = openFile(outjarName); | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(build2)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set expectedOutputJarContents = new HashSet(); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set<String> expectedOutputJarContents = new HashSet<String>(); | |||
// From indir1 | |||
expectedOutputJarContents.add("example/HelloWorld.class"); | |||
// If we don't copy resources, this file won't make it | |||
// expectedOutputJarContents.add("example/HelloWorld.java"); | |||
// If we don't copy resources, this file won't make it | |||
// expectedOutputJarContents.add("example/HelloWorld.java"); | |||
// From src | |||
expectedOutputJarContents.add("Aspect.class"); | |||
compareJars(indir2, "src", outjar, expectedOutputJarContents); | |||
// Extra test. The HelloWorld class from the input directory should have been woven | |||
// Extra test. The HelloWorld class from the input directory should have been woven | |||
// by the aspect - verify that the size of the HelloWorld class in the output directory | |||
// is a different size to the input version. | |||
int outputsize = fetchFromJar(outjar, "example/HelloWorld.class"); | |||
int outputsize = fetchFromJar(outjar, "example/HelloWorld.class"); | |||
try { | |||
FileInputStream fis = new FileInputStream(openFile(indir2Name+"/example/HelloWorld.class")); | |||
FileInputStream fis = new FileInputStream(openFile(indir2Name + "/example/HelloWorld.class")); | |||
byte[] filedata = FileUtil.readAsByteArray(fis); | |||
int inputsize = filedata.length; | |||
assertTrue("Weaving of Aspect should have occurred but the input and output size for HelloWorld.class are the same", | |||
(inputsize!=outputsize)); | |||
(inputsize != outputsize)); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
fail(); | |||
} | |||
} | |||
/** | |||
* More complex inpath - a jar and a directory | |||
* | |||
* Inputs: | |||
* -inpath injar.jar;indir2 | |||
* source is 'src2' which contains Aspect.java | |||
* Inputs: -inpath injar.jar;indir2 source is 'src2' which contains Aspect.java | |||
* | |||
* Expected result: Result should be a directory containing the contents of injar.jar and indir2 and the Aspect.class file. | |||
* | |||
* Expected result: Result should be a directory containing the contents of injar.jar and indir2 and the | |||
* Aspect.class file. | |||
* | |||
*/ | |||
public void testInpathAndInjarToBin() { | |||
Set inpath = new HashSet(); | |||
Set<File> inpath = new HashSet<File>(); | |||
File indir2 = openFile(indir2Name); | |||
inpath.add(indir2); | |||
inpath.add(openFile(injarName)); | |||
compilerConfig.setInpath(inpath); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(build2)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set expectedBindirContents = new HashSet(); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
Set<String> expectedBindirContents = new HashSet<String>(); | |||
// From indir1 | |||
expectedBindirContents.add("example/HelloWorld.class"); | |||
// If we don't copy resources, this file won't make it | |||
// expectedBindirContents.add("example/HelloWorld.java"); | |||
// If we don't copy resources, this file won't make it | |||
// expectedBindirContents.add("example/HelloWorld.java"); | |||
// From injar.jar | |||
expectedBindirContents.add("props/resources.properties"); | |||
// From src | |||
expectedBindirContents.add("Aspect.class"); | |||
compareIndirToBin(indir2, "src", "bin", expectedBindirContents); | |||
// Check the input and output versions of HelloWorld.class are different sizes | |||
try { | |||
FileInputStream fis1 = new FileInputStream(openFile("indir2/example/HelloWorld.class")); | |||
@@ -233,7 +211,7 @@ public class InpathTests extends AjdeCoreTestCase { | |||
byte[] filedata2 = FileUtil.readAsByteArray(fis2); | |||
int outputsize = filedata2.length; | |||
assertTrue("Weaving of Aspect should have occurred but the input and output size for HelloWorld.class are the same", | |||
(outputsize!=inputsize)); | |||
(outputsize != inputsize)); | |||
fis1.close(); | |||
fis2.close(); | |||
@@ -242,44 +220,35 @@ public class InpathTests extends AjdeCoreTestCase { | |||
fail(); | |||
} | |||
} | |||
/* | |||
* Ensure -outjar contains all non-Java resouces from injars | |||
*/ | |||
public void compareJars( | |||
File dirFile, | |||
String sourceDir, | |||
File outjarFile, | |||
Set expectedOutputJarContents) { | |||
public void compareJars(File dirFile, String sourceDir, File outjarFile, Set expectedOutputJarContents) { | |||
try { | |||
assertTrue( | |||
"outjar older than injar: outjarLastMod="+outjarFile.lastModified()+" injarLastMod="+dirFile.lastModified(), | |||
(outjarFile.lastModified() >= dirFile.lastModified())); | |||
"outjar older than injar: outjarLastMod=" + outjarFile.lastModified() + " injarLastMod=" | |||
+ dirFile.lastModified(), (outjarFile.lastModified() >= dirFile.lastModified())); | |||
// Go through the output jar file, for each element, remove it from | |||
// the expectedOutputJarContents - when we finish, the expectedOutputJarContents | |||
// set should be empty! | |||
JarInputStream outjar = | |||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
JarInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
ZipEntry entry; | |||
while (null != (entry = outjar.getNextEntry())) { | |||
String fileName = entry.getName(); | |||
fileName = fileName.replace('\\', '/'); | |||
if (fileName.indexOf("CVS") == -1) { | |||
boolean b = expectedOutputJarContents.remove(fileName); | |||
assertTrue( | |||
"Unexpectedly found : " + fileName + " in outjar", | |||
b); | |||
assertTrue("Unexpectedly found : " + fileName + " in outjar", b); | |||
} | |||
outjar.closeEntry(); | |||
} | |||
outjar.close(); | |||
assertTrue( | |||
"Didnt make it into the output jar: " | |||
+ expectedOutputJarContents.toString(), | |||
expectedOutputJarContents.isEmpty()); | |||
assertTrue("Didnt make it into the output jar: " + expectedOutputJarContents.toString(), | |||
expectedOutputJarContents.isEmpty()); | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
@@ -294,8 +263,7 @@ public class InpathTests extends AjdeCoreTestCase { | |||
try { | |||
JarInputStream outjar = | |||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
JarInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
ZipEntry entry; | |||
while (null != (entry = outjar.getNextEntry())) { | |||
String fileName = entry.getName(); | |||
@@ -308,9 +276,7 @@ public class InpathTests extends AjdeCoreTestCase { | |||
} | |||
outjar.close(); | |||
assertTrue( | |||
"Missing resources: " + resources.toString(), | |||
resources.isEmpty()); | |||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
@@ -319,13 +285,9 @@ public class InpathTests extends AjdeCoreTestCase { | |||
/* | |||
* Ensure bin contains all non-Java resouces from source and injars | |||
*/ | |||
public void compareIndirToBin( | |||
File indirFile, | |||
String sourceDir, | |||
String outdirName, | |||
Set expectedOutdirContents) { | |||
public void compareIndirToBin(File indirFile, String sourceDir, String outdirName, Set expectedOutdirContents) { | |||
// byte[] inManifest = null; | |||
// byte[] inManifest = null; | |||
File binBase = openFile(outdirName); | |||
String[] toResources = FileUtil.listFiles(binBase); | |||
@@ -337,43 +299,37 @@ public class InpathTests extends AjdeCoreTestCase { | |||
} | |||
} | |||
assertTrue( | |||
"Missing resources: " + expectedOutdirContents.toString(), | |||
expectedOutdirContents.isEmpty()); | |||
assertTrue("Missing resources: " + expectedOutdirContents.toString(), expectedOutdirContents.isEmpty()); | |||
} | |||
private void listSourceResources(String indirName, Set resources) { | |||
File srcBase = openFile(indirName); | |||
File[] fromResources = | |||
FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||
for (int i = 0; i < fromResources.length; i++) { | |||
String name = FileUtil.normalizedPath(fromResources[i], srcBase); | |||
//System.err.println("Checking "+name); | |||
if (!name.startsWith("CVS/") | |||
&& (-1 == name.indexOf("/CVS/")) | |||
&& !name.endsWith("/CVS")) { | |||
// System.err.println("Checking "+name); | |||
if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | |||
resources.add(name); | |||
} | |||
} | |||
} | |||
// Return the size of specified entry from the output jar file | |||
public int fetchFromJar(File outjarFile, String filename) { | |||
int ret = -1; | |||
try { | |||
JarInputStream outjar; | |||
outjar = | |||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
ZipEntry entry; | |||
while (null != (entry = outjar.getNextEntry())) { | |||
String zipentryname = entry.getName(); | |||
if (zipentryname.equals(filename)) { | |||
byte[] filedata = FileUtil.readAsByteArray(outjar); | |||
ret = filedata.length; | |||
outjar.closeEntry(); | |||
break; | |||
byte[] filedata = FileUtil.readAsByteArray(outjar); | |||
ret = filedata.length; | |||
outjar.closeEntry(); | |||
break; | |||
} | |||
outjar.closeEntry(); | |||
} | |||
@@ -385,5 +341,5 @@ public class InpathTests extends AjdeCoreTestCase { | |||
} | |||
return ret; | |||
} | |||
} |
@@ -29,32 +29,27 @@ import org.aspectj.util.FileUtil; | |||
public class ResourceCopyTests extends AjdeCoreTestCase { | |||
public static final String PROJECT_DIR = "bug-36071a"; | |||
public static final String srcDir = PROJECT_DIR + "/src"; | |||
public static final String binDir = "bin"; | |||
public static final String injar1Name = "input1.jar"; | |||
public static final String injar2Name = "input2.jar"; | |||
public static final String outjarName = "/bin/output.jar"; | |||
public static final String PROJECT_DIR = "bug-36071a"; | |||
public static final String srcDir = PROJECT_DIR + "/src"; | |||
public static final String binDir = "bin"; | |||
public static final String injar1Name = "input1.jar"; | |||
public static final String injar2Name = "input2.jar"; | |||
public static final String outjarName = "/bin/output.jar"; | |||
private TestMessageHandler handler; | |||
private TestCompilerConfiguration compilerConfig; | |||
private String[] config1 = new String[] { | |||
"src" + File.separator + "Main.java", | |||
"src" + File.separator + "testsrc" + File.separator + "TestProperties.java" | |||
}; | |||
private String[] config2 = new String[] { | |||
"src" + File.separator + "aspects" + File.separator + "Logging.java" | |||
}; | |||
private String[] config1 = new String[] { "src" + File.separator + "Main.java", | |||
"src" + File.separator + "testsrc" + File.separator + "TestProperties.java" }; | |||
private String[] config2 = new String[] { "src" + File.separator + "aspects" + File.separator + "Logging.java" }; | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
initialiseProject(PROJECT_DIR); | |||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | |||
compilerConfig = (TestCompilerConfiguration) getCompiler() | |||
.getCompilerConfiguration(); | |||
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration(); | |||
} | |||
protected void tearDown() throws Exception { | |||
@@ -62,16 +57,16 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
handler = null; | |||
compilerConfig = null; | |||
} | |||
public void testSrcToBin () { | |||
public void testSrcToBin() { | |||
assertTrue("Expected there to be no compiler messages but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | |||
doBuild(true); | |||
compareDirs("src","bin"); | |||
compareDirs("src", "bin"); | |||
} | |||
public void testInjarsToOutjar () { | |||
Set injars = new HashSet(); | |||
public void testInjarsToOutjar() { | |||
Set<File> injars = new HashSet<File>(); | |||
File injar1 = openFile(injar1Name); | |||
injars.add(injar1); | |||
compilerConfig.setInpath(injars); | |||
@@ -79,13 +74,12 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareJars(injar1,"src",outjar); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareJars(injar1, "src", outjar); | |||
} | |||
public void testDuplicateResources () { | |||
Set injars = new HashSet(); | |||
public void testDuplicateResources() { | |||
Set<File> injars = new HashSet<File>(); | |||
File injar1 = openFile(injar1Name); | |||
File injar2 = openFile(injar2Name); | |||
injars.add(injar1); | |||
@@ -95,150 +89,145 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | |||
doBuild(true); | |||
assertFalse("Expected compiler errors or warnings but didn't find any" | |||
, handler.getMessages().isEmpty()); | |||
assertFalse("Expected compiler errors or warnings but didn't find any", handler.getMessages().isEmpty()); | |||
List msgs = handler.getMessages(); | |||
String exp = "duplicate resource: "; | |||
String found = ((TestMessageHandler.TestMessage)msgs.get(0)).getContainedMessage().getMessage(); | |||
assertTrue("Expected message to start with 'duplicate resource:' but found" + | |||
" message " + found, found.startsWith(exp)); | |||
compareJars(injar1,"src",outjar); | |||
String found = ((TestMessageHandler.TestMessage) msgs.get(0)).getContainedMessage().getMessage(); | |||
assertTrue("Expected message to start with 'duplicate resource:' but found" + " message " + found, found.startsWith(exp)); | |||
compareJars(injar1, "src", outjar); | |||
} | |||
public void testSrcToOutjar () { | |||
public void testSrcToOutjar() { | |||
File outjar = openFile(outjarName); | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareSourceToOutjar("src",outjar); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareSourceToOutjar("src", outjar); | |||
} | |||
public void testInjarsToBin () { | |||
public void testInjarsToBin() { | |||
Set injars = new HashSet(); | |||
File injar1 = openFile(injar1Name); | |||
injars.add(injar1); | |||
compilerConfig.setInpath(injars); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareInjarsToBin(injar1,"src","bin"); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareInjarsToBin(injar1, "src", "bin"); | |||
} | |||
// BAH! keeps whinging about CVS extraneous resources | |||
// public void testInjarsToOddBin () { | |||
// Set injars = new HashSet(); | |||
// File injar1 = openFile(injar1Name); | |||
// injars.add(injar1); | |||
// ideManager.getProjectProperties().setOutputPath("crazy.jar"); | |||
// ideManager.getProjectProperties().setInJars(injars); | |||
// assertTrue("Build failed",doSynchronousBuild("config2.lst")); | |||
// assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); | |||
// compareInjarsToBin(injar1,"src","crazy.jar"); | |||
// } | |||
public void testInjarsToOutjarOddNames () { | |||
Set injars = new HashSet(); | |||
// BAH! keeps whinging about CVS extraneous resources | |||
// public void testInjarsToOddBin () { | |||
// Set injars = new HashSet(); | |||
// File injar1 = openFile(injar1Name); | |||
// injars.add(injar1); | |||
// ideManager.getProjectProperties().setOutputPath("crazy.jar"); | |||
// ideManager.getProjectProperties().setInJars(injars); | |||
// assertTrue("Build failed",doSynchronousBuild("config2.lst")); | |||
// assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); | |||
// compareInjarsToBin(injar1,"src","crazy.jar"); | |||
// } | |||
public void testInjarsToOutjarOddNames() { | |||
Set<File> injars = new HashSet<File>(); | |||
File injar1 = openFile("input1"); | |||
File outjar = openFile(outjarName+".fozout"); | |||
File outjar = openFile(outjarName + ".fozout"); | |||
injars.add(injar1); | |||
compilerConfig.setInpath(injars); | |||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | |||
doBuild(true); | |||
assertTrue("Expected no compiler errors or warnings but found " | |||
+ handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareJars(injar1,"src",outjar); | |||
assertTrue("Expected no compiler errors or warnings but found " + handler.getMessages(), handler.getMessages().isEmpty()); | |||
compareJars(injar1, "src", outjar); | |||
} | |||
/* | |||
* Ensure bin contains all non-Java resouces from source and injars | |||
*/ | |||
public void compareDirs (String indirName, String outdirName) { | |||
public void compareDirs(String indirName, String outdirName) { | |||
File binBase = openFile(outdirName); | |||
File[] toResources = FileUtil.listFiles(binBase,aspectjResourceFileFilter); | |||
File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | |||
HashSet resources = new HashSet(); | |||
listSourceResources(indirName,resources); | |||
listSourceResources(indirName, resources); | |||
for (int i = 0; i < toResources.length; i++) { | |||
String fileName = FileUtil.normalizedPath(toResources[i],binBase); | |||
String fileName = FileUtil.normalizedPath(toResources[i], binBase); | |||
boolean b = resources.remove(fileName); | |||
assertTrue("Extraneous resources: " + fileName,b); | |||
assertTrue("Extraneous resources: " + fileName, b); | |||
} | |||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | |||
} | |||
private void listSourceResources (String indirName, Set resources) { | |||
} | |||
private void listSourceResources(String indirName, Set resources) { | |||
File srcBase = openFile(indirName); | |||
File[] fromResources = FileUtil.listFiles(srcBase,aspectjResourceFileFilter); | |||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||
for (int i = 0; i < fromResources.length; i++) { | |||
String name = FileUtil.normalizedPath(fromResources[i],srcBase); | |||
String name = FileUtil.normalizedPath(fromResources[i], srcBase); | |||
if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | |||
resources.add(name); | |||
} | |||
} | |||
} | |||
} | |||
public static final FileFilter aspectjResourceFileFilter = new FileFilter() { | |||
public boolean accept(File pathname) { | |||
String name = pathname.getName().toLowerCase(); | |||
boolean isCVSRelated = name.indexOf("/cvs/")!=-1; | |||
boolean isCVSRelated = name.indexOf("/cvs/") != -1; | |||
return (!isCVSRelated && !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj")); | |||
} | |||
}; | |||
/* | |||
* Ensure -outjar contains all non-Java resouces from injars | |||
*/ | |||
public void compareJars (File injarFile, String indirName, File outjarFile) { | |||
public void compareJars(File injarFile, String indirName, File outjarFile) { | |||
HashSet resources = new HashSet(); | |||
try { | |||
try { | |||
assertTrue( | |||
"outjar older than injar: outjarLastMod="+outjarFile.lastModified()+" injarLastMod="+injarFile.lastModified(), | |||
(outjarFile.lastModified() >= injarFile.lastModified())); | |||
byte[] inManifest = listJarResources(injarFile,resources,true); | |||
listSourceResources(indirName,resources); | |||
"outjar older than injar: outjarLastMod=" + outjarFile.lastModified() + " injarLastMod=" | |||
+ injarFile.lastModified(), (outjarFile.lastModified() >= injarFile.lastModified())); | |||
byte[] inManifest = listJarResources(injarFile, resources, true); | |||
listSourceResources(indirName, resources); | |||
ZipInputStream outjar = new ZipInputStream(new java.io.FileInputStream(outjarFile)); | |||
ZipEntry entry; | |||
while (null != (entry = outjar.getNextEntry())) { | |||
String fileName = entry.getName(); | |||
if (!fileName.endsWith(".class")) { | |||
/* Ensure we copied right JAR manifest */ | |||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | |||
byte[] outManifest = FileUtil.readAsByteArray(outjar); | |||
assertTrue("Wrong manifest has been copied",Arrays.equals(inManifest,outManifest)); | |||
assertTrue("Wrong manifest has been copied", Arrays.equals(inManifest, outManifest)); | |||
} | |||
boolean b = resources.remove(fileName); | |||
assertTrue(fileName,b); | |||
assertTrue(fileName, b); | |||
} | |||
outjar.closeEntry(); | |||
} | |||
outjar.close(); | |||
resources.remove("META-INF/"); | |||
assertTrue(resources.toString(),resources.isEmpty()); | |||
} | |||
catch (IOException ex) { | |||
assertTrue(resources.toString(), resources.isEmpty()); | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
} | |||
/* | |||
* Ensure -outjar conatins all non-Java resouces from source and injars | |||
*/ | |||
public void compareSourceToOutjar (String indirName, File outjarFile) { | |||
HashSet resources = new HashSet(); | |||
listSourceResources(indirName,resources); | |||
try { | |||
public void compareSourceToOutjar(String indirName, File outjarFile) { | |||
HashSet resources = new HashSet(); | |||
listSourceResources(indirName, resources); | |||
try { | |||
ZipInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||
ZipEntry entry; | |||
@@ -246,49 +235,49 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
String fileName = entry.getName(); | |||
if (!fileName.endsWith(".class")) { | |||
boolean b = resources.remove(fileName); | |||
assertTrue(fileName,b); | |||
assertTrue(fileName, b); | |||
} | |||
outjar.closeEntry(); | |||
} | |||
outjar.close(); | |||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | |||
} | |||
catch (IOException ex) { | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
} | |||
/* | |||
* Ensure bin contains all non-Java resouces from source and injars | |||
*/ | |||
public void compareInjarsToBin(File injarFile, String indirName, String outdirName) { | |||
HashSet resources = new HashSet(); | |||
try { | |||
byte[] inManifest = listJarResources(injarFile,resources,false); | |||
listSourceResources(indirName,resources); | |||
try { | |||
byte[] inManifest = listJarResources(injarFile, resources, false); | |||
listSourceResources(indirName, resources); | |||
File binBase = openFile(outdirName); | |||
File[] toResources = FileUtil.listFiles(binBase,aspectjResourceFileFilter); | |||
File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | |||
for (int i = 0; i < toResources.length; i++) { | |||
String fileName = FileUtil.normalizedPath(toResources[i],binBase); | |||
String fileName = FileUtil.normalizedPath(toResources[i], binBase); | |||
/* Ensure we copied the right JAR manifest */ | |||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | |||
byte[] outManifest = FileUtil.readAsByteArray(toResources[i]); | |||
assertTrue("Wrong manifest has been copied",Arrays.equals(inManifest,outManifest)); | |||
assertTrue("Wrong manifest has been copied", Arrays.equals(inManifest, outManifest)); | |||
} | |||
boolean b = resources.remove(fileName); | |||
assertTrue("Extraneous resources: " + fileName,b); | |||
assertTrue("Extraneous resources: " + fileName, b); | |||
} | |||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | |||
} | |||
catch (IOException ex) { | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
} | |||
/** | |||
* Look in the specified jar file for resources (anything not .class) and add it the resources Set. | |||
* | |||
@@ -297,9 +286,9 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
* @param wantDirectories should any directories found in the jar be included | |||
* @return the byte data for any discovered manifest | |||
*/ | |||
private byte[] listJarResources(File injarFile, Set resources, boolean wantDirectories) { | |||
private byte[] listJarResources(File injarFile, Set resources, boolean wantDirectories) { | |||
byte[] manifest = null; | |||
try { | |||
ZipInputStream injar = new ZipInputStream(new java.io.FileInputStream(injarFile)); | |||
ZipEntry entry; | |||
@@ -310,7 +299,7 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
resources.add(fileName); | |||
} | |||
} else if (!fileName.endsWith(".class")) { | |||
/* JAR manifests shouldn't be copied */ | |||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | |||
manifest = FileUtil.readAsByteArray(injar); | |||
@@ -320,11 +309,10 @@ public class ResourceCopyTests extends AjdeCoreTestCase { | |||
injar.closeEntry(); | |||
} | |||
injar.close(); | |||
} | |||
catch (IOException ex) { | |||
} catch (IOException ex) { | |||
fail(ex.toString()); | |||
} | |||
return manifest; | |||
} | |||
} | |||
} |
@@ -32,42 +32,34 @@ import org.aspectj.bridge.IMessage; | |||
import org.aspectj.util.LangUtil; | |||
/** | |||
* Weaving messages are complicated things. There are multiple places where weaving | |||
* takes place and the places vary depending on whether we are doing a binary weave or | |||
* going from source. All places that output weaving messages are tagged: | |||
* // TAG: WeavingMessage | |||
* so you can easily find them! | |||
* Weaving messages are complicated things. There are multiple places where weaving takes place and the places vary depending on | |||
* whether we are doing a binary weave or going from source. All places that output weaving messages are tagged: // TAG: | |||
* WeavingMessage so you can easily find them! | |||
* | |||
* Advice is the simplest to deal with as that is advice weaving is always done in the weaver. | |||
* | |||
* Next is intertype declarations. These are also always done in the weaver but in the case | |||
* of a binary weave we don't know the originating source line for the ITD. | |||
* Next is intertype declarations. These are also always done in the weaver but in the case of a binary weave we don't know the | |||
* originating source line for the ITD. | |||
* | |||
* Finally, declares. | |||
* Declare Parents: extends Can only be done when going from source, if attempted by a | |||
* binary weave then an error message (compiler limitation) is | |||
* produced. | |||
* Declare Parents: implements Is (currently!) done at both compile time and weave time. | |||
* If going from source then the message is produced by the | |||
* code in the compiler. if going from binary then the message | |||
* is produced by the weaver. | |||
* Declare Soft: Comes out with 'advice' as a special kind of advice: softener advice | |||
* Finally, declares. Declare Parents: extends Can only be done when going from source, if attempted by a binary weave then an error | |||
* message (compiler limitation) is produced. Declare Parents: implements Is (currently!) done at both compile time and weave time. | |||
* If going from source then the message is produced by the code in the compiler. if going from binary then the message is produced | |||
* by the weaver. Declare Soft: Comes out with 'advice' as a special kind of advice: softener advice | |||
* | |||
* | |||
* Q: Where are the messages turned on/off? | |||
* A: It is a bit messy. See BuildArgParser.genBuildConfig(). Basically that method is the first time | |||
* we parse the option set. Whether weaving messages are on or off is stored in the build config. | |||
* As soon as we have parser the options and determined that weave messages are on, we grab the | |||
* top level message handler and tell it not to ignore WeaveInfo messages. | |||
* Q: Where are the messages turned on/off? A: It is a bit messy. See BuildArgParser.genBuildConfig(). Basically that method is the | |||
* first time we parse the option set. Whether weaving messages are on or off is stored in the build config. As soon as we have | |||
* parser the options and determined that weave messages are on, we grab the top level message handler and tell it not to ignore | |||
* WeaveInfo messages. | |||
* | |||
* | |||
* TODO - Other forms of declare? Do they need messages? e.g. declare precedence * | |||
* TODO - Other forms of declare? Do they need messages? e.g. declare precedence * | |||
*/ | |||
public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
private static boolean regenerate; | |||
private static boolean debugTests = false; | |||
static { | |||
// Switch this to true for a single iteration if you want to reconstruct the | |||
// 'expected weaving messages' files. | |||
@@ -79,18 +71,18 @@ public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
public static final String binDir = "bin"; | |||
public static final String expectedResultsDir = "expected"; | |||
public String[] one = new String[] {"AspectAdvice.aj","Simple.java"}; | |||
public String[] two = new String[] {"AspectITD.aj","Simple.java"}; | |||
public String[] three = new String[] {"AspectDeclare.aj","Simple.java"}; | |||
public String[] four = new String[] {"AspectDeclareExtends.aj","Simple.java"}; | |||
public String[] five = new String[] {"Simple.java","AspectDeclareSoft.aj"}; | |||
public String[] six = new String[] {"AspectDeclareAnnotations.aj"}; | |||
public String[] seven = new String[] {"AspectDeclareAnnotations.aj"}; | |||
public String[] one = new String[] { "AspectAdvice.aj", "Simple.java" }; | |||
public String[] two = new String[] { "AspectITD.aj", "Simple.java" }; | |||
public String[] three = new String[] { "AspectDeclare.aj", "Simple.java" }; | |||
public String[] four = new String[] { "AspectDeclareExtends.aj", "Simple.java" }; | |||
public String[] five = new String[] { "Simple.java", "AspectDeclareSoft.aj" }; | |||
public String[] six = new String[] { "AspectDeclareAnnotations.aj" }; | |||
public String[] seven = new String[] { "AspectDeclareAnnotations.aj" }; | |||
public String[] empty = new String[] {}; | |||
private TestMessageHandler handler; | |||
private TestCompilerConfiguration compilerConfig; | |||
protected void setUp() throws Exception { | |||
super.setUp(); | |||
initialiseProject(PROJECT_DIR); | |||
@@ -105,214 +97,212 @@ public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
handler = null; | |||
compilerConfig = null; | |||
} | |||
/** | |||
* Weave all the possible kinds of advice and verify the messages that come out. | |||
*/ | |||
public void testWeaveMessagesAdvice() { | |||
if (debugTests) System.out.println("testWeaveMessagesAdvice: Building with One.lst"); | |||
if (debugTests) | |||
System.out.println("testWeaveMessagesAdvice: Building with One.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(one)); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice", true); | |||
} | |||
/** | |||
* Weave field and method ITDs and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesITD() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesITD: Building with Two.lst"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesITD: Building with Two.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(two)); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd", true); | |||
} | |||
/** | |||
* Weave "declare parents: implements" and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesDeclare() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesDeclare: Building with Three.lst"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesDeclare: Building with Three.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(three)); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1", true); | |||
} | |||
/** | |||
* Weave "declare parents: extends" and check the weave messages that come out. | |||
* Can't do equivalent binary test - as can't do extends in binary. | |||
* Weave "declare parents: extends" and check the weave messages that come out. Can't do equivalent binary test - as can't do | |||
* extends in binary. | |||
*/ | |||
public void testWeaveMessagesDeclareExtends() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesDeclareExtends: Building with Four.lst"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesDeclareExtends: Building with Four.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(four)); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.extends",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.extends", true); | |||
} | |||
/** | |||
* Weave "declare soft: type: pointcut" and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesDeclareSoft() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesDeclareSoft: Building with Five.lst"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesDeclareSoft: Building with Five.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(five)); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft", true); | |||
} | |||
/** | |||
* Weave 'declare @type, @constructor, @method and @field' and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesDeclareAnnotation() { | |||
if (!LangUtil.is15VMOrGreater()) return; // annotation classes won't be about pre 15 | |||
if (debugTests) System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Six.lst"); | |||
if (!LangUtil.is15VMOrGreater()) | |||
return; // annotation classes won't be about pre 15 | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Six.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(six)); | |||
setRunIn15Mode(); | |||
compilerConfig.setNonStandardOptions("-showWeaveInfo -1.5"); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.annotation",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.annotation", true); | |||
} | |||
/** | |||
* Weave 'declare @type, @constructor, @method and @field' and check the weave messages don't come out without the -showWeaveInfo arg. | |||
* Weave 'declare @type, @constructor, @method and @field' and check the weave messages don't come out without the | |||
* -showWeaveInfo arg. | |||
*/ | |||
public void testWeaveMessagesDeclareAnnotationWeaveInfoOff() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Seven.lst"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Seven.lst"); | |||
compilerConfig.setProjectSourceFiles(getSourceFileList(seven)); | |||
compilerConfig.setNonStandardOptions(""); | |||
setRunIn15Mode(); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.annotationNoWeaveInfo",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.annotationNoWeaveInfo", true); | |||
} | |||
// BINARY WEAVING TESTS | |||
/** | |||
* Binary weave variant of the advice weaving test above - to check messages are ok for | |||
* binary weave. Unlike the source level weave, in this test we are using an aspect on | |||
* the aspectpath - which means it has already had its necessary parts woven - so the list | |||
* of weaving messages we expect is less. | |||
* Binary weave variant of the advice weaving test above - to check messages are ok for binary weave. Unlike the source level | |||
* weave, in this test we are using an aspect on the aspectpath - which means it has already had its necessary parts woven - so | |||
* the list of weaving messages we expect is less. | |||
*/ | |||
public void testWeaveMessagesBinaryAdvice() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectAdvice.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary", true); | |||
} | |||
public void testWeaveMessagesBinaryITD() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectITD.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd",false); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd", false); | |||
} | |||
public void testWeaveMessagesBinaryDeclare() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryDeclare: Simple.jar + AspectDeclare.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryDeclare: Simple.jar + AspectDeclare.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectDeclare.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1",false); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1", false); | |||
} | |||
/** | |||
* Weave "declare soft: type: pointcut" and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesBinaryDeclareSoft() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryDeclareSoft: Simple.jar + AspectDeclareSoft.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryDeclareSoft: Simple.jar + AspectDeclareSoft.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectDeclareSoft.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft.binary",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft.binary", true); | |||
} | |||
public void testWeaveMessagesBinaryAdviceInPackageFromJar() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryAdviceInPackageFromJar: Simple.jar + AspectInPackage.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryAdviceInPackageFromJar: Simple.jar + AspectInPackage.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectInPackage.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.package.jar",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.package.jar", true); | |||
} | |||
public void testWeaveMessagesBinaryAdviceInPackage() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryAdviceInPackage: Simple.jar + AspectInPackage.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryAdviceInPackage: Simple.jar + AspectInPackage.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("pkg")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.package",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.package", true); | |||
} | |||
// BINARY WEAVING WHEN WE'VE LOST THE SOURCE POINTERS | |||
public void testWeaveMessagesBinaryAdviceNoDebugInfo() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryAdvice: Simple.jar + AspectAdvice.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple_nodebug.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectAdvice_nodebug.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.nodebug",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("advice.binary.nodebug", true); | |||
} | |||
public void testWeaveMessagesBinaryITDNoDebugInfo() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryITD: Simple.jar + AspectITD.jar"); | |||
Set inpath = new HashSet(); | |||
inpath.add(openFile("Simple_nodebug.jar")); | |||
compilerConfig.setInpath(inpath); | |||
@@ -320,45 +310,43 @@ public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
aspectpath.add(openFile("AspectITD_nodebug.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd.nodebug",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("itd.nodebug", true); | |||
} | |||
public void testWeaveMessagesBinaryDeclareNoDebugInfo() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryDeclareNoDebugInfo: Simple.jar + AspectDeclare.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryDeclareNoDebugInfo: Simple.jar + AspectDeclare.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple_nodebug.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectDeclare_nodebug.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1.nodebug",true); | |||
} | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare1.nodebug", true); | |||
} | |||
/** | |||
* Weave "declare soft: type: pointcut" and check the weave messages that come out. | |||
*/ | |||
public void testWeaveMessagesBinaryDeclareSoftNoDebugInfo() { | |||
if (debugTests) System.out.println("\ntestWeaveMessagesBinaryDeclareSoftNoDebugInfo: Simple.jar + AspectDeclareSoft.jar"); | |||
Set inpath = new HashSet(); | |||
if (debugTests) | |||
System.out.println("\ntestWeaveMessagesBinaryDeclareSoftNoDebugInfo: Simple.jar + AspectDeclareSoft.jar"); | |||
Set<File> inpath = new HashSet<File>(); | |||
inpath.add(openFile("Simple_nodebug.jar")); | |||
compilerConfig.setInpath(inpath); | |||
Set aspectpath = new HashSet(); | |||
Set<File> aspectpath = new HashSet<File>(); | |||
aspectpath.add(openFile("AspectDeclareSoft_nodebug.jar")); | |||
compilerConfig.setAspectPath(aspectpath); | |||
doBuild(); | |||
assertTrue("Expected no compiler errors but found " | |||
+ handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft.binary.nodebug",true); | |||
assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty()); | |||
verifyWeavingMessages("declare.soft.binary.nodebug", true); | |||
} | |||
public void verifyWeavingMessages(String testid,boolean source) { | |||
File expectedF = openFile(expectedResultsDir+File.separator+testid+".txt"); | |||
public void verifyWeavingMessages(String testid, boolean source) { | |||
File expectedF = openFile(expectedResultsDir + File.separator + testid + ".txt"); | |||
if (regenerate && source) { | |||
// Create the file | |||
saveWeaveMessages(expectedF); | |||
@@ -367,7 +355,7 @@ public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
compareWeaveMessages(expectedF); | |||
} | |||
} | |||
/** | |||
* Compare weaving messages with what is in the file | |||
*/ | |||
@@ -378,69 +366,73 @@ public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | |||
// Load the file in | |||
fr = new BufferedReader(new FileReader(f)); | |||
String line = null; | |||
while ((line=fr.readLine())!=null) fileContents.add(line); | |||
while ((line = fr.readLine()) != null) | |||
fileContents.add(line); | |||
List originalFileContents = new ArrayList(); | |||
originalFileContents.addAll(fileContents); | |||
// See if the messages match | |||
int msgCount = 0; | |||
List l = handler.getMessages(); | |||
for (Iterator iter = l.iterator(); iter.hasNext();) { | |||
IMessage msg = ((TestMessageHandler.TestMessage) iter.next()).getContainedMessage(); | |||
if (debugTests) System.out.println("Looking at ["+msg+"]"); | |||
if (debugTests) | |||
System.out.println("Looking at [" + msg + "]"); | |||
if (msg.getKind().equals(IMessage.WEAVEINFO)) { | |||
if (!fileContents.contains(msg.getMessage())) { | |||
fail("Could not find message '"+msg.getMessage()+"' in the expected results. Expected results are:\n"+ | |||
stringify(originalFileContents)); | |||
fail("Could not find message '" + msg.getMessage() + "' in the expected results. Expected results are:\n" | |||
+ stringify(originalFileContents)); | |||
} else { | |||
fileContents.remove(msg.getMessage()); | |||
} | |||
msgCount++; | |||
} | |||
} | |||
assertTrue("Didn't get these expected messages: "+fileContents,fileContents.size()==0); | |||
if (debugTests) System.out.println("Successfully verified "+msgCount+" weaving messages"); | |||
assertTrue("Didn't get these expected messages: " + fileContents, fileContents.size() == 0); | |||
if (debugTests) | |||
System.out.println("Successfully verified " + msgCount + " weaving messages"); | |||
} catch (Exception e) { | |||
fail("Unexpected exception saving weaving messages:"+e); | |||
fail("Unexpected exception saving weaving messages:" + e); | |||
} | |||
} | |||
private String stringify(List l) { | |||
StringBuffer result = new StringBuffer(); | |||
for (Iterator iter = l.iterator(); iter.hasNext();) { | |||
String str = (String) iter.next(); | |||
result.append(str);result.append("\n"); | |||
result.append(str); | |||
result.append("\n"); | |||
} | |||
return result.toString(); | |||
} | |||
/** | |||
* Store the weaving messages in the specified file. | |||
*/ | |||
private void saveWeaveMessages(File f) { | |||
System.out.println("Saving weave messages into "+f.getName()); | |||
System.out.println("Saving weave messages into " + f.getName()); | |||
FileWriter fw; | |||
try { | |||
fw = new FileWriter(f); | |||
fw = new FileWriter(f); | |||
List l = handler.getMessages(); | |||
for (Iterator iter = l.iterator(); iter.hasNext();) { | |||
IMessage msg = ((TestMessageHandler.TestMessage) iter.next()).getContainedMessage(); | |||
if (msg.getKind().equals(IMessage.WEAVEINFO)) { | |||
fw.write(msg.getMessage()+"\n"); | |||
fw.write(msg.getMessage() + "\n"); | |||
} | |||
} | |||
fw.close(); | |||
} catch (Exception e) { | |||
fail("Unexpected exception saving weaving messages:"+e); | |||
fail("Unexpected exception saving weaving messages:" + e); | |||
} | |||
} | |||
private void setRunIn15Mode() { | |||
Map m = new Hashtable(); | |||
m.put(JavaOptions.COMPLIANCE_LEVEL,JavaOptions.VERSION_15); | |||
m.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL,JavaOptions.VERSION_15); | |||
m.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL,JavaOptions.VERSION_15); | |||
m.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_15); | |||
m.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_15); | |||
m.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL, JavaOptions.VERSION_15); | |||
compilerConfig.setJavaOptions(m); | |||
} | |||
} |
@@ -46,12 +46,12 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase { | |||
// // see pr148027 | |||
// public void testUsesPointcut() { | |||
// if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return; | |||
// | |||
// | |||
// IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage"); | |||
// assertNotNull(ptUsage); | |||
// IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts"); | |||
// assertNotNull(pts); | |||
// | |||
// | |||
// IProgramElement pUsesA = manager.getHierarchy().findElementForLabel( | |||
// ptUsage, | |||
// IProgramElement.Kind.POINTCUT, | |||
@@ -63,7 +63,7 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase { | |||
// IProgramElement.Kind.POINTCUT, | |||
// "a()"/*Point"*/); | |||
// assertNotNull(ptsA); | |||
// | |||
// | |||
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0); | |||
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0); | |||
// } | |||
@@ -81,7 +81,7 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase { | |||
assertTrue(rels.size() > 0); | |||
// assertTrue(rel.getTargets().size() > 0); | |||
// | |||
// | |||
// checkDeclareMapping("DeclareCoverage", "Point", , | |||
// "Point", "matched by", "matches declare", | |||
// IProgramElement.Kind.DECLARE_PARENTS); | |||
@@ -137,7 +137,7 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase { | |||
.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); | |||
assertNotNull(beforeExecNode); | |||
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); | |||
for (Iterator it = rel.getTargets().iterator(); it.hasNext();) { | |||
for (Iterator<String> it = rel.getTargets().iterator(); it.hasNext();) { | |||
String currHandle = (String) it.next(); | |||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) | |||
return; | |||
@@ -184,7 +184,7 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase { | |||
// String set = to; | |||
IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); | |||
// String handle2 = (String)rel2.getTargets().get(0); | |||
for (Iterator it = rel2.getTargets().iterator(); it.hasNext();) { | |||
for (Iterator<String> it = rel2.getTargets().iterator(); it.hasNext();) { | |||
String currHandle = (String) it.next(); | |||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) | |||
return; |