import org.aspectj.ajde.core.AjCompiler; | import org.aspectj.ajde.core.AjCompiler; | ||||
import org.aspectj.ajde.core.ICompilerConfiguration; | import org.aspectj.ajde.core.ICompilerConfiguration; | ||||
import org.aspectj.ajde.core.IOutputLocationManager; | import org.aspectj.ajde.core.IOutputLocationManager; | ||||
import org.aspectj.ajde.core.JavaOptions; | |||||
import org.aspectj.ajdt.ajc.AjdtCommand; | import org.aspectj.ajdt.ajc.AjdtCommand; | ||||
import org.aspectj.ajdt.ajc.BuildArgParser; | import org.aspectj.ajdt.ajc.BuildArgParser; | ||||
import org.aspectj.ajdt.ajc.ConfigParser; | import org.aspectj.ajdt.ajc.ConfigParser; | ||||
handleMessage(new Message(getFormattedOptionsString(),IMessage.INFO,null,null)); | handleMessage(new Message(getFormattedOptionsString(),IMessage.INFO,null,null)); | ||||
CompilationAndWeavingContext.reset(); | CompilationAndWeavingContext.reset(); | ||||
AjBuildConfig buildConfig = genAjBuildConfig(); | AjBuildConfig buildConfig = genAjBuildConfig(); | ||||
if (buildConfig == null) return; | if (buildConfig == null) return; | ||||
if (buildFresh) { | |||||
ajBuildManager.batchBuild(buildConfig,msgHandlerAdapter); | |||||
} else { | |||||
ajBuildManager.incrementalBuild(buildConfig,msgHandlerAdapter); | |||||
} | |||||
/* | |||||
if (buildFresh) { | if (buildFresh) { | ||||
AjBuildConfig buildConfig = genAjBuildConfig(); | |||||
if (buildConfig == null) return; | |||||
ajBuildManager.batchBuild(buildConfig,msgHandlerAdapter); | ajBuildManager.batchBuild(buildConfig,msgHandlerAdapter); | ||||
} else { | } else { | ||||
AjBuildConfig buildConfig = ajBuildManager.getState().getBuildConfig(); | |||||
ajBuildManager.incrementalBuild(buildConfig,msgHandlerAdapter); | ajBuildManager.incrementalBuild(buildConfig,msgHandlerAdapter); | ||||
} | } | ||||
*/ | |||||
IncrementalStateManager.recordSuccessfulBuild(compiler.getId(),ajBuildManager.getState()); | IncrementalStateManager.recordSuccessfulBuild(compiler.getId(),ajBuildManager.getState()); | ||||
} catch (ConfigParser.ParseException pe) { | } catch (ConfigParser.ParseException pe) { | ||||
} else { | } else { | ||||
handleMessage(new Message(message.getMessage() + "\n" | handleMessage(new Message(message.getMessage() + "\n" | ||||
+ CompilationAndWeavingContext.getCurrentContext(),IMessage.ERROR,e,null)); | + CompilationAndWeavingContext.getCurrentContext(),IMessage.ERROR,e,null)); | ||||
}; | |||||
} | |||||
} catch (Throwable t) { | } catch (Throwable t) { | ||||
handleMessage(new Message("Compile error: " + LangUtil.unqualifiedClassName(t) + " thrown: " + | handleMessage(new Message("Compile error: " + LangUtil.unqualifiedClassName(t) + " thrown: " + | ||||
"" + t.getMessage(),IMessage.ABORT,t,null)); | "" + t.getMessage(),IMessage.ABORT,t,null)); | ||||
return config; | return config; | ||||
} | } | ||||
/** | |||||
* Check that the user hasn't specified Java 6 for the compliance, source and | |||||
* target levels. If they have then an error is thrown. | |||||
*/ | |||||
private void checkNotAskedForJava6Compliance() { | |||||
// bug 164384 - Throwing an IMessage.ERRROR rather than an IMessage.ABORT | |||||
// means that we'll continue to try to compile the code. This means that | |||||
// the user may see other errors (for example, if they're using annotations | |||||
// then they'll get errors saying that they require 5.0 compliance). | |||||
// Throwing IMessage.ABORT would prevent this, however, 'abort' is really | |||||
// for compiler exceptions. | |||||
Map javaOptions = compiler.getCompilerConfiguration().getJavaOptionsMap(); | |||||
if (javaOptions != null){ | |||||
String version = (String)javaOptions.get(CompilerOptions.OPTION_Compliance); | |||||
String sourceVersion = (String)javaOptions.get(CompilerOptions.OPTION_Source); | |||||
String targetVersion = (String)javaOptions.get(CompilerOptions.OPTION_TargetPlatform); | |||||
if (version!=null && version.equals(JavaOptions.VERSION_16)) { | |||||
String msg = "Java 6.0 compliance level is unsupported"; | |||||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||||
compiler.getMessageHandler().handleMessage(m); | |||||
} else if (sourceVersion!=null && sourceVersion.equals(JavaOptions.VERSION_16)) { | |||||
String msg = "Java 6.0 source level is unsupported"; | |||||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||||
compiler.getMessageHandler().handleMessage(m); | |||||
} else if (targetVersion!=null && targetVersion.equals(JavaOptions.VERSION_16)) { | |||||
String msg = "Java 6.0 target level is unsupported"; | |||||
IMessage m = new Message(msg, IMessage.ERROR, null, null); | |||||
compiler.getMessageHandler().handleMessage(m); | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Configure the given AjBuildConfig with the options found in the | * Configure the given AjBuildConfig with the options found in the | ||||
* ICompilerConfiguration implementation associated with the AjCompiler | * ICompilerConfiguration implementation associated with the AjCompiler |
public void testDeclareMessageContents() { | public void testDeclareMessageContents() { | ||||
List msgs = handler.getMessages(); | List msgs = handler.getMessages(); | ||||
IMessage msg = (IMessage)((TestMessageHandler.TestMessage)msgs.get(1)).getContainedMessage(); | |||||
IMessage msg = ((TestMessageHandler.TestMessage)msgs.get(1)).getContainedMessage(); | |||||
assertEquals( "Please don't call setters" , msg.getMessage()); | assertEquals( "Please don't call setters" , msg.getMessage()); | ||||
assertEquals("field-set(int apackage.SomeClass.x)", msg.getDetails()); | assertEquals("field-set(int apackage.SomeClass.x)", msg.getDetails()); | ||||
} | } |
private TestMessageHandler handler; | private TestMessageHandler handler; | ||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
private String testProps; | |||||
private String[] config1 = new String[] { | private String[] config1 = new String[] { | ||||
"src" + File.separator + "Main.java", | "src" + File.separator + "Main.java", | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | handler = (TestMessageHandler) getCompiler().getMessageHandler(); | ||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | compilerConfig = (TestCompilerConfiguration) getCompiler() | ||||
.getCompilerConfiguration(); | .getCompilerConfiguration(); | ||||
testProps = getAbsoluteProjectDir() + File.separator + "src" + File.separator + "testsrc" + File.separator + "test.props"; | |||||
} | } | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { |
import org.aspectj.ajde.core.AjdeCoreTestCase; | import org.aspectj.ajde.core.AjdeCoreTestCase; | ||||
import org.aspectj.ajde.core.TestCompilerConfiguration; | import org.aspectj.ajde.core.TestCompilerConfiguration; | ||||
import org.aspectj.ajde.core.TestMessageHandler; | |||||
import org.aspectj.asm.AsmManager; | import org.aspectj.asm.AsmManager; | ||||
import org.aspectj.asm.IHierarchy; | import org.aspectj.asm.IHierarchy; | ||||
import org.aspectj.asm.IProgramElement; | import org.aspectj.asm.IProgramElement; | ||||
"pkg" + File.separator + "InPackage.java" | "pkg" + File.separator + "InPackage.java" | ||||
}; | }; | ||||
private TestMessageHandler handler; | |||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
protected void setUp() throws Exception { | protected void setUp() throws Exception { | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject("coverage"); | initialiseProject("coverage"); | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | |||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | compilerConfig = (TestCompilerConfiguration) getCompiler() | ||||
.getCompilerConfiguration(); | .getCompilerConfiguration(); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
super.tearDown(); | super.tearDown(); | ||||
handler = null; | |||||
compilerConfig = null; | compilerConfig = null; | ||||
model = null; | model = null; | ||||
} | } | ||||
public void testRoot() { | public void testRoot() { | ||||
IProgramElement root = (IProgramElement)model.getRoot(); | |||||
IProgramElement root = model.getRoot(); | |||||
assertNotNull(root); | assertNotNull(root); | ||||
assertEquals("Expected root to be named 'coverage' but found " | assertEquals("Expected root to be named 'coverage' but found " | ||||
+ root.toLabelString(), root.toLabelString(), "coverage"); | + root.toLabelString(), root.toLabelString(), "coverage"); | ||||
} | } | ||||
public void testInterTypeMemberDeclares() { | public void testInterTypeMemberDeclares() { | ||||
IProgramElement node = (IProgramElement)model.getRoot(); | |||||
IProgramElement node = model.getRoot(); | |||||
assertNotNull(node); | assertNotNull(node); | ||||
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "InterTypeDecCoverage"); | IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "InterTypeDecCoverage"); | ||||
} | } | ||||
public void testPointcuts() { | public void testPointcuts() { | ||||
IProgramElement node = (IProgramElement)model.getRoot(); | |||||
IProgramElement node = model.getRoot(); | |||||
assertNotNull(node); | assertNotNull(node); | ||||
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); | IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); | ||||
} | } | ||||
public void testAbstract() { | public void testAbstract() { | ||||
IProgramElement node = (IProgramElement)model.getRoot(); | |||||
IProgramElement node = model.getRoot(); | |||||
assertNotNull(node); | assertNotNull(node); | ||||
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AbstractAspect"); | IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AbstractAspect"); | ||||
} | } | ||||
public void testAdvice() { | public void testAdvice() { | ||||
IProgramElement node = (IProgramElement)model.getRoot(); | |||||
IProgramElement node = model.getRoot(); | |||||
assertNotNull(node); | assertNotNull(node); | ||||
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); | IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); |
import org.aspectj.ajde.core.AjdeCoreTestCase; | import org.aspectj.ajde.core.AjdeCoreTestCase; | ||||
import org.aspectj.ajde.core.TestCompilerConfiguration; | import org.aspectj.ajde.core.TestCompilerConfiguration; | ||||
import org.aspectj.ajde.core.TestMessageHandler; | |||||
import org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder; | import org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder; | ||||
import org.aspectj.asm.AsmManager; | import org.aspectj.asm.AsmManager; | ||||
import org.aspectj.asm.IProgramElement; | import org.aspectj.asm.IProgramElement; | ||||
"pkg" + File.separator + "InPackage.java" | "pkg" + File.separator + "InPackage.java" | ||||
}; | }; | ||||
private TestMessageHandler handler; | |||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
protected void setUp() throws Exception { | protected void setUp() throws Exception { | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject("coverage"); | initialiseProject("coverage"); | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | |||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | compilerConfig = (TestCompilerConfiguration) getCompiler() | ||||
.getCompilerConfiguration(); | .getCompilerConfiguration(); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
super.tearDown(); | super.tearDown(); | ||||
handler = null; | |||||
compilerConfig = null; | compilerConfig = null; | ||||
manager = null; | manager = null; | ||||
} | } |
import org.aspectj.ajde.core.AjdeCoreTestCase; | import org.aspectj.ajde.core.AjdeCoreTestCase; | ||||
import org.aspectj.ajde.core.TestCompilerConfiguration; | import org.aspectj.ajde.core.TestCompilerConfiguration; | ||||
import org.aspectj.ajde.core.TestMessageHandler; | |||||
import org.aspectj.asm.AsmManager; | import org.aspectj.asm.AsmManager; | ||||
import org.aspectj.asm.HierarchyWalker; | import org.aspectj.asm.HierarchyWalker; | ||||
import org.aspectj.asm.IHierarchy; | import org.aspectj.asm.IHierarchy; | ||||
"figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java" | "figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java" | ||||
}; | }; | ||||
private TestMessageHandler handler; | |||||
private TestCompilerConfiguration compilerConfig; | private TestCompilerConfiguration compilerConfig; | ||||
protected void setUp() throws Exception { | protected void setUp() throws Exception { | ||||
super.setUp(); | super.setUp(); | ||||
initialiseProject("figures-coverage"); | initialiseProject("figures-coverage"); | ||||
handler = (TestMessageHandler) getCompiler().getMessageHandler(); | |||||
compilerConfig = (TestCompilerConfiguration) getCompiler() | compilerConfig = (TestCompilerConfiguration) getCompiler() | ||||
.getCompilerConfiguration(); | .getCompilerConfiguration(); | ||||
compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | compilerConfig.setProjectSourceFiles(getSourceFileList(files)); | ||||
protected void tearDown() throws Exception { | protected void tearDown() throws Exception { | ||||
super.tearDown(); | super.tearDown(); | ||||
handler = null; | |||||
compilerConfig = null; | compilerConfig = null; | ||||
manager = null; | manager = null; | ||||
} | } | ||||
IProgramElement node = manager.getHierarchy().findElementForSourceFile( | IProgramElement node = manager.getHierarchy().findElementForSourceFile( | ||||
testFile.getAbsolutePath()); | testFile.getAbsolutePath()); | ||||
assertTrue("find result", node != null) ; | assertTrue("find result", node != null) ; | ||||
IProgramElement pNode = (IProgramElement)node; | |||||
String child = ((IProgramElement)pNode.getChildren().get(1)).getName(); | |||||
String child = ((IProgramElement)node.getChildren().get(1)).getName(); | |||||
assertTrue("expected Figure got child " + child, child.equals("Figure")); | assertTrue("expected Figure got child " + child, child.equals("Figure")); | ||||
} | } | ||||
IProgramElement node = manager.getHierarchy().findElementForSourceFile( | IProgramElement node = manager.getHierarchy().findElementForSourceFile( | ||||
testFile.getAbsolutePath()); | testFile.getAbsolutePath()); | ||||
assertTrue("find result", node != null) ; | assertTrue("find result", node != null) ; | ||||
IProgramElement pNode = (IProgramElement)((IProgramElement)node).getChildren().get(2); | |||||
IProgramElement pNode = (IProgramElement)(node).getChildren().get(2); | |||||
IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0); | IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0); | ||||
assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT)); | assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT)); | ||||
assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()")); | assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()")); | ||||
testFile.getAbsolutePath(), 1); | testFile.getAbsolutePath(), 1); | ||||
assertTrue("find result", node != null) ; | assertTrue("find result", node != null) ; | ||||
assertEquals("find result has children", 3, node.getChildren().size()) ; | assertEquals("find result has children", 3, node.getChildren().size()) ; | ||||
IProgramElement pNode = (IProgramElement)node; | |||||
assertTrue("found node: " + pNode.getName(), pNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)); | |||||
assertTrue("found node: " + node.getName(), node.getKind().equals(IProgramElement.Kind.FILE_JAVA)); | |||||
} | } | ||||
/** | /** | ||||
File testFile = openFile("figures" + File.separator + "Main.java"); | File testFile = openFile("figures" + File.separator + "Main.java"); | ||||
IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11); | IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11); | ||||
assertTrue("find result", node != null); | assertTrue("find result", node != null); | ||||
IProgramElement pNode = (IProgramElement)((IProgramElement)node).getParent(); | |||||
IProgramElement pNode = node.getParent(); | |||||
if (null == pNode) { | if (null == pNode) { | ||||
assertTrue("null parent of " + node, false); | assertTrue("null parent of " + node, false); | ||||
} | } |