Search in sources :

Example 1 with ClassFile

use of com.google.cloud.tools.opensource.classpath.ClassFile in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageMonitor method messageForNewErrors.

/**
 * Returns a message on {@code snapshotProblems} that do not exist in {@code baselineProblems}.
 */
@VisibleForTesting
static String messageForNewErrors(Set<LinkageProblem> snapshotProblems, Set<LinkageProblem> baselineProblems, ClassPathResult classPathResult) {
    Set<LinkageProblem> newProblems = Sets.difference(snapshotProblems, baselineProblems);
    Builder<ClassPathEntry> problematicJars = ImmutableSet.builder();
    ImmutableListMultimap<String, LinkageProblem> groupedBySymbolProblem = Multimaps.index(newProblems, problem -> problem.formatSymbolProblem());
    StringBuilder message = new StringBuilder("Newly introduced problem" + (groupedBySymbolProblem.keySet().size() > 1 ? "s" : "") + ":\n");
    for (String problem : groupedBySymbolProblem.keySet()) {
        message.append(problem + "\n");
        for (LinkageProblem linkageProblem : groupedBySymbolProblem.get(problem)) {
            // This is null for ClassNotFound error.
            if (linkageProblem.getTargetClass() != null) {
                problematicJars.add(linkageProblem.getTargetClass().getClassPathEntry());
            }
            ClassFile sourceClass = linkageProblem.getSourceClass();
            message.append(String.format("  referenced from %s (%s)\n", sourceClass.getBinaryName(), sourceClass.getClassPathEntry()));
            problematicJars.add(sourceClass.getClassPathEntry());
        }
    }
    message.append("\n");
    message.append(classPathResult.formatDependencyPaths(problematicJars.build()));
    return message.toString();
}
Also used : LinkageProblem(com.google.cloud.tools.opensource.classpath.LinkageProblem) ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ClassFile

use of com.google.cloud.tools.opensource.classpath.ClassFile in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageMonitorTest method setup.

@Before
public void setup() throws IOException {
    system = RepositoryUtility.newRepositorySystem();
    session = RepositoryUtility.newSession(system);
    methodNotFoundProblemFromA = new SymbolNotFoundProblem(new ClassFile(jarA, "com.abc.AAA"), new ClassFile(jarB, "io.grpc.protobuf.ProtoUtils"), new MethodSymbol("io.grpc.protobuf.ProtoUtils", "marshaller", "(Lcom/google/protobuf/Message;)Lio/grpc/MethodDescriptor$Marshaller;", false));
    methodNotFoundProblemFromB = new SymbolNotFoundProblem(new ClassFile(jarA, "com.abc.BBB"), new ClassFile(jarB, "io.grpc.protobuf.ProtoUtils"), new MethodSymbol("io.grpc.protobuf.ProtoUtils", "marshaller", "(Lcom/google/protobuf/Message;)Lio/grpc/MethodDescriptor$Marshaller;", false));
}
Also used : ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) MethodSymbol(com.google.cloud.tools.opensource.classpath.MethodSymbol) SymbolNotFoundProblem(com.google.cloud.tools.opensource.classpath.SymbolNotFoundProblem) Before(org.junit.Before)

Example 3 with ClassFile

use of com.google.cloud.tools.opensource.classpath.ClassFile in project cloud-opensource-java by GoogleCloudPlatform.

the class LinkageCheckTask method dependencyPathsOfProblematicJars.

private String dependencyPathsOfProblematicJars(ResolvedComponentResult componentResult, Set<LinkageProblem> symbolProblems) {
    ImmutableSet.Builder<ClassPathEntry> problematicJars = ImmutableSet.builder();
    for (LinkageProblem problem : symbolProblems) {
        ClassFile targetClass = problem.getTargetClass();
        if (targetClass != null) {
            problematicJars.add(targetClass.getClassPathEntry());
        }
        ClassFile sourceClass = problem.getSourceClass();
        problematicJars.add(sourceClass.getClassPathEntry());
    }
    return "Problematic artifacts in the dependency tree:\n" + dependencyPathToArtifacts(componentResult, problematicJars.build());
}
Also used : LinkageProblem(com.google.cloud.tools.opensource.classpath.LinkageProblem) ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry)

Example 4 with ClassFile

use of com.google.cloud.tools.opensource.classpath.ClassFile in project cloud-opensource-java by GoogleCloudPlatform.

the class FreemarkerTest method setUp.

@Before
public void setUp() {
    Artifact artifact = new DefaultArtifact("com.google:foo:1.0.0").setFile(new File("foo/bar-1.2.3.jar"));
    ClassPathEntry entry = new ClassPathEntry(artifact);
    ImmutableSet<LinkageProblem> dummyProblems = ImmutableSet.of(new ClassNotFoundProblem(new ClassFile(entry, "abc.def.G"), new ClassSymbol("com.foo.Bar")));
    symbolProblemTable = ImmutableMap.of(entry, dummyProblems);
}
Also used : LinkageProblem(com.google.cloud.tools.opensource.classpath.LinkageProblem) ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) ClassNotFoundProblem(com.google.cloud.tools.opensource.classpath.ClassNotFoundProblem) ClassSymbol(com.google.cloud.tools.opensource.classpath.ClassSymbol) ClassFile(com.google.cloud.tools.opensource.classpath.ClassFile) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ClassPathEntry(com.google.cloud.tools.opensource.classpath.ClassPathEntry) Before(org.junit.Before)

Aggregations

ClassFile (com.google.cloud.tools.opensource.classpath.ClassFile)4 ClassPathEntry (com.google.cloud.tools.opensource.classpath.ClassPathEntry)3 LinkageProblem (com.google.cloud.tools.opensource.classpath.LinkageProblem)3 Before (org.junit.Before)2 ClassNotFoundProblem (com.google.cloud.tools.opensource.classpath.ClassNotFoundProblem)1 ClassSymbol (com.google.cloud.tools.opensource.classpath.ClassSymbol)1 MethodSymbol (com.google.cloud.tools.opensource.classpath.MethodSymbol)1 SymbolNotFoundProblem (com.google.cloud.tools.opensource.classpath.SymbolNotFoundProblem)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 File (java.io.File)1 Artifact (org.eclipse.aether.artifact.Artifact)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1