import java.util.StringTokenizer;
import org.aspectj.asm.IRelationship;
-import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
-import org.aspectj.bridge.Message;
import org.aspectj.util.LangUtil;
import org.aspectj.weaver.ICrossReferenceHandler;
import org.aspectj.weaver.Lint;
world.setXnoInline(weaverOption.noInline);
// AMC - autodetect as per line below, needed for AtAjLTWTests.testLTWUnweavable
world.setBehaveInJava5Way(LangUtil.is15VMOrGreater());
- //-Xlintfile: first so that lint wins
+
+ /* First load defaults */
+ bcelWorld.getLint().loadDefaultProperties();
+
+ /* Second overlay LTW defaults */
+ bcelWorld.getLint().adviceDidNotMatch.setKind(null);
+
+ /* Third load user file using -Xlintfile so that -Xlint wins */
if (weaverOption.lintFile != null) {
InputStream resource = null;
try {
}
}
if (failure != null || resource == null) {
- world.getMessageHandler().handleMessage(new Message(
- "Cannot access resource for -Xlintfile:"+weaverOption.lintFile,
- IMessage.WARNING,
- failure,
- null));
+ warn("Cannot access resource for -Xlintfile:"+weaverOption.lintFile,failure);
+// world.getMessageHandler().handleMessage(new Message(
+// "Cannot access resource for -Xlintfile:"+weaverOption.lintFile,
+// IMessage.WARNING,
+// failure,
+// null));
}
} finally {
try { resource.close(); } catch (Throwable t) {;}
}
- }
- if (weaverOption.lint == null) {
- bcelWorld.getLint().loadDefaultProperties();
- bcelWorld.getLint().adviceDidNotMatch.setKind(IMessage.INFO);
- } else {
+ }
+
+ /* Fourth override with -Xlint */
+ if (weaverOption.lint != null) {
if (weaverOption.lint.equals("default")) {//FIXME should be AjBuildConfig.AJLINT_DEFAULT but yetanother deps..
bcelWorld.getLint().loadDefaultProperties();
} else {
String line = (String) iter.next();
lineNo++;
String outputLine = strTok.nextToken().trim();
- if (!line.equals(outputLine)) {
+ /* Avoid trying to match on ajSandbox source names that appear in messages */
+ if (outputLine.indexOf(line) == -1) {
matches = false;
break;
}
private OutputSpec stdErrSpec;
private OutputSpec stdOutSpec;
private String ltwFile;
+ private String xlintFile;
public RunSpec() {
}
String[] args = buildArgs();
// System.err.println("? execute() inTestCase='" + inTestCase + "', ltwFile=" + ltwFile);
boolean useLtw = copyLtwFile(inTestCase.getSandboxDirectory());
+ copyXlintFile(inTestCase.getSandboxDirectory());
AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,getClasspath(),useLtw);
if (stdErrSpec != null) {
stdErrSpec.matchAgainst(rr.getStdErr());
return useLtw;
}
+
+ public String getXlintFile() {
+ return xlintFile;
+ }
+
+ public void setXlintFile(String xlintFile) {
+ this.xlintFile = xlintFile;
+ }
+
+ private void copyXlintFile (File sandboxDirectory) {
+ if (xlintFile != null) {
+ File from = new File(baseDir,xlintFile);
+ File to = new File(sandboxDirectory, File.separator + xlintFile);
+ try {
+ FileUtil.copyFile(from,to);
+ }
+ catch (IOException ex) {
+ AjcTestCase.fail(ex.toString());
+ }
+ }
+ }
}
digester.addObjectCreate("suite/ajc-test/run",RunSpec.class);
digester.addSetProperties("suite/ajc-test/run","class","classToRun");
digester.addSetProperties("suite/ajc-test/run","ltw","ltwFile");
+ digester.addSetProperties("suite/ajc-test/run","xlintfile","xlintFile");
digester.addSetNext("suite/ajc-test/run","addTestStep","org.aspectj.testing.ITestStep");
digester.addObjectCreate("*/message",ExpectedMessageSpec.class);
digester.addSetProperties("*/message");
--- /dev/null
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+import org.aspectj.lang.JoinPoint;
+
+public aspect Aspect3 {
+
+ before () : execution(void Main.test999()) {
+ System.err.println("Aspect1.before_" + thisJoinPoint.getSignature().getName());
+ }
+}
--- /dev/null
+adviceDidNotMatch = warning
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Aspect3"/>
+ </aspects>
+
+ <weaver options="-verbose -showWeaveInfo"/>
+</aspectj>
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Aspect3"/>
+ </aspects>
+
+ <weaver options="-verbose -showWeaveInfo -Xlint:warning"/>
+</aspectj>
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Aspect3"/>
+ </aspects>
+
+ <weaver options="-verbose -showWeaveInfo -Xlintfile:Xlint-nomatch.properties"/>
+</aspectj>
--- /dev/null
+<aspectj>
+ <weaver options="-Xlintfile:Xlint-empty.properties"/>
+</aspectj>
runTest("Ensure weaver lint warning issued when an aspect is not used for weaving");
}
+ public void testXlintfileEmpty () {
+ runTest("Empty Xlint.properties file");
+ }
+
+ public void testXlintfileMissing () {
+ runTest("Warning with missing Xlint.properties file");
+ }
+
+ public void testXlintWarningAdviceDidNotMatchSuppressed () {
+ runTest("Warning when advice doesn't match suppressed for LTW");
+ }
+
+ public void testXlintfile () {
+ runTest("Override suppressing of warning when advice doesn't match using -Xlintfile");
+ }
+
+ public void testXlintDefault () {
+ runTest("Warning when advice doesn't match using -Xlint:default");
+ }
+
+ public void testXlintWarning () {
+ runTest("Override suppressing of warning when advice doesn't match using -Xlint:warning");
+ }
+
/*
* Allow system properties to be set and restored
* TODO maw move to XMLBasedAjcTestCase or RunSpec
+
<!-- Load-time weaving tests -->
<ajc-test dir="ltw"
</run>
</ajc-test>
+ <ajc-test dir="ltw"
+ title="Empty Xlint.properties file"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <run class="Main" ltw="aop-xlintfile.xml" xlintfile="Xlint-empty.properties">
+ <stderr>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Warning with missing Xlint.properties file"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <run class="Main" ltw="aop-xlintfile.xml">
+ <stderr>
+ <line text="warning Cannot access resource for -Xlintfile:Xlint-empty.properties"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Warning when advice doesn't match suppressed for LTW"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <compile
+ files="Aspect3.aj"
+ >
+ </compile>
+ <run class="Main" ltw="aop-nomatch.xml">
+ <stderr>
+ <line text="info register aspect Aspect3"/>
+ <line text="info weaving 'Main'"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Override suppressing of warning when advice doesn't match using -Xlintfile"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <compile
+ files="Aspect3.aj"
+ >
+ </compile>
+ <run class="Main" ltw="aop-nomatchxlintfile.xml" xlintfile="Xlint-nomatch.properties">
+ <stderr>
+ <line text="info register aspect Aspect3"/>
+ <line text="info weaving 'Main'"/>
+ <line text="advice defined in Aspect3 has not been applied [Xlint:adviceDidNotMatch]"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Warning when advice doesn't match using -Xlint:default"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <compile
+ files="Aspect3.aj"
+ >
+ </compile>
+ <run class="Main" ltw="aop-nomatchxlint.xml">
+ <stderr>
+ <line text="info register aspect Aspect3"/>
+ <line text="info weaving 'Main'"/>
+ <line text="advice defined in Aspect3 has not been applied [Xlint:adviceDidNotMatch]"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Override suppressing of warning when advice doesn't match using -Xlint:warning"
+ keywords="xlint, ltw">
+ <compile
+ files="Main.java"
+ >
+ </compile>
+ <compile
+ files="Aspect3.aj"
+ >
+ </compile>
+ <run class="Main" ltw="aop-nomatchxlint.xml">
+ <stderr>
+ <line text="info register aspect Aspect3"/>
+ <line text="info weaving 'Main'"/>
+ <line text="advice defined in Aspect3 has not been applied [Xlint:adviceDidNotMatch]"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
}
protected boolean warn (String message, Throwable th) {
- return messageHandler.handleMessage(new Message("Register definition failed", IMessage.WARNING, th, null));
+ return messageHandler.handleMessage(new Message(message, IMessage.WARNING, th, null));
}
protected boolean error (String message) {
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.WildcardType;
-import java.util.HashMap;
-import java.util.Map;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.AjType;
import org.aspectj.lang.reflect.AjTypeSystem;
import org.aspectj.lang.reflect.Pointcut;
import org.aspectj.weaver.AnnotationX;
-import org.aspectj.weaver.BoundedReferenceType;
import org.aspectj.weaver.ReferenceType;
import org.aspectj.weaver.ResolvedMember;
import org.aspectj.weaver.ResolvedPointcutDefinition;
import org.aspectj.weaver.ResolvedType;
-import org.aspectj.weaver.TypeFactory;
import org.aspectj.weaver.TypeVariable;
import org.aspectj.weaver.TypeVariableReferenceType;
import org.aspectj.weaver.UnresolvedType;