FELIX-580: support deployment of OBR metadata using prefixed URLs (-DprefixUrl=http://...) or absolute URLs (-DbundleUrl=http://...)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@682034 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java
index a0fb276..2ac3bfa 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java
@@ -21,6 +21,7 @@
 
 import java.io.File;
 import java.net.URI;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -55,6 +56,20 @@
     private boolean ignoreLock;
 
     /**
+     * Optional public URL prefix for the remote repository.
+     *
+     * @parameter expression="${prefixUrl}"
+     */
+    private String prefixUrl;
+
+    /**
+     * Optional public URL where the bundle has been deployed.
+     *
+     * @parameter expression="${bundleUrl}"
+     */
+    private String bundleUrl;
+
+    /**
      * Remote OBR Repository.
      * 
      * @parameter expression="${remoteOBR}" default-value="NONE"
@@ -90,6 +105,13 @@
     private String altDeploymentRepository;
 
     /**
+     * OBR specific deployment repository. Format: id::layout::url
+     * 
+     * @parameter expression="${obrDeploymentRepository}"
+     */
+    private String obrDeploymentRepository;
+
+    /**
      * Local Repository.
      * 
      * @parameter expression="${localRepository}"
@@ -205,6 +227,20 @@
 
             Config userConfig = new Config();
             userConfig.setRemoteFile( true );
+            
+            if ( bundleUrl != null )
+            {
+                // public URL differs from the bundle file location
+                userConfig.setRemoteBundle( URI.create( bundleUrl ) );
+            }
+            else if ( prefixUrl != null )
+            {
+                // support absolute bundle URLs based on given prefix
+                URI bundleJar = ObrUtils.getArtifactURI( localRepository, project.getArtifact() );
+                String relative = ObrUtils.getRelativeURI( ObrUtils.toFileURI( mavenRepository ),  bundleJar).toASCIIString();
+                URL resourceURL = new URL( new URL( prefixUrl + '/' ), relative );
+                userConfig.setRemoteBundle( resourceURL.toURI() );
+            }
 
             update = new ObrUpdate( repositoryXml, obrXmlFile, project, mavenRepository, userConfig, log );
             update.parseRepositoryXml();
@@ -247,6 +283,12 @@
 
     private void openRepositoryConnection( RemoteFileManager remoteFile ) throws MojoExecutionException
     {
+        // use OBR specific deployment location?
+        if ( obrDeploymentRepository != null )
+        {
+            altDeploymentRepository = obrDeploymentRepository;
+        }
+
         if ( deploymentRepository == null && altDeploymentRepository == null )
         {
             String msg = "Deployment failed: repository element was not specified in the pom inside"
diff --git a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java
index 7bfd93c..868a380 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrRemoteClean.java
@@ -82,11 +82,11 @@
     private boolean ignoreLock;
     
     /**
-     * Public URL prefix for the remote repository.
+     * Optional public URL prefix for the remote repository.
      *
-     * @parameter expression="${prefixURL}"
+     * @parameter expression="${prefixUrl}"
      */
-    private String prefixURL;
+    private String prefixUrl;
 
     /**
      * Remote OBR Repository.
@@ -124,6 +124,13 @@
     private String altDeploymentRepository;
 
     /**
+     * OBR specific deployment repository. Format: id::layout::url
+     *
+     * @parameter expression="${obrDeploymentRepository}"
+     */
+    private String obrDeploymentRepository;
+
+    /**
      * The Maven project.
      * 
      * @parameter expression="${project}"
@@ -179,9 +186,9 @@
 
         RemoteFileManager remoteFile = new RemoteFileManager( m_wagonManager, settings, log );
         openRepositoryConnection( remoteFile );
-        if ( null == prefixURL || prefixURL.trim().length() == 0 )
+        if ( null == prefixUrl )
         {
-            prefixURL = remoteFile.toString();
+            prefixUrl = remoteFile.toString();
         }
 
         // ======== LOCK REMOTE OBR ========
@@ -240,6 +247,12 @@
 
     private void openRepositoryConnection( RemoteFileManager remoteFile ) throws MojoExecutionException
     {
+        // use OBR specific deployment location?
+        if ( obrDeploymentRepository != null )
+        {
+            altDeploymentRepository = obrDeploymentRepository;
+        }
+
         if ( deploymentRepository == null && altDeploymentRepository == null )
         {
             String msg = "Deployment failed: repository element was not specified in the pom inside"
@@ -286,7 +299,7 @@
 
             URL url;
             try {
-                url = new URL(prefixURL + '/' + value);
+                url = new URL( new URL( prefixUrl + '/' ), value);
             } catch (MalformedURLException e) {
                 getLog().error("Malformed URL when creating the resource absolute URI : " + e.getMessage());
                 return null;