felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mccu...@apache.org
Subject svn commit: r618550 - in /felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin: AbstractFileMojo.java ObrInstall.java ObrInstallFile.java PomHelper.java
Date Tue, 05 Feb 2008 05:34:36 GMT
Author: mcculls
Date: Mon Feb  4 21:34:35 2008
New Revision: 618550

URL: http://svn.apache.org/viewvc?rev=618550&view=rev
Log:
FELIX-475: refactor install-file goal to match with the one from the install plugin

Added:
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java
  (with props)
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java
  (with props)
Modified:
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
    felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java

Added: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java?rev=618550&view=auto
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java
(added)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java
Mon Feb  4 21:34:35 2008
@@ -0,0 +1,133 @@
+/*
+ * 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.obr.plugin;
+
+
+import java.io.File;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+
+/**
+ * Base class for the command-line install-file and deploy-file goals.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public abstract class AbstractFileMojo extends AbstractMojo
+{
+    /**
+     * GroupId of the bundle. Retrieved from POM file if specified.
+     *
+     * @parameter expression="${groupId}"
+     */
+    private String groupId;
+
+    /**
+     * ArtifactId of the bundle. Retrieved from POM file if specified.
+     *
+     * @parameter expression="${artifactId}"
+     */
+    private String artifactId;
+
+    /**
+     * Version of the bundle. Retrieved from POM file if specified.
+     *
+     * @parameter expression="${version}"
+     */
+    private String version;
+
+    /**
+     * Packaging type of the bundle. Retrieved from POM file if specified.
+     *
+     * @parameter expression="${packaging}"
+     */
+    private String packaging;
+
+    /**
+     * Classifier type of the bundle. Defaults to none.
+     *
+     * @parameter expression="${classifier}"
+     */
+    private String classifier;
+
+    /**
+     * Location of an existing POM file.
+     *
+     * @parameter expression="${pomFile}"
+     */
+    private File pomFile;
+
+    /**
+     * Bundle file, defaults to the artifact in the local Maven repository.
+     *
+     * @parameter expression="${file}"
+     */
+    protected File file;
+
+    /**
+     * Optional XML file describing additional requirements and capabilities.
+     * 
+     * @parameter expression="${obrXml}"
+     */
+    protected String obrXml;
+
+    /**
+     * Component factory for Maven artifacts
+     * 
+     * @component
+     */
+    private ArtifactFactory m_factory;
+
+
+    /**
+     * @return project based on command-line settings, with bundle attached
+     * @throws MojoExecutionException
+     */
+    public MavenProject getProject() throws MojoExecutionException
+    {
+        final MavenProject project;
+        if ( pomFile != null && pomFile.exists() )
+        {
+            project = PomHelper.readPom( pomFile );
+
+            groupId = project.getGroupId();
+            artifactId = project.getArtifactId();
+            version = project.getVersion();
+            packaging = project.getPackaging();
+        }
+        else
+        {
+            project = PomHelper.buildPom( groupId, artifactId, version, packaging );
+        }
+
+        if ( groupId == null || artifactId == null || version == null || packaging == null
)
+        {
+            throw new MojoExecutionException( "Missing group, artifact, version, or packaging
information" );
+        }
+
+        Artifact bundle = m_factory.createArtifactWithClassifier( groupId, artifactId, version,
packaging, classifier );
+        project.setArtifact( bundle );
+
+        return project;
+    }
+}

Propchange: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/AbstractFileMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java?rev=618550&r1=618549&r2=618550&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstall.java
Mon Feb  4 21:34:35 2008
@@ -31,7 +31,7 @@
 
 
 /**
- * Installs bundle details in the local OBR repository
+ * Installs bundle details in the local OBR repository (life-cycle goal)
  * 
  * @goal install
  * @phase install
@@ -81,12 +81,12 @@
             String mavenRepository = localRepository.getBasedir();
 
             URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository
);
-            URI obrXml = ObrUtils.findObrXml( project.getResources() );
+            URI obrXmlFile = ObrUtils.findObrXml( project.getResources() );
             URI bundleJar = ObrUtils.findBundleJar( localRepository, project.getArtifact()
);
 
             Config userConfig = new Config();
 
-            update = new ObrUpdate( repositoryXml, obrXml, project, bundleJar, mavenRepository,
userConfig, log );
+            update = new ObrUpdate( repositoryXml, obrXmlFile, project, bundleJar, mavenRepository,
userConfig, log );
 
             update.updateRepository();
         }

Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java?rev=618550&r1=618549&r2=618550&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
(original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
Mon Feb  4 21:34:35 2008
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -19,146 +19,72 @@
 package org.apache.felix.obr.plugin;
 
 
-import java.io.File;
 import java.net.URI;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-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;
 
 
 /**
- * Install bundle metadata to local OBR (command-line goal).
+ * Installs bundle details in the local OBR repository (command-line goal)
  * 
- * @goal install-file
  * @requiresProject false
+ * @goal install-file
  * @phase install
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ObrInstallFile extends AbstractMojo
+public final class ObrInstallFile extends AbstractFileMojo
 {
     /**
-     * Component factory for Maven artifacts
+     * OBR Repository.
      * 
-     * @component
+     * @parameter expression="${obrRepository}"
      */
-    private ArtifactFactory m_factory;
+    private String obrRepository;
 
     /**
-     * The local Maven repository.
+     * Local Repository.
      * 
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
      */
-    private ArtifactRepository m_localRepo;
-
-    /**
-     * path to the repository.xml.
-     * 
-     * @parameter expression="${repository-path}" alias="repository-path"
-     */
-    private String m_repositoryPath;
-
-    /**
-     * Artifact Id.
-     * @description symbolic name define by the user
-     * @parameter expression="${artifactId}"
-     */
-    private String m_artifactId;
-
-    /**
-     * Group Id.
-     * @description groupId define by the user
-     * @parameter expression="${groupId}"
-     */
-    private String m_groupId;
-
-    /**
-     * Version.
-     * @description version define by the user
-     * @parameter expression="${version}"
-     */
-    private String m_version;
-
-    /**
-     * Packaging.
-     * @description packaging define by the user
-     * @parameter expression="${packaging}"
-     */
-    private String m_packaging;
-
-    /**
-     * OBR File.
-     * @description obr file define by the user
-     * @parameter expression="${obr-file}" alias="obr-file"
-     */
-    private String m_obrFile;
+    private ArtifactRepository localRepository;
 
 
-    /**
-     * main method for this goal.
-     * @implements org.apache.maven.plugin.Mojo.execute 
-     * @throws MojoExecutionException if the plugin failed
-     */
     public void execute() throws MojoExecutionException
     {
-        MavenProject project = new MavenProject();
-        project.setArtifactId( m_artifactId );
-        project.setGroupId( m_groupId );
-        project.setVersion( m_version );
-        project.setPackaging( m_packaging );
+        MavenProject project = getProject();
 
-        if ( m_groupId == null )
-        {
-            getLog().error( "-DgroupId=VALUE is required" );
-            return;
-        }
-        if ( m_artifactId == null )
-        {
-            getLog().error( "-Dartifactid=VALUE is required" );
-            return;
-        }
-        if ( m_version == null )
+        if ( "NONE".equalsIgnoreCase( obrRepository ) )
         {
-            getLog().error( "-Dversion=VALUE is required" );
-            return;
-        }
-        if ( m_packaging == null )
-        {
-            getLog().error( "-Dpackaging=VALUE is required" );
             return;
         }
 
-        // locate the obr.xml file
-        URI obrXml = ObrUtils.toFileURI( m_obrFile );
-        if ( null == obrXml )
-        {
-            getLog().info( "obr.xml is not present, use default" );
-        }
+        Log log = getLog();
+        ObrUpdate update;
 
-        Artifact bundleArtifact = m_factory.createBuildArtifact( m_groupId, m_artifactId,
m_version, m_packaging );
+        String mavenRepository = localRepository.getBasedir();
 
-        // get the path to local maven repository
-        String mavenRepository = m_localRepo.getBasedir();
+        URI repositoryXml = ObrUtils.findRepositoryXml( mavenRepository, obrRepository );
+        URI obrXmlFile = ObrUtils.toFileURI( obrXml );
+        URI bundleJar;
 
-        URI repoXml = ObrUtils.findRepositoryXml( mavenRepository, m_repositoryPath );
-        URI bundleJar = ObrUtils.findBundleJar( m_localRepo, bundleArtifact );
-
-        if ( !new File( bundleJar ).exists() )
+        if ( null == file )
         {
-            getLog().error( "file not found in local repository: " + bundleJar );
-            return;
+            bundleJar = ObrUtils.findBundleJar( localRepository, project.getArtifact() );
+        }
+        else
+        {
+            bundleJar = file.toURI();
         }
 
-        // use default configuration
         Config userConfig = new Config();
 
-        ObrUpdate update = new ObrUpdate( repoXml, obrXml, project, bundleJar, null, userConfig,
getLog() );
+        update = new ObrUpdate( repositoryXml, obrXmlFile, project, bundleJar, mavenRepository,
userConfig, log );
 
         update.updateRepository();
     }

Added: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java?rev=618550&view=auto
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java
(added)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java
Mon Feb  4 21:34:35 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.obr.plugin;
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+
+/**
+ * Maven POM helper methods.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public final class PomHelper
+{
+    public static MavenProject readPom( File pomFile ) throws MojoExecutionException
+    {
+        Reader reader = null;
+
+        try
+        {
+            reader = new FileReader( pomFile );
+            MavenXpp3Reader modelReader = new MavenXpp3Reader();
+            return new MavenProject( modelReader.read( reader ) );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(),
e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(),
e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new MojoExecutionException( "Error reading specified POM file: " + e.getMessage(),
e );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+    }
+
+
+    public static MavenProject buildPom( String groupId, String artifactId, String version,
String packaging )
+    {
+        Model model = new Model();
+
+        model.setModelVersion( "4.0.0" );
+        model.setGroupId( groupId );
+        model.setArtifactId( artifactId );
+        model.setVersion( version );
+        model.setPackaging( packaging );
+
+        return new MavenProject( model );
+    }
+}

Propchange: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PomHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message