aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-10-31 07:36:34 +0100
committerSven Gothel <[email protected]>2013-10-31 07:36:34 +0100
commit2a6a6bb1df175847a7bb84bd741ce3632d6590f6 (patch)
tree5f431b7185c2138014e0d2aefe6fe092a6190a06 /src/java/com/jogamp/common/util
parent9622dd60d2572257b1497370dad7230898ee592d (diff)
Bug 754 - JarUtil: Add method to generate resource URI from class's Jar URI and resource name (Remove Ubuntu fonts from jogl-all.jar, provide it separately to reduce footprint for the masses.)
Diffstat (limited to 'src/java/com/jogamp/common/util')
-rw-r--r--src/java/com/jogamp/common/util/JarUtil.java66
-rw-r--r--src/java/com/jogamp/common/util/cache/TempJarCache.java2
2 files changed, 68 insertions, 0 deletions
diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java
index b5f8850..8897496 100644
--- a/src/java/com/jogamp/common/util/JarUtil.java
+++ b/src/java/com/jogamp/common/util/JarUtil.java
@@ -473,6 +473,72 @@ public class JarUtil {
}
/**
+ * Locates the {@link JarUtil#getJarFileURI(URI) Jar file URI} of a given resource
+ * relative to a given class's Jar's URI.
+ * <pre>
+ * class's jar url path + cutOffInclSubDir + relResPath,
+ * </pre>
+ * Example #1
+ * <pre>
+ * classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar)
+ * cutOffInclSubDir = lights/
+ * relResPath = LightAssets.jar
+ * Result : file:/storage/lights/LightAssets.jar
+ * </pre>
+ * Example #2
+ * <pre>
+ * classFromJavaJar = com.lighting.Test (in: file:/storage/lights/TestLighting.jar)
+ * cutOffInclSubDir = lights/
+ * relResPath = LightAssets.jar
+ * Result : file:/storage/lights/LightAssets.jar
+ * </pre>
+ *
+ * TODO: Enhance documentation!
+ *
+ * @param classFromJavaJar Used to get the root URI for the class's Jar URI.
+ * @param cutOffInclSubDir The <i>cut off</i> included sub-directory prepending the relative resource path.
+ * If the root URI includes cutOffInclSubDir, it is no more added to the result.
+ * @param relResPath The relative resource path.
+ * @return The resulting resource URI, which is not tested.
+ * @throws IllegalArgumentException
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public static URI getRelativeOf(Class<?> classFromJavaJar, String cutOffInclSubDir, String relResPath) throws IllegalArgumentException, IOException, URISyntaxException {
+ final ClassLoader cl = classFromJavaJar.getClassLoader();
+ final URI classJarURI = JarUtil.getJarURI(classFromJavaJar.getName(), cl);
+ if( DEBUG ) {
+ System.err.println("JarUtil.getRelativeOf: "+"(classFromJavaJar "+classFromJavaJar+", classJarURI "+classJarURI+
+ ", cutOffInclSubDir "+cutOffInclSubDir+", relResPath "+relResPath+"): ");
+ }
+
+ final URI jarSubURI = JarUtil.getJarSubURI( classJarURI );
+ if(null == jarSubURI) {
+ throw new IllegalArgumentException("JarSubURI is null of: "+classJarURI);
+ }
+ final String jarUriRoot_s = IOUtil.getURIDirname( jarSubURI.toString() );
+ if( DEBUG ) {
+ System.err.println("JarUtil.getRelativeOf: "+"uri "+jarSubURI.toString()+" -> "+jarUriRoot_s);
+ }
+
+ final String resUri_s;
+ if( jarUriRoot_s.endsWith(cutOffInclSubDir) ) {
+ resUri_s = jarUriRoot_s+relResPath;
+ } else {
+ resUri_s = jarUriRoot_s+cutOffInclSubDir+relResPath;
+ }
+ if( DEBUG ) {
+ System.err.println("JarUtil.getRelativeOf: "+"... -> "+resUri_s);
+ }
+
+ final URI resURI = JarUtil.getJarFileURI(resUri_s);
+ if( DEBUG ) {
+ System.err.println("JarUtil.getRelativeOf: "+"fin "+resURI);
+ }
+ return resURI;
+ }
+
+ /**
* Return a map from native-lib-base-name to entry-name.
*/
public static Map<String, String> getNativeLibNames(JarFile jarFile) {
diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java
index c127314..99bb272 100644
--- a/src/java/com/jogamp/common/util/cache/TempJarCache.java
+++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java
@@ -397,6 +397,7 @@ public class TempJarCache {
return null;
} */
+ /** Similar to {@link ClassLoader#getResource(String)}. */
public synchronized static final String findResource(String name) {
checkInitialized();
final File f = new File(tmpFileCache.getTempDir(), name);
@@ -406,6 +407,7 @@ public class TempJarCache {
return null;
}
+ /** Similar to {@link ClassLoader#getResource(String)}. */
public synchronized static final URI getResource(String name) throws URISyntaxException {
checkInitialized();
final File f = new File(tmpFileCache.getTempDir(), name);