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 2007/09/26 19:41:04 UTC

svn commit: r579728 - in /felix/trunk/bundleplugin: pom.xml src/main/java/org/apache/felix/bundleplugin/OBRInstall.java src/main/resources/META-INF/plexus/components.xml

Author: mcculls
Date: Wed Sep 26 10:41:03 2007
New Revision: 579728

URL: http://svn.apache.org/viewvc?rev=579728&view=rev
Log:
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.

Added:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java   (with props)
Modified:
    felix/trunk/bundleplugin/pom.xml
    felix/trunk/bundleplugin/src/main/resources/META-INF/plexus/components.xml

Modified: felix/trunk/bundleplugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/pom.xml?rev=579728&r1=579727&r2=579728&view=diff
==============================================================================
--- felix/trunk/bundleplugin/pom.xml (original)
+++ felix/trunk/bundleplugin/pom.xml Wed Sep 26 10:41:03 2007
@@ -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>

Added: 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=579728&view=auto
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java (added)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java Wed Sep 26 10:41:03 2007
@@ -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;
+    }
+}

Propchange: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/OBRInstall.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/bundleplugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/resources/META-INF/plexus/components.xml?rev=579728&r1=579727&r2=579728&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ felix/trunk/bundleplugin/src/main/resources/META-INF/plexus/components.xml Wed Sep 26 10:41:03 2007
@@ -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>