Search in sources :

Example 1 with PatchedClassReader

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GradleException(org.gradle.api.GradleException) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) FileInputStream(java.io.FileInputStream)

Example 2 with PatchedClassReader

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;
}
Also used : PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassWriter(org.objectweb.asm.ClassWriter)

Example 3 with PatchedClassReader

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()));
    }
}
Also used : IntSet(it.unimi.dsi.fastutil.ints.IntSet) PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) IOException(java.io.IOException) PatchedClassReader(org.gradle.util.internal.PatchedClassReader)

Example 4 with PatchedClassReader

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);
}
Also used : PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) PatchedClassReader(org.gradle.util.internal.PatchedClassReader)

Example 5 with PatchedClassReader

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;
}
Also used : PatchedClassReader(org.gradle.util.internal.PatchedClassReader) ClassReader(org.objectweb.asm.ClassReader) ApiClassExtractor(org.gradle.api.internal.tasks.compile.ApiClassExtractor) PatchedClassReader(org.gradle.util.internal.PatchedClassReader)

Aggregations

PatchedClassReader (org.gradle.util.internal.PatchedClassReader)8 ClassReader (org.objectweb.asm.ClassReader)8 IOException (java.io.IOException)3 GradleException (org.gradle.api.GradleException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 ApiClassExtractor (org.gradle.api.internal.tasks.compile.ApiClassExtractor)2 ImmutableList (com.google.common.collect.ImmutableList)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 List (java.util.List)1 Map (java.util.Map)1