Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsotovalero committed Mar 8, 2021
1 parent c35d64d commit 9644869
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import org.codehaus.plexus.util.DirectoryScanner;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -29,8 +31,6 @@
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;

import org.codehaus.plexus.util.DirectoryScanner;

/**
* Utility to visit classes in a library given either as a jar file or an exploded directory.
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ private static void acceptJar(URL url, ClassFileVisitor visitor)
{
try (JarInputStream in = new JarInputStream(url.openStream())) {
JarEntry entry = null;
while ((entry = in.getNextJarEntry()) != null) {
while ((entry = in.getNextJarEntry()) != null) {//NOSONAR
String name = entry.getName();
// ignore files like package-info.class and module-info.class
if (name.endsWith(CLASS) && name.indexOf('-') == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package se.kth.depclean.core.analysis.asm;

import lombok.extern.slf4j.Slf4j;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.FieldVisitor;
Expand All @@ -37,6 +38,7 @@
*
* @see #getDependencies()
*/
@Slf4j
public class DependencyClassFileVisitor implements ClassFileVisitor {

private final ResultCollector resultCollector = new ResultCollector();
Expand All @@ -47,62 +49,50 @@ public class DependencyClassFileVisitor implements ClassFileVisitor {
*/
public void visitClass(String className, InputStream in) {
try {
try {
ClassReader reader = new ClassReader(in);
ClassReader reader = new ClassReader(in);

// System.out.println("**************************************************");
// System.out.println("Reading class: " + className);

final Set<String> constantPoolClassRefs = ConstantPoolParser.getConstantPoolClassReferences(reader.b);
for (String string : constantPoolClassRefs) {
resultCollector.addName(string);
}

/* visit class members */
AnnotationVisitor annotationVisitor = new DefaultAnnotationVisitor(
resultCollector
);
SignatureVisitor signatureVisitor = new DefaultSignatureVisitor(
resultCollector
);
FieldVisitor fieldVisitor = new DefaultFieldVisitor(
annotationVisitor,
resultCollector
);
MethodVisitor methodVisitor = new DefaultMethodVisitor(
annotationVisitor,
signatureVisitor,
resultCollector
);

DefaultClassVisitor defaultClassVisitor = new DefaultClassVisitor(
signatureVisitor,
annotationVisitor,
fieldVisitor,
methodVisitor,
resultCollector
);

reader.accept(defaultClassVisitor, 0);

// inset edge in the graph based on the bytecode analysis
DefaultCallGraph.addEdge(className, resultCollector.getDependencies());
resultCollector.clearClasses();

} catch (IOException exception) {
exception.printStackTrace();
} catch (IndexOutOfBoundsException e) {
// some bug inside ASM causes an IOB exception. Log it and move on?
// this happens when the class isn't valid.
System.out.println("Unable to process: " + className);
final Set<String> constantPoolClassRefs = ConstantPoolParser.getConstantPoolClassReferences(reader.b);
for (String string : constantPoolClassRefs) {
resultCollector.addName(string);
}

/* visit class members */
AnnotationVisitor annotationVisitor = new DefaultAnnotationVisitor(
resultCollector
);
SignatureVisitor signatureVisitor = new DefaultSignatureVisitor(
resultCollector
);
FieldVisitor fieldVisitor = new DefaultFieldVisitor(
annotationVisitor,
resultCollector
);
MethodVisitor methodVisitor = new DefaultMethodVisitor(
annotationVisitor,
signatureVisitor,
resultCollector
);

DefaultClassVisitor defaultClassVisitor = new DefaultClassVisitor(
signatureVisitor,
annotationVisitor,
fieldVisitor,
methodVisitor,
resultCollector
);

reader.accept(defaultClassVisitor, 0);

// inset edge in the graph based on the bytecode analysis
DefaultCallGraph.addEdge(className, resultCollector.getDependencies());
resultCollector.clearClasses();

} catch (IndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException | IOException e) {
// some bug inside ASM causes an IOB exception. Log it and move on?
// this happens when the class isn't valid.
System.out.println("Unable to process: " + className);
log.warn("Unable to process: " + className);
}
resultCollector.clearClasses();
}

// public methods ---------------------------------------------------------
Expand Down

0 comments on commit 9644869

Please sign in to comment.