Commits

Anonymous committed ed7d15d

Refactoring to single active lisp for the system. Loading project does not work yet.

Comments (0)

Files changed (6)

    <extension
          point="org.eclipse.debug.core.launchConfigurationTypes">
       <launchConfigurationType
-            delegate="org.lispdev.swank.debug.BaseLocalLispLaunchDelegate"
+            delegate="org.lispdev.swank.BaseLocalLispLaunchDelegate"
             id="org.lispdev.swank.baseLocalLaunchConfigurationType"
             modes="profile"
             name="Local Lisp"

src/org/lispdev/swank/BaseLocalLispLaunchDelegate.java

+package org.lispdev.swank;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.lispdev.log.Log;
+import org.lispdev.swank.debug.LispDebugTarget;
+import org.lispdev.swank.debug.LispProcess;
+
+public class BaseLocalLispLaunchDelegate extends LaunchConfigurationDelegate
+{
+  public final static String ID =
+    "org.lispdev.swank.baseLocalLaunchConfigurationType";
+  public final static String LOCAL_ID =
+    "org.lispdev.replview.localLaunchConfigurationType";
+
+  private final static String ATTR_EXE = "path-to-executable-string";
+  private final static String ATTR_SWANK = "path-to-swank-loader.lisp";
+  private final static String ATTR_CMD_PARAMS = "command-line-params-list";
+  private final static String ATTR_ENV = ILaunchManager.ATTR_ENVIRONMENT_VARIABLES;
+  private final static String ATTR_PORT = "port-int";
+  private final static String ATTR_EXT = "lisp-extensions-path-string";
+  private final static String ATTR_START_REPL_THREAD = "start-repl-thread";
+  private final static String ATTR_COMPILER_OUTPUTS = "compiler-outputs-extensions";
+  //for now to folder containing lisp-extensions folder: see basicStartup
+  //function in SwankInterface
+
+  public static String getExePath(ILaunchConfiguration config) throws CoreException
+  {
+    final String exe = config.getAttribute(ATTR_EXE, "");
+    return exe;
+  }
+
+  public static void setExePath(ILaunchConfigurationWorkingCopy wc, String path)
+  {
+    wc.setAttribute(ATTR_EXE, path);
+  }
+
+  public static String getSwankLoaderDir(ILaunchConfiguration config) throws CoreException
+  {
+    final String swankDir = config.getAttribute(ATTR_SWANK, "");
+    return swankDir;
+  }
+
+  public static void setSwankLoaderDir(ILaunchConfigurationWorkingCopy wc,
+      String path)
+  {
+    wc.setAttribute(ATTR_SWANK, path);
+  }
+
+  @SuppressWarnings("unchecked")
+  public static List<String> getCmdParams(ILaunchConfiguration config) throws CoreException
+  {
+    return config.getAttribute(ATTR_CMD_PARAMS, new ArrayList<String>());
+  }
+
+  public static void setCmdParams(ILaunchConfigurationWorkingCopy wc,
+      List<String> params)
+  {
+    wc.setAttribute(ATTR_CMD_PARAMS, params);
+  }
+
+  @SuppressWarnings("unchecked")
+  public static Map<String,String> getEnvVars(ILaunchConfiguration config) throws CoreException
+  {
+    return config.getAttribute(ATTR_ENV, new HashMap<String,String>());
+  }
+
+  public static void setEnvVars(ILaunchConfigurationWorkingCopy wc,
+      Map<String,String> x)
+  {
+    wc.setAttribute(ATTR_ENV, x);
+  }
+
+  public static int getPort(ILaunchConfiguration config) throws CoreException
+  {
+    return config.getAttribute(ATTR_PORT, -1);
+  }
+
+  public static void setPort(ILaunchConfigurationWorkingCopy wc, int port)
+  {
+    wc.setAttribute(ATTR_PORT, port);
+  }
+
+  /**
+   * @param config
+   * @return directory where lisp-extensions folder is located
+   * @throws CoreException
+   */
+  public static String getLispExtDir(ILaunchConfiguration config) throws CoreException
+  {
+    final String ext = config.getAttribute(ATTR_EXT, "");
+    return ext;
+  }
+
+  public static void setLispExtDir(ILaunchConfigurationWorkingCopy wc,
+      String dir)
+  {
+    wc.setAttribute(ATTR_EXT, dir);
+  }
+
+  public static boolean getStartReplThread(ILaunchConfiguration config) throws CoreException
+  {
+    return config.getAttribute(ATTR_START_REPL_THREAD, false);
+  }
+
+  public static void setStartReplThread(ILaunchConfigurationWorkingCopy wc,
+      boolean val)
+  {
+    wc.setAttribute(ATTR_START_REPL_THREAD, val);
+  }
+
+  @SuppressWarnings("rawtypes")
+  public static boolean isCompilerOutput(ILaunchConfiguration c, String filename) throws CoreException
+  {
+    IPath path = new Path(filename);
+    String ext = path.getFileExtension();
+    for(Object o : c.getAttribute(ATTR_COMPILER_OUTPUTS, new ArrayList()))
+    {
+      if( o.equals(ext) ) return true;
+    }
+    return false;
+  }
+
+  public static void setCompilerOutputs(ILaunchConfigurationWorkingCopy wc,
+      List<String> val)
+  {
+    wc.setAttribute(ATTR_COMPILER_OUTPUTS, val);
+  }
+
+  protected static LispProcess launch(ILaunchConfiguration config,
+      ILaunch launch, IRunnableDriver r) throws CoreException
+  {
+    if( SwankPlugin.get().launch2process.get(config) != null )
+    {
+      Log.abort("Cannot launch twice", null);
+    }
+
+    final String exe = getExePath(config);
+    File cmd = new File(exe);
+    if( !cmd.exists() )
+    {
+      Log.abort("Lisp executable "+exe+" does not exist", null);
+    }
+    if( !cmd.canExecute() )
+    {
+      Log.abort("File " + exe + " is not executable", null);
+    }
+    final String swankDir = getSwankLoaderDir(config);
+    File swankf = new File(swankDir,"swank-loader.lisp");
+    if( !swankf.exists() )
+    {
+      Log.abort("Swank was not found in folder "+swankDir, null);
+    }
+    final int port = getPort(config);
+    if( port < AvailablePortFinder.MIN_PORT_NUMBER
+        || port > AvailablePortFinder.MAX_PORT_NUMBER )
+    {
+      Log.abort("Port is outside of available range", null);
+    }
+    if( !AvailablePortFinder.available(port) )
+    {
+      Log.abort("Port "+port+" is not available", null);
+    }
+    final LocalLispImplementation implem =
+      new LocalLispImplementation(exe, swankDir, getCmdParams(config),
+          getEnvVars(config), port, getStartReplThread(config));
+    final String ext = getLispExtDir(config);
+    final File extf = new File(ext);
+    if( !extf.isDirectory() )
+    {
+      Log.abort("Extensions directory "+ext+" does not exist", null);
+    }
+    final SwankInterface s = new SwankInterface(ext,implem,r);
+    //s.connect();
+
+    LispProcess p = new LispProcess(launch, config.getName(), null, s);
+    launch.addProcess(p);
+    launch.addDebugTarget(new LispDebugTarget(launch, p));
+    SwankPlugin.get().launch2process.put(config,p);
+    if( SwankPlugin.get().getActiveConfig() == null )
+    {
+      SwankPlugin.get().setActiveConfig(config);
+    }
+    return p;
+  }
+
+  @Override
+  public void launch(ILaunchConfiguration configuration, String mode,
+      ILaunch launch, IProgressMonitor monitor) throws CoreException
+  {
+    Assert.isLegal(ILaunchManager.PROFILE_MODE.equals(mode), "Wrong mode");
+    launch(configuration,launch,new TestRunnableDriver());
+  }
+
+}

src/org/lispdev/swank/LocalLispImplementation.java

 public class LocalLispImplementation extends LispImplementation
 {
   private final String[] commandLine;
-  @SuppressWarnings("rawtypes")
-  private final Map env;
+  private final Map<String,String> env;
   private final boolean startReplThread;
 
-  @SuppressWarnings("rawtypes")
-  public LocalLispImplementation(String exePath, String swankDir, List cmdParams,
-      Map env, int port, boolean startReplThread)
+  public LocalLispImplementation(String exePath, String swankDir,
+      List<String> cmdParams, Map<String,String> env,
+      int port, boolean startReplThread)
   {
     super(port);
     final int cmdSize = (cmdParams == null ? 0 : cmdParams.size());
         .replace(File.separator+File.separator, File.separator);
     for( int i = 0; i < cmdSize; ++i )
     {
-      commandLine[i+3] = String.valueOf(cmdParams.get(i));
+      commandLine[i+3] = cmdParams.get(i);
     }
     this.env = (env == null ? new HashMap<String,String>() : env);
     this.startReplThread = startReplThread;
     Assert.isLegal(sw.exists(), "Swank loader "
         + commandLine[2] + " does not exist");
     final ProcessBuilder pb = new ProcessBuilder(commandLine);
-    for( Object k : env.keySet() )
+    for( String k : env.keySet() )
     {
-      pb.environment().put(String.valueOf(k), String.valueOf(env.get(k)));
+      pb.environment().put(k, env.get(k));
     }
 
     Process lispEngine = pb.start();

src/org/lispdev/swank/SwankInterfaceTest.java

 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.lispdev.swank.debug.BaseLocalLispLaunchDelegate;
 import org.lispdev.swank.debug.LispProcess;
 import org.lispdev.swank.debug.LispVariable;
 import org.lispdev.swank.runnables.SwankCompilationRunnable;
         manager.getLaunchConfigurationType(BaseLocalLispLaunchDelegate.ID);
       ILaunchConfiguration cfg = cfgType.newInstance(null, "swank");
       ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXE,
+      BaseLocalLispLaunchDelegate.setExePath(wc,
           "D:\\projects\\lisp\\sbcl1.0.40-threads-1\\sbcl.exe");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_SWANK,
+      BaseLocalLispLaunchDelegate.setSwankLoaderDir(wc,
           "D:\\projects\\lisp\\slime-2010-07-16\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_ENV,
+      BaseLocalLispLaunchDelegate.setEnvVars(wc,
           new HashMap<String,String>()
           {private static final long serialVersionUID = 1L;
           {put("SBCL_HOME","D:\\projects\\lisp\\sbcl1.0.40-threads-1\\");}});
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXT,
+      BaseLocalLispLaunchDelegate.setLispExtDir(wc,
           "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_PORT, 4005);
+      BaseLocalLispLaunchDelegate.setPort(wc, 4005);
       cfg = wc.doSave();
       ILaunch launch = cfg.launch(ILaunchManager.PROFILE_MODE, null, false);
       cfg.delete();
         manager.getLaunchConfigurationType(BaseLocalLispLaunchDelegate.ID);
       ILaunchConfiguration cfg = cfgType.newInstance(null, "swank");
       ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXE,
+      BaseLocalLispLaunchDelegate.setExePath(wc,
           "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\sbcl\\sbcl.exe");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_SWANK,
+      BaseLocalLispLaunchDelegate.setSwankLoaderDir(wc,
           "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\slime\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_ENV,
+      BaseLocalLispLaunchDelegate.setEnvVars(wc,
           new HashMap<String,String>()
           {private static final long serialVersionUID = 1L;
           {put("SBCL_HOME","D:\\projects\\lispdev\\ws\\org.lispdev.swank\\sbcl\\");}});
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXT,
+      BaseLocalLispLaunchDelegate.setLispExtDir(wc,
           "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_PORT, 4005);
+      BaseLocalLispLaunchDelegate.setPort(wc, 4005);
       cfg = wc.doSave();
       ILaunch launch = cfg.launch(ILaunchManager.PROFILE_MODE, null, false);
       cfg.delete();
         manager.getLaunchConfigurationType(BaseLocalLispLaunchDelegate.ID);
       ILaunchConfiguration cfg = cfgType.newInstance(null, "swank");
       ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXE,
+      BaseLocalLispLaunchDelegate.setExePath(wc,
           "D:\\projects\\lisp\\ccl\\wx86cl.exe");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_SWANK,
+      BaseLocalLispLaunchDelegate.setSwankLoaderDir(wc,
           "D:\\projects\\lisp\\slime-2010-07-16\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_EXT,
+      BaseLocalLispLaunchDelegate.setExePath(wc,
           "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\");
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_PORT, 4005);
-      wc.setAttribute(BaseLocalLispLaunchDelegate.ATTR_START_REPL_THREAD, true);
+      BaseLocalLispLaunchDelegate.setPort(wc, 4005);
+      BaseLocalLispLaunchDelegate.setStartReplThread(wc, true);
       cfg = wc.doSave();
       ILaunch launch = cfg.launch(ILaunchManager.PROFILE_MODE, null, false);
       cfg.delete();

src/org/lispdev/swank/SwankPlugin.java

 package org.lispdev.swank;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Plugin;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchManager;
+import org.lispdev.log.Log;
 import org.lispdev.swank.debug.LispProcess;
 import org.osgi.framework.BundleContext;
 
   // The shared instance
   private static SwankPlugin plugin;
 
-  /**
-   * The constructor
-   */
-  public SwankPlugin()
-  {}
-
-  /*
-   * (non-Javadoc)
-   *
-   * @see
-   * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
-   */
   @Override
   public void start(BundleContext context) throws Exception
   {
     plugin = this;
   }
 
-  /*
-   * (non-Javadoc)
-   *
-   * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
-   */
   @Override
   public void stop(BundleContext context) throws Exception
   {
     return ""; //$NON-NLS-1$
   }
 
-  public String getSlimePath()
+  protected final Map<ILaunchConfiguration, LispProcess> launch2process =
+    new HashMap<ILaunchConfiguration, LispProcess>();
+
+  public ILaunchConfiguration[] getConfigs()
   {
-    return getPluginPath() + "slime/swank-loader.lisp";
+    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+    ILaunchConfigurationType type =
+      manager.getLaunchConfigurationType(BaseLocalLispLaunchDelegate.LOCAL_ID);
+    try
+    {
+      return manager.getLaunchConfigurations(type);
+    }
+    catch(CoreException e)
+    {
+      Log.logException(e);
+    }
+    return new ILaunchConfiguration[0];
   }
 
-
-  /**
-   * Holds list of all lisp processes
-   */
-  private final List<LispProcess> processes = new ArrayList<LispProcess>();
-
-  public List<LispProcess> getProcesses()
+  public LispProcess getProcess(ILaunchConfiguration config)
   {
-    return processes;
+    return launch2process.get(config);
   }
 
-  public void addProcess(LispProcess p)
+  private ILaunchConfiguration active;
+
+  public void setActiveConfig(ILaunchConfiguration config)
   {
-    processes.add(p);
+    active = config;
+  }
+
+  public ILaunchConfiguration getActiveConfig()
+  {
+    return active;
+  }
+
+  public LispProcess getActiveProcess()
+  {
+    return launch2process.get(active);
   }
 }

src/org/lispdev/swank/debug/BaseLocalLispLaunchDelegate.java

-package org.lispdev.swank.debug;
-
-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;
-import org.lispdev.swank.AvailablePortFinder;
-import org.lispdev.swank.IRunnableDriver;
-import org.lispdev.swank.LocalLispImplementation;
-import org.lispdev.swank.SwankInterface;
-import org.lispdev.swank.SwankPlugin;
-import org.lispdev.swank.TestRunnableDriver;
-
-public class BaseLocalLispLaunchDelegate extends LaunchConfigurationDelegate
-{
-  public final static String ID =
-    "org.lispdev.swank.baseLocalLaunchConfigurationType";
-  public final static String ATTR_EXE = "path-to-executable-string";
-  public final static String ATTR_SWANK = "path-to-swank-loader.lisp";
-  public final static String ATTR_CMD_PARAMS = "command-line-params-list";
-  public final static String ATTR_ENV = ILaunchManager.ATTR_ENVIRONMENT_VARIABLES;
-  public final static String ATTR_PORT = "port-int";
-  public final static String ATTR_EXT = "lisp-extensions-path-string";
-  public final static String ATTR_START_REPL_THREAD = "start-repl-thread";
-  //for now to folder containing lisp-extensions folder: see basicStartup
-  //function in SwankInterface
-
-  protected static LispProcess launch(ILaunchConfiguration config,
-      ILaunch launch, IRunnableDriver r) throws CoreException
-  {
-    final String exe = config.getAttribute(ATTR_EXE, "");
-    File cmd = new File(exe);
-    if( !cmd.exists() )
-    {
-      Log.abort("Lisp executable "+exe+" does not exist", null);
-    }
-    if( !cmd.canExecute() )
-    {
-      Log.abort("File " + exe + " is not executable", null);
-    }
-    final String swankDir = config.getAttribute(ATTR_SWANK, "");
-    File swankf = new File(swankDir,"swank-loader.lisp");
-    if( !swankf.exists() )
-    {
-      Log.abort("Swank was not found in folder "+swankDir, null);
-    }
-    final int port = config.getAttribute(ATTR_PORT, -1);
-    if( port < AvailablePortFinder.MIN_PORT_NUMBER
-        || port > AvailablePortFinder.MAX_PORT_NUMBER )
-    {
-      Log.abort("Port is outside of available range", null);
-    }
-    if( !AvailablePortFinder.available(port) )
-    {
-      Log.abort("Port "+port+" is not available", null);
-    }
-    @SuppressWarnings("rawtypes")
-    final LocalLispImplementation implem =
-      new LocalLispImplementation(exe, swankDir,
-          config.getAttribute(ATTR_CMD_PARAMS, new ArrayList()),
-          config.getAttribute(ATTR_ENV, new HashMap()),
-          port, config.getAttribute(ATTR_START_REPL_THREAD, false));
-    final String ext = config.getAttribute(ATTR_EXT, "");
-    final File extf = new File(ext);
-    if( !extf.isDirectory() )
-    {
-      Log.abort("Extensions directory "+ext+" does not exist", null);
-    }
-    final SwankInterface s = new SwankInterface(ext,implem,r);
-    //s.connect();
-
-    LispProcess p = new LispProcess(launch, config.getName(), null, s);
-    launch.addProcess(p);
-    launch.addDebugTarget(new LispDebugTarget(launch, p));
-    SwankPlugin.get().addProcess(p);
-    return p;
-  }
-
-  @Override
-  public void launch(ILaunchConfiguration configuration, String mode,
-      ILaunch launch, IProgressMonitor monitor) throws CoreException
-  {
-    Assert.isLegal(ILaunchManager.PROFILE_MODE.equals(mode), "Wrong mode");
-    launch(configuration,launch,new TestRunnableDriver());
-  }
-
-}