Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 65348 invoked from network); 28 Oct 2006 23:37:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Oct 2006 23:37:18 -0000 Received: (qmail 98222 invoked by uid 500); 28 Oct 2006 23:37:29 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 98194 invoked by uid 500); 28 Oct 2006 23:37:29 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 98183 invoked by uid 99); 28 Oct 2006 23:37:29 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Oct 2006 16:37:29 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Oct 2006 16:37:16 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 0F6A81A9846; Sat, 28 Oct 2006 16:36:55 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r468786 - /geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java Date: Sat, 28 Oct 2006 23:36:54 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061028233655.0F6A81A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jdillon Date: Sat Oct 28 16:36:54 2006 New Revision: 468786 URL: http://svn.apache.org/viewvc?view=rev&rev=468786 Log: Install an ArtifactLookup into a thread local to allow the cached G kernel's repo adapter to resolved based on the current project For some crazy reason some CAR builds depend on themselves... so when the artifact is the same as the project being built do not resolve and only return the path in the repo where it _should_ exist, else if we return null a bunch of stuff breaks Cache artifacts once we resolve them to prevent needing to ask mvn to keep resolving them over and over Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PackageMojo.java 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=468786&r1=468785&r2=468786 ============================================================================== --- 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 16:36:54 2006 @@ -27,6 +27,8 @@ import java.util.Set; import java.util.HashSet; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.apache.geronimo.deployment.PluginBootstrap2; import org.apache.geronimo.system.configuration.RepositoryConfigurationStore; @@ -55,6 +57,7 @@ import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.archiver.jar.JarArchiver; @@ -221,6 +224,12 @@ */ private boolean bootstrap = false; + /** + * Holds a local repo lookup instance so that we can use the current project to resolve. + * This is required since the Kernel used to deploy is cached. + */ + private static ThreadLocal lookupHolder = new ThreadLocal(); + // // Mojo // @@ -265,6 +274,12 @@ generateExplicitVersionProperties(explicitResolutionProperties); + // + // 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()); + if (bootstrap) { executeBootShell(); } @@ -490,44 +505,16 @@ // GBeanData repoGBean = bootstrap.addGBean("SourceRepository", GBeanInfo.getGBeanInfo(Maven2RepositoryAdapter.class.getName(), cl)); Maven2RepositoryAdapter.ArtifactLookup lookup = new Maven2RepositoryAdapter.ArtifactLookup() { + private Maven2RepositoryAdapter.ArtifactLookup getDelegate() { + return (Maven2RepositoryAdapter.ArtifactLookup) lookupHolder.get(); + } + public File getBasedir() { - String path = getArtifactRepository().getBasedir(); - return new File(path); + return getDelegate().getBasedir(); } 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; + return getDelegate().getLocation(artifact); } }; repoGBean.setAttribute("lookup", lookup); @@ -637,5 +624,90 @@ }; return (List) kernel.invoke(deployer, "deploy", args, DEPLOY_SIGNATURE); + } + + // + // ArtifactLookupImpl + // + + /** + * Map of G artifact to M artifact which have already been resolved. + */ + private static Map presolvedArtifacts = new HashMap(); + + private class ArtifactLookupImpl + implements Maven2RepositoryAdapter.ArtifactLookup + { + public File getBasedir() { + String path = getArtifactRepository().getBasedir(); + return new File(path); + } + + private boolean isProjectArtifact(final org.apache.geronimo.kernel.repository.Artifact artifact) { + MavenProject project = getProject(); + + return artifact.getGroupId().equals(project.getGroupId()) && + artifact.getArtifactId().equals(project.getArtifactId()); + } + + public File getLocation(final org.apache.geronimo.kernel.repository.Artifact artifact) { + assert artifact != null; + + boolean debug = log.isDebugEnabled(); + + Artifact mavenArtifact = (Artifact)presolvedArtifacts.get(artifact); + + // If not cached, then make a new artifact + if (mavenArtifact == null) { + mavenArtifact = getArtifactFactory().createArtifact( + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion().toString(), + null, + artifact.getType() + ); + } + + // 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); + } + + // + // HACK: Still have to return something, otherwise some CAR packaging will fail... + // no idea what is using this file, or if the files does exist if that will be + // used instead of any details we are currently building + // + return new File(getBasedir(), getArtifactRepository().pathOf(mavenArtifact)); + } + + File file; + try { + if (!mavenArtifact.isResolved()) { + if (debug) { + log.debug("Resolving artifact: " + mavenArtifact); + } + mavenArtifact = resolveArtifact(mavenArtifact); + + // Cache the resolved artifact + presolvedArtifacts.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); + file = new File(mavenArtifact.getFile().getParentFile(), file.getName()); + } + catch (MojoExecutionException e) { + throw new RuntimeException("Failed to resolve: " + mavenArtifact, e); + } + + return file; + } } }