diff --git a/java/compiler/compile-server/src/org/jetbrains/jpsservice/Client.java b/java/compiler/compile-server/src/org/jetbrains/jpsservice/Client.java index fd4b02ff0384..eb888f3f7a43 100644 --- a/java/compiler/compile-server/src/org/jetbrains/jpsservice/Client.java +++ b/java/compiler/compile-server/src/org/jetbrains/jpsservice/Client.java @@ -14,10 +14,7 @@ import org.jetbrains.jpsservice.impl.JpsClientMessageHandler; import org.jetbrains.jpsservice.impl.ProtoUtil; import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; @@ -92,9 +89,7 @@ public class Client { @NotNull public RequestFuture sendCompileRequest(String projectId, List modules, boolean rebuild, JpsServerResponseHandler handler) throws Exception{ - if (myState.get() != State.CONNECTED) { - throw new Exception("Client not connected"); - } + checkConnected(); return sendRequest( rebuild? ProtoUtil.createRebuildRequest(projectId, modules) : ProtoUtil.createMakeRequest(projectId, modules), handler @@ -103,18 +98,26 @@ public class Client { @NotNull public RequestFuture sendShutdownRequest() throws Exception { - if (myState.get() != State.CONNECTED) { - throw new Exception("Client not connected"); - } + checkConnected(); return sendRequest(ProtoUtil.createShutdownRequest(true), null); } @NotNull public RequestFuture sendSetupRequest(final Map pathVariables, final List sdkAndLibs) throws Exception { + checkConnected(); + return sendRequest(ProtoUtil.createSetupRequest(pathVariables, sdkAndLibs), null); + } + + @NotNull + public RequestFuture sendProjectReloadRequest(Collection projectPaths) throws Exception { + checkConnected(); + return sendRequest(ProtoUtil.createReloadProjectRequest(projectPaths), null); + } + + private void checkConnected() throws Exception { if (myState.get() != State.CONNECTED) { throw new Exception("Client not connected"); } - return sendRequest(ProtoUtil.createSetupRequest(pathVariables, sdkAndLibs), null); } private RequestFuture sendRequest(JpsRemoteProto.Message.Request request, @Nullable JpsServerResponseHandler handler) { diff --git a/java/compiler/compile-server/src/org/jetbrains/jpsservice/impl/JpsServerMessageHandler.java b/java/compiler/compile-server/src/org/jetbrains/jpsservice/impl/JpsServerMessageHandler.java index 6e91e9d02a05..da7376fbf234 100644 --- a/java/compiler/compile-server/src/org/jetbrains/jpsservice/impl/JpsServerMessageHandler.java +++ b/java/compiler/compile-server/src/org/jetbrains/jpsservice/impl/JpsServerMessageHandler.java @@ -42,11 +42,15 @@ public class JpsServerMessageHandler extends SimpleChannelHandler { else { final JpsRemoteProto.Message.Request request = message.getRequest(); final JpsRemoteProto.Message.Request.Type requestType = request.getRequestType(); + final Facade facade = Facade.getInstance(); switch (requestType) { case COMPILE_REQUEST : reply = startBuild(sessionId, ctx, request.getCompileRequest()); break; - + case RELOAD_PROJECT_COMMAND: + final JpsRemoteProto.Message.Request.ReloadProjectCommand reloadProjectCommand = request.getReloadProjectCommand(); + facade.clearProjectCache(reloadProjectCommand.getProjectIdList()); + break; case SETUP_COMMAND: final Map pathVars = new HashMap(); final JpsRemoteProto.Message.Request.SetupCommand setupCommand = request.getSetupCommand(); @@ -61,7 +65,7 @@ public class JpsServerMessageHandler extends SimpleChannelHandler { new GlobalLibrary(library.getName(), library.getPathList()) ); } - Facade.getInstance().setGlobals(libs, pathVars); + facade.setGlobals(libs, pathVars); reply = ProtoUtil.toMessage(sessionId, ProtoUtil.createCommandCompletedEvent(null)); break; @@ -93,6 +97,7 @@ public class JpsServerMessageHandler extends SimpleChannelHandler { final JpsRemoteProto.Message.Request.CompilationRequest.Type compileType = compileRequest.getCommandType(); switch (compileType) { + // todo case CLEAN: case MAKE: case REBUILD: { diff --git a/java/compiler/impl/src/com/intellij/compiler/JpsServerManager.java b/java/compiler/impl/src/com/intellij/compiler/JpsServerManager.java index bc9abf77c222..ea6b4d65a1f0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/JpsServerManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/JpsServerManager.java @@ -15,6 +15,7 @@ */ package com.intellij.compiler; +import com.intellij.ProjectTopics; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.process.OSProcessHandler; @@ -23,10 +24,15 @@ import com.intellij.openapi.application.PathMacros; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.project.ProjectManagerAdapter; import com.intellij.openapi.projectRoots.JavaSdkType; import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; +import com.intellij.openapi.roots.ModuleRootEvent; +import com.intellij.openapi.roots.ModuleRootListener; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; @@ -35,6 +41,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.net.NetUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,7 +65,8 @@ public class JpsServerManager implements ApplicationComponent{ private volatile Client myServerClient; private volatile OSProcessHandler myProcessHandler; - public JpsServerManager() { + public JpsServerManager(ProjectManager projectManager) { + projectManager.addProjectManagerListener(new ProjectWatcher()); ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { @Override public void run() { @@ -177,7 +185,7 @@ public class JpsServerManager implements ApplicationComponent{ final Sdk projectJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk(); final GeneralCommandLine cmdLine = new GeneralCommandLine(); cmdLine.setExePath(((JavaSdkType)projectJdk.getSdkType()).getVMExecutablePath(projectJdk)); - //cmdLine.addParameter("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5007"); + cmdLine.addParameter("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5007"); cmdLine.addParameter("-Xmx256m"); cmdLine.addParameter("-classpath"); @@ -223,4 +231,45 @@ public class JpsServerManager implements ApplicationComponent{ } return builder.toString(); } + + private class ProjectWatcher extends ProjectManagerAdapter { + private final Map myConnections = new HashMap(); + + public void projectOpened(final Project project) { + final MessageBusConnection conn = project.getMessageBus().connect(); + myConnections.put(project, conn); + conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() { + public void beforeRootsChange(final ModuleRootEvent event) { + sendReloadRequest(project); + } + + public void rootsChanged(final ModuleRootEvent event) { + } + }); + + } + + public void projectClosing(Project project) { + sendReloadRequest(project); + } + + public void projectClosed(Project project) { + final MessageBusConnection conn = myConnections.remove(project); + if (conn != null) { + conn.disconnect(); + } + } + + private void sendReloadRequest(Project project) { + final Client client = myServerClient; + if (client != null) { + try { + client.sendProjectReloadRequest(Collections.singletonList(project.getLocation())); + } + catch (Exception e) { + LOG.info(e); + } + } + } + } } diff --git a/lib/rt/jps-incremental/jps-facade.jar b/lib/rt/jps-incremental/jps-facade.jar index 37b9055959cf..7cc4e3de7235 100644 Binary files a/lib/rt/jps-incremental/jps-facade.jar and b/lib/rt/jps-incremental/jps-facade.jar differ diff --git a/lib/rt/jps-incremental/jps.jar b/lib/rt/jps-incremental/jps.jar index 6ec7d0104dfa..3c143522ed57 100644 Binary files a/lib/rt/jps-incremental/jps.jar and b/lib/rt/jps-incremental/jps.jar differ diff --git a/lib/rt/jps-incremental/src/jps-sources.zip b/lib/rt/jps-incremental/src/jps-sources.zip index b67a400a7ee7..b0728cda3ca5 100644 Binary files a/lib/rt/jps-incremental/src/jps-sources.zip and b/lib/rt/jps-incremental/src/jps-sources.zip differ