Search in sources :

Example 6 with BuildDataCorruptedException

use of org.jetbrains.jps.builders.storage.BuildDataCorruptedException in project intellij-community by JetBrains.

the class JavaBuilderUtil method updateMappings.

/**
   * @param filesToCompile   files compiled in this round
   * @param markDirtyRound   compilation round at which dirty files should be visible to builders
   * @return true if additional compilation pass is required, false otherwise
   * @throws Exception
   */
private static boolean updateMappings(CompileContext context, final Mappings delta, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, ModuleChunk chunk, Collection<File> filesToCompile, Collection<File> successfullyCompiled, final CompilationRound markDirtyRound, @Nullable FileFilter skipMarkingDirtyFilter) throws IOException {
    try {
        boolean performIntegrate = true;
        boolean additionalPassRequired = false;
        final Set<String> removedPaths = getRemovedPaths(chunk, dirtyFilesHolder);
        final Mappings globalMappings = context.getProjectDescriptor().dataManager.getMappings();
        final boolean errorsDetected = Utils.errorsDetected(context);
        if (!isForcedRecompilationAllJavaModules(context)) {
            if (context.shouldDifferentiate(chunk)) {
                context.processMessage(new ProgressMessage("Checking dependencies... [" + chunk.getPresentableShortName() + "]"));
                final Set<File> allCompiledFiles = getFilesContainer(context, ALL_COMPILED_FILES_KEY);
                final Set<File> allAffectedFiles = getFilesContainer(context, ALL_AFFECTED_FILES_KEY);
                // mark as affected all files that were dirty before compilation
                allAffectedFiles.addAll(filesToCompile);
                // accumulate all successfully compiled in this round
                allCompiledFiles.addAll(successfullyCompiled);
                // unmark as affected all successfully compiled
                allAffectedFiles.removeAll(successfullyCompiled);
                final Set<File> affectedBeforeDif = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                affectedBeforeDif.addAll(allAffectedFiles);
                final Set<File> compiledWithErrors = getFilesContainer(context, COMPILED_WITH_ERRORS_KEY);
                COMPILED_WITH_ERRORS_KEY.set(context, null);
                final ModulesBasedFileFilter moduleBasedFilter = new ModulesBasedFileFilter(context, chunk);
                final boolean incremental = globalMappings.differentiateOnIncrementalMake(delta, removedPaths, filesToCompile, compiledWithErrors, allCompiledFiles, allAffectedFiles, moduleBasedFilter, CONSTANT_SEARCH_SERVICE.get(context));
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Differentiate Results:");
                    LOG.debug("   Compiled Files:");
                    for (final File c : allCompiledFiles) {
                        LOG.debug("      " + c.getAbsolutePath());
                    }
                    LOG.debug("   Affected Files:");
                    for (final File c : allAffectedFiles) {
                        LOG.debug("      " + c.getAbsolutePath());
                    }
                    LOG.debug("End Of Differentiate Results.");
                }
                if (incremental) {
                    final Set<File> newlyAffectedFiles = new HashSet<>(allAffectedFiles);
                    newlyAffectedFiles.removeAll(affectedBeforeDif);
                    final String infoMessage = "Dependency analysis found " + newlyAffectedFiles.size() + " affected files";
                    LOG.info(infoMessage);
                    context.processMessage(new ProgressMessage(infoMessage));
                    removeFilesAcceptedByFilter(newlyAffectedFiles, skipMarkingDirtyFilter);
                    if (!newlyAffectedFiles.isEmpty()) {
                        if (LOG.isDebugEnabled()) {
                            for (File file : newlyAffectedFiles) {
                                LOG.debug("affected file: " + file.getPath());
                            }
                            final List<Pair<File, JpsModule>> wrongFiles = checkAffectedFilesInCorrectModules(context, newlyAffectedFiles, moduleBasedFilter);
                            if (!wrongFiles.isEmpty()) {
                                LOG.debug("Wrong affected files for module chunk " + chunk.getName() + ": ");
                                for (Pair<File, JpsModule> pair : wrongFiles) {
                                    final String name = pair.second != null ? pair.second.getName() : "null";
                                    LOG.debug("\t[" + name + "] " + pair.first.getPath());
                                }
                            }
                        }
                        for (File file : newlyAffectedFiles) {
                            FSOperations.markDirtyIfNotDeleted(context, markDirtyRound, file);
                        }
                        additionalPassRequired = isCompileJavaIncrementally(context) && chunkContainsAffectedFiles(context, chunk, newlyAffectedFiles);
                    }
                } else {
                    // non-incremental mode
                    final String messageText = "Marking " + chunk.getPresentableShortName() + " and direct dependants for recompilation";
                    LOG.info("Non-incremental mode: " + messageText);
                    context.processMessage(new ProgressMessage(messageText));
                    final boolean alreadyMarkedDirty = FSOperations.isMarkedDirty(context, chunk);
                    additionalPassRequired = isCompileJavaIncrementally(context) && !alreadyMarkedDirty;
                    if (alreadyMarkedDirty) {
                        // need this to make sure changes data stored in Delta is complete
                        globalMappings.differentiateOnNonIncrementalMake(delta, removedPaths, filesToCompile);
                    } else {
                        performIntegrate = false;
                    }
                    FileFilter toBeMarkedFilter = skipMarkingDirtyFilter == null ? null : new NegationFileFilter(skipMarkingDirtyFilter);
                    FSOperations.markDirtyRecursively(context, markDirtyRound, chunk, toBeMarkedFilter);
                }
            } else {
                if (!errorsDetected) {
                    // makes sense only if we are going to integrate changes
                    globalMappings.differentiateOnNonIncrementalMake(delta, removedPaths, filesToCompile);
                }
            }
        } else {
            if (!errorsDetected) {
                // makes sense only if we are going to integrate changes
                globalMappings.differentiateOnRebuild(delta);
            }
        }
        if (errorsDetected) {
            // will be compiled during the first phase of the next make
            return false;
        }
        if (performIntegrate) {
            context.processMessage(new ProgressMessage("Updating dependency information... [" + chunk.getPresentableShortName() + "]"));
            globalMappings.integrate(delta);
        }
        return additionalPassRequired;
    } catch (BuildDataCorruptedException e) {
        throw e.getCause();
    } finally {
        // clean progress messages
        context.processMessage(new ProgressMessage(""));
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) THashSet(gnu.trove.THashSet) JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) Mappings(org.jetbrains.jps.builders.java.dependencyView.Mappings) FileFilter(java.io.FileFilter) File(java.io.File) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair)

Example 7 with BuildDataCorruptedException

use of org.jetbrains.jps.builders.storage.BuildDataCorruptedException in project intellij-community by JetBrains.

the class IncProjectBuilder method build.

public void build(CompileScope scope, boolean forceCleanCaches) throws RebuildRequestedException {
    final LowMemoryWatcher memWatcher = LowMemoryWatcher.register(() -> {
        JavacMain.clearCompilerZipFileCache();
        myProjectDescriptor.dataManager.flush(false);
        myProjectDescriptor.timestamps.getStorage().force();
    });
    startTempDirectoryCleanupTask();
    CompileContextImpl context = null;
    try {
        context = createContext(scope);
        runBuild(context, forceCleanCaches);
        myProjectDescriptor.dataManager.saveVersion();
        reportRebuiltModules(context);
        reportUnprocessedChanges(context);
    } catch (StopBuildException e) {
        reportRebuiltModules(context);
        reportUnprocessedChanges(context);
        // some builder decided to stop the build
        // report optional progress message if any
        final String msg = e.getMessage();
        if (!StringUtil.isEmptyOrSpaces(msg)) {
            myMessageDispatcher.processMessage(new ProgressMessage(msg));
        }
    } catch (BuildDataCorruptedException e) {
        LOG.info(e);
        requestRebuild(e, e);
    } catch (ProjectBuildException e) {
        LOG.info(e);
        final Throwable cause = e.getCause();
        if (cause instanceof PersistentEnumerator.CorruptedException || cause instanceof MappingFailedException || cause instanceof IOException || cause instanceof BuildDataCorruptedException) {
            requestRebuild(e, cause);
        } else {
            // should stop the build with error
            final String errMessage = e.getMessage();
            final CompilerMessage msg;
            if (StringUtil.isEmptyOrSpaces(errMessage)) {
                msg = new CompilerMessage("", cause != null ? cause : e);
            } else {
                final String causeMessage = cause != null ? cause.getMessage() : "";
                msg = new CompilerMessage("", BuildMessage.Kind.ERROR, StringUtil.isEmptyOrSpaces(causeMessage) || errMessage.trim().endsWith(causeMessage) ? errMessage : errMessage + ": " + causeMessage);
            }
            myMessageDispatcher.processMessage(msg);
        }
    } finally {
        memWatcher.stop();
        flushContext(context);
        // wait for async tasks
        final CanceledStatus status = context == null ? CanceledStatus.NULL : context.getCancelStatus();
        synchronized (myAsyncTasks) {
            for (Future task : myAsyncTasks) {
                if (status.isCanceled()) {
                    break;
                }
                waitForTask(status, task);
            }
        }
    }
}
Also used : CanceledStatus(org.jetbrains.jps.api.CanceledStatus) MappingFailedException(com.intellij.util.io.MappingFailedException) IOException(java.io.IOException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException)

Example 8 with BuildDataCorruptedException

use of org.jetbrains.jps.builders.storage.BuildDataCorruptedException in project intellij-community by JetBrains.

the class IncProjectBuilder method buildTargetsChunk.

private void buildTargetsChunk(CompileContext context, final BuildTargetChunk chunk) throws ProjectBuildException {
    final BuildFSState fsState = myProjectDescriptor.fsState;
    boolean doneSomething;
    try {
        context.setCompilationStartStamp(chunk.getTargets(), System.currentTimeMillis());
        sendBuildingTargetMessages(chunk.getTargets(), BuildingTargetProgressMessage.Event.STARTED);
        Utils.ERRORS_DETECTED_KEY.set(context, Boolean.FALSE);
        for (BuildTarget<?> target : chunk.getTargets()) {
            BuildOperations.ensureFSStateInitialized(context, target);
        }
        doneSomething = processDeletedPaths(context, chunk.getTargets());
        fsState.beforeChunkBuildStart(context, chunk);
        doneSomething |= runBuildersForChunk(context, chunk);
        fsState.clearContextRoundData(context);
        fsState.clearContextChunk(context);
        BuildOperations.markTargetsUpToDate(context, chunk);
    //if (doneSomething && GENERATE_CLASSPATH_INDEX) {
    //  myAsyncTasks.add(SharedThreadPool.getInstance().executeOnPooledThread(new Runnable() {
    //    @Override
    //    public void run() {
    //      createClasspathIndex(chunk);
    //    }
    //  }));
    //}
    } catch (BuildDataCorruptedException | ProjectBuildException e) {
        throw e;
    } catch (Throwable e) {
        final StringBuilder message = new StringBuilder();
        message.append(chunk.getPresentableName()).append(": ").append(e.getClass().getName());
        final String exceptionMessage = e.getMessage();
        if (exceptionMessage != null) {
            message.append(": ").append(exceptionMessage);
        }
        throw new ProjectBuildException(message.toString(), e);
    } finally {
        for (BuildRootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().clearTempRoots(context)) {
            context.getProjectDescriptor().fsState.clearRecompile(rd);
        }
        try {
            // restore deleted paths that were not processed by 'integrate'
            final Map<BuildTarget<?>, Collection<String>> map = Utils.REMOVED_SOURCES_KEY.get(context);
            if (map != null) {
                for (Map.Entry<BuildTarget<?>, Collection<String>> entry : map.entrySet()) {
                    final BuildTarget<?> target = entry.getKey();
                    final Collection<String> paths = entry.getValue();
                    if (paths != null) {
                        for (String path : paths) {
                            fsState.registerDeleted(context, target, new File(path), null);
                        }
                    }
                }
            }
        } catch (IOException e) {
            //noinspection ThrowFromFinallyBlock
            throw new ProjectBuildException(e);
        } finally {
            Utils.REMOVED_SOURCES_KEY.set(context, null);
            sendBuildingTargetMessages(chunk.getTargets(), BuildingTargetProgressMessage.Event.FINISHED);
        }
    }
}
Also used : IOException(java.io.IOException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 9 with BuildDataCorruptedException

use of org.jetbrains.jps.builders.storage.BuildDataCorruptedException in project intellij-community by JetBrains.

the class IntObjectPersistentMultiMaplet method put.

@Override
public void put(final int key, final Collection<V> value) {
    try {
        myCache.remove(key);
        myMap.appendData(key, new PersistentHashMap.ValueDataAppender() {

            public void append(DataOutput out) throws IOException {
                for (V v : value) {
                    myValueExternalizer.save(out, v);
                }
            }
        });
    } catch (IOException e) {
        throw new BuildDataCorruptedException(e);
    }
}
Also used : BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) PersistentHashMap(com.intellij.util.io.PersistentHashMap)

Example 10 with BuildDataCorruptedException

use of org.jetbrains.jps.builders.storage.BuildDataCorruptedException in project intellij-community by JetBrains.

the class ClassRepr method toStream.

@Override
public void toStream(final DependencyContext context, final PrintStream stream) {
    super.toStream(context, stream);
    stream.print("      Filename   : ");
    stream.println(context.getValue(myFileName));
    stream.print("      Superclass : ");
    stream.println(mySuperClass == null ? "<null>" : mySuperClass.getDescr(context));
    stream.print("      Interfaces : ");
    final TypeRepr.AbstractType[] is = myInterfaces.toArray(new TypeRepr.AbstractType[myInterfaces.size()]);
    Arrays.sort(is, Comparator.comparing(o -> o.getDescr(context)));
    for (final TypeRepr.AbstractType t : is) {
        stream.print(t.getDescr(context));
        stream.print(" ");
    }
    stream.println();
    stream.print("      Targets    : ");
    final ElemType[] es = myAnnotationTargets.toArray(new ElemType[myAnnotationTargets.size()]);
    Arrays.sort(es);
    for (final ElemType e : es) {
        stream.print(e);
        stream.print("; ");
    }
    stream.println();
    stream.print("      Policy     : ");
    stream.println(myRetentionPolicy);
    stream.print("      Outer class: ");
    stream.println(context.getValue(myOuterClassName));
    stream.print("      Local class: ");
    stream.println(myIsLocal);
    stream.print("      Anonymous class: ");
    stream.println(myIsAnonymous);
    stream.println("      Fields:");
    final FieldRepr[] fs = myFields.toArray(new FieldRepr[myFields.size()]);
    Arrays.sort(fs, (o1, o2) -> {
        if (o1.name == o2.name) {
            return o1.myType.getDescr(context).compareTo(o2.myType.getDescr(context));
        }
        return context.getValue(o1.name).compareTo(context.getValue(o2.name));
    });
    for (final FieldRepr f : fs) {
        f.toStream(context, stream);
    }
    stream.println("      End Of Fields");
    stream.println("      Methods:");
    final MethodRepr[] ms = myMethods.toArray(new MethodRepr[myMethods.size()]);
    Arrays.sort(ms, (o1, o2) -> {
        if (o1.name == o2.name) {
            final String d1 = o1.myType.getDescr(context);
            final String d2 = o2.myType.getDescr(context);
            final int c = d1.compareTo(d2);
            if (c == 0) {
                final int l1 = o1.myArgumentTypes.length;
                final int l2 = o2.myArgumentTypes.length;
                if (l1 == l2) {
                    for (int i = 0; i < l1; i++) {
                        final String d11 = o1.myArgumentTypes[i].getDescr(context);
                        final String d22 = o2.myArgumentTypes[i].getDescr(context);
                        final int cc = d11.compareTo(d22);
                        if (cc != 0) {
                            return cc;
                        }
                    }
                    return 0;
                }
                return l1 - l2;
            }
            return c;
        }
        return context.getValue(o1.name).compareTo(context.getValue(o2.name));
    });
    for (final MethodRepr m : ms) {
        m.toStream(context, stream);
    }
    stream.println("      End Of Methods");
    stream.println("      Usages:");
    final List<String> usages = new LinkedList<>();
    for (final UsageRepr.Usage u : myUsages) {
        final ByteArrayOutputStream bas = new ByteArrayOutputStream();
        u.toStream(myContext, new PrintStream(bas));
        try {
            bas.close();
        } catch (final IOException e) {
            throw new BuildDataCorruptedException(e);
        }
        usages.add(bas.toString());
    }
    Collections.sort(usages);
    for (final String s : usages) {
        stream.println(s);
    }
    stream.println("      End Of Usages");
}
Also used : Nullable(org.jetbrains.annotations.Nullable) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) java.util(java.util) DataExternalizer(com.intellij.util.io.DataExternalizer) java.io(java.io) Opcodes(org.jetbrains.org.objectweb.asm.Opcodes) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull) DataInputOutputUtil(com.intellij.util.io.DataInputOutputUtil) RetentionPolicy(java.lang.annotation.RetentionPolicy) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException)

Aggregations

BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)26 IOException (java.io.IOException)8 PersistentHashMap (com.intellij.util.io.PersistentHashMap)4 File (java.io.File)4 THashSet (gnu.trove.THashSet)3 NotNull (org.jetbrains.annotations.NotNull)3 DataExternalizer (com.intellij.util.io.DataExternalizer)2 DataInputOutputUtil (com.intellij.util.io.DataInputOutputUtil)2 java.io (java.io)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)2 JpsModule (org.jetbrains.jps.model.module.JpsModule)2 AtomicNotNullLazyValue (com.intellij.openapi.util.AtomicNotNullLazyValue)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 Processor (com.intellij.util.Processor)1 MultiMap (com.intellij.util.containers.MultiMap)1 SLRUCache (com.intellij.util.containers.SLRUCache)1 KeyDescriptor (com.intellij.util.io.KeyDescriptor)1 MappingFailedException (com.intellij.util.io.MappingFailedException)1