use of abs.backend.java.observing.SystemObserver in project abstools by abstools.
the class Debugger method addSystemObservers.
private static boolean addSystemObservers(String debuggerArgsSystemObserver, final ABSRuntime r) {
boolean useThisSystemObserver = false;
if (debuggerArgsSystemObserver != null && !debuggerArgsSystemObserver.isEmpty()) {
String systemObserverArgs = debuggerArgsSystemObserver.replaceFirst("-Dabs.systemobserver=", "");
String[] systemObservers = systemObserverArgs.split(",");
for (String observer : systemObservers) {
if (!observer.isEmpty()) {
try {
Class<?> c = Class.forName(observer);
Object o = c.newInstance();
SystemObserver so = (SystemObserver) o;
if (so instanceof Debugger) {
useThisSystemObserver = true;
} else {
r.addSystemObserver(so);
}
// FIXME do not close eclipse
} catch (ClassNotFoundException e) {
// skip
e.printStackTrace();
} catch (InstantiationException e) {
// skip
e.printStackTrace();
} catch (IllegalAccessException e) {
// skip
e.printStackTrace();
}
}
}
}
return useThisSystemObserver;
}
use of abs.backend.java.observing.SystemObserver in project abstools by abstools.
the class JavaBackendTest method assertValidJavaExecution.
void assertValidJavaExecution(boolean withStdLib, String... codeLines) throws Exception {
StringBuilder absCode = new StringBuilder();
for (String line : codeLines) {
absCode.append(line);
absCode.append("\n");
}
JavaCode javaCode = getJavaCode(absCode.toString(), withStdLib ? Config.WITH_STD_LIB : null);
try {
String genDir = javaCode.getSrcDir().getAbsolutePath() + "/gen/test";
javaCode.compile("-classpath", "bin", "-d", genDir);
final ABSRuntime r = makeAbsRuntime();
r.enableDebugging(true);
final boolean[] finished = new boolean[] { false };
final List<ABSException> exceptions = Collections.synchronizedList(new ArrayList<ABSException>());
r.addSystemObserver(new SystemObserver() {
@Override
public void systemStarted() {
}
@Override
public void systemFinished() {
synchronized (finished) {
finished[0] = true;
finished.notifyAll();
}
}
@Override
public void systemError(ABSException e) {
exceptions.add(e);
}
@Override
public void newCOGCreated(COGView cog, ObjectView initialObject) {
}
});
r.start(new File(genDir), "Test.Main");
while (!finished[0]) {
synchronized (finished) {
finished.wait(100);
}
}
r.shutdown();
for (ABSException e : exceptions) {
throw e;
}
} catch (Exception e) {
System.out.println(javaCode);
throw e;
} finally {
javaCode.deleteCode();
}
}
Aggregations