From e96f9b0c05b9fd5e47f55c2079271d6969a27a80 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 20 May 2023 14:31:39 +0200 Subject: JarUtil.getRelativeOf(): Make'cutOffInclSubDir' optional, i.e. ignore if null in case no sub-directory is desired --- src/java/com/jogamp/common/util/JarUtil.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/java/com/jogamp/common') diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index d621e1c..9dc0fb6 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -418,14 +418,25 @@ public class JarUtil { *
      *   class's jar url path + cutOffInclSubDir + relResPath,
      * 
+ * or with cutOffInclSubDir being null just + *
+     *   class's jar url path + relResPath,
+     * 
* Example #1 *
      *   classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar)
+     *   cutOffInclSubDir = null
+     *   relResPath       = LightAssets.jar
+     *   Result           : file:/storage/LightAssets.jar
+     * 
+ * Example #2 + *
+     *   classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar)
      *   cutOffInclSubDir = lights/
      *   relResPath       = LightAssets.jar
      *   Result           : file:/storage/lights/LightAssets.jar
      * 
- * Example #2 + * Example #3 *
      *   classFromJavaJar = com.lighting.Test (in: file:/storage/lights/TestLighting.jar)
      *   cutOffInclSubDir = lights/
@@ -436,8 +447,9 @@ public class JarUtil {
      * TODO: Enhance documentation!
      *
      * @param classFromJavaJar Used to get the root Uri for the class's Jar Uri.
-     * @param cutOffInclSubDir The cut off included sub-directory prepending the relative resource path.
+     * @param cutOffInclSubDir Optional cut off included sub-directory prepending the relative resource path.
      *                         If the root Uri includes cutOffInclSubDir, it is no more added to the result.
+     *                         Parameter will be ignored if null.
      * @param relResPath The relative resource path. (Uri encoded)
      * @return The resulting resource Uri, which is not tested.
      * @throws IllegalArgumentException
@@ -451,7 +463,6 @@ public class JarUtil {
             System.err.println("JarUtil.getRelativeOf: "+"(classFromJavaJar "+classFromJavaJar+", classJarUri "+classJarUri+
                     ", cutOffInclSubDir "+cutOffInclSubDir+", relResPath "+relResPath+"): ");
         }
-
         final Uri jarSubUri = classJarUri.getContainedUri();
         if(null == jarSubUri) {
             throw new IllegalArgumentException("JarSubUri is null of: "+classJarUri);
@@ -460,9 +471,8 @@ public class JarUtil {
         if( DEBUG ) {
             System.err.println("JarUtil.getRelativeOf: "+"uri "+jarSubUri.toString()+" -> "+jarUriRoot);
         }
-
         final Uri.Encoded resUri;
-        if( jarUriRoot.endsWith(cutOffInclSubDir.get()) ) {
+        if( null == cutOffInclSubDir || jarUriRoot.endsWith(cutOffInclSubDir.get()) ) {
             resUri = jarUriRoot.concat(relResPath);
         } else {
             resUri = jarUriRoot.concat(cutOffInclSubDir).concat(relResPath);
@@ -470,7 +480,6 @@ public class JarUtil {
         if( DEBUG ) {
             System.err.println("JarUtil.getRelativeOf: "+"...  -> "+resUri);
         }
-
         final Uri resJarUri = JarUtil.getJarFileUri(resUri);
         if( DEBUG ) {
             System.err.println("JarUtil.getRelativeOf: "+"fin "+resJarUri);
-- 
cgit v1.2.3