Search in sources :

Example 1 with SystemObserver

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;
}
Also used : DebugUtils.getDebugger(org.absmodels.abs.plugin.debug.DebugUtils.getDebugger) SystemObserver(abs.backend.java.observing.SystemObserver)

Example 2 with SystemObserver

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();
    }
}
Also used : COGView(abs.backend.java.observing.COGView) SystemObserver(abs.backend.java.observing.SystemObserver) JavaCode(abs.backend.java.codegeneration.JavaCode) ObjectView(abs.backend.java.observing.ObjectView) JavaCodeGenerationException(abs.backend.java.codegeneration.JavaCodeGenerationException) ABSException(abs.backend.java.lib.runtime.ABSException) ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime) ABSException(abs.backend.java.lib.runtime.ABSException)

Aggregations

SystemObserver (abs.backend.java.observing.SystemObserver)2 JavaCode (abs.backend.java.codegeneration.JavaCode)1 JavaCodeGenerationException (abs.backend.java.codegeneration.JavaCodeGenerationException)1 ABSException (abs.backend.java.lib.runtime.ABSException)1 ABSRuntime (abs.backend.java.lib.runtime.ABSRuntime)1 COGView (abs.backend.java.observing.COGView)1 ObjectView (abs.backend.java.observing.ObjectView)1 DebugUtils.getDebugger (org.absmodels.abs.plugin.debug.DebugUtils.getDebugger)1