use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class LegacyConverterArtifactConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
try {
ArtifactReference reference = managedRepository.toArtifactReference(path);
Artifact artifact = artifactFactory.createArtifact(reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference.getClassifier(), reference.getType());
artifactConverter.convert(artifact, destinationRepository);
} catch (LayoutException e) {
log.warn("Unable to convert artifact: {} : {}", path, e.getMessage(), e);
} catch (ArtifactConversionException e) {
log.warn("Unable to convert artifact: {} : {}", path, e.getMessage(), e);
}
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class SimpleArtifactConsumer method processFile.
public void processFile(String path, boolean executeOnEntireRepo) throws ConsumerException {
log.info("Processing entry [{}] from repository [{}]", path, this.repository.getId());
try {
ManagedRepositoryContent repositoryContent = repository.getContent();
ArtifactReference artifact = repositoryContent.toArtifactReference(path);
repositorySession.getRepository().getArtifacts(repository.getId(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
} catch (LayoutException | MetadataResolutionException e) {
throw new ConsumerException(e.getLocalizedMessage(), e);
}
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class MetadataTools method getFirstArtifact.
/**
* Get the first Artifact found in the provided VersionedReference location.
*
* @param managedRepository the repository to search within.
* @param reference the reference to the versioned reference to search within
* @return the ArtifactReference to the first artifact located within the versioned reference. or null if
* no artifact was found within the versioned reference.
* @throws IOException if the versioned reference is invalid (example: doesn't exist, or isn't a directory)
* @throws LayoutException
*/
public ArtifactReference getFirstArtifact(ManagedRepositoryContent managedRepository, VersionedReference reference) throws LayoutException, IOException {
String path = toPath(reference);
int idx = path.lastIndexOf('/');
if (idx > 0) {
path = path.substring(0, idx);
}
Path repoDir = Paths.get(managedRepository.getRepoRoot(), path);
if (!Files.exists(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-existant directory: " + repoDir.toAbsolutePath());
}
if (!Files.isDirectory(repoDir)) {
throw new IOException("Unable to gather the list of snapshot versions on a non-directory: " + repoDir.toAbsolutePath());
}
try (Stream<Path> stream = Files.list(repoDir)) {
String result = stream.filter(Files::isRegularFile).map(path1 -> PathUtil.getRelative(managedRepository.getRepoRoot(), path1)).filter(filetypes::matchesArtifactPattern).findFirst().orElse(null);
if (result != null) {
return managedRepository.toArtifactReference(result);
}
}
// No artifact was found.
return null;
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class ArchivaDavResourceFactory method fetchContentFromProxies.
private boolean fetchContentFromProxies(ManagedRepositoryContent managedRepository, DavServletRequest request, LogicalResource resource) throws DavException {
String path = resource.getPath();
if (repositoryRequest.isSupportFile(path)) {
Path proxiedFile = connectors.fetchFromProxies(managedRepository, path);
return (proxiedFile != null);
}
// Is it a Metadata resource?
if (repositoryRequest.isDefault(path) && repositoryRequest.isMetadata(path)) {
return connectors.fetchMetadataFromProxies(managedRepository, path).isModified();
}
// Is it an Archetype Catalog?
if (repositoryRequest.isArchetypeCatalog(path)) {
// FIXME we must implement a merge of remote archetype catalog from remote servers.
Path proxiedFile = connectors.fetchFromProxies(managedRepository, path);
return (proxiedFile != null);
}
// Not any of the above? Then it's gotta be an artifact reference.
try {
// Get the artifact reference in a layout neutral way.
ArtifactReference artifact = repositoryRequest.toArtifactReference(path);
if (artifact != null) {
String repositoryLayout = managedRepository.getRepository().getLayout();
RepositoryStorage repositoryStorage = this.applicationContext.getBean("repositoryStorage#" + repositoryLayout, RepositoryStorage.class);
repositoryStorage.applyServerSideRelocation(managedRepository, artifact);
Path proxiedFile = connectors.fetchFromProxies(managedRepository, artifact);
resource.setPath(managedRepository.toPath(artifact));
log.debug("Proxied artifact '{}:{}:{}'", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
return (proxiedFile != null);
}
} catch (LayoutException e) {
/* eat it */
} catch (ProxyDownloadException e) {
log.error(e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to fetch artifact resource.");
}
return false;
}
use of org.apache.archiva.repository.LayoutException in project archiva by apache.
the class ArchivaDavResourceFactory method processRepository.
private DavResource processRepository(final DavServletRequest request, ArchivaDavResourceLocator archivaLocator, String activePrincipal, ManagedRepositoryContent managedRepositoryContent, org.apache.archiva.repository.ManagedRepository managedRepository) throws DavException {
DavResource resource = null;
if (isAuthorized(request, managedRepositoryContent.getId())) {
boolean readMethod = WebdavMethodUtil.isReadMethod(request.getMethod());
// Maven Centric part ask evaluation if -SNAPSHOT
// MRM-1846 test if read method to prevent issue with maven 2.2.1 and uniqueVersion false
String path = readMethod ? evaluatePathWithVersion(archivaLocator, managedRepositoryContent, request.getContextPath()) : getLogicalResource(archivaLocator, managedRepository, false);
if (path.startsWith("/")) {
path = path.substring(1);
}
LogicalResource logicalResource = new LogicalResource(path);
Path resourceFile = Paths.get(managedRepositoryContent.getRepoRoot(), path);
resource = new ArchivaDavResource(resourceFile.toAbsolutePath().toString(), path, managedRepositoryContent.getRepository(), request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
if (WebdavMethodUtil.isReadMethod(request.getMethod())) {
if (archivaLocator.getHref(false).endsWith("/") && !Files.isDirectory(resourceFile)) {
// force a resource not found
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Resource does not exist");
} else {
if (!resource.isCollection()) {
boolean previouslyExisted = Files.exists(resourceFile);
boolean fromProxy = fetchContentFromProxies(managedRepositoryContent, request, logicalResource);
// legacy layout format.
try {
// Perform an adjustment of the resource to the managed
// repository expected path.
String localResourcePath = repositoryRequest.toNativePath(logicalResource.getPath(), managedRepositoryContent);
resourceFile = Paths.get(managedRepositoryContent.getRepoRoot(), localResourcePath);
resource = new ArchivaDavResource(resourceFile.toAbsolutePath().toString(), logicalResource.getPath(), managedRepositoryContent.getRepository(), request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
} catch (LayoutException e) {
if (!Files.exists(resourceFile)) {
throw new DavException(HttpServletResponse.SC_NOT_FOUND, e);
}
}
if (fromProxy) {
String action = (previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE) + PROXIED_SUFFIX;
log.debug("Proxied artifact '{}' in repository '{}' (current user '{}')", resourceFile.getFileName(), managedRepositoryContent.getId(), activePrincipal);
triggerAuditEvent(request.getRemoteAddr(), archivaLocator.getRepositoryId(), logicalResource.getPath(), action, activePrincipal);
}
if (!Files.exists(resourceFile)) {
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Resource does not exist");
}
}
}
}
if (request.getMethod().equals(HTTP_PUT_METHOD)) {
String resourcePath = logicalResource.getPath();
// we suppose that release-artifacts can be deployed only to repos enabled for releases
if (managedRepositoryContent.getRepository().getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE) && !repositoryRequest.isMetadata(resourcePath) && !repositoryRequest.isSupportFile(resourcePath)) {
ArtifactReference artifact = null;
try {
artifact = managedRepositoryContent.toArtifactReference(resourcePath);
if (!VersionUtil.isSnapshot(artifact.getVersion())) {
// check if artifact already exists and if artifact re-deployment to the repository is allowed
if (managedRepositoryContent.hasContent(artifact) && managedRepositoryContent.getRepository().blocksRedeployments()) {
log.warn("Overwriting released artifacts in repository '{}' is not allowed.", managedRepositoryContent.getId());
throw new DavException(HttpServletResponse.SC_CONFLICT, "Overwriting released artifacts is not allowed.");
}
}
} catch (LayoutException e) {
log.warn("Artifact path '{}' is invalid.", resourcePath);
}
}
/*
* Create parent directories that don't exist when writing a file This actually makes this
* implementation not compliant to the WebDAV RFC - but we have enough knowledge about how the
* collection is being used to do this reasonably and some versions of Maven's WebDAV don't correctly
* create the collections themselves.
*/
Path rootDirectory = Paths.get(managedRepositoryContent.getRepoRoot());
Path destDir = rootDirectory.resolve(logicalResource.getPath()).getParent();
if (!Files.exists(destDir)) {
try {
Files.createDirectories(destDir);
} catch (IOException e) {
log.error("Could not create directory {}: {}", destDir, e.getMessage(), e);
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not create directory " + destDir);
}
String relPath = PathUtil.getRelative(rootDirectory.toAbsolutePath().toString(), destDir);
log.debug("Creating destination directory '{}' (current user '{}')", destDir.getFileName(), activePrincipal);
triggerAuditEvent(request.getRemoteAddr(), managedRepositoryContent.getId(), relPath, AuditEvent.CREATE_DIR, activePrincipal);
}
}
}
return resource;
}
Aggregations