use of com.google.cloud.tools.opensource.dependencies.Bom in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageCheckerTest method testBomResolutionWithMissingTransitiveDependency.
@Test
public void testBomResolutionWithMissingTransitiveDependency() throws Exception {
DefaultArtifact cglib = new DefaultArtifact("cglib:cglib-nodep:jar:2.2");
// cglib-nodep has 2 transitive dependencies, which do not exist in Maven Central
// cglib:cglib-nodep:jar:2.2
// - ant:ant:jar:1.6.2 (compile?)
// - xml-apis:xml-apis:jar:2.6.2 (compile?)
// - xerces:xerces-impl:jar:2.6.2 (compile?)
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/2097
Bom bomWithMissingTransitiveDependency = new Bom("com.google.cloud:bom-with-missing-transitive-dependency:0.1", ImmutableList.of(cglib));
try {
LinkageChecker.create(bomWithMissingTransitiveDependency);
fail("Linkage Checker should throw IOException");
} catch (IOException expected) {
assertEquals("Could not resolve 2 dependencies. See the message above for details.", expected.getMessage());
}
}
use of com.google.cloud.tools.opensource.dependencies.Bom in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageMonitor method copyWithSnapshot.
/**
* Returns a copy of {@code bom} replacing its managed dependencies that have locally-installed
* snapshot versions.
*/
@VisibleForTesting
static Bom copyWithSnapshot(RepositorySystem repositorySystem, RepositorySystemSession session, Bom bom, Map<String, String> localArtifacts) throws ModelBuildingException, ArtifactResolutionException {
ImmutableList.Builder<Artifact> managedDependencies = ImmutableList.builder();
Model model = buildModelWithSnapshotBom(repositorySystem, session, bom.getCoordinates(), localArtifacts);
ArtifactTypeRegistry registry = session.getArtifactTypeRegistry();
ImmutableList<Artifact> newManagedDependencies = model.getDependencyManagement().getDependencies().stream().map(dependency -> RepositoryUtils.toDependency(dependency, registry)).map(Dependency::getArtifact).collect(toImmutableList());
for (Artifact managedDependency : newManagedDependencies) {
if (Bom.shouldSkipBomMember(managedDependency)) {
continue;
}
String version = localArtifacts.getOrDefault(managedDependency.getGroupId() + ":" + managedDependency.getArtifactId(), managedDependency.getVersion());
managedDependencies.add(managedDependency.setVersion(version));
}
// "-SNAPSHOT" suffix for coordinate to distinguish easily.
return new Bom(bom.getCoordinates() + "-SNAPSHOT", managedDependencies.build());
}
use of com.google.cloud.tools.opensource.dependencies.Bom in project cloud-opensource-java by GoogleCloudPlatform.
the class MaximumLinkageErrorsTest method testForNewLinkageErrors.
@Test
public void testForNewLinkageErrors() throws IOException, MavenRepositoryException, RepositoryException {
// Not using RepositoryUtility.findLatestCoordinates, which may return a snapshot version
String version = findLatestNonSnapshotVersion();
String baselineCoordinates = "com.google.cloud:libraries-bom:" + version;
Bom baseline = Bom.readBom(baselineCoordinates);
Path bomFile = Paths.get("../cloud-oss-bom/pom.xml");
Bom bom = Bom.readBom(bomFile);
ImmutableSet<LinkageProblem> oldProblems = LinkageChecker.create(baseline).findLinkageProblems();
LinkageChecker checker = LinkageChecker.create(bom);
ImmutableSet<LinkageProblem> currentProblems = checker.findLinkageProblems();
// This only tests for newly missing methods, not new invocations of
// previously missing methods.
Set<LinkageProblem> newProblems = Sets.difference(currentProblems, oldProblems);
// Appengine-api-1.0-sdk is known to contain linkage errors because it shades dependencies
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/441
newProblems = newProblems.stream().filter(problem -> !hasLinkageProblemFromArtifactId(problem, "appengine-api-1.0-sdk")).collect(Collectors.toSet());
// Check that no new linkage errors have been introduced since the baseline
StringBuilder message = new StringBuilder("Baseline BOM: " + baselineCoordinates + "\n");
if (!newProblems.isEmpty()) {
message.append("Newly introduced problems:\n");
message.append(LinkageProblem.formatLinkageProblems(newProblems, null));
Assert.fail(message.toString());
}
}
use of com.google.cloud.tools.opensource.dependencies.Bom in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageMonitor method run.
/**
* Returns new problems in the BOM specified by {@code groupId} and {@code artifactId}. This
* method compares the latest release of the BOM and its snapshot version which uses artifacts in
* {@link #localArtifacts}.
*/
private ImmutableSet<LinkageProblem> run(String groupId, String artifactId) throws RepositoryException, IOException, MavenRepositoryException, ModelBuildingException {
String latestBomCoordinates = RepositoryUtility.findLatestCoordinates(repositorySystem, groupId, artifactId);
logger.info("BOM Coordinates: " + latestBomCoordinates);
Bom baseline = Bom.readBom(latestBomCoordinates);
ImmutableSet<LinkageProblem> problemsInBaseline = LinkageChecker.create(baseline, null).findLinkageProblems();
Bom snapshot = copyWithSnapshot(repositorySystem, session, baseline, localArtifacts);
// Comparing coordinates because DefaultArtifact does not override equals
ImmutableList<String> baselineCoordinates = coordinatesList(baseline.getManagedDependencies());
ImmutableList<String> snapshotCoordinates = coordinatesList(snapshot.getManagedDependencies());
if (baselineCoordinates.equals(snapshotCoordinates)) {
logger.info("Snapshot is same as baseline. Not running comparison.");
logger.info("Baseline coordinates: " + Joiner.on(";").join(baselineCoordinates));
return ImmutableSet.of();
}
ImmutableList<Artifact> snapshotManagedDependencies = snapshot.getManagedDependencies();
ClassPathResult classPathResult = (new ClassPathBuilder()).resolve(snapshotManagedDependencies, true, DependencyMediation.MAVEN);
ImmutableList<ClassPathEntry> classpath = classPathResult.getClassPath();
List<ClassPathEntry> entryPointJars = classpath.subList(0, snapshotManagedDependencies.size());
ImmutableSet<LinkageProblem> problemsInSnapshot = LinkageChecker.create(classpath, ImmutableSet.copyOf(entryPointJars), null).findLinkageProblems();
if (problemsInBaseline.equals(problemsInSnapshot)) {
logger.info("Snapshot versions have the same " + problemsInBaseline.size() + " errors as baseline");
return ImmutableSet.of();
}
Set<LinkageProblem> fixedProblems = Sets.difference(problemsInBaseline, problemsInSnapshot);
if (!fixedProblems.isEmpty()) {
logger.info(messageForFixedErrors(fixedProblems));
}
Set<LinkageProblem> newProblems = Sets.difference(problemsInSnapshot, problemsInBaseline);
if (!newProblems.isEmpty()) {
logger.severe(messageForNewErrors(problemsInSnapshot, problemsInBaseline, classPathResult));
}
return ImmutableSet.copyOf(newProblems);
}
use of com.google.cloud.tools.opensource.dependencies.Bom in project cloud-opensource-java by GoogleCloudPlatform.
the class LinkageMonitorTest method testBomSnapshot.
@Test
public void testBomSnapshot() throws ModelBuildingException, ArtifactResolutionException, ArtifactDescriptorException {
Bom bom = Bom.readBom("com.google.cloud:libraries-bom:1.2.0");
Bom snapshotBom = LinkageMonitor.copyWithSnapshot(system, session, bom, ImmutableMap.of("com.google.protobuf:protobuf-java", "3.8.0-SNAPSHOT"));
assertWithMessage("The first element of the SNAPSHOT BOM should be the same as the original BOM").that(toCoordinates(snapshotBom.getManagedDependencies().get(0))).isEqualTo("com.google.protobuf:protobuf-java:3.8.0-SNAPSHOT");
assertWithMessage("Artifacts other than protobuf-java should have the original version").that(skip(snapshotBom.getManagedDependencies(), 1)).comparingElementsUsing(transforming(Artifacts::toCoordinates, Artifacts::toCoordinates, "has the same Maven coordinates as")).containsExactlyElementsIn(skip(bom.getManagedDependencies(), 1)).inOrder();
}
Aggregations