Changeset 15394
- Timestamp:
- 10/10/20 21:43:26 (3 years ago)
- Location:
- trunk/abcl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/Lisp.java
r15393 r15394 1914 1914 return (Pathname) arg; 1915 1915 if (arg instanceof AbstractString) 1916 return Pathname.parseNamestring((AbstractString)arg);1916 return (Pathname)Pathname.parseNamestring((AbstractString)arg); 1917 1917 if (arg instanceof FileStream) 1918 1918 return ((FileStream)arg).getPathname(); -
trunk/abcl/src/org/armedbear/lisp/Pathname.java
r15393 r15394 50 50 public class Pathname extends LispObject implements Serializable { 51 51 52 protected static Pathname create(Pathname p) {53 return new Pathname(p);54 }55 56 52 protected static Pathname create() { 57 53 return new Pathname(); 58 54 } 59 55 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 60 66 public static LispObject create(String s) { 61 67 // TODO distinguish between logical hosts and schemes for URLs 62 68 // 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 { 64 76 if (LogicalPathname.isValidLogicalPathname(s)) { 65 77 return LogicalPathname.create(s); 66 78 } 67 79 } 68 return new Pathname(s); 80 Pathname result = new Pathname(); 81 result.init(s); 82 return result; 69 83 } 70 84 … … 673 687 @Override 674 688 public LispObject typeOf() { 675 if (isURL()) {676 return Symbol.URL_PATHNAME;677 }678 if (isJar()) {679 return Symbol.JAR_PATHNAME;680 }681 689 if (isJar()) { 690 return Symbol.JAR_PATHNAME; 691 } 692 if (isURL()) { 693 return Symbol.URL_PATHNAME; 694 } 695 return Symbol.PATHNAME; 682 696 } 683 697 684 698 @Override 685 699 public LispObject classOf() { 686 if (isURL()) {687 return BuiltInClass.URL_PATHNAME;688 }689 if (isJar()) {690 return BuiltInClass.JAR_PATHNAME;691 }692 700 if (isJar()) { 701 return BuiltInClass.JAR_PATHNAME; 702 } 703 if (isURL()) { 704 return BuiltInClass.URL_PATHNAME; 705 } 706 return BuiltInClass.PATHNAME; 693 707 } 694 708 … … 1122 1136 return true; 1123 1137 } 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 reached1131 // }1132 // }1133 1138 1134 1139 URLConnection getURLConnection() { … … 2418 2423 result = new URL(pathname.getNamestring()); 2419 2424 } 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 } 2423 2433 } 2424 2434 } catch (MalformedURLException e) { … … 2832 2842 } 2833 2843 } 2834 2835 // BEGIN REMOVE ME use standard Factory pattern create() method instead2836 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 ME2851 2844 } 2852 -
trunk/abcl/test/src/org/armedbear/lisp/PathnameJarTest.java
r15393 r15394 2 2 3 3 import java.util.List; 4 import java.text.MessageFormat; 4 5 import org.junit.After; 5 6 import org.junit.AfterClass; … … 67 68 } 68 69 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 } 69 107 }
Note: See TracChangeset
for help on using the changeset viewer.