use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class DaysOldRepositoryPurge method process.
@Override
public void process(String path) throws RepositoryPurgeException {
try {
Path artifactFile = Paths.get(repository.getRepoRoot(), path);
if (!Files.exists(artifactFile)) {
return;
}
ArtifactReference artifact = repository.toArtifactReference(path);
Calendar olderThanThisDate = Calendar.getInstance(DateUtils.UTC_TIME_ZONE);
olderThanThisDate.add(Calendar.DATE, -retentionPeriod);
// respect retention count
VersionedReference reference = new VersionedReference();
reference.setGroupId(artifact.getGroupId());
reference.setArtifactId(artifact.getArtifactId());
reference.setVersion(artifact.getVersion());
List<String> versions = new ArrayList<>(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;
Set<ArtifactReference> artifactsToDelete = new HashSet<>();
for (String version : versions) {
if (countToPurge-- <= 0) {
break;
}
ArtifactReference newArtifactReference = repository.toArtifactReference(artifactFile.toAbsolutePath().toString());
newArtifactReference.setVersion(version);
Path newArtifactFile = repository.toFile(newArtifactReference);
// Is this a generic snapshot "1.0-SNAPSHOT" ?
if (VersionUtil.isGenericSnapshot(newArtifactReference.getVersion())) {
if (Files.getLastModifiedTime(newArtifactFile).toMillis() < olderThanThisDate.getTimeInMillis()) {
artifactsToDelete.addAll(repository.getRelatedArtifacts(newArtifactReference));
}
} else // Is this a timestamp snapshot "1.0-20070822.123456-42" ?
if (VersionUtil.isUniqueSnapshot(newArtifactReference.getVersion())) {
Calendar timestampCal = uniqueSnapshotToCalendar(newArtifactReference.getVersion());
if (timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis()) {
artifactsToDelete.addAll(repository.getRelatedArtifacts(newArtifactReference));
}
}
}
purge(artifactsToDelete);
} catch (ContentNotFoundException | IOException e) {
throw new RepositoryPurgeException(e.getMessage(), e);
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
}
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class SnapshotTransferTest method testMetadataDrivenSnapshotNotPresentAlready.
@Test
public void testMetadataDrivenSnapshotNotPresentAlready() throws Exception {
String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
Files.deleteIfExists(expectedFile);
assertFalse(Files.exists(expectedFile));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile, proxiedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class SnapshotTransferTest method testNewerTimestampDrivenSnapshotOnFirstRepo.
@Test
public void testNewerTimestampDrivenSnapshotOnFirstRepo() throws Exception {
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
assertTrue(Files.exists(expectedFile));
Files.setLastModifiedTime(expectedFile, FileTime.from(getPastDate().getTime(), TimeUnit.MILLISECONDS));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals(expectedFile, downloadedFile, proxiedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class SnapshotTransferTest method testTimestampDrivenSnapshotNotExpired.
/**
* TODO: Has problems with wagon implementation not preserving timestamp.
*/
/*
public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
throws Exception
{
String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path );
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = createArtifactReference( "default", path );
Files.delete(expectedFile);
assertFalse( Files.exists(expectedFile) );
// Create customized proxy / target repository
File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
REPOPATH_PROXIED1_TARGET, "default" );
new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
Path proxiedFile = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile );
}
public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready()
throws Exception
{
String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path );
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = createArtifactReference( "default", path );
Files.delete(expectedFile);
assertFalse( Files.exists(expectedFile) );
// Create customized proxy / target repository
File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
REPOPATH_PROXIED2_TARGET, "default" );
new File( targetProxyDir, path ).setLastModified( getPastDate().getTime() );
// Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2_TARGET, ChecksumPolicy.IGNORED, ReleasesPolicy.IGNORED,
SnapshotsPolicy.IGNORED, CachedFailuresPolicy.IGNORED );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1_TARGET, path );
assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile );
} */
@Test
public void testTimestampDrivenSnapshotNotExpired() throws Exception {
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
assertTrue(Files.exists(expectedFile));
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
Files.setLastModifiedTime(proxiedFile, FileTime.from(getFutureDate().getTime(), TimeUnit.MILLISECONDS));
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
assertFileEquals(expectedFile, downloadedFile, proxiedFile);
assertNoTempFiles(expectedFile);
}
use of org.apache.archiva.model.ArtifactReference in project archiva by apache.
the class SnapshotTransferTest method testTimestampDrivenSnapshotNotUpdated.
@Test
public void testTimestampDrivenSnapshotNotUpdated() throws Exception {
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository(path);
Path expectedFile = managedDefaultDir.resolve(path);
Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedNewerThanRemote(expectedFile, remoteFile, 12000000);
long expectedTimestamp = Files.getLastModifiedTime(expectedFile).toMillis();
ArtifactReference artifact = managedDefaultRepository.toArtifactReference(path);
// Configure Connector (usually done within archiva.xml configuration)
saveConnector(ID_DEFAULT_MANAGED, ID_PROXIED1, false);
Path downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository, artifact);
assertNotDownloaded(downloadedFile);
assertNotModified(expectedFile, expectedTimestamp);
assertNoTempFiles(expectedFile);
}
Aggregations