mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
eb89e520e4
commit
22adefde14
|
@ -335,8 +335,15 @@ public class DependenciesReport
|
||||||
private MavenProject getMavenProjectFromRepository( Artifact artifact, ArtifactRepository localRepository )
|
private MavenProject getMavenProjectFromRepository( Artifact artifact, ArtifactRepository localRepository )
|
||||||
throws ProjectBuildingException
|
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
|
// TODO: we should use the MavenMetadataSource instead
|
||||||
return mavenProjectBuilder.buildFromRepository( artifact, project.getRepositories(), localRepository );
|
return mavenProjectBuilder.buildFromRepository( projectArtifact, project.getRepositories(), localRepository );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -321,17 +321,33 @@ public class DefaultMavenProjectBuilder
|
||||||
ArtifactRepository localRepository )
|
ArtifactRepository localRepository )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
MavenProject project = getCachedProject( artifact.getGroupId(), artifact.getArtifactId(),
|
Artifact projectArtifact;
|
||||||
artifact.getVersion() );
|
|
||||||
|
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;
|
Model model;
|
||||||
if ( project == null )
|
if ( project == null )
|
||||||
{
|
{
|
||||||
// TODO: can't assume artifact is a POM
|
// TODO: can't assume artifact is a POM
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
|
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
|
||||||
|
|
||||||
File file = artifact.getFile();
|
File file = projectArtifact.getFile();
|
||||||
model = readModel( file );
|
model = readModel( file );
|
||||||
|
|
||||||
String downloadUrl = null;
|
String downloadUrl = null;
|
||||||
|
@ -346,7 +362,7 @@ public class DefaultMavenProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: configurable actions dependant on status
|
// 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)
|
// use default policy (enabled, daily update, warn on bad checksum)
|
||||||
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
|
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
|
||||||
|
@ -356,11 +372,11 @@ public class DefaultMavenProjectBuilder
|
||||||
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
|
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
|
||||||
{
|
{
|
||||||
getLogger().info(
|
getLogger().info(
|
||||||
artifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
|
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
artifact.setResolved( false );
|
projectArtifact.setResolved( false );
|
||||||
artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository );
|
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository );
|
||||||
}
|
}
|
||||||
catch ( ArtifactResolutionException e )
|
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?
|
// Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
|
||||||
if ( downloadUrl != null )
|
if ( downloadUrl != null )
|
||||||
{
|
{
|
||||||
artifact.setDownloadUrl( downloadUrl );
|
projectArtifact.setDownloadUrl( downloadUrl );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
artifact.setDownloadUrl( model.getUrl() );
|
projectArtifact.setDownloadUrl( model.getUrl() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -388,15 +404,15 @@ public class DefaultMavenProjectBuilder
|
||||||
// only not found should have the below behaviour
|
// only not found should have the below behaviour
|
||||||
// throw new ProjectBuildingException( "Unable to find the POM in the repository", e );
|
// 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 = new Model();
|
||||||
model.setModelVersion( "4.0.0" );
|
model.setModelVersion( "4.0.0" );
|
||||||
model.setArtifactId( artifact.getArtifactId() );
|
model.setArtifactId( projectArtifact.getArtifactId() );
|
||||||
model.setGroupId( artifact.getGroupId() );
|
model.setGroupId( projectArtifact.getGroupId() );
|
||||||
model.setVersion( artifact.getVersion() );
|
model.setVersion( projectArtifact.getVersion() );
|
||||||
// TODO: not correct in some instances
|
// TODO: not correct in some instances
|
||||||
model.setPackaging( artifact.getType() );
|
model.setPackaging( projectArtifact.getType() );
|
||||||
|
|
||||||
model.setDistributionManagement( new DistributionManagement() );
|
model.setDistributionManagement( new DistributionManagement() );
|
||||||
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
|
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
|
||||||
|
|
Loading…
Reference in New Issue