Changeset 12524


Ignore:
Timestamp:
03/11/10 15:49:05 (13 years ago)
Author:
Mark Evenson
Message:

Enable ABCL to load in an OSGi context.

OSGi abstracts the loading of resources via the "bundle:" URI schema,
providing a custom URLProtocolHandler implementation. Unfortunately,
since these references cannot be handled by ABCL pathnames, the newly
revised logic for our FASL loading strategy breaks down. This patch
kludingly addresses this issue to the point that ABCL can be loaded by
reference in an OSGi bundle, but should be revised when a correct
implementation strategy is decided upon.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Debug.java

    r12441 r12524  
    4242    {
    4343        if (!b) {
    44             System.err.println("Assertion failed!");
    45             Error e = new Error();
     44            String msg = "ABCL Debug.assertTrue() assertion failed!";
     45            System.err.println(msg);
     46            Error e = new Error(msg);
    4647            e.printStackTrace();
    4748            throw e;
  • trunk/abcl/src/org/armedbear/lisp/Lisp.java

    r12516 r12524  
    12271227          load = Pathname.mergePathnames(name, (Pathname) truename, Keyword.NEWEST);
    12281228      } else {
    1229           load = name;
    1230       }
    1231       InputStream input = load.getInputStream();
     1229          if (!Pathname.truename(name).equals(NIL)) {
     1230              load = name;
     1231          } else {
     1232              load = null;
     1233          }
     1234      }
     1235      InputStream input = null;
     1236      if (load != null) {
     1237          input = load.getInputStream();
     1238      } else {
     1239          // Make a last-ditch attempt to load from the boot classpath XXX OSGi hack
     1240          URL url = null;
     1241          try {
     1242              url = Lisp.class.getResource(name.getNamestring());
     1243              input = url.openStream();
     1244          } catch (IOException e) {
     1245              error(new LispError("Failed to read class bytes from boot class " + url));
     1246          }
     1247      }
    12321248      byte[] bytes = new byte[4096];
    12331249      try {
    12341250          if (input == null) {
    1235               Debug.trace("Pathname: " + name);
    1236               Debug.trace("LOAD_TRUENAME_FASL: " + truenameFasl);
    1237               Debug.trace("LOAD_TRUENAME: " + truename);
    1238               Debug.assertTrue(input != null);
     1251                  Debug.trace("Pathname: " + name);
     1252                  Debug.trace("LOAD_TRUENAME_FASL: " + truenameFasl);
     1253                  Debug.trace("LOAD_TRUENAME: " + truename);
     1254                  Debug.assertTrue(input != null);
    12391255          }
    12401256
  • trunk/abcl/src/org/armedbear/lisp/Load.java

    r12513 r12524  
    253253        Pathname truename = null;
    254254        pathname = new Pathname(filename);
    255         Pathname mergedPathname = Pathname.mergePathnames(pathname, Site.getLispHome());
     255        LispObject bootPath = Site.getLispHome();
     256        Pathname mergedPathname;
     257        if (bootPath instanceof Pathname) {
     258            mergedPathname = Pathname.mergePathnames(pathname, (Pathname)bootPath);
     259        } else {
     260            mergedPathname = pathname;
     261        }
     262        URL url = null;
    256263        truename = findLoadableFile(mergedPathname);
    257         if (truename == null || truename.equals(NIL)) {
     264        if (truename == null || truename.equals(NIL) || bootPath.equals(NIL)) {
    258265            // Make an attempt to use the boot classpath
    259266            String path = pathname.asEntryPath();
    260             URL url = Lisp.class.getResource(path);
     267            url = Lisp.class.getResource(path);
    261268            if (url == null || url.toString().endsWith("/")) {
    262269                url = Lisp.class.getResource(path + ".abcl");
     
    270277                                           + " in boot classpath."));
    271278            }               
    272             Pathname urlPathname = new Pathname(url);
    273             truename = findLoadableFile(urlPathname);
    274             if (truename == null) {
    275                 return error(new LispError("Failed to find loadable system file in boot classpath "
    276                                            + "'" + url + "'"));
     279            if (!bootPath.equals(NIL)) {
     280                Pathname urlPathname = new Pathname(url);
     281                truename = findLoadableFile(urlPathname);
     282                if (truename == null) {
     283                    return error(new LispError("Failed to find loadable system file in boot classpath "
     284                                               + "'" + url + "'"));
     285                }
     286            } else {
     287                truename = null; // We can't represent the FASL in a Pathname (q.v. OSGi)
    277288            }
    278289        }
    279290
    280291        // Look for a init FASL inside a packed FASL
    281         if (truename.type.writeToString().equals(COMPILE_FILE_TYPE) && Utilities.checkZipFile(truename))  {
     292        if (truename != null
     293            && truename.type.writeToString().equals(COMPILE_FILE_TYPE) && Utilities.checkZipFile(truename))  {
    282294            Pathname init = new Pathname(truename.getNamestring());
    283295            init.type = COMPILE_FILE_INIT_FASL_TYPE;
     
    291303        }
    292304
    293         in = truename.getInputStream();
     305        if (truename != null) {
     306            in = truename.getInputStream();
     307        } else {
     308            try {
     309                Debug.assertTrue(url != null);
     310                in = url.openStream();
     311            } catch (IOException e) {
     312                error(new FileError("Failed to load system file: "
     313                                    + "'" + filename + "'"
     314                                    + " from URL: "
     315                                    + "'" + url + "'"));
     316            }
     317        }
    294318
    295319        if (in != null) {
     
    374398                                                       boolean auto)
    375399        {
    376         return loadFileFromStream(pathname, truename, in, verbose, print, auto, false);
     400            return loadFileFromStream(pathname == null ? NIL : pathname,
     401                                      truename == null ? NIL : truename,
     402                                      in, verbose, print, auto, false);
    377403    }
    378404
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r12513 r12524  
    152152    }
    153153
     154    public static boolean isSupportedProtocol(String protocol) {
     155        return "jar".equals(protocol) || "file".equals(protocol);
     156    }
     157
    154158    public Pathname(URL url) {
    155159        String protocol = url.getProtocol();
     160        if (!isSupportedProtocol(protocol)) {
     161            error(new LispError("Unsupported URL: '" + url.toString() + "'"));
     162        }
     163
    156164        if ("jar".equals(protocol)) {
    157165            init(url.toString());
     
    182190            }
    183191        }
    184         error(new LispError("Unsupported URL: '" + url.toString() + "'"));
     192        error(new LispError("Failed to construct Pathname from URL: "
     193                            + "'" + url.toString() + "'"));
    185194    }
    186195
  • trunk/abcl/src/org/armedbear/lisp/Site.java

    r12422 r12524  
    4343public final class Site
    4444{
    45     private static Pathname LISP_HOME;
     45    private static LispObject LISP_HOME;
    4646
    4747    private static void init() {
     
    5050            String fileSeparator = System.getProperty("file.separator");
    5151            if (!s.endsWith(fileSeparator)) {
    52                 s += fileSeparator;;
     52                s += fileSeparator;
    5353            }
    5454            LISP_HOME = new Pathname(s);
    55             return;
    5655        }
    5756        URL url = Lisp.class.getResource("boot.lisp");
    5857        if (url != null) {
    59             LISP_HOME = new Pathname(url);
    60             LISP_HOME.name = NIL;
    61             LISP_HOME.type = NIL;
    62             LISP_HOME.invalidateNamestring();
     58            if (!Pathname.isSupportedProtocol(url.getProtocol())) {
     59                LISP_HOME = NIL;
     60            } else {
     61                Pathname p = new Pathname(url);
     62                p.name = NIL;
     63                p.type = NIL;
     64                p.invalidateNamestring();
     65                LISP_HOME = p;
     66            }
    6367            return;
    6468        }
     
    6670    }
    6771
    68 
    69     public static final Pathname getLispHome()
     72    public static final LispObject getLispHome()
    7073    {
    7174      if (LISP_HOME == null) {
     
    8083
    8184    static {
    82         Pathname p  = Site.getLispHome();
     85        LispObject p  = Site.getLispHome();
    8386        if (p != null)
    8487            _LISP_HOME_.setSymbolValue(p);
Note: See TracChangeset for help on using the changeset viewer.