OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 180
Line 54... Line 54...
54
            }
54
            }
55
        });
55
        });
56
    }
56
    }
57
 
57
 
58
    /**
58
    /**
59
     * Wrap the passed URL into a {@link Handler jarjar} one. Needed since the jre cannot read files
59
     * Return a jar URL to the root of a jar file. Needed since the JRE cannot read files inside a
60
     * inside a jar inside a jar.
60
     * jar inside a jar.
61
     * 
61
     * 
62
     * @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".
63
     * @return the wrapped URL, if necessary, i.e. if <code>u</code> references a jar in a jar, e.g.
-
 
64
     *         "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
63
     * @return the wrapped URL, e.g. "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
65
     */
64
     */
66
    public static final URL toJarJar(URL u) {
65
    public static final URL intoJar(final URL u) {
67
        return toJarJar(u, "");
66
        return intoJar(u, "");
68
    }
67
    }
69
 
68
 
70
    public static final URL toJarJar(final URL u, final String s) {
69
    public static final URL intoJar(final URL u, final String s) {
-
 
70
        if (!u.getPath().endsWith(".jar"))
-
 
71
            throw new IllegalArgumentException("Doesn't end with .jar :" + u);
-
 
72
 
-
 
73
        final URL res;
71
        // if it's a jar inside another jar
74
        // if it's a jar inside another jar
72
        if ("jar".equals(u.getProtocol()) && u.getPath().endsWith(".jar")) {
75
        if ("jar".equals(u.getProtocol())) {
73
            try {
76
            try {
74
                return new URL("jar:jar" + u.toString().replace('!', '^') + "!/" + s);
77
                res = new URL("jar:jar" + u.toExternalForm().replace('!', '^') + "!/" + s);
75
            } catch (MalformedURLException e) {
78
            } catch (MalformedURLException e) {
76
                // shouldn't happen since we modify a valid URL
79
                // shouldn't happen since we modify a valid URL
77
                throw new IllegalStateException("Couldn't transform " + u, e);
80
                throw new IllegalStateException("Couldn't transform to jarjar " + u, e);
-
 
81
            }
-
 
82
        } else {
-
 
83
            try {
-
 
84
                res = new URL("jar:" + u.toExternalForm() + "!/" + s);
-
 
85
            } catch (MalformedURLException e) {
-
 
86
                // shouldn't happen since constructed from a valid URL
-
 
87
                throw new IllegalStateException("Couldn't transform to jar URL " + u, e);
-
 
88
            }
78
            }
89
        }
79
        } else
-
 
80
            return u;
90
        return res;
81
    }
91
    }
82
 
92
 
83
}
93
}