From 70ab341c649274950da47532b245ff1b24aeacda Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 7 Oct 2005 08:03:25 +0000 Subject: [PATCH] PR: MNG-1108 don't resolve a default POM for a parent or dependency of type POM git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307047 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/DefaultPluginManager.java | 2 +- .../version/DefaultPluginVersionManager.java | 13 +++++---- .../maven-project-info-reports-plugin/pom.xml | 5 +++- .../projectinfo/DependenciesReport.java | 6 ++-- .../project/DefaultMavenProjectBuilder.java | 29 +++++++++++++++---- .../maven/project/MavenProjectBuilder.java | 14 +++++++++ .../project/artifact/MavenMetadataSource.java | 4 +-- 7 files changed, 56 insertions(+), 17 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 3d65ae84f6..5fb245db98 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -231,7 +231,7 @@ public class DefaultPluginManager Artifact artifact = artifactFactory.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, - localRepository ); + localRepository, false ); // if we don't have the required Maven version, then ignore an update if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index 7fb62ff598..3e3fc4f252 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -92,12 +92,12 @@ public class DefaultPluginVersionManager { // before we do anything else, if this is a self-reference we need to short-circuit the resolution process. String projectKey = constructPluginKey( project.getGroupId(), project.getArtifactId() ); - + if ( projectKey.equals( constructPluginKey( groupId, artifactId ) ) ) { return project.getVersion(); } - + // first pass...if the plugin is specified in the pom, try to retrieve the version from there. String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin ); @@ -595,8 +595,9 @@ public class DefaultPluginVersionManager } catch ( IOException e ) { - getLogger().warn( "Cannot rewrite user-level plugin-registry.xml with new plugin version of plugin: \'" - + groupId + ":" + artifactId + "\'.", e ); + getLogger().warn( + "Cannot rewrite user-level plugin-registry.xml with new plugin version of plugin: \'" + groupId + + ":" + artifactId + "\'.", e ); } finally { @@ -653,7 +654,7 @@ public class DefaultPluginVersionManager if ( artifact.getFile() != null ) { MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, - localRepository ); + localRepository, false ); boolean pluginValid = true; @@ -672,7 +673,7 @@ public class DefaultPluginVersionManager } String artifactVersion = artifact.getVersion(); - + if ( pluginValid && !metaVersionId.equals( artifactVersion ) ) { version = artifactVersion; diff --git a/maven-plugins/maven-project-info-reports-plugin/pom.xml b/maven-plugins/maven-project-info-reports-plugin/pom.xml index 923dbd4937..05f131f2da 100644 --- a/maven-plugins/maven-project-info-reports-plugin/pom.xml +++ b/maven-plugins/maven-project-info-reports-plugin/pom.xml @@ -2,7 +2,7 @@ maven-plugin-parent org.apache.maven.plugins - 2.0-beta-1 + 2.0-beta-4-SNAPSHOT 4.0.0 maven-project-info-reports-plugin @@ -10,6 +10,9 @@ Maven Project Info Reports Plugin 2.0-beta-2-SNAPSHOT 2005 + + 2.0-beta-4-SNAPSHOT + vsiveton diff --git a/maven-plugins/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java b/maven-plugins/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java index 40e156a27b..f1010be2c6 100644 --- a/maven-plugins/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java +++ b/maven-plugins/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java @@ -351,16 +351,18 @@ public class DependenciesReport { Artifact projectArtifact = artifact; + boolean allowStubModel = false; if ( !"pom".equals( artifact.getType() ) ) { projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); + allowStubModel = true; } // TODO: we should use the MavenMetadataSource instead - return mavenProjectBuilder.buildFromRepository( projectArtifact, project.getRepositories(), - localRepository ); + return mavenProjectBuilder.buildFromRepository( projectArtifact, project.getRepositories(), localRepository, + allowStubModel ); } } 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 6174de1b98..70b4bf2809 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 @@ -305,6 +305,13 @@ public class DefaultMavenProjectBuilder public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) throws ProjectBuildingException + { + return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true ); + } + + public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, + ArtifactRepository localRepository, boolean allowStubModel ) + throws ProjectBuildingException { String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); MavenProject project = (MavenProject) projectCache.get( cacheKey ); @@ -313,14 +320,14 @@ public class DefaultMavenProjectBuilder return project; } - Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); + Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel ); return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, null, null ); } private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, - ArtifactRepository localRepository ) + ArtifactRepository localRepository, boolean allowStubModel ) throws ProjectBuildingException { Artifact projectArtifact; @@ -349,6 +356,7 @@ public class DefaultMavenProjectBuilder artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); File file = projectArtifact.getFile(); + // TODO: how can this not be true? if ( projectArtifact.isResolved() ) { model = readModel( file ); @@ -408,10 +416,14 @@ public class DefaultMavenProjectBuilder projectArtifact.setDownloadUrl( model.getUrl() ); } } - else + else if ( allowStubModel ) { model = createStubModel( projectArtifact ); } + else + { + throw new ProjectBuildingException( "POM could not be resolved from the repository" ); + } } catch ( ArtifactResolutionException e ) { @@ -419,7 +431,14 @@ public class DefaultMavenProjectBuilder } catch ( ArtifactNotFoundException e ) { - model = createStubModel( projectArtifact ); + if ( allowStubModel ) + { + model = createStubModel( projectArtifact ); + } + else + { + throw new ProjectBuildingException( "POM not found in repository", e ); + } } } else @@ -854,7 +873,7 @@ public class DefaultMavenProjectBuilder // we can't query the parent to ask where it is :) List remoteRepositories = new ArrayList( aggregatedRemoteWagonRepositories ); remoteRepositories.addAll( parentSearchRepositories ); - model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository ); + model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository, false ); } File parentProjectDir = null; diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index b33f07c200..1f184c1157 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -68,6 +68,20 @@ public interface MavenProjectBuilder ArtifactRepository localRepository ) throws ProjectBuildingException; + /** + * Build the artifact from the local repository, resolving it if necessary. + * + * @param artifact the artifact description + * @param localRepository the local repository + * @param remoteArtifactRepositories the remote repository list + * @param allowStubModel return a stub if the POM is not found + * @return the built project + * @throws ProjectBuildingException + */ + MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, + ArtifactRepository localRepository, boolean allowStubModel ) + throws ProjectBuildingException; + MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository ) throws ProjectBuildingException; } diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 33e4649a66..043f8c4402 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -106,8 +106,8 @@ public class MavenMetadataSource { try { - project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, - localRepository ); + project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository, + true ); } catch ( InvalidModelException e ) {