You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/08/22 01:02:30 UTC

svn commit: r433414 - in /geronimo/trunk/m2-plugins/car-maven-plugin/src: main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java site/apt/usage.apt

Author: jdillon
Date: Mon Aug 21 16:02:30 2006
New Revision: 433414

URL: http://svn.apache.org/viewvc?rev=433414&view=rev
Log:
Added car:install-artifacts goal to install arbitrary Maven artifacts into a Geronimo repo

Added:
    geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java   (with props)
Modified:
    geronimo/trunk/m2-plugins/car-maven-plugin/src/site/apt/usage.apt

Added: geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java?rev=433414&view=auto
==============================================================================
--- geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java (added)
+++ geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java Mon Aug 21 16:02:30 2006
@@ -0,0 +1,113 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.plugin.car;
+
+import org.apache.geronimo.kernel.repository.WriteableRepository;
+import org.apache.geronimo.system.repository.Maven2Repository;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.artifact.Artifact;
+
+import java.io.File;
+
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * Installs one or more artifacts into a local Geronimo repository.
+ *
+ * @goal install-artifacts
+ *
+ * @version $Rev$ $Date$
+ */
+public class InstallArtifactsMojo
+    extends AbstractCarMojo
+{
+    /**
+     * The location of the target repository to install artifacts into.
+     *
+     * @parameter
+     * @required
+     */
+    private File repositoryDirectory = null;
+
+    /**
+     * A list of {@link ArtifactItem} instances to be installed into the repository.
+     *
+     * @parameter
+     * @required
+     */
+    private List artifacts = null;
+
+    /**
+     * Flag to indicate that if an artifact exists already, that we should delete it and re-install.
+     *
+     * @parameter default-value="true"
+     */
+    private boolean force = true;
+
+    protected void doExecute() throws Exception {
+        if (!repositoryDirectory.exists()) {
+            repositoryDirectory.mkdirs();
+            log.info("Created directory: " + repositoryDirectory);
+        }
+        else if (!repositoryDirectory.isDirectory()) {
+            throw new MojoExecutionException("Invalid reposiory directory: " + repositoryDirectory);
+        }
+
+        WriteableRepository repository = new Maven2Repository(repositoryDirectory);
+
+        // Install all of the artifacts we were asked to...
+        Iterator iter = artifacts.iterator();
+        while (iter.hasNext()) {
+            ArtifactItem item = (ArtifactItem)iter.next();
+            log.info("Installing: " + item);
+
+            Artifact artifact = getArtifact(item);
+
+            org.apache.geronimo.kernel.repository.Artifact gartifact = mavenArtifactToGeronimo(artifact);
+            if (repository.contains(gartifact)) {
+                if (force) {
+                    File file = repository.getLocation(gartifact);
+                    log.debug("Force deletion of: " + file);
+
+                    if (!file.delete()) {
+                        throw new MojoExecutionException("Failed to delete artifact from repository: " + item);
+                    }
+                }
+                else {
+                    throw new MojoExecutionException("Artifact already exists in repository: " + item);
+                }
+            }
+
+            repository.copyToRepository(artifact.getFile(), gartifact, null);
+        }
+    }
+
+    /**
+     * Convert a Maven artifact into a the Geronimo flavor.
+     */
+    private org.apache.geronimo.kernel.repository.Artifact mavenArtifactToGeronimo(final Artifact artifact) {
+        assert artifact != null;
+
+        return new org.apache.geronimo.kernel.repository.Artifact(
+            artifact.getGroupId(),
+            artifact.getArtifactId(),
+            artifact.getVersion(),
+            artifact.getType()
+        );
+    }
+}

Propchange: geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/trunk/m2-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/InstallArtifactsMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/trunk/m2-plugins/car-maven-plugin/src/site/apt/usage.apt
URL: http://svn.apache.org/viewvc/geronimo/trunk/m2-plugins/car-maven-plugin/src/site/apt/usage.apt?rev=433414&r1=433413&r2=433414&view=diff
==============================================================================
--- geronimo/trunk/m2-plugins/car-maven-plugin/src/site/apt/usage.apt (original)
+++ geronimo/trunk/m2-plugins/car-maven-plugin/src/site/apt/usage.apt Mon Aug 21 16:02:30 2006
@@ -174,3 +174,35 @@
     ...
 <project>
 +----------+
+
+* Install artifacts into a Geronimo repository
+
+ Install arbitrary artifacts into a Geronimo repository.
+
++----------+
+<plugin>
+    <groupId>org.apache.geronimo.plugins</groupId>
+    <artifactId>car-maven-plugin</artifactId>
+    <executions>
+        <execution>
+            <id>install-repository</id>
+            <phase>compile</phase>
+            <goals>
+                <goal>install-artifacts</goal>
+            </goals>
+            <configuration>
+                <repositoryDirectory>${project.build.outputDirectory}/repository</repositoryDirectory>
+                
+                <artifacts>
+                    <artifactItem>
+                        <groupId>org.apache.geronimo.modules</groupId>
+                        <artifactId>ge-activemq-rar</artifactId>
+                        <type>rar</type>
+                    </artifactItem>
+                </artifacts>
+            </configuration>
+        </execution>
+    </executions>
+</plugin>
++----------+
+