use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class WildcardMapTest method testGet.
@Test
public void testGet() throws Exception {
final String value = "1.2";
ProjectRef key1 = SimpleProjectRef.parse("org.group:new-artifact");
ProjectRef key2 = SimpleProjectRef.parse("org.group:new-new-artifact");
map.put(key1, value);
map.put(key2, value);
assertTrue(value.equals(map.get(key1)));
assertTrue(value.equals(map.get(key2)));
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef 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;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class RESTCollector method parseVersions.
/**
* Parse the rest result for the project GAs and store them in versioning state for use
* there by incremental suffix calculation.
*/
private Map<ProjectRef, Set<String>> parseVersions(ManipulationSession session, List<Project> projects, RESTState state, ArrayList<ProjectVersionRef> newProjectKeys, Map<ProjectVersionRef, String> restResult) throws ManipulationException {
Map<ProjectRef, Set<String>> versionStates = new HashMap<>();
for (final ProjectVersionRef p : newProjectKeys) {
if (restResult.containsKey(p)) {
// Found part of the current project to store in Versioning State
Set<String> versions = versionStates.get(p.asProjectRef());
if (versions == null) {
versions = new HashSet<>();
versionStates.put(p.asProjectRef(), versions);
}
versions.add(restResult.get(p));
}
}
logger.debug("Added the following ProjectRef:Version from REST call into VersionState {}", versionStates);
// We know we have ProjectVersionRef(s) of the current project(s). We need to establish potential
// blacklist by calling
// GET /listings/blacklist/ga?groupid=GROUP_ID&artifactid=ARTIFACT_ID
// passing in the groupId and artifactId.
// From the results we then need to establish whether the community version occurs in the blacklist
// causing a total abort and whether any redhat versions occur in the blacklist. If they do, that will
// affect the incremental potential options. The simplest option is simply to add those results to versionStates
// list. This will cause the incremental build number to be set to greater than those.
List<ProjectVersionRef> blacklist;
for (Project p : projects) {
if (p.isExecutionRoot()) {
logger.debug("Calling REST client for blacklist with {}...", p.getKey().asProjectRef());
blacklist = state.getVersionTranslator().findBlacklisted(p.getKey().asProjectRef());
if (blacklist.size() > 0) {
String suffix = PropertiesUtils.getSuffix(session);
String bVersion = blacklist.get(0).getVersionString();
String pVersion = p.getVersion();
logger.debug("REST Client returned for blacklist {} ", blacklist);
if (isEmpty(suffix)) {
logger.warn("No version suffix found ; unable to verify community blacklisting.");
} else if (blacklist.size() == 1 && !bVersion.contains(suffix)) {
if (pVersion.contains(suffix)) {
pVersion = pVersion.substring(0, pVersion.indexOf(suffix) - 1);
}
if (pVersion.equals(bVersion)) {
throw new ManipulationException("community artifact '" + blacklist.get(0) + "' has been blacklisted. Unable to build project version " + p.getVersion());
}
}
// Found part of the current project to store in Versioning State
Set<String> versions = versionStates.get(p.getKey().asProjectRef());
if (versions == null) {
versions = new HashSet<>();
versionStates.put(p.getKey().asProjectRef(), versions);
}
for (ProjectVersionRef b : blacklist) {
versions.add(b.getVersionString());
}
}
break;
}
}
return versionStates;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class VersioningCalculatorTest method setupSession.
private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
session = new ManipulationSession();
session.setMavenSession(mavenSession);
final VersioningState state = new VersioningState(properties);
session.setState(state);
final Map<String, byte[]> dataMap = new HashMap<>();
if (versionMap != null && !versionMap.isEmpty()) {
for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
final String path = toMetadataPath(entry.getKey());
final byte[] data = setupMetadataVersions(entry.getValue());
dataMap.put(path, data);
}
}
final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
final Transport mdTrans = new StubTransport(dataMap);
modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
return state;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class IdUtils method parseGAs.
/**
* Splits the value on ',', then wraps each value in {@link SimpleProjectRef#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 GA to parse
* @return a collection of parsed ProjectRef.
*/
public static List<ProjectRef> parseGAs(final String value) {
if (isEmpty(value)) {
return null;
} else {
final String[] gavs = value.split(",");
final List<ProjectRef> refs = new ArrayList<>();
for (final String gav : gavs) {
try {
final ProjectRef ref = SimpleProjectRef.parse(gav);
refs.add(ref);
} catch (final InvalidRefException e) {
logger.error("Skipping invalid remote management GAV: " + gav);
throw e;
}
}
return refs;
}
}
Aggregations