Anonymous avatar Anonymous committed bb2a102

Moved launching to swank.

Comments (0)

Files changed (8)

       <launchConfigurationType
             delegate="org.lispdev.swank.BaseLocalLispLaunchDelegate"
             id="org.lispdev.swank.baseLocalLaunchConfigurationType"
-            modes="debug"
+            modes="profile"
             name="Local Lisp"
             public="true">
       </launchConfigurationType>

src/org/lispdev/swank/BaseLocalLispLaunchDelegate.java

 package org.lispdev.swank;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.lispdev.log.Log;
 
 public class BaseLocalLispLaunchDelegate extends LaunchConfigurationDelegate
 {
   public final static String ID =
-    "org.lispdev.replview.localLaunchConfigurationType";
+    "org.lispdev.swank.baseLocalLaunchConfigurationType";
   public final static String ATTR_EXE = "path-to-executable-string";
   public final static String ATTR_CMD_PARAMS = "command-line-params-list";
   public final static String ATTR_ENV = "environment-variables-map";
   //for now to folder containing lisp-extensions folder: see basicStartup
   //function in SwankInterface
 
+  @SuppressWarnings("unchecked")
+  protected static SwankInterface launch(ILaunchConfiguration config,
+      ILaunch launch) throws CoreException
+  {
+    final LocalLispImplementation implem =
+      new LocalLispImplementation(config.getAttribute(ATTR_EXE, ""),
+          config.getAttribute(ATTR_CMD_PARAMS, new ArrayList()),
+          config.getAttribute(ATTR_ENV, new HashMap()),
+          config.getAttribute(ATTR_PORT, 4005));
+    // FIXME: right now paths are checked in lisp implementation and
+    // produce runtime exceptions if something wrong
+    // instead should check here and produce coreexceptions
+    final String ext = config.getAttribute(ATTR_EXT, "");
+    final File extf = new File(ext);
+    if( !extf.isDirectory() )
+    {
+      Log.abort("Directory "+ext+" does not exist", null);
+    }
+    final SwankInterface s = new SwankInterface(ext,4005,implem);
+
+    LispProcess p = new LispProcess(launch, "swank", null, s);
+    launch.addProcess(p);
+    launch.addDebugTarget(new LispDebugTarget(launch, p));
+    return s;
+  }
 
 
   @Override
   public void launch(ILaunchConfiguration configuration, String mode,
       ILaunch launch, IProgressMonitor monitor) throws CoreException
   {
-  // TODO Auto-generated method stub
-
+    Assert.isLegal(ILaunchManager.PROFILE_MODE.equals(mode), "Wrong mode");
+    launch(configuration,launch).initParams(new TestRunnableDriver());
   }
 
 }

src/org/lispdev/swank/LispDebugElement.java

+package org.lispdev.swank;
+
+import org.eclipse.debug.core.model.DebugElement;
+
+public class LispDebugElement extends DebugElement
+{
+  public static final String MODEL_ID = "org.lispdev.debug.model";
+
+  public LispDebugElement(LispDebugTarget target)
+  {
+    super(target);
+  }
+
+  public ISwank getSwank()
+  {
+    return ((LispDebugTarget)getDebugTarget()).getSwank();
+  }
+
+  @Override
+  public String getModelIdentifier()
+  {
+    return MODEL_ID;
+  }
+
+}

src/org/lispdev/swank/LispDebugTarget.java

+package org.lispdev.swank;
+
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IMemoryBlock;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IThread;
+
+public class LispDebugTarget extends LispDebugElement implements IDebugTarget
+{
+  private final ILaunch launch;
+  private final LispProcess process;
+  private final IThread[] threads;
+  private final LispThread thread;
+  private boolean terminated = false;
+
+  public LispDebugTarget(ILaunch launch, LispProcess process)
+  {
+    super(null);
+    this.launch = launch;
+    this.process = process;
+    thread = new LispThread(this);
+    threads = new IThread[] {thread};
+  }
+
+  @Override
+  public ISwank getSwank()
+  {
+    if( process != null )
+    {
+      return process.getSwank();
+    }
+    return null;
+  }
+
+  @Override
+  public ILaunch getLaunch()
+  {
+    return launch;
+  }
+
+  @Override
+  public String getName() throws DebugException
+  {
+    return "swank";
+  }
+
+  @Override
+  public IProcess getProcess()
+  {
+    return process;
+  }
+
+  @Override
+  public IThread[] getThreads() throws DebugException
+  {
+    return threads;
+  }
+
+  public LispThread getMainThread()
+  {
+    return thread;
+  }
+
+  @Override
+  public boolean hasThreads() throws DebugException
+  {
+    return true;
+  }
+
+  @Override
+  public boolean supportsBreakpoint(IBreakpoint breakpoint)
+  {
+    return false;
+  }
+
+  @Override
+  public boolean canTerminate()
+  {
+    return process.canTerminate();
+  }
+
+  @Override
+  public boolean isTerminated()
+  {
+    return terminated || process.isTerminated();
+  }
+
+  @Override
+  public void terminate() throws DebugException
+  {
+    terminated = true;
+  }
+
+  @Override
+  public boolean canResume()
+  {
+    return !isTerminated() && isSuspended();
+  }
+
+  @Override
+  public boolean canSuspend()
+  {
+    return !isTerminated() && !isSuspended();
+  }
+
+  @Override
+  public boolean isSuspended()
+  {
+    return !isTerminated() && thread.isSuspended();
+  }
+
+  @Override
+  public void resume() throws DebugException
+  {
+    thread.resume();
+  }
+
+  @Override
+  public void suspend() throws DebugException
+  {
+    thread.suspend();
+  }
+
+  @Override
+  public void breakpointAdded(IBreakpoint breakpoint)
+  {
+  }
+
+  @Override
+  public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta)
+  {
+  }
+
+  @Override
+  public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta)
+  {
+  }
+
+  @Override
+  public boolean canDisconnect()
+  {
+    return false;
+  }
+
+  @Override
+  public void disconnect() throws DebugException
+  {
+  }
+
+  @Override
+  public boolean isDisconnected()
+  {
+    return false;
+  }
+
+  @Override
+  public IMemoryBlock getMemoryBlock(long startAddress, long length)
+      throws DebugException
+  {
+    return null;
+  }
+
+  @Override
+  public boolean supportsStorageRetrieval()
+  {
+    return false;
+  }
+
+  @Override
+  public IDebugTarget getDebugTarget()
+  {
+    return this;
+  }
+}

src/org/lispdev/swank/LispProcess.java

+package org.lispdev.swank;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamsProxy;
+
+public class LispProcess extends PlatformObject implements IProcess
+{
+
+  private final HashMap<String,String> attr = new HashMap<String,String>();
+  /**
+   * The name of the process
+   */
+  private final String fName;
+  /**
+   * The launch this process is contained in
+   */
+  private final ILaunch fLaunch;
+
+  private final ISwank fSwank;
+  /**
+   * This process's exit value
+   */
+  private final int fExitValue = 0;
+
+  public LispProcess(ILaunch launch, String name, Map<String,String> attributes,
+      ISwank swank)
+  {
+    fLaunch = launch;
+    fName = name;
+    if( attributes != null )
+    {
+      attr.putAll(attributes);
+    }
+    fSwank = swank;
+  }
+
+  @Override
+  public String getAttribute(String key)
+  {
+    return attr.get(key);
+  }
+
+  @Override
+  public int getExitValue() throws DebugException
+  {
+    if( isTerminated() )
+    {
+      return fExitValue;
+    }
+    throw new DebugException(
+        new Status(
+            IStatus.ERROR,
+            DebugPlugin.getUniqueIdentifier(),
+            DebugException.TARGET_REQUEST_FAILED,
+            "Exit value not available until process terminates.",
+            null));
+  }
+
+  @Override
+  public String getLabel()
+  {
+    return fName;
+  }
+
+  @Override
+  public ILaunch getLaunch()
+  {
+    return fLaunch;
+  }
+
+  @Override
+  public IStreamsProxy getStreamsProxy()
+  {
+    return null;
+  }
+
+  @Override
+  public void setAttribute(String key, String value)
+  {
+    attr.put(key, value);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public Object getAdapter(Class adapter)
+  {
+    if( adapter.equals(IProcess.class) )
+    {
+      return this;
+    }
+    if( adapter.equals(IDebugTarget.class) )
+    {
+      ILaunch launch = getLaunch();
+      for( IDebugTarget t : launch.getDebugTargets() )
+      {
+        if( this.equals(t.getProcess()) )
+        {
+          return t;
+        }
+      }
+      return null;
+    }
+    if( adapter.equals(ILaunch.class) )
+    {
+      return getLaunch();
+    }
+    // CONTEXTLAUNCHING
+    if( adapter.equals(ILaunchConfiguration.class) )
+    {
+      return getLaunch().getLaunchConfiguration();
+    }
+    return super.getAdapter(adapter);
+  }
+
+  @Override
+  public boolean canTerminate()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean isTerminated()
+  {
+    return false;
+  }
+
+  @Override
+  public void terminate() throws DebugException
+  {
+  }
+
+  public ISwank getSwank()
+  {
+    return fSwank;
+  }
+}

src/org/lispdev/swank/LispStackFrame.java

+package org.lispdev.swank;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IRegisterGroup;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.debug.core.model.IVariable;
+
+public class LispStackFrame extends LispDebugElement implements IStackFrame
+{
+  private final String name;
+  private final LispThread thread;
+
+  public LispStackFrame(LispThread thread, String name)
+  {
+    super((LispDebugTarget)thread.getDebugTarget());
+    this.thread = thread;
+    this.name = name;
+  }
+
+  @Override
+  public int getCharEnd() throws DebugException
+  {
+    return -1;
+  }
+
+  @Override
+  public int getCharStart() throws DebugException
+  {
+    return -1;
+  }
+
+  @Override
+  public int getLineNumber() throws DebugException
+  {
+    return 0;
+  }
+
+  @Override
+  public String getName() throws DebugException
+  {
+    return name;
+  }
+
+  @Override
+  public IRegisterGroup[] getRegisterGroups() throws DebugException
+  {
+    return null;
+  }
+
+  @Override
+  public IThread getThread()
+  {
+    return thread;
+  }
+
+  @Override
+  public IVariable[] getVariables() throws DebugException
+  {
+    return new IVariable[0];
+  }
+
+  @Override
+  public boolean hasRegisterGroups() throws DebugException
+  {
+    return false;
+  }
+
+  @Override
+  public boolean hasVariables() throws DebugException
+  {
+    return false;
+  }
+
+  @Override
+  public boolean canStepInto()
+  {
+    return getThread().canStepInto();
+  }
+
+  @Override
+  public boolean canStepOver()
+  {
+    return getThread().canStepOver();
+  }
+
+  @Override
+  public boolean canStepReturn()
+  {
+    return getThread().canStepReturn();
+  }
+
+  @Override
+  public boolean isStepping()
+  {
+    return getThread().isStepping();
+  }
+
+  @Override
+  public void stepInto() throws DebugException
+  {
+    getThread().stepInto();
+  }
+
+  @Override
+  public void stepOver() throws DebugException
+  {
+    getThread().stepOver();
+
+  }
+
+  @Override
+  public void stepReturn() throws DebugException
+  {
+    getThread().stepReturn();
+  }
+
+  @Override
+  public boolean canResume()
+  {
+    return getThread().canResume();
+  }
+
+  @Override
+  public boolean canSuspend()
+  {
+    return getThread().canSuspend();
+  }
+
+  @Override
+  public boolean isSuspended()
+  {
+    return getThread().isSuspended();
+  }
+
+  @Override
+  public void resume() throws DebugException
+  {
+    getThread().resume();
+  }
+
+  @Override
+  public void suspend() throws DebugException
+  {
+    getThread().suspend();
+  }
+
+  @Override
+  public boolean canTerminate()
+  {
+    return getThread().canTerminate();
+  }
+
+  @Override
+  public boolean isTerminated()
+  {
+    return getThread().isTerminated();
+  }
+
+  @Override
+  public void terminate() throws DebugException
+  {
+    getThread().terminate();
+  }
+
+}

src/org/lispdev/swank/LispThread.java

+package org.lispdev.swank;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.debug.core.model.IThread;
+
+public class LispThread extends LispDebugElement implements IThread
+{
+  private boolean suspended;
+  private LispNode debugInfo = null;
+
+  public LispThread(LispDebugTarget target)
+  {
+    super(target);
+  }
+
+  @Override
+  public IBreakpoint[] getBreakpoints()
+  {
+    return null;
+  }
+
+  @Override
+  public String getName() throws DebugException
+  {
+    return "Main thread";
+  }
+
+  @Override
+  public int getPriority() throws DebugException
+  {
+    return 0;
+  }
+
+  public LispNode getRestarts()
+  {
+    if( isSuspended() && debugInfo != null )
+    {
+      return debugInfo.get(4);
+    }
+    return null;
+  }
+
+  public String getThreadID()
+  {
+    if( isSuspended() && debugInfo != null )
+    {
+      return debugInfo.get(1).value;
+    }
+    return null;
+  }
+
+  public String getDebugLevel()
+  {
+    if( isSuspended() && debugInfo != null )
+    {
+      return debugInfo.get(2).value;
+    }
+    return null;
+  }
+
+  @Override
+  public IStackFrame[] getStackFrames() throws DebugException
+  {
+    if( isSuspended() && debugInfo != null )
+    {
+      LispNode backtrace = debugInfo.get(5);
+      if( backtrace != null )
+      {
+        IStackFrame[] res = new IStackFrame[backtrace.getParamsCount()];
+        for( int i = 0; i < res.length; ++i )
+        {
+          res[i] = new LispStackFrame(this, backtrace.get(i).toString());
+        }
+        return res;
+      }
+
+    }
+    return new IStackFrame[0];
+  }
+
+  @Override
+  public IStackFrame getTopStackFrame() throws DebugException
+  {
+    IStackFrame[] frames = getStackFrames();
+    if( frames.length > 0 )
+    {
+      return frames[0];
+    }
+    return null;
+  }
+
+  @Override
+  public boolean hasStackFrames() throws DebugException
+  {
+    return isSuspended();
+  }
+
+  @Override
+  public boolean canResume()
+  {
+    return isSuspended();
+  }
+
+  @Override
+  public boolean canSuspend()
+  {
+    return !isSuspended();
+  }
+
+  @Override
+  public boolean isSuspended()
+  {
+    return suspended && !isTerminated();
+  }
+
+  @Override
+  public void resume() throws DebugException
+  {
+  }
+
+  @Override
+  public void suspend() throws DebugException
+  {
+  }
+
+  @Override
+  public boolean canStepInto()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean canStepOver()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean canStepReturn()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean isStepping()
+  {
+    return false;
+  }
+
+  @Override
+  public void stepInto() throws DebugException
+  {
+  }
+
+  @Override
+  public void stepOver() throws DebugException
+  {
+  }
+
+  @Override
+  public void stepReturn() throws DebugException
+  {
+  }
+
+  @Override
+  public boolean canTerminate()
+  {
+    return !isTerminated();
+  }
+
+  @Override
+  public boolean isTerminated()
+  {
+    return getDebugTarget().isTerminated();
+  }
+
+  @Override
+  public void terminate() throws DebugException
+  {
+  }
+
+  public void setSuspended(LispNode info)
+  {
+    debugInfo = info;
+    suspended = (info != null);
+    fireSuspendEvent(1);
+  }
+
+}

src/org/lispdev/swank/LocalLispImplementation.java

+package org.lispdev.swank;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+
+public class LocalLispImplementation extends LispImplementation
+{
+  private final String[] commandLine;
+  @SuppressWarnings("unchecked")
+  private final Map env;
+  private final int port;
+
+  @SuppressWarnings("unchecked")
+  public LocalLispImplementation(String exePath, List cmdParams,
+      Map env, int port)
+  {
+    commandLine = new String[1+cmdParams.size()];
+    commandLine[0] = exePath;
+    for( int i = 0; i < cmdParams.size(); ++i )
+    {
+      commandLine[i+1] = String.valueOf(cmdParams.get(i));
+    }
+    this.env = (env == null ? new HashMap<String,String>() : env);
+    this.port = port;
+  }
+
+  @Override
+  public Process start() throws IOException
+  {
+    File cmd = new File(commandLine[0]);
+    Assert.isLegal(cmd.exists(), "Lisp executable " +
+        commandLine[0]+" does not exist");
+    Assert.isLegal(cmd.canExecute(), "File " + commandLine[0] +
+        " is not executable");
+    final ProcessBuilder pb = new ProcessBuilder(commandLine);
+    for( Object k : env.keySet() )
+    {
+      pb.environment().put(String.valueOf(k), String.valueOf(env.get(k)));
+    }
+
+    Process lispEngine = pb.start();
+    DataOutputStream commandInterface =
+      new DataOutputStream(lispEngine.getOutputStream());
+    commandInterface
+      .writeBytes("(swank-loader::init :load-contribs t :setup t)");
+    commandInterface.flush();
+    commandInterface
+      .writeBytes("(progn (swank:create-server :coding-system \"utf-8\" :port "
+          + port + "))\n");
+    commandInterface.flush();
+    return lispEngine;
+  }
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.