From 68f63508828d1c1ea7076d051cc77713625f6a03 Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 23 Mar 2005 16:47:55 +0000 Subject: [PATCH] fix for Bug 84122 - Allow aspectPath to contain directories --- docs/adk15ProgGuideDB/miscellaneous.xml | 12 ++++ .../org/aspectj/ajdt/ajc/BuildArgParser.java | 2 +- .../org/aspectj/ajdt/ajc/messages.properties | 2 +- .../ajdt/internal/core/builder/AjState.java | 28 +++++++-- tests/options/aspectpath/MyAspect.aj | 5 ++ tests/options/aspectpath/MyClass.java | 5 ++ .../systemtest/ajc150/Ajc150Tests.java | 4 ++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 12 +++- .../org/aspectj/weaver/bcel/BcelWeaver.java | 57 +++++++++++++------ 9 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 tests/options/aspectpath/MyAspect.aj create mode 100644 tests/options/aspectpath/MyClass.java diff --git a/docs/adk15ProgGuideDB/miscellaneous.xml b/docs/adk15ProgGuideDB/miscellaneous.xml index 063c8b816..899ac1208 100644 --- a/docs/adk15ProgGuideDB/miscellaneous.xml +++ b/docs/adk15ProgGuideDB/miscellaneous.xml @@ -91,5 +91,17 @@ + + + Tools + + + Aspectpath + + AspectJ 5 allows the specification of directories (containing .class files) on the aspectpath in + addition to jar/zip files. + + + diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index 0c2806acc..0f8909585 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -441,7 +441,7 @@ public class BuildArgParser extends Main { while (st.hasMoreTokens()) { String filename = st.nextToken(); File jarFile = makeFile(filename); - if (jarFile.exists() && FileUtil.hasZipSuffix(filename)) { + if (jarFile.exists() && (FileUtil.hasZipSuffix(filename) || jarFile.isDirectory())) { buildConfig.getAspectpath().add(jarFile); } else { showError("bad aspectpath: " + filename); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties index 061417143..2777b867a 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties @@ -22,7 +22,7 @@ AspectJ-specific options:\n\ \t-injars use classes in zip files as source\n\ \t ( uses classpath delimiter)\n\ \t deprecated - use inpath instead.\n\ -\t-aspectpath weave aspects from zip files into sources\n\ +\t-aspectpath weave aspects in .class files from dirs and jars/zip into sources\n\ \t ( uses classpath delimiter)\n\ \t-outjar put output classes in zip file \n\ \t-argfile specify line-delimited list of source files\n\ diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java index d6bb9ffda..e5668bc32 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java @@ -170,24 +170,39 @@ public class AjState { return ret; } + private boolean classFileChangedInDirSinceLastBuild(File dir) { + File[] classFiles = FileUtil.listFiles(dir, new FileFilter(){ + + public boolean accept(File pathname) { + return pathname.getName().endsWith(".class"); + } + + }); + for (int i = 0; i < classFiles.length; i++) { + long modTime = classFiles[i].lastModified(); + if (modTime + 1000 >= lastSuccessfulBuildTime) return true; + } + return false; + } + private boolean pathChange(AjBuildConfig oldConfig, AjBuildConfig newConfig) { boolean changed = false; List oldClasspath = oldConfig.getClasspath(); List newClasspath = newConfig.getClasspath(); - if (changed(oldClasspath,newClasspath)) return true; + if (changed(oldClasspath,newClasspath,true)) return true; List oldAspectpath = oldConfig.getAspectpath(); List newAspectpath = newConfig.getAspectpath(); - if (changed(oldAspectpath,newAspectpath)) return true; + if (changed(oldAspectpath,newAspectpath,true)) return true; List oldInJars = oldConfig.getInJars(); List newInJars = newConfig.getInJars(); - if (changed(oldInJars,newInJars)) return true; + if (changed(oldInJars,newInJars,false)) return true; List oldInPath = oldConfig.getInpath(); List newInPath = newConfig.getInpath(); - if (changed(oldInPath, newInPath)) return true; + if (changed(oldInPath, newInPath,false)) return true; return changed; } - private boolean changed(List oldPath, List newPath) { + private boolean changed(List oldPath, List newPath, boolean checkClassFiles) { if (oldPath == null) oldPath = new ArrayList(); if (newPath == null) newPath = new ArrayList(); if (oldPath.size() != newPath.size()) { @@ -207,6 +222,9 @@ public class AjState { if (f.exists() && !f.isDirectory() && (f.lastModified() >= lastSuccessfulBuildTime)) { return true; } + if (f.exists() && f.isDirectory() && checkClassFiles) { + return classFileChangedInDirSinceLastBuild(f); + } } return false; } diff --git a/tests/options/aspectpath/MyAspect.aj b/tests/options/aspectpath/MyAspect.aj new file mode 100644 index 000000000..4b2c632d7 --- /dev/null +++ b/tests/options/aspectpath/MyAspect.aj @@ -0,0 +1,5 @@ +public aspect MyAspect { + + declare warning : execution(* *(..)) : "a method"; + +} \ No newline at end of file diff --git a/tests/options/aspectpath/MyClass.java b/tests/options/aspectpath/MyClass.java new file mode 100644 index 000000000..ef0d28767 --- /dev/null +++ b/tests/options/aspectpath/MyClass.java @@ -0,0 +1,5 @@ +public class MyClass { + + void foo() {} + +} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index bdcc31a41..0d3b6b076 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -145,6 +145,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("varargs in constructor sig"); } + public void testAspectpathdirs() { + runTest("dirs on aspectpath"); + } + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 4ee4988f4..e92516e85 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -312,7 +312,7 @@ - + @@ -2019,4 +2019,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 1caa54574..3f1134b6f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -142,10 +142,22 @@ public class BcelWeaver implements IWeaver { public void addLibraryJarFile(File inFile) throws IOException { - ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered + List addedAspects = null; + if (inFile.isDirectory()) { + addedAspects = addAspectsFromDirectory(inFile); + } else { + addedAspects = addAspectsFromJarFile(inFile); + } + for (Iterator i = addedAspects.iterator(); i.hasNext();) { + ResolvedTypeX aspectX = (ResolvedTypeX) i.next(); + xcutSet.addOrReplaceAspect(aspectX); + } + } + + private List addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException { + ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered List addedAspects = new ArrayList(); - while (true) { ZipEntry entry = inStream.getNextEntry(); if (entry == null) break; @@ -154,25 +166,38 @@ public class BcelWeaver implements IWeaver { continue; } - ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName()); - JavaClass jc = parser.parse(); - inStream.closeEntry(); - - ResolvedTypeX type = world.addSourceObjectType(jc).getResolvedTypeX(); - if (type.isAspect()) { - addedAspects.add(type); - } - + addIfAspect(FileUtil.readAsByteArray(inStream), entry.getName(), addedAspects); + inStream.closeEntry(); } - inStream.close(); + return addedAspects; + } + + private List addAspectsFromDirectory(File dir) throws FileNotFoundException, IOException{ + List addedAspects = new ArrayList(); + File[] classFiles = FileUtil.listFiles(dir,new FileFilter(){ - for (Iterator i = addedAspects.iterator(); i.hasNext();) { - ResolvedTypeX aspectX = (ResolvedTypeX) i.next(); - xcutSet.addOrReplaceAspect(aspectX); + public boolean accept(File pathname) { + return pathname.getName().endsWith(".class"); + } + + }); + for (int i = 0; i < classFiles.length; i++) { + FileInputStream fis = new FileInputStream(classFiles[i]); + byte[] bytes = FileUtil.readAsByteArray(fis); + addIfAspect(bytes,classFiles[i].getAbsolutePath(),addedAspects); } + return addedAspects; + } + + private void addIfAspect(byte[] bytes, String name, List toList) throws IOException { + ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes),name); + JavaClass jc = parser.parse(); + ResolvedTypeX type = world.addSourceObjectType(jc).getResolvedTypeX(); + if (type.isAspect()) { + toList.add(type); + } } - // // The ANT copy task should be used to copy resources across. // private final static boolean CopyResourcesFromInpathDirectoriesToOutput=false; -- 2.39.5