Search in sources :

Example 6 with FailSafeClassReader

use of com.intellij.compiler.instrumentation.FailSafeClassReader in project intellij-community by JetBrains.

the class BaseInstrumentingBuilder method performBuild.

@Override
protected final ExitCode performBuild(CompileContext context, ModuleChunk chunk, InstrumentationClassFinder finder, OutputConsumer outputConsumer) {
    ExitCode exitCode = ExitCode.NOTHING_DONE;
    for (CompiledClass compiledClass : outputConsumer.getCompiledClasses().values()) {
        if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
            LOG.info("checking " + compiledClass + " by " + getClass());
        }
        final BinaryContent originalContent = compiledClass.getContent();
        final ClassReader reader = new FailSafeClassReader(originalContent.getBuffer(), originalContent.getOffset(), originalContent.getLength());
        final int version = getClassFileVersion(reader);
        if (IS_INSTRUMENTED_KEY.get(compiledClass, Boolean.FALSE) || !canInstrument(compiledClass, version)) {
            // do not instrument the same content twice
            continue;
        }
        final ClassWriter writer = new InstrumenterClassWriter(reader, getAsmClassWriterFlags(version), finder);
        try {
            if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
                LOG.info("instrumenting " + compiledClass + " by " + getClass());
            }
            final BinaryContent instrumented = instrument(context, compiledClass, reader, writer, finder);
            if (instrumented != null) {
                compiledClass.setContent(instrumented);
                finder.cleanCachedData(compiledClass.getClassName());
                IS_INSTRUMENTED_KEY.set(compiledClass, Boolean.TRUE);
                exitCode = ExitCode.OK;
            }
        } catch (Throwable e) {
            LOG.info(e);
            final String message = e.getMessage();
            if (message != null) {
                context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
            } else {
                context.processMessage(new CompilerMessage(getPresentableName(), e));
            }
        }
    }
    return exitCode;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) InstrumenterClassWriter(com.intellij.compiler.instrumentation.InstrumenterClassWriter) FailSafeClassReader(com.intellij.compiler.instrumentation.FailSafeClassReader) ClassWriter(org.jetbrains.org.objectweb.asm.ClassWriter) InstrumenterClassWriter(com.intellij.compiler.instrumentation.InstrumenterClassWriter)

Aggregations

FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)6 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)4 InstrumenterClassWriter (com.intellij.compiler.instrumentation.InstrumenterClassWriter)3 File (java.io.File)3 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)3 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)2 ClassWriter (org.jetbrains.org.objectweb.asm.ClassWriter)2 CompiledClassPropertiesProvider (com.intellij.uiDesigner.lw.CompiledClassPropertiesProvider)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 MultiMap (com.intellij.util.containers.MultiMap)1 THashMap (gnu.trove.THashMap)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 BuildException (org.apache.tools.ant.BuildException)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 Callbacks (org.jetbrains.jps.builders.java.dependencyView.Callbacks)1 BinaryContent (org.jetbrains.jps.incremental.BinaryContent)1 CompiledClass (org.jetbrains.jps.incremental.CompiledClass)1