Add helper method to relativize repository URIs

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@615560 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
index 9c0e627..b9421a4 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUtils.java
@@ -100,4 +100,27 @@
         }
         return null;
     }
+
+
+    /**
+     * @param repositoryXml URI pointing to repository.xml
+     * @param bundlePath local path to bundle jarfile
+     * @return relative path to bundle jarfile
+     */
+    public static String relativize( URI repositoryXml, String bundlePath )
+    {
+        try
+        {
+            String repositoryPath = repositoryXml.getPath();
+            int index = repositoryPath.lastIndexOf( '/' );
+
+            URI rootURI = new URI( null, repositoryPath.substring( 0, index ), null );
+
+            return rootURI.relativize( new URI( null, bundlePath, null ) ).toASCIIString();
+        }
+        catch ( Exception e )
+        {
+            return bundlePath;
+        }
+    }
 }