Search in sources :

Example 1 with MetadataResolutionException

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

the class FileMetadataRepository method getProjects.

@Override
public Collection<String> getProjects(String repoId, String namespace) throws MetadataResolutionException {
    try {
        List<String> projects;
        Path directory = getDirectory(repoId).resolve(namespace);
        if (!(Files.exists(directory) && Files.isDirectory(directory))) {
            return Collections.emptyList();
        }
        final String searchFile = PROJECT_METADATA_KEY + ".properties";
        try (Stream<Path> fs = Files.list(directory)) {
            projects = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> path.getFileName().toString()).collect(Collectors.toList());
        }
        return projects;
    } 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 2 with MetadataResolutionException

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

the class FileMetadataRepository method getProject.

@Override
public ProjectMetadata getProject(String repoId, String namespace, String projectId) throws MetadataResolutionException {
    try {
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId);
        Properties properties = readOrCreateProperties(directory, PROJECT_METADATA_KEY);
        ProjectMetadata project = null;
        String id = properties.getProperty("id");
        if (id != null) {
            project = new ProjectMetadata();
            project.setNamespace(properties.getProperty("namespace"));
            project.setId(id);
        }
        return project;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) IOException(java.io.IOException) Properties(java.util.Properties) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 3 with MetadataResolutionException

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

the class FileMetadataRepository method getProjectReferences.

@Override
public Collection<ProjectVersionReference> getProjectReferences(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);
        int numberOfRefs = Integer.parseInt(properties.getProperty("ref:lastReferenceNum", "-1")) + 1;
        List<ProjectVersionReference> references = new ArrayList<>();
        for (int i = 0; i < numberOfRefs; i++) {
            ProjectVersionReference reference = new ProjectVersionReference();
            reference.setProjectId(properties.getProperty("ref:reference." + i + ".projectId"));
            reference.setNamespace(properties.getProperty("ref:reference." + i + ".namespace"));
            reference.setProjectVersion(properties.getProperty("ref:reference." + i + ".projectVersion"));
            reference.setReferenceType(ProjectVersionReference.ReferenceType.valueOf(properties.getProperty("ref:reference." + i + ".referenceType")));
            references.add(reference);
        }
        return references;
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 4 with MetadataResolutionException

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

the class FileMetadataRepository method getArtifacts.

@Override
public Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
    try {
        Map<String, ArtifactMetadata> artifacts = new HashMap<>();
        Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        for (Map.Entry entry : properties.entrySet()) {
            String name = (String) entry.getKey();
            StringTokenizer tok = new StringTokenizer(name, ":");
            if (tok.hasMoreTokens() && "artifact".equals(tok.nextToken())) {
                String field = tok.nextToken();
                String id = tok.nextToken();
                ArtifactMetadata artifact = artifacts.get(id);
                if (artifact == null) {
                    artifact = new ArtifactMetadata();
                    artifact.setRepositoryId(repoId);
                    artifact.setNamespace(namespace);
                    artifact.setProject(projectId);
                    artifact.setProjectVersion(projectVersion);
                    artifact.setVersion(projectVersion);
                    artifact.setId(id);
                    artifacts.put(id, artifact);
                }
                String value = (String) entry.getValue();
                if ("updated".equals(field)) {
                    artifact.setFileLastModified(Long.parseLong(value));
                } else if ("size".equals(field)) {
                    artifact.setSize(Long.valueOf(value));
                } else if ("whenGathered".equals(field)) {
                    artifact.setWhenGathered(new Date(Long.parseLong(value)));
                } else if ("version".equals(field)) {
                    artifact.setVersion(value);
                } else if ("md5".equals(field)) {
                    artifact.setMd5(value);
                } else if ("sha1".equals(field)) {
                    artifact.setSha1(value);
                } else if ("facetIds".equals(field)) {
                    if (value.length() > 0) {
                        String propertyPrefix = "artifact:facet:" + id + ":";
                        for (String facetId : value.split(",")) {
                            MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
                            if (factory == null) {
                                log.error("Attempted to load unknown artifact metadata facet: {}", facetId);
                            } else {
                                MetadataFacet facet = factory.createMetadataFacet();
                                String prefix = propertyPrefix + facet.getFacetId();
                                Map<String, String> map = new HashMap<>();
                                for (Object key : new ArrayList<>(properties.keySet())) {
                                    String property = (String) key;
                                    if (property.startsWith(prefix)) {
                                        map.put(property.substring(prefix.length() + 1), properties.getProperty(property));
                                    }
                                }
                                facet.fromProperties(map);
                                artifact.addFacet(facet);
                            }
                        }
                    }
                    updateArtifactFacets(artifact, properties);
                }
            }
        }
        return artifacts.values();
    } catch (IOException e) {
        throw new MetadataResolutionException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) StringTokenizer(java.util.StringTokenizer) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MetadataResolutionException

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

the class FileMetadataRepository method getArtifactsByDateRange.

@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
    try {
        // TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
        // of this information (eg. in Lucene, as before)
        List<ArtifactMetadata> artifacts = new ArrayList<>();
        for (String ns : getRootNamespaces(repoId)) {
            getArtifactsByDateRange(artifacts, repoId, ns, startTime, endTime);
        }
        artifacts.sort(new ArtifactComparator());
        return artifacts;
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) 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