Browse Source

148190#30: rebase tests

tags/Root_extensions
aclement 17 years ago
parent
commit
df061d470f

+ 1
- 0
testing/.classpath View File

@@ -21,5 +21,6 @@
<classpathentry kind="src" path="/org.aspectj.ajdt.core"/>
<classpathentry combineaccessrules="false" kind="src" path="/weaver"/>
<classpathentry combineaccessrules="false" kind="src" path="/loadtime"/>
<classpathentry combineaccessrules="false" kind="src" path="/ajde.core"/>
<classpathentry kind="output" path="bin"/>
</classpath>

+ 125
- 196
testing/src/org/aspectj/testing/ajde/CompileCommand.java View File

@@ -7,23 +7,37 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wes Isberg initial implementation
* Wes Isberg initial implementation
* Helen Hawkins Converted to new interface (bug 148190)
* ******************************************************************/

package org.aspectj.testing.ajde;

import java.awt.Frame;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.aspectj.ajde.core.AjCompiler;
import org.aspectj.ajde.core.IBuildMessageHandler;
import org.aspectj.ajde.core.IBuildProgressMonitor;
import org.aspectj.ajde.core.ICompilerConfiguration;
import org.aspectj.ajde.core.IOutputLocationManager;
import org.aspectj.ajde.core.JavaOptions;
import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.ICommand;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.MessageHandler;
import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.testing.harness.bridge.Globals;
import org.aspectj.ajde.*;
import org.aspectj.ajde.ui.*;
import org.aspectj.ajde.ui.internal.*;
import org.aspectj.ajde.ui.swing.*;
import org.aspectj.asm.*;
import org.aspectj.bridge.*;
import org.aspectj.util.FileUtil;

/**
@@ -37,10 +51,12 @@ public class CompileCommand implements ICommand {
// this proxy ignores calls
InvocationHandler proxy = new VoidInvocationHandler();
InvocationHandler loggingProxy = new LoggingInvocationHandler();
MyTaskListManager myHandler = new MyTaskListManager();
MyMessageHandler myHandler = new MyMessageHandler();
long endTime;
boolean buildNextFresh;
File tempDir;
private AjCompiler compiler;

/**
* Clients call this before repeatCommand as a one-shot
@@ -57,11 +73,8 @@ public class CompileCommand implements ICommand {
myHandler.start();
long startTime = System.currentTimeMillis();
try {
Ajde.getDefault().getBuildManager().buildFresh();
// System.err.println("compiling " + Arrays.asList(args));
waitForCompletion(startTime);
compiler.buildFresh();
} finally {
myHandler.finish(handler);
runCommandCleanup();
}
return !myHandler.hasError();
@@ -73,12 +86,10 @@ public class CompileCommand implements ICommand {
// System.err.println("recompiling...");
if (buildNextFresh) {
buildNextFresh = false;
Ajde.getDefault().getBuildManager().buildFresh();
compiler.buildFresh();
} else {
Ajde.getDefault().getBuildManager().build();
compiler.build();
}
waitForCompletion(startTime);
myHandler.finish(handler);
return !myHandler.hasError();
}
void runCommandCleanup() {
@@ -92,33 +103,13 @@ public class CompileCommand implements ICommand {
void setEndTime(long endTime) {
this.endTime = endTime;
}

private void waitForCompletion(long startTime) {
long maxTime = startTime + MAX_TIME;
while ((startTime > endTime)
&& (maxTime > System.currentTimeMillis())) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}

private void setup(String[] args) {
File config = writeConfig(args);
if (null == config) {
throw new Error("unable to write config file");
}
EditorAdapter editorAdapter =
(EditorAdapter) makeProxy(EditorAdapter.class);
TaskListManager taskListManager = myHandler;
BuildProgressMonitor buildProgressMonitor =
new DefaultBuildProgressMonitor(new Frame()) {
public void finish(boolean b) {
super.finish(b);
setEndTime(System.currentTimeMillis());
}
};
IBuildProgressMonitor buildProgressMonitor = new MyBuildProgressMonitor();
String classesDir = "../testing/bin/classes";
for (int i = 0; i < args.length; i++) {
if ("-d".equals(args[i]) && ((1 +i) < args.length)) {
@@ -126,56 +117,8 @@ public class CompileCommand implements ICommand {
break;
}
}

ProjectPropertiesAdapter projectPropertiesAdapter =
new ProjectProperties(classesDir);
// neither of these are in the true classpath
// new NullIdeProperties(""); // in testsrc
// = new BrowserProperties(); // in ajbrowser
BuildOptionsAdapter buildOptionsAdapter =
new AjcBuildOptions(new UserPreferencesStore(false));
IdeUIAdapter ideUIAdapter =
(IdeUIAdapter) makeProxy(IdeUIAdapter.class);
ErrorHandler errorHandler =
(ErrorHandler) makeProxy(ErrorHandler.class);

AbstractIconRegistry iconRegistry = new AbstractIconRegistry() {
protected AbstractIcon createIcon(String path) {
return new AbstractIcon(new Object());
}
};
StructureViewNodeFactory structureViewNodeFactory =
new StructureViewNodeFactory(iconRegistry) {
protected IStructureViewNode createDeclaration(
IProgramElement node,
AbstractIcon icon,
List children) {
return new SwingTreeViewNode(node, icon, children);
}
protected IStructureViewNode createRelationship(
IRelationship node,
AbstractIcon icon) {
return new SwingTreeViewNode(node, icon);
}
protected IStructureViewNode createLink(
IProgramElement node,
AbstractIcon icon) {
return new SwingTreeViewNode(node, icon);
}
};

Ajde.init(
editorAdapter,
taskListManager,
buildProgressMonitor,
projectPropertiesAdapter,
buildOptionsAdapter,
structureViewNodeFactory,
ideUIAdapter,
errorHandler);

Ajde.getDefault().getConfigurationManager().setActiveConfigFile(
config.getAbsolutePath());
MyCompilerConfig compilerConfig = new MyCompilerConfig();
compiler = new AjCompiler("blah",compilerConfig,buildProgressMonitor,myHandler);
}

private File writeConfig(String[] args) {
@@ -214,61 +157,18 @@ public class CompileCommand implements ICommand {
}
}

class MyTaskListManager
extends MessageHandler
implements TaskListManager {
class MyMessageHandler implements IBuildMessageHandler {

boolean hasError;
boolean hasWarning;
MyTaskListManager() {
super(true);
}
public void addProjectTask(String message, IMessage.Kind kind) {
maintainHasWarning(kind);
}

public void addSourcelineTask(IMessage message) {
maintainHasWarning(message.getKind());
handleMessage(message);
}

public void addSourcelineTask(
String message,
ISourceLocation sourceLocation,
IMessage.Kind kind) {
addSourcelineTask(
new Message(message, kind, null, sourceLocation));
}

public void clearTasks() {
if (hasWarning) {
hasWarning = false;
}
if (hasError) {
hasError = false;
}
init(true);
}

public boolean hasWarning() {
return hasWarning;
}

boolean hasError() {
return hasError;
}
private MessageHandler messageHandler = new MessageHandler(false);

void start() {
clearTasks();
}
void finish(IMessageHandler copyTo) {
if (copyTo == this) {
return;
}
IMessage[] messages = getMessages(null, true);
for (int i = 0; i < messages.length; i++) {
copyTo.handleMessage(messages[i]);
}
}
public boolean handleMessage(IMessage message) throws AbortException {
maintainHasWarning(message.getKind());
return messageHandler.handleMessage(message);
}
private void maintainHasWarning(IMessage.Kind kind) {
if (!hasError) {
if (IMessage.ERROR.isSameOrLessThan(kind)) {
@@ -280,10 +180,53 @@ class MyTaskListManager
hasWarning = true;
}
}
public void buildSuccessful(boolean wasFullBuild) {
// TODO Auto-generated method stub
public boolean hasWarning() {
return hasWarning;
}

public boolean hasError() {
return hasError;
}
public void start() {
hasWarning = false;
hasError = false;
messageHandler.init(true);
}

public void dontIgnore(Kind kind) {
messageHandler.dontIgnore(kind);
}

public void ignore(Kind kind) {
messageHandler.ignore(kind);
}

public boolean isIgnoring(Kind kind) {
return messageHandler.isIgnoring(kind);
}
}

class MyBuildProgressMonitor implements IBuildProgressMonitor {

public void begin() {
}

public void finish(boolean wasFullBuild) {
}

public boolean isCancelRequested() {
return false;
}

public void setProgress(double percentDone) {
}

public void setProgressText(String text) {
}
}

class VoidInvocationHandler implements InvocationHandler {
@@ -349,63 +292,49 @@ class LoggingInvocationHandler implements InvocationHandler {
}
}

class MyCompilerConfig implements ICompilerConfiguration {

class ProjectProperties implements ProjectPropertiesAdapter {
final private static String PREFIX
= ProjectProperties.class.getName() + ": ";
final private String outputDir;
private Set inJars;
private Set inpath;
private Set sourceRoots;
private Set aspectPath;
private String outJar;
private IOutputLocationManager locationMgr;
public Set getAspectPath() { return aspectPath;}
public void setAspectPath(Set path) {aspectPath = path;}
public String getClasspath() { return Globals.S_aspectjrt_jar; }

public ProjectProperties(String outputDir) {
this.outputDir = outputDir;
}

// known used, per logging proxy
public String getDefaultBuildConfigFile() { return null; }
public void setInJars(Set input) { inJars = input; }
public Set getInpath() { return inpath; }
public void setInpath(Set input) { inpath = input; }
public Set getInJars( ) { return inJars; }
public Set getInpath() { return inpath; }
public void setSourceRoots(Set input) { sourceRoots = input; }
public Set getSourceRoots() { return sourceRoots; }
public void setAspectPath(Set path) { aspectPath = path; }
public Set getAspectPath() { return aspectPath; }
public String getClasspath() { return Globals.S_aspectjrt_jar; }
public String getBootClasspath() { return null; }
public void setOutJar(String input){ outJar = input; }
public String getOutJar() { return outJar; }
public String getOutputPath() { return outputDir; }
public OutputLocationManager getOutputLocationManager() {
return null;
}
public Map getJavaOptionsMap() {return JavaOptions.getDefaultJavaOptions();}

// not known if used - log any calls to it
public List getBuildConfigFiles() { return logs("buildConfigFiles"); }
public String getLastActiveBuildConfigFile() { return log("lastActiveBuildConfigFile"); }
public String getProjectName() { return log("projectName"); }
public String getRootProjectDir() { return log("rootProjectDir"); }
public List getProjectSourceFiles() { return logs("projectSourceFiles"); }
public String getProjectSourcePath() { return log("projectSourcePath"); }
public String getAjcWorkingDir() { return log("ajcWorkingDir"); }
public String getClassToExecute() { return log("classToExecute"); }
public String getExecutionArgs() { return log("executionArgs"); }
public String getVmArgs() { return log("vmArgs"); }
private String log(String s) {
System.out.println(PREFIX + s);
return null;
}
private List logs(String s) {
log(s);
return null;
}
public String getOutJar() { return outJar; }
public void setOutJar(String input){ outJar = input; }

public Map getSourcePathResources() {
return null;
public IOutputLocationManager getOutputLocationManager() {
if (locationMgr == null) {
locationMgr = new MyOutputLocationManager();
}
return locationMgr;
}

public String getNonStandardOptions() {return null;}
public List getProjectSourceFiles() {return null;}
public Map getSourcePathResources() {return null;}
}

class MyOutputLocationManager implements IOutputLocationManager {

public List getAllOutputLocations() {return null;}

public File getDefaultOutputLocation() {return null;}

public File getOutputLocationForClass(File compilationUnit) {return null;}

public File getOutputLocationForResource(File resource) {return null;}

public String getUniqueIdentifier() {return null;}
}

+ 8
- 0
testing/testdata/figures-coverage/all.lst View File

@@ -0,0 +1,8 @@
figures/Debug.java
figures/Figure.java
figures/FigureElement.java
figures/Main.java
figures/composites/Line.java
figures/composites/Square.java
figures/primitives/planar/Point.java
figures/primitives/solid/SolidPoint.java

+ 7
- 0
testing/testdata/figures-coverage/figures/Debug.java View File

@@ -0,0 +1,7 @@

package figures;

aspect Debug {

}


+ 56
- 0
testing/testdata/figures-coverage/figures/Main.java View File

@@ -0,0 +1,56 @@

package figures;

import figures.primitives.planar.Point;
import figures.primitives.solid.SolidPoint;

class Main {

private static Point startPoint;

public static void main(String[] args) {
try {
System.out.println("> starting...");

startPoint = makeStartPoint();
//startPoint.setX(3); new Point(0, 0);
// SolidPoint sp1 = new SolidPoint(1, 3, 3);

// sp1.setZ(1);
// p1.incrXY(3, 3);
} catch (RuntimeException re) {
re.printStackTrace();
}
System.out.println("> finished.");
}

/** @deprecated use something else */
public static Point makeStartPoint() {
//return new Point(1, 2);
return null;
}

/** This should produce a deprecation warning with JDK > 1.2 */
static class TestGUI extends javax.swing.JFrame {
TestGUI() {
this.disable();
}
}

/** This should produce a porting-deprecation warning. */
//static pointcut mainExecution(): execution(void main(*));
}

privileged aspect Test {
pointcut testptct(): call(* *.*(..));

before(Point p, int newval): target(p) && set(int Point.xx) && args(newval) {
System.err.println("> new value of x is: " + p.x + ", setting to: " + newval);
}

before(int newValue): set(int Point.*) && args(newValue) {
if (newValue < 0) {
throw new IllegalArgumentException("too small");
}
}
}

+ 6
- 0
testing/testdata/figures-coverage/figures/composites/Line.java View File

@@ -0,0 +1,6 @@

package figures.composites;

class Line { }

class BoundedLine extends Line { }

+ 6
- 0
testing/testdata/figures-coverage/figures/composites/Square.java View File

@@ -0,0 +1,6 @@

package figures.composites;

class Square {
private String name = "Square";
}

+ 22
- 12
testing/testsrc/org/aspectj/testing/util/StructureModelUtilTest.java View File

@@ -7,30 +7,37 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Xerox/PARC initial implementation
* Xerox/PARC initial implementation
* Helen Hawkins Converted to new interface (bug 148190)
* ******************************************************************/


package org.aspectj.testing.util;

import java.util.*;
import java.io.File;
import java.util.List;

import junit.framework.TestSuite;

import org.aspectj.ajde.AjdeTestCase;
import org.aspectj.ajde.core.AjdeCoreTestCase;
import org.aspectj.ajde.core.TestCompilerConfiguration;
import org.aspectj.asm.IProgramElement;

/**
* @author Mik Kersten
*/
public class StructureModelUtilTest extends AjdeTestCase {
public class StructureModelUtilTest extends AjdeCoreTestCase{
// TODO-path
private final String CONFIG_FILE_PATH = "../examples/figures-coverage/all.lst";

public StructureModelUtilTest(String name) {
super(name);
}
private String[] files = new String[]{
"figures" + File.separator + "Debug.java",
"figures" + File.separator + "Figure.java",
"figures" + File.separator + "FigureElement.java",
"figures" + File.separator + "Main.java",
"figures" + File.separator + "composites" + File.separator + "Line.java",
"figures" + File.separator + "composites" + File.separator + "Square.java",
"figures" + File.separator + "primitives" + File.separator + "planar" + File.separator + "Point.java",
"figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java"
};

public static void main(String[] args) {
junit.swingui.TestRunner.run(StructureModelUtilTest.class);
@@ -66,8 +73,11 @@ public class StructureModelUtilTest extends AjdeTestCase {

protected void setUp() throws Exception {
super.setUp("StructureModelUtilTest");
doSynchronousBuild(CONFIG_FILE_PATH);
initialiseProject("figures-coverage");
TestCompilerConfiguration compilerConfig = (TestCompilerConfiguration) getCompiler()
.getCompilerConfiguration();
compilerConfig.setProjectSourceFiles(getSourceFileList(files));
doBuild();
}

protected void tearDown() throws Exception {

Loading…
Cancel
Save