Search in sources :

Example 1 with Debugger

use of org.develnext.jphp.debug.impl.Debugger in project jphp by jphp-compiler.

the class DebugExtension method onRegister.

@Override
public void onRegister(final CompileScope scope) {
    if (scope.isDebugMode()) {
        String debugIdeKey = "JPHP_DEBUGGER";
        if (scope.configuration.containsKey("debug.ideKey")) {
            debugIdeKey = scope.configuration.get("debug.ideKey").toString();
        }
        String debugRootPath = "./src/";
        if (scope.configuration.containsKey("debug.rootPath")) {
            debugRootPath = scope.configuration.get("debug.rootPath").toString();
        }
        int debugPort = 9000;
        if (scope.configuration.containsKey("debug.port")) {
            debugPort = scope.configuration.get("debug.port").toInteger();
        }
        String debugHost = "127.0.0.1";
        if (scope.configuration.containsKey("debug.host")) {
            debugHost = scope.configuration.get("debug.host").toString();
        }
        final String finalDebugIdeKey = debugIdeKey;
        final String finalDebugRootPath = debugRootPath;
        final int finalDebugPort = debugPort;
        final DebugTickHandler tickHandler = new DebugTickHandler();
        scope.setTickHandler(tickHandler);
        final String finalDebugHost = debugHost;
        Thread debuggerThread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    final Debugger debugger = new Debugger(finalDebugPort, finalDebugHost);
                    scope.registerProgramShutdownHandler(new ProgramShutdownHandler() {

                        @Override
                        public void onShutdown(CompileScope scope, Environment env) {
                            debugger.shutdown();
                        }
                    });
                    if (debugger.isWorking()) {
                        debugger.setIdeKey(finalDebugIdeKey);
                        debugger.setRootPath(finalDebugRootPath);
                        debugger.run();
                    }
                    tickHandler.setDebugger(debugger);
                } catch (IOException e) {
                    throw new DebuggerException(e);
                }
            }
        });
        debuggerThread.setName("jphpDebuggerThread");
        debuggerThread.start();
    }
}
Also used : Debugger(org.develnext.jphp.debug.impl.Debugger) ProgramShutdownHandler(php.runtime.env.handler.ProgramShutdownHandler) CompileScope(php.runtime.env.CompileScope) DebuggerException(org.develnext.jphp.debug.impl.DebuggerException) Environment(php.runtime.env.Environment) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Debugger (org.develnext.jphp.debug.impl.Debugger)1 DebuggerException (org.develnext.jphp.debug.impl.DebuggerException)1 CompileScope (php.runtime.env.CompileScope)1 Environment (php.runtime.env.Environment)1 ProgramShutdownHandler (php.runtime.env.handler.ProgramShutdownHandler)1