diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-29 16:48:39 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-29 16:48:39 -0800 |
commit | be07484b4a9da8ba8399080c182bf095ba62a2fe (patch) | |
tree | a30608f5ccb2b9c8dd92834f74ab16b22937b6af /ajde/src/test | |
parent | e770fb965370b4c4daf15b3e0f03b8ce77f75c0c (diff) | |
download | aspectj-be07484b4a9da8ba8399080c182bf095ba62a2fe.tar.gz aspectj-be07484b4a9da8ba8399080c182bf095ba62a2fe.zip |
mavenizing ajde - wip
Diffstat (limited to 'ajde/src/test')
19 files changed, 1560 insertions, 0 deletions
diff --git a/ajde/src/test/java/org/aspectj/ajde/AjdeCompilerTests.java b/ajde/src/test/java/org/aspectj/ajde/AjdeCompilerTests.java new file mode 100644 index 000000000..0d9d6d68d --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/AjdeCompilerTests.java @@ -0,0 +1,76 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +import org.aspectj.ajde.core.AjCompiler; + +/** + * Tests ajde's management of the AjCompiler instances. Expect + * there to be a different one for each .lst file and for ajde + * to only remember the compiler for the last .lst file. + */ +public class AjdeCompilerTests extends AjdeTestCase { + + protected void setUp() throws Exception { + super.setUp(); + initialiseProject("LstBuildConfigManagerTest"); + } + + // Expect to get a different compiler instance for each + // different config file + public void testGetSameAjCompilerForSameConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("bad-injar.lst"); + assertEquals("expected the same AjCompiler instance to be returned" + + " for the same configFile but found different ones", c1, c2); + } + + // Expect to get a different compiler instance for each + // different config file + public void testGetDifferentAjCompilerForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertNotSame("expected different AjCompiler instances to be returned" + + " for different configFiles but found the smae", c1, c2); + } + + // want to keep the same setting regardless of the configFile + // being built - therefore the same instance should be passed + // from one AjCompiler instance to the next + public void testSameCompilerConfigForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same compilerConfig instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getCompilerConfiguration(), c2.getCompilerConfiguration()); + } + + // want to have a different messageHandler instance for the different + // config files - or we can just reset?!?! Resetting would be easier + public void testSameMessageHandlerForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same messageHandler instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getMessageHandler(), c2.getMessageHandler()); + } + + // can have the same buildProgressMonitor for the different configFiles + // because it holds no state + public void testSameBuildProgressMonitorForDifferentConfigFiles() { + AjCompiler c1 = getCompilerForConfigFileWithName("bad-injar.lst"); + AjCompiler c2 = getCompilerForConfigFileWithName("dir-entry.lst"); + assertEquals("expected the same buildProgressMonitor instance to be associated" + + " with the different AjCompiler's however found different ones", + c1.getBuildProgressMonitor(), c2.getBuildProgressMonitor()); + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/AjdeModuleTests.java b/ajde/src/test/java/org/aspectj/ajde/AjdeModuleTests.java new file mode 100644 index 000000000..b6a1daa55 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/AjdeModuleTests.java @@ -0,0 +1,27 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ +package org.aspectj.ajde; + +import junit.framework.*; + +public class AjdeModuleTests extends TestCase { + + public static TestSuite suite() { + TestSuite suite = new TestSuite(AjdeModuleTests.class.getName()); + suite.addTest(org.aspectj.ajde.AjdeTests.suite()); + return suite; + } + + public AjdeModuleTests(String name) { super(name); } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java b/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java new file mode 100644 index 000000000..5f2b2f2f7 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java @@ -0,0 +1,135 @@ +/******************************************************************** + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) and + * to use a sandbox directory + *******************************************************************/ +package org.aspectj.ajde; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +import org.aspectj.ajde.core.AjCompiler; +import org.aspectj.ajde.ui.utils.TestBuildProgressMonitor; +import org.aspectj.ajde.ui.utils.TestCompilerConfiguration; +import org.aspectj.ajde.ui.utils.TestEditorAdapter; +import org.aspectj.ajde.ui.utils.TestIdeUIAdapter; +import org.aspectj.ajde.ui.utils.TestMessageHandler; +import org.aspectj.ajde.ui.utils.TestRuntimeProperties; +import org.aspectj.tools.ajc.Ajc; + +public class AjdeTestCase extends TestCase { + + public final static String testdataSrcDir = "../ajde/testdata"; + protected static File sandboxDir; + + private String projectDir; + + protected void setUp() throws Exception { + super.setUp(); + // Create a sandbox in which to work + sandboxDir = Ajc.createEmptySandbox(); + // AMC - added this next line as a temporary workaround for + // listener leakage in AsmManager induced by the Ajde test suite. + // Ajde.getDefault().getModel().removeAllListeners(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + projectDir = null; + sandboxDir = null; + } + + /** + * Fill in the working directory with the project files and creates a compiler instance for this project + */ + public void initialiseProject(String projectName) { + + File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName); + File destination = new File(getWorkingDir(), projectName); + if (!destination.exists()) { + destination.mkdir(); + } + copy(projectSrc, destination); + projectDir = destination.getAbsolutePath(); + + // need to initialize via AjdeUIManager + Ajde.getDefault().init(new TestCompilerConfiguration(projectDir), new TestMessageHandler(), new TestBuildProgressMonitor(), + new TestEditorAdapter(), new TestIdeUIAdapter(), new IconRegistry(), null, // new JFrame(), + new TestRuntimeProperties(), true); + } + + /** + * @return the working directory + */ + protected File getWorkingDir() { + return sandboxDir; + } + + /** + * @return the absolute path of the project directory for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject + */ + protected String getAbsoluteProjectDir() { + return projectDir; + } + + /** + * Copy the contents of some directory to another location - the copy is recursive. + */ + private void copy(File from, File to) { + String contents[] = from.list(); + if (contents == null) + return; + for (int i = 0; i < contents.length; i++) { + String string = contents[i]; + File f = new File(from, string); + File t = new File(to, string); + + if (f.isDirectory()) { + t.mkdir(); + copy(f, t); + } else if (f.isFile()) { + try { + org.aspectj.util.FileUtil.copyFile(f, t); + } catch (IOException e) { + throw new AssertionFailedError("Unable to copy " + f + " to " + t); + } + } + } + } + + protected File openFile(String path) { + return new File(projectDir + File.separatorChar + path); + } + + public void doBuild(String configFile) { + getCompilerForConfigFileWithName(configFile).build(); + } + + public AjCompiler getCompilerForConfigFileWithName(String configFileName) { + return Ajde.getDefault().getCompilerForConfigFile(projectDir + File.separator + configFileName); + } + + public List getErrorMessages(String configFileName) { + return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getErrors(); + } + + public List getMessages(String configFileName) { + return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getMessages(); + } + + protected String genStructureModelExternFilePath(String configFilePath) { + return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym"; + } +} diff --git a/ajde/src/test/java/org/aspectj/ajde/AjdeTests.java b/ajde/src/test/java/org/aspectj/ajde/AjdeTests.java new file mode 100644 index 000000000..c48b9d2fe --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/AjdeTests.java @@ -0,0 +1,44 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins updated for bug 148190 + * ******************************************************************/ +package org.aspectj.ajde; + +import org.aspectj.ajde.internal.AspectJBuildManagerTest; +import org.aspectj.ajde.internal.LstBuildConfigManagerTest; +import org.aspectj.ajde.ui.StructureSearchManagerTest; +import org.aspectj.ajde.ui.StructureViewManagerTest; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AjdeTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(AjdeTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(SymbolFileGenerationTest.class); + suite.addTestSuite(ExtensionTests.class); + suite.addTestSuite(AspectJBuildManagerTest.class); + suite.addTestSuite(LstBuildConfigManagerTest.class); + suite.addTestSuite(StructureSearchManagerTest.class); + suite.addTestSuite(StructureViewManagerTest.class); + suite.addTestSuite(AjdeCompilerTests.class); + + //$JUnit-END$ + return suite; + } + + public AjdeTests(String name) { super(name); } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ExtensionTests.java b/ajde/src/test/java/org/aspectj/ajde/ExtensionTests.java new file mode 100644 index 000000000..0a445ba8b --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ExtensionTests.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.ajde; + +import java.io.File; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; +import org.aspectj.tools.ajc.AjcTestCase; +import org.aspectj.tools.ajc.CompilationResult; + +/** + * Tests the 'extensions' to AJDE: 1) ID is now available on messages to allow you to see what 'kind' of message it is - this + * activates quick fixes/etc in Eclipse. + */ +public class ExtensionTests extends AjcTestCase { + + public static final String PROJECT_DIR = "extensions"; + private static final boolean debugTests = false; + private File baseDir; + + protected void setUp() throws Exception { + super.setUp(); + // TODO-path + baseDir = new File("../ajde/testdata", PROJECT_DIR); + } + + /** + * Aim: Check that the ID of certain message kinds are correct + * + * ajc -warn:unusedImport UnusedImport.java + * + * Expected result is that id matches IProblem.UnusedImport + */ + public void testMessageID() { + String[] args = new String[] { "UnusedImport.java", "-warn:unusedImport" }; + CompilationResult result = ajc(baseDir, args); + List l = result.getWarningMessages(); + IMessage m = ((IMessage) l.get(0)); + assertTrue("Expected ID of message to be " + IProblem.UnusedImport + " (UnusedImport) but found an ID of " + m.getID(), + m.getID() == IProblem.UnusedImport); + } + + public void testInnerClassesInASM() { + String[] args = new String[] { "InnerClasses.java", "-emacssym", "-Xset:minimalModel=false" }; + CompilationResult result = ajc(baseDir, args); + /* List l = */result.getWarningMessages(); + /* Properties p = */AsmManager.lastActiveStructureModel.summarizeModel().getProperties(); + if (debugTests) + System.out.println("Structure Model for InnerClasses.java:"); + walkit(AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0); + foundNode = null; + findChild("main", AsmManager.lastActiveStructureModel.getHierarchy().getRoot()); + assertTrue("Should have found node 'main' in the model", foundNode != null); + IProgramElement runnableChild = getChild(foundNode, "new Runnable() {..}"); + assertTrue("'main' should have a child 'new Runnable() {..}'", runnableChild != null); + assertTrue("'new Runnable() {..}' should have a 'run' child", getChild(runnableChild, "run") != null); + + /* + * Left hand side is before the fix, right hand side is after: <root> InnerClasses.java import declarations InnerClasses A A + * method method 1 new Runnable() {..} run run main main 2 new Runnable() {..} run run 3 new Object() {..} toString toString + * 4 new Runnable run run + */ + + } + + private IProgramElement getChild(IProgramElement parent, String s) { + List<IProgramElement> kids = parent.getChildren(); + for (Iterator<IProgramElement> iter = kids.iterator(); iter.hasNext();) { + IProgramElement element = (IProgramElement) iter.next(); + if (element.getName().indexOf(s) != -1) + return element; + } + return null; + } + + private IProgramElement foundNode = null; + + private void findChild(String s, IProgramElement ipe) { + if (ipe == null) + return; + if (ipe.getName().indexOf(s) != -1) { + foundNode = ipe; + return; + } + if (ipe.getChildren() != null) { + List kids = ipe.getChildren(); + for (Iterator iter = kids.iterator(); iter.hasNext();) { + IProgramElement element = (IProgramElement) iter.next(); + findChild(s, element); + } + } + } + + public void walkit(IProgramElement ipe, int indent) { + if (ipe != null) { + if (debugTests) + for (int i = 0; i < indent; i++) + System.out.print(" "); + if (debugTests) + System.out.println(ipe.toLabelString());// getName()); + if (ipe.getChildren() != null) { + List kids = ipe.getChildren(); + for (Iterator iter = kids.iterator(); iter.hasNext();) { + IProgramElement element = (IProgramElement) iter.next(); + walkit(element, indent + 2); + } + } + } + } + + /** + * Aim: Check that the start/end of certain warnings are correct + * + * ajc -warn:unusedImport UnusedImport.java + * + * Expected result is first warning message has start=7 end=20 + */ + public void testMessageSourceStartEnd() { + String[] args = new String[] { "UnusedImport.java", "-warn:unusedImport" }; + CompilationResult result = ajc(baseDir, args); + List l = result.getWarningMessages(); + IMessage m = ((IMessage) l.get(0)); + assertTrue("Expected source start to be 7 but was " + m.getSourceStart(), m.getSourceStart() == 7); + assertTrue("Expected source end to be 20 but was " + m.getSourceEnd(), m.getSourceEnd() == 20); + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/SymbolFileGenerationTest.java b/ajde/src/test/java/org/aspectj/ajde/SymbolFileGenerationTest.java new file mode 100644 index 000000000..2d1669695 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/SymbolFileGenerationTest.java @@ -0,0 +1,81 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajde; + +import java.io.File; +import java.io.FileFilter; + +import org.aspectj.tools.ajc.AjcTestCase; +import org.aspectj.util.FileUtil; + +/** + * @author Mik Kersten + */ +public class SymbolFileGenerationTest extends AjcTestCase { + private static final String DIR = "../ajde/testdata/examples/coverage"; + + protected File dir = new File(DIR); + protected File configFile = new File(DIR + "/coverage.lst"); + protected File esymFile, outDir, crossRefsFile; + + protected void setUp() throws Exception { + super.setUp(); + esymFile = new File(DIR + "/ModelCoverage.ajesym"); + outDir = new File(DIR + "/bin"); + crossRefsFile = new File(outDir.getAbsolutePath() + "/build.ajsym"); + } + + protected void tearDown() throws Exception { + super.tearDown(); + + FileUtil.deleteContents(new File(DIR), ajesymResourceFileFilter); + FileUtil.deleteContents(new File(DIR + "/pkg"), ajesymResourceFileFilter); + + FileUtil.deleteContents(new File(DIR + "/bin")); + (new File(DIR + "/bin")).delete(); + + } + + public FileFilter ajesymResourceFileFilter = new FileFilter() { + public boolean accept(File pathname) { + String name = pathname.getName().toLowerCase(); + return name.endsWith(".ajesym"); + } + }; + + public void testCrossRefsFileGeneration() { + if (crossRefsFile.exists()) + assertTrue(crossRefsFile.delete()); + if (esymFile.exists()) + assertTrue(esymFile.delete()); + String[] args = new String[] { "-d", outDir.getAbsolutePath(), "-crossrefs", "@" + configFile.getAbsolutePath() }; + ajc(dir, args); + + assertFalse(esymFile.exists()); + assertTrue(crossRefsFile.exists()); + } + + public void testEmacssymGeneration() { + if (crossRefsFile.exists()) { + assertTrue(crossRefsFile.delete()); + } + if (esymFile.exists()) + assertTrue(esymFile.delete()); + String[] args = new String[] { "-d", outDir.getAbsolutePath(), "-emacssym", "@" + configFile.getAbsolutePath() }; + ajc(dir, args); + + assertTrue(esymFile.exists()); + assertFalse(crossRefsFile.exists()); + } +} diff --git a/ajde/src/test/java/org/aspectj/ajde/internal/AspectJBuildManagerTest.java b/ajde/src/test/java/org/aspectj/ajde/internal/AspectJBuildManagerTest.java new file mode 100644 index 000000000..41c2aec9f --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/internal/AspectJBuildManagerTest.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.internal; + +import junit.framework.*; +import org.aspectj.ajde.*; +import org.aspectj.asm.AsmManager; + +import java.io.*; + +/** + * @author Mik Kersten + */ +public class AspectJBuildManagerTest extends AjdeTestCase { + + public static TestSuite suite() { + TestSuite result = new TestSuite(); + result.addTestSuite(AspectJBuildManagerTest.class); + return result; + } + + public void testSequence() { + AsmManager.dumpModelPostBuild=true; // or you wont get a .ajsym file + try { + // XXX should fail? empty configs fail b/c no sources specified + initialiseProject("AspectJBuildManagerTest"); + doBuild("empty.lst"); + assertTrue("Expected there to be no error messages from the build but found that" + + " there were some " + getErrorMessages("empty.lst"),getErrorMessages("empty.lst").isEmpty()); + // TODO-path + initialiseProject("figures-coverage"); + doBuild("all.lst"); + assertTrue("Expected there to be no error messages from the build but found that" + + " there were some " + getErrorMessages("empty.lst"),getErrorMessages("empty.lst").isEmpty()); + File file = new File(getCompilerForConfigFileWithName("all.lst").getCompilerConfiguration().getOutputLocationManager().getDefaultOutputLocation() + "/figures/Main.class"); + if (file.exists()) { + file.delete(); + } else { + assertTrue("expected class " + file, false); + } + + // TODO-path + file = openFile("all.ajsym"); + if (file.exists()) { + file.delete(); + } else { + assertTrue("expected .ajsym: " + file, false); + } + } finally { + AsmManager.dumpModelPostBuild=false; + } + } +} diff --git a/ajde/src/test/java/org/aspectj/ajde/internal/LstBuildConfigManagerTest.java b/ajde/src/test/java/org/aspectj/ajde/internal/LstBuildConfigManagerTest.java new file mode 100644 index 000000000..902c34d62 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/internal/LstBuildConfigManagerTest.java @@ -0,0 +1,84 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.internal; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import junit.framework.TestSuite; + +import org.aspectj.ajde.AjdeTestCase; +import org.aspectj.ajde.ui.BuildConfigModel; +import org.aspectj.ajde.ui.utils.TestMessageHandler.TestMessage; + +public class LstBuildConfigManagerTest extends AjdeTestCase { + + private BuildConfigManager buildConfigManager = new LstBuildConfigManager(); + + public static void main(String[] args) { + junit.swingui.TestRunner.run(LstBuildConfigManagerTest.class); + } + + public static TestSuite suite() { + TestSuite result = new TestSuite(); + result.addTestSuite(LstBuildConfigManagerTest.class); + return result; + } + + protected void setUp() throws Exception { + super.setUp(); + initialiseProject("LstBuildConfigManagerTest"); + } + + public void testConfigParserErrorMessages() { + doBuild("dir-entry.lst"); + List messages = getMessages("dir-entry.lst"); + TestMessage message = (TestMessage)messages.get(0); + + assertEquals(message.getContainedMessage().getSourceLocation().getSourceFile().getAbsolutePath(), openFile("dir-entry.lst").getAbsolutePath()); + + doBuild("bad-injar.lst"); + messages = getMessages("bad-injar.lst"); + message = (TestMessage)messages.get(0); + assertTrue(message.getContainedMessage().getMessage().indexOf("skipping missing, empty or corrupt inpath entry") != -1); + } + + public void testErrorMessages() throws IOException { + doBuild("invalid-entry.lst"); + assertFalse("expected there to be error messages because the build failed but didn't" + + " find any", getErrorMessages("invalid-entry.lst").isEmpty()); + + List messages = getMessages("invalid-entry.lst"); + TestMessage message = (TestMessage)messages.get(0); + assertTrue(message.getContainedMessage().getMessage(), message.getContainedMessage().getMessage().indexOf("aaa.bbb") != -1); + + } + + public void testNonExistentConfigFile() throws IOException { + File file = openFile("mumbleDoesNotExist.lst"); + assertTrue("valid non-existing file", !file.exists()); + BuildConfigModel model = buildConfigManager.buildModel(file.getCanonicalPath()); + assertTrue("root: " + model.getRoot(), model.getRoot() != null); + } + + public void testFileRelativePathSameDir() throws IOException { + File file = openFile("file-relPath-sameDir.lst"); + buildConfigManager.buildModel(file.getCanonicalPath()); + assertTrue("single file", true); + } + +} + diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeFileStructureView.java b/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeFileStructureView.java new file mode 100644 index 000000000..40c0b2b92 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeFileStructureView.java @@ -0,0 +1,39 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + + +/** + * @author Mik Kersten + */ +public class NullIdeFileStructureView extends FileStructureView { + + private String sourceFilePath = null; + + public NullIdeFileStructureView(StructureViewProperties viewProperties) { + super(viewProperties); + } + public String getSourceFile() { + return sourceFilePath; + } + + public void setSourceFile(String sourceFile) { + this.sourceFilePath = sourceFile; + } + + public void setRootNode(IStructureViewNode rootNode) { + super.setRootNode(rootNode); + notifyViewUpdated(); + } +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeStructureViewRenderer.java b/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeStructureViewRenderer.java new file mode 100644 index 000000000..81b65dea0 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/NullIdeStructureViewRenderer.java @@ -0,0 +1,44 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + + +/** + * @author Mik Kersten + */ +public class NullIdeStructureViewRenderer implements StructureViewRenderer { + + private boolean hasBeenNotified = false; + + public void updateView(StructureView structureView) { + hasBeenNotified = true; + } + + public void setActiveNode(IStructureViewNode node) { + // ignored + } + + public void setActiveNode(IStructureViewNode node, int lineOffset) { + // ignored + } + + public boolean getHasBeenNotified() { + return hasBeenNotified; + } + + public void setHasBeenNotified(boolean hasBeenNotified) { + this.hasBeenNotified = hasBeenNotified; + } +} + diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/StructureSearchManagerTest.java b/ajde/src/test/java/org/aspectj/ajde/ui/StructureSearchManagerTest.java new file mode 100644 index 000000000..f25262424 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/StructureSearchManagerTest.java @@ -0,0 +1,74 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.util.List; + +import junit.framework.TestSuite; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.AjdeTestCase; +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public class StructureSearchManagerTest extends AjdeTestCase { + + public static void main(String[] args) { + junit.swingui.TestRunner.run(StructureSearchManagerTest.class); + } + + public static TestSuite suite() { + TestSuite result = new TestSuite(); + result.addTestSuite(StructureSearchManagerTest.class); + return result; + } + + public void testFindPatternMatch() { + Ajde.getDefault().getStructureSearchManager().findMatches( + "Point", + null + ); + assertTrue("non existent node", true); + } + + public void testFindPatternAndKindMatch() { + Ajde.getDefault().getStructureSearchManager().findMatches( + "Point", + IProgramElement.Kind.CONSTRUCTOR + ); + assertTrue("non existent node", true); + } + + public void testFindNonExistent() { + List matches = Ajde.getDefault().getStructureSearchManager().findMatches( + "mumbleNodeDesNotExist", + null + ); + assertTrue("non existent", matches.isEmpty()); + } + + protected void setUp() throws Exception { + super.setUp(); + initialiseProject("StructureSearchManagerTest"); + doBuild("all.lst"); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } +} + diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java b/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java new file mode 100644 index 000000000..8e407f48d --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java @@ -0,0 +1,140 @@ +/* ******************************************************************* + * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.io.File; +import java.util.Iterator; + +import junit.framework.TestSuite; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.AjdeTestCase; +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public class StructureViewManagerTest extends AjdeTestCase { + + // TODO-path + private final String CONFIG_FILE_PATH = "all.lst"; + private final String CONFIG_FILE_PATH_2 = "inheritance.lst"; + + private FileStructureView currentView; + private final NullIdeStructureViewRenderer renderer = new NullIdeStructureViewRenderer(); + private File testFile; + private StructureViewProperties properties; + + public static void main(String[] args) { + junit.swingui.TestRunner.run(StructureViewManagerTest.class); + } + + public static TestSuite suite() { + TestSuite result = new TestSuite(); + result.addTestSuite(StructureViewManagerTest.class); + return result; + } + + public void testModelExists() { + assertTrue(Ajde.getDefault().getModel().getHierarchy() != null); + } + + public void testNotificationAfterConfigFileChange() { + initialiseProject("inheritance"); + doBuild(CONFIG_FILE_PATH_2); + renderer.setHasBeenNotified(false); + assertTrue("not yet notified", !renderer.getHasBeenNotified()); + Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(CONFIG_FILE_PATH_2); + assertTrue("notified", renderer.getHasBeenNotified()); + renderer.setHasBeenNotified(false); + Ajde.getDefault().getBuildConfigManager().setActiveConfigFile("MumbleDoesNotExist.lst"); + assertTrue("notified", renderer.getHasBeenNotified()); + + assertTrue("no structure", currentView.getRootNode().getStructureNode().getChildren().get(0) == IHierarchy.NO_STRUCTURE); + } + + /** + * @todo this should be moved to a StructureModelManager test + */ + public void testFreshStructureModelCreation() { + renderer.setHasBeenNotified(false); + String modelPath = genStructureModelExternFilePath(CONFIG_FILE_PATH); + openFile(modelPath).delete(); + + Ajde.getDefault().getModel().readStructureModel(CONFIG_FILE_PATH); + + assertTrue("notified", renderer.getHasBeenNotified()); + // AMC should this be currentView, or should we recreate the root... do the latter + // IProgramElement n = currentView.getRootNode().getIProgramElement(); + IProgramElement n = Ajde.getDefault().getModel().getHierarchy().getRoot(); + assertTrue("no structure", + // currentView.getRootNode().getIProgramElement().getChildren().get(0) + n == IHierarchy.NO_STRUCTURE); + } + + public void testModelIntegrity() { + doBuild(CONFIG_FILE_PATH); + IProgramElement modelRoot = Ajde.getDefault().getModel().getHierarchy().getRoot(); + assertTrue("root exists", modelRoot != null); + + try { + testModelIntegrityHelper(modelRoot); + } catch (Exception e) { + assertTrue(e.toString(), false); + } + } + + private void testModelIntegrityHelper(IProgramElement node) throws Exception { + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + IProgramElement child = (IProgramElement) it.next(); + if (node == child.getParent()) { + testModelIntegrityHelper(child); + } else { + throw new Exception("parent-child check failed for child: " + child.toString()); + } + } + } + + public void testNotificationAfterBuild() { + renderer.setHasBeenNotified(false); + doBuild(CONFIG_FILE_PATH); + assertTrue("notified", renderer.getHasBeenNotified()); + } + + public void testViewCreationWithNullSourceFileAndProperties() { + currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(null, null); + assertTrue("no structure", currentView.getRootNode().getStructureNode() == IHierarchy.NO_STRUCTURE); + } + + protected void setUp() throws Exception { + super.setUp(); + + AsmManager.forceSingletonBehaviour = true; + initialiseProject("figures-coverage"); + doBuild(CONFIG_FILE_PATH); + + properties = Ajde.getDefault().getStructureViewManager().getDefaultViewProperties(); + // TODO-path + testFile = openFile("../examples/figures-coverage/figures/Figure.java"); + currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(testFile.getAbsolutePath(), properties); + currentView.setRenderer(renderer); + } + + protected void tearDown() throws Exception { + super.tearDown(); + AsmManager.forceSingletonBehaviour = false; + } +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java new file mode 100644 index 000000000..935dcc363 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java @@ -0,0 +1,96 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.core.IBuildProgressMonitor; + +/** + * Test implementation of IBuildProgressMonitor which prints out + * progress to the console and enables users to cancel the build process + * after a specified string has been printed. + */ +public class TestBuildProgressMonitor implements IBuildProgressMonitor { + + private static boolean debugTests = false; + + public int numWovenClassMessages = 0; + public int numWovenAspectMessages = 0; + public int numCompiledMessages = 0; + + private String programmableString; + private int count; + private List messagesReceived = new ArrayList(); + private int currentVal; + private boolean isCancelRequested = false; + + public void finish(boolean wasFullBuild) { + System.out.println("build finished. Was full build: " + wasFullBuild); + } + + public boolean isCancelRequested() { + return isCancelRequested; + } + + public void setProgress(double percentDone) { + System.out.println("progress. Completed " + percentDone + " percent"); + } + + public void setProgressText(String text) { + System.out.println("progress text: " + text); + String newText = text+" [Percentage="+currentVal+"%]"; + messagesReceived.add(newText); + if (text.startsWith("woven aspect ")) numWovenAspectMessages++; + if (text.startsWith("woven class ")) numWovenClassMessages++; + if (text.startsWith("compiled:")) numCompiledMessages++; + if (programmableString != null + && text.indexOf(programmableString) != -1) { + count--; + if (count==0) { + if (debugTests) System.out.println("Just got message '"+newText+"' - asking build to cancel"); + isCancelRequested = true; + programmableString = null; + } + } + } + + public void begin() { + System.out.println("build started"); + currentVal = 0; + } + + // ------------- methods to help with testing ------------- + public void cancelOn(String string,int count) { + programmableString = string; + this.count = count; + } + + public boolean containsMessage(String prefix,String distinguishingMarks) { + for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + if (element.startsWith(prefix) && + element.indexOf(distinguishingMarks)!=-1) return true; + } + return false; + } + + public void dumpMessages() { + System.out.println("ProgressMonitorMessages"); + for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + System.out.println(element); + } + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java new file mode 100644 index 000000000..69e5ea9d9 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java @@ -0,0 +1,200 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.aspectj.ajde.core.ICompilerConfiguration; +import org.aspectj.ajde.core.IOutputLocationManager; +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.tools.ajc.AjcTests; +import org.aspectj.util.FileUtil; +import org.aspectj.util.LangUtil; + +/** + * Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null + * for all options except getClasspath(), getJavaOptionsMap() (by default returns that it's 1.3 compliant), + * getOutputLocationManager(), getSourcePathResources() (it recursively looks for them) and getProjectSourceFiles(). If no source + * files are specified by the user, then getProjectSourceFiles() returns an empty list. + */ +public class TestCompilerConfiguration implements ICompilerConfiguration { + + private String projectPath; + + private Set aspectpath; + private Set inpath; + private String outjar; + private Map<String,String> javaOptions; + private String nonStandardOptions; + private List projectSourceFiles = new ArrayList(); + private Map sourcePathResources; + + private String srcDirName = "src"; + + private IOutputLocationManager outputLoc; + + public TestCompilerConfiguration(String projectPath) { + this.projectPath = projectPath; + } + + public void configurationRead() { + } + + public List getProjectXmlConfigFiles() { + return Collections.EMPTY_LIST; + } + + public Set getAspectPath() { + return aspectpath; + } + + public String getClasspath() { + String cp = projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator + + AjcTests.aspectjrtClasspath(); + if (LangUtil.is19VMOrGreater()) { + cp = LangUtil.getJrtFsFilePath()+File.pathSeparator+cp; + } + return cp; + } + + public Set getInpath() { + return inpath; + } + + public Map<String,String> getJavaOptionsMap() { + if (javaOptions == null) { + javaOptions = new Hashtable<>(); + javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13); + javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13); + } + return javaOptions; + } + + public String getNonStandardOptions() { + return nonStandardOptions; + } + + public String getOutJar() { + return outjar; + } + + public IOutputLocationManager getOutputLocationManager() { + if (outputLoc == null) { + outputLoc = new TestOutputLocationManager(projectPath); + } + return outputLoc; + } + + public List getProjectSourceFiles() { + return projectSourceFiles; + } + + public List getProjectSourceFilesChanged() { + return null; + } + + public Map getSourcePathResources() { + if (sourcePathResources == null) { + sourcePathResources = new HashMap(); + + /* Allow the user to override the testProjectPath by using sourceRoots */ + File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; + + for (int j = 0; j < srcBase.length; j++) { + File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() { + public boolean accept(File pathname) { + String name = pathname.getName().toLowerCase(); + return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") + && !name.endsWith(".lst") && !name.endsWith(".jar"); + } + }); + for (int i = 0; i < fromResources.length; i++) { + String normPath = FileUtil.normalizedPath(fromResources[i], srcBase[j]); + sourcePathResources.put(normPath, fromResources[i]); + + } + } + } + return sourcePathResources; + } + + // -------------------- setter methods useful for testing --------------- + public void setAspectPath(Set aspectPath) { + this.aspectpath = aspectPath; + } + + public void setInpath(Set inpath) { + this.inpath = inpath; + } + + public void setOutjar(String outjar) { + this.outjar = outjar; + } + + public void setJavaOptions(Map javaOptions) { + this.javaOptions = javaOptions; + } + + public void setNonStandardOptions(String options) { + this.nonStandardOptions = options; + } + + public void setProjectSourceFiles(List projectSourceFiles) { + this.projectSourceFiles = projectSourceFiles; + } + + public void setSourcePathResources(Map sourcePathResources) { + this.sourcePathResources = sourcePathResources; + } + + public void setSourceDir(String srcDirName) { + this.srcDirName = srcDirName; + } + + public int getConfigurationChanges() { + return ICompilerConfiguration.EVERYTHING; + } + + public List getClasspathElementsWithModifiedContents() { + return null; + } + + public String getProjectEncoding() { + return null; + } + + public String getProcessor() { + return null; + } + + public String getProcessorPath() { + return null; + } + + @Override + public String getModulepath() { + return null; + } + + @Override + public String getModuleSourcepath() { + return null; + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestEditorAdapter.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestEditorAdapter.java new file mode 100644 index 000000000..6c94e7f33 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestEditorAdapter.java @@ -0,0 +1,48 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.IOException; +import java.util.List; + +import org.aspectj.ajde.EditorAdapter; +import org.aspectj.bridge.ISourceLocation; + +/** + * EditorAdapter with empty implementation + */ +public class TestEditorAdapter implements EditorAdapter { + + public String getCurrFile() { + return null; + } + + public void pasteToCaretPos(String text) { + } + + public void saveContents() throws IOException { + } + + public void showSourceLine(String filePath, int lineNumber, + boolean highlight) { + } + + public void showSourceLine(ISourceLocation sourceLocation, boolean highlight) { + } + + public void showSourceLine(int lineNumber, boolean highlight) { + } + + public void showSourcelineAnnotation(String filePath, int lineNumber, + List items) { + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java new file mode 100644 index 000000000..2bc23ec60 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java @@ -0,0 +1,23 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import org.aspectj.ajde.IdeUIAdapter; + +/** + * IdeUIAdapter with empty implementation + */ +public class TestIdeUIAdapter implements IdeUIAdapter { + + public void displayStatusInformation(String message) { + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestMessageHandler.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestMessageHandler.java new file mode 100644 index 000000000..8901b02f4 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestMessageHandler.java @@ -0,0 +1,112 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.ajde.IUIBuildMessageHandler; +import org.aspectj.bridge.AbortException; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessage.Kind; + +/** + * Test implementation of IBuildMessageHandler. By default it + * ignores INFO and WEAVEINFO messages. Stores all messages it's + * not ignoring in an ArrayList and ERRORS and ABORTS also in + * a separate ArrayList enabling users to query whether anything + * went wrong with the build. + */ +public class TestMessageHandler implements IUIBuildMessageHandler { + + private List ignoring; + private List messages; + private List errors; + + public TestMessageHandler() { + ignoring = new ArrayList(); + messages = new ArrayList(); + errors = new ArrayList(); + ignore(IMessage.INFO); + ignore(IMessage.WEAVEINFO); + } + + public boolean handleMessage(IMessage message) throws AbortException { + IMessage.Kind kind = message.getKind(); + if (isIgnoring(kind)) { + return true; + } + TestMessage t = new TestMessage(message); + messages.add(t); + if (kind.equals(IMessage.ABORT) || message.getThrown() != null) { + System.err.println("> AjCompiler error: "+message.getMessage()); //$NON-NLS-1$ + message.getThrown().printStackTrace(); + errors.add(t); + } else if (kind.equals(IMessage.ERROR)) { + errors.add(t); + } + System.out.println("> "+message); //$NON-NLS-1$ + return true; + } + + public void dontIgnore(Kind kind) { + if (null != kind) { + ignoring.remove(kind); + } + } + + public boolean isIgnoring(Kind kind) { + return ((null != kind) && (ignoring.contains(kind))); + } + + public void ignore(Kind kind) { + if ((null != kind) && (!ignoring.contains(kind))) { + ignoring.add(kind); + } + } + + public List getMessages() { + return messages; + } + + public List getErrors() { + return errors; + } + + public static class TestMessage { + IMessage message; + + public TestMessage(IMessage m) { + message = m; + } + + public IMessage getContainedMessage() { + return message; + } + + public String toString() { + String loc = "<no location>"; + if (null != message.getSourceLocation()) { + loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine(); + } + return "TestMessage [" + message.getMessage() + + ", " + loc + + ", " + message.getKind() + + "]"; + } + } + + public void reset() { + messages.clear(); + errors.clear(); + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java new file mode 100644 index 000000000..157f3ecd4 --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java @@ -0,0 +1,104 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.aspectj.ajde.core.IOutputLocationManager; + +/** + * Test implementation of IOutputLocationManager. By default returns the same location for both resources and classes, however, + * setter methods enable the user to specify different location for these. Note that the user is unable to specify different output + * location for different class files. + */ +public class TestOutputLocationManager implements IOutputLocationManager { + + private String testProjectOutputPath; + private File classOutputLoc; + private File resourceOutputLoc; + private List allOutputLocations; + + public TestOutputLocationManager(String testProjectPath) { + this.testProjectOutputPath = testProjectPath + File.separator + "bin"; + } + + public void reportFileWrite(String outputfile, int filetype) { + } + + public String getUniqueIdentifier() { + return testProjectOutputPath; + } + + public Map getInpathMap() { + return Collections.EMPTY_MAP; + } + + public File getOutputLocationForClass(File compilationUnit) { + initLocations(); + return classOutputLoc; + } + + public File getOutputLocationForResource(File resource) { + initLocations(); + return resourceOutputLoc; + } + + // -------------- setter methods useful for testing ------------- + public void setOutputLocForClass(File f) { + classOutputLoc = f; + } + + public void setOutputLocForResource(File f) { + resourceOutputLoc = f; + } + + public List getAllOutputLocations() { + if (allOutputLocations == null) { + allOutputLocations = new ArrayList(); + initLocations(); + allOutputLocations.add(classOutputLoc); + if (!classOutputLoc.equals(resourceOutputLoc)) { + allOutputLocations.add(resourceOutputLoc); + } + } + return allOutputLocations; + } + + public File getDefaultOutputLocation() { + return classOutputLoc; + } + + private void initLocations() { + if (classOutputLoc == null) { + classOutputLoc = new File(testProjectOutputPath); + } + if (resourceOutputLoc == null) { + resourceOutputLoc = new File(testProjectOutputPath); + } + } + + public String getSourceFolderForFile(File sourceFile) { + return null; + } + + public void reportFileRemove(String outputfile, int filetype) { + } + + public int discoverChangesSince(File dir, long buildtime) { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java new file mode 100644 index 000000000..a9e923e2a --- /dev/null +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java @@ -0,0 +1,28 @@ +/******************************************************************** + * Copyright (c) 2007 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: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.utils; + +import org.aspectj.ajde.IRuntimeProperties; + +/** + * IRuntimeProperties with empty implementation + */ +public class TestRuntimeProperties implements IRuntimeProperties { + + public String getClassToExecute() { + return null; + } + + public String getExecutionArgs() { + return null; + } + +} |