Search in sources :

Example 1 with SimpleArtifactRef

use of org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef in project galley by Commonjava.

the class MavenModelProcessor method addPluginDependencies.

private void addPluginDependencies(final Collection<PluginDependencyView> pluginDependencies, final PluginView plugin, final ProjectVersionRef pluginRef, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (pluginDependencies != null) {
        for (final PluginDependencyView dep : pluginDependencies) {
            try {
                final ProjectVersionRef ref = dep.asProjectVersionRef();
                final String profileId = dep.getProfileId();
                final URI location = RelationshipUtils.profileLocation(profileId);
                final ArtifactRef artifactRef = new SimpleArtifactRef(ref, dep.getType(), dep.getClassifier());
                // force the InvalidVersionSpecificationException.
                artifactRef.getVersionSpec();
                boolean inherited = dep.getOriginInfo().isInherited();
                boolean mixin = dep.getOriginInfo().isMixin();
                builder.withPluginDependencies(new SimplePluginDependencyRelationship(source, location, projectRef, pluginRef, artifactRef, builder.getNextPluginDependencyIndex(pluginRef, managed, inherited), managed, inherited));
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: plugin dependency is invalid in: %s! Reason: %s. Skipping:\n\n%s\n\n", projectRef, pluginRef, e.getMessage(), dep.toXML()), e);
            }
        }
    }
}
Also used : PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) SimplePluginDependencyRelationship(org.commonjava.maven.atlas.graph.rel.SimplePluginDependencyRelationship) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) URI(java.net.URI) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)

Example 2 with SimpleArtifactRef

use of org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef 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)

Example 3 with SimpleArtifactRef

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

the class GroovyManipulator method parseGroovyScripts.

/**
 * Splits the value on ',', then wraps each value in {@link SimpleArtifactRef#parse(String)} and prints a warning / skips in the event of a
 * parsing error. Returns null if the input value is null.
 * @param value a comma separated list of GAVTC to parse
 * @return a collection of parsed ArtifactRef.
 */
public List<File> parseGroovyScripts(final String value) throws ManipulationException {
    if (isEmpty(value)) {
        return Collections.emptyList();
    } else {
        final List<File> result = new ArrayList<>();
        logger.debug("Processing groovy scripts {} ", value);
        try {
            final String[] scripts = value.split(",");
            for (final String script : scripts) {
                File found;
                if (script.startsWith("http")) {
                    logger.info("Attempting to read URL {} ", script);
                    found = fileIO.resolveURL(new URL(script));
                } else {
                    final ArtifactRef ar = SimpleArtifactRef.parse(script);
                    logger.info("Attempting to read GAV {} with classifier {} and type {} ", ar.asProjectVersionRef(), ar.getClassifier(), ar.getType());
                    found = modelBuilder.resolveRawFile(ar);
                }
                result.add(found);
            }
        } catch (IOException e) {
            throw new ManipulationException("Unable to parse groovyScripts", e);
        }
        return result;
    }
}
Also used : ArrayList(java.util.ArrayList) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)

Example 4 with SimpleArtifactRef

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

the class Project method resolveDeps.

private void resolveDeps(MavenSessionHandler session, List<Dependency> deps, boolean includeManagedDependencies, HashMap<ArtifactRef, Dependency> resolvedDependencies) throws ManipulationException {
    ListIterator<Dependency> iterator = deps.listIterator(deps.size());
    // Iterate in reverse order so later deps take precedence
    while (iterator.hasPrevious()) {
        Dependency d = iterator.previous();
        String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(d.getGroupId()) ? getGroupId() : d.getGroupId());
        String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(d.getArtifactId()) ? getArtifactId() : d.getArtifactId());
        String v = PropertyResolver.resolveInheritedProperties(session, this, d.getVersion());
        if (includeManagedDependencies && isEmpty(v)) {
            v = "*";
        }
        if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) {
            SimpleArtifactRef sar = new SimpleArtifactRef(g, a, v, d.getType(), d.getClassifier());
            // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate.
            if (resolvedDependencies.containsKey(sar)) {
                logger.error("Found duplicate entry within dependency list. Key of {} and dependency {}", sar, d);
                iterator.remove();
            } else {
                Dependency old = resolvedDependencies.put(sar, d);
                if (old != null) {
                    logger.error("Internal project dependency resolution failure ; replaced {} in store by {}:{}:{}.", old, g, a, v);
                    throw new ManipulationException("Internal project dependency resolution failure ; replaced " + old + " by " + d);
                }
            }
        }
    }
}
Also used : SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) Dependency(org.apache.maven.model.Dependency)

Example 5 with SimpleArtifactRef

use of org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef in project galley by Commonjava.

the class MavenModelProcessor method addDependencies.

private void addDependencies(final List<DependencyView> deps, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (deps != null) {
        for (final DependencyView dep : deps) {
            try {
                final ProjectVersionRef ref = dep.asProjectVersionRef();
                final String profileId = dep.getProfileId();
                final URI location = RelationshipUtils.profileLocation(profileId);
                final ArtifactRef artifactRef = new SimpleArtifactRef(ref, dep.getType(), dep.getClassifier());
                // force the InvalidVersionSpecificationException.
                artifactRef.getVersionSpec();
                Set<ProjectRefView> exclusionsView = dep.getExclusions();
                ProjectRef[] excludes;
                if (exclusionsView != null && !exclusionsView.isEmpty()) {
                    excludes = new ProjectRef[exclusionsView.size()];
                    int i = 0;
                    for (ProjectRefView exclusionView : exclusionsView) {
                        excludes[i] = exclusionView.asProjectRef();
                        i++;
                    }
                } else {
                    excludes = new ProjectRef[0];
                }
                builder.withDependencies(new SimpleDependencyRelationship(source, location, projectRef, artifactRef, dep.getScope(), builder.getNextDependencyIndex(managed), managed, dep.getOriginInfo().isInherited(), dep.isOptional(), excludes));
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
            }
        }
    }
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectRefView(org.commonjava.maven.galley.maven.model.view.ProjectRefView) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) URI(java.net.URI) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleDependencyRelationship(org.commonjava.maven.atlas.graph.rel.SimpleDependencyRelationship) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef)

Aggregations

SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)5 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)4 URI (java.net.URI)2 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)2 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)2 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)2 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)2 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)2 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Dependency (org.apache.maven.model.Dependency)1 Profile (org.apache.maven.model.Profile)1 SimpleDependencyRelationship (org.commonjava.maven.atlas.graph.rel.SimpleDependencyRelationship)1 SimplePluginDependencyRelationship (org.commonjava.maven.atlas.graph.rel.SimplePluginDependencyRelationship)1