use of org.commonjava.maven.atlas.ident.ref.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class DependencyManipulator method removeReactorGAs.
/**
* Remove version overrides which refer to projects in the current reactor.
* Projects in the reactor include things like inter-module dependencies
* which should never be overridden.
* @param versionOverrides current set of ArtifactRef:newVersion overrides.
* @return A new Map with the reactor GAs removed.
*/
private Map<ArtifactRef, String> removeReactorGAs(final Map<ArtifactRef, String> versionOverrides) throws ManipulationException {
final Map<ArtifactRef, String> reducedVersionOverrides = new LinkedHashMap<>(versionOverrides);
for (final Project project : session.getProjects()) {
final String reactorGA = gav(project.getModel());
reducedVersionOverrides.remove(SimpleArtifactRef.parse(reactorGA));
}
return reducedVersionOverrides;
}
use of org.commonjava.maven.atlas.ident.ref.ArtifactRef 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.ArtifactRef 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.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class RESTCollector method collect.
/**
* Prescans the Project to build up a list of Project GAs and also the various Dependencies.
*/
private void collect(final List<Project> projects) throws ManipulationException {
final RESTState state = session.getState(RESTState.class);
final VersioningState vs = session.getState(VersioningState.class);
final DependencyState ds = session.getState(DependencyState.class);
final PluginState ps = session.getState(PluginState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return;
}
final ArrayList<ProjectVersionRef> restParam = new ArrayList<>();
final ArrayList<ProjectVersionRef> newProjectKeys = new ArrayList<>();
final String override = vs.getOverride();
for (final Project project : projects) {
if (isEmpty(override)) {
// TODO: Check this : For the rest API I think we need to check every project GA not just inheritance root.
// Strip SNAPSHOT from the version for matching. DA will handle OSGi conversion.
ProjectVersionRef newKey = new SimpleProjectVersionRef(project.getKey());
if (project.getKey().getVersionString().endsWith("-SNAPSHOT")) {
if (!vs.preserveSnapshot()) {
newKey = new SimpleProjectVersionRef(project.getKey().asProjectRef(), project.getKey().getVersionString().substring(0, project.getKey().getVersionString().indexOf("-SNAPSHOT")));
} else {
logger.warn("SNAPSHOT detected for REST call but preserve-snapshots is enabled.");
}
}
newProjectKeys.add(newKey);
} else if (project.isExecutionRoot()) {
// We want to manually override the version ; therefore ignore what is in the project and calculate potential
// matches for that instead.
Project p = projects.get(0);
newProjectKeys.add(new SimpleProjectVersionRef(p.getGroupId(), p.getArtifactId(), override));
}
}
restParam.addAll(newProjectKeys);
// We only recognise dependencyManagement of the form g:a:version-rebuild not g:a:version-rebuild-<numeric>.
for (ProjectVersionRef bom : (ds.getRemoteBOMDepMgmt() == null ? Collections.<ProjectVersionRef>emptyList() : ds.getRemoteBOMDepMgmt())) {
if (!Version.hasBuildNumber(bom.getVersionString()) && bom.getVersionString().contains(PropertiesUtils.getSuffix(session))) {
// Create the dummy PVR to send to DA (which requires a numeric suffix).
ProjectVersionRef newBom = new SimpleProjectVersionRef(bom.asProjectRef(), bom.getVersionString() + "-0");
logger.debug("Adding dependencyManagement BOM {} into REST call.", newBom);
restParam.add(newBom);
}
}
Set<ArtifactRef> localDeps = establishAllDependencies(session, projects, null);
// Need to send that to the rest interface to get a translation.
for (ArtifactRef p : localDeps) {
restParam.add(p.asProjectVersionRef());
}
// Call the REST to populate the result.
logger.debug("Passing {} GAVs following into the REST client api {} ", restParam.size(), restParam);
logger.info("Calling REST client...");
long start = System.nanoTime();
Map<ProjectVersionRef, String> restResult = null;
try {
restResult = state.getVersionTranslator().translateVersions(restParam);
} finally {
printFinishTime(start, (restResult != null));
}
logger.debug("REST Client returned {} ", restResult);
// Process rest result for boms
ListIterator<ProjectVersionRef> iterator = (ds.getRemoteBOMDepMgmt() == null ? Collections.<ProjectVersionRef>emptyList().listIterator() : ds.getRemoteBOMDepMgmt().listIterator());
while (iterator.hasNext()) {
ProjectVersionRef pvr = iterator.next();
// As before, only process the BOMs if they are of the format <rebuild suffix> without a numeric portion.
if (!Version.hasBuildNumber(pvr.getVersionString()) && pvr.getVersionString().contains(PropertiesUtils.getSuffix(session))) {
// Create the dummy PVR to compare with results to...
ProjectVersionRef newBom = new SimpleProjectVersionRef(pvr.asProjectRef(), pvr.getVersionString() + "-0");
if (restResult.keySet().contains(newBom)) {
ProjectVersionRef replacementBOM = new SimpleProjectVersionRef(pvr.asProjectRef(), restResult.get(newBom));
logger.debug("Replacing BOM value of {} with {}.", pvr, replacementBOM);
iterator.remove();
iterator.add(replacementBOM);
}
}
}
vs.setRESTMetadata(parseVersions(session, projects, state, newProjectKeys, restResult));
final Map<ArtifactRef, String> overrides = new HashMap<>();
// Convert the loaded remote ProjectVersionRefs to the original ArtifactRefs
for (ArtifactRef a : localDeps) {
if (restResult.containsKey(a.asProjectVersionRef())) {
overrides.put(a, restResult.get(a.asProjectVersionRef()));
}
}
logger.debug("Setting REST Overrides {} ", overrides);
ds.setRemoteRESTOverrides(overrides);
// Unfortunately as everything is just GAVs we have to send everything to the PluginManipulator as well.
ps.setRemoteRESTOverrides(overrides);
}
use of org.commonjava.maven.atlas.ident.ref.ArtifactRef in project pom-manipulation-ext by release-engineering.
the class ResolveArtifactTest method testResolveArtifacts.
@Test
public void testResolveArtifacts() throws Exception {
final ManipulationSession session = new ManipulationSession();
// Locate the PME project pom file.
final File projectroot = new File(TestUtils.resolveFileResource("properties/", "").getParentFile().getParentFile().getParentFile().getParentFile(), "pom.xml");
PomIO pomIO = new PomIO();
List<Project> projects = pomIO.parseProject(projectroot);
Set<ArtifactRef> artifacts = RESTCollector.establishAllDependencies(session, projects, null);
// NB If this test fails then check if PME deps/plugins have changed...
assertTrue(artifacts.size() == 59);
}
Aggregations