Refactor to use new OBR utilities
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@615573 13f79535-47bb-0310-9956-ffa450edef68
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 cbc9bd1..b51c42c 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
@@ -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() );
+ URI repositoryXml = ObrUtils.findRepositoryXml( project.getBasedir(), mavenRepository, obrRepository );
+ URI obrXml = ObrUtils.findObrXml( project.getResources() );
- Config user = new Config();
+ String obrXmlPath = null;
+ if ( null != obrXml )
+ {
+ obrXmlPath = obrXml.getPath();
+ }
- update = new ObrUpdate( repositoryXml, extensionXml, project, bundlePath, localRepoPath, user, log );
+ Config userConfig = new Config();
- repositoryXml.createPath();
+ update = new ObrUpdate( new PathFile( repositoryXml.getPath() ), obrXmlPath, project, bundlePath,
+ mavenRepository, userConfig, log );
+
update.updateRepository();
}
- catch( Exception e )
+ catch ( Exception e )
{
log.warn( "Exception while updating OBR: " + e.getLocalizedMessage(), e );
}
}
-
- 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() )
- {
- file = new File( mavenPath, obrPath );
- }
-
- uri = file.toURI();
- }
-
- // PathFile workaround: for now provide decoded strings to maven-obr-plugin
- return new PathFile( uri.getScheme() + ':' + uri.getSchemeSpecificPart() );
- }
-
- private static String findOBRExtensions( List resources )
- {
- for( Iterator i = resources.iterator(); i.hasNext(); )
- {
- Resource resource = (Resource) i.next();
- File obrFile = new File( resource.getDirectory(), "obr.xml" );
- if( obrFile.exists() )
- {
- return obrFile.getPath();
- }
- }
- return null;
- }
}