use of org.commonjava.maven.atlas.ident.ref.ArtifactRef 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.ArtifactRef in project galley by Commonjava.
the class ArtifactBatch method setArtifactToResourceMapping.
public void setArtifactToResourceMapping(final Map<ArtifactRef, Resource> mappings) {
artifactMappings = new HashMap<>();
final Set<ConcreteResource> resources = new HashSet<>();
for (final Entry<ArtifactRef, Resource> entry : mappings.entrySet()) {
final ArtifactRef artifact = entry.getKey();
final Resource resource = entry.getValue();
if (resource instanceof ConcreteResource) {
artifactMappings.put(artifact, Collections.singletonList((ConcreteResource) resource));
resources.add((ConcreteResource) resource);
} else {
final List<ConcreteResource> res = ((VirtualResource) resource).toConcreteResources();
artifactMappings.put(artifact, res);
resources.addAll(res);
}
}
setResources(resources);
}
use of org.commonjava.maven.atlas.ident.ref.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class ModelIO method getRemoteDependencyVersionOverrides.
public Map<ArtifactRef, String> getRemoteDependencyVersionOverrides(final ProjectVersionRef ref) throws ManipulationException {
logger.debug("Resolving dependency management GAV: " + ref);
final Map<ArtifactRef, String> versionOverrides = new LinkedHashMap<>();
try {
final MavenPomView pomView = galleyWrapper.readPomView(ref);
// TODO: active profiles!
final List<DependencyView> deps = pomView.getAllManagedDependencies();
if (deps == null || deps.isEmpty()) {
logger.warn("Attempting to align to a BOM that does not have a dependencyManagement section");
} else {
for (final DependencyView dep : deps) {
versionOverrides.put(dep.asArtifactRef(), dep.getVersion());
logger.debug("Added version override for: " + dep.asProjectRef().toString() + ":" + dep.getVersion());
}
}
} catch (final GalleyMavenException e) {
throw new ManipulationException("Unable to resolve: %s", e, ref);
}
return versionOverrides;
}
use of org.commonjava.maven.atlas.ident.ref.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method loadRemoteOverrides.
/**
* This will load the remote overrides. It will first try to load any overrides that might have
* been prepopulated by the REST scanner, failing that it will load from a remote POM file.
*
* @return the loaded overrides
* @throws ManipulationException if an error occurs.
*/
private Map<ArtifactRef, String> loadRemoteOverrides() throws ManipulationException {
final DependencyState depState = session.getState(DependencyState.class);
final RESTState restState = session.getState(RESTState.class);
final List<ProjectVersionRef> gavs = depState.getRemoteBOMDepMgmt();
// While in theory we are only mapping ProjectRef -> NewVersion if we store key as ProjectRef we can't then have
// org.foo:foobar -> 1.2.0.redhat-2
// org.foo:foobar -> 2.0.0.redhat-2
// Which is useful for strictAlignment scenarios (although undefined for non-strict).
Map<ArtifactRef, String> restOverrides = depState.getRemoteRESTOverrides();
Map<ArtifactRef, String> bomOverrides = new LinkedHashMap<>();
Map<ArtifactRef, String> mergedOverrides = new LinkedHashMap<>();
if (gavs != null) {
final ListIterator<ProjectVersionRef> iter = gavs.listIterator(gavs.size());
// Iterate in reverse order so that the first GAV in the list overwrites the last
while (iter.hasPrevious()) {
final ProjectVersionRef ref = iter.previous();
Map<ArtifactRef, String> rBom = effectiveModelBuilder.getRemoteDependencyVersionOverrides(ref);
// We don't normalise the BOM list here as ::applyOverrides can handle multiple GA with different V
// for strict override. However, it is undefined if strict is not enabled.
bomOverrides.putAll(rBom);
}
}
if (depState.getPrecedence() == DependencyPrecedence.BOM) {
mergedOverrides = bomOverrides;
if (mergedOverrides.isEmpty()) {
String msg = restState.isEnabled() ? "dependencySource for restURL" : "dependencyManagement";
logger.warn("No dependencies found for dependencySource {}. Has {} been configured? ", depState.getPrecedence(), msg);
}
}
if (depState.getPrecedence() == DependencyPrecedence.REST) {
mergedOverrides = restOverrides;
if (mergedOverrides.isEmpty()) {
logger.warn("No dependencies found for dependencySource {}. Has restURL been configured? ", depState.getPrecedence());
}
} else if (depState.getPrecedence() == DependencyPrecedence.RESTBOM) {
mergedOverrides = bomOverrides;
removeDuplicateArtifacts(mergedOverrides, restOverrides);
mergedOverrides.putAll(restOverrides);
} else if (depState.getPrecedence() == DependencyPrecedence.BOMREST) {
mergedOverrides = restOverrides;
removeDuplicateArtifacts(mergedOverrides, bomOverrides);
mergedOverrides.putAll(bomOverrides);
}
logger.info("Remote precedence is {}", depState.getPrecedence());
logger.debug("Final remote override list is {}", mergedOverrides);
return mergedOverrides;
}
use of org.commonjava.maven.atlas.ident.ref.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method applyOverrides.
/**
* Apply a set of version overrides to a list of dependencies. Return a set of the overrides which were not applied.
*
* @param project The current Project
* @param dependencies The list of dependencies
* @param explicitOverrides Any explicitOverrides to track for ignoring
* @param overrides The map of dependency version overrides
* @return The map of overrides that were not matched in the dependencies
* @throws ManipulationException if an error occurs
*/
private Map<ArtifactRef, String> applyOverrides(final Project project, final HashMap<ArtifactRef, Dependency> dependencies, final WildcardMap<String> explicitOverrides, final Map<ArtifactRef, String> overrides) throws ManipulationException {
// Duplicate the override map so unused overrides can be easily recorded
final Map<ArtifactRef, String> unmatchedVersionOverrides = new LinkedHashMap<>();
unmatchedVersionOverrides.putAll(overrides);
if (dependencies == null || dependencies.size() == 0) {
return unmatchedVersionOverrides;
}
final CommonState commonState = session.getState(CommonState.class);
final boolean strict = commonState.getStrict();
// Apply matching overrides to dependencies
for (final ArtifactRef dependency : dependencies.keySet()) {
ProjectRef depPr = new SimpleProjectRef(dependency.getGroupId(), dependency.getArtifactId());
// will most likely happen is last-wins.
for (final Map.Entry<ArtifactRef, String> entry : overrides.entrySet()) {
ProjectRef groupIdArtifactId = entry.getKey().asProjectRef();
if (depPr.equals(groupIdArtifactId)) {
final String oldVersion = dependencies.get(dependency).getVersion();
final String overrideVersion = entry.getValue();
final String resolvedValue = dependency.getVersionString();
if (isEmpty(overrideVersion)) {
logger.warn("Unable to align with an empty override version for " + groupIdArtifactId + "; ignoring");
} else if (isEmpty(oldVersion)) {
logger.debug("Dependency is a managed version for " + groupIdArtifactId + "; ignoring");
} else // By avoiding the potential duplicate work it also avoids a possible property clash problem.
if (explicitOverrides.containsKey(depPr)) {
logger.debug("Dependency {} matches known explicit override so not performing initial override pass.", depPr);
unmatchedVersionOverrides.remove(entry.getKey());
} else // have immediate access to the original property so the closest that is feasible is verify strict matching.
if (strict && oldVersion.contains("$") && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
logger.debug("Original fully resolved version {} of {} does not match override version {} -> {} so ignoring", resolvedValue, dependency, entry.getKey(), overrideVersion);
if (commonState.getFailOnStrictViolation()) {
throw new ManipulationException("For {} replacing original property version {} (fully resolved: {} ) with new version {} for {} violates the strict version-alignment rule!", depPr.toString(), dependencies.get(dependency).getVersion(), resolvedValue, entry.getKey().getVersionString(), entry.getKey().asProjectRef().toString());
} else {
logger.warn("Replacing original property version {} with new version {} for {} violates the strict version-alignment rule!", resolvedValue, overrideVersion, dependencies.get(dependency).getVersion());
}
} else {
// Too much spurious logging with project.version.
if (!oldVersion.equals("${project.version}")) {
logger.info("Updating version {} for dependency {} from {}.", overrideVersion, dependency, project.getPom());
}
if (!PropertiesUtils.cacheProperty(project, commonState, versionPropertyUpdateMap, oldVersion, overrideVersion, entry.getKey(), false)) {
if (oldVersion.equals("${project.version}")) {
logger.debug("For dependency {} ; version is built in {} so skipping inlining {}", groupIdArtifactId, oldVersion, overrideVersion);
} else if (strict && !PropertiesUtils.checkStrictValue(session, resolvedValue, overrideVersion)) {
if (commonState.getFailOnStrictViolation()) {
throw new ManipulationException("Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!", oldVersion, groupIdArtifactId.toString(), overrideVersion);
} else {
logger.warn("Replacing original version {} in dependency {} with new version {} violates the strict version-alignment rule!", oldVersion, groupIdArtifactId, overrideVersion);
}
} else {
logger.debug("Altered dependency {} : {} -> {}", groupIdArtifactId, oldVersion, overrideVersion);
if (oldVersion.contains("${")) {
String suffix = PropertiesUtils.getSuffix(session);
String replaceVersion;
if (commonState.getStrictIgnoreSuffix() && oldVersion.contains(suffix)) {
replaceVersion = StringUtils.substringBefore(oldVersion, suffix);
replaceVersion += suffix + StringUtils.substringAfter(overrideVersion, suffix);
} else {
replaceVersion = oldVersion + StringUtils.removeStart(overrideVersion, resolvedValue);
}
logger.debug("Resolved value is {} and replacement version is {} ", resolvedValue, replaceVersion);
// In this case the previous value couldn't be cached even though it contained a property
// as it was either multiple properties or a property combined with a hardcoded value. Therefore
// just append the suffix.
dependencies.get(dependency).setVersion(replaceVersion);
} else {
dependencies.get(dependency).setVersion(overrideVersion);
}
}
}
unmatchedVersionOverrides.remove(entry.getKey());
}
}
}
}
return unmatchedVersionOverrides;
}
Aggregations