Search in sources :

Example 1 with SimpleTypeAndClassifier

use of org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier in project pom-manipulation-ext by release-engineering.

the class RESTCollector method recordDependencies.

/**
 * Translate a given set of pvr:dependencies into ArtifactRefs.
 * @param session the ManipulationSession
 * @param project currently scanned project
 * @param deps Set of ArtifactRef to store the results in.
 * @param dependencies dependencies to examine
 */
private static void recordDependencies(ManipulationSession session, Project project, Set<ArtifactRef> deps, HashMap<ArtifactRef, Dependency> dependencies) throws ManipulationException {
    if (dependencies == null) {
        return;
    }
    for (ArtifactRef pvr : dependencies.keySet()) {
        Dependency d = dependencies.get(pvr);
        deps.add(new SimpleScopedArtifactRef(pvr, new SimpleTypeAndClassifier(d.getType(), d.getClassifier()), isEmpty(d.getScope()) ? DependencyScope.compile.realName() : PropertyResolver.resolveInheritedProperties(session, project, d.getScope())));
    }
}
Also used : SimpleScopedArtifactRef(org.commonjava.maven.ext.common.model.SimpleScopedArtifactRef) SimpleTypeAndClassifier(org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier) Dependency(org.apache.maven.model.Dependency) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleScopedArtifactRef(org.commonjava.maven.ext.common.model.SimpleScopedArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)

Example 2 with SimpleTypeAndClassifier

use of org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier in project pom-manipulation-ext by release-engineering.

the class RESTCollector method establishAllDependencies.

/**
 * Scans a list of projects and accumulates all dependencies and returns them.
 *
 * @param session the ManipulationSession
 * @param projects the projects to scan.
 * @param activeProfiles which profiles to check
 * @return an unsorted set of ArtifactRefs used.
 * @throws ManipulationException if an error occurs
 */
public static Set<ArtifactRef> establishAllDependencies(ManipulationSession session, final List<Project> projects, Set<String> activeProfiles) throws ManipulationException {
    Set<ArtifactRef> localDeps = new TreeSet<>();
    Set<String> activeModules = new HashSet<>();
    boolean scanAll = false;
    if (activeProfiles != null && !activeProfiles.isEmpty()) {
        for (final Project project : projects) {
            if (project.isInheritanceRoot()) {
                activeModules.addAll(project.getModel().getModules());
                List<Profile> profiles = project.getModel().getProfiles();
                if (profiles != null) {
                    for (Profile p : profiles) {
                        if (activeProfiles.contains(p.getId())) {
                            logger.debug("Adding modules for profile {}", p.getId());
                            activeModules.addAll(p.getModules());
                        }
                    }
                }
            }
        }
        logger.debug("Found {} active modules with {} active profiles.", activeModules, activeProfiles);
    } else {
        scanAll = true;
    }
    // Iterate over current project set and populate list of dependencies
    for (final Project project : projects) {
        if (project.isInheritanceRoot() || scanAll || activeModules.contains(project.getPom().getParentFile().getName())) {
            if (project.getModelParent() != null) {
                SimpleProjectVersionRef parent = new SimpleProjectVersionRef(project.getModelParent().getGroupId(), project.getModelParent().getArtifactId(), project.getModelParent().getVersion());
                localDeps.add(new SimpleArtifactRef(parent, new SimpleTypeAndClassifier("pom", null)));
            }
            recordDependencies(session, project, localDeps, project.getResolvedManagedDependencies(session));
            recordDependencies(session, project, localDeps, project.getResolvedDependencies(session));
            recordPlugins(localDeps, project.getResolvedManagedPlugins(session));
            recordPlugins(localDeps, project.getResolvedPlugins(session));
            List<Profile> profiles = project.getModel().getProfiles();
            if (profiles != null) {
                for (Profile p : profiles) {
                    if (!scanAll && !activeProfiles.contains(p.getId())) {
                        continue;
                    }
                    recordDependencies(session, project, localDeps, project.getResolvedProfileManagedDependencies(session).get(p));
                    recordDependencies(session, project, localDeps, project.getResolvedProfileDependencies(session).get(p));
                    recordPlugins(localDeps, project.getResolvedProfileManagedPlugins(session).get(p));
                    recordPlugins(localDeps, project.getResolvedProfilePlugins(session).get(p));
                }
            }
        }
    }
    return localDeps;
}
Also used : SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleScopedArtifactRef(org.commonjava.maven.ext.common.model.SimpleScopedArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) Project(org.commonjava.maven.ext.common.model.Project) TreeSet(java.util.TreeSet) SimpleTypeAndClassifier(org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier) HashSet(java.util.HashSet)

Aggregations

ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)2 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)2 SimpleTypeAndClassifier (org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier)2 SimpleScopedArtifactRef (org.commonjava.maven.ext.common.model.SimpleScopedArtifactRef)2 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Dependency (org.apache.maven.model.Dependency)1 Profile (org.apache.maven.model.Profile)1 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)1 Project (org.commonjava.maven.ext.common.model.Project)1