diff options
author | aclement <aclement> | 2005-11-26 16:36:23 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-11-26 16:36:23 +0000 |
commit | 3ce492be631f9f598bbf9d1e045e4d9637885bf1 (patch) | |
tree | 50ee0c552d617078497916ba9f5db8fd8682ed2d /loadtime | |
parent | 249d797a9eb4cbcd7bfdc658e128770eaeacc400 (diff) | |
download | aspectj-3ce492be631f9f598bbf9d1e045e4d9637885bf1.tar.gz aspectj-3ce492be631f9f598bbf9d1e045e4d9637885bf1.zip |
Matthews changes - enabling us to see bytecode before and after LTW (bug 117854)
Diffstat (limited to 'loadtime')
6 files changed, 35 insertions, 37 deletions
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/Aj.java b/loadtime/src/org/aspectj/weaver/loadtime/Aj.java index 079b5439a..c70545301 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/Aj.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/Aj.java @@ -11,8 +11,6 @@ *******************************************************************************/ package org.aspectj.weaver.loadtime; -import java.io.File; -import java.io.FileOutputStream; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.Map; @@ -63,11 +61,7 @@ public class Aj implements ClassPreProcessor { try { WeavingAdaptor weavingAdaptor = WeaverContainer.getWeaver(loader, weavingContext); - byte[] weaved = weavingAdaptor.weaveClass(className, bytes); - if (weavingAdaptor.shouldDump(className.replace('/', '.'))) { - dump(className, weaved); - } - return weaved; + return weavingAdaptor.weaveClass(className, bytes); } catch (Throwable t) { //FIXME AV wondering if we should have the option to fail (throw runtime exception) here // would make sense at least in test f.e. see TestHelper.handleMessage() @@ -165,32 +159,6 @@ public class Aj implements ClassPreProcessor { } /** - * Dump the given bytcode in _dump/... (dev mode) - * - * @param name - * @param b - * @throws Throwable - */ - static void dump(String name, byte[] b) throws Throwable { - String className = name.replace('.', '/'); - final File dir; - if (className.indexOf('/') > 0) { - dir = new File("_ajdump" + File.separator + className.substring(0, className.lastIndexOf('/'))); - } else { - dir = new File("_ajdump"); - } - dir.mkdirs(); - String fileName = "_ajdump" + File.separator + className + ".class"; - FileOutputStream os = new FileOutputStream(fileName); - os.write(b); - os.close(); - } - - /* - * Shared classes methods - */ - - /** * Returns a namespace based on the contest of the aspects available */ public String getNamespace (ClassLoader loader) { diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java index 09d11f162..b17392d05 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java @@ -54,6 +54,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { private final static String AOP_XML = "META-INF/aop.xml"; private List m_dumpTypePattern = new ArrayList(); + private boolean m_dumpBefore = false; private List m_includeTypePattern = new ArrayList(); private List m_excludeTypePattern = new ArrayList(); private List m_includeStartsWith = new ArrayList(); @@ -81,8 +82,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { */ public void acceptClass(String name, byte[] bytes) { try { - if (shouldDump(name.replace('/', '.'))) { - Aj.dump(name, bytes); + if (shouldDump(name.replace('/', '.'), false)) { + dump(name, bytes, false); } } catch (Throwable throwable) { throwable.printStackTrace(); @@ -438,6 +439,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { TypePattern pattern = new PatternParser(dump).parseTypePattern(); m_dumpTypePattern.add(pattern); } + if (definition.shouldDumpBefore()) { + m_dumpBefore = true; + } } } @@ -543,11 +547,17 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { return accept; } - public boolean shouldDump(String className) { + protected boolean shouldDump(String className, boolean before) { + // Don't dump before weaving unless asked to + if (before && !m_dumpBefore) { + return false; + } + // avoid ResolvedType if not needed if (m_dumpTypePattern.isEmpty()) { return false; } + //TODO AV - optimize for className.startWith only ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(className), true); //dump diff --git a/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java b/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java index efb7d3259..2730428d2 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java @@ -24,6 +24,7 @@ public class Definition { private StringBuffer m_weaverOptions; private List m_dumpPatterns; + private boolean m_dumpBefore; private List m_includePatterns; @@ -39,6 +40,7 @@ public class Definition { public Definition() { m_weaverOptions = new StringBuffer(); + m_dumpBefore = false; m_dumpPatterns = new ArrayList(0); m_includePatterns = new ArrayList(0); m_excludePatterns = new ArrayList(0); @@ -56,6 +58,14 @@ public class Definition { return m_dumpPatterns; } + public void setDumpBefore(boolean b) { + m_dumpBefore = b; + } + + public boolean shouldDumpBefore() { + return m_dumpBefore; + } + public List getIncludePatterns() { return m_includePatterns; } diff --git a/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java b/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java index 931e26d17..2800ebece 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java @@ -51,6 +51,7 @@ public class DocumentParser extends DefaultHandler { private final static String ASPECTJ_ELEMENT = "aspectj"; private final static String WEAVER_ELEMENT = "weaver"; private final static String DUMP_ELEMENT = "dump"; + private final static String DUMP_BEFOREANDAFTER_ATTRIBUTE = "beforeandafter"; private final static String INCLUDE_ELEMENT = "include"; private final static String EXCLUDE_ELEMENT = "exclude"; private final static String OPTIONS_ATTRIBUTE = "options"; @@ -206,6 +207,10 @@ public class DocumentParser extends DefaultHandler { if (!isNull(typePattern)) { m_definition.getDumpPatterns().add(typePattern); } + String beforeAndAfter = attributes.getValue(DUMP_BEFOREANDAFTER_ATTRIBUTE); + if (isTrue(beforeAndAfter)) { + m_definition.setDumpBefore(true); + } } else if (EXCLUDE_ELEMENT.equals(qName) && m_inAspects) { String typePattern = attributes.getValue(WITHIN_ATTRIBUTE); if (!isNull(typePattern)) { @@ -258,5 +263,9 @@ public class DocumentParser extends DefaultHandler { return (s == null || s.length() <= 0); } + private boolean isTrue(String s) { + return (s != null && s.equals("true")); + } + } diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java index fddbc2794..92d35983f 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java @@ -39,6 +39,7 @@ public class DocumentParserTest extends TestCase { assertEquals("@Baz", def.getAspectExcludePatterns().get(0)); assertEquals("@Whoo", def.getAspectIncludePatterns().get(0)); assertEquals("foo..*", def.getDumpPatterns().get(0)); + assertEquals(true,def.shouldDumpBefore()); } } diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml index f565e6ef1..252bc0136 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml @@ -3,7 +3,7 @@ <aspectj> <weaver options="-showWeaveInfo"> <include within="foo..bar.Goo+"/> - <dump within="foo..*"/> + <dump within="foo..*" beforeandafter="true"/> </weaver> <aspects> <exclude within="@Baz"/> |