From 22adefde141571f142f6026eed66ad5ea99c8f5c Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 14 Sep 2005 18:38:54 +0000 Subject: [PATCH] Fixing case where non-POM artifacts are passed to the project builder for parsing...doing defensive construction of POM artifacts inside the project builder, and fixed the call in the DependenciesReport. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280903 13f79535-47bb-0310-9956-ffa450edef68 --- .../projectinfo/DependenciesReport.java | 9 +++- .../project/DefaultMavenProjectBuilder.java | 46 +++++++++++++------ 2 files changed, 39 insertions(+), 16 deletions(-) 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 22f047c3bd..56187e31a7 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 @@ -335,8 +335,15 @@ public class DependenciesReport private MavenProject getMavenProjectFromRepository( Artifact artifact, ArtifactRepository localRepository ) throws ProjectBuildingException { + Artifact projectArtifact = artifact; + + if ( !"pom".equals( artifact.getType() ) ) + { + projectArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); + } + // TODO: we should use the MavenMetadataSource instead - return mavenProjectBuilder.buildFromRepository( artifact, project.getRepositories(), localRepository ); + return mavenProjectBuilder.buildFromRepository( projectArtifact, project.getRepositories(), localRepository ); } } 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 1b058b9bcb..ab5efbe60e 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 @@ -321,17 +321,33 @@ public class DefaultMavenProjectBuilder ArtifactRepository localRepository ) throws ProjectBuildingException { - MavenProject project = getCachedProject( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ); + Artifact projectArtifact; + + if ( "pom".equals( artifact.getType() ) ) + { + projectArtifact = artifact; + } + else + { + getLogger().warn( + "Attempting to build MavenProject instance for Artifact of type: " + artifact.getType() + + "; constructing POM artifact instead." ); + + projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), artifact.getScope() ); + } + + MavenProject project = getCachedProject( projectArtifact.getGroupId(), projectArtifact.getArtifactId(), + projectArtifact.getVersion() ); Model model; if ( project == null ) { // TODO: can't assume artifact is a POM try { - artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository ); + artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); - File file = artifact.getFile(); + File file = projectArtifact.getFile(); model = readModel( file ); String downloadUrl = null; @@ -346,7 +362,7 @@ public class DefaultMavenProjectBuilder } // TODO: configurable actions dependant on status - if ( !artifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) + if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) { // use default policy (enabled, daily update, warn on bad checksum) ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(); @@ -356,11 +372,11 @@ public class DefaultMavenProjectBuilder if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) ) { getLogger().info( - artifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); + projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); try { - artifact.setResolved( false ); - artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository ); + projectArtifact.setResolved( false ); + artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository ); } catch ( ArtifactResolutionException e ) { @@ -374,11 +390,11 @@ public class DefaultMavenProjectBuilder // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions? if ( downloadUrl != null ) { - artifact.setDownloadUrl( downloadUrl ); + projectArtifact.setDownloadUrl( downloadUrl ); } else { - artifact.setDownloadUrl( model.getUrl() ); + projectArtifact.setDownloadUrl( model.getUrl() ); } } @@ -388,15 +404,15 @@ public class DefaultMavenProjectBuilder // only not found should have the below behaviour // throw new ProjectBuildingException( "Unable to find the POM in the repository", e ); - getLogger().warn( "\n ***** Using defaults for missing POM " + artifact.getId() + " *****\n" ); + getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" ); model = new Model(); model.setModelVersion( "4.0.0" ); - model.setArtifactId( artifact.getArtifactId() ); - model.setGroupId( artifact.getGroupId() ); - model.setVersion( artifact.getVersion() ); + model.setArtifactId( projectArtifact.getArtifactId() ); + model.setGroupId( projectArtifact.getGroupId() ); + model.setVersion( projectArtifact.getVersion() ); // TODO: not correct in some instances - model.setPackaging( artifact.getType() ); + model.setPackaging( projectArtifact.getType() ); model.setDistributionManagement( new DistributionManagement() ); model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );