mirror of https://github.com/apache/maven.git
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:
parent
a565ef8590
commit
79cad82736
|
@ -312,11 +312,5 @@ it2001: Test that repositories are accumulated as the artifact resolution
|
|||
|
||||
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).
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -324,6 +324,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
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;
|
||||
|
@ -342,62 +343,67 @@ public class DefaultMavenProjectBuilder
|
|||
Model model;
|
||||
if ( project == null )
|
||||
{
|
||||
// TODO: can't assume artifact is a POM
|
||||
try
|
||||
{
|
||||
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
|
||||
|
||||
File file = projectArtifact.getFile();
|
||||
model = readModel( file );
|
||||
|
||||
String downloadUrl = null;
|
||||
ArtifactStatus status = ArtifactStatus.NONE;
|
||||
|
||||
DistributionManagement distributionManagement = model.getDistributionManagement();
|
||||
if ( distributionManagement != null )
|
||||
if ( projectArtifact.isResolved() )
|
||||
{
|
||||
downloadUrl = distributionManagement.getDownloadUrl();
|
||||
model = readModel( file );
|
||||
|
||||
status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
|
||||
}
|
||||
String downloadUrl = null;
|
||||
ArtifactStatus status = ArtifactStatus.NONE;
|
||||
|
||||
// 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() ) ) )
|
||||
DistributionManagement distributionManagement = model.getDistributionManagement();
|
||||
if ( distributionManagement != null )
|
||||
{
|
||||
getLogger().info(
|
||||
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
|
||||
try
|
||||
downloadUrl = distributionManagement.getDownloadUrl();
|
||||
|
||||
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 );
|
||||
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
|
||||
localRepository );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
getLogger().warn( "Error updating POM - using existing version" );
|
||||
getLogger().debug( "Cause", e );
|
||||
getLogger().info(
|
||||
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
|
||||
try
|
||||
{
|
||||
projectArtifact.setResolved( false );
|
||||
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
|
||||
localRepository );
|
||||
}
|
||||
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
|
||||
// Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
|
||||
if ( downloadUrl != null )
|
||||
{
|
||||
projectArtifact.setDownloadUrl( downloadUrl );
|
||||
// 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() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
projectArtifact.setDownloadUrl( model.getUrl() );
|
||||
model = createStubModel( projectArtifact );
|
||||
}
|
||||
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
|
@ -405,40 +411,7 @@ 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 " + projectArtifact.getId() + " *****\n" );
|
||||
|
||||
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 );
|
||||
}
|
||||
*/
|
||||
model = createStubModel( projectArtifact );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -449,6 +422,45 @@ public class DefaultMavenProjectBuilder
|
|||
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,
|
||||
List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager )
|
||||
throws ProjectBuildingException
|
||||
|
|
|
@ -4,10 +4,13 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.artifact.DefaultArtifact;
|
||||
import org.apache.maven.artifact.InvalidArtifactRTException;
|
||||
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.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AttachedArtifact
|
||||
|
@ -112,4 +115,14 @@ public class AttachedArtifact
|
|||
return parent.isSnapshot();
|
||||
}
|
||||
|
||||
public void addMetadata( ArtifactMetadata metadata )
|
||||
{
|
||||
// ignore. The parent artifact will handle metadata.
|
||||
}
|
||||
|
||||
public Collection getMetadataList()
|
||||
{
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue