allVersions = null;
try
@@ -761,6 +866,135 @@ public class MetadataTools
return getLastUpdated( metadata );
}
+ /**
+ * Update the metadata based on the following rules.
+ *
+ * 1) If this is a SNAPSHOT reference, then utilize the proxy/repository specific
+ * metadata files to represent the current / latest SNAPSHOT available.
+ * 2) If this is a RELEASE reference, and the metadata file does not exist, then
+ * create the metadata file with contents required of the VersionedReference
+ *
+ * @param managedRepository the managed repository where the metadata is kept.
+ * @param reference the versioned reference to update
+ * @throws LayoutException
+ * @throws RepositoryMetadataException
+ * @throws IOException
+ * @throws ContentNotFoundException
+ * @deprecated
+ */
+ public void updateVersionMetadata( ManagedRepositoryContent managedRepository, ItemSelector reference )
+ throws LayoutException, RepositoryMetadataException, IOException, ContentNotFoundException
+ {
+ StorageAsset metadataFile = managedRepository.getRepository().getAsset( toPath( reference ) );
+ ArchivaRepositoryMetadata existingMetadata = readMetadataFile(managedRepository, metadataFile );
+
+ long lastUpdated = getExistingLastUpdated( existingMetadata );
+
+ ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
+ metadata.setGroupId( reference.getNamespace() );
+ metadata.setArtifactId( reference.getArtifactId() );
+
+ if ( VersionUtil.isSnapshot( reference.getVersion() ) )
+ {
+ // Do SNAPSHOT handling.
+ metadata.setVersion( VersionUtil.getBaseVersion( reference.getVersion() ) );
+
+ // Gather up all of the versions found in the reference dir, and any
+ // proxied maven-metadata.xml files.
+ Set snapshotVersions = gatherSnapshotVersions( managedRepository, reference );
+
+ if ( snapshotVersions.isEmpty() )
+ {
+ throw new ContentNotFoundException(
+ "No snapshot versions found on reference [" + reference + "]." );
+ }
+
+ // sort the list to determine to aide in determining the Latest version.
+ List sortedVersions = new ArrayList<>();
+ sortedVersions.addAll( snapshotVersions );
+ Collections.sort( sortedVersions, new VersionComparator() );
+
+ String latestVersion = sortedVersions.get( sortedVersions.size() - 1 );
+
+ if ( VersionUtil.isUniqueSnapshot( latestVersion ) )
+ {
+ // The latestVersion will contain the full version string "1.0-alpha-5-20070821.213044-8"
+ // This needs to be broken down into ${base}-${timestamp}-${build_number}
+
+ Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( latestVersion );
+ if ( m.matches() )
+ {
+ metadata.setSnapshotVersion( new SnapshotVersion() );
+ int buildNumber = NumberUtils.toInt( m.group( 3 ), -1 );
+ metadata.getSnapshotVersion().setBuildNumber( buildNumber );
+
+ Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) );
+ if ( mtimestamp.matches() )
+ {
+ String tsDate = mtimestamp.group( 1 );
+ String tsTime = mtimestamp.group( 2 );
+
+ long snapshotLastUpdated = toLastUpdatedLong( tsDate + tsTime );
+
+ lastUpdated = Math.max( lastUpdated, snapshotLastUpdated );
+
+ metadata.getSnapshotVersion().setTimestamp( m.group( 2 ) );
+ }
+ }
+ }
+ else if ( VersionUtil.isGenericSnapshot( latestVersion ) )
+ {
+ // The latestVersion ends with the generic version string.
+ // Example: 1.0-alpha-5-SNAPSHOT
+
+ metadata.setSnapshotVersion( new SnapshotVersion() );
+
+ /* Disabled due to decision in [MRM-535].
+ * Do not set metadata.lastUpdated to file.lastModified.
+ *
+ * Should this be the last updated timestamp of the file, or in the case of an
+ * archive, the most recent timestamp in the archive?
+ *
+ ArtifactReference artifact = getFirstArtifact( managedRepository, reference );
+
+ if ( artifact == null )
+ {
+ throw new IOException( "Not snapshot artifact found to reference in " + reference );
+ }
+
+ File artifactFile = managedRepository.toFile( artifact );
+
+ if ( artifactFile.exists() )
+ {
+ Date lastModified = new Date( artifactFile.lastModified() );
+ metadata.setLastUpdatedTimestamp( lastModified );
+ }
+ */
+ }
+ else
+ {
+ throw new RepositoryMetadataException(
+ "Unable to process snapshot version <" + latestVersion + "> reference <" + reference + ">" );
+ }
+ }
+ else
+ {
+ // Do RELEASE handling.
+ metadata.setVersion( reference.getVersion() );
+ }
+
+ // Set last updated
+ if ( lastUpdated > 0 )
+ {
+ metadata.setLastUpdatedTimestamp( toLastUpdatedDate( lastUpdated ) );
+ }
+
+ // Save the metadata model to disk.
+ RepositoryMetadataWriter.write( metadata, metadataFile );
+ ChecksummedFile checksum = new ChecksummedFile( metadataFile.getFilePath() );
+ checksum.fixChecksums( algorithms );
+ }
+
/**
* Update the metadata based on the following rules.
*
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml b/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
index 08daeb383..b6df47cff 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
@@ -65,10 +65,6 @@
org.apache.archiva
archiva-filelock