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(""));
}
}
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);
}
}
}
}
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);
}
}
}
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);
}
}
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");
}
Aggregations