From d25a161f33cf159536e402609746d725633c0731 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Tue, 30 Sep 2008 04:58:51 +0000 Subject: [PATCH] Remove repository helper. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@700336 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/DefaultMavenProjectBuilder.java | 46 ++- .../project/DefaultRepositoryHelper.java | 291 ------------------ .../maven/project/RepositoryHelper.java | 32 -- .../resources/META-INF/plexus/components.xml | 26 +- .../maven/project/ProjectClasspathTest.xml | 38 --- .../canonical/CanonicalProjectBuilderTest.xml | 39 +-- 6 files changed, 36 insertions(+), 436 deletions(-) delete mode 100644 maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java delete mode 100644 maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 9a9e2723e4..1a6c8d51d5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -93,8 +93,6 @@ public class DefaultMavenProjectBuilder private ProjectBuilder projectBuilder; - private RepositoryHelper repositoryHelper; - private Logger logger; //DO NOT USE, it is here only for backward compatibility reasons. The existing @@ -131,7 +129,7 @@ public class DefaultMavenProjectBuilder throws ProjectBuildingException { MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( - config.getLocalRepository(), repositoryHelper.buildArtifactRepositories( + config.getLocalRepository(), buildArtifactRepositories( getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config ); project.setFile( projectDescriptor ); @@ -164,21 +162,29 @@ public class DefaultMavenProjectBuilder if ( project != null ) { return project; - } - - File f = (artifact.getFile() != null) ? artifact.getFile() : - new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );; - repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); + } + File originalArtifactFile = artifact.getFile(); + File f; + if ( !"pom".equals( artifact.getType() ) ) + { + Artifact a = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), artifact.getScope() ); + f = new File( localRepository.getBasedir(), localRepository.pathOf( a ) ); + } else + { + f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); + } ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ); List artifactRepositories = new ArrayList( remoteArtifactRepositories ); - artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories( getSuperProject( config, artifact.getFile(), false ).getModel() ) ); + artifactRepositories.addAll( buildArtifactRepositories( getSuperProject( config, f, false ).getModel() ) ); - project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); - project = buildInternal( project.getModel(), config, artifact.getFile(), project.getParentFile(), false ); + project = readModelFromLocalPath( "unknown", f, new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); + project = buildInternal( project.getModel(), config, f, project.getParentFile(), false ); + + artifact.setFile( originalArtifactFile ); - artifact.setFile( f ); project.setVersion( artifact.getVersion() ); hm.put( artifact.getId(), project ); @@ -595,4 +601,20 @@ public class DefaultMavenProjectBuilder setBuildOutputDirectoryOnParent( parent ); } } + + public List buildArtifactRepositories( Model model ) + throws ProjectBuildingException + { + try + { + return mavenTools.buildArtifactRepositories( model.getRepositories() ); + } + catch ( InvalidRepositoryException e ) + { + String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); + + throw new ProjectBuildingException( projectId, e.getMessage(), e ); + } + } + } \ No newline at end of file diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java b/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java deleted file mode 100644 index b3f9bfd1f4..0000000000 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java +++ /dev/null @@ -1,291 +0,0 @@ -package org.apache.maven.project; - -/* - * 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.MavenTools; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactStatus; -import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Model; -import org.apache.maven.model.Repository; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.profiles.activation.ProfileActivationContext; -import org.apache.maven.profiles.build.ProfileAdvisor; -import org.codehaus.plexus.logging.LogEnabled; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.*; - -/** - * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be - * eliminated when Mercury is integrated. - */ -public class DefaultRepositoryHelper - implements RepositoryHelper, Initializable, LogEnabled -{ - - private Logger logger; - - public static final String MAVEN_MODEL_VERSION = "4.0.0"; - - private ArtifactFactory artifactFactory; - - private ArtifactResolver artifactResolver; - - private MavenTools mavenTools; - - private ProfileAdvisor profileAdvisor; - - private MavenXpp3Reader modelReader; - - private static HashMap cache = new HashMap(); - - private Logger getLogger() - { - return logger; - } - - public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, - ArtifactRepository localRepository ) - throws ProjectBuildingException - { - - if(cache.containsKey(artifact.getId())) - { - artifact.setFile(cache.get(artifact.getId()).getFile()); - } - - String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); - remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId ); - - Artifact projectArtifact; - - // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. - if ( "pom".equals( artifact.getType() ) ) - { - projectArtifact = artifact; - } - else - { - getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" + - artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " + artifact.getType() + - "; constructing POM artifact instead." ); - - projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getScope() ); - } - - try - { - artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); - - File file = projectArtifact.getFile(); - artifact.setFile( file ); - cache.put(artifact.getId(), artifact); - } - catch ( ArtifactResolutionException e ) - { - throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + - "' from the repository: " + e.getMessage(), e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new ProjectBuildingException( projectId, - "POM '" + projectId + "' not found in repository: " + e.getMessage(), - e ); - } - } - - public List buildArtifactRepositories( Model model ) - throws ProjectBuildingException - { - try - { - return mavenTools.buildArtifactRepositories( model.getRepositories() ); - } - catch ( InvalidRepositoryException e ) - { - String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); - - throw new ProjectBuildingException( projectId, e.getMessage(), e ); - } - } - - /* - * Order is: - * - * 1. model profile repositories - * 2. model repositories - * 3. superModel profile repositories - * 4. superModel repositories - * 5. parentSearchRepositories - */ - public LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories, - File pomFile, boolean validProfilesXmlLocation, - ProfileActivationContext profileActivationContext ) - throws ProjectBuildingException - { - LinkedHashSet collected = new LinkedHashSet(); - - collectInitialRepositoriesFromModel( collected, model, pomFile, validProfilesXmlLocation, - profileActivationContext ); - - collectInitialRepositoriesFromModel( collected, superModel, null, validProfilesXmlLocation, - profileActivationContext ); - - if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() ) - { - collected.addAll( parentSearchRepositories ); - } - - return collected; - } - - private List normalizeToArtifactRepositories( List remoteArtifactRepositories, String projectId ) - throws ProjectBuildingException - { - List normalized = new ArrayList( remoteArtifactRepositories.size() ); - - boolean normalizationNeeded = false; - for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) - { - Object item = it.next(); - - if ( item instanceof ArtifactRepository ) - { - normalized.add( item ); - } - else if ( item instanceof Repository ) - { - Repository repo = (Repository) item; - try - { - item = mavenTools.buildArtifactRepository( repo ); - - normalized.add( item ); - normalizationNeeded = true; - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( projectId, - "Error building artifact repository for id: " + repo.getId(), - e ); - } - } - else - { - throw new ProjectBuildingException( projectId, - "Error building artifact repository from non-repository information item: " + - item ); - } - } - - if ( normalizationNeeded ) - { - return normalized; - } - else - { - return remoteArtifactRepositories; - } - } - - private String safeVersionlessKey( String groupId, String artifactId ) - { - String gid = groupId; - - if ( StringUtils.isEmpty( gid ) ) - { - gid = "unknown"; - } - - String aid = artifactId; - - if ( StringUtils.isEmpty( aid ) ) - { - aid = "unknown"; - } - - return ArtifactUtils.versionlessKey( gid, aid ); - } - - private void collectInitialRepositoriesFromModel( LinkedHashSet collected, Model model, File pomFile, - boolean validProfilesXmlLocation, - ProfileActivationContext profileActivationContext ) - throws ProjectBuildingException - { - - Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, - validProfilesXmlLocation, - profileActivationContext ); - - if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() ) - { - collected.addAll( reposFromProfiles ); - } - - List modelRepos = model.getRepositories(); - - if ( ( modelRepos != null ) && !modelRepos.isEmpty() ) - { - try - { - collected.addAll( mavenTools.buildArtifactRepositories( modelRepos ) ); - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ), - "Failed to construct ArtifactRepository instances for repositories declared in: " + - model.getId(), e ); - } - } - } - - - public void initialize() - throws InitializationException - { - modelReader = new MavenXpp3Reader(); - } - - public void enableLogging( Logger logger ) - { - this.logger = logger; - } -} \ No newline at end of file diff --git a/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java b/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java deleted file mode 100644 index 1c8ff9ec5e..0000000000 --- a/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.maven.project; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.profiles.activation.ProfileActivationContext; - -import java.io.File; -import java.util.LinkedHashSet; -import java.util.List; - -/** - * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be - * eliminated when Mercury is integrated. - */ -public interface RepositoryHelper -{ - - String ROLE = RepositoryHelper.class.getName(); - - void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, - ArtifactRepository localRepository ) - throws ProjectBuildingException; - - List buildArtifactRepositories( Model model ) - throws ProjectBuildingException; - - LinkedHashSet collectInitialRepositories( Model model, Model superModel, List parentSearchRepositories, - File pomFile, boolean validProfilesXmlLocation, - ProfileActivationContext profileActivationContext ) - throws ProjectBuildingException; -} 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 3ffc41e6c6..744cb3b044 100644 --- a/maven-project/src/main/resources/META-INF/plexus/components.xml +++ b/maven-project/src/main/resources/META-INF/plexus/components.xml @@ -88,10 +88,7 @@ under the License. org.apache.maven.project.MavenProjectBuilder default org.apache.maven.project.DefaultMavenProjectBuilder - - - org.apache.maven.project.RepositoryHelper - + org.apache.maven.project.builder.ProjectBuilder @@ -119,27 +116,6 @@ under the License. - - - - org.apache.maven.project.RepositoryHelper - org.apache.maven.project.DefaultRepositoryHelper - - - org.apache.maven.profiles.build.ProfileAdvisor - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.resolver.ArtifactResolver - default - - - org.apache.maven.MavenTools - - - - - org.apache.maven.project.RepositoryHelper - org.apache.maven.project.DefaultRepositoryHelper - - - org.apache.maven.profiles.build.ProfileAdvisor - default - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.resolver.ArtifactResolver - default - - - org.apache.maven.MavenTools - - - - org.apache.maven.profiles.injection.ProfileInjector test @@ -114,9 +79,6 @@ under the License. test org.apache.maven.project.TestProjectBuilder - - org.apache.maven.project.RepositoryHelper - org.apache.maven.project.builder.ProjectBuilder diff --git a/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml b/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml index cad1bd921b..f0c3af1072 100644 --- a/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml +++ b/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml @@ -18,41 +18,7 @@ under the License. --> - - - org.apache.maven.project.RepositoryHelper - org.apache.maven.project.DefaultRepositoryHelper - - - org.apache.maven.profiles.build.ProfileAdvisor - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.resolver.ArtifactResolver - default - - - org.apache.maven.MavenTools - - - - - + org.apache.maven.profiles.injection.ProfileInjector test @@ -111,9 +77,6 @@ under the License. test org.apache.maven.project.TestProjectBuilder - - org.apache.maven.project.RepositoryHelper - org.apache.maven.project.builder.ProjectBuilder