use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class Standalone method runBuild.
public static void runBuild(JpsModelLoader loader, File dataStorageRoot, MessageHandler messageHandler, List<TargetTypeBuildScope> scopes, boolean includeDependenciesToScope) throws Exception {
final BuildRunner buildRunner = new BuildRunner(loader);
ProjectDescriptor descriptor = buildRunner.load(messageHandler, dataStorageRoot, new BuildFSState(true));
try {
buildRunner.runBuild(descriptor, CanceledStatus.NULL, null, messageHandler, BuildType.BUILD, scopes, includeDependenciesToScope);
} finally {
descriptor.release();
}
}
use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class JpsBuildTestCase method createProjectDescriptor.
protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
try {
BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
ProjectTimestamps timestamps = new ProjectTimestamps(myDataStorageRoot, targetsState);
BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, true);
return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class BuildOperations method initTargetFSState.
private static void initTargetFSState(CompileContext context, BuildTarget<?> target, final boolean forceMarkDirty) throws IOException {
final ProjectDescriptor pd = context.getProjectDescriptor();
final Timestamps timestamps = pd.timestamps.getStorage();
final THashSet<File> currentFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
FSOperations.markDirtyFiles(context, target, CompilationRound.CURRENT, timestamps, forceMarkDirty, currentFiles, null);
// handle deleted paths
final BuildFSState fsState = pd.fsState;
fsState.clearDeletedPaths(target);
final SourceToOutputMapping sourceToOutputMap = pd.dataManager.getSourceToOutputMap(target);
for (final Iterator<String> it = sourceToOutputMap.getSourcesIterator(); it.hasNext(); ) {
final String path = it.next();
// can check if the file exists
final File file = new File(path);
if (!currentFiles.contains(file)) {
fsState.registerDeleted(context, target, file, timestamps);
}
}
pd.fsState.markInitialScanPerformed(target);
}
use of org.jetbrains.jps.incremental.fs.BuildFSState in project intellij-community by JetBrains.
the class BuildMain method main.
public static void main(String[] args) throws Throwable {
try {
final long processStart = System.currentTimeMillis();
final String startMessage = "Build process started. Classpath: " + System.getProperty("java.class.path");
System.out.println(startMessage);
LOG.info(startMessage);
final String host = args[HOST_ARG];
final int port = Integer.parseInt(args[PORT_ARG]);
final UUID sessionId = UUID.fromString(args[SESSION_ID_ARG]);
@SuppressWarnings("ConstantConditions") final File systemDir = new File(FileUtil.toCanonicalPath(args[SYSTEM_DIR_ARG]));
Utils.setSystemRoot(systemDir);
final long connectStart = System.currentTimeMillis();
// IDEA-123132, let's try again
for (int attempt = 0; attempt < 3; attempt++) {
try {
ourEventLoopGroup = new NioEventLoopGroup(1, SharedThreadPool.getInstance());
break;
} catch (IllegalStateException e) {
if (attempt == 2) {
printErrorAndExit(host, port, e);
return;
} else {
LOG.warn("Cannot create event loop, attempt #" + attempt, e);
try {
//noinspection BusyWait
Thread.sleep(10 * (attempt + 1));
} catch (InterruptedException ignored) {
}
}
}
}
final Bootstrap bootstrap = new Bootstrap().group(ourEventLoopGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), new MyMessageHandler(sessionId));
}
}).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true);
final ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)).awaitUninterruptibly();
final boolean success = future.isSuccess();
if (success) {
LOG.info("Connection to IDE established in " + (System.currentTimeMillis() - connectStart) + " ms");
final String projectPathToPreload = System.getProperty(PRELOAD_PROJECT_PATH, null);
final String globalsPathToPreload = System.getProperty(PRELOAD_CONFIG_PATH, null);
if (projectPathToPreload != null && globalsPathToPreload != null) {
final PreloadedData data = new PreloadedData();
ourPreloadedData = data;
try {
// this will pre-load all FS optimizations
FileSystemUtil.getAttributes(projectPathToPreload);
final BuildRunner runner = new BuildRunner(new JpsModelLoaderImpl(projectPathToPreload, globalsPathToPreload, null));
data.setRunner(runner);
final File dataStorageRoot = Utils.getDataStorageRoot(projectPathToPreload);
final BuildFSState fsState = new BuildFSState(false);
final ProjectDescriptor pd = runner.load(new MessageHandler() {
@Override
public void processMessage(BuildMessage msg) {
data.addMessage(msg);
}
}, dataStorageRoot, fsState);
data.setProjectDescriptor(pd);
try {
final File fsStateFile = new File(dataStorageRoot, BuildSession.FS_STATE_FILE);
final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(fsStateFile)));
try {
final int version = in.readInt();
if (version == BuildFSState.VERSION) {
final long savedOrdinal = in.readLong();
// must skip "has-work-to-do" flag
final boolean hasWorkToDo = in.readBoolean();
fsState.load(in, pd.getModel(), pd.getBuildRootIndex());
data.setFsEventOrdinal(savedOrdinal);
data.setHasHasWorkToDo(hasWorkToDo);
}
} finally {
in.close();
}
} catch (FileNotFoundException ignored) {
} catch (IOException e) {
LOG.info("Error pre-loading FS state", e);
fsState.clearAll();
}
// preloading target configurations
final BuildTargetsState targetsState = pd.getTargetsState();
for (BuildTarget<?> target : pd.getBuildTargetIndex().getAllTargets()) {
targetsState.getTargetConfiguration(target);
}
BuilderRegistry.getInstance();
LOG.info("Pre-loaded process ready in " + (System.currentTimeMillis() - processStart) + " ms");
} catch (Throwable e) {
LOG.info("Failed to pre-load project " + projectPathToPreload, e);
// just failed to preload the project, the situation will be handled later, when real build starts
}
} else if (projectPathToPreload != null || globalsPathToPreload != null) {
LOG.info("Skipping project pre-loading step: both paths to project configuration files and path to global settings must be specified");
}
future.channel().writeAndFlush(CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createParamRequest()));
} else {
printErrorAndExit(host, port, future.cause());
}
} catch (Throwable e) {
LOG.error(e);
throw e;
}
}
use of org.jetbrains.jps.incremental.fs.BuildFSState 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);
}
}
}
Aggregations