Commits

Anonymous committed b744c40

Added LocalLispLauncher.

Comments (0)

Files changed (2)

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.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+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;
+
+public class LocalLispLaunchDelegate extends LaunchConfigurationDelegate
+    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();
+    s.initParams(new SwankRunnableDriver(), ext, implem);
+
+    LispProcess p = new LispProcess(launch, "swank", null, s);
+    launch.addProcess(p);
+    launch.addDebugTarget(new LispDebugTarget(launch, p));
+  }
+
+}