Refactor code to re-use maven-obr-plugin utility methods

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@615731 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/pom.xml b/bundleplugin/pom.xml
index 700d8b2..c8df17b 100644
--- a/bundleplugin/pom.xml
+++ b/bundleplugin/pom.xml
@@ -44,7 +44,7 @@
   <dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-obr-plugin</artifactId>
-   <version>1.1.0-SNAPSHOT</version>
+   <version>1.2.0-SNAPSHOT</version>
   </dependency>
   <dependency>
    <groupId>biz.aQute</groupId>
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
index b51c42c..5b9109a 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
@@ -89,15 +89,9 @@
             URI repositoryXml = ObrUtils.findRepositoryXml( project.getBasedir(), mavenRepository, obrRepository );
             URI obrXml = ObrUtils.findObrXml( project.getResources() );
 
-            String obrXmlPath = null;
-            if ( null != obrXml )
-            {
-                obrXmlPath = obrXml.getPath();
-            }
-
             Config userConfig = new Config();
 
-            update = new ObrUpdate( new PathFile( repositoryXml.getPath() ), obrXmlPath, project, bundlePath,
+            update = new ObrUpdate( new PathFile( repositoryXml.getPath() ), obrXml, project, bundlePath,
                 mavenRepository, userConfig, log );
 
             update.updateRepository();
diff --git a/maven-obr-plugin/pom.xml b/maven-obr-plugin/pom.xml
index dc1a867..6b7beb9 100644
--- a/maven-obr-plugin/pom.xml
+++ b/maven-obr-plugin/pom.xml
@@ -28,7 +28,7 @@
   <modelVersion>4.0.0</modelVersion>
 
   <artifactId>maven-obr-plugin</artifactId>
-  <version>1.1.0-SNAPSHOT</version>
+  <version>1.2.0-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
   
   <name>OBR Maven Plugin</name>
@@ -46,7 +46,7 @@
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.osgi.service.obr</artifactId>
-      <version>1.0.0</version>
+      <version>1.1.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
@@ -64,4 +64,4 @@
       <version>2.0.7</version>
     </dependency>
   </dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
index 83a847d..ec76b6d 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeploy.java
@@ -24,11 +24,10 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
-import java.util.List;
+import java.net.URI;
 
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -128,22 +127,12 @@
         ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
 
         // locate the obr.xml file
-        String obrXmlFile = null;
-        List l = m_project.getResources();
-        for ( int i = 0; i < l.size(); i++ )
-        {
-            File f = new File( ( ( Resource ) l.get( i ) ).getDirectory() + File.separator + "obr.xml" );
-            if ( f.exists() )
-            {
-                obrXmlFile = ( ( Resource ) l.get( i ) ).getDirectory() + File.separator + "obr.xml";
-                break;
-            }
-        }
+        URI obrXml = ObrUtils.findObrXml( m_project.getResources() );
 
         // the obr.xml file is not present
-        if ( obrXmlFile == null )
+        if ( null == obrXml )
         {
-            getLog().warn( "obr.xml is not present, use default" );
+            getLog().info( "obr.xml is not present, use default" );
         }
 
         File repoDescriptorFile = null;
@@ -305,7 +294,7 @@
 
         file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
 
-        ObrUpdate obrUpdate = new ObrUpdate( file, obrXmlFile, m_project, m_fileInLocalRepo, PathFile
+        ObrUpdate obrUpdate = new ObrUpdate( file, obrXml, m_project, m_fileInLocalRepo, PathFile
             .uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
 
         obrUpdate.updateRepository();
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
index 2f7f6b5..31dd639 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
@@ -24,6 +24,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
+import java.net.URI;
 
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -120,10 +121,10 @@
         ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
 
         // locate the obr.xml file
-        PathFile fileObrXml = new PathFile( m_obrFile );
-        if ( !fileObrXml.isExists() )
+        URI obrXml = ObrUtils.toFileURI( m_obrFile );
+        if ( null == obrXml )
         {
-            getLog().warn( "obr.xml file not found, use default" );
+            getLog().info( "obr.xml is not present, use default" );
         }
 
         File repoDescriptorFile = null;
@@ -285,8 +286,8 @@
 
         file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
 
-        ObrUpdate obrUpdate = new ObrUpdate( file, fileObrXml.getOnlyAbsoluteFilename(), m_project, m_fileInLocalRepo,
-            PathFile.uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
+        ObrUpdate obrUpdate = new ObrUpdate( file, obrXml, m_project, m_fileInLocalRepo, PathFile
+            .uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
 
         obrUpdate.updateRepository();
 
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
index bce9414..f31855d 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
@@ -20,10 +20,9 @@
 
 
 import java.io.File;
-import java.util.List;
+import java.net.URI;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
@@ -106,7 +105,7 @@
         if ( m_repositoryPath == null )
         {
             m_repositoryPath = "file:/" + m_localRepo.getBasedir() + File.separator + "repository.xml";
-            getLog().warn( "-DpathRepo is not define, use default repository: " + m_repositoryPath );
+            getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath );
         }
 
         PathFile file = new PathFile( m_repositoryPath );
@@ -119,21 +118,12 @@
         }
 
         // locate the obr.xml file
-        String obrXmlFile = null;
-        List l = m_project.getResources();
-        for ( int i = 0; i < l.size(); i++ )
-        {
-            File f = new File( ( ( Resource ) l.get( i ) ).getDirectory() + File.separator + "obr.xml" );
-            if ( f.exists() )
-            {
-                obrXmlFile = ( ( Resource ) l.get( i ) ).getDirectory() + File.separator + "obr.xml";
-                break;
-            }
-        }
+        URI obrXml = ObrUtils.findObrXml( m_project.getResources() );
+
         // the obr.xml file is not present
-        if ( obrXmlFile == null )
+        if ( null == obrXml )
         {
-            getLog().warn( "obr.xml is not present, use default" );
+            getLog().info( "obr.xml is not present, use default" );
         }
 
         // get the path to local maven repository
@@ -173,9 +163,9 @@
         Config user = new Config();
 
         getLog().debug( "Maven2 Local File repository = " + fileRepo.getAbsoluteFilename() );
-        getLog().debug( "OBR repository = " + obrXmlFile );
+        getLog().debug( "OBR repository = " + obrXml );
 
-        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXmlFile, m_project, m_fileInLocalRepo, PathFile
+        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, m_fileInLocalRepo, PathFile
             .uniformSeparator( m_settings.getLocalRepository() ), user, getLog() );
         try
         {
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
index 1ef7a78..4d1638a 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
@@ -20,6 +20,7 @@
 
 
 import java.io.File;
+import java.net.URI;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
@@ -112,8 +113,6 @@
      */
     public void execute() throws MojoExecutionException, MojoFailureException
     {
-        getLog().info( "Install-File Obr starts:" );
-
         m_project = new MavenProject();
         m_project.setArtifactId( m_artifactId );
         m_project.setGroupId( m_groupId );
@@ -164,7 +163,7 @@
         if ( m_repositoryPath == null )
         {
             m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
-            getLog().warn( "-DpathRepo is not define, use default repository: " + m_repositoryPath );
+            getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath );
         }
 
         PathFile fileRepo = new PathFile( m_repositoryPath );
@@ -180,17 +179,17 @@
             fileRepo.createPath();
         }
 
-        PathFile fileObrXml = new PathFile( m_obrFile );
-        if ( !fileObrXml.isExists() )
+        URI obrXml = ObrUtils.toFileURI( m_obrFile );
+        if ( null == obrXml )
         {
-            getLog().warn( "obr.xml file not found, use default" );
+            getLog().info( "obr.xml is not present, use default" );
         }
 
         // build the user config
         Config userConfig = new Config();
 
-        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, fileObrXml.getOnlyAbsoluteFilename(), m_project, fileOut
-            .getOnlyAbsoluteFilename(), m_localRepo.getBasedir(), userConfig, getLog() );
+        ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, fileOut.getOnlyAbsoluteFilename(),
+            m_localRepo.getBasedir(), userConfig, getLog() );
         obrUpdate.updateRepository();
 
     }
diff --git a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
index cbc9389..468b956 100644
--- a/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
+++ b/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
@@ -122,13 +122,13 @@
      * @param userConfig user information
      * @param logger plugin logger
      */
-    public ObrUpdate( PathFile repositoryXml, String obrXml, MavenProject project, String bundlePath,
+    public ObrUpdate( PathFile repositoryXml, URI obrXml, MavenProject project, String bundlePath,
         String mavenRepositoryPath, Config userConfig, Log logger )
     {
         // m_localRepo = localRepo;
         m_bundlePath = ObrUtils.toFileURI( bundlePath );
         m_repositoryXml = repositoryXml.getFile().toURI(); // FIXME: remove when PathFile is gone
-        m_obrXml = ObrUtils.toFileURI( obrXml );
+        m_obrXml = obrXml;
         m_project = project;
         m_logger = logger;