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/10/28 22:31:08 UTC

svn commit: r468737 - in /geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car: Maven2RepositoryAdapter.java PackageMojo.java

Author: jdillon
Date: Sat Oct 28 13:31:07 2006
New Revision: 468737

URL: http://svn.apache.org/viewvc?view=rev&rev=468737
Log:
Forcing deployment modules configured to be resolved first, so they (and their transitive deps) end up in the local mvn repo
Installing an adapter for the local maven repo when packaging, so that the Maven API will be used to resolve SNAPSHOT artifacts correctly (including timestamped snaps)

Added:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Maven2RepositoryAdapter.java   (with props)
Modified:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Maven2RepositoryAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Maven2RepositoryAdapter.java?view=auto&rev=468737
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Maven2RepositoryAdapter.java (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Maven2RepositoryAdapter.java Sat Oct 28 13:31:07 2006
@@ -0,0 +1,78 @@
+/*
+ * 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.geronimo.mavenplugins.car;
+
+import java.io.File;
+
+import org.apache.geronimo.system.repository.Maven2Repository;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+/**
+ * Helps adapt Geronimo repositories to Maven repositories for packaging building.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Maven2RepositoryAdapter
+    extends Maven2Repository
+{
+    private ArtifactLookup lookup;
+
+    public Maven2RepositoryAdapter(final ArtifactLookup lookup) {
+        super(lookup.getBasedir());
+
+        this.lookup = lookup;
+    }
+
+    public File getLocation(final Artifact artifact) {
+        assert artifact != null;
+
+        return lookup.getLocation(artifact);
+    }
+
+    //
+    // ArtifactLookup
+    //
+
+    public static interface ArtifactLookup
+    {
+        File getLocation(Artifact artifact);
+
+        File getBasedir();
+    }
+
+    //
+    // GBean
+    //
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(Maven2RepositoryAdapter.class, "Repository");
+        infoFactory.addAttribute("lookup", ArtifactLookup.class, true);
+        infoFactory.setConstructor(new String[]{ "lookup" });
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

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

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

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

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java?view=diff&rev=468737&r1=468736&r2=468737
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java Sat Oct 28 13:31:07 2006
@@ -22,11 +22,11 @@
 import java.io.File;
 import java.net.URI;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.Arrays;
 
 import org.apache.geronimo.deployment.PluginBootstrap2;
 import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
@@ -122,7 +122,7 @@
     private String finalName = null;
 
     /**
-     * ???
+     * The local Maven repository which will be used to pull artifacts into the Geronimo repository when packaging.
      *
      * @parameter expression="${settings.localRepository}"
      * @required
@@ -131,7 +131,7 @@
     private File repository = null;
 
     /**
-     * ???
+     * The Geronimo repository where modules will be packaged up from.
      *
      * @parameter expression="${project.build.directory}/repository"
      * @required
@@ -139,20 +139,20 @@
     private File targetRepository = null;
 
     /**
-     * ???
+     * The default deployer module to be used when no other deployer modules are configured.
      *
      * @parameter expression="org.apache.geronimo.configs/geronimo-gbean-deployer/${geronimoVersion}/car"
      * @required
      * @readonly
      */
-    private String deafultDeploymentConfig = null;
+    private String defaultDeploymentConfig = null;
 
     /**
-     * ???
+     * Ther deployer modules to be used when packaging.
      *
      * @parameter
      */
-    private List deploymentConfigs;
+    private String[] deploymentConfigs;
 
     /**
      * The name of the deployer which will be used to deploy the CAR.
@@ -188,7 +188,8 @@
      * The location where the properties mapping will be generated.
      *
      * <p>
-     * Probably don't wanto to change this.
+     * Probably don't want to change this.
+     * </p>
      *
      * @parameter expression="${project.build.directory}/explicit-versions.properties"
      */
@@ -231,10 +232,29 @@
 
         // Use the default configs if none specified
         if (deploymentConfigs == null) {
-            deploymentConfigs = new ArrayList();
-            deploymentConfigs.add(deafultDeploymentConfig);
+            deploymentConfigs = new String[] {
+                    defaultDeploymentConfig
+            };
+        }
+        log.debug("Deployment configs: " + Arrays.asList(deploymentConfigs));
+
+        //
+        // NOTE: Resolve deployment modules, this is needed to ensure that the proper artifacts are in the
+        //       local repository to perform deployment.  If the deployer modules (or their dependencies)
+        //       are missing from the source respository, then strange packaging failures will occur.
+        //
+        for (int i=0; i<deploymentConfigs.length; i++) {
+            String[] parts = deploymentConfigs[i].split("/");
+            ArtifactItem item = new ArtifactItem();
+            item.setGroupId(parts[0]);
+            item.setArtifactId(parts[1]);
+            item.setVersion(parts[2]);
+            item.setType(parts[3]);
+
+            log.debug("Resolving deployer module: " + item);
+            Artifact artifact = createArtifact(item);
+            resolveArtifact(artifact, true);
         }
-        log.debug("Deployment configs: " + deploymentConfigs);
 
         // If module is set, then resolve the artifact and set moduleFile
         if (module != null) {
@@ -377,7 +397,6 @@
     public void buildPackage() throws Exception {
         log.info("Packaging module configuration: " + planFile);
 
-
         Kernel kernel = createKernel();
         if (!targetSet) {
             kernel.stopGBean(targetRepositoryAName);
@@ -396,8 +415,8 @@
         // start the Configuration we're going to use for this deployment
         ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
         try {
-            for (Iterator iterator = deploymentConfigs.iterator(); iterator.hasNext();) {
-                String artifactName = (String) iterator.next();
+            for (int i=0; i<deploymentConfigs.length; i++) {
+                String artifactName = deploymentConfigs[i];
                 org.apache.geronimo.kernel.repository.Artifact configName =
                         org.apache.geronimo.kernel.repository.Artifact.create(artifactName);
                 if (!configurationManager.isLoaded(configName)) {
@@ -453,6 +472,7 @@
      * <p>
      * This contains Repository and ConfigurationStore GBeans that map to
      * the local maven installation.
+     * </p>
      */
     private void bootDeployerSystem() throws Exception {
         log.debug("Booting deployer system...");
@@ -464,10 +484,53 @@
         ClassLoader cl = getClass().getClassLoader();
         Set repoNames = new HashSet();
 
-        // Source repo
-        GBeanData repoGBean = bootstrap.addGBean("SourceRepository", GBeanInfo.getGBeanInfo(Maven2Repository.class.getName(), cl));
-        URI repositoryURI = repository.toURI();
-        repoGBean.setAttribute("root", repositoryURI);
+        //
+        // NOTE: Install an adapter for the source repository that will leverage the Maven2 repository subsystem
+        //       to allow for better handling of SNAPSHOT values.
+        //
+        GBeanData repoGBean = bootstrap.addGBean("SourceRepository", GBeanInfo.getGBeanInfo(Maven2RepositoryAdapter.class.getName(), cl));
+        Maven2RepositoryAdapter.ArtifactLookup lookup = new Maven2RepositoryAdapter.ArtifactLookup() {
+            public File getBasedir() {
+                String path = getArtifactRepository().getBasedir();
+                return new File(path);
+            }
+
+            public File getLocation(final org.apache.geronimo.kernel.repository.Artifact artifact) {
+                // System.err.println("Checking location of: " + artifact);
+
+                Artifact mavenArtifact = getArtifactFactory().createArtifact(
+                        artifact.getGroupId(),
+                        artifact.getArtifactId(),
+                        artifact.getVersion().toString(),
+                        null,
+                        artifact.getType()
+                );
+
+                File file;
+                try {
+                    if (!mavenArtifact.isResolved()) {
+                        mavenArtifact = resolveArtifact(mavenArtifact);
+                    }
+
+                    //
+                    // HACK: Construct the real local filename from the path and resolved artifact file.
+                    //       Probably a better way to do this with the Maven API directly, but this is the
+                    //       best I can do for now.
+                    //
+                    String path = getArtifactRepository().pathOf(mavenArtifact);
+                    file = new File(getBasedir(), path);
+                    file = new File(mavenArtifact.getFile().getParentFile(), file.getName());
+                }
+                catch (MojoExecutionException e) {
+                    throw new RuntimeException("Failed to resolve: " + mavenArtifact, e);
+                }
+
+                // System.err.println("Using location: " + file);
+
+                return file;
+            }
+        };
+        repoGBean.setAttribute("lookup", lookup);
         repoNames.add(repoGBean.getAbstractName());
 
         // Target repo