Skip to content

Commit

Permalink
Merge pull request #26 from saeg/remove-asm-deprecated-api
Browse files Browse the repository at this point in the history
Remove `instrument(ClassReader)` and `analyze(ClassReader)`
  • Loading branch information
andrioli authored Sep 20, 2021
2 parents 8bf2bbe + 32b8c5b commit 3d9b03b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import br.usp.each.saeg.badua.core.data.ExecutionDataStore;
import br.usp.each.saeg.badua.core.internal.ContentTypeDetector;
import br.usp.each.saeg.badua.core.internal.data.CRC64;
import br.usp.each.saeg.commons.io.Files;

public class Analyzer {

Expand All @@ -45,8 +46,9 @@ private ExecutionData getData(final long classId, final String className) {
return new ExecutionData(classId, className, null);
}

public void analyze(final ClassReader reader) {
final long classId = CRC64.checksum(reader.b);
public void analyze(final byte[] buffer) {
final long classId = CRC64.checksum(buffer);
final ClassReader reader = new ClassReader(buffer);
final ClassAnalyzer ca = new ClassAnalyzer(getData(classId, reader.getClassName()), stringPool);
reader.accept(ca, DEFAULT);
final ClassCoverage coverage = ca.getCoverage();
Expand All @@ -57,7 +59,7 @@ public void analyze(final ClassReader reader) {

public void analyze(final InputStream input, final String location) throws IOException {
try {
analyze(new ClassReader(input));
analyze(Files.toByteArray(input));
} catch (final RuntimeException e) {
throw analyzeError(location, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public Instrumenter(final IExecutionDataAccessorGenerator accessorGenerator) {
this.accessorGenerator = accessorGenerator;
}

public byte[] instrument(final ClassReader reader) {
final long classId = CRC64.checksum(reader.b);
public byte[] instrument(final byte[] buffer) {
final long classId = CRC64.checksum(buffer);
final ClassReader reader = new ClassReader(buffer);
final ClassWriter writer = new ClassWriter(reader, DEFAULT);
final ClassVisitor ci = new ClassInstrumenter(classId, writer, accessorGenerator);
reader.accept(ci, ClassReader.EXPAND_FRAMES);
Expand All @@ -44,7 +45,7 @@ public byte[] instrument(final ClassReader reader) {

public byte[] instrument(final byte[] buffer, final String name) throws IOException {
try {
return instrument(new ClassReader(buffer));
return instrument(buffer);
} catch (final RuntimeException e) {
throw instrumentError(name, e);
}
Expand All @@ -53,7 +54,7 @@ public byte[] instrument(final byte[] buffer, final String name) throws IOExcept
public void instrument(final InputStream input, final OutputStream output, final String name)
throws IOException {
try {
output.write(instrument(new ClassReader(input)));
output.write(instrument(Files.toByteArray(input)));
} catch (final RuntimeException e) {
throw instrumentError(name, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.junit.Assert;
import org.junit.Before;
import org.objectweb.asm.ClassReader;

import br.usp.each.saeg.badua.core.analysis.Analyzer;
import br.usp.each.saeg.badua.core.analysis.ClassCoverage;
Expand Down Expand Up @@ -47,7 +46,7 @@ public void setUp() throws Exception {
final byte[] bytes = ValidationTestClassLoader.getClassDataAsBytes(target);
final ExecutionDataStore store = execute(bytes);
final Analyzer analyzer = new Analyzer(store, this);
analyzer.analyze(new ClassReader(bytes));
analyzer.analyze(bytes);
Assert.assertEquals(1, classes.size());
for (final MethodCoverage coverage : classes.iterator().next().getMethods()) {
defUses.addAll(coverage.getDefUses());
Expand Down

0 comments on commit 3d9b03b

Please sign in to comment.