Search in sources :

Example 1 with RelocationException

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);
    }
}
Also used : RepositoryStorage(org.apache.archiva.metadata.repository.storage.RepositoryStorage) XMLException(org.apache.archiva.xml.XMLException) RelocationException(org.apache.archiva.metadata.repository.storage.RelocationException) DavException(org.apache.jackrabbit.webdav.DavException)

Example 2 with RelocationException

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;
}
Also used : Path(java.nio.file.Path) RelocationException(org.apache.archiva.metadata.repository.storage.RelocationException) LayoutException(org.apache.archiva.repository.LayoutException) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Aggregations

RelocationException (org.apache.archiva.metadata.repository.storage.RelocationException)2 Path (java.nio.file.Path)1 RepositoryStorage (org.apache.archiva.metadata.repository.storage.RepositoryStorage)1 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)1 ArtifactReference (org.apache.archiva.model.ArtifactReference)1 LayoutException (org.apache.archiva.repository.LayoutException)1 XMLException (org.apache.archiva.xml.XMLException)1 DavException (org.apache.jackrabbit.webdav.DavException)1