OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 179 → Rev 180

/trunk/OpenConcerto/src/org/openconcerto/utils/protocol/Helper.java
56,28 → 56,38
}
 
/**
* Wrap the passed URL into a {@link Handler jarjar} one. Needed since the jre cannot read files
* inside a jar inside a jar.
* Return a jar URL to the root of a jar file. Needed since the JRE cannot read files inside a
* jar inside a jar.
*
* @param u the URL to wrap, e.g. "jar:file:/C:/mylibs/Outer.jar!/Inner.jar".
* @return the wrapped URL, if necessary, i.e. if <code>u</code> references a jar in a jar, e.g.
* "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
* @return the wrapped URL, e.g. "jar:jarjar:file:/C:/mylibs/Outer.jar^/Inner.jar!/".
*/
public static final URL toJarJar(URL u) {
return toJarJar(u, "");
public static final URL intoJar(final URL u) {
return intoJar(u, "");
}
 
public static final URL toJarJar(final URL u, final String s) {
public static final URL intoJar(final URL u, final String s) {
if (!u.getPath().endsWith(".jar"))
throw new IllegalArgumentException("Doesn't end with .jar :" + u);
 
final URL res;
// if it's a jar inside another jar
if ("jar".equals(u.getProtocol()) && u.getPath().endsWith(".jar")) {
if ("jar".equals(u.getProtocol())) {
try {
return new URL("jar:jar" + u.toString().replace('!', '^') + "!/" + s);
res = new URL("jar:jar" + u.toExternalForm().replace('!', '^') + "!/" + s);
} catch (MalformedURLException e) {
// shouldn't happen since we modify a valid URL
throw new IllegalStateException("Couldn't transform " + u, e);
throw new IllegalStateException("Couldn't transform to jarjar " + u, e);
}
} else
return u;
} else {
try {
res = new URL("jar:" + u.toExternalForm() + "!/" + s);
} catch (MalformedURLException e) {
// shouldn't happen since constructed from a valid URL
throw new IllegalStateException("Couldn't transform to jar URL " + u, e);
}
}
return res;
}
 
}