if ( !artifactFile.exists() )
{
return;
}
ArtifactReference artifact = repository.toArtifactReference( path );
Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
olderThanThisDate.add( Calendar.DATE, -daysOlder );
// respect retention count
VersionedReference reference = new VersionedReference();
reference.setGroupId( artifact.getGroupId() );
reference.setArtifactId( artifact.getArtifactId() );
reference.setVersion( artifact.getVersion() );
List<String> versions = new ArrayList<String>( repository.getVersions( reference ) );
Collections.sort( versions, VersionComparator.getInstance() );
if ( retentionCount > versions.size() )
{
// Done. nothing to do here. skip it.
return;
}
int countToPurge = versions.size() - retentionCount;
for ( String version : versions )
{
if ( countToPurge <= 0 )
{
break;
}
ArtifactReference newArtifactReference =
repository.toArtifactReference( artifactFile.getAbsolutePath() );
newArtifactReference.setVersion( version );
File newArtifactFile = repository.toFile( newArtifactReference );
// Is this a generic snapshot "1.0-SNAPSHOT" ?
if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion() ) )
{
if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
{
doPurgeAllRelated( newArtifactReference );
countToPurge--;
}
}
// Is this a timestamp snapshot "1.0-20070822.123456-42" ?
else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion() ) )
{
Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion() );
if ( timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis() )
{
doPurgeAllRelated( newArtifactReference );
countToPurge--;