Changeset 15394


Ignore:
Timestamp:
10/10/20 21:43:26 (3 years ago)
Author:
Mark Evenson
Message:

Starting to hook jar/uri mechanisms up

Failing to roundtrip

(pathname "jar:jar:file:foo.jar!/baz.abcl!/")

Location:
trunk/abcl
Files:
3 edited

Legend:

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

    r15393 r15394  
    19141914      return (Pathname) arg;
    19151915    if (arg instanceof AbstractString)
    1916       return Pathname.parseNamestring((AbstractString)arg);
     1916      return (Pathname)Pathname.parseNamestring((AbstractString)arg);
    19171917    if (arg instanceof FileStream)
    19181918      return ((FileStream)arg).getPathname();
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r15393 r15394  
    5050public class Pathname extends LispObject implements Serializable {
    5151
    52   protected static Pathname create(Pathname p) {
    53     return new Pathname(p);
    54   }
    55 
    5652  protected static Pathname create() {
    5753    return new Pathname();
    5854  }
    5955
     56  protected static Pathname create(Pathname p) {
     57    if (p instanceof PathnameJar) {
     58      return (PathnameJar)PathnameJar.create(p.getNamestring());
     59    } else if (p instanceof PathnameURL) {
     60      return (PathnameURL)PathnameURL.create(((PathnameURL)p).getNamestringAsURI());
     61    } else {
     62      return new Pathname(p);
     63    }
     64  }
     65
    6066  public static LispObject create(String s) {
    6167    // TODO distinguish between logical hosts and schemes for URLs
    6268    // which we can meaningfully parse.
    63     if (!isValidURL(s)) {
     69
     70    if (s.startsWith(PathnameJar.JAR_URI_PREFIX)) {
     71        return PathnameJar.create(s);
     72    }
     73    if (isValidURL(s)) {
     74      return PathnameURL.create(s);
     75    } else {
    6476      if (LogicalPathname.isValidLogicalPathname(s)) {
    6577        return LogicalPathname.create(s);
    6678      }
    6779    }
    68     return new Pathname(s);
     80    Pathname result = new Pathname();
     81    result.init(s);
     82    return result;
    6983  }
    7084
     
    673687    @Override
    674688    public LispObject typeOf() {
    675         if (isURL()) {
    676             return Symbol.URL_PATHNAME;
    677         }
    678         if (isJar()) {
    679             return Symbol.JAR_PATHNAME;
    680         }
    681         return Symbol.PATHNAME;
     689      if (isJar()) {
     690        return Symbol.JAR_PATHNAME;
     691      }
     692      if (isURL()) {
     693        return Symbol.URL_PATHNAME;
     694      }
     695      return Symbol.PATHNAME;
    682696    }
    683697
    684698    @Override
    685699    public LispObject classOf() {
    686         if (isURL()) {
    687             return BuiltInClass.URL_PATHNAME;
    688         }
    689         if (isJar()) {
    690             return BuiltInClass.JAR_PATHNAME;
    691         }
    692         return BuiltInClass.PATHNAME;
     700      if (isJar()) {
     701        return BuiltInClass.JAR_PATHNAME;
     702      }
     703      if (isURL()) {
     704        return BuiltInClass.URL_PATHNAME;
     705      }
     706      return BuiltInClass.PATHNAME;
    693707    }
    694708
     
    11221136        return true;
    11231137    }
    1124 
    1125 //    public static URL toURL(Pathname p) {
    1126  //       try {
    1127 //            return p.toURL();
    1128 //        } catch (MalformedURLException e) {
    1129 //            Debug.assertTrue(false);
    1130 //            return null; // not reached
    1131 //        }
    1132 //    }
    11331138
    11341139    URLConnection getURLConnection() {
     
    24182423                result = new URL(pathname.getNamestring());
    24192424            } else {
    2420                 // XXX Properly encode Windows drive letters and UNC paths
    2421                 // XXX ensure that we have cannonical path?
    2422                 result = new URL("file://" + pathname.getNamestring());
     2425              // XXX Properly encode Windows drive letters and UNC paths
     2426              // XXX ensure that we have cannonical path?
     2427              String ns = pathname.getNamestring();
     2428              if (ns.startsWith("/"))  {
     2429                result = new URL("file://" + ns);
     2430              } else { // "relative" path
     2431                result = new URL("file:" + ns);
     2432              }
    24232433            }
    24242434        } catch (MalformedURLException e) {
     
    28322842        }
    28332843    }
    2834 
    2835   // BEGIN REMOVE ME use standard Factory pattern create() method instead
    2836   public static Pathname make(String s) {
    2837     Pathname p = Pathname.create();
    2838     p.init(s);
    2839     return p;
    2840   }
    2841 
    2842   public static Pathname makeFrom(Pathname p) {
    2843     return Pathname.create(p);
    2844   }
    2845 
    2846   public static Pathname makeFrom(Pathname p, String s) {
    2847     p.init(s);
    2848     return p;
    2849   }
    2850   // END REMOVE ME
    28512844}
    2852 
  • trunk/abcl/test/src/org/armedbear/lisp/PathnameJarTest.java

    r15393 r15394  
    22
    33import java.util.List;
     4import java.text.MessageFormat;
    45import org.junit.After;
    56import org.junit.AfterClass;
     
    6768  }
    6869
     70  @Test
     71  public void roundTrips() {
     72    String namestrings[] = {
     73      "jar:file:foo.jar!/",
     74      "jar:jar:file:foo.jar!/baz.abcl!/",
     75      "jar:jar:file:foo.jar!/baz.abcl!/__loader__._"
     76    };
     77
     78    for (String namestring  : namestrings) {
     79      Pathname result = (Pathname) Pathname.create(namestring);
     80      String resultingNamestring = result.getNamestring();
     81      String message = MessageFormat.format("Namestring \"{0}\" failed to roundtrip", namestring);
     82      assertTrue(message,
     83                 namestring.equals(resultingNamestring));
     84    }
     85  }
     86
     87  @Test
     88  public void invalidNamestrings() {
     89    String namestrings[] = {
     90      "jar:file:foo.jar!/baz.abcl!/",
     91      "jar:file:foo.jar!/baz.abcl!/__loader__._"
     92    };
     93
     94    // JUnit 4.12 (which is what is available in Netbeans 12) doesn't
     95    // have an assertion about throwing an error.
     96    for (String namestring  : namestrings) {
     97      try {
     98        Pathname.create(namestring);
     99      } catch (Throwable t) {
     100        String message = MessageFormat.format("Namestring \"{0}\" is invalid throwing: {1}",
     101                                              namestring,
     102                                              t.getCause());
     103        assertTrue(message, true);
     104      }
     105    }
     106  }
    69107}
Note: See TracChangeset for help on using the changeset viewer.