Changeset 12612


Ignore:
Timestamp:
04/15/10 14:50:33 (14 years ago)
Author:
Mark Evenson
Message:

Incremental checkpoint on making JAR pathnames use the new URL pathname.

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

Legend:

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

    r12607 r12612  
    6969      result = result.push(rest.car());
    7070      if (rest.cdr() == NIL) {
    71         result = result.push(NIL);
    7271        break;
    7372      }
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r12608 r12612  
    9898                device = new Cons(NIL, NIL);
    9999                LispObject first = jars.car();
    100                 if (first instanceof SimpleString) {
    101                     ((Cons)device).car = new SimpleString(((SimpleString)first).getStringValue());
    102                 } else if (first instanceof Pathname) {
     100                if (first instanceof Pathname) {
    103101                    ((Cons)device).car = new Pathname((Pathname)first);
    104102                } else {
     
    214212    static final Symbol SCHEME = internKeyword("SCHEME");
    215213    static final Symbol AUTHORITY = internKeyword("AUTHORITY");
     214    static final Symbol QUERY = internKeyword("QUERY");
     215    static final Symbol FRAGMENT = internKeyword("FRAGMENT");
    216216
    217217    static final private String jarSeparator = "!/";
     
    249249                type = p.type;
    250250                version = p.version;
     251                invalidateNamestring();
    251252                return;
    252253            }
     
    266267                s = s.substring("jar:".length(), i + jarSeparator.length());
    267268                Pathname p = new Pathname(s);
    268                 LispObject first = ((Cons) p.device).car();
    269                 if (first instanceof AbstractString) {
    270                     jars = jars.push(first);
    271                 } else {
    272                     jars = jars.push(p.device.car());
    273                 }
     269                jars = jars.push(p.device.car());
    274270            }
    275271            if (jar.startsWith("jar:file:")) {
    276                 String jarString = jar.substring("jar:".length(),
    277                   jar.length() - jarSeparator.length());
     272                String jarString
     273                    = jar.substring("jar:".length(),
     274                                    jar.length() - jarSeparator.length());
    278275                // Use URL constructor to normalize Windows' use of device
    279276                URL url = null;
     
    286283                }
    287284                Pathname jarPathname = new Pathname(url);
    288                 if (jarString.endsWith(jarSeparator)) {
    289                     jars = jars.push(jarPathname.device);
    290                 } else {
    291                     jars = jars.push(jarPathname);
    292                 }
     285                jars = jars.push(jarPathname);
    293286            } else {
    294287                URL url = null;
    295288                try {
    296289                    url = new URL(jar.substring("jar:".length(), jar.length() - 2));
    297                     jars = jars.push(new SimpleString(url.toString()));
     290                    Pathname p = new Pathname(url);
     291                    jars = jars.push(p);
    298292                } catch (MalformedURLException e) {
    299                     error(new LispError("Failed to parse url '" + url + "'"
    300                       + e.getMessage()));
     293                    error(new LispError("Failed to parse URL "
     294                                        + "'" + url + "'"
     295                                        + e.getMessage()));
    301296                }
    302297            }
    303298            jars = jars.nreverse();
    304299            device = jars;
     300            invalidateNamestring();
    305301            return;
    306302        }
     
    336332            }
    337333            String scheme = url.getProtocol();
     334            if (scheme.equals("file")) {
     335                Pathname p = new Pathname(s);
     336                this.host = p.host;
     337                this.device = p.device;
     338                this.directory = p.directory;
     339                this.name = p.name;
     340                this.type = p.type;
     341                this.version = p.version;
     342                return;
     343            }
    338344            Debug.assertTrue(scheme != null);
    339345            String authority = url.getAuthority();
     
    345351            host = host.push(AUTHORITY);
    346352            host = host.push(new SimpleString(authority));
    347             host = host.nreverse();
    348353
    349354            device = NIL;
     
    365370            String query = uri.getRawQuery();
    366371            if (query != null) {
    367                 path += "?" + query;
     372                host = host.push(QUERY);
     373                host = host.push(new SimpleString(query));
    368374            }
    369375            String fragment = uri.getRawFragment();
    370376            if (fragment != null) {
    371                 path += "#" + fragment;
     377                host = host.push(FRAGMENT);
     378                host = host.push(new SimpleString(fragment));
    372379            }
    373380            Pathname p = new Pathname(path != null ? path : "");
     
    377384            type = p.type;
    378385           
     386            host = host.nreverse();
     387            invalidateNamestring();
    379388            return;
    380389        }
     
    613622        } else if (device instanceof Cons) {
    614623            LispObject[] jars = ((Cons) device).copyToArray();
    615             int i = 0;
    616             if (jars[0] instanceof AbstractString) {
    617                 sb.append("jar:");
    618                 sb.append(((AbstractString) jars[0]).getStringValue());
    619                 sb.append("!/");
    620                 i = 1;
    621             }
    622624            StringBuilder prefix = new StringBuilder();
    623             for (; i < jars.length; i++) {
     625            for (int i = 0; i < jars.length; i++) {
    624626                prefix.append("jar:");
    625                 if (i == 0) {
     627                if (!((Pathname)jars[i]).isURL() && i == 0) {
    626628                    sb.append("file:");
    627629                }
    628                 if (jars[i] instanceof Pathname) {
    629                     sb.append(((Pathname) jars[i]).getNamestring());
    630                 }
     630                sb.append(((Pathname) jars[i]).getNamestring());
    631631                sb.append("!/");
    632632            }
     
    679679            }
    680680        }
     681       
     682        if (isURL()) {
     683            LispObject o = Symbol.GETF.execute(host, QUERY, NIL);
     684            if (o != NIL) {
     685                sb.append("?");
     686                sb.append(o.getStringValue());
     687            }
     688            o = Symbol.GETF.execute(host, FRAGMENT, NIL);
     689            if (o != NIL) {
     690                sb.append("#");
     691                sb.append(o.getStringValue());
     692            }
     693        }
     694           
    681695        if (this instanceof LogicalPathname) {
    682696            if (version.integerp()) {
     
    695709        }
    696710        namestring = sb.toString();
    697         if (isURL()) {
     711        if (isURL()) { 
    698712            namestring = Utilities.uriEncode(namestring);
    699713        }
     
    14621476                SimpleString wildcardDirectory = new SimpleString(directory + "/");
    14631477
    1464                 ZipFile jar = ZipCache.get(pathname.device.car());
     1478                ZipFile jar = ZipCache.get((Pathname)pathname.device.car());
    14651479                LispObject matches;
    14661480                for (Enumeration<? extends ZipEntry> entries = jar.entries();
     
    15601574            final SimpleString wildcard = new SimpleString(wild);
    15611575
    1562             ZipFile jar = ZipCache.get(pathname.device.car());
     1576            ZipFile jar = ZipCache.get((Pathname)pathname.device.car());
    15631577
    15641578            for (Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements();) {
     
    19291943            Cons jars = (Cons) pathname.device;
    19301944            LispObject o = jars.car();
    1931             if (o instanceof Pathname) {
     1945            if (o instanceof Pathname && ! (((Pathname)o).isURL())) {
    19321946                LispObject truename = Pathname.truename((Pathname)o, errorIfDoesNotExist);
    19331947                if (truename != null
     
    19461960            // 3.  JAR with Entry
    19471961            // 4.  JAR in JAR with Entry
    1948             ZipFile jarFile = ZipCache.get(jars.car());
     1962            ZipFile jarFile = ZipCache.get((Pathname)jars.car());
    19491963            String entryPath = pathname.asEntryPath();
    19501964            if (jarFile != null) {
     
    20132027    }
    20142028
    2015     protected static URL makeURL(LispObject device) {
     2029    protected static URL makeURL(Pathname pathname) {
    20162030        URL result = null;
    20172031        try {
    2018         if (device instanceof SimpleString) {
    2019             result = new URL(((SimpleString)device).getStringValue());
    2020         } else {
    2021         // XXX ensure that we have cannonical path.
    2022             Pathname p = (Pathname)device;
    2023             result = new URL("file:" + p.getNamestring());
    2024         }
     2032            if (pathname.isURL()) {
     2033                result = new URL(pathname.getNamestring());
     2034            } else {
     2035                // XXX ensure that we have cannonical path.
     2036                result = new URL("file://" + pathname.getNamestring());
     2037            }
    20252038        } catch (MalformedURLException e) {
    2026             Debug.trace("Could not form URL from " + device);
     2039            Debug.trace("Could not form URL from " + pathname);
    20272040        }
    20282041        return result;
     
    20352048            // XXX We only return the bytes of an entry in a JAR
    20362049            Debug.assertTrue(entryPath != null);
    2037             ZipFile jarFile = ZipCache.get(device.car());
     2050            ZipFile jarFile = ZipCache.get((Pathname)device.car());
    20382051            Debug.assertTrue(jarFile != null);
    20392052            // Is this a JAR within a JAR?
     
    20642077                result = url.openStream();
    20652078            } catch (IOException e) {
    2066                 error(new FileError("Failed to get InputStream from "
    2067                                     + "'" + Utilities.escapeFormat(getNamestring()) + "'"
    2068                                     + ": " + e,
    2069                                     this));
     2079                Debug.trace("Failed to get InputStream from "
     2080                            + "'" + getNamestring() + "'"
     2081                            + ": " + e);
    20702082            }
    20712083        } else {
     
    20742086                result = new FileInputStream(file);
    20752087            } catch (IOException e) {
    2076                 error(new FileError("Failed to get InputStream from "
    2077                                     + "'" + getNamestring() + "'"
    2078                                     + ": " + e, this));
     2088                Debug.trace("Failed to get InputStream from "
     2089                            + "'" + getNamestring() + "'"
     2090                            + ": " + e);
    20792091            }
    20802092        }
     
    21032115                if (entryPath.length() == 0) {
    21042116                    LispObject o = d.car();
    2105                     if (o instanceof SimpleString) {
    21062117                        // 0. JAR from URL
    2107                         // URL u = makeJarURL(o.getStringValue());
    2108                         // XXX unimplemented
    2109                         Debug.assertTrue(false);
    2110                         // URLConnection c = null;
    2111                         // try {
    2112                         //   c = u.openConnection();
    2113                         // } catch(IOException e) {
    2114                         //   Debug.trace("Failed to open Connection for URL "
    2115                         //               + "'" + u + "'");
    2116                         //   return 0;
    2117                         // }
    2118                         // c.getLastModified();
    2119                     } else  { 
    21202118                        // 1. JAR
    2121                         return ((Pathname)o).getLastModified();
    2122                     }
     2119                    return ((Pathname)o).getLastModified();
    21232120                } else {
    21242121                    // 3. Entry in JAR
    21252122                    final ZipEntry entry
    2126                         = ZipCache.get(device.car()).getEntry(entryPath);
     2123                        = ZipCache.get((Pathname)device.car()).getEntry(entryPath);
    21272124                    if (entry == null) {
    21282125                        return 0;
     
    21352132                }
    21362133            } else {
    2137                 ZipFile outerJar = ZipCache.get(d.car());
     2134                ZipFile outerJar = ZipCache.get((Pathname)d.car());
    21382135                if (entryPath.length() == 0) {
    21392136                    // 4.  JAR in JAR
     
    22102207                error(new FileError("Bad place for a wild pathname.", newName));
    22112208            }
     2209            if (original.isJar()) {
     2210                error(new FileError("Bad place for a jar pathname.", original));
     2211            }
     2212            if (newName.isJar()) {
     2213                error(new FileError("Bad place for a jar pathname.", newName));
     2214            }
     2215            if (original.isURL()) {
     2216                error(new FileError("Bad place for a URL pathname.", original));
     2217            }
     2218            if (newName.isURL()) {
     2219                error(new FileError("Bad place for a jar pathname.", newName));
     2220            }
     2221               
    22122222            newName = mergePathnames(newName, original, NIL);
    22132223            final String newNamestring;
     
    22732283        @Override
    22742284        public LispObject execute(LispObject arg) {
    2275             return coerceToPathname(arg).host;
     2285            return coerceToPathname(arg).host; // XXX URL-PATHNAME
    22762286        }
    22772287    }
  • trunk/abcl/src/org/armedbear/lisp/Utilities.java

    r12607 r12612  
    152152
    153153  public static InputStream getEntryAsInputStream(ZipInputStream zipInputStream,
    154                                                     String entryName)
     154                                                  String entryName)
    155155    {
    156156        ZipEntry entry = getEntry(zipInputStream, entryName);
     
    255255    }
    256256
    257 
    258257    static String uriEncode(String s) {
    259258        try {
  • trunk/abcl/src/org/armedbear/lisp/ZipCache.java

    r12607 r12612  
    9898    static HashMap<URL, Entry> zipCache = new HashMap<URL, Entry>();
    9999
    100     synchronized public static ZipFile get(LispObject arg) {
    101         return get(Pathname.makeURL(arg));
     100    synchronized public static ZipFile get(Pathname p) {
     101        return get(Pathname.makeURL(p));
    102102    }
    103103
Note: See TracChangeset for help on using the changeset viewer.