You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2008/01/27 12:08:30 UTC

svn commit: r615573 - /felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java

Author: mcculls
Date: Sun Jan 27 03:08:29 2008
New Revision: 615573

URL: http://svn.apache.org/viewvc?rev=615573&view=rev
Log:
Refactor to use new OBR utilities

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java?rev=615573&r1=615572&r2=615573&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java Sun Jan 27 03:08:29 2008
@@ -18,22 +18,21 @@
  */
 package org.apache.felix.bundleplugin;
 
+
 import java.io.File;
 import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Iterator;
-import java.util.List;
 
 import org.apache.felix.obr.plugin.Config;
 import org.apache.felix.obr.plugin.ObrUpdate;
+import org.apache.felix.obr.plugin.ObrUtils;
 import org.apache.felix.obr.plugin.PathFile;
 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.logging.Log;
 import org.apache.maven.project.MavenProject;
 
+
 /**
  * Installs bundle details in the local OBR repository
  * 
@@ -69,10 +68,10 @@
      */
     private MavenProject project;
 
-    public void execute()
-        throws MojoExecutionException
+
+    public void execute() throws MojoExecutionException
     {
-        if( "NONE".equalsIgnoreCase( obrRepository ) )
+        if ( "NONE".equalsIgnoreCase( obrRepository ) )
         {
             return;
         }
@@ -82,74 +81,30 @@
 
         try
         {
-            String localRepoPath = localRepository.getBasedir();
+            String mavenRepository = localRepository.getBasedir();
             String artifactPath = localRepository.pathOf( project.getArtifact() );
-            String bundlePath = localRepoPath + File.separator + artifactPath;
+            String bundlePath = mavenRepository + File.separator + artifactPath;
             bundlePath = bundlePath.replace( '\\', '/' );
 
-            PathFile repositoryXml = normalizeRepositoryPath( obrRepository, localRepoPath );
-            String extensionXml = findOBRExtensions( project.getResources() );
-
-            Config user = new Config();
-
-            update = new ObrUpdate( repositoryXml, extensionXml, project, bundlePath, localRepoPath, user, log );
-
-            repositoryXml.createPath();
-            update.updateRepository();
-        }
-        catch( Exception e )
-        {
-            log.warn( "Exception while updating OBR: " + e.getLocalizedMessage(), e );
-        }
-    }
+            URI repositoryXml = ObrUtils.findRepositoryXml( project.getBasedir(), mavenRepository, obrRepository );
+            URI obrXml = ObrUtils.findObrXml( project.getResources() );
 
-    private static PathFile normalizeRepositoryPath( String obrPath, String mavenPath )
-    {
-        if( null == obrPath || obrPath.length() == 0 )
-        {
-            obrPath = mavenPath + File.separatorChar + "repository.xml";
-        }
-        else if( !obrPath.endsWith( ".xml" ) )
-        {
-            obrPath = obrPath + File.separatorChar + "repository.xml";
-        }
-
-        URI uri;
-        try
-        {
-            uri = new URI( obrPath );
-        }
-        catch( URISyntaxException e )
-        {
-            uri = null;
-        }
-
-        if( null == uri || !uri.isAbsolute() )
-        {
-            File file = new File( obrPath );
-            if( !file.isAbsolute() )
+            String obrXmlPath = null;
+            if ( null != obrXml )
             {
-                file = new File( mavenPath, obrPath );
+                obrXmlPath = obrXml.getPath();
             }
 
-            uri = file.toURI();
-        }
+            Config userConfig = new Config();
 
-        // PathFile workaround: for now provide decoded strings to maven-obr-plugin
-        return new PathFile( uri.getScheme() + ':' + uri.getSchemeSpecificPart() );
-    }
+            update = new ObrUpdate( new PathFile( repositoryXml.getPath() ), obrXmlPath, project, bundlePath,
+                mavenRepository, userConfig, log );
 
-    private static String findOBRExtensions( List resources )
-    {
-        for( Iterator i = resources.iterator(); i.hasNext(); )
+            update.updateRepository();
+        }
+        catch ( Exception e )
         {
-            Resource resource = (Resource) i.next();
-            File obrFile = new File( resource.getDirectory(), "obr.xml" );
-            if( obrFile.exists() )
-            {
-                return obrFile.getPath();
-            }
+            log.warn( "Exception while updating OBR: " + e.getLocalizedMessage(), e );
         }
-        return null;
     }
 }