clear caches in jps server on roots change and project close

This commit is contained in:
Eugene Zhuravlev
2011-10-05 22:50:03 +02:00
parent 0f33d62785
commit c0435798cf
6 changed files with 72 additions and 15 deletions
@@ -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<String> 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<String, String> pathVariables, final List<GlobalLibrary> sdkAndLibs) throws Exception {
checkConnected();
return sendRequest(ProtoUtil.createSetupRequest(pathVariables, sdkAndLibs), null);
}
@NotNull
public RequestFuture sendProjectReloadRequest(Collection<String> 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) {
@@ -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<String, String> pathVars = new HashMap<String, String>();
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: {
@@ -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<Project, MessageBusConnection> myConnections = new HashMap<Project, MessageBusConnection>();
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);
}
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.