Search in sources :

Example 61 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.

the class BuildRunner method load.

public ProjectDescriptor load(MessageHandler msgHandler, File dataStorageRoot, BuildFSState fsState) throws IOException {
    final JpsModel jpsModel = myModelLoader.loadModel();
    BuildDataPaths dataPaths = new BuildDataPathsImpl(dataStorageRoot);
    BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(jpsModel);
    ModuleExcludeIndex index = new ModuleExcludeIndexImpl(jpsModel);
    IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(jpsModel);
    BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, jpsModel, index, dataPaths, ignoredFileIndex);
    BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
    BuildTargetsState targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
    ProjectTimestamps projectTimestamps = null;
    BuildDataManager dataManager = null;
    try {
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        if (dataManager.versionDiffers()) {
            myForceCleanCaches = true;
            msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Dependency data format has changed, project rebuild required"));
        }
    } catch (Exception e) {
        // second try
        LOG.info(e);
        if (projectTimestamps != null) {
            projectTimestamps.close();
        }
        if (dataManager != null) {
            dataManager.close();
        }
        myForceCleanCaches = true;
        FileUtil.delete(dataStorageRoot);
        targetsState = new BuildTargetsState(dataPaths, jpsModel, buildRootIndex);
        projectTimestamps = new ProjectTimestamps(dataStorageRoot, targetsState);
        dataManager = new BuildDataManager(dataPaths, targetsState, STORE_TEMP_CACHES_IN_MEMORY);
        // second attempt succeeded
        msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.INFO, "Project rebuild forced: " + e.getMessage()));
    }
    return new ProjectDescriptor(jpsModel, fsState, projectTimestamps, dataManager, BuildLoggingManager.DEFAULT, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) JpsModel(org.jetbrains.jps.model.JpsModel) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) IOException(java.io.IOException) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 62 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.

the class JavaBuilder method doBuild.

public ExitCode doBuild(@NotNull CompileContext context, @NotNull ModuleChunk chunk, @NotNull DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, @NotNull OutputConsumer outputConsumer, @NotNull JavaCompilingTool compilingTool) throws ProjectBuildException, IOException {
    try {
        final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

            @Override
            public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
                if (JAVA_SOURCES_FILTER.accept(file) && ourCompilableModuleTypes.contains(target.getModule().getModuleType())) {
                    filesToCompile.add(file);
                }
                return true;
            }
        });
        if ((!filesToCompile.isEmpty() || dirtyFilesHolder.hasRemovedFiles()) && JpsJavaSdkType.parseVersion(getLanguageLevel(ContainerUtil.getFirstItem(chunk.getModules()))) >= 9) {
            // at the moment, there is no incremental compilation for module-info files, so they should be rebuilt on every change
            JavaModuleIndex index = getJavaModuleIndex(context);
            for (JpsModule module : chunk.getModules()) {
                ContainerUtil.addIfNotNull(filesToCompile, index.getModuleInfoFile(module));
            }
        }
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled() && !filesToCompile.isEmpty()) {
                logger.logCompiledFiles(filesToCompile, BUILDER_NAME, "Compiling files:");
            }
        }
        return compile(context, chunk, dirtyFilesHolder, filesToCompile, outputConsumer, compilingTool);
    } catch (BuildDataCorruptedException | PersistentEnumeratorBase.CorruptedException | ProjectBuildException e) {
        throw e;
    } catch (Exception e) {
        LOG.info(e);
        String message = e.getMessage();
        if (message == null) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            final PrintStream stream = new PrintStream(out);
            try {
                e.printStackTrace(stream);
            } finally {
                stream.close();
            }
            message = "Internal error: \n" + out;
        }
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
        throw new StopBuildException();
    }
}
Also used : JavaModuleIndex(org.jetbrains.jps.model.java.JavaModuleIndex) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashSet(gnu.trove.THashSet) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)

Example 63 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.

the class ResourcesBuilder method build.

@Override
public void build(@NotNull ResourcesTarget target, @NotNull DirtyFilesHolder<ResourceRootDescriptor, ResourcesTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    if (!isResourceProcessingEnabled(target.getModule())) {
        return;
    }
    try {
        holder.processDirtyFiles(new FileProcessor<ResourceRootDescriptor, ResourcesTarget>() {

            private final Map<ResourceRootDescriptor, Boolean> mySkippedRoots = new HashMap<>();

            public boolean apply(ResourcesTarget target, final File file, final ResourceRootDescriptor sourceRoot) throws IOException {
                Boolean isSkipped = mySkippedRoots.get(sourceRoot);
                if (isSkipped == null) {
                    final File outputDir = target.getOutputDir();
                    isSkipped = Boolean.valueOf(outputDir == null || FileUtil.filesEqual(outputDir, sourceRoot.getRootFile()));
                    mySkippedRoots.put(sourceRoot, isSkipped);
                }
                if (isSkipped.booleanValue()) {
                    return true;
                }
                try {
                    copyResource(context, sourceRoot, file, outputConsumer);
                } catch (IOException e) {
                    LOG.info(e);
                    context.processMessage(new CompilerMessage("resources", BuildMessage.Kind.ERROR, e.getMessage(), FileUtil.toSystemIndependentName(file.getPath())));
                    return false;
                }
                return !context.getCancelStatus().isCanceled();
            }
        });
        context.checkCanceled();
        context.processMessage(new ProgressMessage(""));
    } catch (BuildDataCorruptedException | ProjectBuildException e) {
        throw e;
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) IOException(java.io.IOException) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) ResourcesTarget(org.jetbrains.jps.incremental.ResourcesTarget) ResourceRootDescriptor(org.jetbrains.jps.builders.java.ResourceRootDescriptor) File(java.io.File)

Example 64 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage 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)

Example 65 with CompilerMessage

use of org.jetbrains.jps.incremental.messages.CompilerMessage in project intellij-community by JetBrains.

the class GroovycOutputParser method parseOutput.

private void parseOutput(String text) {
    final String trimmed = text.trim();
    if (trimmed.startsWith(GroovyRtConstants.PRESENTABLE_MESSAGE)) {
        updateStatus(trimmed.substring(GroovyRtConstants.PRESENTABLE_MESSAGE.length()));
        return;
    }
    if (GroovyRtConstants.CLEAR_PRESENTABLE.equals(trimmed)) {
        updateStatus(GROOVY_COMPILER_IN_OPERATION);
        return;
    }
    if (StringUtil.isNotEmpty(text)) {
        outputBuffer.append(text);
        //compiled start marker have to be in the beginning on each string
        if (outputBuffer.indexOf(GroovyRtConstants.COMPILED_START) != -1) {
            if (outputBuffer.indexOf(GroovyRtConstants.COMPILED_END) == -1) {
                return;
            }
            final String compiled = handleOutputBuffer(GroovyRtConstants.COMPILED_START, GroovyRtConstants.COMPILED_END);
            final List<String> list = splitAndTrim(compiled);
            String outputPath = list.get(0);
            String sourceFile = list.get(1);
            OutputItem item = new OutputItem(outputPath, sourceFile);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Output: " + item);
            }
            myCompiledItems.add(item);
        } else if (outputBuffer.indexOf(GroovyRtConstants.MESSAGES_START) != -1) {
            if (outputBuffer.indexOf(GroovyRtConstants.MESSAGES_END) == -1) {
                return;
            }
            text = handleOutputBuffer(GroovyRtConstants.MESSAGES_START, GroovyRtConstants.MESSAGES_END);
            List<String> tokens = splitAndTrim(text);
            LOG.assertTrue(tokens.size() > 4, "Wrong number of output params");
            String category = tokens.get(0);
            String message = tokens.get(1);
            String url = tokens.get(2);
            String lineNum = tokens.get(3);
            String columnNum = tokens.get(4);
            int lineInt;
            int columnInt;
            try {
                lineInt = Integer.parseInt(lineNum);
                columnInt = Integer.parseInt(columnNum);
            } catch (NumberFormatException e) {
                LOG.error(e);
                lineInt = 0;
                columnInt = 0;
            }
            BuildMessage.Kind kind = category.equals(GroovyCompilerMessageCategories.ERROR) ? BuildMessage.Kind.ERROR : category.equals(GroovyCompilerMessageCategories.WARNING) ? BuildMessage.Kind.WARNING : BuildMessage.Kind.INFO;
            if (StringUtil.isEmpty(url) || "null".equals(url)) {
                url = null;
                message = "While compiling " + myChunk.getPresentableShortName() + ": " + message;
            }
            CompilerMessage compilerMessage = new CompilerMessage("Groovyc", kind, message, url, -1, -1, -1, lineInt, columnInt);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Message: " + compilerMessage);
            }
            addCompilerMessage(compilerMessage);
        }
    }
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)75 File (java.io.File)34 IOException (java.io.IOException)22 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)18 JpsModule (org.jetbrains.jps.model.module.JpsModule)15 HashMap (com.intellij.util.containers.HashMap)11 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)11 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)9 ArrayList (java.util.ArrayList)9 THashSet (gnu.trove.THashSet)8 Nullable (org.jetbrains.annotations.Nullable)8 ProjectBuildException (org.jetbrains.jps.incremental.ProjectBuildException)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 NotNull (org.jetbrains.annotations.NotNull)7 BuildMessage (org.jetbrains.jps.incremental.messages.BuildMessage)6 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)5 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)4 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 Pair (com.intellij.openapi.util.Pair)3 THashMap (gnu.trove.THashMap)3