diff --git a/build.properties b/build.properties index dac095d794..ced4f0227b 100644 --- a/build.properties +++ b/build.properties @@ -17,7 +17,7 @@ aspectj.version=1.5.3 classworlds.version=1.2-alpha-10 -plexus.version=1.0-alpha-38 +plexus.version=1.0-alpha-39 plexus-utils.version=1.4.5 maven-artifact.version=3.0-SNAPSHOT commons-cli.version=1.0 diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index 42c15936f1..872b9fd819 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -19,6 +19,167 @@ under the License. + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + jar + org.apache.maven.artifact.handler.DefaultArtifactHandler + + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + test-jar + org.apache.maven.artifact.handler.DefaultArtifactHandler + + tests + jar + test-jar + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + maven-plugin + org.apache.maven.artifact.handler.DefaultArtifactHandler + + maven-plugin + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + pom + org.apache.maven.artifact.handler.DefaultArtifactHandler + + pom + + + + + org.apache.maven.artifact.handler.ArtifactHandler + java-source + org.apache.maven.artifact.handler.DefaultArtifactHandler + + sources + java-source + jar + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + javadoc + org.apache.maven.artifact.handler.DefaultArtifactHandler + + javadoc + javadoc + jar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + war + org.apache.maven.artifact.handler.DefaultArtifactHandler + + war + true + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ear + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ear + true + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb-client + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb-client + jar + ejb + client + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + rar + org.apache.maven.artifact.handler.DefaultArtifactHandler + + rar + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + par + org.apache.maven.artifact.handler.DefaultArtifactHandler + + par + java + true + + + + + org.apache.maven.artifact.handler.ArtifactHandler + ejb3 + org.apache.maven.artifact.handler.DefaultArtifactHandler + + ejb3 + java + true + + + org.apache.maven.extension.BuildExtensionScanner default diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java new file mode 100644 index 0000000000..8caf3fc880 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/PomMetadataSource.java @@ -0,0 +1,206 @@ +package org.apache.maven.project.artifact; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; +import org.apache.maven.artifact.resolver.metadata.ArtifactMetadata; +import org.apache.maven.artifact.resolver.metadata.MetadataResolution; +import org.apache.maven.artifact.resolver.metadata.MetadataRetrievalException; +import org.apache.maven.artifact.resolver.metadata.MetadataSource; +import org.apache.maven.context.BuildContextManager; +import org.apache.maven.model.Dependency; +import org.apache.maven.project.InvalidProjectModelException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.build.ProjectBuildCache; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * @author Jason van Zyl + * @version $Id$ + */ +public class PomMetadataSource + extends AbstractLogEnabled + implements MetadataSource, Contextualizable +{ + public static final String ROLE_HINT = "default"; + + private MavenProjectBuilder mavenProjectBuilder; + + private ArtifactFactory artifactFactory; + + private BuildContextManager buildContextManager; + + // lazily instantiated and cached. + private MavenProject superProject; + + private PlexusContainer container; + + /** Unfortunately we have projects that are still sending us JARs without the accompanying POMs. */ + private boolean strictlyEnforceThePresenceOfAValidMavenPOM = true; + + public MetadataResolution retrieve( ArtifactMetadata artifactMetadata, + ArtifactRepository localRepository, + List remoteRepositories ) + throws MetadataRetrievalException + { + try + { + loadProjectBuilder(); + } + catch ( ComponentLookupException e ) + { + throw new MetadataRetrievalException( + "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e ); + } + + ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager ); + + MavenProject project; + + Artifact pomArtifact = artifactFactory.createProjectArtifact( artifactMetadata.getGroupId(), artifactMetadata.getArtifactId(), + artifactMetadata.getVersion(), artifactMetadata.getScope() ); + + project = cache.getCachedProject( artifactMetadata.getGroupId(), artifactMetadata.getArtifactId(), artifactMetadata.getVersion() ); + + if ( project == null ) + { + try + { + project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository ); + } + catch ( InvalidProjectModelException e ) + { + // We want to capture this in the graph so that we can display the error to the user + } + catch ( ProjectBuildingException e ) + { + if ( strictlyEnforceThePresenceOfAValidMavenPOM ) + { + throw new MetadataRetrievalException( + "Unable to read the metadata file for artifactMetadata '" + + artifactMetadata.getDependencyConflictId() + "': " + e.getMessage(), e, artifactMetadata ); + } + } + } + + Set artifacts = new HashSet(); + + for ( Iterator i = project.getDependencies().iterator(); i.hasNext(); ) + { + Dependency d = (Dependency) i.next(); + + artifacts.add( new ArtifactMetadata( d.getGroupId(), d.getArtifactId(), d.getVersion() ) ); + } + + // The remote repositories is intentially null here while working in the graph in the least invasive way + // and making sure repositories added for a POM are scope only for a particular POM. We don't want + // repositories lingering around or being aggregated after they are used. jvz + + return new MetadataResolution( artifacts, null ); + } + + private void loadProjectBuilder() + throws ComponentLookupException + { + if ( mavenProjectBuilder == null ) + { + mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class ); + } + } + + private List aggregateRepositoryLists( List remoteRepositories, + List remoteArtifactRepositories ) + throws ArtifactMetadataRetrievalException + { + if ( superProject == null ) + { + try + { + superProject = mavenProjectBuilder.buildStandaloneSuperProject(); + } + catch ( ProjectBuildingException e ) + { + throw new ArtifactMetadataRetrievalException( + "Unable to parse the Maven built-in model: " + e.getMessage(), e ); + } + } + + List repositories = new ArrayList(); + + repositories.addAll( remoteRepositories ); + + // ensure that these are defined + for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); ) + { + ArtifactRepository superRepo = (ArtifactRepository) it.next(); + + for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); ) + { + ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next(); + + // if the repository exists in the list and was introduced by another POM's super-pom, + // remove it...the repository definitions from the super-POM should only be at the end of + // the list. + // if the repository has been redefined, leave it. + if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) ) + { + aggregatedIterator.remove(); + } + } + } + + // this list should contain the super-POM repositories, so we don't have to explicitly add them back. + for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) + { + ArtifactRepository repository = (ArtifactRepository) it.next(); + + if ( !repositories.contains( repository ) ) + { + repositories.add( repository ); + } + } + + return repositories; + } + + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } +} \ No newline at end of file diff --git a/maven-project/src/main/resources/META-INF/plexus/components.xml b/maven-project/src/main/resources/META-INF/plexus/components.xml index 12de897237..695b2b6cd4 100644 --- a/maven-project/src/main/resources/META-INF/plexus/components.xml +++ b/maven-project/src/main/resources/META-INF/plexus/components.xml @@ -69,9 +69,6 @@ under the License. - - - org.apache.maven.project.build.model.ModelLineageBuilder default @@ -346,6 +343,21 @@ under the License. + + org.apache.maven.artifact.resolver.metadata.MetadataSource + default + org.apache.maven.project.artifact.PomMetadataSource + + + org.apache.maven.artifact.factory.ArtifactFactory + + + org.apache.maven.context.BuildContextManager + default + + + + org.apache.maven.MavenTools org.apache.maven.DefaultMavenTools diff --git a/pom.xml b/pom.xml index 33f8ed6abe..921abced73 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ under the License. maven-embedder - 1.0-alpha-38 + 1.0-alpha-39 1.0-beta-2 @@ -294,4 +294,4 @@ under the License. - \ No newline at end of file +