in maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java [536:620]
private Model findModelFromRepository( Artifact artifact,
List remoteArtifactRepositories,
ProjectBuilderConfiguration config,
boolean allowStubModel )
throws ProjectBuildingException
{
String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
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().debug( "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() );
}
Model model;
try
{
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, config.getLocalRepository() );
File file = projectArtifact.getFile();
model = readModel( projectId, file, false );
String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE;
DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement != null )
{
downloadUrl = distributionManagement.getDownloadUrl();
status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
}
checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, config.getLocalRepository() );
// TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
// Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
if ( downloadUrl != null )
{
projectArtifact.setDownloadUrl( downloadUrl );
}
else
{
projectArtifact.setDownloadUrl( model.getUrl() );
}
}
catch ( ArtifactResolutionException e )
{
throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId
+ "' from the repository: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
if ( allowStubModel )
{
getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
model = createStubModel( projectArtifact );
}
else
{
throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: "
+ e.getMessage(), e );
}
}
return model;
}