void (String[] args) { try { final long processStart = System.nanoTime(); final String startMessage = "Build process started. Classpath: " + System.getProperty("java.class.path"); System.out.println(startMessage); LOG.info("=================================================="); 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]); final File systemDir = new File(FileUtilRt.toCanonicalPath(args[SYSTEM_DIR_ARG], File.separatorChar, true)); Utils.setSystemRoot(systemDir); final long connectStart = System.nanoTime(); // IDEA-123132, let's try again for (int attempt = 0; ; attempt++) { try { ourEventLoopGroup = new NioEventLoopGroup(1, (ThreadFactory)r -> new Thread(r, "JPS event loop")); break; } catch (IllegalStateException e) { if (attempt == 2) { printErrorAndExit(host, port, e); return; } else { LOG.warn("Cannot create event loop, attempt #" + attempt, e); TimeoutUtil.sleep(10L * (attempt + 1)); } } } final Bootstrap bootstrap = new Bootstrap().group(ourEventLoopGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<>() { @Override protected void initChannel(Channel channel) { 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 " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - 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 { final BuildRunner runner = new BuildRunner(new JpsModelLoaderImpl(projectPathToPreload, globalsPathToPreload, false, 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); final File fsStateFile = new File(dataStorageRoot, BuildSession.FS_STATE_FILE); try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(fsStateFile)))) { final int version = in.readInt(); if (version == BuildFSState.VERSION) { final long savedOrdinal = in.readLong(); final boolean hasWorkToDo = in.readBoolean(); fsState.load(in, pd.getModel(), pd.getBuildRootIndex()); data.setFsEventOrdinal(savedOrdinal); data.setHasHasWorkToDo(hasWorkToDo); } } catch (FileNotFoundException ignored) { } catch (IOException e) { LOG.info("Error pre-loading FS state", e); fsState.clearAll(); } // preloading target configurations and pre-calculating target dirty state final BuildTargetsState targetsState = pd.getTargetsState(); for (BuildTarget<?> target : pd.getBuildTargetIndex().getAllTargets()) { targetsState.getTargetConfiguration(target).isTargetDirty(pd); } //noinspection ResultOfMethodCallIgnored BuilderRegistry.getInstance(); JpsServiceManager.getInstance().getExtensions(PreloadedDataExtension.class).forEach(ext-> ext.preloadData(data)); LOG.info("Pre-loaded process ready in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - processStart) + " ms"); } catch (Throwable e) { LOG.info("Failed to pre-load project " + projectPathToPreload, e); // 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; } }