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