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;
}
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));
}
}
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;
}
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;
}
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;
}
Aggregations