Search in sources :

Example 6 with RepositoryStorageRuntimeException

use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.

the class Maven2RepositoryStorage method listNamespaces.

@Override
public Collection<String> listNamespaces(String repoId, String namespace, Filter<String> filter) throws RepositoryStorageRuntimeException {
    Path dir = pathTranslator.toFile(getRepositoryBasedir(repoId), namespace);
    if (!(Files.exists(dir) && Files.isDirectory(dir))) {
        return Collections.emptyList();
    }
    // scan all the directories which are potential namespaces. Any directories known to be projects are excluded
    Predicate<Path> dFilter = new DirectoryFilter(filter);
    try (Stream<Path> stream = Files.list(dir)) {
        return stream.filter(dFilter).filter(path -> !isProject(path, filter)).map(path -> path.getFileName().toString()).sorted().collect(Collectors.toList());
    } catch (IOException e) {
        LOGGER.error("Could not read directory {}: {}", dir, e.getMessage(), e);
        return Collections.emptyList();
    }
}
Also used : Path(java.nio.file.Path) StringUtils(org.apache.commons.lang.StringUtils) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Date(java.util.Date) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) LoggerFactory(org.slf4j.LoggerFactory) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) XMLException(org.apache.archiva.xml.XMLException) RepositoryProblemFacet(org.apache.archiva.metadata.model.facets.RepositoryProblemFacet) ReleaseScheme(org.apache.archiva.repository.ReleaseScheme) NetworkProxyAdmin(org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin) ModelBuilder(org.apache.maven.model.building.ModelBuilder) PathParser(org.apache.archiva.repository.content.PathParser) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Path(java.nio.file.Path) ProxyConnectorAdmin(org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin) Try(org.apache.archiva.common.Try) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) Filter(org.apache.archiva.metadata.repository.filter.Filter) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) Scm(org.apache.maven.model.Scm) FileNotFoundException(java.io.FileNotFoundException) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Relocation(org.apache.maven.model.Relocation) Organization(org.apache.maven.model.Organization) List(java.util.List) DistributionManagement(org.apache.maven.model.DistributionManagement) Stream(java.util.stream.Stream) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) PostConstruct(javax.annotation.PostConstruct) ArtifactReference(org.apache.archiva.model.ArtifactReference) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) Model(org.apache.maven.model.Model) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) CiManagement(org.apache.maven.model.CiManagement) NetworkProxy(org.apache.archiva.admin.model.beans.NetworkProxy) RepositoryPathTranslator(org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator) RelocationException(org.apache.archiva.metadata.repository.storage.RelocationException) Dependency(org.apache.maven.model.Dependency) HashMap(java.util.HashMap) WagonFactory(org.apache.archiva.proxy.common.WagonFactory) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RemoteRepository(org.apache.archiva.repository.RemoteRepository) Charset(java.nio.charset.Charset) Service(org.springframework.stereotype.Service) ChecksumAlgorithm(org.apache.archiva.checksum.ChecksumAlgorithm) MavenMetadataReader(org.apache.archiva.maven2.metadata.MavenMetadataReader) Named(javax.inject.Named) LayoutException(org.apache.archiva.repository.LayoutException) IssueManagement(org.apache.maven.model.IssueManagement) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) SnapshotVersion(org.apache.archiva.model.SnapshotVersion) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) VersionUtil(org.apache.archiva.common.utils.VersionUtil) IOException(java.io.IOException) License(org.apache.maven.model.License) ApplicationContext(org.springframework.context.ApplicationContext) ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) ModelProblem(org.apache.maven.model.building.ModelProblem) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) Paths(java.nio.file.Paths) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) MailingList(org.apache.maven.model.MailingList) Collections(java.util.Collections) RepositoryStorage(org.apache.archiva.metadata.repository.storage.RepositoryStorage) ArrayUtils(org.apache.commons.lang.ArrayUtils) IOException(java.io.IOException)

Example 7 with RepositoryStorageRuntimeException

use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.

the class DefaultMetadataResolver method resolveProjectVersion.

@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    MetadataRepository metadataRepository = session.getRepository();
    ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
    // may then work here and be more efficient than always trying again)
    if (metadata == null || metadata.isIncomplete()) {
        try {
            ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
            metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
            log.debug("Resolved project version metadata from storage: {}", metadata);
            // eg. maven projects should be able to process parent here
            if (!metadata.getDependencies().isEmpty()) {
                ProjectVersionReference ref = new ProjectVersionReference();
                ref.setNamespace(namespace);
                ref.setProjectId(projectId);
                ref.setProjectVersion(projectVersion);
                ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
            }
            try {
                for (RepositoryListener listener : listeners) {
                    listener.addArtifact(session, repoId, namespace, projectId, metadata);
                }
                metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
            } catch (MetadataRepositoryException e) {
                log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
            }
            session.markDirty();
        } catch (RepositoryStorageMetadataInvalidException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
            throw new MetadataResolutionException(e.getMessage(), e);
        } catch (RepositoryStorageMetadataNotFoundException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
        // no need to rethrow - return null
        } catch (RepositoryStorageRuntimeException e) {
            for (RepositoryListener listener : listeners) {
                listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
            }
            throw new MetadataResolutionException(e.getMessage(), e);
        }
    }
    return metadata;
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)

Example 8 with RepositoryStorageRuntimeException

use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.

the class DefaultMetadataResolver method resolveProjects.

@Override
public Collection<String> resolveProjects(RepositorySession session, String repoId, String namespace) throws MetadataResolutionException {
    try {
        MetadataRepository metadataRepository = session.getRepository();
        Collection<String> projects = metadataRepository.getProjects(repoId, namespace);
        Collection<String> exclusions = new ArrayList<>(projects);
        String cacheKey = repoId + "-" + namespace;
        Collection<String> namespaces = namespacesCache.get(cacheKey);
        if (namespaces == null) {
            namespaces = metadataRepository.getNamespaces(repoId, namespace);
            namespacesCache.put(cacheKey, namespaces);
        }
        exclusions.addAll(namespaces);
        Collection<String> storageProjects = repositoryStorage.listProjects(repoId, namespace, new ExcludesFilter<>(exclusions));
        if (storageProjects != null && !storageProjects.isEmpty()) {
            log.debug("Resolved projects from storage: {}", storageProjects);
            for (String projectId : storageProjects) {
                ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata(repoId, namespace, projectId);
                if (projectMetadata != null) {
                    try {
                        metadataRepository.updateProject(repoId, projectMetadata);
                    } catch (MetadataRepositoryException e) {
                        log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
                    }
                }
            }
            session.markDirty();
            projects = new ArrayList<>(projects);
            projects.addAll(storageProjects);
        }
        return projects;
    } catch (RepositoryStorageRuntimeException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) ArrayList(java.util.ArrayList)

Example 9 with RepositoryStorageRuntimeException

use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.

the class DefaultMetadataResolver method resolveProjectVersions.

@Override
public Collection<String> resolveProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException {
    try {
        MetadataRepository metadataRepository = session.getRepository();
        Collection<String> projectVersions = metadataRepository.getProjectVersions(repoId, namespace, projectId);
        Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions(repoId, namespace, projectId, new ExcludesFilter<String>(projectVersions));
        if (storageProjectVersions != null && !storageProjectVersions.isEmpty()) {
            log.debug("Resolved project versions from storage: {}", storageProjectVersions);
            for (String projectVersion : storageProjectVersions) {
                try {
                    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion);
                    ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifact(session, repoId, namespace, projectId, versionMetadata);
                    }
                    metadataRepository.updateProjectVersion(repoId, namespace, projectId, versionMetadata);
                } catch (MetadataRepositoryException e) {
                    log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
                } catch (RepositoryStorageMetadataInvalidException e) {
                    log.warn("Not update project in metadata repository due to an error resolving it from storage: {}", e.getMessage());
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
                    }
                } catch (RepositoryStorageMetadataNotFoundException e) {
                    for (RepositoryListener listener : listeners) {
                        listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
                    }
                }
            }
            session.markDirty();
            projectVersions = new ArrayList<>(projectVersions);
            projectVersions.addAll(storageProjectVersions);
        }
        return projectVersions;
    } catch (RepositoryStorageRuntimeException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) RepositoryStorageMetadataInvalidException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException) RepositoryStorageMetadataNotFoundException(org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)

Example 10 with RepositoryStorageRuntimeException

use of org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed.

@Test
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed() throws Exception {
    testRepo.setSnapshots(false);
    configuration.save(c);
    repositoryRegistry.reload();
    assertFalse(c.getManagedRepositories().get(0).isSnapshots());
    copyTestArtifactWithParent("target/test-classes/com/example/test/test-snapshot-artifact-module-a", "target/test-repository/com/example/test/test-snapshot-artifact-module-a");
    try {
        ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a", "1.1-SNAPSHOT"));
        fail("Should not be found");
    } catch (RepositoryStorageRuntimeException e) {
    }
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-snapshot-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-snapshot-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : RepositoryStorageRuntimeException(org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

RepositoryStorageRuntimeException (org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException)10 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)8 ReadMetadataRequest (org.apache.archiva.metadata.repository.storage.ReadMetadataRequest)8 RepositoryStorageMetadataInvalidException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException)7 RepositoryStorageMetadataNotFoundException (org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException)7 ArrayList (java.util.ArrayList)6 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)5 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)5 FileNotFoundException (java.io.FileNotFoundException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 List (java.util.List)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)4 IOException (java.io.IOException)3 Reader (java.io.Reader)3 Charset (java.nio.charset.Charset)3 Files (java.nio.file.Files)3