Search in sources :

Example 1 with JavaModuleIndex

use of org.jetbrains.jps.model.java.JavaModuleIndex 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)

Aggregations

THashSet (gnu.trove.THashSet)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)1 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)1 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)1 JavaModuleIndex (org.jetbrains.jps.model.java.JavaModuleIndex)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1