use of org.commonjava.maven.atlas.ident.ref.ProjectRef 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.ProjectRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method removeDuplicateArtifacts.
private void removeDuplicateArtifacts(Map<ArtifactRef, String> mergedOverrides, Map<ArtifactRef, String> targetOverrides) {
Iterator<ArtifactRef> i = mergedOverrides.keySet().iterator();
while (i.hasNext()) {
ArtifactRef key = i.next();
ProjectRef pRef = key.asProjectRef();
for (ArtifactRef target : targetOverrides.keySet()) {
if (pRef.equals(target.asProjectRef())) {
logger.debug("From source overrides artifact {} clashes with target {}", key, target);
i.remove();
break;
}
}
}
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method applyExplicitOverrides.
/**
* Apply explicit overrides to a set of dependencies from a project. The explicit overrides come from
* dependencyExclusion. However they have to be separated out from standard overrides so we can easily
* ignore any property references (and overwrite them).
*
* @param project the current Project
* @param dependencies dependencies to check
* @param explicitOverrides a custom map to handle wildcard overrides
* @param state the CommonState, to retrieve Common Properties
* @param versionPropertyUpdateMap properties to update
* @throws ManipulationException if an error occurs
*/
private void applyExplicitOverrides(final Project project, final HashMap<ArtifactRef, Dependency> dependencies, final WildcardMap<String> explicitOverrides, final CommonState state, final Map<Project, Map<String, String>> versionPropertyUpdateMap) throws ManipulationException {
// Apply matching overrides to dependencies
for (final ProjectVersionRef dependency : dependencies.keySet()) {
final ProjectRef groupIdArtifactId = new SimpleProjectRef(dependency.getGroupId(), dependency.getArtifactId());
if (explicitOverrides.containsKey(groupIdArtifactId)) {
final String overrideVersion = explicitOverrides.get(groupIdArtifactId);
final String oldVersion = dependencies.get(dependency).getVersion();
if (isEmpty(overrideVersion) || isEmpty(oldVersion)) {
if (isEmpty(oldVersion)) {
logger.debug("Unable to force align as no existing version field to update for " + groupIdArtifactId + "; ignoring");
} else {
logger.warn("Unable to force align as override version is empty for " + groupIdArtifactId + "; ignoring");
}
} else {
for (String target : overrideVersion.split(",")) {
if (target.startsWith("+")) {
logger.info("Adding dependency exclusion {} to dependency {} ", target.substring(1), dependency);
Exclusion e = new Exclusion();
e.setGroupId(target.substring(1).split(":")[0]);
e.setArtifactId(target.split(":")[1]);
dependencies.get(dependency).addExclusion(e);
} else {
logger.info("Explicit overrides : force aligning {} to {}.", groupIdArtifactId, target);
if (!PropertiesUtils.cacheProperty(project, state, versionPropertyUpdateMap, oldVersion, target, dependency, true)) {
if (oldVersion.contains("${")) {
logger.warn("Overriding version with {} when old version contained a property {} ", target, oldVersion);
// TODO: Should this throw an exception?
}
// Not checking strict version alignment here as explicit overrides take priority.
dependencies.get(dependency).setVersion(target);
}
}
}
}
}
}
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method applyModuleVersionOverrides.
/**
* Remove module overrides which do not apply to the current module. Searches the full list of version overrides
* for any keys which contain the '@' symbol. Removes these from the version overrides list, and add them back
* without the '@' symbol only if they apply to the current module.
*
* @param projectGA the current project group : artifact
* @param originalOverrides The full list of version overrides, both global and module specific
* @param moduleOverrides are individual overrides e.g. group:artifact@groupId:artifactId :: value
* @param explicitOverrides a custom map to handle wildcard overrides
* @return The map of global and module specific overrides which apply to the given module
* @throws ManipulationException if an error occurs
*/
private Map<ArtifactRef, String> applyModuleVersionOverrides(final String projectGA, final Map<String, String> moduleOverrides, Map<ArtifactRef, String> originalOverrides, final WildcardMap explicitOverrides) throws ManipulationException {
final Map<ArtifactRef, String> remainingOverrides = new LinkedHashMap<>(originalOverrides);
logger.debug("Calculating module-specific version overrides. Starting with:\n {}", join(remainingOverrides.entrySet(), "\n "));
// These modes correspond to two different kinds of passes over the available override properties:
// 1. Module-specific: Don't process wildcard overrides here, allow module-specific settings to take precedence.
// 2. Wildcards: Add these IF there is no corresponding module-specific override.
final boolean[] wildcardMode = { false, true };
for (boolean aWildcardMode : wildcardMode) {
for (final String currentKey : new HashSet<>(moduleOverrides.keySet())) {
final String currentValue = moduleOverrides.get(currentKey);
logger.debug("Processing key {} for override with value {}", currentKey, currentValue);
if (!currentKey.contains("@")) {
logger.debug("Not an override. Skip.");
continue;
}
final boolean isModuleWildcard = currentKey.endsWith("@*");
logger.debug("Is wildcard? {} and in module wildcard mode? {} ", isModuleWildcard, aWildcardMode);
// process module-specific overrides (first)
if (!aWildcardMode) {
// skip wildcard overrides in this mode
if (isModuleWildcard) {
logger.debug("Not currently in wildcard mode. Skip.");
continue;
}
final String[] artifactAndModule = currentKey.split("@");
if (artifactAndModule.length != 2) {
throw new ManipulationException("Invalid format for exclusion key " + currentKey);
}
final String artifactGA = artifactAndModule[0];
final ProjectRef moduleGA = SimpleProjectRef.parse(artifactAndModule[1]);
logger.debug("For artifact override: {}, comparing parsed module: {} to current project: {}", artifactGA, moduleGA, projectGA);
if (moduleGA.toString().equals(projectGA) || (moduleGA.getArtifactId().equals("*") && SimpleProjectRef.parse(projectGA).getGroupId().equals(moduleGA.getGroupId()))) {
if (currentValue != null && !currentValue.isEmpty()) {
explicitOverrides.put(SimpleProjectRef.parse(artifactGA), currentValue);
logger.debug("Overriding module dependency for {} with {} : {}", moduleGA, artifactGA, currentValue);
} else {
// Override prevention...
removeGA(remainingOverrides, SimpleProjectRef.parse(artifactGA));
logger.debug("For module {}, ignoring dependency override for {} ", moduleGA, artifactGA);
}
}
} else // process wildcard overrides (second)
{
// skip module-specific overrides in this mode i.e. format of groupdId:artifactId@*=
if (!isModuleWildcard) {
logger.debug("Currently in wildcard mode. Skip.");
continue;
}
final String artifactGA = currentKey.substring(0, currentKey.length() - 2);
logger.debug("For artifact override: {}, checking if current overrides already contain a module-specific version.", artifactGA);
if (explicitOverrides.containsKey(SimpleProjectRef.parse(artifactGA))) {
logger.debug("For artifact override: {}, current overrides already contain a module-specific version. Skip.", artifactGA);
continue;
}
// I think this is only used for e.g. dependencyExclusion.groupId:artifactId@*=<explicitVersion>
if (currentValue != null && !currentValue.isEmpty()) {
logger.debug("Overriding module dependency for {} with {} : {}", projectGA, artifactGA, currentValue);
explicitOverrides.put(SimpleProjectRef.parse(artifactGA), currentValue);
} else {
// If we have a wildcard artifact we want to replace any prior explicit overrides
// with this one i.e. this takes precedence.
removeGA(remainingOverrides, SimpleProjectRef.parse(artifactGA));
logger.debug("Removing artifactGA " + artifactGA + " from overrides");
}
}
}
}
return remainingOverrides;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class PluginRemovalManipulator method apply.
private boolean apply(final Project project, final Model model) {
final PluginRemovalState state = session.getState(PluginRemovalState.class);
logger.debug("Applying plugin changes to: " + ga(project));
boolean result = false;
List<ProjectRef> pluginsToRemove = state.getPluginRemoval();
if (model.getBuild() != null) {
result = scanPlugins(pluginsToRemove, model.getBuild().getPlugins());
}
for (final Profile profile : ProfileUtils.getProfiles(session, model)) {
if (profile.getBuild() != null && scanPlugins(pluginsToRemove, profile.getBuild().getPlugins())) {
result = true;
}
}
return result;
}
Aggregations