Search in sources :

Example 21 with ProjectVersionRef

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

the class MavenPomReader method getDocRef.

private DocRef<ProjectVersionRef> getDocRef(final ProjectVersionRef ref, final Transfer pom, final boolean cache, final EventMetadata eventMetadata) throws GalleyMavenException, TransferException {
    DocRef<ProjectVersionRef> dr = getFirstCached(ref, Collections.singletonList(pom.getLocation()));
    if (dr == null) {
        final Document doc = xml.parse(pom, eventMetadata);
        dr = new DocRef<ProjectVersionRef>(ref, pom.getLocation(), doc);
    }
    if (cache) {
        cache(dr);
    }
    return dr;
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document)

Example 22 with ProjectVersionRef

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

the class MavenPomReader method assembleImportedInformation.

private void assembleImportedInformation(final MavenPomView view, final List<? extends Location> locations) throws GalleyMavenException {
    final List<DependencyView> md = view.getAllBOMs();
    for (final DependencyView dv : md) {
        final ProjectVersionRef ref = dv.asProjectVersionRef();
        logger.debug("Found BOM: {} for: {}", ref, view.getRef());
        // This is a BOM, it's likely to be used in multiple locations...cache this.
        final MavenPomView imp = read(ref, locations, true);
        view.addMixin(new MavenXmlMixin<ProjectVersionRef>(imp, MavenXmlMixin.DEPENDENCY_MIXIN));
    }
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) DependencyView(org.commonjava.maven.galley.maven.model.view.DependencyView) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 23 with ProjectVersionRef

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

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final Transfer pom, final List<? extends Location> locations, final EventMetadata eventMetadata, final String... activeProfileLocations) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, pom, false, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, ref, stack.size(), ref, e.getMessage());
    }
    stack.add(dr);
    ProjectVersionRef next = xml.getParentRef(dr.getDoc());
    while (next != null && dr != null) {
        try {
            dr = getDocRef(next, locations, false, eventMetadata);
        } catch (final TransferException e) {
            throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, next, stack.size(), ref, e.getMessage());
        }
        if (dr == null) {
            throw new GalleyMavenException("Cannot resolve {}, {} levels dep in the ancestry stack of: {}", next, stack.size(), ref);
        }
        stack.add(dr);
        next = xml.getParentRef(dr.getDoc());
    }
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileLocations);
    assembleImportedInformation(view, locations);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 24 with ProjectVersionRef

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

the class MavenPomView method resolveXPathToElementView.

/**
     * RAW ACCESS: Retrieve a {@link MavenPomElementView} instance for the first element matching the given
     * XPath expression and within the other given parameters. If none is found, return null.
     *
     * @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
     */
public MavenPomElementView resolveXPathToElementView(final String path, final boolean cachePath, final int maxDepth) throws GalleyMavenRuntimeException {
    int maxAncestry = maxDepth;
    for (final String pathPrefix : localOnlyPaths) {
        if (path.startsWith(pathPrefix)) {
            maxAncestry = 0;
            break;
        }
    }
    int ancestryDepth = 0;
    Element n = null;
    for (final DocRef<ProjectVersionRef> dr : stack) {
        if (maxAncestry > -1 && ancestryDepth > maxAncestry) {
            break;
        }
        final MavenPomView oldView = ResolveFunctions.getPomView();
        try {
            ResolveFunctions.setPomView(this);
            n = (Element) dr.getDocContext().selectSingleNode(path);
        } finally {
            ResolveFunctions.setPomView(oldView);
        }
        if (n != null) {
            break;
        }
        ancestryDepth++;
    }
    if (n != null) {
        return new MavenPomElementView(this, n, new OriginInfo(ancestryDepth != 0));
    }
    MavenPomElementView result = null;
    for (final MavenXmlMixin<ProjectVersionRef> mixin : mixins) {
        if (mixin.matches(path)) {
            final MavenPomView mixinView = (MavenPomView) mixin.getMixin();
            result = mixinView.resolveXPathToElementView(path, true, maxAncestry);
        //                        logger.info( "Value of '{}' in mixin: {} is: '{}'", path, mixin );
        }
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Element(org.w3c.dom.Element)

Example 25 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)

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