All Downloads are FREE. Search and download functionalities are using the official Maven repository.

editor.run.OutOfProcessDebug Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package editor.run;

import com.sun.jdi.Bootstrap;
import com.sun.jdi.VirtualMachineManager;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.connect.LaunchingConnector;
import editor.settings.CompilerSettings;
import editor.util.PlatformUtil;
import gw.lang.Gosu;

import java.io.File;
import java.util.Map;

/**
 */
public class OutOfProcessDebug extends AbstractOutOfProcessExecutor
{
  public OutOfProcessDebug()
  {
    super( RunState.Debug );
  }

  @Override
  protected String exec() throws Exception
  {
    VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
    LaunchingConnector conn = vmm.defaultConnector();
    Map defaultArguments = conn.defaultArguments();
    String jreHome = getRunConfig().getJreForProcessOrDefault( defaultArguments.get( "home" ).value() );
    defaultArguments.get( "home" ).setValue( jreHome );
    String progArgs = getRunConfig().getProgArgs() == null ? "" : getRunConfig().getProgArgs();
    if( CompilerSettings.isStaticCompile() )
    {
      defaultArguments.get( "main" ).setValue( getRunConfig().getFqn().replace( '.', '/' ) + " " + progArgs );
    }
    else
    {
      defaultArguments.get( "main" ).setValue( Gosu.class.getName().replace( '.', '/' ) + " -fqn " + getRunConfig().getFqn() + " " + progArgs );
    }
    String vmArgs = getRunConfig().getVmArgs() == null ? "" : getRunConfig().getVmArgs();
    defaultArguments.get( "options" ).setValue( vmArgs + " -cp \"" + makeClasspath( getGosuPanel(), true ) + "\"" );
    printLabMessage( makeDebuggingMessage( defaultArguments ) );
    setVm( conn.launch( defaultArguments ) );
    setProcess( getVm().process() );
    getGosuPanel().pipeInput();
    getGosuPanel().makeDebugger( getVm() );
    waitFor();
    return String.valueOf( "Process finished with exit code " + getProcess().exitValue() );
  }

  private String makeDebuggingMessage( Map vmArgs )
  {
    StringBuilder sb = new StringBuilder();
    String java = vmArgs.get( "home" ).value() + File.separator + "bin" + File.separator + "java" + (PlatformUtil.isWindows() ? ".exe" : "");
    String javaArgs = vmArgs.get( "options" ).value();
    String target = vmArgs.get( "main" ).value();
    sb.append( java ).append( ' ' )
      .append( javaArgs ).append( ' ' )
      .append( target )
      .append( '\n' );
    sb.append( "Debugging: " ).append( getRunConfig().getName() ).append( "...\n" );
    return sb.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy