Commits

Anonymous committed d9be684

Moved launching to swank.

Comments (0)

Files changed (9)

src/org/lispdev/replview/LispDebugElement.java

-package org.lispdev.replview;
-
-import org.eclipse.debug.core.model.DebugElement;
-import org.lispdev.swank.ISwank;
-
-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/replview/LispDebugTarget.java

-package org.lispdev.replview;
-
-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;
-import org.lispdev.swank.ISwank;
-
-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/replview/LispProcess.java

-package org.lispdev.replview;
-
-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;
-import org.lispdev.swank.ISwank;
-
-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/replview/LispStackFrame.java

-package org.lispdev.replview;
-
-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/replview/LispThread.java

-package org.lispdev.replview;
-
-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;
-import org.lispdev.swank.LispNode;
-
-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/replview/LocalLispImplementation.java

-package org.lispdev.replview;
-
-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;
-import org.lispdev.swank.LispImplementation;
-
-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;
-  }
-
-}

src/org/lispdev/replview/LocalLispLaunchDelegate.java

 package org.lispdev.replview;
 
-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.ILaunchConfigurationDelegate;
-import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
-import org.lispdev.log.Log;
 import org.lispdev.repl.SwankRunnableDriver;
-import org.lispdev.swank.SwankInterface;
+import org.lispdev.swank.BaseLocalLispLaunchDelegate;
 
-public class LocalLispLaunchDelegate extends LaunchConfigurationDelegate
+public class LocalLispLaunchDelegate extends BaseLocalLispLaunchDelegate
     implements ILaunchConfigurationDelegate
 {
   public final static String ID =
     "org.lispdev.replview.localLaunchConfigurationType";
-  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";
-  public final static String ATTR_PORT = "port-int";
-  public final static String ATTR_EXT = "lisp-extensions-path-string";
-  //for now to folder containing lisp-extensions folder: see basicStartup
-  //function in SwankInterface
 
-  @SuppressWarnings("unchecked")
   @Override
   public void launch(ILaunchConfiguration config, String mode,
       ILaunch launch, IProgressMonitor monitor) 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);
-    s.initParams(new SwankRunnableDriver());
-
-    LispProcess p = new LispProcess(launch, "swank", null, s);
-    launch.addProcess(p);
-    launch.addDebugTarget(new LispDebugTarget(launch, p));
+    Assert.isLegal(ILaunchManager.DEBUG_MODE.equals(mode), "Wrong mode");
+    launch(config,launch).initParams(new SwankRunnableDriver());
   }
 
 }

src/org/lispdev/replview/ReplView.java

 import org.lispdev.repl.ReadState;
 import org.lispdev.swank.ISwank;
 import org.lispdev.swank.LispNode;
+import org.lispdev.swank.LispProcess;
+import org.lispdev.swank.LispThread;
 
 public class ReplView extends ViewPart
 {

src/org/lispdev/replview/RestartActionDelegate.java

 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.ui.IViewActionDelegate;
 import org.eclipse.ui.IViewPart;
+import org.lispdev.swank.LispDebugTarget;
 import org.lispdev.swank.LispNode;
+import org.lispdev.swank.LispThread;
 
 public class RestartActionDelegate implements IViewActionDelegate, IMenuCreator
 {