aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/JarUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/common/util/JarUtil.java')
-rw-r--r--src/java/com/jogamp/common/util/JarUtil.java83
1 files changed, 61 insertions, 22 deletions
diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java
index 5604c3d..29e7dc7 100644
--- a/src/java/com/jogamp/common/util/JarUtil.java
+++ b/src/java/com/jogamp/common/util/JarUtil.java
@@ -53,6 +53,8 @@ import jogamp.common.Debug;
public class JarUtil {
private static final boolean DEBUG = Debug.debug("JarUtil");
+ private static final int BUFFER_SIZE = 4096;
+
/**
* Interface allowing users to provide an URL resolver that will convert custom classloader
* URLs like Eclipse/OSGi <i>bundleresource:</i> URLs to normal <i>jar:</i> URLs.
@@ -138,8 +140,9 @@ public class JarUtil {
throw new IllegalArgumentException("null arguments: clazzBinName "+clazzBinName+", cl "+cl);
}
final URI uri;
+ final URL url;
{
- final URL url = IOUtil.getClassURL(clazzBinName, cl);
+ url = IOUtil.getClassURL(clazzBinName, cl);
final String scheme = url.getProtocol();
if( null != resolver &&
!scheme.equals( IOUtil.JAR_SCHEME ) &&
@@ -163,6 +166,9 @@ public class JarUtil {
if( !uri.getScheme().equals( IOUtil.JAR_SCHEME ) ) {
throw new IllegalArgumentException("URI is not using scheme "+IOUtil.JAR_SCHEME+": <"+uri+">");
}
+ if(DEBUG) {
+ System.out.println("getJarURI res: "+clazzBinName+" -> "+url+" -> "+uri);
+ }
return uri;
}
@@ -187,7 +193,7 @@ public class JarUtil {
if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) {
throw new IllegalArgumentException("URI is not using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">");
}
- String uriS = classJarURI.getRawSchemeSpecificPart();
+ String uriS = classJarURI.getSchemeSpecificPart();
// from
// file:/some/path/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
@@ -264,26 +270,27 @@ public class JarUtil {
if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) {
throw new IllegalArgumentException("URI is not a using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">");
}
- String uriS = classJarURI.getRawSchemeSpecificPart();
// from
// file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
// to
// file:/some/path/gluegen-rt.jar
- int idx = uriS.lastIndexOf('!');
+ final String uriS0 = classJarURI.getSchemeSpecificPart();
+ int idx = uriS0.lastIndexOf('!');
+ final String uriS1;
if (0 <= idx) {
- uriS = uriS.substring(0, idx); // exclude '!/'
+ uriS1 = uriS0.substring(0, idx); // exclude '!/'
} else {
throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">");
}
-
- if(0 >= uriS.lastIndexOf(".jar")) {
+ if(0 >= uriS1.lastIndexOf(".jar")) {
throw new IllegalArgumentException("No Jar name in <"+classJarURI+">");
- }
+ }
+ final String uriS2 = IOUtil.encodeToURI(uriS1);
if(DEBUG) {
- System.out.println("getJarSubURI res: "+uriS);
+ System.out.println("getJarSubURI res: "+classJarURI+" -> "+uriS0+" -> "+uriS1+" -> "+uriS2);
}
- return new URI(uriS);
+ return new URI(uriS2);
}
/**
@@ -302,7 +309,7 @@ public class JarUtil {
if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) {
throw new IllegalArgumentException("URI is not a using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">");
}
- String uriS = classJarURI.getRawSchemeSpecificPart();
+ String uriS = classJarURI.getSchemeSpecificPart();
// from
// file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
@@ -391,6 +398,19 @@ public class JarUtil {
}
/**
+ * @param jarSubUriS file:/some/path/gluegen-rt.jar
+ * @return jar:file:/some/path/gluegen-rt.jar!/
+ * @throws IllegalArgumentException null arguments
+ * @throws URISyntaxException
+ */
+ public static URI getJarFileURI(String jarSubUriS) throws IllegalArgumentException, URISyntaxException {
+ if(null == jarSubUriS) {
+ throw new IllegalArgumentException("jarSubURIS is null");
+ }
+ return new URI(IOUtil.JAR_SCHEME, jarSubUriS+"!/", null);
+ }
+
+ /**
* @param jarFileURI jar:file:/some/path/gluegen-rt.jar!/
* @param jarEntry com/jogamp/common/GlueGenVersion.class
* @return jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
@@ -499,22 +519,23 @@ public class JarUtil {
* @param dest
* @param nativeLibMap
* @param jarFile
- * @param deepDirectoryTraversal
+ * @param nativeLibraryPath if not null, only extracts native libraries within this path.
* @param extractNativeLibraries
* @param extractClassFiles
* @param extractOtherFiles
+ * @param deepDirectoryTraversal
* @return
* @throws IOException
*/
public static final int extract(File dest, Map<String, String> nativeLibMap,
JarFile jarFile,
+ String nativeLibraryPath,
boolean extractNativeLibraries,
- boolean extractClassFiles,
- boolean extractOtherFiles) throws IOException {
+ boolean extractClassFiles, boolean extractOtherFiles) throws IOException {
if (DEBUG) {
System.err.println("JarUtil: extract: "+jarFile.getName()+" -> "+dest+
- ", extractNativeLibraries "+extractNativeLibraries+
+ ", extractNativeLibraries "+extractNativeLibraries+" ("+nativeLibraryPath+")"+
", extractClassFiles "+extractClassFiles+
", extractOtherFiles "+extractOtherFiles);
}
@@ -528,11 +549,29 @@ public class JarUtil {
// Match entries with correct prefix and suffix (ignoring case)
final String libBaseName = NativeLibrary.isValidNativeLibraryName(entryName, false);
final boolean isNativeLib = null != libBaseName;
- if(isNativeLib && !extractNativeLibraries) {
- if (DEBUG) {
- System.err.println("JarUtil: JarEntry : " + entryName + " native-lib skipped");
+ if(isNativeLib) {
+ if(!extractNativeLibraries) {
+ if (DEBUG) {
+ System.err.println("JarUtil: JarEntry : " + entryName + " native-lib skipped, skip all native libs");
+ }
+ continue;
+ }
+ if(null != nativeLibraryPath) {
+ final String nativeLibraryPathS;
+ final String dirnameS;
+ try {
+ nativeLibraryPathS = IOUtil.slashify(nativeLibraryPath, false /* startWithSlash */, true /* endWithSlash */);
+ dirnameS = IOUtil.getDirname(entryName);
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+ if( !nativeLibraryPathS.equals(dirnameS) ) {
+ if (DEBUG) {
+ System.err.println("JarUtil: JarEntry : " + entryName + " native-lib skipped, not in path: "+nativeLibraryPathS);
+ }
+ continue;
+ }
}
- continue;
}
final boolean isClassFile = entryName.endsWith(".class");
@@ -566,20 +605,20 @@ public class JarUtil {
if (DEBUG) {
System.err.println("JarUtil: MKDIR: " + entryName + " -> " + destFile );
}
- destFile.mkdir();
+ destFile.mkdirs();
} else {
final File destFolder = new File(destFile.getParent());
if(!destFolder.exists()) {
if (DEBUG) {
System.err.println("JarUtil: MKDIR (parent): " + entryName + " -> " + destFolder );
}
- destFolder.mkdir();
+ destFolder.mkdirs();
}
final InputStream in = new BufferedInputStream(jarFile.getInputStream(entry));
final OutputStream out = new BufferedOutputStream(new FileOutputStream(destFile));
int numBytes = -1;
try {
- numBytes = IOUtil.copyStream2Stream(in, out, -1);
+ numBytes = IOUtil.copyStream2Stream(BUFFER_SIZE, in, out, -1);
} finally {
in.close();
out.close();