From 7d6b500be325633c3057abaf973b8c56464d6706 Mon Sep 17 00:00:00 2001 From: acolyer Date: Thu, 18 Mar 2004 14:36:58 +0000 Subject: [PATCH] fix for Bugzilla Bug 55134 Incremental compilation does not delete weaver-generated class files --- tests/ajcTests.xml | 14 ++++++++++ .../AdviceOnIntroduced.delete.20.java | 26 +++++++++++++++++++ .../AdviceOnIntroduced.java | 26 +++++++++++++++++++ .../classWAroundClosureRemoved/Main.java | 9 +++++++ .../aspectj/weaver/bcel/UnwovenClassFile.java | 26 +++++++++++++++---- 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.delete.20.java create mode 100644 tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.java create mode 100644 tests/incremental/initialTests/classWAroundClosureRemoved/Main.java diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index 496db30ab..f0da796c3 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -7489,4 +7489,18 @@ + + + + + + + + + + diff --git a/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.delete.20.java b/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.delete.20.java new file mode 100644 index 000000000..4da93f0ca --- /dev/null +++ b/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.delete.20.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.Tester; + +public aspect AdviceOnIntroduced { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new Foo(10).foo(5), 6, "foo"); + } + + int Foo.foo(int n) { return n; } + Foo.new(int w) {} + + int around(int n): + within(AdviceOnIntroduced) && + (args(n) && execution(int foo(int))) { + int result = proceed(n); + return result+1; + } + + before(): within(Foo) && execution(new(..)) { + //System.out.println("before new"); + } +} + +class Foo { +} diff --git a/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.java b/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.java new file mode 100644 index 000000000..4da93f0ca --- /dev/null +++ b/tests/incremental/initialTests/classWAroundClosureRemoved/AdviceOnIntroduced.java @@ -0,0 +1,26 @@ +import org.aspectj.testing.Tester; + +public aspect AdviceOnIntroduced { + public static void main(String[] args) { test(); } + + public static void test() { + Tester.checkEqual(new Foo(10).foo(5), 6, "foo"); + } + + int Foo.foo(int n) { return n; } + Foo.new(int w) {} + + int around(int n): + within(AdviceOnIntroduced) && + (args(n) && execution(int foo(int))) { + int result = proceed(n); + return result+1; + } + + before(): within(Foo) && execution(new(..)) { + //System.out.println("before new"); + } +} + +class Foo { +} diff --git a/tests/incremental/initialTests/classWAroundClosureRemoved/Main.java b/tests/incremental/initialTests/classWAroundClosureRemoved/Main.java new file mode 100644 index 000000000..7c85f90c2 --- /dev/null +++ b/tests/incremental/initialTests/classWAroundClosureRemoved/Main.java @@ -0,0 +1,9 @@ +import org.aspectj.testing.Tester; + +public class Main { + + public static void main(String[] args) { + Tester.checkFailed("Incremental compilation did not appear to (re)weave Main"); + } + +} \ No newline at end of file diff --git a/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java b/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java index ab4463407..e67f17529 100644 --- a/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java +++ b/weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java @@ -15,6 +15,7 @@ package org.aspectj.weaver.bcel; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -150,14 +151,29 @@ public class UnwovenClassFile { public String toString() { return "UnwovenClassFile(" + filename + ", " + getClassName() + ")"; } - + + /** + * delete not just this file, but any files in the same directory that + * were generated as a result of weaving it (e.g. for an around closure). + */ public void deleteRealFile() throws IOException { - new File(filename).delete(); + File victim = new File(filename); + String namePrefix = victim.getName(); + namePrefix = namePrefix.substring(0,namePrefix.lastIndexOf('.')); + final String targetPrefix = namePrefix + "$Ajc"; + File dir = victim.getParentFile(); + if (dir != null) { + File[] weaverGenerated = dir.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.startsWith(targetPrefix); + }}); + for (int i = 0; i < weaverGenerated.length; i++) { + weaverGenerated[i].delete(); + } + } + victim.delete(); } - - - // record public static class ChildClass { public final String name; -- 2.39.5