use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class Maven2RepositoryStorage method getFilePathWithVersion.
@Override
public String getFilePathWithVersion(final String requestPath, ManagedRepositoryContent managedRepositoryContent) throws XMLException, RelocationException {
if (StringUtils.endsWith(requestPath, METADATA_FILENAME)) {
return getFilePath(requestPath, managedRepositoryContent.getRepository());
}
String filePath = getFilePath(requestPath, managedRepositoryContent.getRepository());
ArtifactReference artifactReference = null;
try {
artifactReference = pathParser.toArtifactReference(filePath);
} catch (LayoutException e) {
return filePath;
}
if (StringUtils.endsWith(artifactReference.getVersion(), VersionUtil.SNAPSHOT)) {
// read maven metadata to get last timestamp
Path metadataDir = Paths.get(managedRepositoryContent.getRepoRoot(), filePath).getParent();
if (!Files.exists(metadataDir)) {
return filePath;
}
Path metadataFile = metadataDir.resolve(METADATA_FILENAME);
if (!Files.exists(metadataFile)) {
return filePath;
}
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(metadataFile);
int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
// MRM-1846
if (buildNumber < 1 && timestamp == null) {
return filePath;
}
// org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar
// -> archiva-checksum-1.4-M4-20130425.081822-1.jar
filePath = //
StringUtils.replace(//
filePath, //
artifactReference.getArtifactId() + "-" + //
artifactReference.getVersion(), //
artifactReference.getArtifactId() + "-" + StringUtils.remove(artifactReference.getVersion(), //
"-" + VersionUtil.SNAPSHOT) + "-" + //
timestamp + "-" + buildNumber);
throw new RelocationException("/repository/" + managedRepositoryContent.getRepository().getId() + (StringUtils.startsWith(filePath, "/") ? "" : "/") + filePath, RelocationException.RelocationType.TEMPORARY);
}
return filePath;
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class MetadataUpdaterConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
// Ignore paths like .index etc
if (!path.startsWith(".")) {
try {
ArtifactReference artifact = repository.toArtifactReference(path);
updateVersionMetadata(artifact, path);
updateProjectMetadata(artifact, path);
} catch (LayoutException e) {
log.info("Not processing path that is not an artifact: {} ({})", path, e.getMessage());
}
}
}
use of org.apache.archiva.repository.LayoutException 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.repository.LayoutException in project archiva by apache.
the class RepositoryRequestTest method testNativePathBadRequestNull.
@Test
public void testNativePathBadRequestNull() throws Exception {
ManagedRepositoryContent repository = createManagedRepo("default");
// Test bad request path (too short)
try {
repoRequest.toNativePath(null, repository);
fail("Should have thrown an exception about an null request.");
} catch (LayoutException e) {
// expected path.
}
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class ManagedDefaultRepositoryContent method getVersions.
@Override
public Set<String> getVersions(VersionedReference reference) throws ContentNotFoundException {
String path = toMetadataPath(reference);
int idx = path.lastIndexOf('/');
if (idx > 0) {
path = path.substring(0, idx);
}
Path repoBase = PathUtil.getPathFromUri(repository.getLocation());
Path repoDir = repoBase.resolve(path);
if (!Files.exists(repoDir)) {
throw new ContentNotFoundException("Unable to get versions on a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new ContentNotFoundException("Unable to get versions on a non-directory: " + repoDir.toAbsolutePath());
}
Set<String> foundVersions = new HashSet<>();
try (Stream<Path> stream = Files.list(repoDir)) {
return stream.filter(Files::isRegularFile).map(p -> repoBase.relativize(p).toString()).filter(p -> !filetypes.matchesDefaultExclusions(p)).filter(filetypes::matchesArtifactPattern).map(path1 -> {
try {
return toArtifactReference(path1);
} catch (LayoutException e) {
log.debug("Not processing file that is not an artifact: {}", e.getMessage());
return null;
}
}).filter(Objects::nonNull).map(ar -> ar.getVersion()).collect(Collectors.toSet());
} catch (IOException e) {
log.error("Could not read directory {}: {}", repoDir, e.getMessage(), e);
}
return Collections.emptySet();
}
Aggregations