Search in sources :

Example 26 with ProjectVersionRef

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

the class MavenPomView method resolveXPathToAggregatedElementViewList.

/**
     * RAW ACCESS: Retrieve an ordered list of {@link MavenPomElementView} instances matching the given XPath
     * expression and within the other given parameters.
     *
     * @param path The XPath expression to resolve
     * @param cachePath Whether to cache the compiled XPath instance. Do this if the expression isn't overly
     *   specific, and will be used multiple times.
     * @param maxDepth If a large ancestry (parents of parents of...) exists, limit the search to the given
     *   depth
     * @param includeMixins Whether to include mix-ins (eg. BOMs) when searching for matches
     */
public synchronized List<MavenPomElementView> resolveXPathToAggregatedElementViewList(final String path, final boolean cachePath, final int maxDepth, final boolean includeMixins) throws GalleyMavenRuntimeException {
    int maxAncestry = maxDepth;
    for (final String pathPrefix : localOnlyPaths) {
        if (path.startsWith(pathPrefix)) {
            maxAncestry = 0;
            break;
        }
    }
    int ancestryDepth = 0;
    final List<MavenPomElementView> result = new ArrayList<MavenPomElementView>();
    for (final DocRef<ProjectVersionRef> dr : stack) {
        if (maxAncestry > -1 && ancestryDepth > maxAncestry) {
            break;
        }
        final List<Node> nodes = getLocalNodeList(dr.getDocContext(), path);
        if (nodes != null) {
            for (final Node node : nodes) {
                result.add(new MavenPomElementView(this, (Element) node, new OriginInfo(ancestryDepth != 0)));
            }
        }
        ancestryDepth++;
    }
    if (includeMixins) {
        for (final MavenXmlMixin<ProjectVersionRef> mixin : mixins) {
            if (!mixin.matches(path)) {
                continue;
            }
            final MavenPomView mixinView = (MavenPomView) mixin.getMixin();
            final List<MavenPomElementView> nodes = mixinView.resolveXPathToAggregatedElementViewList(path, cachePath, maxAncestry, includeMixins);
            if (nodes != null) {
                for (final MavenPomElementView node : nodes) {
                    node.getOriginInfo().setMixin(true);
                    result.add(node);
                }
            }
        }
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)

Example 27 with ProjectVersionRef

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

Example 28 with ProjectVersionRef

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

the class MavenModelProcessor method addExtensionUsages.

private void addExtensionUsages(final URI source, final Builder builder, final MavenPomView pomView, final ProjectVersionRef projectRef) throws GalleyMavenException {
    List<ExtensionView> extensions = null;
    try {
        extensions = pomView.getBuildExtensions();
    } catch (final GalleyMavenException e) {
        logger.error(String.format("%s: Cannot retrieve build extensions: %s", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidVersionSpecificationException e) {
        logger.error(String.format("%s: Cannot retrieve build extensions: %s", pomView.getRef(), e.getMessage()), e);
    } catch (final InvalidRefException e) {
        logger.error(String.format("%s: Cannot retrieve build extensions: %s", pomView.getRef(), e.getMessage()), e);
    }
    for (final ExtensionView ext : extensions) {
        if (ext == null) {
            continue;
        }
        try {
            final ProjectVersionRef ref = ext.asProjectVersionRef();
            // force the InvalidVersionSpecificationException.
            ref.getVersionSpec();
            builder.withExtensions(new SimpleExtensionRelationship(source, projectRef, ref, builder.getNextExtensionIndex(), ext.getOriginInfo().isInherited()));
        } catch (final InvalidRefException e) {
            logger.error(String.format("%s: Build extension is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), ext.toXML()), e);
        } catch (final InvalidVersionSpecificationException e) {
            logger.error(String.format("%s: Build extension is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), ext.toXML()), e);
        } catch (final GalleyMavenException e) {
            logger.error(String.format("%s: Build extension is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), ext.toXML()), e);
        }
    }
}
Also used : 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) SimpleExtensionRelationship(org.commonjava.maven.atlas.graph.rel.SimpleExtensionRelationship) ExtensionView(org.commonjava.maven.galley.maven.model.view.ExtensionView)

Example 29 with ProjectVersionRef

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

the class MavenModelProcessor method addPlugins.

private void addPlugins(final List<PluginView> plugins, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
    if (plugins != null) {
        for (final PluginView plugin : plugins) {
            ProjectVersionRef pluginRef = null;
            try {
                if (plugin.getVersion() == null) {
                    logger.error("%s: Cannot find a version for plugin: {}. Skipping.", projectRef, plugin.toXML());
                    continue;
                }
                pluginRef = plugin.asProjectVersionRef();
                // force the InvalidVersionSpecificationException.
                pluginRef.getVersionSpec();
                final String profileId = plugin.getProfileId();
                final URI location = RelationshipUtils.profileLocation(profileId);
                boolean inherited = plugin.getOriginInfo().isInherited();
                boolean mixin = plugin.getOriginInfo().isMixin();
                builder.withPlugins(new SimplePluginRelationship(source, location, projectRef, pluginRef, builder.getNextPluginDependencyIndex(projectRef, managed, inherited), managed, inherited));
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
                continue;
            }
            List<PluginDependencyView> pluginDependencies = null;
            Set<PluginDependencyView> impliedPluginDependencies = null;
            try {
                pluginDependencies = plugin.getLocalPluginDependencies();
                impliedPluginDependencies = plugin.getImpliedPluginDependencies();
            } catch (final GalleyMavenException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            } catch (final InvalidVersionSpecificationException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            } catch (final InvalidRefException e) {
                logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
            }
            addPluginDependencies(pluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
            logger.debug("{}: Adding implied dependencies for: {}\n\n  {}", projectRef, pluginRef, impliedPluginDependencies == null ? "-NONE-" : new JoinString("\n  ", impliedPluginDependencies));
            addPluginDependencies(impliedPluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
        }
    }
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) SimplePluginRelationship(org.commonjava.maven.atlas.graph.rel.SimplePluginRelationship) InvalidRefException(org.commonjava.maven.atlas.ident.ref.InvalidRefException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) URI(java.net.URI) PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView)

Example 30 with ProjectVersionRef

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

the class MavenModelProcessor method readRelationships.

public EProjectDirectRelationships readRelationships(final MavenPomView pomView, final URI source, final ModelProcessorConfig discoveryConfig) throws GalleyMavenException {
    final boolean includeManagedDependencies = discoveryConfig.isIncludeManagedDependencies();
    final boolean includeBuildSection = discoveryConfig.isIncludeBuildSection();
    final boolean includeManagedPlugins = discoveryConfig.isIncludeManagedPlugins();
    logger.info("Reading relationships for: {}\n  (from: {})", pomView.getRef(), source);
    try {
        final ProjectVersionRef projectRef = pomView.getRef();
        final EProjectDirectRelationships.Builder builder = new EProjectDirectRelationships.Builder(source, projectRef);
        addParentRelationship(source, builder, pomView, projectRef);
        addDependencyRelationships(source, builder, pomView, projectRef, includeManagedDependencies);
        if (includeBuildSection) {
            addExtensionUsages(source, builder, pomView, projectRef);
            addPluginUsages(source, builder, pomView, projectRef, includeManagedPlugins);
        }
        return builder.build();
    } catch (final InvalidVersionSpecificationException e) {
        throw new GalleyMavenException("Failed to parse version for model: {}. Reason: {}", e, pomView, e.getMessage());
    } catch (final IllegalArgumentException e) {
        throw new GalleyMavenException("Failed to parse relationships for model: {}. Reason: {}", e, pomView, e.getMessage());
    }
}
Also used : Builder(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships.Builder) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Builder(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships.Builder) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)

Aggregations

ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)42 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)22 Test (org.junit.Test)22 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)11 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)10 URI (java.net.URI)9 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)9 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)9 Transfer (org.commonjava.maven.galley.model.Transfer)9 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)8 PomPeek (org.commonjava.maven.galley.maven.parse.PomPeek)8 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)6 Document (org.w3c.dom.Document)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)5 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)5 PluginDependencyView (org.commonjava.maven.galley.maven.model.view.PluginDependencyView)5