Skip to content

Commit

Permalink
make listClassFileNames void
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Mar 27, 2020
1 parent 18cde4d commit 05d4198
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Expand Up @@ -189,7 +189,10 @@ private static Path generate(Bom bom) throws IOException, TemplateException, URI
// When checking a BOM, entry point classes are the ones in the artifacts listed in the BOM
List<ClassPathEntry> artifactJarsInBom = classpath.subList(0, managedDependencies.size());
ImmutableSet<ClassPathEntry> entryPoints = ImmutableSet.copyOf(artifactJarsInBom);

for (ClassPathEntry entry : entryPoints) {
entry.listClassFileNames();
}

LinkageChecker linkageChecker = LinkageChecker.create(classpath, entryPoints);

ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems =
Expand Down
Expand Up @@ -341,7 +341,7 @@ static ImmutableSetMultimap<ClassPathEntry, String> mapJarToClassFileNames(
List<ClassPathEntry> classPath) throws IOException {
Builder<ClassPathEntry, String> pathToClasses = ImmutableSetMultimap.builder();
for (ClassPathEntry jar : classPath) {
for (String classFileName : jar.listClassFileNames()) {
for (String classFileName : jar.getClassFileNames()) {
pathToClasses.put(jar, classFileName);
}
}
Expand All @@ -357,7 +357,7 @@ private ImmutableSet<JavaClass> listClasses(ClassPathEntry entry) throws IOExcep

ImmutableList.Builder<String> corruptedClassFileNames = ImmutableList.builder();

for (String classFileName : entry.listClassFileNames()) {
for (String classFileName : entry.getClassFileNames()) {
if (classFileName.startsWith("META-INF.versions.")) {
// Linkage Checker does not support multi-release JAR (for Java 9+) yet
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/897
Expand Down
Expand Up @@ -109,7 +109,9 @@ public static ClassPathEntry of(String coordinates, String filePath) {
* Usually the class name and class file name are the same. However a class file name may have a
* framework-specific prefix. Example: {@code BOOT-INF.classes.com.google.Foo}.
*/
ImmutableSet<String> listClassFileNames() throws IOException {
// Could do this on construction but that makes construction slow and throw an IOException.
// Is this OK? Or maybe lazy load in getClassFileNames?
public void listClassFileNames() throws IOException {
URL jarUrl = getJar().toUri().toURL();
// Setting parent as null because we don't want other classes than this jar file
URLClassLoader classLoaderFromJar = new URLClassLoader(new URL[] {jarUrl}, null);
Expand All @@ -119,7 +121,6 @@ ImmutableSet<String> listClassFileNames() throws IOException {
com.google.common.reflect.ClassPath.from(classLoaderFromJar);

classFileNames = classPath.getAllClasses().stream().map(ClassInfo::getName).collect(toImmutableSet());
return classFileNames;
}

public ImmutableSet<String> getClassFileNames() {
Expand Down
Expand Up @@ -50,7 +50,7 @@ static ClassReferenceGraph create(

ImmutableSet.Builder<String> entryPointClassBuilder = ImmutableSet.builder();
for (ClassPathEntry entry : entryPoints) {
for (String className : entry.listClassFileNames()) {
for (String className : entry.getClassFileNames()) {
entryPointClassBuilder.add(className);
}
}
Expand Down

0 comments on commit 05d4198

Please sign in to comment.