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