use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class BuildSession method runBuild.
private void runBuild(final MessageHandler msgHandler, CanceledStatus cs) throws Throwable {
final File dataStorageRoot = Utils.getDataStorageRoot(myProjectPath);
if (dataStorageRoot == null) {
msgHandler.processMessage(new CompilerMessage("build", BuildMessage.Kind.ERROR, "Cannot determine build data storage root for project " + myProjectPath));
return;
}
final boolean storageFilesAbsent = !dataStorageRoot.exists() || !new File(dataStorageRoot, FS_STATE_FILE).exists();
if (storageFilesAbsent) {
// invoked the very first time for this project
myBuildRunner.setForceCleanCaches(true);
}
final ProjectDescriptor preloadedProject = myPreloadedData != null ? myPreloadedData.getProjectDescriptor() : null;
final DataInputStream fsStateStream = storageFilesAbsent || preloadedProject != null || myInitialFSDelta == null ? /*this will force FS rescan*/
null : createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
if (fsStateStream != null || myPreloadedData != null) {
// optimization: check whether we can skip the build
final boolean hasWorkFlag = fsStateStream != null ? fsStateStream.readBoolean() : myPreloadedData.hasWorkToDo();
final boolean hasWorkToDoWithModules = hasWorkFlag || myInitialFSDelta == null;
if (!myForceModelLoading && (myBuildType == BuildType.BUILD || myBuildType == BuildType.UP_TO_DATE_CHECK) && !hasWorkToDoWithModules && scopeContainsModulesOnlyForIncrementalMake(myScopes) && !containsChanges(myInitialFSDelta)) {
final DataInputStream storedFsData;
if (myPreloadedData != null) {
storedFsData = createFSDataStream(dataStorageRoot, myInitialFSDelta.getOrdinal());
if (storedFsData != null) {
// skip hasWorkToDo flag
storedFsData.readBoolean();
}
} else {
storedFsData = fsStateStream;
}
if (storedFsData != null) {
updateFsStateOnDisk(dataStorageRoot, storedFsData, myInitialFSDelta.getOrdinal());
LOG.info("No changes found since last build. Exiting.");
if (preloadedProject != null) {
preloadedProject.release();
}
return;
}
}
}
final BuildFSState fsState = preloadedProject != null ? preloadedProject.fsState : new BuildFSState(false);
try {
final ProjectDescriptor pd;
if (preloadedProject != null) {
pd = preloadedProject;
final List<BuildMessage> preloadMessages = myPreloadedData.getLoadMessages();
if (!preloadMessages.isEmpty()) {
// replay preload-time messages, so that they are delivered to the IDE
for (BuildMessage message : preloadMessages) {
msgHandler.processMessage(message);
}
}
if (myInitialFSDelta == null || myPreloadedData.getFsEventOrdinal() + 1L != myInitialFSDelta.getOrdinal()) {
// FS rescan was forced
fsState.clearAll();
} else {
// apply events to already loaded state
try {
applyFSEvent(pd, myInitialFSDelta, false);
} catch (Throwable e) {
LOG.error(e);
fsState.clearAll();
}
}
} else {
// standard case
pd = myBuildRunner.load(msgHandler, dataStorageRoot, fsState);
TimingLog.LOG.debug("Project descriptor loaded");
if (fsStateStream != null) {
try {
try {
fsState.load(fsStateStream, pd.getModel(), pd.getBuildRootIndex());
applyFSEvent(pd, myInitialFSDelta, false);
TimingLog.LOG.debug("FS Delta loaded");
} finally {
fsStateStream.close();
}
} catch (Throwable e) {
LOG.error(e);
fsState.clearAll();
}
}
}
myProjectDescriptor = pd;
myLastEventOrdinal = myInitialFSDelta != null ? myInitialFSDelta.getOrdinal() : 0L;
// free memory
myInitialFSDelta = null;
// ensure events from controller are processed after FSState initialization
myEventsProcessor.startProcessing();
myBuildRunner.runBuild(pd, cs, myConstantSearch, msgHandler, myBuildType, myScopes, false);
TimingLog.LOG.debug("Build finished");
} finally {
saveData(fsState, dataStorageRoot);
}
}
use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class ChainedTargetsBuildListener method filesGenerated.
@Override
public void filesGenerated(FileGeneratedEvent event) {
final ProjectDescriptor pd = myContext.getProjectDescriptor();
final BuildFSState fsState = pd.fsState;
for (Pair<String, String> pair : event.getPaths()) {
final String relativePath = pair.getSecond();
final File file = relativePath.equals(".") ? new File(pair.getFirst()) : new File(pair.getFirst(), relativePath);
for (BuildRootDescriptor desc : pd.getBuildRootIndex().findAllParentDescriptors(file, myContext)) {
if (!event.getSourceTarget().equals(desc.getTarget())) {
// It is assumed that those files will be explicitly marked dirty by particular builder, if needed.
try {
fsState.markDirty(myContext, file, desc, pd.timestamps.getStorage(), false);
} catch (IOException ignored) {
}
}
}
}
}
Aggregations