Search in sources :

Example 1 with DirtyFilesHolderBase

use of org.jetbrains.jps.builders.impl.DirtyFilesHolderBase in project intellij-community by JetBrains.

the class IncProjectBuilder method buildTarget.

private <R extends BuildRootDescriptor, T extends BuildTarget<R>> void buildTarget(final T target, final CompileContext context, TargetBuilder<?, ?> builder) throws ProjectBuildException, IOException {
    if (builder.getTargetTypes().contains(target.getTargetType())) {
        DirtyFilesHolder<R, T> holder = new DirtyFilesHolderBase<R, T>(context) {

            @Override
            public void processDirtyFiles(@NotNull FileProcessor<R, T> processor) throws IOException {
                context.getProjectDescriptor().fsState.processFilesToRecompile(context, target, processor);
            }
        };
        //noinspection unchecked
        BuildOutputConsumerImpl outputConsumer = new BuildOutputConsumerImpl(target, context);
        long start = System.nanoTime();
        ((TargetBuilder<R, T>) builder).build(target, holder, outputConsumer, context);
        storeBuilderStatistics(builder, System.nanoTime() - start, outputConsumer.getNumberOfProcessedSources());
        outputConsumer.fireFileGeneratedEvent();
        context.checkCanceled();
    }
}
Also used : DirtyFilesHolderBase(org.jetbrains.jps.builders.impl.DirtyFilesHolderBase) NotNull(org.jetbrains.annotations.NotNull) BuildOutputConsumerImpl(org.jetbrains.jps.builders.impl.BuildOutputConsumerImpl)

Example 2 with DirtyFilesHolderBase

use of org.jetbrains.jps.builders.impl.DirtyFilesHolderBase in project intellij-community by JetBrains.

the class IncProjectBuilder method runModuleLevelBuilders.

// return true if changed something, false otherwise
private boolean runModuleLevelBuilders(final CompileContext context, final ModuleChunk chunk) throws ProjectBuildException, IOException {
    for (BuilderCategory category : BuilderCategory.values()) {
        for (ModuleLevelBuilder builder : myBuilderRegistry.getBuilders(category)) {
            builder.chunkBuildStarted(context, chunk);
        }
    }
    boolean doneSomething = false;
    boolean rebuildFromScratchRequested = false;
    float stageCount = myTotalModuleLevelBuilderCount;
    final int modulesInChunk = chunk.getModules().size();
    int buildersPassed = 0;
    boolean nextPassRequired;
    ChunkBuildOutputConsumerImpl outputConsumer = new ChunkBuildOutputConsumerImpl(context);
    try {
        do {
            nextPassRequired = false;
            myProjectDescriptor.fsState.beforeNextRoundStart(context, chunk);
            DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder = new DirtyFilesHolderBase<JavaSourceRootDescriptor, ModuleBuildTarget>(context) {

                @Override
                public void processDirtyFiles(@NotNull FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget> processor) throws IOException {
                    FSOperations.processFilesToRecompile(context, chunk, processor);
                }
            };
            if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
                final Map<ModuleBuildTarget, Set<File>> cleanedSources = BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, dirtyFilesHolder);
                for (Map.Entry<ModuleBuildTarget, Set<File>> entry : cleanedSources.entrySet()) {
                    final ModuleBuildTarget target = entry.getKey();
                    final Set<File> files = entry.getValue();
                    if (!files.isEmpty()) {
                        final SourceToOutputMapping mapping = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
                        for (File srcFile : files) {
                            mapping.setOutputs(srcFile.getPath(), Collections.<String>emptyList());
                        }
                    }
                }
            }
            BUILDER_CATEGORY_LOOP: for (BuilderCategory category : BuilderCategory.values()) {
                final List<ModuleLevelBuilder> builders = myBuilderRegistry.getBuilders(category);
                if (category == BuilderCategory.CLASS_POST_PROCESSOR) {
                    // ensure changes from instrumenters are visible to class post-processors
                    saveInstrumentedClasses(outputConsumer);
                }
                if (builders.isEmpty()) {
                    continue;
                }
                try {
                    for (ModuleLevelBuilder builder : builders) {
                        processDeletedPaths(context, chunk.getTargets());
                        long start = System.nanoTime();
                        int processedSourcesBefore = outputConsumer.getNumberOfProcessedSources();
                        final ModuleLevelBuilder.ExitCode buildResult = builder.build(context, chunk, dirtyFilesHolder, outputConsumer);
                        storeBuilderStatistics(builder, System.nanoTime() - start, outputConsumer.getNumberOfProcessedSources() - processedSourcesBefore);
                        doneSomething |= (buildResult != ModuleLevelBuilder.ExitCode.NOTHING_DONE);
                        if (buildResult == ModuleLevelBuilder.ExitCode.ABORT) {
                            throw new StopBuildException("Builder " + builder.getPresentableName() + " requested build stop");
                        }
                        context.checkCanceled();
                        if (buildResult == ModuleLevelBuilder.ExitCode.ADDITIONAL_PASS_REQUIRED) {
                            nextPassRequired = true;
                        } else if (buildResult == ModuleLevelBuilder.ExitCode.CHUNK_REBUILD_REQUIRED) {
                            if (!rebuildFromScratchRequested && !JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
                                LOG.info("Builder " + builder.getPresentableName() + " requested rebuild of module chunk " + chunk.getName());
                                // allow rebuild from scratch only once per chunk
                                rebuildFromScratchRequested = true;
                                try {
                                    // forcibly mark all files in the chunk dirty
                                    context.getProjectDescriptor().fsState.clearContextRoundData(context);
                                    FSOperations.markDirty(context, CompilationRound.NEXT, chunk, null);
                                    // reverting to the beginning
                                    myTargetsProcessed -= (buildersPassed * modulesInChunk) / stageCount;
                                    stageCount = myTotalModuleLevelBuilderCount;
                                    buildersPassed = 0;
                                    nextPassRequired = true;
                                    outputConsumer.clear();
                                    break BUILDER_CATEGORY_LOOP;
                                } catch (Exception e) {
                                    throw new ProjectBuildException(e);
                                }
                            } else {
                                LOG.debug("Builder " + builder.getPresentableName() + " requested second chunk rebuild");
                            }
                        }
                        buildersPassed++;
                        updateDoneFraction(context, modulesInChunk / (stageCount));
                    }
                } finally {
                    final boolean moreToCompile = JavaBuilderUtil.updateMappingsOnRoundCompletion(context, dirtyFilesHolder, chunk);
                    if (moreToCompile) {
                        nextPassRequired = true;
                    }
                    if (nextPassRequired && !rebuildFromScratchRequested) {
                        // recalculate basis
                        myTargetsProcessed -= (buildersPassed * modulesInChunk) / stageCount;
                        stageCount += myTotalModuleLevelBuilderCount;
                        myTargetsProcessed += (buildersPassed * modulesInChunk) / stageCount;
                    }
                }
            }
        } while (nextPassRequired);
    } finally {
        saveInstrumentedClasses(outputConsumer);
        outputConsumer.fireFileGeneratedEvents();
        outputConsumer.clear();
        for (BuilderCategory category : BuilderCategory.values()) {
            for (ModuleLevelBuilder builder : myBuilderRegistry.getBuilders(category)) {
                builder.chunkBuildFinished(context, chunk);
            }
        }
    }
    return doneSomething;
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) IOException(java.io.IOException) MappingFailedException(com.intellij.util.io.MappingFailedException) DirtyFilesHolderBase(org.jetbrains.jps.builders.impl.DirtyFilesHolderBase) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) SmartList(com.intellij.util.SmartList) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)2 DirtyFilesHolderBase (org.jetbrains.jps.builders.impl.DirtyFilesHolderBase)2 SmartList (com.intellij.util.SmartList)1 MultiMap (com.intellij.util.containers.MultiMap)1 MappingFailedException (com.intellij.util.io.MappingFailedException)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BuildOutputConsumerImpl (org.jetbrains.jps.builders.impl.BuildOutputConsumerImpl)1 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)1 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)1 SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)1