Commits

sk  committed 026919c

- Removed SBCL implementation - instead use LocalLispImplementation.
- Fixed tests.

  • Participants
  • Parent commits bdfcb80

Comments (0)

Files changed (2)

File src/org/lispdev/swank/SBCLImplementation.java

-package org.lispdev.swank;
-
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-
-/**
- * This is a class for finding and starting Steel Bank Common Lisp. Static
- * methods are provided for finding an SBCL implementation on the system.
- *
- * An instance of this class can be used for spawning SBCL processes and
- * starting them up.
- *
- * @author Red Daly
- */
-public class SBCLImplementation extends LispImplementation
-{
-
-  /**
-   *
-   * @return the executable SBCL file on the host computer
-   */
-  static public File findExecutable(String pluginDir)
-  {
-    File implementafoltionFolder = findFolder(pluginDir);
-    if( implementafoltionFolder != null )
-    {
-      String os = System.getProperty("os.name").toLowerCase();
-      String execName;
-      if( os.contains("windows") ) execName = "sbcl.exe";
-      else execName = "sbcl";
-      File possibleExecutable =
-          new File(implementafoltionFolder.getPath() + File.separator
-              + execName);
-
-      if( possibleExecutable.exists() ) return possibleExecutable;
-      else return null;
-    }
-    else
-    {
-      // TODO: just default to whatever happens when you type `sbcl' into bash
-      return null;
-    }
-  }
-
-  /**
-   *
-   * @return the SBCL directory on the host computer
-   */
-  public static File findFolder(String pluginDir)
-  {
-    File sbclFolder = new File(pluginDir + "sbcl/");
-    if( sbclFolder.exists() )
-    {
-      System.out.println(">>> Found default sbcl folder: "
-          + sbclFolder.toString());
-      return sbclFolder;
-    }
-    else
-    {
-
-      File pluginsFolder = new File(pluginDir).getParentFile();
-
-      sbclFolder = new File(pluginsFolder.getPath() + "/sbcl/");
-
-      if( sbclFolder.exists() )
-      {
-        System.out.println(">>> Found next default sbcl folder: "
-            + sbclFolder.toString());
-        return sbclFolder;
-      }
-      else
-      {
-        // This filter only returns directories that start with sbcl
-        FileFilter dirFilter = new FileFilter(){
-          public boolean accept(File file)
-          {
-            return (file.isDirectory() && file.getName().startsWith("sbcl"));
-          }
-        };
-
-        ArrayList<File> sbclFolders = new ArrayList<File>();
-
-        for(File dir : pluginsFolder.listFiles(dirFilter))
-        {
-          System.out.println(">>> Possible sbcl folder: " + dir.toString());
-          sbclFolders.add(dir);
-        }
-
-        if( sbclFolders.size() > 0 )
-        {
-          Collections.sort(sbclFolders);
-
-          sbclFolder =
-              new File(sbclFolders.get(sbclFolders.size() - 1).toString()
-                  + "/sbcl/");
-          System.out.println(">>> Found feature sbcl folder: "
-              + sbclFolder.toString());
-          return sbclFolder;
-        }
-        else
-        {
-          String dir = System.getenv("SBCL_HOME");
-          if( dir != null )
-          {
-            sbclFolder = new File(dir);
-            System.out.println(">>> Found SBCL_HOME sbcl folder: "
-                + sbclFolder.toString());
-            return sbclFolder;
-          }
-        }
-
-        System.out.println(">>> Did not find sbcl folder");
-        return null;
-      }
-    }
-  }
-
-  /**
-   * Attempts to find and return an SBCL implementation on the system.
-   *
-   * @return SBCL implementation found on the system, or null if none is found
-   */
-  static public SBCLImplementation findImplementation(String pluginDir)
-  {
-    File executable = findExecutable(pluginDir);
-    File dir = findFolder(pluginDir);
-    File loadP = new File(pluginDir + "slime/swank-loader.lisp");
-    if( executable != null && dir != null )
-    {
-      try
-      {
-        return new SBCLImplementation(executable, dir,
-            loadP.getCanonicalPath(), 4005);
-      }
-      catch(IOException e)
-      {
-        e.printStackTrace();
-      }
-    }
-    return null;
-  }
-
-  private final File executable;
-  private final File path;
-  private final String loadPath;
-  private final int port;
-
-  /**
-   * Constructs an instance of an SBCL implementation. Does NOT start an SBCL
-   * process, or find an SBCL implementation on the host machine.
-   *
-   * @see start()
-   * @see
-   * @param executable
-   * @param sbclDirectory
-   */
-  public SBCLImplementation(File executable, File sbclDirectory,
-      String loadPath, int port)
-  {
-    this.executable = executable;
-    this.path = sbclDirectory;
-    this.loadPath = loadPath;
-    this.port = port;
-  }
-
-  public String quietCompilationWrap(String msg)
-  {
-    return "(locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note)) "
-        + msg + ")";
-  }
-
-  @Override
-  public Process start() throws IOException
-  {
-    ProcessBuilder pb;
-    String[] commandLine = new String[]{executable.getPath()
-    // ,"--dynamic-space-size", "50000" // simulate the error some windows
-    // users get
-         ,"--load", loadPath
-        };
-
-    pb = new ProcessBuilder(commandLine);
-    pb.environment().put("SBCL_HOME", path.getPath());
-    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;
-  }
-}

File src/org/lispdev/swank/SwankInterfaceTest.java

 {
   private SwankInterface si = null;
 
-  private static final String dir =
-    "D:\\projects\\lispdev\\ws\\org.lispdev.swank\\";
-
   public SwankInterfaceTest()
   {
-    super(dir,4005,SBCLImplementation.findImplementation(dir));
+    super(null,0,null);
   }
 
   private static SwankInterface startSwank()
       synchronized(callBack)
       {
         si.sendCompileString("(defun g (x)\n  (z x))\n\n(defun z (x)\n  (y x))\n",
-            "test.lisp", extDir, 0, "nil", callBack);
+            "test.lisp", si.extDir, 0, "nil", callBack);
         callBack.wait(1000);
       } // sync
     }
         {
           synchronized(callBack)
           {
-            si.sendCompileString("(g 3)\n", "test.lisp", extDir, 40, "nil",
+            si.sendCompileString("(g 3)\n", "test.lisp", si.extDir, 40, "nil",
                 callBack);
             callBack.wait(1000);
           } // sync
       synchronized(callBack)
       {
         si.sendCompileString("(defun f (x)\n  (+ 2 (g x)))\n", "test.lisp",
-            extDir, 0, "nil", callBack);
+            si.extDir, 0, "nil", callBack);
         callBack.wait(1000);
       } // sync
     }
         {
           synchronized(callBack)
           {
-            si.sendCompileString("(f 4)\n", "test.lisp", extDir, 25, "nil",
+            si.sendCompileString("(f 4)\n", "test.lisp", si.extDir, 25, "nil",
                 callBack);
             callBack.wait(1000);
           } // sync
     return callBack.getReturn().getf(":swank-compilation-unit")
       .getf(":message").value.equals("undefined function: G")
       && callBack.getReturn().getf(":swank-compilation-unit")
-          .toString().contains(extDir + "test.lisp") ;
+          .toString().contains(si.extDir + "test.lisp") ;
   }
 
   // run it to find out which buffer to use in previous test
     {
       synchronized(callBack)
       {
-        si.sendCompileString("(defun g (x)\n  (+ 2 x))\n", "test.lisp", extDir,
+        si.sendCompileString("(defun g (x)\n  (+ 2 x))\n", "test.lisp", si.extDir,
             0, "nil", callBack);
         callBack.wait(1000);
       } // sync
       synchronized(callBack)
       {
         si.sendCompileString("(defun f (x)\n  (+ 2 (g x)))\n", "test.lisp",
-            extDir, 25, "nil", callBack);
+            si.extDir, 25, "nil", callBack);
         callBack.wait(1000);
       } // sync
     }
     } // catch
 
     assertEquals("G", callBack.getReturn().get(0).get(0).value);
-    assertEquals(extDir + "test.lisp", callBack.getReturn().get(0).get(1)
+    assertEquals(si.extDir + "test.lisp", callBack.getReturn().get(0).get(1)
       .getf(":location").getf(":buffer").value);
     assertEquals("1",
         callBack.getReturn().get(0).get(1).getf(":position").value);
     // was not able to finish in time alloted (see callBack.wait() after
     // sendGetCallers()
     assertEquals("F", callBack.getReturn().get(0).get(0).value);
-    assertEquals(extDir + "test.lisp", callBack.getReturn().get(0).get(1)
+    assertEquals(si.extDir + "test.lisp", callBack.getReturn().get(0).get(1)
       .getf(":location").getf(":buffer").value);
     assertEquals("26",
         callBack.getReturn().get(0).get(1).getf(":position").value);
     {
       synchronized(callBack)
       {
-        si.sendCompileString("(defun g (x)\n  (+ 2 x))", "test.lisp", extDir,
+        si.sendCompileString("(defun g (x)\n  (+ 2 x))", "test.lisp", si.extDir,
             0, "nil", callBack);
         callBack.wait(1000);
       } // sync
     } // catch
 
     assertEquals("(DEFUN G)", callBack.getReturn().get(0).get(0).value);
-    assertEquals(extDir + "test.lisp", callBack.getReturn().get(0).get(1)
+    assertEquals(si.extDir + "test.lisp", callBack.getReturn().get(0).get(1)
       .getf(":location").getf(":buffer").value);
     assertEquals("1",
         callBack.getReturn().get(0).get(1).getf(":position").value);
     {
       synchronized(callBack)
       {
-        si.sendCompileString("(defun g (x)\n  (+ 1 x))", "test.lisp", extDir,
+        si.sendCompileString("(defun g (x)\n  (+ 1 x))", "test.lisp", si.extDir,
             0, "nil", callBack);
         callBack.wait(1000);
       } // sync
     {
       synchronized(callBack)
       {
-        si.sendCompileString("(defun g (x)\n  (+ 1 x))", "test.lisp", extDir,
+        si.sendCompileString("(defun g (x)\n  (+ 1 x))", "test.lisp", si.extDir,
             0, "nil", callBack);
         callBack.wait(1000);
       } // sync
     {
       synchronized(callBack)
       {
-        si.sendCompileFile(extDir + "test.lisp", callBack);
+        si.sendCompileFile(si.extDir + "test.lisp", callBack);
         callBack.wait(1000);
       } // sync
     }
   @Test
   public void test_basicStartup()
   {
-    String res = si.basicStartup(false, null, extDir);
+    String res = si.basicStartup(false, null, si.extDir);
     assertEquals(true,res.startsWith("\"You are running SBCL 1.0."));
   }