diff options
author | aclement <aclement> | 2007-01-15 09:37:23 +0000 |
---|---|---|
committer | aclement <aclement> | 2007-01-15 09:37:23 +0000 |
commit | 8559a350a486171c332791c8364d857a074531e0 (patch) | |
tree | 9fea02d68204d89bb16c1abb162b02338abfc9d7 /ajde/testsrc/org/aspectj | |
parent | fb86dd4ca2edac7e1eb639cfde1d4b2a4f450457 (diff) | |
download | aspectj-8559a350a486171c332791c8364d857a074531e0.tar.gz aspectj-8559a350a486171c332791c8364d857a074531e0.zip |
148190#35
Diffstat (limited to 'ajde/testsrc/org/aspectj')
9 files changed, 640 insertions, 13 deletions
diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeCompilerTests.java b/ajde/testsrc/org/aspectj/ajde/AjdeCompilerTests.java new file mode 100644 index 000000000..0d9d6d68d --- /dev/null +++ b/ajde/testsrc/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/testsrc/org/aspectj/ajde/AjdeTestCase.java b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java index b6d9cf02c..ea70c88c0 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java @@ -62,9 +62,16 @@ public class AjdeTestCase extends TestCase { */ 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(projectName), + new TestCompilerConfiguration(projectDir), new TestMessageHandler(), new TestBuildProgressMonitor(), new TestEditorAdapter(), @@ -73,18 +80,6 @@ public class AjdeTestCase extends TestCase { new JFrame(), new TestRuntimeProperties(), true); - - 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(); - -// compiler = new AjCompiler( -// projectDir, -// new TestCompilerConfiguration(projectDir), -// new TestBuildProgressMonitor(), -// new TestMessageHandler()); } /** diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java new file mode 100644 index 000000000..935dcc363 --- /dev/null +++ b/ajde/testsrc/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/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java new file mode 100644 index 000000000..85e14fc5b --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java @@ -0,0 +1,163 @@ +/******************************************************************** + * 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.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; + +/** + * 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 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 Set getAspectPath() { + return aspectpath; + } + + public String getClasspath() { + return projectPath + + File.pathSeparator + + System.getProperty("sun.boot.class.path") + + File.pathSeparator + + AjcTests.aspectjrtClasspath(); + } + + public Set getInpath() { + return inpath; + } + + public Map 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 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; + } + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestEditorAdapter.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestEditorAdapter.java new file mode 100644 index 000000000..6c94e7f33 --- /dev/null +++ b/ajde/testsrc/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/testsrc/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestIdeUIAdapter.java new file mode 100644 index 000000000..2bc23ec60 --- /dev/null +++ b/ajde/testsrc/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/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java new file mode 100644 index 000000000..8901b02f4 --- /dev/null +++ b/ajde/testsrc/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/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java new file mode 100644 index 000000000..eede163d8 --- /dev/null +++ b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestOutputLocationManager.java @@ -0,0 +1,86 @@ +/******************************************************************** + * 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.List; + +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 String getUniqueIdentifier() { + return testProjectOutputPath; + } + + 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); + } + } + + +} diff --git a/ajde/testsrc/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java b/ajde/testsrc/org/aspectj/ajde/ui/utils/TestRuntimeProperties.java new file mode 100644 index 000000000..a9e923e2a --- /dev/null +++ b/ajde/testsrc/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; + } + +} |