FELIX-370: add simple install mojo to bundle plugin that calls the relevant code from the OBR plugin (this solves the dependency lookup problem). Use -DobrRepository=NONE to turn off OBR installation. For complete control over install / deploy of OBR metadata people should explicitly use the OBR plugin.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@579728 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/pom.xml b/bundleplugin/pom.xml
index 50cc5b3..9869d4e 100644
--- a/bundleplugin/pom.xml
+++ b/bundleplugin/pom.xml
@@ -43,14 +43,11 @@
</description>
<dependencies>
-<!--
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>maven-obr-plugin</artifactId>
<version>0.1.0-SNAPSHOT</version>
- <scope>runtime</scope>
</dependency>
--->
<dependency>
<groupId>biz.aQute</groupId>
<artifactId>bndlib</artifactId>
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
new file mode 100644
index 0000000..c6619f5
--- /dev/null
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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.sandbox.obr.plugin.Config;
+import org.apache.felix.sandbox.obr.plugin.ObrUpdate;
+import org.apache.felix.sandbox.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
+ *
+ * @goal install
+ * @phase install
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class OBRInstall extends AbstractMojo
+{
+ /**
+ * OBR Repository.
+ *
+ * @parameter expression="${obrRepository}"
+ */
+ private String obrRepository;
+
+ /**
+ * Local Repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * The Maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ public void execute()
+ throws MojoExecutionException
+ {
+ if( "NONE".equalsIgnoreCase( obrRepository ) )
+ {
+ return;
+ }
+
+ Log log = getLog();
+
+ String localRepoPath = localRepository.getBasedir();
+ String artifactPath = localRepository.pathOf( project.getArtifact() );
+ String bundlePath = localRepoPath + File.separatorChar + artifactPath;
+
+ PathFile repositoryXml = normalizeRepositoryPath( obrRepository, localRepoPath );
+ String extensionXml = findOBRExtensions( project.getResources() );
+
+ Config user = new Config();
+
+ ObrUpdate update = new ObrUpdate( repositoryXml, extensionXml, project, bundlePath, localRepoPath, user, log );
+
+ repositoryXml.createPath();
+ update.updateRepository();
+ }
+
+ private static PathFile normalizeRepositoryPath( String obrPath, String mavenPath )
+ {
+ if( null == obrPath || obrPath.length() == 0 )
+ {
+ obrPath = mavenPath + File.separatorChar + "repository.xml";
+ }
+ else if( !obrPath.endsWith( "repository.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();
+ }
+
+ return new PathFile( uri.toASCIIString() );
+ }
+
+ 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;
+ }
+}
diff --git a/bundleplugin/src/main/resources/META-INF/plexus/components.xml b/bundleplugin/src/main/resources/META-INF/plexus/components.xml
index 27ea07c..c26255a 100644
--- a/bundleplugin/src/main/resources/META-INF/plexus/components.xml
+++ b/bundleplugin/src/main/resources/META-INF/plexus/components.xml
@@ -35,20 +35,11 @@
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>org.apache.felix:maven-bundle-plugin:bundle</package>
<install>
- org.apache.maven.plugins:maven-install-plugin:install<!--,
-REMOVED org.apache.felix:maven-obr-plugin:repository-->
+ org.apache.maven.plugins:maven-install-plugin:install,
+ org.apache.felix:maven-bundle-plugin:install
</install>
- <deploy>
- org.apache.maven.plugins:maven-deploy-plugin:deploy<!--,
-REMOVED org.apache.felix:maven-obr-plugin:deployment-->
- </deploy>
+ <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
-<!--
- <optional-mojos>
- <optional-mojo>org.apache.felix:maven-obr-plugin:repository</optional-mojo>
- <optional-mojo>org.apache.felix:maven-obr-plugin:deployment</optional-mojo>
- </optional-mojos>
--->
<!-- END SNIPPET: bundle-lifecycle -->
</lifecycle>
</lifecycles>