mirror of https://github.com/apache/archiva.git
[MRM-535] metadata-updater is changing lastUpdating timestamp when it shouldn't
Correcting logic in snapshot metadata to only update on the following conditions. * Last Updated exist in original metadata.xml or ... * Last Updated timestamp as found in unique (timestamped) snapshots is newer. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@584994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a97d5c15b7
commit
0ef85fe69c
|
@ -501,6 +501,22 @@ public class MetadataTools
|
||||||
|
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long toLastUpdatedLong( String timestampString )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Date date = lastUpdatedFormat.parse( timestampString );
|
||||||
|
Calendar cal = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
|
||||||
|
cal.setTime( date );
|
||||||
|
|
||||||
|
return cal.getTimeInMillis();
|
||||||
|
}
|
||||||
|
catch ( ParseException e )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long getLastUpdated( ArchivaRepositoryMetadata metadata )
|
private long getLastUpdated( ArchivaRepositoryMetadata metadata )
|
||||||
{
|
{
|
||||||
|
@ -570,16 +586,12 @@ public class MetadataTools
|
||||||
{
|
{
|
||||||
File metadataFile = new File( managedRepository.getRepoRoot(), toPath( reference ) );
|
File metadataFile = new File( managedRepository.getRepoRoot(), toPath( reference ) );
|
||||||
|
|
||||||
long originalLastUpdated = getExistingLastUpdated( metadataFile );
|
long lastUpdated = getExistingLastUpdated( metadataFile );
|
||||||
|
|
||||||
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
|
ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
|
||||||
metadata.setGroupId( reference.getGroupId() );
|
metadata.setGroupId( reference.getGroupId() );
|
||||||
metadata.setArtifactId( reference.getArtifactId() );
|
metadata.setArtifactId( reference.getArtifactId() );
|
||||||
if ( originalLastUpdated > 0 )
|
|
||||||
{
|
|
||||||
metadata.setLastUpdatedTimestamp( toLastUpdatedDate( originalLastUpdated ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( VersionUtil.isSnapshot( reference.getVersion() ) )
|
if ( VersionUtil.isSnapshot( reference.getVersion() ) )
|
||||||
{
|
{
|
||||||
// Do SNAPSHOT handling.
|
// Do SNAPSHOT handling.
|
||||||
|
@ -619,7 +631,11 @@ public class MetadataTools
|
||||||
{
|
{
|
||||||
String tsDate = mtimestamp.group( 1 );
|
String tsDate = mtimestamp.group( 1 );
|
||||||
String tsTime = mtimestamp.group( 2 );
|
String tsTime = mtimestamp.group( 2 );
|
||||||
metadata.setLastUpdated( tsDate + tsTime );
|
|
||||||
|
long snapshotLastUpdated = toLastUpdatedLong( tsDate + tsTime );
|
||||||
|
|
||||||
|
lastUpdated = Math.max( lastUpdated, snapshotLastUpdated );
|
||||||
|
|
||||||
metadata.getSnapshotVersion().setTimestamp( m.group( 2 ) );
|
metadata.getSnapshotVersion().setTimestamp( m.group( 2 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,9 +647,12 @@ public class MetadataTools
|
||||||
|
|
||||||
metadata.setSnapshotVersion( new SnapshotVersion() );
|
metadata.setSnapshotVersion( new SnapshotVersion() );
|
||||||
|
|
||||||
/* TODO: Should this be the last updated timestamp of the file, or in the case of an
|
/* 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?
|
* archive, the most recent timestamp in the archive?
|
||||||
*/
|
*
|
||||||
ArtifactReference artifact = getFirstArtifact( managedRepository, reference );
|
ArtifactReference artifact = getFirstArtifact( managedRepository, reference );
|
||||||
|
|
||||||
if ( artifact == null )
|
if ( artifact == null )
|
||||||
|
@ -648,6 +667,7 @@ public class MetadataTools
|
||||||
Date lastModified = new Date( artifactFile.lastModified() );
|
Date lastModified = new Date( artifactFile.lastModified() );
|
||||||
metadata.setLastUpdatedTimestamp( lastModified );
|
metadata.setLastUpdatedTimestamp( lastModified );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -661,6 +681,12 @@ public class MetadataTools
|
||||||
metadata.setVersion( reference.getVersion() );
|
metadata.setVersion( reference.getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set last updated
|
||||||
|
if ( lastUpdated > 0 )
|
||||||
|
{
|
||||||
|
metadata.setLastUpdatedTimestamp( toLastUpdatedDate( lastUpdated ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Save the metadata model to disk.
|
// Save the metadata model to disk.
|
||||||
RepositoryMetadataWriter.write( metadata, metadataFile );
|
RepositoryMetadataWriter.write( metadata, metadataFile );
|
||||||
checksums.update( metadataFile );
|
checksums.update( metadataFile );
|
||||||
|
|
Loading…
Reference in New Issue