Resolving: MNG-1021, MNG-1049

o Added check for projectArtifact.isResolved() before attempting to read the model from it within DefaultMavenProjectBuilder, otherwise, stub out a dummy model just like if an ArtifactResolutionException occurs.

o Disabled metadata handling for AttachedArtifact...attachments should be slaves to the main artifact, deriving version info and metadata from it.

o Cleaned up entry for it2003 in maven-core-it/README.txt...that test has been removed.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@295069 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-10-05 18:31:37 +00:00
parent a565ef8590
commit 79cad82736
3 changed files with 98 additions and 79 deletions

View File

@ -312,11 +312,5 @@ it2001: Test that repositories are accumulated as the artifact resolution
it2002: Test the release plugin. it2002: Test the release plugin.
it2003: Test that source artifacts share the same build number as the main
project artifact. This is only defined in the 2000 series because of
the exorbitant time it takes to execute (it uses a uniquely defined
local repository, to avoid pollution from existing artifacts in
pattern matching of the results).
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -324,6 +324,7 @@ public class DefaultMavenProjectBuilder
{ {
Artifact projectArtifact; 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() ) ) if ( "pom".equals( artifact.getType() ) )
{ {
projectArtifact = artifact; projectArtifact = artifact;
@ -342,62 +343,67 @@ public class DefaultMavenProjectBuilder
Model model; Model model;
if ( project == null ) if ( project == null )
{ {
// TODO: can't assume artifact is a POM
try try
{ {
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
File file = projectArtifact.getFile(); File file = projectArtifact.getFile();
model = readModel( file ); if ( projectArtifact.isResolved() )
String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE;
DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement != null )
{ {
downloadUrl = distributionManagement.getDownloadUrl(); model = readModel( file );
status = ArtifactStatus.valueOf( distributionManagement.getStatus() ); String downloadUrl = null;
} ArtifactStatus status = ArtifactStatus.NONE;
// TODO: configurable actions dependant on status DistributionManagement distributionManagement = model.getDistributionManagement();
if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) if ( distributionManagement != null )
{
// use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
// TODO: re-enable [MNG-798/865]
policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
{ {
getLogger().info( downloadUrl = distributionManagement.getDownloadUrl();
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
try status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
}
// TODO: configurable actions dependant on status
if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
{
// use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
// TODO: re-enable [MNG-798/865]
policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
{ {
projectArtifact.setResolved( false ); getLogger().info(
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
localRepository ); try
} {
catch ( ArtifactResolutionException e ) projectArtifact.setResolved( false );
{ artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
getLogger().warn( "Error updating POM - using existing version" ); localRepository );
getLogger().debug( "Cause", e ); }
catch ( ArtifactResolutionException e )
{
getLogger().warn( "Error updating POM - using existing version" );
getLogger().debug( "Cause", e );
}
} }
} }
}
// TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that // 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? // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
if ( downloadUrl != null ) if ( downloadUrl != null )
{ {
projectArtifact.setDownloadUrl( downloadUrl ); projectArtifact.setDownloadUrl( downloadUrl );
}
else
{
projectArtifact.setDownloadUrl( model.getUrl() );
}
} }
else else
{ {
projectArtifact.setDownloadUrl( model.getUrl() ); model = createStubModel( projectArtifact );
} }
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
@ -405,40 +411,7 @@ 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 " + projectArtifact.getId() + " *****\n" ); model = createStubModel( projectArtifact );
model = new Model();
model.setModelVersion( "4.0.0" );
model.setArtifactId( projectArtifact.getArtifactId() );
model.setGroupId( projectArtifact.getGroupId() );
model.setVersion( projectArtifact.getVersion() );
// TODO: not correct in some instances
model.setPackaging( projectArtifact.getType() );
model.setDistributionManagement( new DistributionManagement() );
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
/* TODO: we should only do this if we can verify the existence of the JAR itself
File file = artifact.getFile();
file.getParentFile().mkdirs();
FileWriter writer = null;
try
{
writer = new FileWriter( file );
MavenXpp3Writer w = new MavenXpp3Writer();
w.write( writer, model );
}
catch ( IOException ioe )
{
getLogger().warn( "Attempted to write out a temporary generated POM, but failed", ioe );
}
finally
{
IOUtil.close( writer );
}
*/
} }
} }
else else
@ -449,6 +422,45 @@ public class DefaultMavenProjectBuilder
return model; return model;
} }
private Model createStubModel(Artifact projectArtifact)
{
getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" );
Model model = new Model();
model.setModelVersion( "4.0.0" );
model.setArtifactId( projectArtifact.getArtifactId() );
model.setGroupId( projectArtifact.getGroupId() );
model.setVersion( projectArtifact.getVersion() );
// TODO: not correct in some instances
model.setPackaging( projectArtifact.getType() );
model.setDistributionManagement( new DistributionManagement() );
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
/* TODO: we should only do this if we can verify the existence of the JAR itself
File file = artifact.getFile();
file.getParentFile().mkdirs();
FileWriter writer = null;
try
{
writer = new FileWriter( file );
MavenXpp3Writer w = new MavenXpp3Writer();
w.write( writer, model );
}
catch ( IOException ioe )
{
getLogger().warn( "Attempted to write out a temporary generated POM, but failed", ioe );
}
finally
{
IOUtil.close( writer );
}
*/
return model;
}
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository, private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository,
List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager ) List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager )
throws ProjectBuildingException throws ProjectBuildingException

View File

@ -4,10 +4,13 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.InvalidArtifactRTException; import org.apache.maven.artifact.InvalidArtifactRTException;
import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
public class AttachedArtifact public class AttachedArtifact
@ -112,4 +115,14 @@ public class AttachedArtifact
return parent.isSnapshot(); return parent.isSnapshot();
} }
public void addMetadata( ArtifactMetadata metadata )
{
// ignore. The parent artifact will handle metadata.
}
public Collection getMetadataList()
{
return Collections.EMPTY_LIST;
}
} }