Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

package com.google.cloud.tools.opensource.classpath;

import static com.google.common.base.Preconditions.checkArgument;

import com.google.cloud.tools.opensource.dependencies.Artifacts;
import com.google.cloud.tools.opensource.dependencies.DependencyPath;
import com.google.cloud.tools.opensource.dependencies.UnresolvableArtifactProblem;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.util.logging.Logger;
import org.eclipse.aether.artifact.Artifact;

/** Result of class path resolution with {@link UnresolvableArtifactProblem}s if any. */
public final class ClassPathResult {
private static final Logger logger = Logger.getLogger(ClassPathResult.class.getName());

private final ImmutableList<ClassPathEntry> classPath;

Expand Down Expand Up @@ -65,7 +66,11 @@ public String formatDependencyPaths(Iterable<ClassPathEntry> entries) {
StringBuilder message = new StringBuilder();
for (ClassPathEntry entry : entries) {
ImmutableList<DependencyPath> dependencyPaths = getDependencyPaths(entry);
checkArgument(dependencyPaths.size() >= 1, "%s is not in the class path", entry);

if (dependencyPaths.isEmpty()) {
logger.warning(entry + " is not in the class path");
continue;
}

message.append(entry + " is at:\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.cloud.tools.opensource.classpath;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import com.google.cloud.tools.opensource.dependencies.DependencyPath;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -115,21 +114,6 @@ public void testFormatDependencyPaths_threePathsForA() {
actual);
}

@Test
public void testFormatDependencyPaths_irrelevantJar() {
AnnotatedClassPath annotatedClassPath =
AnnotatedClassPath.fromMultimap(ImmutableListMultimap.of(jarA, dependencyPath_A));

ClassPathResult classPathResult = new ClassPathResult(annotatedClassPath, ImmutableSet.of());

try {
classPathResult.formatDependencyPaths(ImmutableList.of(jarB));
fail("The irrelevant JAR file should be invalidated.");
} catch (IllegalArgumentException expected) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, the method doesn't throw IllegalArgumentException any more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning is not critical message. I keep as it is.

assertEquals("com.google:b:1 is not in the class path", expected.getMessage());
}
}

@Test
public void testGetClassPathEntries() {
AnnotatedClassPath annotatedClassPath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class BuildStatusFunctionalTest extends Specification {
| com.google.cloud.ServiceOptionsTest (com.google.cloud:google-cloud-core:jar:tests:1.95.4)
| com.google.cloud.BatchResultTest (com.google.cloud:google-cloud-core:jar:tests:1.95.4)
| """.stripMargin())
!result.output.contains("StackOverflowError")
result.task(":linkageCheck").outcome == TaskOutcome.FAILED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,26 @@ private void recordDependencyPaths(
ResolvedDependencyResult resolvedDependencyResult =
(ResolvedDependencyResult) dependencyResult;
ResolvedComponentResult child = resolvedDependencyResult.getSelected();
stack.add(child);
recordDependencyPaths(output, stack, targetCoordinates);

if (stack.contains(child)) {
// Circular dependency check
getLogger()
.error(
"Circular dependency for: "
+ resolvedDependencyResult
+ "\n The stack is: " + stack);
} else {
stack.add(child);
recordDependencyPaths(output, stack, targetCoordinates);
}
} else if (dependencyResult instanceof UnresolvedDependencyResult) {
UnresolvedDependencyResult unresolvedResult = (UnresolvedDependencyResult) dependencyResult;
getLogger()
.error(
"Could not resolve dependency: "
+ unresolvedResult.getAttempted().getDisplayName());
} else {
throw new IllegalStateException("Unexpected dependency result type: " + dependencyResult);
getLogger().error("Unexpected dependency result type: " + dependencyResult);
}
}

Expand Down