brett 2005/03/29 07:44:28
Modified: maven-core/src/main/java/org/apache/maven/artifact/metadata
MavenMetadata.java
maven-core/src/main/java/org/apache/maven/project
MavenProject.java
maven-artifact/src/main/java/org/apache/maven/artifact/installer
ArtifactInstaller.java
maven-artifact/src/main/java/org/apache/maven/artifact/metadata
AbstractArtifactMetadata.java ArtifactMetadata.java
SnapshotArtifactMetadata.java
maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
AbstractArtifactRepositoryLayout.java
DefaultRepositoryLayout.java
LegacyRepositoryLayout.java
maven-artifact/src/main/java/org/apache/maven/artifact/transform
SnapshotTransformation.java
maven-artifact/src/main/java/org/apache/maven/artifact
Artifact.java DefaultArtifact.java
Log:
snapshot resolution working, with glitches. committing working copy that is
only enabled by a sys property until other features are in place.
Revision Changes Path
1.3 +2 -2
maven-components/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java
Index: MavenMetadata.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MavenMetadata.java 29 Mar 2005 07:12:50 -0000 1.2
+++ MavenMetadata.java 29 Mar 2005 15:44:27 -0000 1.3
@@ -42,7 +42,7 @@
public MavenMetadata( Artifact artifact, File file )
{
- super( artifact, "pom" );
+ super( artifact, artifact.getArtifactId() + "-" +
artifact.getVersion() + ".pom" );
this.file = file;
}
1.37 +2 -2
maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Index: MavenProject.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- MavenProject.java 24 Mar 2005 16:16:49 -0000 1.36
+++ MavenProject.java 29 Mar 2005 15:44:27 -0000 1.37
@@ -710,8 +710,8 @@
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 );
}
1.6 +2 -2
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/ArtifactInstaller.java
Index: ArtifactInstaller.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/installer/ArtifactInstaller.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ArtifactInstaller.java 24 Mar 2005 10:30:58 -0000 1.5
+++ ArtifactInstaller.java 29 Mar 2005 15:44:27 -0000 1.6
@@ -30,7 +30,7 @@
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
1.3 +5 -5
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java
Index: AbstractArtifactMetadata.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractArtifactMetadata.java 24 Mar 2005 10:30:58 -0000 1.2
+++ AbstractArtifactMetadata.java 29 Mar 2005 15:44:27 -0000 1.3
@@ -27,14 +27,14 @@
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 @@
return artifact;
}
- public String getFilenameSuffix()
+ public String getFilename()
{
- return filenameSuffix;
+ return filename;
}
}
1.6 +4 -14
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java
Index: ArtifactMetadata.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ArtifactMetadata.java 24 Mar 2005 14:52:25 -0000 1.5
+++ ArtifactMetadata.java 29 Mar 2005 15:44:27 -0000 1.6
@@ -17,7 +17,6 @@
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
@@ -40,15 +39,6 @@
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.
*
* @return the artifact
@@ -56,11 +46,11 @@
Artifact getArtifact();
/**
- * Get the filenameSuffix of this metadata.
+ * Get the filename of this metadata.
*
- * @return the filenameSuffix
+ * @return the filename
*/
- String getFilenameSuffix();
+ String getFilename();
/**
1.7 +28 -28
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java
Index: SnapshotArtifactMetadata.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SnapshotArtifactMetadata.java 24 Mar 2005 16:03:51 -0000 1.6
+++ SnapshotArtifactMetadata.java 29 Mar 2005 15:44:27 -0000 1.7
@@ -46,24 +46,22 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{
throw new ArtifactMetadataRetrievalException( "Unable to
retrieve metadata", e );
}
+
+ return snapshotMetadata;
}
private void readFromFile( File destination )
1.7 +3 -1
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
Index: AbstractArtifactRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractArtifactRepositoryLayout.java 24 Mar 2005 10:30:58 -0000
1.6
+++ AbstractArtifactRepositoryLayout.java 29 Mar 2005 15:44:28 -0000
1.7
@@ -59,7 +59,7 @@
{
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 @@
path = StringUtils.replace( path, "${version}",
artifact.getVersion() );
+ path = StringUtils.replace( path, "${baseVersion}",
artifact.getBaseVersion() );
+
ArtifactHandler artifactHandler = null;
try
{
1.6 +2 -2
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
Index: DefaultRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultRepositoryLayout.java 24 Mar 2005 10:30:58 -0000 1.5
+++ DefaultRepositoryLayout.java 29 Mar 2005 15:44:28 -0000 1.6
@@ -25,12 +25,12 @@
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 )
1.6 +1 -1
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
Index: LegacyRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LegacyRepositoryLayout.java 24 Mar 2005 10:30:58 -0000 1.5
+++ LegacyRepositoryLayout.java 29 Mar 2005 15:44:28 -0000 1.6
@@ -30,7 +30,7 @@
protected String metadataLayoutPattern()
{
- return
"${groupPath}/poms/${artifactId}-${version}.${metadataSuffix}";
+ return "${groupPath}/poms/${metadataFilename}";
}
protected String groupIdAsPath( String groupId )
1.10 +25 -21
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
Index: SnapshotTransformation.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SnapshotTransformation.java 24 Mar 2005 16:03:51 -0000 1.9
+++ SnapshotTransformation.java 29 Mar 2005 15:44:28 -0000 1.10
@@ -23,7 +23,9 @@
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 @@
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 @@
// - 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 @@
{
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 @@
artifact = createArtifactCopy( artifact, localMetadata );
resolvedArtifactCache.add( getCacheKey( artifact ) );
-*/
}
return artifact;
}
@@ -117,17 +117,21 @@
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 @@
{
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 @@
private Artifact createArtifactCopy( Artifact artifact,
SnapshotArtifactMetadata metadata )
{
- ArtifactRepository oldRepository = artifact.getRepository();
- List list = artifact.getMetadataList();
-
- artifact = new DefaultArtifact( artifact.getGroupId(),
artifact.getArtifactId(), metadata.getVersion(),
- artifact.getScope(),
artifact.getType(), artifact.getClassifier() );
+ Artifact newArtifact = new DefaultArtifact( artifact.getGroupId(),
artifact.getArtifactId(),
+
metadata.constructVersion(), artifact.getScope(),
+ artifact.getType(),
artifact.getClassifier() );
+ newArtifact.setBaseVersion( artifact.getBaseVersion() );
- 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 )
1.10 +6 -0
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
Index: Artifact.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Artifact.java 24 Mar 2005 14:52:25 -0000 1.9
+++ Artifact.java 29 Mar 2005 15:44:28 -0000 1.10
@@ -24,6 +24,8 @@
/**
* Description of an artifact.
+ *
+ * @todo do we really need an interface here?
*/
public interface Artifact
{
@@ -60,6 +62,10 @@
void setFile( File destination );
+ String getBaseVersion();
+
+ void setBaseVersion( String baseVersion );
+
// ----------------------------------------------------------------------
String getId();
1.20 +19 -6
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
Index: DefaultArtifact.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DefaultArtifact.java 24 Mar 2005 14:52:25 -0000 1.19
+++ DefaultArtifact.java 29 Mar 2005 15:44:28 -0000 1.20
@@ -39,6 +39,8 @@
private final String version;
+ private String baseVersion;
+
private final String type;
private final String classifier;
@@ -129,10 +131,6 @@
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 String getId()
{
- return getConflictId() + ( hasClassifier() ? ( ":" + getClassifier()
) : "" ) + ":" + getVersion();
+ return getConflictId() + ( hasClassifier() ? ( ":" + getClassifier()
) : "" ) + ":" + getBaseVersion();
}
public String getConflictId()
@@ -230,4 +228,19 @@
}
return true;
}
+
+ public String getBaseVersion()
+ {
+ if ( baseVersion == null )
+ {
+ baseVersion = version;
+ }
+ return baseVersion;
+ }
+
+ public void setBaseVersion( String baseVersion )
+ {
+ this.baseVersion = baseVersion;
+ }
+
}
\ No newline at end of file