Search in sources :

Example 16 with MetadataResolutionException

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

the class DefaultBrowseService method getProjectVersionMetadata.

@Override
public ProjectVersionMetadata getProjectVersionMetadata(String groupId, String artifactId, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    RepositorySession repositorySession = null;
    try {
        Collection<String> projectVersions = getVersions(selectedRepos, groupId, artifactId);
        repositorySession = repositorySessionFactory.createSession();
        MetadataResolver metadataResolver = repositorySession.getResolver();
        ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
        MavenProjectFacet mavenFacet = new MavenProjectFacet();
        mavenFacet.setGroupId(groupId);
        mavenFacet.setArtifactId(artifactId);
        sharedModel.addFacet(mavenFacet);
        boolean isFirstVersion = true;
        for (String version : projectVersions) {
            ProjectVersionMetadata versionMetadata = null;
            for (String repoId : selectedRepos) {
                if (versionMetadata == null || versionMetadata.isIncomplete()) {
                    try {
                        ProjectVersionMetadata projectVersionMetadataResolved = null;
                        boolean useCache = !StringUtils.endsWith(version, VersionUtil.SNAPSHOT);
                        String cacheKey = null;
                        boolean cacheToUpdate = false;
                        // not a snapshot so get it from cache
                        if (useCache) {
                            cacheKey = repoId + groupId + artifactId + version;
                            projectVersionMetadataResolved = versionMetadataCache.get(cacheKey);
                        }
                        if (useCache && projectVersionMetadataResolved != null) {
                            versionMetadata = projectVersionMetadataResolved;
                        } else {
                            projectVersionMetadataResolved = metadataResolver.resolveProjectVersion(repositorySession, repoId, groupId, artifactId, version);
                            versionMetadata = projectVersionMetadataResolved;
                            cacheToUpdate = true;
                        }
                        if (useCache && cacheToUpdate) {
                            versionMetadataCache.put(cacheKey, projectVersionMetadataResolved);
                        }
                    } catch (MetadataResolutionException e) {
                        log.error("Skipping invalid metadata while compiling shared model for " + groupId + ":" + artifactId + " in repo " + repoId + ": " + e.getMessage());
                    }
                }
            }
            if (versionMetadata == null) {
                continue;
            }
            if (isFirstVersion) {
                sharedModel = versionMetadata;
                sharedModel.setId(null);
            } else {
                MavenProjectFacet versionMetadataMavenFacet = (MavenProjectFacet) versionMetadata.getFacet(MavenProjectFacet.FACET_ID);
                if (versionMetadataMavenFacet != null) {
                    if (// 
                    mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase(mavenFacet.getPackaging(), versionMetadataMavenFacet.getPackaging())) {
                        mavenFacet.setPackaging(null);
                    }
                }
                if (// 
                StringUtils.isEmpty(sharedModel.getName()) && !StringUtils.isEmpty(versionMetadata.getName())) {
                    sharedModel.setName(versionMetadata.getName());
                }
                if (// 
                sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase(sharedModel.getDescription(), versionMetadata.getDescription())) {
                    sharedModel.setDescription(StringUtils.isNotEmpty(versionMetadata.getDescription()) ? versionMetadata.getDescription() : "");
                }
                if (// 
                sharedModel.getIssueManagement() != null && // 
                versionMetadata.getIssueManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getIssueManagement().getUrl(), versionMetadata.getIssueManagement().getUrl())) {
                    sharedModel.setIssueManagement(versionMetadata.getIssueManagement());
                }
                if (// 
                sharedModel.getCiManagement() != null && // 
                versionMetadata.getCiManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getCiManagement().getUrl(), versionMetadata.getCiManagement().getUrl())) {
                    sharedModel.setCiManagement(versionMetadata.getCiManagement());
                }
                if (// 
                sharedModel.getOrganization() != null && // 
                versionMetadata.getOrganization() != null && !StringUtils.equalsIgnoreCase(sharedModel.getOrganization().getName(), versionMetadata.getOrganization().getName())) {
                    sharedModel.setOrganization(versionMetadata.getOrganization());
                }
                if (// 
                sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase(sharedModel.getUrl(), versionMetadata.getUrl())) {
                    sharedModel.setUrl(versionMetadata.getUrl());
                }
            }
            isFirstVersion = false;
        }
        return sharedModel;
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) MavenProjectFacet(org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 17 with MetadataResolutionException

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

the class DefaultBrowseService method getDependees.

@Override
public List<Artifact> getDependees(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<ProjectVersionReference> references = new ArrayList<>();
    // TODO: what if we get duplicates across repositories?
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataResolver metadataResolver = repositorySession.getResolver();
        for (String repoId : getObservableRepos()) {
            // TODO: what about if we want to see this irrespective of version?
            references.addAll(metadataResolver.resolveProjectReferences(repositorySession, repoId, groupId, artifactId, version));
        }
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    List<Artifact> artifacts = new ArrayList<>(references.size());
    for (ProjectVersionReference projectVersionReference : references) {
        artifacts.add(new Artifact(projectVersionReference.getNamespace(), projectVersionReference.getProjectId(), projectVersionReference.getProjectVersion()));
    }
    return artifacts;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact)

Example 18 with MetadataResolutionException

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

the class DefaultBrowseService method getProjectMetadata.

@Override
public ProjectVersionMetadata getProjectMetadata(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    RepositorySession repositorySession = null;
    try {
        repositorySession = repositorySessionFactory.createSession();
        MetadataResolver metadataResolver = repositorySession.getResolver();
        ProjectVersionMetadata versionMetadata = null;
        for (String repoId : selectedRepos) {
            if (versionMetadata == null || versionMetadata.isIncomplete()) {
                try {
                    ProjectVersionMetadata versionMetadataTmp = metadataResolver.resolveProjectVersion(repositorySession, repoId, groupId, artifactId, version);
                    if (versionMetadata == null && versionMetadataTmp != null) {
                        versionMetadata = versionMetadataTmp;
                    }
                } catch (MetadataResolutionException e) {
                    log.warn("Skipping invalid metadata while compiling shared model for {}:{} in repo {}: {}", groupId, artifactId, repoId, e.getMessage());
                }
            }
        }
        return versionMetadata;
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 19 with MetadataResolutionException

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

the class DefaultBrowseService method getArtifactDownloadInfos.

@Override
public List<Artifact> getArtifactDownloadInfos(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    List<Artifact> artifactDownloadInfos = new ArrayList<>();
    try (RepositorySession session = repositorySessionFactory.createSession()) {
        MetadataResolver metadataResolver = session.getResolver();
        for (String repoId : selectedRepos) {
            List<ArtifactMetadata> artifacts = new ArrayList<>(metadataResolver.resolveArtifacts(session, repoId, groupId, artifactId, version));
            Collections.sort(artifacts, ArtifactMetadataVersionComparator.INSTANCE);
            if (artifacts != null && !artifacts.isEmpty()) {
                return buildArtifacts(artifacts, repoId);
            }
        }
    } catch (MetadataResolutionException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    return artifactDownloadInfos;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 20 with MetadataResolutionException

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

the class CassandraMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repositoryId, String namespaceId, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
    try {
        Namespace namespace = getNamespace(repositoryId, namespaceId);
        if (namespace == null) {
            updateOrAddNamespace(repositoryId, namespaceId);
        }
        if (getProject(repositoryId, namespaceId, projectId) == null) {
            ProjectMetadata projectMetadata = new ProjectMetadata();
            projectMetadata.setNamespace(namespaceId);
            projectMetadata.setId(projectId);
            updateProject(repositoryId, projectMetadata);
        }
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    versionMetadata.getId()).execute();
    ProjectVersionMetadataModel projectVersionMetadataModel = null;
    boolean creation = true;
    if (result.get().getCount() > 0) {
        projectVersionMetadataModel = mapProjectVersionMetadataModel(result.get().getList().get(0).getColumnSlice());
        creation = false;
    } else {
        projectVersionMetadataModel = getModelMapper().map(versionMetadata, ProjectVersionMetadataModel.class);
    }
    projectVersionMetadataModel.setProjectId(projectId);
    projectVersionMetadataModel.setNamespace(new Namespace(namespaceId, new Repository(repositoryId)));
    projectVersionMetadataModel.setCiManagement(versionMetadata.getCiManagement());
    projectVersionMetadataModel.setIssueManagement(versionMetadata.getIssueManagement());
    projectVersionMetadataModel.setOrganization(versionMetadata.getOrganization());
    projectVersionMetadataModel.setScm(versionMetadata.getScm());
    projectVersionMetadataModel.setMailingLists(versionMetadata.getMailingLists());
    projectVersionMetadataModel.setDependencies(versionMetadata.getDependencies());
    projectVersionMetadataModel.setLicenses(versionMetadata.getLicenses());
    // we don't test of repository and namespace really exist !
    String key = // 
    new ProjectVersionMetadataModel.KeyBuilder().withRepository(// 
    repositoryId).withNamespace(// 
    namespaceId).withProjectId(// 
    projectId).withProjectVersion(// 
    versionMetadata.getVersion()).withId(// 
    versionMetadata.getId()).build();
    // FIXME nested objects to store!!!
    if (creation) {
        String cf = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
        Mutator<String> mutator = projectVersionMetadataTemplate.createMutator().addInsertion(key, cf, // 
        column(PROJECT_ID.toString(), projectId)).addInsertion(key, cf, // 
        column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        column(NAMESPACE_ID.toString(), namespaceId)).addInsertion(key, cf, // 
        column(PROJECT_VERSION.toString(), versionMetadata.getVersion()));
        addInsertion(mutator, key, cf, DESCRIPTION.toString(), versionMetadata.getDescription());
        addInsertion(mutator, key, cf, NAME.toString(), versionMetadata.getName());
        addInsertion(mutator, key, cf, "incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addInsertion(mutator, key, cf, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addInsertion(mutator, key, cf, "ciManagement.system", ci.getSystem());
                addInsertion(mutator, key, cf, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addInsertion(mutator, key, cf, "issueManagement.system", issueManagement.getSystem());
                addInsertion(mutator, key, cf, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addInsertion(mutator, key, cf, "organization.name", organization.getName());
                addInsertion(mutator, key, cf, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addInsertion(mutator, key, cf, "scm.url", scm.getUrl());
                addInsertion(mutator, key, cf, "scm.connection", scm.getConnection());
                addInsertion(mutator, key, cf, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        recordMailingList(key, versionMetadata.getMailingLists());
        recordLicenses(key, versionMetadata.getLicenses());
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        MutationResult mutationResult = mutator.execute();
    } else {
        ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater(key);
        addUpdateStringValue(updater, PROJECT_ID.toString(), projectId);
        addUpdateStringValue(updater, REPOSITORY_NAME.toString(), repositoryId);
        addUpdateStringValue(updater, NAMESPACE_ID.toString(), namespaceId);
        addUpdateStringValue(updater, PROJECT_VERSION.toString(), versionMetadata.getVersion());
        addUpdateStringValue(updater, DESCRIPTION.toString(), versionMetadata.getDescription());
        addUpdateStringValue(updater, NAME.toString(), versionMetadata.getName());
        updater.setString("incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addUpdateStringValue(updater, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addUpdateStringValue(updater, "ciManagement.system", ci.getSystem());
                addUpdateStringValue(updater, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addUpdateStringValue(updater, "issueManagement.system", issueManagement.getSystem());
                addUpdateStringValue(updater, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addUpdateStringValue(updater, "organization.name", organization.getName());
                addUpdateStringValue(updater, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addUpdateStringValue(updater, "scm.url", scm.getUrl());
                addUpdateStringValue(updater, "scm.connection", scm.getConnection());
                addUpdateStringValue(updater, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        // update is a delete record
        removeMailingList(key);
        recordMailingList(key, versionMetadata.getMailingLists());
        removeLicenses(key);
        recordLicenses(key, versionMetadata.getLicenses());
        removeDependencies(key);
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        projectVersionMetadataTemplate.update(updater);
    }
    ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
    artifactMetadataModel.setRepositoryId(repositoryId);
    artifactMetadataModel.setNamespace(namespaceId);
    artifactMetadataModel.setProject(projectId);
    artifactMetadataModel.setProjectVersion(versionMetadata.getVersion());
    artifactMetadataModel.setVersion(versionMetadata.getVersion());
    updateFacets(versionMetadata, artifactMetadataModel);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) Organization(org.apache.archiva.metadata.model.Organization) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) MutationResult(me.prettyprint.hector.api.mutation.MutationResult)

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