diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
index 962f5447b1..47dac0cf1e 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java
@@ -16,8 +16,14 @@ package org.apache.maven.artifact;
* limitations under the License.
*/
-import java.io.File;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import java.io.File;
+import java.util.List;
+
+/**
+ * Description of an artifact.
+ */
public interface Artifact
{
// TODO: into scope handler
@@ -61,4 +67,8 @@ public interface Artifact
String getId();
String getConflictId();
+
+ void addMetadata( ArtifactMetadata metadata );
+
+ List getMetadataList();
}
\ No newline at end of file
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
index 872ea56a2c..73c015b9d9 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
@@ -16,9 +16,13 @@ package org.apache.maven.artifact;
* limitations under the License.
*/
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* @author Jason van Zyl
@@ -46,6 +50,8 @@ public class DefaultArtifact
private String path;
+ private List metadataList;
+
/**
* @todo this should be replaced by type handler
* !!! WARNING !!! Never put in the POM. It is for mojo use
@@ -161,6 +167,20 @@ public class DefaultArtifact
return getGroupId() + ":" + getArtifactId() + ":" + getType();
}
+ public void addMetadata( ArtifactMetadata metadata )
+ {
+ if ( metadataList == null )
+ {
+ metadataList = new ArrayList();
+ }
+ metadataList.add( metadata );
+ }
+
+ public List getMetadataList()
+ {
+ return metadataList == null ? Collections.EMPTY_LIST : metadataList;
+ }
+
// ----------------------------------------------------------------------
// Object overrides
// ----------------------------------------------------------------------
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
index b1a560db71..231f1e1d62 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java
@@ -82,7 +82,6 @@ public class DefaultArtifactHandlerManager
// TODO: perform transformation
}
- String artifactPath = localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
- return artifactPath;
+ return localRepository.getBasedir() + "/" + localRepository.pathOf( artifact );
}
}
\ No newline at end of file
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
index 52f132554c..0d5a97b1c7 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java
@@ -19,6 +19,7 @@ package org.apache.maven.artifact.installer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -26,6 +27,7 @@ import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
+import java.util.Iterator;
public class DefaultArtifactInstaller
extends AbstractLogEnabled
@@ -65,6 +67,13 @@ public class DefaultArtifactInstaller
getLogger().info( "Installing " + source.getPath() + " to " + artifact.getPath() );
FileUtils.copyFile( source, artifact.getFile() );
+
+ // must be after the artifact is installed
+ for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
+ {
+ ArtifactMetadata metadata = (ArtifactMetadata) i.next();
+ metadata.storeInLocalRepository( localRepository );
+ }
}
catch ( IOException e )
{
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java
new file mode 100644
index 0000000000..c9a25349a4
--- /dev/null
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java
@@ -0,0 +1,49 @@
+package org.apache.maven.artifact.metadata;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * Common elements of artifact metadata.
+ *
+ * @author Brett Porter
+ * @version $Id$
+ */
+public abstract class AbstractArtifactMetadata
+ implements ArtifactMetadata
+{
+ protected final String filename;
+
+ protected final Artifact artifact;
+
+ protected AbstractArtifactMetadata( Artifact artifact, String filename )
+ {
+ this.artifact = artifact;
+ this.filename = filename;
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public String getFilename()
+ {
+ return filename;
+ }
+}
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java
new file mode 100644
index 0000000000..4c3eede196
--- /dev/null
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java
@@ -0,0 +1,56 @@
+package org.apache.maven.artifact.metadata;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
+
+import java.io.IOException;
+
+/**
+ * Contains metadata about an artifact, and methods to retrieve/store it from an artifact repository.
+ *
+ * @author Brett Porter
+ * @version $Id$
+ * @todo naming is too close to ArtifactMetadataSource which refers to a POM. A POM is sometimes an artifact itself,
+ * so that naming may no longer be appropriate.
+ */
+public interface ArtifactMetadata
+{
+ /**
+ * Store the metadata in the local repository.
+ *
+ * @param localRepository the local repository
+ */
+ void storeInLocalRepository( ArtifactRepository localRepository )
+ throws IOException, ArtifactPathFormatException;
+
+ /**
+ * Get the associated artifact.
+ *
+ * @return the artifact
+ */
+ Artifact getArtifact();
+
+ /**
+ * Get the filename of this metadata.
+ *
+ * @return the filename
+ */
+ String getFilename();
+}
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java
new file mode 100644
index 0000000000..5b9e46bab7
--- /dev/null
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java
@@ -0,0 +1,81 @@
+package org.apache.maven.artifact.metadata;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * Contains the information stored for a snapshot.
+ *
+ * @author Brett Porter
+ * @version $Id$
+ */
+public class SnapshotArtifactMetadata
+ extends AbstractArtifactMetadata
+{
+ private String timestamp = null;
+
+ private int buildNumber = 1;
+
+ 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 SnapshotArtifactMetadata( Artifact artifact, String filename )
+ {
+ super( artifact, filename );
+ }
+
+ public static SnapshotArtifactMetadata createLocalSnapshotMetadata( Artifact artifact )
+ {
+ return new SnapshotArtifactMetadata( artifact, SNAPSHOT_VERSION_LOCAL_FILE );
+ }
+
+ public void storeInLocalRepository( ArtifactRepository localRepository )
+ throws IOException, ArtifactPathFormatException
+ {
+ FileUtils.fileWrite( localRepository.getBasedir() + "/" + localRepository.pathOfMetadata( this ),
+ getTimestamp() + "-" + buildNumber );
+ }
+
+ public String getTimestamp()
+ {
+ if ( timestamp == null )
+ {
+ timestamp = getUtcDateFormatter().format( new Date() );
+ }
+ return timestamp;
+ }
+
+ public DateFormat getUtcDateFormatter()
+ {
+ DateFormat utcDateFormatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
+ utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
+ return utcDateFormatter;
+ }
+}
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
index 4fa1f6f6b4..832ec3357c 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java
@@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
@@ -55,4 +56,10 @@ public class ArtifactRepository
return layout.pathOf( artifact );
}
+ public String pathOfMetadata( ArtifactMetadata artifactMetadata )
+ throws ArtifactPathFormatException
+ {
+ return layout.pathOfMetadata( artifactMetadata );
+ }
+
}
\ No newline at end of file
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
index a2bf8474d2..0a6679a472 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
@@ -20,35 +20,27 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.codehaus.plexus.util.StringUtils;
/**
* @author jdcasey
*/
public abstract class AbstractArtifactRepositoryLayout
- extends AbstractLogEnabled
implements ArtifactRepositoryLayout
{
-
private ArtifactHandlerManager artifactHandlerManager;
protected abstract String layoutPattern();
+ protected abstract String metadataLayoutPattern();
+
protected abstract String groupIdAsPath( String groupId );
public String pathOf( Artifact artifact )
throws ArtifactPathFormatException
{
- String path = layoutPattern();
-
- String groupPath = groupIdAsPath( artifact.getGroupId() );
-
- path = StringUtils.replace( path, "${groupPath}", groupPath );
-
- path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
-
- path = StringUtils.replace( path, "${version}", artifact.getVersion() );
+ String path = basicPathOf( artifact, layoutPattern() );
if ( artifact.hasClassifier() )
{
@@ -59,6 +51,32 @@ public abstract class AbstractArtifactRepositoryLayout
path = StringUtils.replace( path, "-${classifier}", "" );
}
+ return path;
+ }
+
+ public String pathOfMetadata( ArtifactMetadata metadata )
+ throws ArtifactPathFormatException
+ {
+ String path = basicPathOf( metadata.getArtifact(), metadataLayoutPattern() );
+
+ path = StringUtils.replace( path, "${metadataFilename}", metadata.getFilename() );
+
+ return path;
+ }
+
+ private String basicPathOf( Artifact artifact, String pattern )
+ throws ArtifactPathFormatException
+ {
+ String path = pattern;
+
+ String groupPath = groupIdAsPath( artifact.getGroupId() );
+
+ path = StringUtils.replace( path, "${groupPath}", groupPath );
+
+ path = StringUtils.replace( path, "${artifactId}", artifact.getArtifactId() );
+
+ path = StringUtils.replace( path, "${version}", artifact.getVersion() );
+
ArtifactHandler artifactHandler = null;
try
{
@@ -73,7 +91,6 @@ public abstract class AbstractArtifactRepositoryLayout
path = StringUtils.replace( path, "${directory}", artifactHandler.directory() );
path = StringUtils.replace( path, "${extension}", artifactHandler.extension() );
-
return path;
}
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
index d2268fced4..a1b50979da 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java
@@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.layout;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
/**
* @author jdcasey
@@ -29,4 +30,6 @@ public interface ArtifactRepositoryLayout
String pathOf( Artifact artifact )
throws ArtifactPathFormatException;
+ String pathOfMetadata( ArtifactMetadata metadata )
+ throws ArtifactPathFormatException;
}
\ No newline at end of file
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
index 31eccf9a6d..037273e24c 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
@@ -28,6 +28,11 @@ public class DefaultRepositoryLayout
return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
}
+ protected String metadataLayoutPattern()
+ {
+ return "${groupPath}/${artifactId}/${version}/${metadataFilename}";
+ }
+
protected String groupIdAsPath( String groupId )
{
return groupId.replace( '.', '/' );
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
index 214cbd5a33..7d0ff4a3cf 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
@@ -28,6 +28,11 @@ public class LegacyRepositoryLayout
return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}";
}
+ protected String metadataLayoutPattern()
+ {
+ return "${groupPath}/${directory}/${artifactId}-${version}-${metadataFilename}";
+ }
+
protected String groupIdAsPath( String groupId )
{
return groupId;
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
index 6ccaa02528..8d2fcac638 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java
@@ -17,6 +17,8 @@ package org.apache.maven.artifact.transform;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
@@ -185,7 +187,17 @@ public class SnapshotTransformation
*/
public Artifact transformLocalArtifact( Artifact artifact, ArtifactRepository localRepository )
{
- // TODO: implement
+ if ( isSnapshot( artifact ) && "pom".equals( artifact.getType() ) )
+ {
+ // only store the snapshot-version-local.txt file for POMs as every file has an associated POM
+ ArtifactMetadata metadata = SnapshotArtifactMetadata.createLocalSnapshotMetadata( artifact );
+ artifact.addMetadata( metadata );
+ }
return artifact;
}
+
+ private static boolean isSnapshot( Artifact artifact )
+ {
+ return artifact.getVersion().endsWith( "SNAPSHOT" );
+ }
}
\ No newline at end of file