use of com.google.cloud.tools.opensource.classpath.ClassPathEntry in project cloud-opensource-java by GoogleCloudPlatform.
the class MaximumLinkageErrorsTest method hasLinkageProblemFromArtifactId.
private boolean hasLinkageProblemFromArtifactId(LinkageProblem problem, String artifactId) {
ClassPathEntry sourceClassPathEntry = problem.getSourceClass().getClassPathEntry();
Artifact sourceArtifact = sourceClassPathEntry.getArtifact();
return artifactId.equals(sourceArtifact.getArtifactId());
}
use of com.google.cloud.tools.opensource.classpath.ClassPathEntry in project java-cloud-bom by googleapis.
the class BomContentTest method findNoDowngradeViolation.
/**
* Returns messages describing the violation of the no-downgrade rule by {@code artifact} against
* the BOM containing {@code bomArtifacts}. An empty list if there is no violations.
*/
private static ImmutableList<String> findNoDowngradeViolation(Map<String, Artifact> bomArtifacts, Artifact artifact) throws InvalidVersionSpecificationException {
ImmutableList.Builder<String> violations = ImmutableList.builder();
ClassPathBuilder classPathBuilder = new ClassPathBuilder();
ClassPathResult result = classPathBuilder.resolve(ImmutableList.of(artifact), false, DependencyMediation.MAVEN);
for (ClassPathEntry entry : result.getClassPath()) {
Artifact transitiveDependency = entry.getArtifact();
String key = Artifacts.makeKey(transitiveDependency);
Artifact bomArtifact = bomArtifacts.get(key);
if (bomArtifact == null) {
// transitiveDependency is not part of the BOM
continue;
}
Version versionInBom = versionScheme.parseVersion(bomArtifact.getVersion());
Version versionInTransitiveDependency = versionScheme.parseVersion(transitiveDependency.getVersion());
if (versionInTransitiveDependency.compareTo(versionInBom) <= 0) {
// the no-downgrade rule.
continue;
}
// Filter by scopes that are invisible to library users
ImmutableList<DependencyPath> dependencyPaths = result.getDependencyPaths(entry);
Verify.verify(!dependencyPaths.isEmpty(), "The class path entry should have at least one dependency path from the root");
boolean dependencyVisibleToUsers = false;
for (DependencyPath dependencyPath : dependencyPaths) {
int length = dependencyPath.size();
// As the root element is an empty node, the last element is at "length - 2".
Dependency dependency = dependencyPath.getDependency(length - 2);
if (dependencyScopesVisibleToUsers.contains(dependency.getScope())) {
dependencyVisibleToUsers = true;
break;
}
}
if (!dependencyVisibleToUsers) {
// provided scope.
continue;
}
// A violation of the no-downgrade rule is found.
violations.add(artifact + " has a transitive dependency " + transitiveDependency + ". This is higher version than " + bomArtifact + " in the BOM. Example dependency path: " + dependencyPaths.get(0));
}
return violations.build();
}
Aggregations