You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2008/05/19 19:48:14 UTC

svn commit: r657880 [1/2] - in /geronimo/server/trunk: buildsupport/ buildsupport/car-maven-plugin/ buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenp...

Author: djencks
Date: Mon May 19 10:48:13 2008
New Revision: 657880

URL: http://svn.apache.org/viewvc?rev=657880&view=rev
Log:
GERONIMO-4013 Use more maven infrastructure to figure out dependencies.  Don't base c-m-p on mojo pluginsupport.  Use the same dependency code to do the same work in more places

Removed:
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ImportConfig.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
Modified:
    geronimo/server/trunk/buildsupport/car-maven-plugin/pom.xml
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ClasspathElement.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/InstallModulesMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UpdatePluginListMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ValidateConfigurationMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojoTest.java
    geronimo/server/trunk/buildsupport/geronimo-maven-plugin/pom.xml
    geronimo/server/trunk/buildsupport/pom.xml
    geronimo/server/trunk/buildsupport/testsuite-maven-plugin/pom.xml
    geronimo/server/trunk/framework/configs/geronimo-gbean-deployer/src/it/j2ee-system-2/pom.xml
    geronimo/server/trunk/framework/configs/gshell-geronimo/pom.xml
    geronimo/server/trunk/framework/configs/gshell-remote/pom.xml
    geronimo/server/trunk/framework/configs/j2ee-system/pom.xml
    geronimo/server/trunk/framework/configs/jsr88-deploymentfactory/pom.xml
    geronimo/server/trunk/plugins/activemq/activemq-broker/pom.xml
    geronimo/server/trunk/plugins/aspectj/aspectj/pom.xml
    geronimo/server/trunk/plugins/axis/axis/pom.xml
    geronimo/server/trunk/plugins/axis2/axis2-ejb/pom.xml
    geronimo/server/trunk/plugins/axis2/axis2/pom.xml
    geronimo/server/trunk/plugins/client/client/pom.xml
    geronimo/server/trunk/plugins/connector/client-transaction/pom.xml
    geronimo/server/trunk/plugins/connector/transaction/pom.xml
    geronimo/server/trunk/plugins/cxf/cxf-ejb/pom.xml
    geronimo/server/trunk/plugins/cxf/cxf/pom.xml
    geronimo/server/trunk/plugins/jasper/jasper/pom.xml
    geronimo/server/trunk/plugins/jetty/jetty6/pom.xml
    geronimo/server/trunk/plugins/mejb/mejb/src/main/plan/plan.xml
    geronimo/server/trunk/plugins/openejb/openejb/pom.xml
    geronimo/server/trunk/plugins/openjpa/openjpa/pom.xml
    geronimo/server/trunk/plugins/system-database/system-database/pom.xml
    geronimo/server/trunk/plugins/tomcat/tomcat6/pom.xml
    geronimo/server/trunk/plugins/webservices/webservices-common/pom.xml

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/pom.xml?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/pom.xml Mon May 19 10:48:13 2008
@@ -101,10 +101,32 @@
         
         <dependency>
             <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <version>2.0.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.maven</groupId>
             <artifactId>maven-archiver</artifactId>
             <version>2.2</version>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-dependency-tree</artifactId>
+            <version>1.1</version>
+        </dependency>
+
         <dependency>
             <groupId>velocity</groupId>
             <artifactId>velocity</artifactId>

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java Mon May 19 10:48:13 2008
@@ -23,29 +23,31 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.Collections;
-import java.util.HashMap;
 
+import org.apache.geronimo.kernel.repository.ImportType;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.Mojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.codehaus.mojo.pluginsupport.MojoSupport;
-import org.codehaus.mojo.pluginsupport.dependency.DependencyHelper;
-import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
+import org.apache.maven.shared.dependency.tree.DependencyNode;
+import org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 /**
  * Support for <em>packaging</em> Mojos.
@@ -53,8 +55,10 @@
  * @version $Rev$ $Date$
  */
 public abstract class AbstractCarMojo
-    extends MojoSupport
-{
+        extends AbstractLogEnabled implements Mojo {
+
+    private Log log;
+
     /**
      * The maven project.
      *
@@ -73,30 +77,50 @@
      */
     protected File basedir;
 
+    protected Set<Artifact> dependencies;
+    protected Set<Artifact> localDependencies;
+
+
     /**
-     * The maven project's helper.
+     * The artifact repository to use.
+     *
+     * @parameter expression="${localRepository}"
+     * @required
+     * @readonly
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * The artifact factory to use.
      *
      * @component
      * @required
      * @readonly
      */
-    protected MavenProjectHelper projectHelper;
-    
+    protected ArtifactFactory artifactFactory;
+
     /**
-     * dependency resolution for the maven repository
+     * The artifact metadata source to use.
      *
      * @component
+     * @required
+     * @readonly
      */
-    protected DependencyHelper dependencyHelper = null;
+    private ArtifactMetadataSource artifactMetadataSource;
+
     /**
+     * The artifact collector to use.
+     *
      * @component
      * @required
      * @readonly
      */
-    protected ArtifactFactory artifactFactory;
-    protected Set<Artifact> dependencies;
-    protected Map<Artifact, Artifact> dependencyMap = new HashMap<Artifact, Artifact>();
-    protected ProjectNode projectNode;
+    private ArtifactCollector artifactCollector;
+
+    /**
+     * The computed dependency tree root node of the Maven project.
+     */
+    private DependencyNode rootNode;
 
     //
     // MojoSupport Hooks
@@ -116,28 +140,26 @@
     protected ArtifactRepository getArtifactRepository() {
         return artifactRepository;
     }
-    
+
     protected void init() throws MojoExecutionException, MojoFailureException {
-        super.init();
-        
-        dependencyHelper.setArtifactRepository(artifactRepository);
+//        super.init();
     }
-    
+
     /**
      * Generates a properties file with explicit versions of artifacts of the current project transitivly.
      */
     protected void generateExplicitVersionProperties(final File outputFile, Set<org.apache.maven.artifact.Artifact> dependencies) throws MojoExecutionException, IOException {
-        log.debug("Generating explicit version properties: " + outputFile);
+        getLog().debug("Generating explicit version properties: " + outputFile);
 
         // Generate explicit_versions for all our dependencies...
         Properties props = new Properties();
 
-        for (org.apache.maven.artifact.Artifact artifact: dependencies) {
+        for (org.apache.maven.artifact.Artifact artifact : dependencies) {
             String name = artifact.getGroupId() + "/" + artifact.getArtifactId() + "//" + artifact.getType();
             String value = artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getType();
 
-            if (log.isDebugEnabled()) {
-                log.debug("Setting " + name + "=" + value);
+            if (getLog().isDebugEnabled()) {
+                getLog().debug("Setting " + name + "=" + value);
             }
             props.setProperty(name, value);
         }
@@ -146,12 +168,11 @@
         output.flush();
         output.close();
     }
-   
+
     protected static File getArchiveFile(final File basedir, final String finalName, String classifier) {
         if (classifier == null) {
             classifier = "";
-        }
-        else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) {
+        } else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) {
             classifier = "-" + classifier;
         }
 
@@ -167,7 +188,7 @@
 
         return new org.apache.geronimo.kernel.repository.Artifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType());
     }
-    
+
     protected org.apache.geronimo.kernel.repository.Artifact mavenToGeronimoArtifact(final org.apache.maven.model.Dependency artifact) {
         assert artifact != null;
 
@@ -176,21 +197,14 @@
 
     protected org.apache.maven.artifact.Artifact geronimoToMavenArtifact(final org.apache.geronimo.kernel.repository.Artifact artifact) throws MojoExecutionException {
         assert artifact != null;
-
-        ArtifactItem item = new ArtifactItem();
-        item.setGroupId(artifact.getGroupId());
-        item.setArtifactId(artifact.getArtifactId());
-        item.setVersion(artifact.getVersion().toString());
-        item.setType(artifact.getType());
-
-        return createArtifact(item);
+        return artifactFactory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion().toString(), artifact.getType(), null);
     }
 
     /**
      * Determine if the given artifact is a Geronimo module.
      *
-     * @param artifact  The artifact to check; must not be null.
-     * @return          True if the artifact is a Geronimo module.
+     * @param artifact The artifact to check; must not be null.
+     * @return True if the artifact is a Geronimo module.
      */
     protected boolean isModuleArtifact(final org.apache.geronimo.kernel.repository.Artifact artifact) {
         assert artifact != null;
@@ -207,7 +221,7 @@
     }
 
     protected org.apache.maven.model.Dependency resolveDependency(org.apache.maven.model.Dependency dependency, List<org.apache.maven.model.Dependency> artifacts) {
-        for (org.apache.maven.model.Dependency match: artifacts) {
+        for (org.apache.maven.model.Dependency match : artifacts) {
             if (matches(dependency, match)) {
                 return match;
             }
@@ -228,35 +242,147 @@
         return true;
     }
 
-    protected void getDependencies(MavenProject project) throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException {
-        Map managedVersions = DependencyHelper.getManagedVersionMap(project, artifactFactory);
+    protected void getDependencies(MavenProject project, boolean useTransitiveDependencies) throws MojoExecutionException {
+
+        DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener(getLogger());
+
+        try {
+            Map managedVersions = project.getManagedVersionMap();
+
+            Set dependencyArtifacts = project.getDependencyArtifacts();
+
+            if (dependencyArtifacts == null) {
+                dependencyArtifacts = project.createArtifacts(artifactFactory, null, null);
+            }
+            ArtifactResolutionResult result = artifactCollector.collect(dependencyArtifacts, project.getArtifact(), managedVersions, localRepository,
+                    project.getRemoteArtifactRepositories(), artifactMetadataSource, null,
+                    Collections.singletonList(listener));
+
+            dependencies = result.getArtifacts();
+            rootNode = listener.getRootNode();
+        }
+        catch (ArtifactResolutionException exception) {
+            throw new MojoExecutionException("Cannot build project dependency tree", exception);
+        }
+        catch (InvalidDependencyVersionException e) {
+            throw new MojoExecutionException("Invalid dependency version for artifact "
+                    + project.getArtifact());
+        }
+
+        Scanner scanner = new Scanner();
+        scanner.scan(rootNode, useTransitiveDependencies);
+        localDependencies = scanner.localDependencies;
+
+    }
+
+    public void setLog(Log log) {
+        this.log = log;
+    }
+
+    public Log getLog() {
+        if (log == null) {
+            setLog(new SystemStreamLog());
+        }
+        return log;
+    }
+
+    protected static org.apache.geronimo.kernel.repository.Dependency toGeronimoDependency(final Artifact dependency, boolean includeVersion) {
+        org.apache.geronimo.kernel.repository.Artifact artifact = toGeronimoArtifact(dependency, includeVersion);
+        return new org.apache.geronimo.kernel.repository.Dependency(artifact, ImportType.ALL);
+    }
+
+    private static org.apache.geronimo.kernel.repository.Artifact toGeronimoArtifact(final Artifact dependency, boolean includeVersion) {
+        String groupId = dependency.getGroupId();
+        String artifactId = dependency.getArtifactId();
+        String version = includeVersion ? dependency.getVersion() : null;
+        String type = dependency.getType();
+
+        return new org.apache.geronimo.kernel.repository.Artifact(groupId, artifactId, version, type);
+    }
+
+    private static class Scanner {
+        private static enum Accept {
+            ACCEPT(true, true),
+            PROVIDED(true, false),
+            STOP(false, false);
+
+            private final boolean more;
+            private final boolean local;
+
+            private Accept(boolean more, boolean local) {
+                this.more = more;
+                this.local = local;
+            }
+
+            public boolean isContinue() {
+                return more;
+            }
 
-        if (project.getDependencyArtifacts() == null) {
-            project.setDependencyArtifacts(project.createArtifacts(artifactFactory, null, null));
+            public boolean isLocal() {
+                return local;
+            }
+        }
+
+        //all the dependencies, including provided and their dependencies
+        private final Set<Artifact> dependencies = new HashSet<Artifact>();
+        //all the dependencies needed for this car, with provided dependencies removed
+        private final Set<Artifact> localDependencies = new HashSet<Artifact>();
+        //dependencies from ancestor cars, to be removed from localDependencies.
+        private final Set<Artifact> carDependencies = new HashSet<Artifact>();
+
+        public void scan(DependencyNode rootNode, boolean useTransitiveDependencies) {
+            for (DependencyNode child : (List<DependencyNode>) rootNode.getChildren()) {
+                scan(child, localDependencies, carDependencies, Accept.ACCEPT, useTransitiveDependencies);
+            }
+            if (useTransitiveDependencies) {
+                localDependencies.removeAll(carDependencies);
+            }
         }
 
-        DependencyListener listener = new DependencyListener();
+        private void scan(DependencyNode rootNode, Set<Artifact> localDependencies, Set<Artifact> carDependencies, Accept accept, boolean useTransitiveDependencies) {
+            Artifact artifact = getArtifact(rootNode);
+
+            accept = accept(artifact, accept);
+            if (accept.isContinue()) {
+                dependencies.add(artifact);
+                if (accept.isLocal()) {
+                    localDependencies.add(artifact);
+                    if (artifact.getType().equals("car") || !useTransitiveDependencies) {
+                        localDependencies = carDependencies;
+                    }
+                }
+                for (DependencyNode child : (List<DependencyNode>) rootNode.getChildren()) {
+                    scan(child, localDependencies, carDependencies, accept, useTransitiveDependencies);
+                }
+            }
+        }
 
-        ArtifactResolutionResult artifactResolutionResult = dependencyHelper.getArtifactCollector().collect(
-                project.getDependencyArtifacts(),
-                project.getArtifact(),
-                managedVersions,
-                getArtifactRepository(),
-                project.getRemoteArtifactRepositories(),
-                dependencyHelper.getArtifactMetadataSource(),
-                null,
-                Collections.singletonList(listener));
-
-        dependencies = artifactResolutionResult.getArtifacts();
-        projectNode = listener.getTop();
-        for (Artifact artifact: dependencies) {
-            dependencyMap.put(DependencyListener.shrink(artifact), artifact);
+        private Artifact getArtifact(DependencyNode rootNode) {
+            Artifact artifact = rootNode.getArtifact();
+            if (rootNode.getRelatedArtifact() != null) {
+                artifact = rootNode.getRelatedArtifact();
+            }
+            return artifact;
         }
+
+        private Accept accept(Artifact dependency, Accept previous) {
+            if (dependency.getGroupId().startsWith("org.apache.geronimo.genesis")) {
+                return Accept.STOP;
+            }
+            String scope = dependency.getScope();
+            if (scope == null || "runtime".equalsIgnoreCase(scope) || "compile".equalsIgnoreCase(scope)) {
+                return previous;
+            }
+            if ("provided".equalsIgnoreCase(scope)) {
+                return Accept.PROVIDED;
+            }
+            return Accept.STOP;
+        }
+
     }
 
     protected class ArtifactLookupImpl
-        implements Maven2RepositoryAdapter.ArtifactLookup
-    {
+            implements Maven2RepositoryAdapter.ArtifactLookup {
 
         private final Map<org.apache.geronimo.kernel.repository.Artifact, Artifact> resolvedArtifacts;
 
@@ -273,31 +399,31 @@
             MavenProject project = getProject();
 
             return artifact.getGroupId().equals(project.getGroupId()) &&
-                   artifact.getArtifactId().equals(project.getArtifactId());
+                    artifact.getArtifactId().equals(project.getArtifactId());
         }
 
         public File getLocation(final org.apache.geronimo.kernel.repository.Artifact artifact) {
             assert artifact != null;
 
-            boolean debug = log.isDebugEnabled();
+            boolean debug = getLog().isDebugEnabled();
 
             Artifact mavenArtifact = resolvedArtifacts.get(artifact);
 
             // If not cached, then make a new artifact
             if (mavenArtifact == null) {
-                mavenArtifact = getArtifactFactory().createArtifact(
+                mavenArtifact = artifactFactory.createArtifactWithClassifier(
                         artifact.getGroupId(),
                         artifact.getArtifactId(),
                         artifact.getVersion().toString(),
-                        null,
-                        artifact.getType()
+                        artifact.getType(),
+                        null
                 );
             }
 
             // Do not attempt to resolve an artifact that is the same as the project
             if (isProjectArtifact(artifact)) {
                 if (debug) {
-                    log.debug("Skipping resolution of project artifact: " + artifact);
+                    getLog().debug("Skipping resolution of project artifact: " + artifact);
                 }
 
                 //
@@ -309,32 +435,47 @@
             }
 
             File file;
-            try {
-                if (!mavenArtifact.isResolved()) {
-                    if (debug) {
-                        log.debug("Resolving artifact: " + mavenArtifact);
-                    }
-                    mavenArtifact = resolveArtifact(mavenArtifact);
-
-                    // Cache the resolved artifact
-                    resolvedArtifacts.put(artifact, mavenArtifact);
+            if (!mavenArtifact.isResolved()) {
+                if (debug) {
+                    getLog().debug("Resolving artifact: " + mavenArtifact);
                 }
+                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);
+                // Cache the resolved artifact
+                resolvedArtifacts.put(artifact, 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);
+
             return file;
         }
     }
-    
+
+    protected Artifact resolveArtifact(Artifact mavenArtifact) {
+        return resolveArtifact(mavenArtifact.getGroupId(), mavenArtifact.getArtifactId(), mavenArtifact.getType());
+    }
+
+    protected Artifact resolveArtifact(String groupId, String artifactId, String type) {
+        for (Artifact artifact : dependencies) {
+            if (matches(groupId, artifactId, type, artifact)) {
+                return artifact;
+            }
+        }
+        return null;
+    }
+
+    private boolean matches(String groupId, String artifactId, String type, Artifact artifact) {
+        if (!groupId.equals(artifact.getGroupId())) return false;
+        if (!artifactId.equals(artifact.getArtifactId())) return false;
+        if (!type.equals(artifact.getType())) return false;
+
+        return true;
+    }
+
 }

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveCarMojo.java Mon May 19 10:48:13 2008
@@ -20,45 +20,18 @@
 package org.apache.geronimo.mavenplugins.car;
 
 import java.io.File;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Set;
 
-import org.apache.geronimo.deployment.PluginBootstrap2;
-import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.AbstractNameQuery;
-import org.apache.geronimo.gbean.GBeanData;
-import org.apache.geronimo.gbean.GBeanInfo;
-import org.apache.geronimo.gbean.ReferencePatterns;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelFactory;
-import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.kernel.Naming;
-import org.apache.geronimo.kernel.config.ConfigurationData;
-import org.apache.geronimo.kernel.config.ConfigurationManager;
-import org.apache.geronimo.kernel.config.ConfigurationUtil;
-import org.apache.geronimo.kernel.config.KernelConfigurationManager;
-import org.apache.geronimo.kernel.config.LifecycleException;
-import org.apache.geronimo.kernel.config.RecordingLifecycleMonitor;
-import org.apache.geronimo.kernel.management.State;
-import org.apache.geronimo.kernel.repository.DefaultArtifactManager;
-import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
-import org.apache.geronimo.system.repository.Maven2Repository;
-import org.apache.geronimo.system.resolver.ExplicitDefaultArtifactResolver;
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.codehaus.plexus.util.FileUtils;
 
 /**
  * Jar up a packaged plugin
@@ -172,8 +145,8 @@
     // Mojo
     //
 
-    protected void doExecute() throws Exception {
-
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        getDependencies(project, false);
         // Build the archive
         File archive = createArchive();
 
@@ -257,8 +230,10 @@
             if (entry != null) {
                 buff.append(entry);
             } else {
-                Artifact artifact = getArtifact(classpath[i]);
-
+                Artifact artifact = resolveArtifact(classpath[i].getGroupId(), classpath[i].getArtifactId(), classpath[i].getType());
+                if (artifact == null) {
+                    throw new MojoExecutionException("Could not resolve classpath item: " + classpath[i]);
+                }
                 //
                 // TODO: Need to optionally get all transitive dependencies... but dunno how to get that intel from m2
                 //
@@ -276,7 +251,8 @@
                     }
                 }
 
-                File file = artifact.getFile();
+                String path = getArtifactRepository().pathOf(artifact);
+                File file = new File(path);
                 buff.append(file.getName());
             }
 
@@ -285,7 +261,7 @@
             }
         }
 
-        log.debug("Using classpath: " + buff);
+        getLog().debug("Using classpath: " + buff);
 
         return buff.toString();
     }

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ArchiveMojo.java Mon May 19 10:48:13 2008
@@ -27,25 +27,17 @@
 import org.apache.geronimo.system.plugin.ArchiverGBean;
 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
-import org.codehaus.mojo.pluginsupport.MojoSupport;
 import org.codehaus.plexus.archiver.ArchiverException;
 
 /**
  * @version $Rev$ $Date$
  * @goal archive
  */
-public class ArchiveMojo extends MojoSupport {
-
-    /**
-     * The maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    private MavenProject project;
+public class ArchiveMojo extends AbstractCarMojo {
 
     /**
      * The target directory of the project.
@@ -88,22 +80,25 @@
      */
     private File targetFile;
 
-    protected void doExecute() throws Exception {
+    public void execute() throws MojoExecutionException, MojoFailureException {
         // this installs the pom using the default artifact handler configured in components.xml
-        log.debug("Setting artifact file: " + targetFile);
+        getLog().debug("Setting artifact file: " + targetFile);
         org.apache.maven.artifact.Artifact artifact = project.getArtifact();
         artifact.setFile(targetFile);
-        
-        // now pack up the server.
-        ServerInfo serverInfo = new BasicServerInfo(targetServerDirectory.getAbsolutePath(), false);
-        ArchiverGBean archiver = new ArchiverGBean(serverInfo);
-        if (excludes != null) {
-            for (String exclude : excludes) {
-                archiver.addExclude(exclude);
+        try {
+            //now pack up the server.
+            ServerInfo serverInfo = new BasicServerInfo(targetServerDirectory.getAbsolutePath(), false);
+            ArchiverGBean archiver = new ArchiverGBean(serverInfo);
+            if (excludes != null) {
+                for (String exclude : excludes) {
+                    archiver.addExclude(exclude);
+                }
             }
+            archive("tar.gz", archiver);
+            archive("zip", archiver);
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not archive plugin", e);
         }
-        archive("tar.gz", archiver);
-        archive("zip", archiver);
     }
 
     private void archive(String type, ArchiverGBean archiver) throws ArchiverException, IOException {

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ClasspathElement.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ClasspathElement.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ClasspathElement.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ClasspathElement.java Mon May 19 10:48:13 2008
@@ -19,8 +19,6 @@
 
 package org.apache.geronimo.mavenplugins.car;
 
-import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
-
 /**
  * Represents a Maven-artifact with additional classpath prefix details to build a
  * jar's Manifest Class-Path.
@@ -28,15 +26,52 @@
  * @version $Rev:385659 $ $Date$
  */
 public class ClasspathElement
-    extends ArtifactItem
 {
     /**
+     * Group Id of artifact.
+     *
+     * @parameter
+     * @required
+     */
+    private String groupId;
+
+    /**
+     * Name of artifact.
+     *
+     * @parameter
+     * @required
+     */
+    private String artifactId;
+
+    /**
+     * Version of artifact.
+     *
+     * @parameter
+     */
+    private String version = null;
+
+    /**
+     * Type of artifact.
+     *
+     * @parameter
+     * @required
+     */
+    private String type = "jar";
+
+    /**
+     * Classifier for artifact.
+     *
+     * @parameter
+     */
+    private String classifier;
+
+    /**
      * Prefix to be prepended to the artifact, like <tt>../lib</tt>.
      *
      * @parameter
      */
     private String classpathPrefix;
-    
+
     /**
      * Entry name used in replacement for ArtifactItem that is not resolved
      *
@@ -45,6 +80,76 @@
     private String entry;
 
     /**
+     * @return Returns the artifactId.
+     */
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    /**
+     * @param artifactId The artifactId to set.
+     */
+    public void setArtifactId(final String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    /**
+     * @return Returns the groupId.
+     */
+    public String getGroupId() {
+        return groupId;
+    }
+
+    /**
+     * @param groupId The groupId to set.
+     */
+    public void setGroupId(final String groupId) {
+        this.groupId = groupId;
+    }
+
+    /**
+     * @return Returns the type.
+     */
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * @param type The type to set.
+     */
+    public void setType(final String type) {
+        this.type = type;
+    }
+
+    /**
+     * @return Returns the version.
+     */
+    public String getVersion() {
+        return version;
+    }
+
+    /**
+     * @param version The version to set.
+     */
+    public void setVersion(final String version) {
+        this.version = version;
+    }
+
+    /**
+     * @return Classifier.
+     */
+    public String getClassifier() {
+        return classifier;
+    }
+
+    /**
+     * @param classifier Classifier.
+     */
+    public void setClassifier(final String classifier) {
+        this.classifier = classifier;
+    }
+
+    /**
      * @return Returns the classpath prefix.
      */
     public String getClasspathPrefix() {
@@ -65,4 +170,10 @@
     public void setEntry(final String entry) {
         this.entry = entry;
     }
+
+    public String toString() {
+        return classpathPrefix + "::" + groupId + ":" + artifactId + ":" + classifier + ":" + version + ":" + type + "::" + entry;
+    }
+
+
 }
\ No newline at end of file

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/CreatePluginListMojo.java Mon May 19 10:48:13 2008
@@ -27,21 +27,28 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.SortedSet;
+import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
+import java.lang.*;
 
 import javax.xml.bind.JAXBException;
 import javax.xml.stream.XMLStreamException;
 
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.repository.*;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.ListableRepository;
-import org.apache.geronimo.kernel.repository.Maven2Repository;
 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.xml.sax.SAXException;
 
 /**
@@ -55,18 +62,22 @@
  */
 public class CreatePluginListMojo extends AbstractCarMojo {
 
-    protected void doExecute() throws Exception {
+    public void execute() throws MojoExecutionException, MojoFailureException {
         String path = getArtifactRepository().getBasedir();
         File baseDir = new File(path);
 
         ListableRepository repository = new Maven2Repository(baseDir);
-        PluginListType pluginList = createPluginListForRepositories(repository,  path);
-        File outFile = new File(baseDir, "geronimo-plugins.xml");
-        Writer out = new FileWriter(outFile, false);
         try {
-            PluginXmlUtil.writePluginList(pluginList, out);
-        } finally {
-            out.close();
+            PluginListType pluginList = createPluginListForRepositories(repository,  path);
+            File outFile = new File(baseDir, "geronimo-plugins.xml");
+            Writer out = new FileWriter(outFile, false);
+            try {
+                PluginXmlUtil.writePluginList(pluginList, out);
+            } finally {
+                out.close();
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not create plugin list", e);
         }
     }
 
@@ -95,7 +106,7 @@
     private PluginType getPluginMetadata(ListableRepository repository, Artifact configId) {
         File dir = repository.getLocation(configId);
         if (!dir.isFile() || !dir.canRead()) {
-            log.error("Cannot read artifact dir " + dir.getAbsolutePath());
+            getLog().error("Cannot read artifact dir " + dir.getAbsolutePath());
             throw new IllegalStateException("Cannot read artifact dir " + dir.getAbsolutePath());
         }
         if (dir.toString().endsWith(".pom")) {
@@ -124,13 +135,13 @@
         } catch (ZipException e) {
             //not a zip file, ignore
         } catch (SAXException e) {
-            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+            getLog().error("Unable to read JAR file " + dir.getAbsolutePath(), e);
         } catch (XMLStreamException e) {
-            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+            getLog().error("Unable to read JAR file " + dir.getAbsolutePath(), e);
         } catch (JAXBException e) {
-            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+            getLog().error("Unable to read JAR file " + dir.getAbsolutePath(), e);
         } catch (IOException e) {
-            log.error("Unable to read JAR file " + dir.getAbsolutePath(), e);
+            getLog().error("Unable to read JAR file " + dir.getAbsolutePath(), e);
         }
         return null;
     }

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/InstallModulesMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/InstallModulesMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/InstallModulesMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/InstallModulesMojo.java Mon May 19 10:48:13 2008
@@ -24,6 +24,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.LinkedHashSet;
 
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.basic.BasicKernel;
@@ -33,12 +34,17 @@
 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 import org.apache.geronimo.system.plugin.SourceRepository;
 import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.model.AttributesType;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 import org.apache.geronimo.system.plugin.model.PluginListType;
 import org.apache.geronimo.system.plugin.model.PluginType;
-import org.apache.geronimo.system.plugin.model.AttributesType;
 import org.apache.geronimo.system.resolver.AliasedArtifactResolver;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.project.ProjectBuildingException;
 
 /**
  * Installs Geronimo module CAR files into a target repository to support assembly.
@@ -46,9 +52,7 @@
  * @version $Rev$ $Date$
  * @goal install-modules
  */
-public class InstallModulesMojo
-    extends AbstractCarMojo
-{
+public class InstallModulesMojo extends AbstractCarMojo {
     /**
      * The location of the server repository.
      *
@@ -133,8 +137,8 @@
      */
     private Set installedArtifacts = new HashSet();
 
-    protected void doExecute() throws Exception {
-        getDependencies(project);
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        getDependencies(project, false);
         Maven2RepositoryAdapter.ArtifactLookup lookup = new ArtifactLookupImpl(new HashMap<Artifact, org.apache.maven.artifact.Artifact>());
         SourceRepository sourceRepo = new Maven2RepositoryAdapter(dependencies, lookup);
         PluginListType pluginList = new PluginListType();
@@ -166,19 +170,21 @@
                     installer.mergeOverrides(override.getServer(), attributes);
                 }
             }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not use plugin installer bean", e);
         } finally {
             kernel.shutdown();
         }
-        log.info("Installed plugins: ");
+        getLog().info("Installed plugins: ");
         for (Artifact artifact: downloadPoller.getInstalledConfigIDs()) {
-            log.info("    " + artifact);
+            getLog().info("    " + artifact);
         }
-        log.info("Installed dependencies: ");
+        getLog().info("Installed dependencies: ");
         for (Artifact artifact: downloadPoller.getDependenciesInstalled()) {
-            log.info("    " + artifact);
+            getLog().info("    " + artifact);
         }
         if (downloadPoller.isFailed()) {
-            throw downloadPoller.getFailure();
+            throw new MojoExecutionException("Could not download all dependencies", downloadPoller.getFailure());
         }
     }
 

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java Mon May 19 10:48:13 2008
@@ -50,7 +50,8 @@
 import org.apache.geronimo.system.repository.Maven2Repository;
 import org.apache.geronimo.system.resolver.ExplicitDefaultArtifactResolver;
 import org.apache.maven.artifact.Artifact;
-import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -61,9 +62,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class PackageMojo
-    extends AbstractCarMojo
-{
+public class PackageMojo extends AbstractCarMojo {
 
 
     /**
@@ -131,15 +130,15 @@
     private File moduleFile = null;
 
     /**
-     * An {@link ArtifactItem} to include as a module of the CAR.
+     * An {@link Dependency} to include as a module of the CAR.
      *
      * @parameter
      */
-    private ArtifactItem module = null;
+    private Dependency module = null;
 
     /**
      * The location where the properties mapping will be generated.
-     *
+     * <p/>
      * <p>
      * Probably don't want to change this.
      * </p>
@@ -165,66 +164,46 @@
     // Mojo
     //
 
-    protected void doExecute() throws Exception {
-        // We need to make sure to clean up any previous work first or this operation will fail
-        FileUtils.forceDelete(targetRepository);
-        FileUtils.forceMkdir(targetRepository);
-
-        // Use the default configs if none specified
-        if (deploymentConfigs == null) {
-            if (!bootstrap) {
-                deploymentConfigs = new String[] {defaultDeploymentConfig};
-            } else {
-                deploymentConfigs = new String[] {};
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        try {
+// We need to make sure to clean up any previous work first or this operation will fail
+            FileUtils.forceDelete(targetRepository);
+            FileUtils.forceMkdir(targetRepository);
+
+            // Use the default configs if none specified
+            if (deploymentConfigs == null) {
+                if (!bootstrap) {
+                    deploymentConfigs = new String[]{defaultDeploymentConfig};
+                } else {
+                    deploymentConfigs = new String[]{};
+                }
             }
-        }
-        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.
-        //
-        Set<Artifact> additionalArtifacts = new HashSet<Artifact>();
-        for (String deploymentConfig : deploymentConfigs) {
-            Artifact artifact = geronimoToMavenArtifact(org.apache.geronimo.kernel.repository.Artifact.create(deploymentConfig));
-            log.debug("Resolving deployer module: " + artifact);
-            Artifact resolved = resolveArtifact(artifact, true);
-            additionalArtifacts.add(resolved);
-        }
-        //Ensure that these dependencies are available to geronimo
-        if (project.getDependencyArtifacts() == null) {
-            Set<Artifact> oldArtifacts = project.createArtifacts(dependencyHelper.getArtifactFactory(), null, null);
-            additionalArtifacts.addAll(oldArtifacts);
-        } else {
-            Set<Artifact> oldArtifacts = project.getDependencyArtifacts();
-            additionalArtifacts.addAll(oldArtifacts);
-        }
-        project.setDependencyArtifacts(additionalArtifacts);
-
+            getLog().debug("Deployment configs: " + Arrays.asList(deploymentConfigs));
 
-        // If module is set, then resolve the artifact and set moduleFile
-        if (module != null) {
-            Artifact artifact = getArtifact(module);
-            moduleFile = artifact.getFile();
-            log.debug("Using module file: " + moduleFile);
-        }
+            getDependencies(project, false);
+            // If module is set, then resolve the artifact and set moduleFile
+            if (module != null) {
+                Artifact artifact = resolveArtifact(module.getGroupId(), module.getArtifactId(), module.getType());
+                moduleFile = artifact.getFile();
+                getLog().debug("Using module file: " + moduleFile);
+            }
 
-        getDependencies(project);
 
-        generateExplicitVersionProperties(explicitResolutionProperties, dependencies);
+            generateExplicitVersionProperties(explicitResolutionProperties, dependencies);
 
-        //
-        // NOTE: Install a local lookup, so that the cached kernel can resolve based on the current project
-        //       and not the project where the kernel was first initialized.
-        //
-        lookupHolder.set(new ArtifactLookupImpl(new HashMap()));
+            //
+            // NOTE: Install a local lookup, so that the cached kernel can resolve based on the current project
+            //       and not the project where the kernel was first initialized.
+            //
+            lookupHolder.set(new ArtifactLookupImpl(new HashMap()));
 
-        if (bootstrap) {
-            executeBootShell();
-        }
-        else {
-            buildPackage();
+            if (bootstrap) {
+                executeBootShell();
+            } else {
+                buildPackage();
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("could not package plugin", e);
         }
     }
 
@@ -242,7 +221,7 @@
     }
 
     public void executeBootShell() throws Exception {
-        log.debug("Starting bootstrap shell...");
+        getLog().debug("Starting bootstrap shell...");
 
         PluginBootstrap2 boot = new PluginBootstrap2();
 
@@ -257,7 +236,6 @@
         boot.bootstrap();
     }
 
-
     //
     // Deployment
     //
@@ -277,7 +255,7 @@
     private boolean targetSet;
 
     public void buildPackage() throws Exception {
-        log.info("Packaging module configuration: " + planFile);
+        getLog().info("Packaging module configuration: " + planFile);
 
         Kernel kernel = createKernel();
         if (!targetSet) {
@@ -292,7 +270,7 @@
             targetSet = true;
         }
 
-        log.debug("Starting configurations..." + Arrays.asList(deploymentConfigs));
+        getLog().debug("Starting configurations..." + Arrays.asList(deploymentConfigs));
 
         // start the Configuration we're going to use for this deployment
         ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
@@ -304,14 +282,14 @@
                     try {
                         configurationManager.loadConfiguration(configName, monitor);
                     } catch (LifecycleException e) {
-                        log.error("Could not load deployer configuration: " + configName + "\n" + monitor.toString(), e);
+                        getLog().error("Could not load deployer configuration: " + configName + "\n" + monitor.toString(), e);
                     }
                     monitor = new RecordingLifecycleMonitor();
                     try {
                         configurationManager.startConfiguration(configName, monitor);
-                        log.info("Started deployer: " + configName);
+                        getLog().info("Started deployer: " + configName);
                     } catch (LifecycleException e) {
-                        log.error("Could not start deployer configuration: " + configName + "\n" + monitor.toString(), e);
+                        getLog().error("Could not start deployer configuration: " + configName + "\n" + monitor.toString(), e);
                     }
                 }
             }
@@ -319,7 +297,7 @@
             ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
         }
 
-        log.debug("Deploying...");
+        getLog().debug("Deploying...");
 
         AbstractName deployer = locateDeployer(kernel);
         invokeDeployer(kernel, deployer, targetConfigStoreAName.toString());
@@ -337,7 +315,7 @@
             return kernel;
         }
 
-        log.debug("Creating kernel...");
+        getLog().debug("Creating kernel...");
 
         // check the registry in case someone else created one
         kernel = KernelRegistry.getKernel(KERNEL_NAME);
@@ -356,14 +334,14 @@
 
     /**
      * Boot the in-Maven deployment system.
-     *
+     * <p/>
      * <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...");
+        getLog().debug("Booting deployer system...");
 
         org.apache.geronimo.kernel.repository.Artifact baseId =
                 new org.apache.geronimo.kernel.repository.Artifact("geronimo", "packaging", "fixed", "car");
@@ -381,7 +359,7 @@
             private Maven2RepositoryAdapter.ArtifactLookup getDelegate() {
                 return lookupHolder.get();
             }
-            
+
             public File getBasedir() {
                 return getDelegate().getBasedir();
             }
@@ -445,7 +423,6 @@
      *
      * @param kernel the kernel to search.
      * @return the ObjectName of the Deployer GBean
-     *
      * @throws IllegalStateException if there is not exactly one GBean matching the deployerName pattern
      */
     private AbstractName locateDeployer(final Kernel kernel) {
@@ -456,7 +433,7 @@
             throw new IllegalStateException("No deployer found matching deployerName: " + name);
         }
 
-        AbstractName deployer = (AbstractName)i.next();
+        AbstractName deployer = (AbstractName) i.next();
         if (i.hasNext()) {
             throw new IllegalStateException("Multiple deployers found matching deployerName: " + name);
         }
@@ -465,36 +442,36 @@
     }
 
     private static final String[] DEPLOY_SIGNATURE = {
-        boolean.class.getName(),
-        File.class.getName(),
-        File.class.getName(),
-        File.class.getName(),
-        Boolean.TYPE.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
-        String.class.getName(),
+            boolean.class.getName(),
+            File.class.getName(),
+            File.class.getName(),
+            File.class.getName(),
+            Boolean.TYPE.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
+            String.class.getName(),
     };
 
     private List invokeDeployer(final Kernel kernel, final AbstractName deployer, final String targetConfigStore) throws Exception {
         Object[] args = {
-            Boolean.FALSE, // Not in-place
-            moduleFile,
-            planFile,
-            null, // Target file
-            Boolean.TRUE, // Install
-            null, // main-class
-            null, // main-gbean
-            null, // main-method
-            null, // Manifest configurations
-            null, // class-path
-            null, // endorsed-dirs
-            null, // extension-dirs
-            targetConfigStore
+                Boolean.FALSE, // Not in-place
+                moduleFile,
+                planFile,
+                null, // Target file
+                Boolean.TRUE, // Install
+                null, // main-class
+                null, // main-gbean
+                null, // main-method
+                null, // Manifest configurations
+                null, // class-path
+                null, // endorsed-dirs
+                null, // extension-dirs
+                targetConfigStore
         };
 
         return (List) kernel.invoke(deployer, "deploy", args, DEPLOY_SIGNATURE);

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java Mon May 19 10:48:13 2008
@@ -33,10 +33,11 @@
 import org.apache.geronimo.deployment.xbeans.EnvironmentType;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
-import org.apache.geronimo.kernel.repository.ImportType;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.Velocity;
@@ -118,7 +119,7 @@
             String key = (String) o;
             String value = props.getProperty(key);
 
-            log.debug("Setting " + key + "=" + value);
+            getLog().debug("Setting " + key + "=" + value);
             context.put(key, value);
         }
 
@@ -127,57 +128,63 @@
         return context;
     }
 
-    protected void doExecute() throws Exception {
-        //
-        // FIXME: Do not need velocity here, we only need to filter,
-        //        could use resources plugin to do this for us, or
-        //        implement what resources plugin does here
-        //
-        //        Also velocity does not handle property expansion of expressions like
-        //        ${foo.bar} to the value of the "foo.bar" property :-(
-        //
-        //        Might be better of just hand rolling something...
-        //
-
-        VelocityContext context = createContext();
-
-        VelocityEngine velocity = new VelocityEngine();
-        velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, sourceDir.getAbsolutePath());
-
-        // Don't spit out any logs
-        velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
-        velocity.init();
-
-        Template template = velocity.getTemplate(planFileName);
-        StringWriter writer = new StringWriter();
-        template.merge(context, writer);
-
-        String plan = writer.toString();
-
-        XmlObject doc = XmlObject.Factory.parse(plan);
-        XmlCursor xmlCursor = doc.newCursor();
-        LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> dependencies = toDependencies();
-        Artifact configId = new Artifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "car");
-
+    public void execute() throws MojoExecutionException, MojoFailureException {
         try {
-            mergeEnvironment(xmlCursor, configId, dependencies);
-
-            if (targetDir.exists()) {
-                if (!targetDir.isDirectory()) {
-                    throw new RuntimeException("TargetDir: " + this.targetDir + " exists and is not a directory");
+//
+            // FIXME: Do not need velocity here, we only need to filter,
+            //        could use resources plugin to do this for us, or
+            //        implement what resources plugin does here
+            //
+            //        Also velocity does not handle property expansion of expressions like
+            //        ${foo.bar} to the value of the "foo.bar" property :-(
+            //
+            //        Might be better of just hand rolling something...
+            //
+
+            VelocityContext context = createContext();
+
+            VelocityEngine velocity = new VelocityEngine();
+            velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, sourceDir.getAbsolutePath());
+
+            // Don't spit out any logs
+            velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
+            velocity.init();
+
+            Template template = velocity.getTemplate(planFileName);
+            StringWriter writer = new StringWriter();
+            template.merge(context, writer);
+
+            String plan = writer.toString();
+
+            XmlObject doc = XmlObject.Factory.parse(plan);
+            XmlCursor xmlCursor = doc.newCursor();
+            LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> dependencies = toDependencies(this.dependencies, useMavenDependencies);
+            Artifact configId = new Artifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "car");
+
+            try {
+                mergeEnvironment(xmlCursor, configId, dependencies);
+
+                if (targetDir.exists()) {
+                    if (!targetDir.isDirectory()) {
+                        throw new RuntimeException("TargetDir: " + this.targetDir + " exists and is not a directory");
+                    }
+                } else {
+                    targetDir.mkdirs();
                 }
-            } else {
-                targetDir.mkdirs();
-            }
 
-            XmlOptions xmlOptions = new XmlOptions();
-            xmlOptions.setSavePrettyPrint();
-            doc.save(targetFile, xmlOptions);
+                XmlOptions xmlOptions = new XmlOptions();
+                xmlOptions.setSavePrettyPrint();
+                doc.save(targetFile, xmlOptions);
 
-            log.info("Generated: " + targetFile);
-        }
-        finally {
-            xmlCursor.dispose();
+                if (getLog() != null) {
+                    getLog().info("Generated: " + targetFile);
+                }
+            }
+            finally {
+                xmlCursor.dispose();
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not process plan", e);
         }
     }
 
@@ -258,64 +265,22 @@
         }
     }
 
-    private LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> toDependencies() throws InvalidDependencyVersionException, ArtifactResolutionException, ProjectBuildingException {
+    protected LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> toDependencies(List<Dependency> listedDependencies, UseMavenDependencies useMavenDependencies) throws InvalidDependencyVersionException, ArtifactResolutionException, ProjectBuildingException, MojoExecutionException {
         LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> dependencies = new LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>();
 
         if (useMavenDependencies == null || !useMavenDependencies.isValue()) {
-            for (Dependency dependency : this.dependencies) {
+            for (Dependency dependency : listedDependencies) {
                 org.apache.geronimo.kernel.repository.Dependency gdep = dependency.toDependency();
                 dependencies.add(gdep);
             }
         } else {
-            LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> carDependencies = new LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>();
-            getDependencies(project);
-            processProject(dependencies, carDependencies, projectNode, useMavenDependencies.isUseTransitiveDependencies());
-            dependencies.removeAll(carDependencies);
-        }
-
-        return dependencies;
-    }
-
-    private void processProject(LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> dependencies, LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> carDependencies, ProjectNode node, boolean useTransitiveDependencies) {
-        List<ProjectNode> includedNodes = node.getChildNodes();
-        for (ProjectNode childNode : includedNodes) {
-            org.apache.maven.artifact.Artifact artifact = childNode.getArtifact();
-            if (includeDependency(artifact)) {
-                org.apache.geronimo.kernel.repository.Dependency gdep = toGeronimoDependency(dependencyMap.get(artifact), useMavenDependencies.isIncludeVersion());
-                dependencies.add(gdep);
-                if (useTransitiveDependencies) {
-
-                    if (artifact.getType().equalsIgnoreCase("car")) {
-                        processProject(carDependencies, carDependencies, childNode, useTransitiveDependencies);
-                    } else {
-                        processProject(dependencies, carDependencies, childNode, useTransitiveDependencies);
-                    }
-                }
+            getDependencies(project, useMavenDependencies.isUseTransitiveDependencies());
+            for (org.apache.maven.artifact.Artifact artifact: localDependencies) {
+                dependencies.add(toGeronimoDependency(artifact, useMavenDependencies.isIncludeVersion()));
             }
         }
-    }
 
-    private boolean includeDependency(org.apache.maven.artifact.Artifact dependency) {
-        if (dependency.getGroupId().startsWith("org.apache.geronimo.genesis")) {
-            return false;
-        }
-        String scope = dependency.getScope();
-        return scope == null || "runtime".equalsIgnoreCase(scope) || "compile".equalsIgnoreCase(scope);
-    }
-
-
-    private static org.apache.geronimo.kernel.repository.Dependency toGeronimoDependency(final org.apache.maven.artifact.Artifact dependency, boolean includeVersion) {
-        Artifact artifact = toGeronimoArtifact(dependency, includeVersion);
-        return new org.apache.geronimo.kernel.repository.Dependency(artifact, ImportType.ALL);
-    }
-
-    private static Artifact toGeronimoArtifact(final org.apache.maven.artifact.Artifact dependency, boolean includeVersion) {
-        String groupId = dependency.getGroupId();
-        String artifactId = dependency.getArtifactId();
-        String version = includeVersion ? dependency.getVersion() : null;
-        String type = dependency.getType();
-
-        return new Artifact(groupId, artifactId, version, type);
+        return dependencies;
     }
 
 

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java?rev=657880&r1=657879&r2=657880&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java (original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java Mon May 19 10:48:13 2008
@@ -27,24 +27,23 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.geronimo.kernel.config.ConfigurationData;
-import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
-import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.system.configuration.RepositoryConfigurationStore;
-import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 import org.apache.geronimo.system.plugin.PluginXmlUtil;
 import org.apache.geronimo.system.plugin.model.ArtifactType;
 import org.apache.geronimo.system.plugin.model.DependencyType;
 import org.apache.geronimo.system.plugin.model.LicenseType;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
 import org.apache.geronimo.system.plugin.model.PluginType;
-import org.apache.geronimo.system.repository.Maven2Repository;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.model.License;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
 import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
@@ -133,149 +132,138 @@
      * since maven will not merge them correctly.  Actually we have to fish this out of the model since maven mangles the xml for us.
      */
 //    private PlexusConfiguration instance;
-    protected void doExecute() throws Exception {
-
-        PluginType metadata = new PluginType();
-        metadata.setName(project.getName());
-        metadata.setAuthor(project.getOrganization() == null? "unknown": project.getOrganization().getName());
-        metadata.setUrl(project.getOrganization() == null? "unknown": project.getOrganization().getUrl());
-        metadata.setDescription(project.getDescription());
-        metadata.setCategory(category);
-
-        if (project.getLicenses() != null) {
-            for (Object licenseObj : project.getLicenses()) {
-                License license = (License) licenseObj;
-                LicenseType licenseType = new LicenseType();
-                licenseType.setValue(license.getName());
-                licenseType.setOsiApproved(osiApproved);
-                metadata.getLicense().add(licenseType);
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        try {
+            PluginType metadata = new PluginType();
+            metadata.setName(project.getName());
+            metadata.setAuthor(project.getOrganization() == null? "unknown": project.getOrganization().getName());
+            metadata.setUrl(project.getOrganization() == null? "unknown": project.getOrganization().getUrl());
+            metadata.setDescription(project.getDescription());
+            metadata.setCategory(category);
+
+            if (project.getLicenses() != null) {
+                for (Object licenseObj : project.getLicenses()) {
+                    License license = (License) licenseObj;
+                    LicenseType licenseType = new LicenseType();
+                    licenseType.setValue(license.getName());
+                    licenseType.setOsiApproved(osiApproved);
+                    metadata.getLicense().add(licenseType);
+                }
             }
-        }
-
-        PluginArtifactType instance;
-        Plugin plugin = (Plugin) project.getModel().getBuild().getPluginsAsMap().get("org.apache.geronimo.buildsupport:car-maven-plugin");
-        if (plugin == null) {
-            throw new Error("Unable to resolve car plugin");
-        }
 
-        Xpp3Dom dom;
-        if (plugin.getExecutions().isEmpty()) {
-            dom = (Xpp3Dom) plugin.getConfiguration();
-        } else {
-            if (plugin.getExecutions().size() > 1) {
-                throw new IllegalStateException("Cannot determine correct configuration for PluginMetadataGeneratorMojo: " + plugin.getExecutionsAsMap().keySet());
+            PluginArtifactType instance;
+            Plugin plugin = (Plugin) project.getModel().getBuild().getPluginsAsMap().get("org.apache.geronimo.buildsupport:car-maven-plugin");
+            if (plugin == null) {
+                throw new Error("Unable to resolve car plugin");
             }
-            dom = (Xpp3Dom) ((PluginExecution) plugin.getExecutions().get(0)).getConfiguration();
-        }
-        Xpp3Dom instanceDom = dom.getChild("instance");
 
-        if (instanceDom == null || instanceDom.getChild("plugin-artifact") == null) {
-            instance = new PluginArtifactType();
-        } else {
-            String instanceString = instanceDom.getChild("plugin-artifact").toString();
-            instance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(instanceString.replace("#{", "${")));
-        }
-        if (this.commonInstance != null && this.commonInstance.getChild("plugin-artifact") != null) {
-            PluginArtifactType commonInstance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(this.commonInstance.getChild("plugin-artifact").toString().replace("#{", "${")));
-            //merge
-            if (instance.getArtifactAlias().isEmpty()) {
-                instance.getArtifactAlias().addAll(commonInstance.getArtifactAlias());
-            }
-            if (instance.getConfigSubstitution().isEmpty()) {
-                instance.getConfigSubstitution().addAll(commonInstance.getConfigSubstitution());
-            }
-            //it doesn't make sense to copy a "generic" config.xml content into a specific module.
-//            if ((instance.getConfigXmlContent() == null || instance.getConfigXmlContent().getGbean().isEmpty())
-//                    && (commonInstance.getConfigXmlContent() != null && !commonInstance.getConfigXmlContent().getGbean().isEmpty())) {
-//                instance.setConfigXmlContent(new ConfigXmlContentType());
-//                instance.getConfigXmlContent().getGbean().addAll(commonInstance.getConfigXmlContent().getGbean());
-//            }
-            if (instance.getCopyFile().isEmpty()) {
-                instance.getCopyFile().addAll(commonInstance.getCopyFile());
-            }
-            if (instance.getDependency().isEmpty()) {
-                instance.getDependency().addAll(commonInstance.getDependency());
-            }
-            if (instance.getGeronimoVersion().isEmpty()) {
-                instance.getGeronimoVersion().addAll(commonInstance.getGeronimoVersion());
-            }
-            if (instance.getJvmVersion().isEmpty()) {
-                instance.getJvmVersion().addAll(commonInstance.getJvmVersion());
-            }
-            if (instance.getObsoletes().isEmpty()) {
-                instance.getObsoletes().addAll(commonInstance.getObsoletes());
+            Xpp3Dom dom;
+            if (plugin.getExecutions().isEmpty()) {
+                dom = (Xpp3Dom) plugin.getConfiguration();
+            } else {
+                if (plugin.getExecutions().size() > 1) {
+                    throw new IllegalStateException("Cannot determine correct configuration for PluginMetadataGeneratorMojo: " + plugin.getExecutionsAsMap().keySet());
+                }
+                dom = (Xpp3Dom) ((PluginExecution) plugin.getExecutions().get(0)).getConfiguration();
             }
-            if (instance.getPrerequisite().isEmpty()) {
-                instance.getPrerequisite().addAll(commonInstance.getPrerequisite());
+            Xpp3Dom instanceDom = dom.getChild("instance");
+
+            if (instanceDom == null || instanceDom.getChild("plugin-artifact") == null) {
+                instance = new PluginArtifactType();
+            } else {
+                String instanceString = instanceDom.getChild("plugin-artifact").toString();
+                instance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(instanceString.replace("#{", "${")));
             }
-            if (instance.getSourceRepository().isEmpty()) {
-                instance.getSourceRepository().addAll(commonInstance.getSourceRepository());
+            if (this.commonInstance != null && this.commonInstance.getChild("plugin-artifact") != null) {
+                PluginArtifactType commonInstance = PluginXmlUtil.loadPluginArtifactMetadata(new StringReader(this.commonInstance.getChild("plugin-artifact").toString().replace("#{", "${")));
+                //merge
+                if (instance.getArtifactAlias().isEmpty()) {
+                    instance.getArtifactAlias().addAll(commonInstance.getArtifactAlias());
+                }
+                if (instance.getConfigSubstitution().isEmpty()) {
+                    instance.getConfigSubstitution().addAll(commonInstance.getConfigSubstitution());
+                }
+                //it doesn't make sense to copy a "generic" config.xml content into a specific module.
+    //            if ((instance.getConfigXmlContent() == null || instance.getConfigXmlContent().getGbean().isEmpty())
+    //                    && (commonInstance.getConfigXmlContent() != null && !commonInstance.getConfigXmlContent().getGbean().isEmpty())) {
+    //                instance.setConfigXmlContent(new ConfigXmlContentType());
+    //                instance.getConfigXmlContent().getGbean().addAll(commonInstance.getConfigXmlContent().getGbean());
+    //            }
+                if (instance.getCopyFile().isEmpty()) {
+                    instance.getCopyFile().addAll(commonInstance.getCopyFile());
+                }
+                if (instance.getDependency().isEmpty()) {
+                    instance.getDependency().addAll(commonInstance.getDependency());
+                }
+                if (instance.getGeronimoVersion().isEmpty()) {
+                    instance.getGeronimoVersion().addAll(commonInstance.getGeronimoVersion());
+                }
+                if (instance.getJvmVersion().isEmpty()) {
+                    instance.getJvmVersion().addAll(commonInstance.getJvmVersion());
+                }
+                if (instance.getObsoletes().isEmpty()) {
+                    instance.getObsoletes().addAll(commonInstance.getObsoletes());
+                }
+                if (instance.getPrerequisite().isEmpty()) {
+                    instance.getPrerequisite().addAll(commonInstance.getPrerequisite());
+                }
+                if (instance.getSourceRepository().isEmpty()) {
+                    instance.getSourceRepository().addAll(commonInstance.getSourceRepository());
+                }
             }
-        }
-        metadata.getPluginArtifact().add(instance);
+            metadata.getPluginArtifact().add(instance);
 
-        ArtifactType artifactType = new ArtifactType();
-        artifactType.setGroupId(project.getGroupId());
-        artifactType.setArtifactId(project.getArtifactId());
-        artifactType.setVersion(project.getVersion());
-        ArtifactType existingArtifact = instance.getModuleId();
-        if (existingArtifact != null && existingArtifact.getType() != null) {
-            artifactType.setType(existingArtifact.getType());
-        } else {
-            artifactType.setType(project.getArtifact().getType());
-        }
-        instance.setModuleId(artifactType);
-        addDependencies(instance);
-        targetDir.mkdirs();
-        File targetFile = new File(targetDir.toURI().resolve(pluginMetadataFileName));
-        targetFile.getParentFile().mkdirs();
-        FileOutputStream out = new FileOutputStream(targetFile);
-        try {
-            PluginXmlUtil.writePluginMetadata(metadata, out);
-        } finally {
-            out.close();
+            ArtifactType artifactType = new ArtifactType();
+            artifactType.setGroupId(project.getGroupId());
+            artifactType.setArtifactId(project.getArtifactId());
+            artifactType.setVersion(project.getVersion());
+            ArtifactType existingArtifact = instance.getModuleId();
+            if (existingArtifact != null && existingArtifact.getType() != null) {
+                artifactType.setType(existingArtifact.getType());
+            } else {
+                artifactType.setType(project.getArtifact().getType());
+            }
+            instance.setModuleId(artifactType);
+            addDependencies(instance);
+            targetDir.mkdirs();
+            File targetFile = new File(targetDir.toURI().resolve(pluginMetadataFileName));
+            targetFile.getParentFile().mkdirs();
+            FileOutputStream out = new FileOutputStream(targetFile);
+            try {
+                PluginXmlUtil.writePluginMetadata(metadata, out);
+            } finally {
+                out.close();
+            }
+            Resource resource = new Resource();
+            resource.setDirectory(targetDir.getPath());
+            resource.addInclude(pluginMetadataFileName);
+            getProject().getResources().add(resource);
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not create plugin metadata", e);
         }
-        Resource resource = new Resource();
-        resource.setDirectory(targetDir.getPath());
-        resource.addInclude(pluginMetadataFileName);
-        getProject().getResources().add(resource);
     }
 
-    private void addDependencies(PluginArtifactType instance) throws InvalidConfigException, IOException, NoSuchConfigException {
+    private void addDependencies(PluginArtifactType instance) throws InvalidConfigException, IOException, NoSuchConfigException, InvalidDependencyVersionException, ArtifactResolutionException, ProjectBuildingException, MojoExecutionException {
         if (useMavenDependencies == null || !useMavenDependencies.isValue()) {
             for (Dependency dependency : dependencies) {
                 instance.getDependency().add(dependency.toDependencyType());
             }
         } else {
-            if (targetRepository.exists() && targetRepository.isDirectory()) {
-                Maven2Repository targetRepo = new Maven2Repository(targetRepository);
-                ConfigurationStore configStore = new RepositoryConfigurationStore(targetRepo);
-                Artifact pluginArtifact = PluginInstallerGBean.toArtifact(instance.getModuleId());
-                ConfigurationData data = configStore.loadConfiguration(pluginArtifact);
-                PluginInstallerGBean.addGeronimoDependencies(data, instance.getDependency(), useMavenDependencies.isIncludeVersion());
-            } else {
-                List<org.apache.maven.model.Dependency> includedDependencies = project.getOriginalModel().getDependencies();
-                List<org.apache.maven.model.Dependency> artifacts = project.getDependencies();
-                for (org.apache.maven.model.Dependency dependency : includedDependencies) {
-                    dependency = resolveDependency(dependency, artifacts);
-                    if (includeDependency(dependency)) {
-                        DependencyType gdep = toGeronimoDependency(dependency, useMavenDependencies.isIncludeVersion());
-                        instance.getDependency().add(gdep);
-                    }
-                }
+            getDependencies(project, useMavenDependencies.isUseTransitiveDependencies());
+            for (org.apache.maven.artifact.Artifact artifact: localDependencies) {
+                instance.getDependency().add(toDependencyType(toGeronimoDependency(artifact, useMavenDependencies.isIncludeVersion())));
             }
-
         }
     }
 
-    private static DependencyType toGeronimoDependency(final org.apache.maven.model.Dependency dependency, boolean includeVersion) {
+    private DependencyType toDependencyType(org.apache.geronimo.kernel.repository.Dependency dependency) {
         DependencyType dependencyType = new DependencyType();
-        dependencyType.setGroupId(dependency.getGroupId());
-        dependencyType.setArtifactId(dependency.getArtifactId());
-        if (includeVersion) {
-            dependencyType.setVersion(dependency.getVersion());
+        dependencyType.setGroupId(dependency.getArtifact().getGroupId());
+        dependencyType.setArtifactId(dependency.getArtifact().getArtifactId());
+        if (dependency.getArtifact().getVersion() != null) {
+            dependencyType.setVersion(dependency.getArtifact().getVersion().toString());
         }
-        dependencyType.setType(dependency.getType());
+        dependencyType.setType(dependency.getArtifact().getType());
         dependencyType.setStart(true);
         return dependencyType;
     }