diff options
author | acolyer <acolyer> | 2003-11-11 13:09:14 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2003-11-11 13:09:14 +0000 |
commit | 1c6db5d4f24f6ddaee4c48661503a8b7ea516744 (patch) | |
tree | 776e942fa9f0bd7ed54a717e7227f8e9a3716480 /ajde | |
parent | 8c70c5a515a383e0691eeb3a9bc1caa66a0398b5 (diff) | |
download | aspectj-1c6db5d4f24f6ddaee4c48661503a8b7ea516744.tar.gz aspectj-1c6db5d4f24f6ddaee4c48661503a8b7ea516744.zip |
Andy Clement's patch for enh 46347: "-inpath"
Diffstat (limited to 'ajde')
18 files changed, 535 insertions, 2 deletions
diff --git a/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java b/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java index 2934932ee..6ba8134bb 100644 --- a/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java +++ b/ajde/src/org/aspectj/ajde/ProjectPropertiesAdapter.java @@ -69,6 +69,14 @@ public interface ProjectPropertiesAdapter { public Set getInJars(); /** + * Get the set of input path elements for this compilation. + * Set members should be of the type java.io.File. + * An empty set or null is acceptable for this option. + * From -injars + */ + public Set getInpath(); + + /** * Get the set of non-Java resources for this compilation. * Set members should be of type java.io.File. * An empty set or null is acceptable for this option. diff --git a/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java b/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java index 84e0bb8ec..8006af593 100644 --- a/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java +++ b/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java @@ -188,6 +188,7 @@ public class AspectJBuildManager implements BuildManager { + "\n-> classpath: " + properties.getClasspath() + "\n-> bootclasspath: " + properties.getBootClasspath() + "\n-> -injars " + formatSet(properties.getInJars()) + + "\n-> -inpath " + formatSet(properties.getInpath()) + "\n-> -outjar " + formatOptionalString(properties.getOutJar()) + "\n-> -sourceroots " + formatSet(properties.getSourceRoots()) + "\n-> -aspectpath " + formatSet(properties.getAspectPath()) diff --git a/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java b/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java index 9ee5f111e..d7db8e849 100644 --- a/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java +++ b/ajde/src/org/aspectj/ajde/internal/CompilerAdapter.java @@ -451,8 +451,8 @@ public class CompilerAdapter { /** * Add new options from the ProjectPropertiesAdapter to the configuration. * <ul> - * <li>New list entries are added if not duplicates, - * for classpath, aspectpath, injars, and sourceroots</li> + * <li>New list entries are added if not duplicates in, + * for classpath, aspectpath, injars, inpath and sourceroots</li> * <li>New bootclasspath entries are ignored XXX</li> * <li>Set only one new entry for output dir or output jar * only if there is no output dir/jar entry in the config</li> @@ -497,6 +497,7 @@ public class CompilerAdapter { join(config.getSourceRoots(), properties.getSourceRoots()); join(config.getInJars(), properties.getInJars()); + join(config.getInpath(),properties.getInpath()); config.setSourcePathResources(properties.getSourcePathResources()); join(config.getAspectpath(), properties.getAspectPath()); } diff --git a/ajde/testdata/InpathTest/.cvsignore b/ajde/testdata/InpathTest/.cvsignore new file mode 100644 index 000000000..39b6b088c --- /dev/null +++ b/ajde/testdata/InpathTest/.cvsignore @@ -0,0 +1,3 @@ +bin +build.ajsym +build2.ajsym diff --git a/ajde/testdata/InpathTest/build.lst b/ajde/testdata/InpathTest/build.lst new file mode 100644 index 000000000..ec1f031f5 --- /dev/null +++ b/ajde/testdata/InpathTest/build.lst @@ -0,0 +1 @@ +src1/Main.java
diff --git a/ajde/testdata/InpathTest/build2.lst b/ajde/testdata/InpathTest/build2.lst new file mode 100644 index 000000000..263b509b2 --- /dev/null +++ b/ajde/testdata/InpathTest/build2.lst @@ -0,0 +1 @@ +src2/Aspect.java
diff --git a/ajde/testdata/InpathTest/indir1/META-INF/MANIFEST.MF b/ajde/testdata/InpathTest/indir1/META-INF/MANIFEST.MF new file mode 100644 index 000000000..fb5efeb68 --- /dev/null +++ b/ajde/testdata/InpathTest/indir1/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0
+Created-By: 1.3.1_04 (Sun Microsystems Inc.)
+
diff --git a/ajde/testdata/InpathTest/indir1/META-INF/test.xml b/ajde/testdata/InpathTest/indir1/META-INF/test.xml new file mode 100644 index 000000000..f9efa1f1f --- /dev/null +++ b/ajde/testdata/InpathTest/indir1/META-INF/test.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" ?> +<jar name="input1.jar"> +</jar> + diff --git a/ajde/testdata/InpathTest/indir1/test/TestProperties.class b/ajde/testdata/InpathTest/indir1/test/TestProperties.class Binary files differnew file mode 100644 index 000000000..a58740c20 --- /dev/null +++ b/ajde/testdata/InpathTest/indir1/test/TestProperties.class diff --git a/ajde/testdata/InpathTest/indir1/test/test.props b/ajde/testdata/InpathTest/indir1/test/test.props new file mode 100644 index 000000000..8462a7ab6 --- /dev/null +++ b/ajde/testdata/InpathTest/indir1/test/test.props @@ -0,0 +1 @@ +test=test2
\ No newline at end of file diff --git a/ajde/testdata/InpathTest/indir2/example/HelloWorld.class b/ajde/testdata/InpathTest/indir2/example/HelloWorld.class Binary files differnew file mode 100644 index 000000000..e333988e6 --- /dev/null +++ b/ajde/testdata/InpathTest/indir2/example/HelloWorld.class diff --git a/ajde/testdata/InpathTest/indir2/example/HelloWorld.java b/ajde/testdata/InpathTest/indir2/example/HelloWorld.java new file mode 100644 index 000000000..476abc7ee --- /dev/null +++ b/ajde/testdata/InpathTest/indir2/example/HelloWorld.java @@ -0,0 +1,12 @@ +package example; + +public class HelloWorld { + + public static void say(String msg) { + System.err.println(msg); + } + + public static void main(String []argv) { + say("hello world"); + } +} diff --git a/ajde/testdata/InpathTest/injar.jar b/ajde/testdata/InpathTest/injar.jar Binary files differnew file mode 100644 index 000000000..7dcd06f97 --- /dev/null +++ b/ajde/testdata/InpathTest/injar.jar diff --git a/ajde/testdata/InpathTest/src1/Main.java b/ajde/testdata/InpathTest/src1/Main.java new file mode 100644 index 000000000..417fc6809 --- /dev/null +++ b/ajde/testdata/InpathTest/src1/Main.java @@ -0,0 +1,22 @@ +import java.io.IOException; + +/* + * Created on 30-Jul-03 + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ + +/** + * @author websterm + * + * To change this generated comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class Main { + + public static void main(String[] args) throws IOException { + String propsName = (args.length > 0)? args[0] : "test.props"; + new test.TestProperties().load(propsName); + } +} diff --git a/ajde/testdata/InpathTest/src2/Aspect.java b/ajde/testdata/InpathTest/src2/Aspect.java new file mode 100644 index 000000000..c70994870 --- /dev/null +++ b/ajde/testdata/InpathTest/src2/Aspect.java @@ -0,0 +1,7 @@ +public aspect Aspect { + pointcut sayCalls(): call(* say(..)); + + before(): sayCalls() { + System.err.println("Before say()"); + } +} diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java index cf9c57ca5..a6c7b740d 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTests.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTests.java @@ -30,6 +30,7 @@ public class AjdeTests extends TestCase { suite.addTestSuite(CompilerMessagesTest.class); suite.addTestSuite(AsmDeclarationsTest.class); suite.addTestSuite(AsmRelationshipsTest.class); + suite.addTestSuite(InpathTestcase.class); suite.addTestSuite(ResourceCopyTestCase.class); suite.addTestSuite(ModelPerformanceTest.class); diff --git a/ajde/testsrc/org/aspectj/ajde/InpathTestcase.java b/ajde/testsrc/org/aspectj/ajde/InpathTestcase.java new file mode 100644 index 000000000..b05c56707 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/InpathTestcase.java @@ -0,0 +1,461 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Mik Kersten initial implementation + * Andy Clement Copied/changed for -inpath testing + * ******************************************************************/ + +package org.aspectj.ajde; + +import java.io.*; +import java.util.*; +import java.util.zip.*; + +import org.aspectj.util.FileUtil; + +/** + * @author websterm + */ +public class InpathTestcase extends AjdeTestCase { + + public static final String PROJECT_DIR = "InpathTest"; + public static final String binDir = "bin"; + + public static final String indir1Name = "indir1"; + public static final String indir2Name = "indir2"; + public static final String injarName = "injar.jar"; + public static final String outjarName = "/bin/output.jar"; + + /** + * Constructor for JarResourceCopyTestCase. + * @param arg0 + */ + public InpathTestcase(String arg0) { + super(arg0); + } + + + + /* + * Ensure the output directpry in clean + */ + protected void setUp() throws Exception { + super.setUp(PROJECT_DIR); + FileUtil.deleteContents(openFile(binDir)); + } + + + + /** + * 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 + */ + public void testInpathToOutjar() { + Set inpath = new HashSet(); + File indir1 = openFile(indir1Name); + inpath.add(indir1); + ideManager.getProjectProperties().setInpath(inpath); + File outjar = openFile(outjarName); + ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath()); + assertTrue("Build failed", doSynchronousBuild("build.lst")); + assertTrue("Build warnings", ideManager.getCompilationSourceLineTasks().isEmpty()); + + Set expectedOutputJarContents = new HashSet(); + // From indir1 + 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"); + + compareJars(indir1, "src", outjar, expectedOutputJarContents); + + // Tidy up + FileUtil.deleteContents(openFile(binDir)); + openFile(binDir).delete(); + assertFalse(openFile(binDir).exists()); + } + + + + /** + * Similar to the first test but outputs to a directory rather than + * a jar. + * + */ + public void testInpathToBin() { + Set inpath = new HashSet(); + File indir1 = openFile(indir1Name); + inpath.add(indir1); + ideManager.getProjectProperties().setInpath(inpath); + assertTrue("Build failed", doSynchronousBuild("build.lst")); + assertTrue( + "Build warnings", + ideManager.getCompilationSourceLineTasks().isEmpty()); + + Set expectedBindirContents = new HashSet(); + // From indir1 + 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"); + + compareIndirToBin(indir1, "src", "bin", expectedBindirContents); + + // Tidy up + FileUtil.deleteContents(openFile(binDir)); + openFile(binDir).delete(); + assertFalse(openFile(binDir).exists()); + } + + + + /** + * 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. + * + * 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(); + File indir2 = openFile(indir2Name); + inpath.add(indir2); + ideManager.getProjectProperties().setInpath(inpath); + File outjar = openFile(outjarName); + ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath()); + assertTrue("Build failed", doSynchronousBuild("build2.lst")); + assertTrue( + "Build warnings", + ideManager.getCompilationSourceLineTasks().isEmpty()); + + Set expectedOutputJarContents = new HashSet(); + // From indir1 + expectedOutputJarContents.add("example/HelloWorld.class"); + 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 + // 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"); + try { + 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)); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + FileUtil.deleteContents(openFile(binDir)); + openFile(binDir).delete(); + assertFalse(openFile(binDir).exists()); + } + + + + /** + * More complex inpath - a jar and a directory + * + * 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. + * + */ + public void testInpathAndInjarToBin() { + Set inpath = new HashSet(); + File indir2 = openFile(indir2Name); + inpath.add(indir2); + inpath.add(openFile(injarName)); + ideManager.getProjectProperties().setInpath(inpath); + assertTrue("Build failed", doSynchronousBuild("build2.lst")); + assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty()); + + Set expectedBindirContents = new HashSet(); + + // From indir1 + expectedBindirContents.add("example/HelloWorld.class"); + 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")); + byte[] filedata1 = FileUtil.readAsByteArray(fis1); + int inputsize = filedata1.length; + FileInputStream fis2 = new FileInputStream(openFile("bin/example/HelloWorld.class")); + 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)); + + fis1.close(); + fis2.close(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + FileUtil.deleteContents(openFile(binDir)); + openFile(binDir).delete(); + assertFalse(openFile(binDir).exists()); + } + + + + // Return the size of specified entry from the output jar file + public int fetchFromJar(File outjarFile, String filename) { + int ret = -1; + try { + ZipInputStream outjar; + + outjar = + new ZipInputStream(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; + } + outjar.closeEntry(); + } + outjar.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ret; + } + /* + * Ensure -outjar contains all non-Java resouces from injars + */ + public void compareJars( + File dirFile, + String sourceDir, + File outjarFile, + Set expectedOutputJarContents) { + + try { + assertTrue( + "outjar older than injar", + (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! + ZipInputStream outjar = + new ZipInputStream(new java.io.FileInputStream(outjarFile)); + ZipEntry entry; + while (null != (entry = outjar.getNextEntry())) { + String fileName = entry.getName(); + fileName = fileName.replace('\\', '/'); + boolean b = expectedOutputJarContents.remove(fileName); + assertTrue( + "Unexpectedly found : " + fileName + " in outjar", + b); + outjar.closeEntry(); + } + outjar.close(); + + assertTrue( + "Didnt make it into the output jar: " + + expectedOutputJarContents.toString(), + expectedOutputJarContents.isEmpty()); + } catch (IOException ex) { + fail(ex.toString()); + } + } + + /* + * Ensure -outjar contains all non-Java resouces from source and injars + */ + public void compareSourceToOutjar(String indirName, File outjarFile) { + HashSet resources = new HashSet(); + listSourceResources(indirName, resources); + + try { + + ZipInputStream outjar = + new ZipInputStream(new java.io.FileInputStream(outjarFile)); + ZipEntry entry; + while (null != (entry = outjar.getNextEntry())) { + String fileName = entry.getName(); + + if (!fileName.endsWith(".class")) { + boolean b = resources.remove(fileName); + assertTrue(fileName, b); + } + outjar.closeEntry(); + } + outjar.close(); + + assertTrue( + "Missing resources: " + resources.toString(), + resources.isEmpty()); + } catch (IOException ex) { + fail(ex.toString()); + } + } + + /* + * Ensure bin contains all non-Java resouces from source and injars + */ + public void compareIndirToBin( + File indirFile, + String sourceDir, + String outdirName, + Set expectedOutdirContents) { + + byte[] inManifest = null; + + File binBase = openFile(outdirName); + String[] toResources = FileUtil.listFiles(binBase); + for (int i = 0; i < toResources.length; i++) { + String fileName = toResources[i]; + boolean b = expectedOutdirContents.remove(fileName); + assertTrue("Extraneous resources: " + fileName, b); + } + + assertTrue( + "Missing resources: " + expectedOutdirContents.toString(), + expectedOutdirContents.isEmpty()); + } + + /** + * @param resources + */ + private void dumpResources(HashSet resources) { + System.err.println("Dump: " + resources.size() + " resources"); + for (Iterator iter = resources.iterator(); iter.hasNext();) { + Object element = (Object) iter.next(); + System.err.println(" Resource: " + element); + } + } + + private void listSourceResources(String indirName, Set resources) { + File srcBase = openFile(indirName); + 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")) { + resources.add(name); + } + } + } + + private byte[] listDirResources(File directory, Set resources) { + return listDirResources( + directory.getAbsolutePath(), + directory, + resources); + } + + private byte[] listDirResources( + String prefix, + File directory, + Set resources) { + byte[] manifest = null; + + File[] resourceFiles = directory.listFiles(new FileFilter() { + public boolean accept(File arg0) { + boolean accept = + !arg0.getName().endsWith(".class") && !arg0.isDirectory(); + return accept; + } + }); + for (int i = 0; i < resourceFiles.length; i++) { + File f = resourceFiles[i]; + String name = f.getAbsolutePath(); + if (f.getAbsolutePath().startsWith(prefix)) + name = name.substring(prefix.length()); + name = name.replace('\\', '/'); + + resources.add(resourceFiles[i]); + } + File[] subdirs = directory.listFiles(new FileFilter() { + public boolean accept(File arg0) { + return arg0.isDirectory(); + } + }); + for (int i = 0; i < subdirs.length; i++) { + listDirResources(prefix, subdirs[i], resources); + } + + return manifest; + } + + 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")); + + } + }; + + /* + * Ensure bin contains all non-Java resouces from source and injars + */ + public void compareDirs(String indirName, String outdirName) { + File binBase = openFile(outdirName); + File[] toResources = + FileUtil.listFiles(binBase, aspectjResourceFileFilter); + + HashSet resources = new HashSet(); + listSourceResources(indirName, resources); + + for (int i = 0; i < toResources.length; i++) { + String fileName = FileUtil.normalizedPath(toResources[i], binBase); + boolean b = resources.remove(fileName); + assertTrue("Extraneous resources: " + fileName, b); + } + + assertTrue( + "Missing resources: " + resources.toString(), + resources.isEmpty()); + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java b/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java index 90203e61f..0ea8c7cca 100644 --- a/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java +++ b/ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java @@ -28,6 +28,7 @@ public class NullIdeProperties implements ProjectPropertiesAdapter { private List buildConfigFiles = new ArrayList(); private Set inJars; + private Set inpath; private Set sourceRoots; private Set aspectPath; private String outJar; @@ -101,10 +102,16 @@ public class NullIdeProperties implements ProjectPropertiesAdapter { public void setInJars( Set jars ) { this.inJars = jars; } + public void setInpath( Set path) { this.inpath = path; } + public Set getInJars( ) { return inJars; } + public Set getInpath( ) { + return inpath; + } + public Map getSourcePathResources() { File srcBase = new File(getProjectSourcePath()); File[] fromResources = FileUtil.listFiles(srcBase, new FileFilter() { |