return config; | return config; | ||||
} | } | ||||
private void mergeInto(Collection target, Collection source) { | |||||
private <T> void mergeInto(Collection<T> target, Collection<T> source) { | |||||
if ((null == target) || (null == source)) { | if ((null == target) || (null == source)) { | ||||
return; | return; | ||||
} | } | ||||
for (Iterator iter = source.iterator(); iter.hasNext();) { | |||||
Object next = iter.next(); | |||||
for (T next : source) { | |||||
if (!target.contains(next)) { | if (!target.contains(next)) { | ||||
target.add(next); | target.add(next); | ||||
} | } |
private String projectPath; | private String projectPath; | ||||
private Set aspectpath; | |||||
private Set inpath; | |||||
private Set<File> aspectpath; | |||||
private Set<File> inpath; | |||||
private String outjar; | private String outjar; | ||||
private Map javaOptions; | |||||
private Map<String, String> javaOptions; | |||||
private String nonStandardOptions; | 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"; | private String srcDirName = "src"; | ||||
this.projectPath = projectPath; | this.projectPath = projectPath; | ||||
} | } | ||||
public Set getAspectPath() { | |||||
public Set<File> getAspectPath() { | |||||
return aspectpath; | return aspectpath; | ||||
} | } | ||||
public List getProjectXmlConfigFiles() { | |||||
return Collections.EMPTY_LIST; | |||||
public List<String> getProjectXmlConfigFiles() { | |||||
return Collections.emptyList(); | |||||
} | } | ||||
public String getClasspath() { | public String getClasspath() { | ||||
+ AjcTests.aspectjrtClasspath(); | + AjcTests.aspectjrtClasspath(); | ||||
} | } | ||||
public Set getInpath() { | |||||
public Set<File> getInpath() { | |||||
return inpath; | return inpath; | ||||
} | } | ||||
public Map getJavaOptionsMap() { | |||||
public Map<String, String> getJavaOptionsMap() { | |||||
if (javaOptions == null) { | if (javaOptions == null) { | ||||
javaOptions = new Hashtable(); | |||||
javaOptions = new Hashtable<String, String>(); | |||||
javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13); | javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13); | ||||
javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13); | javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13); | ||||
} | } | ||||
return outputLoc; | return outputLoc; | ||||
} | } | ||||
public List getProjectSourceFiles() { | |||||
public List<String> getProjectSourceFiles() { | |||||
return projectSourceFiles; | return projectSourceFiles; | ||||
} | } | ||||
public void configurationRead() { | public void configurationRead() { | ||||
} | } | ||||
public Map getSourcePathResources() { | |||||
public Map<String, File> getSourcePathResources() { | |||||
if (sourcePathResources == null) { | if (sourcePathResources == null) { | ||||
sourcePathResources = new HashMap(); | |||||
sourcePathResources = new HashMap<String, File>(); | |||||
/* Allow the user to override the testProjectPath by using sourceRoots */ | /* Allow the user to override the testProjectPath by using sourceRoots */ | ||||
File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; | ||||
} | } | ||||
// -------------------- setter methods useful for testing --------------- | // -------------------- setter methods useful for testing --------------- | ||||
public void setAspectPath(Set aspectPath) { | |||||
public void setAspectPath(Set<File> aspectPath) { | |||||
this.aspectpath = aspectPath; | this.aspectpath = aspectPath; | ||||
} | } | ||||
public void setInpath(Set inpath) { | |||||
public void setInpath(Set<File> inpath) { | |||||
this.inpath = inpath; | this.inpath = inpath; | ||||
} | } | ||||
this.nonStandardOptions = options; | this.nonStandardOptions = options; | ||||
} | } | ||||
public void setProjectSourceFiles(List projectSourceFiles) { | |||||
public void setProjectSourceFiles(List<String> projectSourceFiles) { | |||||
this.projectSourceFiles = projectSourceFiles; | this.projectSourceFiles = projectSourceFiles; | ||||
} | } | ||||
public void setSourcePathResources(Map sourcePathResources) { | |||||
public void setSourcePathResources(Map<String, File> sourcePathResources) { | |||||
this.sourcePathResources = sourcePathResources; | this.sourcePathResources = sourcePathResources; | ||||
} | } | ||||
public class InpathTests extends AjdeCoreTestCase { | public class InpathTests extends AjdeCoreTestCase { | ||||
public static final FileFilter aspectjResourceFileFilter = | |||||
new FileFilter() { | |||||
public static final FileFilter aspectjResourceFileFilter = new FileFilter() { | |||||
public boolean accept(File pathname) { | public boolean accept(File pathname) { | ||||
String name = pathname.getName().toLowerCase(); | 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 indir1Name = "indir1"; | ||||
public static final String indir2Name = "indir2"; | 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"; | 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 TestMessageHandler handler; | ||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject("InpathTest"); | initialiseProject("InpathTest"); | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | handler = (TestMessageHandler) getCompiler().getMessageHandler(); | ||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | |||||
.getCompilerConfiguration(); | |||||
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration(); | |||||
} | } | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
handler = null; | handler = null; | ||||
compilerConfig = 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() { | public void testInpathToOutjar() { | ||||
Set inpath = new HashSet(); | |||||
Set<File> inpath = new HashSet<File>(); | |||||
File indir1 = openFile(indir1Name); | File indir1 = openFile(indir1Name); | ||||
inpath.add(indir1); | inpath.add(indir1); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
File outjar = openFile(outjarName); | File outjar = openFile(outjarName); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(build1)); | 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 | // 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"); | expectedOutputJarContents.add("test/TestProperties.class"); | ||||
// From src | // From src | ||||
expectedOutputJarContents.add("Main.class"); | expectedOutputJarContents.add("Main.class"); | ||||
} | } | ||||
/** | /** | ||||
* 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() { | public void testInpathToBin() { | ||||
Set inpath = new HashSet(); | Set inpath = new HashSet(); | ||||
inpath.add(indir1); | inpath.add(indir1); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(build1)); | 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(); | Set expectedBindirContents = new HashSet(); | ||||
// From indir1 | // 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"); | expectedBindirContents.add("test/TestProperties.class"); | ||||
// From src | // From src | ||||
expectedBindirContents.add("Main.class"); | expectedBindirContents.add("Main.class"); | ||||
} | } | ||||
/** | /** | ||||
* 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). | * 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() { | public void testInpathToOutjar2() { | ||||
Set inpath = new HashSet(); | |||||
Set<File> inpath = new HashSet<File>(); | |||||
File indir2 = openFile(indir2Name); | File indir2 = openFile(indir2Name); | ||||
inpath.add(indir2); | inpath.add(indir2); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
File outjar = openFile(outjarName); | File outjar = openFile(outjarName); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(build2)); | 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 | // From indir1 | ||||
expectedOutputJarContents.add("example/HelloWorld.class"); | 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 | // From src | ||||
expectedOutputJarContents.add("Aspect.class"); | expectedOutputJarContents.add("Aspect.class"); | ||||
compareJars(indir2, "src", outjar, expectedOutputJarContents); | 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 | // by the aspect - verify that the size of the HelloWorld class in the output directory | ||||
// is a different size to the input version. | // is a different size to the input version. | ||||
int outputsize = fetchFromJar(outjar, "example/HelloWorld.class"); | |||||
int outputsize = fetchFromJar(outjar, "example/HelloWorld.class"); | |||||
try { | try { | ||||
FileInputStream fis = new FileInputStream(openFile(indir2Name+"/example/HelloWorld.class")); | |||||
FileInputStream fis = new FileInputStream(openFile(indir2Name + "/example/HelloWorld.class")); | |||||
byte[] filedata = FileUtil.readAsByteArray(fis); | byte[] filedata = FileUtil.readAsByteArray(fis); | ||||
int inputsize = filedata.length; | int inputsize = filedata.length; | ||||
assertTrue("Weaving of Aspect should have occurred but the input and output size for HelloWorld.class are the same", | 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) { | } catch (Exception e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
fail(); | fail(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* More complex inpath - a jar and a directory | * 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() { | public void testInpathAndInjarToBin() { | ||||
Set inpath = new HashSet(); | |||||
Set<File> inpath = new HashSet<File>(); | |||||
File indir2 = openFile(indir2Name); | File indir2 = openFile(indir2Name); | ||||
inpath.add(indir2); | inpath.add(indir2); | ||||
inpath.add(openFile(injarName)); | inpath.add(openFile(injarName)); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(build2)); | 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 | // From indir1 | ||||
expectedBindirContents.add("example/HelloWorld.class"); | 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 | // From injar.jar | ||||
expectedBindirContents.add("props/resources.properties"); | expectedBindirContents.add("props/resources.properties"); | ||||
// From src | // From src | ||||
expectedBindirContents.add("Aspect.class"); | expectedBindirContents.add("Aspect.class"); | ||||
compareIndirToBin(indir2, "src", "bin", expectedBindirContents); | compareIndirToBin(indir2, "src", "bin", expectedBindirContents); | ||||
// Check the input and output versions of HelloWorld.class are different sizes | // Check the input and output versions of HelloWorld.class are different sizes | ||||
try { | try { | ||||
FileInputStream fis1 = new FileInputStream(openFile("indir2/example/HelloWorld.class")); | FileInputStream fis1 = new FileInputStream(openFile("indir2/example/HelloWorld.class")); | ||||
byte[] filedata2 = FileUtil.readAsByteArray(fis2); | byte[] filedata2 = FileUtil.readAsByteArray(fis2); | ||||
int outputsize = filedata2.length; | int outputsize = filedata2.length; | ||||
assertTrue("Weaving of Aspect should have occurred but the input and output size for HelloWorld.class are the same", | 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(); | fis1.close(); | ||||
fis2.close(); | fis2.close(); | ||||
fail(); | fail(); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Ensure -outjar contains all non-Java resouces from injars | * 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 { | try { | ||||
assertTrue( | 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 | // Go through the output jar file, for each element, remove it from | ||||
// the expectedOutputJarContents - when we finish, the expectedOutputJarContents | // the expectedOutputJarContents - when we finish, the expectedOutputJarContents | ||||
// set should be empty! | // set should be empty! | ||||
JarInputStream outjar = | |||||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
JarInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
ZipEntry entry; | ZipEntry entry; | ||||
while (null != (entry = outjar.getNextEntry())) { | while (null != (entry = outjar.getNextEntry())) { | ||||
String fileName = entry.getName(); | String fileName = entry.getName(); | ||||
fileName = fileName.replace('\\', '/'); | fileName = fileName.replace('\\', '/'); | ||||
if (fileName.indexOf("CVS") == -1) { | if (fileName.indexOf("CVS") == -1) { | ||||
boolean b = expectedOutputJarContents.remove(fileName); | boolean b = expectedOutputJarContents.remove(fileName); | ||||
assertTrue( | |||||
"Unexpectedly found : " + fileName + " in outjar", | |||||
b); | |||||
assertTrue("Unexpectedly found : " + fileName + " in outjar", b); | |||||
} | } | ||||
outjar.closeEntry(); | outjar.closeEntry(); | ||||
} | } | ||||
outjar.close(); | 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) { | } catch (IOException ex) { | ||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
try { | try { | ||||
JarInputStream outjar = | |||||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
JarInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
ZipEntry entry; | ZipEntry entry; | ||||
while (null != (entry = outjar.getNextEntry())) { | while (null != (entry = outjar.getNextEntry())) { | ||||
String fileName = entry.getName(); | String fileName = entry.getName(); | ||||
} | } | ||||
outjar.close(); | outjar.close(); | ||||
assertTrue( | |||||
"Missing resources: " + resources.toString(), | |||||
resources.isEmpty()); | |||||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | |||||
} catch (IOException ex) { | } catch (IOException ex) { | ||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
/* | /* | ||||
* Ensure bin contains all non-Java resouces from source and injars | * 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); | File binBase = openFile(outdirName); | ||||
String[] toResources = FileUtil.listFiles(binBase); | String[] toResources = FileUtil.listFiles(binBase); | ||||
} | } | ||||
} | } | ||||
assertTrue( | |||||
"Missing resources: " + expectedOutdirContents.toString(), | |||||
expectedOutdirContents.isEmpty()); | |||||
assertTrue("Missing resources: " + expectedOutdirContents.toString(), expectedOutdirContents.isEmpty()); | |||||
} | } | ||||
private void listSourceResources(String indirName, Set resources) { | private void listSourceResources(String indirName, Set resources) { | ||||
File srcBase = openFile(indirName); | File srcBase = openFile(indirName); | ||||
File[] fromResources = | |||||
FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||||
for (int i = 0; i < fromResources.length; i++) { | for (int i = 0; i < fromResources.length; i++) { | ||||
String name = FileUtil.normalizedPath(fromResources[i], srcBase); | 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); | resources.add(name); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Return the size of specified entry from the output jar file | // Return the size of specified entry from the output jar file | ||||
public int fetchFromJar(File outjarFile, String filename) { | public int fetchFromJar(File outjarFile, String filename) { | ||||
int ret = -1; | int ret = -1; | ||||
try { | try { | ||||
JarInputStream outjar; | JarInputStream outjar; | ||||
outjar = | |||||
new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | |||||
ZipEntry entry; | ZipEntry entry; | ||||
while (null != (entry = outjar.getNextEntry())) { | while (null != (entry = outjar.getNextEntry())) { | ||||
String zipentryname = entry.getName(); | String zipentryname = entry.getName(); | ||||
if (zipentryname.equals(filename)) { | 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(); | outjar.closeEntry(); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
} | } |
public class ResourceCopyTests extends AjdeCoreTestCase { | 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 TestMessageHandler handler; | ||||
private TestCompilerConfiguration compilerConfig; | 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 { | protected void setUp() throws Exception { | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject(PROJECT_DIR); | initialiseProject(PROJECT_DIR); | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | handler = (TestMessageHandler) getCompiler().getMessageHandler(); | ||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | |||||
.getCompilerConfiguration(); | |||||
compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration(); | |||||
} | } | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
handler = null; | handler = null; | ||||
compilerConfig = null; | compilerConfig = null; | ||||
} | } | ||||
public void testSrcToBin () { | |||||
public void testSrcToBin() { | |||||
assertTrue("Expected there to be no compiler messages but found " + handler.getMessages(), handler.getMessages().isEmpty()); | assertTrue("Expected there to be no compiler messages but found " + handler.getMessages(), handler.getMessages().isEmpty()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | ||||
doBuild(true); | 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); | File injar1 = openFile(injar1Name); | ||||
injars.add(injar1); | injars.add(injar1); | ||||
compilerConfig.setInpath(injars); | compilerConfig.setInpath(injars); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | ||||
doBuild(true); | 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 injar1 = openFile(injar1Name); | ||||
File injar2 = openFile(injar2Name); | File injar2 = openFile(injar2Name); | ||||
injars.add(injar1); | injars.add(injar1); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | ||||
doBuild(true); | 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(); | List msgs = handler.getMessages(); | ||||
String exp = "duplicate resource: "; | 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); | File outjar = openFile(outjarName); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config1)); | ||||
doBuild(true); | 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(); | Set injars = new HashSet(); | ||||
File injar1 = openFile(injar1Name); | File injar1 = openFile(injar1Name); | ||||
injars.add(injar1); | injars.add(injar1); | ||||
compilerConfig.setInpath(injars); | compilerConfig.setInpath(injars); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | ||||
doBuild(true); | 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 injar1 = openFile("input1"); | ||||
File outjar = openFile(outjarName+".fozout"); | |||||
File outjar = openFile(outjarName + ".fozout"); | |||||
injars.add(injar1); | injars.add(injar1); | ||||
compilerConfig.setInpath(injars); | compilerConfig.setInpath(injars); | ||||
compilerConfig.setOutjar(outjar.getAbsolutePath()); | compilerConfig.setOutjar(outjar.getAbsolutePath()); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | compilerConfig.setProjectSourceFiles(getSourceFileList(config2)); | ||||
doBuild(true); | 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 | * 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 binBase = openFile(outdirName); | ||||
File[] toResources = FileUtil.listFiles(binBase,aspectjResourceFileFilter); | |||||
File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | |||||
HashSet resources = new HashSet(); | HashSet resources = new HashSet(); | ||||
listSourceResources(indirName,resources); | |||||
listSourceResources(indirName, resources); | |||||
for (int i = 0; i < toResources.length; i++) { | 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); | boolean b = resources.remove(fileName); | ||||
assertTrue("Extraneous resources: " + fileName,b); | |||||
assertTrue("Extraneous resources: " + fileName, b); | |||||
} | } | ||||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | 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 srcBase = openFile(indirName); | ||||
File[] fromResources = FileUtil.listFiles(srcBase,aspectjResourceFileFilter); | |||||
File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); | |||||
for (int i = 0; i < fromResources.length; i++) { | 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")) { | if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { | ||||
resources.add(name); | resources.add(name); | ||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
public static final FileFilter aspectjResourceFileFilter = new FileFilter() { | public static final FileFilter aspectjResourceFileFilter = new FileFilter() { | ||||
public boolean accept(File pathname) { | public boolean accept(File pathname) { | ||||
String name = pathname.getName().toLowerCase(); | 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")); | return (!isCVSRelated && !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj")); | ||||
} | } | ||||
}; | }; | ||||
/* | /* | ||||
* Ensure -outjar contains all non-Java resouces from injars | * 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(); | HashSet resources = new HashSet(); | ||||
try { | |||||
try { | |||||
assertTrue( | 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)); | ZipInputStream outjar = new ZipInputStream(new java.io.FileInputStream(outjarFile)); | ||||
ZipEntry entry; | ZipEntry entry; | ||||
while (null != (entry = outjar.getNextEntry())) { | while (null != (entry = outjar.getNextEntry())) { | ||||
String fileName = entry.getName(); | String fileName = entry.getName(); | ||||
if (!fileName.endsWith(".class")) { | if (!fileName.endsWith(".class")) { | ||||
/* Ensure we copied right JAR manifest */ | /* Ensure we copied right JAR manifest */ | ||||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | ||||
byte[] outManifest = FileUtil.readAsByteArray(outjar); | 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); | boolean b = resources.remove(fileName); | ||||
assertTrue(fileName,b); | |||||
assertTrue(fileName, b); | |||||
} | } | ||||
outjar.closeEntry(); | outjar.closeEntry(); | ||||
} | } | ||||
outjar.close(); | outjar.close(); | ||||
resources.remove("META-INF/"); | resources.remove("META-INF/"); | ||||
assertTrue(resources.toString(),resources.isEmpty()); | |||||
} | |||||
catch (IOException ex) { | |||||
assertTrue(resources.toString(), resources.isEmpty()); | |||||
} catch (IOException ex) { | |||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Ensure -outjar conatins all non-Java resouces from source and injars | * 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)); | ZipInputStream outjar = new JarInputStream(new java.io.FileInputStream(outjarFile)); | ||||
ZipEntry entry; | ZipEntry entry; | ||||
String fileName = entry.getName(); | String fileName = entry.getName(); | ||||
if (!fileName.endsWith(".class")) { | if (!fileName.endsWith(".class")) { | ||||
boolean b = resources.remove(fileName); | boolean b = resources.remove(fileName); | ||||
assertTrue(fileName,b); | |||||
assertTrue(fileName, b); | |||||
} | } | ||||
outjar.closeEntry(); | outjar.closeEntry(); | ||||
} | } | ||||
outjar.close(); | outjar.close(); | ||||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | ||||
} | |||||
catch (IOException ex) { | |||||
} catch (IOException ex) { | |||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Ensure bin contains all non-Java resouces from source and injars | * Ensure bin contains all non-Java resouces from source and injars | ||||
*/ | */ | ||||
public void compareInjarsToBin(File injarFile, String indirName, String outdirName) { | public void compareInjarsToBin(File injarFile, String indirName, String outdirName) { | ||||
HashSet resources = new HashSet(); | 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 binBase = openFile(outdirName); | ||||
File[] toResources = FileUtil.listFiles(binBase,aspectjResourceFileFilter); | |||||
File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); | |||||
for (int i = 0; i < toResources.length; i++) { | 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 */ | /* Ensure we copied the right JAR manifest */ | ||||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | ||||
byte[] outManifest = FileUtil.readAsByteArray(toResources[i]); | 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); | boolean b = resources.remove(fileName); | ||||
assertTrue("Extraneous resources: " + fileName,b); | |||||
assertTrue("Extraneous resources: " + fileName, b); | |||||
} | } | ||||
assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | assertTrue("Missing resources: " + resources.toString(), resources.isEmpty()); | ||||
} | |||||
catch (IOException ex) { | |||||
} catch (IOException ex) { | |||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Look in the specified jar file for resources (anything not .class) and add it the resources Set. | * Look in the specified jar file for resources (anything not .class) and add it the resources Set. | ||||
* | * | ||||
* @param wantDirectories should any directories found in the jar be included | * @param wantDirectories should any directories found in the jar be included | ||||
* @return the byte data for any discovered manifest | * @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; | byte[] manifest = null; | ||||
try { | try { | ||||
ZipInputStream injar = new ZipInputStream(new java.io.FileInputStream(injarFile)); | ZipInputStream injar = new ZipInputStream(new java.io.FileInputStream(injarFile)); | ||||
ZipEntry entry; | ZipEntry entry; | ||||
resources.add(fileName); | resources.add(fileName); | ||||
} | } | ||||
} else if (!fileName.endsWith(".class")) { | } else if (!fileName.endsWith(".class")) { | ||||
/* JAR manifests shouldn't be copied */ | /* JAR manifests shouldn't be copied */ | ||||
if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { | ||||
manifest = FileUtil.readAsByteArray(injar); | manifest = FileUtil.readAsByteArray(injar); | ||||
injar.closeEntry(); | injar.closeEntry(); | ||||
} | } | ||||
injar.close(); | injar.close(); | ||||
} | |||||
catch (IOException ex) { | |||||
} catch (IOException ex) { | |||||
fail(ex.toString()); | fail(ex.toString()); | ||||
} | } | ||||
return manifest; | return manifest; | ||||
} | |||||
} | |||||
} | } |
import org.aspectj.util.LangUtil; | 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. | * 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 { | public class ShowWeaveMessagesTests extends AjdeCoreTestCase { | ||||
private static boolean regenerate; | private static boolean regenerate; | ||||
private static boolean debugTests = false; | private static boolean debugTests = false; | ||||
static { | static { | ||||
// Switch this to true for a single iteration if you want to reconstruct the | // Switch this to true for a single iteration if you want to reconstruct the | ||||
// 'expected weaving messages' files. | // 'expected weaving messages' files. | ||||
public static final String binDir = "bin"; | public static final String binDir = "bin"; | ||||
public static final String expectedResultsDir = "expected"; | 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[] {}; | public String[] empty = new String[] {}; | ||||
private TestMessageHandler handler; | private TestMessageHandler handler; | ||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
protected void setUp() throws Exception { | protected void setUp() throws Exception { | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject(PROJECT_DIR); | initialiseProject(PROJECT_DIR); | ||||
handler = null; | handler = null; | ||||
compilerConfig = null; | compilerConfig = null; | ||||
} | } | ||||
/** | /** | ||||
* Weave all the possible kinds of advice and verify the messages that come out. | * Weave all the possible kinds of advice and verify the messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesAdvice() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(one)); | ||||
doBuild(); | 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. | * Weave field and method ITDs and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesITD() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(two)); | ||||
doBuild(); | 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. | * Weave "declare parents: implements" and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesDeclare() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(three)); | ||||
doBuild(); | 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() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(four)); | ||||
doBuild(); | 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. | * Weave "declare soft: type: pointcut" and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesDeclareSoft() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(five)); | ||||
doBuild(); | 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. | * Weave 'declare @type, @constructor, @method and @field' and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesDeclareAnnotation() { | 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)); | compilerConfig.setProjectSourceFiles(getSourceFileList(six)); | ||||
setRunIn15Mode(); | setRunIn15Mode(); | ||||
compilerConfig.setNonStandardOptions("-showWeaveInfo -1.5"); | compilerConfig.setNonStandardOptions("-showWeaveInfo -1.5"); | ||||
doBuild(); | 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() { | 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.setProjectSourceFiles(getSourceFileList(seven)); | ||||
compilerConfig.setNonStandardOptions(""); | compilerConfig.setNonStandardOptions(""); | ||||
setRunIn15Mode(); | setRunIn15Mode(); | ||||
doBuild(); | 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 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() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectAdvice.jar")); | aspectpath.add(openFile("AspectAdvice.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectITD.jar")); | aspectpath.add(openFile("AspectITD.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectDeclare.jar")); | aspectpath.add(openFile("AspectDeclare.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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. | * Weave "declare soft: type: pointcut" and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesBinaryDeclareSoft() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectDeclareSoft.jar")); | aspectpath.add(openFile("AspectDeclareSoft.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectInPackage.jar")); | aspectpath.add(openFile("AspectInPackage.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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")); | inpath.add(openFile("Simple.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("pkg")); | aspectpath.add(openFile("pkg")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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 | // BINARY WEAVING WHEN WE'VE LOST THE SOURCE POINTERS | ||||
public void testWeaveMessagesBinaryAdviceNoDebugInfo() { | 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")); | inpath.add(openFile("Simple_nodebug.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectAdvice_nodebug.jar")); | aspectpath.add(openFile("AspectAdvice_nodebug.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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(); | Set inpath = new HashSet(); | ||||
inpath.add(openFile("Simple_nodebug.jar")); | inpath.add(openFile("Simple_nodebug.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
aspectpath.add(openFile("AspectITD_nodebug.jar")); | aspectpath.add(openFile("AspectITD_nodebug.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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() { | 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")); | inpath.add(openFile("Simple_nodebug.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectDeclare_nodebug.jar")); | aspectpath.add(openFile("AspectDeclare_nodebug.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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. | * Weave "declare soft: type: pointcut" and check the weave messages that come out. | ||||
*/ | */ | ||||
public void testWeaveMessagesBinaryDeclareSoftNoDebugInfo() { | 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")); | inpath.add(openFile("Simple_nodebug.jar")); | ||||
compilerConfig.setInpath(inpath); | compilerConfig.setInpath(inpath); | ||||
Set aspectpath = new HashSet(); | |||||
Set<File> aspectpath = new HashSet<File>(); | |||||
aspectpath.add(openFile("AspectDeclareSoft_nodebug.jar")); | aspectpath.add(openFile("AspectDeclareSoft_nodebug.jar")); | ||||
compilerConfig.setAspectPath(aspectpath); | compilerConfig.setAspectPath(aspectpath); | ||||
doBuild(); | 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) { | if (regenerate && source) { | ||||
// Create the file | // Create the file | ||||
saveWeaveMessages(expectedF); | saveWeaveMessages(expectedF); | ||||
compareWeaveMessages(expectedF); | compareWeaveMessages(expectedF); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Compare weaving messages with what is in the file | * Compare weaving messages with what is in the file | ||||
*/ | */ | ||||
// Load the file in | // Load the file in | ||||
fr = new BufferedReader(new FileReader(f)); | fr = new BufferedReader(new FileReader(f)); | ||||
String line = null; | String line = null; | ||||
while ((line=fr.readLine())!=null) fileContents.add(line); | |||||
while ((line = fr.readLine()) != null) | |||||
fileContents.add(line); | |||||
List originalFileContents = new ArrayList(); | List originalFileContents = new ArrayList(); | ||||
originalFileContents.addAll(fileContents); | originalFileContents.addAll(fileContents); | ||||
// See if the messages match | // See if the messages match | ||||
int msgCount = 0; | int msgCount = 0; | ||||
List l = handler.getMessages(); | List l = handler.getMessages(); | ||||
for (Iterator iter = l.iterator(); iter.hasNext();) { | for (Iterator iter = l.iterator(); iter.hasNext();) { | ||||
IMessage msg = ((TestMessageHandler.TestMessage) iter.next()).getContainedMessage(); | 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 (msg.getKind().equals(IMessage.WEAVEINFO)) { | ||||
if (!fileContents.contains(msg.getMessage())) { | 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 { | } else { | ||||
fileContents.remove(msg.getMessage()); | fileContents.remove(msg.getMessage()); | ||||
} | } | ||||
msgCount++; | 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) { | } catch (Exception e) { | ||||
fail("Unexpected exception saving weaving messages:"+e); | |||||
fail("Unexpected exception saving weaving messages:" + e); | |||||
} | } | ||||
} | } | ||||
private String stringify(List l) { | private String stringify(List l) { | ||||
StringBuffer result = new StringBuffer(); | StringBuffer result = new StringBuffer(); | ||||
for (Iterator iter = l.iterator(); iter.hasNext();) { | for (Iterator iter = l.iterator(); iter.hasNext();) { | ||||
String str = (String) iter.next(); | String str = (String) iter.next(); | ||||
result.append(str);result.append("\n"); | |||||
result.append(str); | |||||
result.append("\n"); | |||||
} | } | ||||
return result.toString(); | return result.toString(); | ||||
} | } | ||||
/** | /** | ||||
* Store the weaving messages in the specified file. | * Store the weaving messages in the specified file. | ||||
*/ | */ | ||||
private void saveWeaveMessages(File f) { | 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; | FileWriter fw; | ||||
try { | try { | ||||
fw = new FileWriter(f); | |||||
fw = new FileWriter(f); | |||||
List l = handler.getMessages(); | List l = handler.getMessages(); | ||||
for (Iterator iter = l.iterator(); iter.hasNext();) { | for (Iterator iter = l.iterator(); iter.hasNext();) { | ||||
IMessage msg = ((TestMessageHandler.TestMessage) iter.next()).getContainedMessage(); | IMessage msg = ((TestMessageHandler.TestMessage) iter.next()).getContainedMessage(); | ||||
if (msg.getKind().equals(IMessage.WEAVEINFO)) { | if (msg.getKind().equals(IMessage.WEAVEINFO)) { | ||||
fw.write(msg.getMessage()+"\n"); | |||||
fw.write(msg.getMessage() + "\n"); | |||||
} | } | ||||
} | } | ||||
fw.close(); | fw.close(); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
fail("Unexpected exception saving weaving messages:"+e); | |||||
fail("Unexpected exception saving weaving messages:" + e); | |||||
} | } | ||||
} | } | ||||
private void setRunIn15Mode() { | private void setRunIn15Mode() { | ||||
Map m = new Hashtable(); | 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); | compilerConfig.setJavaOptions(m); | ||||
} | } | ||||
} | } |
// // see pr148027 | // // see pr148027 | ||||
// public void testUsesPointcut() { | // public void testUsesPointcut() { | ||||
// if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return; | // if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return; | ||||
// | |||||
// | |||||
// IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage"); | // IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage"); | ||||
// assertNotNull(ptUsage); | // assertNotNull(ptUsage); | ||||
// IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts"); | // IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts"); | ||||
// assertNotNull(pts); | // assertNotNull(pts); | ||||
// | |||||
// | |||||
// IProgramElement pUsesA = manager.getHierarchy().findElementForLabel( | // IProgramElement pUsesA = manager.getHierarchy().findElementForLabel( | ||||
// ptUsage, | // ptUsage, | ||||
// IProgramElement.Kind.POINTCUT, | // IProgramElement.Kind.POINTCUT, | ||||
// IProgramElement.Kind.POINTCUT, | // IProgramElement.Kind.POINTCUT, | ||||
// "a()"/*Point"*/); | // "a()"/*Point"*/); | ||||
// assertNotNull(ptsA); | // assertNotNull(ptsA); | ||||
// | |||||
// | |||||
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0); | // assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0); | ||||
// assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0); | // assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0); | ||||
// } | // } | ||||
assertTrue(rels.size() > 0); | assertTrue(rels.size() > 0); | ||||
// assertTrue(rel.getTargets().size() > 0); | // assertTrue(rel.getTargets().size() > 0); | ||||
// | |||||
// | |||||
// checkDeclareMapping("DeclareCoverage", "Point", , | // checkDeclareMapping("DeclareCoverage", "Point", , | ||||
// "Point", "matched by", "matches declare", | // "Point", "matched by", "matches declare", | ||||
// IProgramElement.Kind.DECLARE_PARENTS); | // IProgramElement.Kind.DECLARE_PARENTS); | ||||
.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); | .findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); | ||||
assertNotNull(beforeExecNode); | assertNotNull(beforeExecNode); | ||||
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); | 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(); | String currHandle = (String) it.next(); | ||||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) | if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) | ||||
return; | return; | ||||
// String set = to; | // String set = to; | ||||
IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); | IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); | ||||
// String handle2 = (String)rel2.getTargets().get(0); | // 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(); | String currHandle = (String) it.next(); | ||||
if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) | if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) | ||||
return; | return; |