mirror of https://github.com/apache/maven.git
snapshot resolution working, with glitches. committing working copy that is only enabled by a sys property until other features are in place.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163705 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4a065a33db
commit
16ea34c8c1
|
@ -24,6 +24,8 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Description of an artifact.
|
||||
*
|
||||
* @todo do we really need an interface here?
|
||||
*/
|
||||
public interface Artifact
|
||||
{
|
||||
|
@ -60,6 +62,10 @@ public interface Artifact
|
|||
|
||||
void setFile( File destination );
|
||||
|
||||
String getBaseVersion();
|
||||
|
||||
void setBaseVersion( String baseVersion );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String getId();
|
||||
|
|
|
@ -39,6 +39,8 @@ public class DefaultArtifact
|
|||
|
||||
private final String version;
|
||||
|
||||
private String baseVersion;
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String classifier;
|
||||
|
@ -129,10 +131,6 @@ public class DefaultArtifact
|
|||
|
||||
public File getFile()
|
||||
{
|
||||
if ( file == null )
|
||||
{
|
||||
throw new IllegalStateException( "Artifact's local file has not yet been assigned - not resolved" );
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -152,7 +150,7 @@ public class DefaultArtifact
|
|||
|
||||
public String getId()
|
||||
{
|
||||
return getConflictId() + ( hasClassifier() ? ( ":" + getClassifier() ) : "" ) + ":" + getVersion();
|
||||
return getConflictId() + ( hasClassifier() ? ( ":" + getClassifier() ) : "" ) + ":" + getBaseVersion();
|
||||
}
|
||||
|
||||
public String getConflictId()
|
||||
|
@ -230,4 +228,19 @@ public class DefaultArtifact
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getBaseVersion()
|
||||
{
|
||||
if ( baseVersion == null )
|
||||
{
|
||||
baseVersion = version;
|
||||
}
|
||||
return baseVersion;
|
||||
}
|
||||
|
||||
public void setBaseVersion( String baseVersion )
|
||||
{
|
||||
this.baseVersion = baseVersion;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,7 @@ public interface ArtifactInstaller
|
|||
String ROLE = ArtifactInstaller.class.getName();
|
||||
|
||||
/**
|
||||
* Install an artifact from a particular directory. The artifact handler is used to determine the filenameSuffix
|
||||
* Install an artifact from a particular directory. The artifact handler is used to determine the filename
|
||||
* of the source file.
|
||||
*
|
||||
* @param basedir the directory where the artifact is stored
|
||||
|
|
|
@ -27,14 +27,14 @@ import org.apache.maven.artifact.Artifact;
|
|||
public abstract class AbstractArtifactMetadata
|
||||
implements ArtifactMetadata
|
||||
{
|
||||
protected final String filenameSuffix;
|
||||
protected final String filename;
|
||||
|
||||
protected Artifact artifact;
|
||||
|
||||
protected AbstractArtifactMetadata( Artifact artifact, String filename )
|
||||
{
|
||||
this.artifact = artifact;
|
||||
this.filenameSuffix = filename;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public void setArtifact( Artifact artifact )
|
||||
|
@ -47,8 +47,8 @@ public abstract class AbstractArtifactMetadata
|
|||
return artifact;
|
||||
}
|
||||
|
||||
public String getFilenameSuffix()
|
||||
public String getFilename()
|
||||
{
|
||||
return filenameSuffix;
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.apache.maven.artifact.metadata;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
|
@ -39,15 +38,6 @@ public interface ArtifactMetadata
|
|||
void storeInLocalRepository( ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
||||
/**
|
||||
* Retrieve the metadata from the remote repository into the local repository.
|
||||
*
|
||||
* @param remoteRepository the remote repository
|
||||
* @param wagonManager the wagon manager to use to retrieve the metadata
|
||||
*/
|
||||
public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
|
||||
/**
|
||||
* Get the associated artifact.
|
||||
*
|
||||
|
@ -56,11 +46,11 @@ public interface ArtifactMetadata
|
|||
Artifact getArtifact();
|
||||
|
||||
/**
|
||||
* Get the filenameSuffix of this metadata.
|
||||
* Get the filename of this metadata.
|
||||
*
|
||||
* @return the filenameSuffix
|
||||
* @return the filename
|
||||
*/
|
||||
String getFilenameSuffix();
|
||||
String getFilename();
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,24 +46,22 @@ public class SnapshotArtifactMetadata
|
|||
|
||||
private int buildNumber = 0;
|
||||
|
||||
private static final String SNAPSHOT_VERSION_LOCAL_FILE = "version-local.txt";
|
||||
|
||||
private static final String SNAPSHOT_VERSION_FILE = "version.txt";
|
||||
|
||||
private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
|
||||
|
||||
private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss";
|
||||
|
||||
private SnapshotArtifactMetadata( Artifact artifact, String filename )
|
||||
public SnapshotArtifactMetadata( Artifact artifact )
|
||||
{
|
||||
super( artifact, filename );
|
||||
super( artifact, artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + SNAPSHOT_VERSION_FILE );
|
||||
}
|
||||
|
||||
public static SnapshotArtifactMetadata readLocalSnapshotMetadata( Artifact artifact,
|
||||
ArtifactRepository localRepository )
|
||||
public static SnapshotArtifactMetadata readFromLocalRepository( Artifact artifact,
|
||||
ArtifactRepository localRepository )
|
||||
throws ArtifactPathFormatException, IOException
|
||||
{
|
||||
SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
|
||||
SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact );
|
||||
File f = metadata.getLocalRepositoryLocation( localRepository );
|
||||
if ( f.exists() )
|
||||
{
|
||||
|
@ -72,16 +70,6 @@ public class SnapshotArtifactMetadata
|
|||
return metadata;
|
||||
}
|
||||
|
||||
public static SnapshotArtifactMetadata createLocalSnapshotMetadata( Artifact artifact )
|
||||
{
|
||||
return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
|
||||
}
|
||||
|
||||
public static SnapshotArtifactMetadata createRemoteSnapshotMetadata( Artifact artifact )
|
||||
{
|
||||
return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_FILE );
|
||||
}
|
||||
|
||||
public void storeInLocalRepository( ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
|
@ -92,7 +80,7 @@ public class SnapshotArtifactMetadata
|
|||
timestamp = getUtcDateFormatter().format( new Date() );
|
||||
}
|
||||
String path = getLocalRepositoryLocation( localRepository ).getPath();
|
||||
FileUtils.fileWrite( path, getVersion() );
|
||||
FileUtils.fileWrite( path, constructVersion() );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
@ -110,26 +98,37 @@ public class SnapshotArtifactMetadata
|
|||
return new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) );
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
public String constructVersion()
|
||||
{
|
||||
String version = artifact.getVersion();
|
||||
String version = artifact.getBaseVersion();
|
||||
if ( timestamp != null )
|
||||
{
|
||||
String newVersion = timestamp + "-" + buildNumber;
|
||||
if ( version != null )
|
||||
{
|
||||
version = StringUtils.replace( version, "SNAPSHOT", timestamp ) + "-" + buildNumber;
|
||||
version = StringUtils.replace( version, "SNAPSHOT", newVersion );
|
||||
}
|
||||
else
|
||||
{
|
||||
version = timestamp + "-" + buildNumber;
|
||||
version = newVersion;
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager )
|
||||
/**
|
||||
* Retrieve the metadata from the remote repository into the local repository.
|
||||
*
|
||||
* @param remoteRepository the remote repository
|
||||
* @param wagonManager the wagon manager to use to retrieve the metadata
|
||||
*/
|
||||
public static SnapshotArtifactMetadata retrieveFromRemoteRepository( Artifact artifact,
|
||||
ArtifactRepository remoteRepository,
|
||||
WagonManager wagonManager )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
SnapshotArtifactMetadata snapshotMetadata = new SnapshotArtifactMetadata( artifact );
|
||||
|
||||
try
|
||||
{
|
||||
File destination = File.createTempFile( "maven-artifact", null );
|
||||
|
@ -137,15 +136,14 @@ public class SnapshotArtifactMetadata
|
|||
|
||||
try
|
||||
{
|
||||
wagonManager.getArtifactMetadata( this, remoteRepository, destination );
|
||||
wagonManager.getArtifactMetadata( snapshotMetadata, remoteRepository, destination );
|
||||
|
||||
snapshotMetadata.readFromFile( destination );
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
// this just means that there is no snapshot version file, so we keep timestamp = null, build = 0
|
||||
return;
|
||||
}
|
||||
|
||||
readFromFile( destination );
|
||||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
|
@ -155,6 +153,8 @@ public class SnapshotArtifactMetadata
|
|||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );
|
||||
}
|
||||
|
||||
return snapshotMetadata;
|
||||
}
|
||||
|
||||
private void readFromFile( File destination )
|
||||
|
|
|
@ -59,7 +59,7 @@ public abstract class AbstractArtifactRepositoryLayout
|
|||
{
|
||||
String path = basicPathOf( metadata.getArtifact(), metadataLayoutPattern() );
|
||||
|
||||
path = StringUtils.replace( path, "${metadataSuffix}", metadata.getFilenameSuffix() );
|
||||
path = StringUtils.replace( path, "${metadataFilename}", metadata.getFilename() );
|
||||
|
||||
return path;
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ public abstract class AbstractArtifactRepositoryLayout
|
|||
|
||||
path = StringUtils.replace( path, "${version}", artifact.getVersion() );
|
||||
|
||||
path = StringUtils.replace( path, "${baseVersion}", artifact.getBaseVersion() );
|
||||
|
||||
ArtifactHandler artifactHandler = null;
|
||||
try
|
||||
{
|
||||
|
|
|
@ -25,12 +25,12 @@ public class DefaultRepositoryLayout
|
|||
|
||||
protected String layoutPattern()
|
||||
{
|
||||
return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
|
||||
return "${groupPath}/${artifactId}/${baseVersion}/${artifactId}-${version}-${classifier}.${extension}";
|
||||
}
|
||||
|
||||
protected String metadataLayoutPattern()
|
||||
{
|
||||
return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}.${metadataSuffix}";
|
||||
return "${groupPath}/${artifactId}/${baseVersion}/${metadataFilename}";
|
||||
}
|
||||
|
||||
protected String groupIdAsPath( String groupId )
|
||||
|
|
|
@ -30,7 +30,7 @@ public class LegacyRepositoryLayout
|
|||
|
||||
protected String metadataLayoutPattern()
|
||||
{
|
||||
return "${groupPath}/poms/${artifactId}-${version}.${metadataSuffix}";
|
||||
return "${groupPath}/poms/${metadataFilename}";
|
||||
}
|
||||
|
||||
protected String groupIdAsPath( String groupId )
|
||||
|
|
|
@ -23,7 +23,9 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
|||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -49,7 +51,9 @@ public class SnapshotTransformation
|
|||
ArtifactRepository localRepository )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
if ( isSnapshot( artifact ) )
|
||||
// TODO: remove hack
|
||||
if ( isSnapshot( artifact ) &&
|
||||
!Boolean.valueOf( System.getProperty( "maven.debug.snapshot.disabled", "true" ) ).booleanValue() )
|
||||
{
|
||||
// TODO: this mostly works, however...
|
||||
// - poms and jars are different, so both are checked individually
|
||||
|
@ -57,14 +61,12 @@ public class SnapshotTransformation
|
|||
// - need to gather first, group them all up by groupId/artifactId, then go after them
|
||||
// - alternatively, keep the timestamp when downloading (as is done here), and use the SNAPSHOT file for install
|
||||
// - however, there is no mechanism to flip back and forward, and presently it keeps looking for 2.0-TIMESTAMP-0 instead as that is in the build file
|
||||
|
||||
// - we definitely need the manual/daily check as this is quite slow given the large number of snapshots inside m2 presently
|
||||
|
||||
/*
|
||||
SnapshotArtifactMetadata localMetadata;
|
||||
try
|
||||
{
|
||||
localMetadata = SnapshotArtifactMetadata.readLocalSnapshotMetadata( artifact, localRepository );
|
||||
localMetadata = SnapshotArtifactMetadata.readFromLocalRepository( artifact, localRepository );
|
||||
}
|
||||
catch ( ArtifactPathFormatException e )
|
||||
{
|
||||
|
@ -82,9 +84,8 @@ public class SnapshotTransformation
|
|||
{
|
||||
ArtifactRepository remoteRepository = (ArtifactRepository) i.next();
|
||||
|
||||
SnapshotArtifactMetadata remoteMetadata = SnapshotArtifactMetadata.createRemoteSnapshotMetadata(
|
||||
artifact );
|
||||
remoteMetadata.retrieveFromRemoteRepository( remoteRepository, wagonManager );
|
||||
SnapshotArtifactMetadata remoteMetadata = SnapshotArtifactMetadata.retrieveFromRemoteRepository(
|
||||
artifact, remoteRepository, wagonManager );
|
||||
|
||||
if ( remoteMetadata.compareTo( localMetadata ) > 0 )
|
||||
{
|
||||
|
@ -105,7 +106,6 @@ public class SnapshotTransformation
|
|||
artifact = createArtifactCopy( artifact, localMetadata );
|
||||
|
||||
resolvedArtifactCache.add( getCacheKey( artifact ) );
|
||||
*/
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
@ -117,17 +117,21 @@ public class SnapshotTransformation
|
|||
|
||||
private static String getCacheKey( Artifact artifact )
|
||||
{
|
||||
return artifact.getConflictId();
|
||||
// No type - one per POM
|
||||
return artifact.getGroupId() + ":" + artifact.getArtifactId();
|
||||
}
|
||||
|
||||
public Artifact transformForInstall( Artifact artifact, ArtifactRepository localRepository )
|
||||
{
|
||||
// Nothing to do
|
||||
/* TODO: remove
|
||||
if ( isSnapshot( artifact ) )
|
||||
{
|
||||
// only store the version-local.txt file for POMs as every file has an associated POM
|
||||
ArtifactMetadata metadata = SnapshotArtifactMetadata.createLocalSnapshotMetadata( artifact );
|
||||
artifact.addMetadata( metadata );
|
||||
}
|
||||
*/
|
||||
return artifact;
|
||||
}
|
||||
|
||||
|
@ -136,8 +140,9 @@ public class SnapshotTransformation
|
|||
{
|
||||
if ( isSnapshot( artifact ) )
|
||||
{
|
||||
SnapshotArtifactMetadata metadata = SnapshotArtifactMetadata.createRemoteSnapshotMetadata( artifact );
|
||||
metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager );
|
||||
SnapshotArtifactMetadata metadata = SnapshotArtifactMetadata.retrieveFromRemoteRepository( artifact,
|
||||
remoteRepository,
|
||||
wagonManager );
|
||||
metadata.update();
|
||||
|
||||
// TODO: note, we could currently transform this in place, as it is only used through the deploy mojo,
|
||||
|
@ -150,22 +155,21 @@ public class SnapshotTransformation
|
|||
|
||||
private Artifact createArtifactCopy( Artifact artifact, SnapshotArtifactMetadata metadata )
|
||||
{
|
||||
ArtifactRepository oldRepository = artifact.getRepository();
|
||||
List list = artifact.getMetadataList();
|
||||
Artifact newArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||
metadata.constructVersion(), artifact.getScope(),
|
||||
artifact.getType(), artifact.getClassifier() );
|
||||
newArtifact.setBaseVersion( artifact.getBaseVersion() );
|
||||
|
||||
artifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), metadata.getVersion(),
|
||||
artifact.getScope(), artifact.getType(), artifact.getClassifier() );
|
||||
|
||||
for ( Iterator i = list.iterator(); i.hasNext(); )
|
||||
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactMetadata m = (ArtifactMetadata) i.next();
|
||||
m.setArtifact( artifact );
|
||||
artifact.addMetadata( m );
|
||||
m.setArtifact( newArtifact );
|
||||
newArtifact.addMetadata( m );
|
||||
}
|
||||
|
||||
artifact.setRepository( oldRepository );
|
||||
newArtifact.setRepository( artifact.getRepository() );
|
||||
|
||||
return artifact;
|
||||
return newArtifact;
|
||||
}
|
||||
|
||||
private static boolean isSnapshot( Artifact artifact )
|
||||
|
|
|
@ -42,7 +42,7 @@ public class MavenMetadata
|
|||
|
||||
public MavenMetadata( Artifact artifact, File file )
|
||||
{
|
||||
super( artifact, "pom" );
|
||||
super( artifact, artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom" );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
|
|
|
@ -710,8 +710,8 @@ public class MavenProject
|
|||
existing.getVersion(),
|
||||
a.getScope(), existing.getType() );
|
||||
|
||||
// TODO: should copy files if it is set
|
||||
// artifact.setFile( existing.getFile() );
|
||||
artifact.setFile( artifact.getFile() );
|
||||
artifact.setBaseVersion( artifact.getBaseVersion() );
|
||||
|
||||
artifacts.put( id, artifact );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue