Browse Source

Bug 132080 "LTW concrete-aspect definitions not exposed to weaver"

tags/BEFORE_133532
mwebster 17 years ago
parent
commit
6b31b32ae3

+ 35
- 6
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java View File

import org.aspectj.weaver.World; import org.aspectj.weaver.World;
import org.aspectj.weaver.Lint.Kind; import org.aspectj.weaver.Lint.Kind;
import org.aspectj.weaver.bcel.BcelWeaver; import org.aspectj.weaver.bcel.BcelWeaver;
import org.aspectj.weaver.bcel.BcelWorld;
import org.aspectj.weaver.bcel.Utility;
import org.aspectj.weaver.loadtime.definition.Definition; import org.aspectj.weaver.loadtime.definition.Definition;
import org.aspectj.weaver.loadtime.definition.DocumentParser; import org.aspectj.weaver.loadtime.definition.DocumentParser;
import org.aspectj.weaver.ltw.LTWWorld; import org.aspectj.weaver.ltw.LTWWorld;
private StringBuffer namespace; private StringBuffer namespace;
private IWeavingContext weavingContext; private IWeavingContext weavingContext;


private List concreteAspects = new ArrayList();

private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassLoaderWeavingAdaptor.class); private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassLoaderWeavingAdaptor.class);
public ClassLoaderWeavingAdaptor() { public ClassLoaderWeavingAdaptor() {
// after adding aspects // after adding aspects
weaver.prepareForWeave(); weaver.prepareForWeave();
boolean success = weaveAndDefineConceteAspects();
if (!success) disable();
} }
else { else {
bcelWorld = null; bcelWorld = null;
success = false; success = false;
break; break;
} }
this.generatedClassHandler.acceptClass(
concreteAspect.name,
gen.getBytes()
);
/*ResolvedType aspect = */weaver.addLibraryAspect(concreteAspect.name);
((BcelWorld)weaver.getWorld()).addSourceObjectType(Utility.makeJavaClass(concreteAspect.name, gen.getBytes()));

concreteAspects.add(gen);
weaver.addLibraryAspect(concreteAspect.name);


//generate key for SC //generate key for SC
if(namespace==null){ if(namespace==null){
} }
} }
} }
// System.out.println("ClassLoaderWeavingAdaptor.registerAspects() classloader=" + weavingContext.getClassLoaderName() + ", namespace=" + namespace);
/* We couldn't register one or more aspects so disable the adaptor */ /* We couldn't register one or more aspects so disable the adaptor */
if (!success) { if (!success) {
if (trace.isTraceEnabled()) trace.exit("registerAspects",isEnabled()); if (trace.isTraceEnabled()) trace.exit("registerAspects",isEnabled());
} }


private boolean weaveAndDefineConceteAspects () {
if (trace.isTraceEnabled()) trace.enter("weaveAndDefineConceteAspects",this,concreteAspects);
boolean success = true;

for (Iterator iterator = concreteAspects.iterator(); iterator.hasNext();) {
ConcreteAspectCodeGen gen = (ConcreteAspectCodeGen)iterator.next();
String name = gen.getClassName();
byte[] bytes = gen.getBytes();

try {
byte[] newBytes = weaveClass(name, bytes);
this.generatedClassHandler.acceptClass(name,newBytes);
}
catch (IOException ex) {
trace.error("weaveAndDefineConceteAspects",ex);
error("exception weaving aspect '" + name + "'",ex);
}
}
if (trace.isTraceEnabled()) trace.exit("weaveAndDefineConceteAspects",success);
return success;
}
/** /**
* Register the include / exclude filters * Register the include / exclude filters
* We duplicate simple patterns in startWith filters that will allow faster matching without ResolvedType * We duplicate simple patterns in startWith filters that will allow faster matching without ResolvedType

+ 4
- 0
loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java View File

return false; return false;
} }


public String getClassName () {
return m_concreteAspect.name;
}
/** /**
* Build the bytecode for the concrete aspect * Build the bytecode for the concrete aspect
* *

+ 20
- 0
tests/bugs153/pr132080/AbstractSuperAspect.aj View File

/*******************************************************************************
* Copyright (c) 2005 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthew Webster initial implementation
*******************************************************************************/

public abstract aspect AbstractSuperAspect {
protected abstract pointcut scope ();
before () : execution(public static void main(String[])) && scope() {
System.out.println("? " + thisJoinPoint.getSignature());
}
}

+ 9
- 0
tests/bugs153/pr132080/AbstractSuperAspectWithAround.aj View File

public abstract aspect AbstractSuperAspectWithAround {
protected abstract pointcut scope ();
void around () : execution(public static void main(String[])) && scope() {
System.out.println("? " + thisJoinPoint.getSignature());
proceed();
}
}

+ 13
- 0
tests/bugs153/pr132080/AbstractSuperAspectWithInterface.aj View File

public abstract aspect AbstractSuperAspectWithInterface /*implements TestInterface*/ {
protected abstract pointcut scope ();
before () : execution(public static void main(String[])) && scope() {
System.out.println("? " + thisJoinPoint.getSignature());
}
protected AbstractSuperAspectWithInterface () {
TestInterface test = (TestInterface)this;
test.interfaceMethod();
}
}

+ 4
- 0
tests/bugs153/pr132080/ConcreteAspectWithITD.aj View File

public aspect ConcreteAspectWithITD extends AbstractSuperAspectWithInterface {
protected pointcut scope () :
!within(AbstractSuperAspectWithInterface+);
}

+ 11
- 0
tests/bugs153/pr132080/HelloWorld.java View File

public class HelloWorld {

public void println () {
System.out.println("Hello World!");
}
public static void main (String[] args) throws Exception {
new HelloWorld().println();
}
}

+ 5
- 0
tests/bugs153/pr132080/TestAdvice.aj View File

public aspect TestAdvice {
before () : execution(public new()) && within(!TestAdvice) {
System.out.println("? " + thisJoinPoint.getSignature());
}
}

+ 7
- 0
tests/bugs153/pr132080/TestAroundClosure.aj View File

public aspect TestAroundClosure {
void around () : execution(public new()) && within(!TestAroundClosure) {
System.out.println("> " + thisJoinPoint.getSignature());
proceed();
System.out.println("< " + thisJoinPoint.getSignature());
}
}

+ 8
- 0
tests/bugs153/pr132080/TestITD.aj View File

public aspect TestITD {
declare parents : AbstractSuperAspectWithInterface+ implements TestInterface;
public void TestInterface.interfaceMethod () {
System.out.println("? void TestITD.interfaceMethod()");
}
}

+ 3
- 0
tests/bugs153/pr132080/TestInterface.java View File

public interface TestInterface {
public void interfaceMethod ();
}

+ 11
- 0
tests/bugs153/pr132080/aop-advice.xml View File

<aspectj>
<aspects>
<aspect name="TestAdvice"/>
<concrete-aspect name="ConcreteAspectWithAdvice" extends="AbstractSuperAspect">
<pointcut name="scope" expression="!within(AbstractSuperAspect+)"/>
</concrete-aspect>
</aspects>
<weaver options="-verbose -debug -showWeaveInfo"/>
</aspectj>

+ 11
- 0
tests/bugs153/pr132080/aop-aroundclosure.xml View File

<aspectj>
<aspects>
<aspect name="TestAroundClosure"/>
<concrete-aspect name="ConcreteAspectWithAroundClosure" extends="AbstractSuperAspect">
<pointcut name="scope" expression="!within(AbstractSuperAspect+)"/>
</concrete-aspect>
</aspects>
<weaver options="-verbose -debug -showWeaveInfo -XnoInline"/>
</aspectj>

+ 14
- 0
tests/bugs153/pr132080/aop-itd.xml View File

<aspectj>
<aspects>
<aspect name="TestITD"/>
<concrete-aspect name="ConcreteAspectWithITD" extends="AbstractSuperAspectWithInterface">
<pointcut name="scope" expression="!within(AbstractSuperAspectWithInterface+)"/>
</concrete-aspect>
</aspects>
<weaver options="-verbose -debug -showWeaveInfo">
<!--<dump within="*"/>-->
</weaver>
</aspectj>

+ 1
- 1
tests/bugs153/pr149096/aop-pr149096.xml View File

<aspectj> <aspectj>
<weaver> <weaver>
<dump within="*"/>
<!--<dump within="*"/>-->
</weaver> </weaver>
<aspects> <aspects>
<concrete-aspect name="TestTracing" extends="SimpleTracing"> <concrete-aspect name="TestTracing" extends="SimpleTracing">

+ 16
- 0
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java View File

public void testNPEWithCustomAgent_pr158005() { public void testNPEWithCustomAgent_pr158005() {
runTest("NPE with custom agent"); runTest("NPE with custom agent");
} }

public void testWeaveConcreteSubaspectWithAdvice_pr132080() {
runTest("Weave concrete sub-aspect with advice");
}

public void testWeaveConcreteSubaspectWithITD_pr132080() {
runTest("Weave concrete sub-aspect with ITD");
}

public void testWeaveConcreteSubaspectWithAroundClosure_pr132080() {
runTest("Weave concrete sub-aspect with around closure");
}

public void testWeaveConcreteSubaspectWithCflow_pr132080() {
runTest("Weave concrete sub-aspect with cflow");
}
public void testNoInvalidAbsoluteTypeNameWarning_pr156904_1() {runTest("ensure no invalidAbsoluteTypeName when do match - 1");} public void testNoInvalidAbsoluteTypeNameWarning_pr156904_1() {runTest("ensure no invalidAbsoluteTypeName when do match - 1");}
public void testNoInvalidAbsoluteTypeNameWarning_pr156904_2() {runTest("ensure no invalidAbsoluteTypeName when do match - 2");} public void testNoInvalidAbsoluteTypeNameWarning_pr156904_2() {runTest("ensure no invalidAbsoluteTypeName when do match - 2");}

+ 75
- 0
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml View File

</ant> </ant>
</ajc-test> </ajc-test>


<ajc-test dir="bugs153/pr132080"
title="Weave concrete sub-aspect with advice"
keywords="aop.xml">
<compile
files="HelloWorld.java"
>
</compile>
<compile files="AbstractSuperAspect.aj"/>
<compile files="TestAdvice.aj"/>
<run class="HelloWorld" ltw="aop-advice.xml">
<stdout>
<line text="? ConcreteAspectWithAdvice()"/>
<line text="? void HelloWorld.main(String[])"/>
<line text="? HelloWorld()"/>
<line text="Hello World!"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs153/pr132080"
title="Weave concrete sub-aspect with ITD"
keywords="aop.xml">
<!--
<compile files="AbstractSuperAspectWithInterface.aj, TestInterface.java" options="-verbose"/>
<compile files="HelloWorld.java, TestITD.aj, ConcreteAspectWithITD.aj" options="-verbose">
<message line="3" kind="warning" text="this affected type is not exposed to the weaver: AbstractSuperAspectWithInterface"/>
</compile>
<run class="HelloWorld">
<stdout>
<line text="? void TestITD.interfaceMethod()"/>
<line text="? void HelloWorld.main(String[])"/>
<line text="Hello World!"/>
</stdout>
</run>
-->
<compile files="HelloWorld.java"/>
<compile files="AbstractSuperAspectWithInterface.aj, TestInterface.java"/>
<compile files="TestITD.aj">
<message line="3" kind="warning" text="this affected type is not exposed to the weaver: AbstractSuperAspectWithInterface"/>
</compile>
<run class="HelloWorld" ltw="aop-itd.xml">
<stdout>
<line text="? void TestITD.interfaceMethod()"/>
<line text="? void HelloWorld.main(String[])"/>
<line text="Hello World!"/>
</stdout>
</run>

</ajc-test>

<ajc-test dir="bugs153/pr132080" title="Weave concrete sub-aspect with around closure"
keywords="aop.xml">

<compile files="HelloWorld.java"/>
<compile files="AbstractSuperAspect.aj"/>
<compile files="TestAroundClosure.aj"/>
<run class="HelloWorld" ltw="aop-aroundclosure.xml">
<stdout>
<line text="&rt; ConcreteAspectWithAroundClosure()"/>
<line text="&lt; ConcreteAspectWithAroundClosure()"/>
<line text="? void HelloWorld.main(String[])"/>
<line text="&rt; HelloWorld()"/>
<line text="&lt; HelloWorld()"/>
<line text="Hello World!"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs153/pr149096" title="Weave concrete sub-aspect with cflow">
<compile files="SimpleTracing.aj" outjar="out.jar"/>
<compile files="TestMain.aj"/>
<run class="TestMain" ltw="aop-pr149096.xml"/>
</ajc-test>

</suite> </suite>

+ 4
- 0
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java View File

return MessageUtil.error(messageHandler,message); return MessageUtil.error(messageHandler,message);
} }
protected boolean error (String message, Throwable th) {
return messageHandler.handleMessage(new Message(message, IMessage.ERROR, th, null));
}
public String getContextId () { public String getContextId () {
return "WeavingAdaptor"; return "WeavingAdaptor";
} }

Loading…
Cancel
Save