use of org.gradle.util.internal.PatchedClassReader in project gradle by gradle.
the class AbstractTestFrameworkDetector method classVisitor.
protected TestClassVisitor classVisitor(final File testClassFile) {
final TestClassVisitor classVisitor = createClassVisitor();
InputStream classStream = null;
try {
classStream = new BufferedInputStream(new FileInputStream(testClassFile));
final ClassReader classReader = new PatchedClassReader(IOUtils.toByteArray(classStream));
classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
} catch (Throwable e) {
throw new GradleException("failed to read class file " + testClassFile.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(classStream);
}
return classVisitor;
}
use of org.gradle.util.internal.PatchedClassReader in project gradle by gradle.
the class MixInLegacyTypesClassLoader method transform.
@Override
protected byte[] transform(String className, byte[] bytes) {
ClassReader classReader = new PatchedClassReader(bytes);
ClassWriter classWriter = new ClassWriter(0);
classReader.accept(new TransformingAdapter(classWriter), 0);
bytes = classWriter.toByteArray();
return bytes;
}
use of org.gradle.util.internal.PatchedClassReader in project gradle by gradle.
the class ClassChangeProcessor method processChange.
public void processChange(final InputFileDetails input, final RecompilationSpec spec) {
if (input.isRemoved()) {
// this is a really heavyweight way of getting the dependencies of a file which was removed
// hopefully this is not going to happen too often
String className = previousCompilation.getClassName(input.getFile().getAbsolutePath());
update(input, spec, className, IntSets.EMPTY_SET);
return;
}
final ClassReader classReader;
try {
classReader = new PatchedClassReader(Files.toByteArray(input.getFile()));
String className = classReader.getClassName().replaceAll("/", ".");
IntSet constants = ClassDependenciesVisitor.retrieveConstants(classReader);
update(input, spec, className, constants);
} catch (IOException e) {
throw new IllegalArgumentException(String.format("Unable to read class file: '%s'", input.getFile()));
}
}
use of org.gradle.util.internal.PatchedClassReader in project gradle by gradle.
the class DefaultClassDependenciesAnalyzer method getClassAnalysis.
public ClassAnalysis getClassAnalysis(InputStream input) throws IOException {
ClassReader reader = new PatchedClassReader(ByteStreams.toByteArray(input));
String className = reader.getClassName().replace("/", ".");
return ClassDependenciesVisitor.analyze(className, reader);
}
use of org.gradle.util.internal.PatchedClassReader in project gradle by gradle.
the class AbiExtractingClasspathResourceHasher method hashClassBytes.
private HashCode hashClassBytes(InputStream inputStream) throws IOException {
// Use the ABI as the hash
byte[] classBytes = ByteStreams.toByteArray(inputStream);
ApiClassExtractor extractor = new ApiClassExtractor(Collections.<String>emptySet());
ClassReader reader = new PatchedClassReader(classBytes);
if (extractor.shouldExtractApiClassFrom(reader)) {
byte[] signature = extractor.extractApiClassFrom(reader);
if (signature != null) {
return Hashing.md5().hashBytes(signature);
}
}
return null;
}
Aggregations