FELIX-491: handle classifier in OBR install/deploy goals

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@628824 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
index 732d7f0..981fcb5 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
@@ -361,6 +361,12 @@
         builder.setProperties( properties );
         builder.setClasspath( classpath );
 
+        if ( null != classifier && classifier.trim().length() > 0 )
+        {
+            String bundleVersion = properties.getProperty( Analyzer.BUNDLE_VERSION );
+            properties.put( Analyzer.BUNDLE_VERSION, bundleVersion + '-' + classifier );
+        }
+
         if ( !properties.containsKey( Analyzer.EXPORT_PACKAGE ) && !properties.containsKey( Analyzer.PRIVATE_PACKAGE ) )
         {
             String bsn = properties.getProperty( Analyzer.BUNDLE_SYMBOLICNAME );
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 60db94f..3f4b5d5 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrDeploy.java
@@ -22,10 +22,12 @@
 import java.io.File;
 import java.net.URI;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
@@ -106,6 +108,13 @@
     private MavenProject project;
 
     /**
+     * @parameter expression="${project.attachedArtifacts}
+     * @required
+     * @readonly
+     */
+    private List attachedArtifacts;
+
+    /**
      * Local Maven settings.
      * 
      * @parameter expression="${settings}"
@@ -145,7 +154,6 @@
         String repositoryName = new File( tempURI.getPath() ).getName();
 
         Log log = getLog();
-        ObrUpdate update;
 
         RemoteFileManager remoteFile = new RemoteFileManager( m_wagonManager, settings, log );
         openRepositoryConnection( remoteFile );
@@ -165,14 +173,12 @@
 
             URI repositoryXml = downloadedRepositoryXml.toURI();
             URI obrXmlFile = ObrUtils.findObrXml( project.getResources() );
-            URI bundleJar = ObrUtils.findBundleJar( localRepository, project.getArtifact() );
 
-            Config userConfig = new Config();
-            userConfig.setRemoteFile( true );
-
-            update = new ObrUpdate( repositoryXml, obrXmlFile, project, bundleJar, mavenRepository, userConfig, log );
-
-            update.updateRepository();
+            updateRemoteBundleMetadata( project.getArtifact(), repositoryXml, obrXmlFile, mavenRepository );
+            for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
+            {
+                updateRemoteBundleMetadata( ( Artifact ) i.next(), repositoryXml, obrXmlFile, mavenRepository );
+            }
 
             if ( downloadedRepositoryXml.exists() )
             {
@@ -230,4 +236,24 @@
             remoteFile.connect( deploymentRepository.getId(), deploymentRepository.getUrl() );
         }
     }
+
+
+    private void updateRemoteBundleMetadata( Artifact artifact, URI repoXml, URI obrXml, String mavenRepo )
+        throws MojoExecutionException
+    {
+        if ( null == artifact.getFile() || artifact.getFile().isDirectory() )
+        {
+            return;
+        }
+
+        getLog().info( "Updating: " + artifact );
+
+        URI bundleJar = ObrUtils.findBundleJar( localRepository, artifact );
+
+        Config userConfig = new Config();
+        userConfig.setRemoteFile( true );
+
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, project, bundleJar, mavenRepo, userConfig, getLog() );
+        update.updateRepository();
+    }
 }
diff --git a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java
index e96d0c4..ddcc8f0 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrInstall.java
@@ -21,14 +21,13 @@
 
 import java.net.URI;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
-import org.apache.felix.obrplugin.Config;
-import org.apache.felix.obrplugin.ObrUpdate;
-import org.apache.felix.obrplugin.ObrUtils;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
 
 
@@ -75,6 +74,13 @@
      */
     private MavenProject project;
 
+    /**
+     * @parameter expression="${project.attachedArtifacts}
+     * @required
+     * @readonly
+     */
+    private List attachedArtifacts;
+
 
     public void execute()
     {
@@ -89,26 +95,41 @@
             return;
         }
 
-        Log log = getLog();
-        ObrUpdate update;
-
         try
         {
             String mavenRepository = localRepository.getBasedir();
 
             URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository );
             URI obrXmlFile = ObrUtils.findObrXml( project.getResources() );
-            URI bundleJar = ObrUtils.findBundleJar( localRepository, project.getArtifact() );
 
-            Config userConfig = new Config();
-
-            update = new ObrUpdate( repositoryXml, obrXmlFile, project, bundleJar, mavenRepository, userConfig, log );
-
-            update.updateRepository();
+            updateLocalBundleMetadata( project.getArtifact(), repositoryXml, obrXmlFile, mavenRepository );
+            for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); )
+            {
+                updateLocalBundleMetadata( ( Artifact ) i.next(), repositoryXml, obrXmlFile, mavenRepository );
+            }
         }
         catch ( Exception e )
         {
-            log.warn( "Exception while updating local OBR: " + e.getLocalizedMessage(), e );
+            getLog().warn( "Exception while updating local OBR: " + e.getLocalizedMessage(), e );
         }
     }
+
+
+    private void updateLocalBundleMetadata( Artifact artifact, URI repoXml, URI obrXml, String mavenRepo )
+        throws MojoExecutionException
+    {
+        if ( null == artifact.getFile() || artifact.getFile().isDirectory() )
+        {
+            return;
+        }
+
+        getLog().info( "Updating: " + artifact );
+
+        URI bundleJar = ObrUtils.findBundleJar( localRepository, artifact );
+
+        Config userConfig = new Config();
+
+        ObrUpdate update = new ObrUpdate( repoXml, obrXml, project, bundleJar, mavenRepo, userConfig, getLog() );
+        update.updateRepository();
+    }
 }