Line 24... |
Line 24... |
24 |
public class Helper {
|
24 |
public class Helper {
|
25 |
|
25 |
|
26 |
static private final PropertyList PL = new PropertyList("java.protocol.handler.pkgs", "|");
|
26 |
static private final PropertyList PL = new PropertyList("java.protocol.handler.pkgs", "|");
|
27 |
|
27 |
|
28 |
static final public void register() {
|
28 |
static final public void register() {
|
29 |
// works even if setURLStreamHandlerFactory() is called (as long as the factoy returns null
|
29 |
// Works even if setURLStreamHandlerFactory() is called (as long as the factory returns null
|
30 |
// for our protocols)
|
30 |
// for our protocols)
|
- |
|
31 |
// On Java 11, there's also URLStreamHandlerProvider
|
31 |
PL.add(Helper.class.getPackage().getName());
|
32 |
PL.add(Helper.class.getPackage().getName());
|
32 |
}
|
33 |
}
|
33 |
|
34 |
|
- |
|
35 |
static final public void unregister() {
|
- |
|
36 |
PL.remove(Helper.class.getPackage().getName());
|
- |
|
37 |
}
|
- |
|
38 |
|
34 |
/**
|
39 |
/**
|
35 |
* Set the {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory) factory} to add our
|
40 |
* Set the {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory) factory} to add our
|
36 |
* protocols. This is needed for example in web start when one of our url is embedded into a
|
41 |
* protocols. This is needed for example in web start when one of our url is embedded into a
|
37 |
* library supplied one. E.g. "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/" will cause the
|
42 |
* library supplied one. E.g. "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/" will cause the
|
38 |
* jar Handler to try to create a jarjar URL but its classloader cannot access our classes
|
43 |
* jar Handler to try to create a jarjar URL but its classloader cannot access our classes
|
Line 57... |
Line 62... |
57 |
* @param u the URL to wrap, e.g. "jar:file:/C:/mylibs/Outer.jar!/Inner.jar".
|
62 |
* @param u the URL to wrap, e.g. "jar:file:/C:/mylibs/Outer.jar!/Inner.jar".
|
58 |
* @return the wrapped URL, if necessary, i.e. if <code>u</code> references a jar in a jar, e.g.
|
63 |
* @return the wrapped URL, if necessary, i.e. if <code>u</code> references a jar in a jar, e.g.
|
59 |
* "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
|
64 |
* "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
|
60 |
*/
|
65 |
*/
|
61 |
public static final URL toJarJar(URL u) {
|
66 |
public static final URL toJarJar(URL u) {
|
- |
|
67 |
return toJarJar(u, "");
|
- |
|
68 |
}
|
- |
|
69 |
|
- |
|
70 |
public static final URL toJarJar(final URL u, final String s) {
|
62 |
// if it's a jar inside another jar
|
71 |
// if it's a jar inside another jar
|
63 |
if ("jar".equals(u.getProtocol()) && u.getPath().endsWith(".jar")) {
|
72 |
if ("jar".equals(u.getProtocol()) && u.getPath().endsWith(".jar")) {
|
64 |
try {
|
73 |
try {
|
65 |
return new URL("jar:jar" + u.toString().replace('!', '^') + "!/");
|
74 |
return new URL("jar:jar" + u.toString().replace('!', '^') + "!/" + s);
|
66 |
} catch (MalformedURLException e) {
|
75 |
} catch (MalformedURLException e) {
|
67 |
// shouldn't happen since we modify a valid URL
|
76 |
// shouldn't happen since we modify a valid URL
|
68 |
throw new IllegalStateException("Couldn't transform " + u, e);
|
77 |
throw new IllegalStateException("Couldn't transform " + u, e);
|
69 |
}
|
78 |
}
|
70 |
} else
|
79 |
} else
|