use of org.apache.archiva.metadata.repository.storage.RelocationException in project archiva by apache.
the class ArchivaDavResourceFactory method evaluatePathWithVersion.
private //
String evaluatePathWithVersion(//
ArchivaDavResourceLocator archivaLocator, //
ManagedRepositoryContent managedRepositoryContent, String contextPath) throws DavException {
String layout = managedRepositoryContent.getRepository() == null ? "default" : managedRepositoryContent.getRepository().getLayout();
RepositoryStorage repositoryStorage = this.applicationContext.getBean("repositoryStorage#" + layout, RepositoryStorage.class);
try {
return //
repositoryStorage.getFilePathWithVersion(//
archivaLocator.getResourcePath(), managedRepositoryContent);
} catch (RelocationException e) {
String path = e.getPath();
log.debug("Relocation to {}", path);
throw new BrowserRedirectException(addHrefPrefix(contextPath, path), e.getRelocationType());
} catch (XMLException e) {
log.error(e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
use of org.apache.archiva.metadata.repository.storage.RelocationException 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;
}
Aggregations