Search in sources :

Example 21 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.

the class FileMetadataRepository method getArtifactVersions.

@Override
public Collection<String> getArtifactVersions(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    try {
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        Set<String> versions = new HashSet<>();
        for (Map.Entry entry : properties.entrySet()) {
            String name = (String) entry.getKey();
            if (name.startsWith("artifact:version:")) {
                versions.add((String) entry.getValue());
            }
        }
        return versions;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 22 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.

the class FileMetadataRepository method getNamespaces.

@Override
public Collection<String> getNamespaces(String repoId, String baseNamespace) throws MetadataResolutionException {
    try {
        List<String> allNamespaces;
        Path directory = getDirectory(repoId);
        if (!(Files.exists(directory) && Files.isDirectory(directory))) {
            return Collections.emptyList();
        }
        final String searchFile = NAMESPACE_METADATA_KEY + ".properties";
        try (Stream<Path> fs = Files.list(directory)) {
            allNamespaces = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
        }
        Set<String> namespaces = new LinkedHashSet<>();
        int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
        for (String namespace : allNamespaces) {
            if (baseNamespace == null || namespace.startsWith(baseNamespace + ".")) {
                int i = namespace.indexOf('.', fromIndex);
                if (i >= 0) {
                    namespaces.add(namespace.substring(fromIndex, i));
                } else {
                    namespaces.add(namespace.substring(fromIndex));
                }
            }
        }
        return new ArrayList<>(namespaces);
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MailingList(org.apache.archiva.metadata.model.MailingList) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) StringTokenizer(java.util.StringTokenizer) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Organization(org.apache.archiva.metadata.model.Organization) Scm(org.apache.archiva.metadata.model.Scm) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) OutputStream(java.io.OutputStream) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) Logger(org.slf4j.Logger) Properties(java.util.Properties) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) CiManagement(org.apache.archiva.metadata.model.CiManagement) IOException(java.io.IOException) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) List(java.util.List) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) InputStream(java.io.InputStream) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Files(java.nio.file.Files) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 23 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.

the class FileMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    try {
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        String id = properties.getProperty("id");
        ProjectVersionMetadata versionMetadata = null;
        if (id != null) {
            versionMetadata = new ProjectVersionMetadata();
            versionMetadata.setId(id);
            versionMetadata.setName(properties.getProperty("name"));
            versionMetadata.setDescription(properties.getProperty("description"));
            versionMetadata.setUrl(properties.getProperty("url"));
            versionMetadata.setIncomplete(Boolean.valueOf(properties.getProperty("incomplete", "false")));
            String scmConnection = properties.getProperty("scm.connection");
            String scmDeveloperConnection = properties.getProperty("scm.developerConnection");
            String scmUrl = properties.getProperty("scm.url");
            if (scmConnection != null || scmDeveloperConnection != null || scmUrl != null) {
                Scm scm = new Scm();
                scm.setConnection(scmConnection);
                scm.setDeveloperConnection(scmDeveloperConnection);
                scm.setUrl(scmUrl);
                versionMetadata.setScm(scm);
            }
            String ciSystem = properties.getProperty("ci.system");
            String ciUrl = properties.getProperty("ci.url");
            if (ciSystem != null || ciUrl != null) {
                CiManagement ci = new CiManagement();
                ci.setSystem(ciSystem);
                ci.setUrl(ciUrl);
                versionMetadata.setCiManagement(ci);
            }
            String issueSystem = properties.getProperty("issue.system");
            String issueUrl = properties.getProperty("issue.url");
            if (issueSystem != null || issueUrl != null) {
                IssueManagement issueManagement = new IssueManagement();
                issueManagement.setSystem(issueSystem);
                issueManagement.setUrl(issueUrl);
                versionMetadata.setIssueManagement(issueManagement);
            }
            String orgName = properties.getProperty("org.name");
            String orgUrl = properties.getProperty("org.url");
            if (orgName != null || orgUrl != null) {
                Organization org = new Organization();
                org.setName(orgName);
                org.setUrl(orgUrl);
                versionMetadata.setOrganization(org);
            }
            boolean done = false;
            int i = 0;
            while (!done) {
                String licenseName = properties.getProperty("license." + i + ".name");
                String licenseUrl = properties.getProperty("license." + i + ".url");
                if (licenseName != null || licenseUrl != null) {
                    License license = new License();
                    license.setName(licenseName);
                    license.setUrl(licenseUrl);
                    versionMetadata.addLicense(license);
                } else {
                    done = true;
                }
                i++;
            }
            done = false;
            i = 0;
            while (!done) {
                String mailingListName = properties.getProperty("mailingList." + i + ".name");
                if (mailingListName != null) {
                    MailingList mailingList = new MailingList();
                    mailingList.setName(mailingListName);
                    mailingList.setMainArchiveUrl(properties.getProperty("mailingList." + i + ".archive"));
                    String p = properties.getProperty("mailingList." + i + ".otherArchives");
                    if (p != null && p.length() > 0) {
                        mailingList.setOtherArchives(Arrays.asList(p.split(",")));
                    } else {
                        mailingList.setOtherArchives(Collections.emptyList());
                    }
                    mailingList.setPostAddress(properties.getProperty("mailingList." + i + ".post"));
                    mailingList.setSubscribeAddress(properties.getProperty("mailingList." + i + ".subscribe"));
                    mailingList.setUnsubscribeAddress(properties.getProperty("mailingList." + i + ".unsubscribe"));
                    versionMetadata.addMailingList(mailingList);
                } else {
                    done = true;
                }
                i++;
            }
            done = false;
            i = 0;
            while (!done) {
                String dependencyArtifactId = properties.getProperty("dependency." + i + ".artifactId");
                if (dependencyArtifactId != null) {
                    Dependency dependency = new Dependency();
                    dependency.setArtifactId(dependencyArtifactId);
                    dependency.setGroupId(properties.getProperty("dependency." + i + ".groupId"));
                    dependency.setClassifier(properties.getProperty("dependency." + i + ".classifier"));
                    dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
                    dependency.setScope(properties.getProperty("dependency." + i + ".scope"));
                    dependency.setSystemPath(properties.getProperty("dependency." + i + ".systemPath"));
                    dependency.setType(properties.getProperty("dependency." + i + ".type"));
                    dependency.setVersion(properties.getProperty("dependency." + i + ".version"));
                    dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
                    versionMetadata.addDependency(dependency);
                } else {
                    done = true;
                }
                i++;
            }
            String facetIds = properties.getProperty("facetIds", "");
            if (facetIds.length() > 0) {
                for (String facetId : facetIds.split(",")) {
                    MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
                    if (factory == null) {
                        log.error("Attempted to load unknown project version metadata facet: {}", facetId);
                    } else {
                        MetadataFacet facet = factory.createMetadataFacet();
                        Map<String, String> map = new HashMap<>();
                        for (Object key : new ArrayList<>(properties.keySet())) {
                            String property = (String) key;
                            if (property.startsWith(facet.getFacetId())) {
                                map.put(property.substring(facet.getFacetId().length() + 1), properties.getProperty(property));
                            }
                        }
                        facet.fromProperties(map);
                        versionMetadata.addFacet(facet);
                    }
                }
            }
            updateProjectVersionFacets(versionMetadata, properties);
        }
        return versionMetadata;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) Dependency(org.apache.archiva.metadata.model.Dependency) IOException(java.io.IOException) Properties(java.util.Properties) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Example 24 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.

the class FileMetadataRepository method getProjectVersions.

@Override
public Collection<String> getProjectVersions(String repoId, String namespace, String projectId) throws MetadataResolutionException {
    try {
        List<String> projectVersions;
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId);
        if (!(Files.exists(directory) && Files.isDirectory(directory))) {
            return Collections.emptyList();
        }
        final String searchFile = PROJECT_VERSION_METADATA_KEY + ".properties";
        try (Stream<Path> fs = Files.list(directory)) {
            projectVersions = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
        }
        return projectVersions;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MailingList(org.apache.archiva.metadata.model.MailingList) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) StringTokenizer(java.util.StringTokenizer) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Organization(org.apache.archiva.metadata.model.Organization) Scm(org.apache.archiva.metadata.model.Scm) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) OutputStream(java.io.OutputStream) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) Logger(org.slf4j.Logger) Properties(java.util.Properties) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) CiManagement(org.apache.archiva.metadata.model.CiManagement) IOException(java.io.IOException) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) List(java.util.List) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) InputStream(java.io.InputStream) IOException(java.io.IOException) Files(java.nio.file.Files) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 25 with MetadataResolutionException

use of org.apache.archiva.metadata.repository.MetadataResolutionException in project archiva by apache.

the class JcrMetadataRepository method getProjectReferences.

@Override
public Collection<ProjectVersionReference> getProjectReferences(String repositoryId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    List<ProjectVersionReference> references = new ArrayList<>();
    // TODO: bind variables instead
    String q = "SELECT * FROM [archiva:dependency] WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content]) AND [groupId]='" + namespace + "' AND [artifactId]='" + projectId + "'";
    if (projectVersion != null) {
        q += " AND [version]='" + projectVersion + "'";
    }
    try {
        Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
        QueryResult result = query.execute();
        for (Node n : JcrUtils.getNodes(result)) {
            // dependencies grouping element
            n = n.getParent();
            // project version
            n = n.getParent();
            String usedByProjectVersion = n.getName();
            // project
            n = n.getParent();
            String usedByProject = n.getName();
            // namespace
            n = n.getParent();
            String usedByNamespace = n.getProperty("namespace").getString();
            ProjectVersionReference ref = new ProjectVersionReference();
            ref.setNamespace(usedByNamespace);
            ref.setProjectId(usedByProject);
            ref.setProjectVersion(usedByProjectVersion);
            ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
            references.add(ref);
        }
    } catch (RepositoryException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
    return references;
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Aggregations

MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)26 ArrayList (java.util.ArrayList)14 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)13 Path (java.nio.file.Path)10 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)8 LinkedHashSet (java.util.LinkedHashSet)7 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)7 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)7 Date (java.util.Date)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)6 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)6 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)6 ProjectVersionReference (org.apache.archiva.metadata.model.ProjectVersionReference)6 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)6 Map (java.util.Map)5