Search in sources :

Example 1 with ThreadSafeSessionManager

use of flash.tools.debugger.threadsafe.ThreadSafeSessionManager in project vscode-nextgenas by BowlerHatLLC.

the class SWFDebugSession method launch.

public void launch(Response response, LaunchRequest.LaunchRequestArguments args) {
    LaunchRequestArguments swfArgs = (LaunchRequestArguments) args;
    ThreadSafeSessionManager manager = ThreadSafeBootstrap.sessionManager();
    swfSession = null;
    try {
        manager.startListening();
        if (manager.supportsLaunch()) {
            String program = swfArgs.program;
            Path programPath = Paths.get(program);
            if (!programPath.isAbsolute()) {
                //if it's not an absolute path, we'll treat it as a
                //relative path within the workspace
                String workspacePath = System.getProperty(WORKSPACE_PROPERTY);
                if (workspacePath != null) {
                    program = Paths.get(workspacePath).resolve(programPath).toAbsolutePath().toString();
                }
            }
            Player player = null;
            CustomRuntimeLauncher launcher = null;
            if (swfArgs.runtimeExecutable != null) {
                //if runtimeExecutable is specified, we'll launch that
                launcher = new CustomRuntimeLauncher(swfArgs.runtimeExecutable, swfArgs.runtimeArgs);
            } else {
                //otherwise, let the SWF debugger automatically figure out
                //which runtime is required based on the program path
                String playerPath = program;
                try {
                    URI uri = Paths.get(playerPath).toUri();
                    playerPath = uri.toString();
                } catch (Exception e) {
                //safe to ignore
                }
                player = manager.playerForUri(playerPath, null);
                if (player == null && !playerPath.startsWith("http:") && !playerPath.startsWith("https:") && playerPath.endsWith(".swf")) {
                    if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
                        launcher = findWindowsStandalonePlayer();
                    } else if (//linux
                    !System.getProperty("os.name").toLowerCase().startsWith("mac os")) {
                        launcher = findLinuxStandalonePlayer();
                    }
                }
            }
            if (player == null && launcher == null) {
                sendErrorResponse(response, 10001, "Error launching SWF debug session. Runtime not found for program: " + program);
                return;
            } else {
                AIRLaunchInfo launchInfo = null;
                //check if the debugger automatically detected AIR
                boolean isAIR = player != null && player.getType() == Player.AIR;
                if (!isAIR && player == null && program.endsWith(FILE_EXTENSION_XML)) {
                    //otherwise, check if the program to launch is an AIR
                    //application descriptor
                    isAIR = true;
                }
                if (isAIR && adlPath != null) {
                    launchInfo = new AIRLaunchInfo();
                    launchInfo.profile = swfArgs.profile;
                    launchInfo.screenSize = swfArgs.screensize;
                    launchInfo.dpi = swfArgs.screenDPI;
                    launchInfo.versionPlatform = swfArgs.versionPlatform;
                    launchInfo.airDebugLauncher = adlPath.toFile();
                    launchInfo.extDir = swfArgs.extdir;
                    if (launcher != null) {
                        launcher.isAIR = true;
                    }
                }
                if (launcher != null) {
                    swfSession = (ThreadSafeSession) manager.launch(program, launchInfo, true, null, null, launcher);
                } else {
                    swfSession = (ThreadSafeSession) manager.launch(program, launchInfo, true, null, null);
                }
            }
        }
    } catch (CommandLineException e) {
        OutputEvent.OutputBody body = new OutputEvent.OutputBody();
        body.output = e.getMessage() + "\n" + e.getCommandOutput();
        body.category = OutputEvent.CATEGORY_STDERR;
        sendEvent(new OutputEvent(body));
        e.printStackTrace(System.err);
        sendErrorResponse(response, 10001, "Error launching SWF debug session. Process exited with code: " + e.getExitValue());
        return;
    } catch (IOException e) {
        e.printStackTrace(System.err);
        sendErrorResponse(response, 10001, "Error launching SWF debug session.");
        return;
    }
    try {
        swfSession.bind();
    } catch (VersionException e) {
        e.printStackTrace(System.err);
    }
    try {
        manager.stopListening();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
    sendResponse(response);
    cancelRunner = false;
    sessionThread = new java.lang.Thread(new SessionRunner());
    sessionThread.start();
}
Also used : Path(java.nio.file.Path) OutputEvent(com.nextgenactionscript.vscode.debug.events.OutputEvent) Player(flash.tools.debugger.Player) AIRLaunchInfo(flash.tools.debugger.AIRLaunchInfo) IOException(java.io.IOException) URI(java.net.URI) VersionException(flash.tools.debugger.VersionException) PlayerDebugException(flash.tools.debugger.PlayerDebugException) InProgressException(flash.tools.debugger.InProgressException) NoResponseException(flash.tools.debugger.NoResponseException) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException) NotConnectedException(flash.tools.debugger.NotConnectedException) CommandLineException(flash.tools.debugger.CommandLineException) CommandLineException(flash.tools.debugger.CommandLineException) ThreadSafeSessionManager(flash.tools.debugger.threadsafe.ThreadSafeSessionManager) VersionException(flash.tools.debugger.VersionException)

Aggregations

JsonParseException (com.google.gson.JsonParseException)1 OutputEvent (com.nextgenactionscript.vscode.debug.events.OutputEvent)1 AIRLaunchInfo (flash.tools.debugger.AIRLaunchInfo)1 CommandLineException (flash.tools.debugger.CommandLineException)1 InProgressException (flash.tools.debugger.InProgressException)1 NoResponseException (flash.tools.debugger.NoResponseException)1 NotConnectedException (flash.tools.debugger.NotConnectedException)1 Player (flash.tools.debugger.Player)1 PlayerDebugException (flash.tools.debugger.PlayerDebugException)1 VersionException (flash.tools.debugger.VersionException)1 ThreadSafeSessionManager (flash.tools.debugger.threadsafe.ThreadSafeSessionManager)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Path (java.nio.file.Path)1