mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fsState management inside IDEA, initial
This commit is contained in:
@@ -29,7 +29,7 @@ import com.intellij.compiler.make.ChangedConstantsDependencyProcessor;
|
||||
import com.intellij.compiler.make.DependencyCache;
|
||||
import com.intellij.compiler.progress.CompilerTask;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.compiler.server.BuildMessageHandler;
|
||||
import com.intellij.compiler.server.DefaultMessageHandler;
|
||||
import com.intellij.diagnostic.IdeErrorsDialog;
|
||||
import com.intellij.diagnostic.PluginException;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -549,7 +549,7 @@ public class CompileDriver {
|
||||
else {
|
||||
final BuildManager buildManager = BuildManager.getInstance();
|
||||
buildManager.cancelAutoMakeTasks(myProject);
|
||||
return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, artifactNames, paths, builderParams, new BuildMessageHandler() {
|
||||
return buildManager.scheduleBuild(myProject, compileContext.isRebuild(), compileContext.isMake(), moduleNames, artifactNames, paths, builderParams, new DefaultMessageHandler() {
|
||||
@Override
|
||||
public void sessionTerminated() {
|
||||
final ExitStatus status = COMPILE_SERVER_BUILD_STATUS.get(compileContext);
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.impl.actions.SuppressFix;
|
||||
import com.intellij.codeInsight.daemon.impl.actions.SuppressForClassFix;
|
||||
import com.intellij.compiler.*;
|
||||
import com.intellij.compiler.options.CompilerConfigurable;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.ide.errorTreeView.*;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
@@ -110,6 +111,7 @@ public class CompilerErrorTreeView extends NewErrorTreeViewPanel {
|
||||
if (!project.isDisposed()) {
|
||||
project.save();
|
||||
CompileServerManager.getInstance().sendReloadRequest(project);
|
||||
BuildManager.getInstance().clearState(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+16
-5
@@ -21,6 +21,7 @@ import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.CompilerIOUtil;
|
||||
import com.intellij.compiler.CompilerWorkspaceConfiguration;
|
||||
import com.intellij.compiler.make.MakeUtil;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -1426,7 +1427,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
toMark = Collections.singleton(root);
|
||||
}
|
||||
if (!toMark.isEmpty()) {
|
||||
CompileServerManager.getInstance().notifyFilesDeleted(toMark);
|
||||
notifyFilesDeleted(toMark);
|
||||
}
|
||||
}
|
||||
markDirtyIfSource(eventFile, false);
|
||||
@@ -1544,7 +1545,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
});
|
||||
|
||||
if (!pathsToMark.isEmpty()) {
|
||||
CompileServerManager.getInstance().notifyFilesDeleted(pathsToMark);
|
||||
notifyFilesDeleted(pathsToMark);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1583,10 +1584,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
}
|
||||
});
|
||||
if (fromMove) {
|
||||
CompileServerManager.getInstance().notifyFilesDeleted(pathsToMark);
|
||||
notifyFilesDeleted(pathsToMark);
|
||||
}
|
||||
else {
|
||||
CompileServerManager.getInstance().notifyFilesChanged(pathsToMark);
|
||||
notifyFilesChanged(pathsToMark);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1637,11 +1638,21 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent {
|
||||
}
|
||||
});
|
||||
if (notifyServer) {
|
||||
CompileServerManager.getInstance().notifyFilesChanged(pathsToMark);
|
||||
notifyFilesChanged(pathsToMark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyFilesChanged(Collection<String> paths) {
|
||||
CompileServerManager.getInstance().notifyFilesChanged(paths);
|
||||
BuildManager.getInstance().notifyFilesChanged(paths);
|
||||
}
|
||||
|
||||
private static void notifyFilesDeleted(Collection<String> paths) {
|
||||
CompileServerManager.getInstance().notifyFilesDeleted(paths);
|
||||
BuildManager.getInstance().notifyFilesDeleted(paths);
|
||||
}
|
||||
|
||||
private boolean belongsToIntermediateSources(VirtualFile file, Project project) {
|
||||
return FileUtil.isAncestor(myGeneratedDataPaths.get(project), new File(file.getPath()), true);
|
||||
}
|
||||
|
||||
+2
@@ -17,6 +17,7 @@ package com.intellij.compiler.options;
|
||||
|
||||
import com.intellij.compiler.CompileServerManager;
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
@@ -253,6 +254,7 @@ public class AnnotationProcessorsConfigurable implements SearchableConfigurable,
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
CompileServerManager.getInstance().sendReloadRequest(myProject);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.CompilerConfigurationImpl;
|
||||
import com.intellij.compiler.CompilerSettingsFactory;
|
||||
import com.intellij.compiler.impl.rmiCompiler.RmicConfiguration;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.compiler.options.ExcludedEntriesConfigurable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -181,6 +182,7 @@ public class CompilerConfigurable implements SearchableConfigurable.Parent, Conf
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
CompileServerManager.getInstance().sendReloadRequest(project);
|
||||
BuildManager.getInstance().clearState(project);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.compiler.options;
|
||||
|
||||
import com.intellij.compiler.*;
|
||||
import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
@@ -124,6 +125,7 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
CompileServerManager.getInstance().sendReloadRequest(myProject);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.compiler.CompileServerManager;
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.CompilerConfigurationImpl;
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.ide.ui.ListCellRendererWrapper;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
@@ -128,6 +129,7 @@ public class JavaCompilersTab implements SearchableConfigurable, Configurable.No
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
CompileServerManager.getInstance().sendReloadRequest(myProject);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.compiler.server;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.openapi.compiler.CompilationStatusListener;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.compiler.CompilerTopics;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.problems.Problem;
|
||||
import com.intellij.problems.WolfTheProblemSolver;
|
||||
import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/25/12
|
||||
*/
|
||||
class AutoMakeMessageHandler extends DefaultMessageHandler {
|
||||
private CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status myBuildStatus;
|
||||
private final Project myProject;
|
||||
private final WolfTheProblemSolver myWolf;
|
||||
|
||||
public AutoMakeMessageHandler(Project project) {
|
||||
myProject = project;
|
||||
myBuildStatus = CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status.SUCCESS;
|
||||
myWolf = WolfTheProblemSolver.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBuildEvent(CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
|
||||
if (myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
switch (event.getEventType()) {
|
||||
case BUILD_COMPLETED:
|
||||
if (event.hasCompletionStatus()) {
|
||||
myBuildStatus = event.getCompletionStatus();
|
||||
}
|
||||
return;
|
||||
|
||||
case FILES_GENERATED:
|
||||
final CompilationStatusListener publisher = myProject.getMessageBus().syncPublisher(CompilerTopics.COMPILATION_STATUS);
|
||||
for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : event.getGeneratedFilesList()) {
|
||||
final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
|
||||
final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
|
||||
publisher.fileGenerated(root, relativePath);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompileMessage(CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
|
||||
if (myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
|
||||
if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR) {
|
||||
informWolf(myProject, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(CmdlineRemoteProto.Message.Failure failure) {
|
||||
CompilerManager.NOTIFICATION_GROUP.createNotification("Auto make failure: " + failure.getDescription(), MessageType.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionTerminated() {
|
||||
String statusMessage = null/*"Auto make completed"*/;
|
||||
switch (myBuildStatus) {
|
||||
case SUCCESS:
|
||||
//statusMessage = "Auto make completed successfully";
|
||||
break;
|
||||
case UP_TO_DATE:
|
||||
//statusMessage = "All files are up-to-date";
|
||||
break;
|
||||
case ERRORS:
|
||||
statusMessage = "Auto make completed with errors";
|
||||
break;
|
||||
case CANCELED:
|
||||
//statusMessage = "Auto make has been canceled";
|
||||
break;
|
||||
}
|
||||
if (statusMessage != null) {
|
||||
final Notification notification = CompilerManager.NOTIFICATION_GROUP.createNotification(statusMessage, MessageType.INFO);
|
||||
if (!myProject.isDisposed()) {
|
||||
notification.notify(myProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void informWolf(Project project, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
|
||||
final String srcPath = message.getSourceFilePath();
|
||||
if (srcPath != null && !project.isDisposed()) {
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(srcPath);
|
||||
if (vFile != null) {
|
||||
final int line = (int)message.getLine();
|
||||
final int column = (int)message.getColumn();
|
||||
if (line > 0 && column > 0) {
|
||||
final Problem problem = myWolf.convertToProblem(vFile, line, column, new String[]{message.getText()});
|
||||
myWolf.weHaveGotProblems(vFile, Collections.singletonList(problem));
|
||||
}
|
||||
else {
|
||||
myWolf.queue(vFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,29 +25,24 @@ import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathMacros;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.compiler.CompilationStatusListener;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.compiler.CompilerTopics;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerAdapter;
|
||||
import com.intellij.openapi.projectRoots.*;
|
||||
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.*;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -56,10 +51,7 @@ import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.problems.Problem;
|
||||
import com.intellij.problems.WolfTheProblemSolver;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.containers.ConcurrentHashSet;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.net.NetUtils;
|
||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||
@@ -77,6 +69,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.api.*;
|
||||
import org.jetbrains.jps.cmdline.BuildMain;
|
||||
import org.jetbrains.jps.incremental.fs.FSState;
|
||||
import org.jetbrains.jps.incremental.fs.RootDescriptor;
|
||||
import org.jetbrains.jps.server.ClasspathBootstrap;
|
||||
import org.jetbrains.jps.server.Server;
|
||||
|
||||
@@ -87,7 +81,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -101,9 +94,11 @@ public class BuildManager implements ApplicationComponent{
|
||||
private static final String SYSTEM_ROOT = "compile-server";
|
||||
private static final String LOGGER_CONFIG = "log.xml";
|
||||
private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.xml";
|
||||
private static final int MAKE_TRIGGER_DELAY = 5 * 1000 /*5 seconds*/;
|
||||
|
||||
private final File mySystemDirectory;
|
||||
private final ProjectManager myProjectManager;
|
||||
private static final int MAKE_TRIGGER_DELAY = 5 * 1000 /*5 seconds*/;
|
||||
|
||||
private final Map<RequestFuture, Project> myAutomakeFutures = new HashMap<RequestFuture, Project>();
|
||||
private final CompileServerClasspathManager myClasspathManager = new CompileServerClasspathManager();
|
||||
private final Executor myPooledThreadExecutor = new Executor() {
|
||||
@@ -112,9 +107,9 @@ public class BuildManager implements ApplicationComponent{
|
||||
ApplicationManager.getApplication().executeOnPooledThread(command);
|
||||
}
|
||||
};
|
||||
private final Map<String, SequentialTaskExecutor> myProjectToExecutorMap = Collections.synchronizedMap(new HashMap<String, SequentialTaskExecutor>());
|
||||
private final Map<String, ProjectData> myProjectDataMap = Collections.synchronizedMap(new HashMap<String, ProjectData>());
|
||||
|
||||
private final ChannelGroup myAllOpenChannels = new DefaultChannelGroup("compile-manager");
|
||||
private final ChannelGroup myAllOpenChannels = new DefaultChannelGroup("build-manager");
|
||||
private final BuildMessageDispatcher myMessageDispatcher = new BuildMessageDispatcher();
|
||||
private int myListenPort = -1;
|
||||
private volatile CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings myGlobals;
|
||||
@@ -202,12 +197,89 @@ public class BuildManager implements ApplicationComponent{
|
||||
return ApplicationManager.getApplication().getComponent(BuildManager.class);
|
||||
}
|
||||
|
||||
public void notifyFilesChanged(Collection<String> paths) {
|
||||
// todo: update state
|
||||
public void notifyFilesChanged(final Collection<String> paths) {
|
||||
// todo: temporarily commented
|
||||
//doNotify(paths, false);
|
||||
}
|
||||
|
||||
public void notifyFilesDeleted(Collection<String> paths) {
|
||||
// todo: update state
|
||||
// todo: temporarily commented
|
||||
//doNotify(paths, true);
|
||||
}
|
||||
|
||||
private void doNotify(final Collection<String> paths, final boolean notifyDeletion) {
|
||||
final Project[] openProjects = myProjectManager.getOpenProjects();
|
||||
myPooledThreadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Pair<ProjectFileIndex, ProjectData>> activeProjects = new ArrayList<Pair<ProjectFileIndex, ProjectData>>();
|
||||
for (Project project : openProjects) {
|
||||
if (project.isDisposed() || project.isDefault()) {
|
||||
continue;
|
||||
}
|
||||
final String projectPath = getProjectPath(project);
|
||||
final ProjectData data = myProjectDataMap.get(projectPath);
|
||||
if (data != null) {
|
||||
activeProjects.add(Pair.create(ProjectRootManager.getInstance(project).getFileIndex(), data));
|
||||
}
|
||||
}
|
||||
final LocalFileSystem lfs = LocalFileSystem.getInstance();
|
||||
for (final Pair<ProjectFileIndex, ProjectData> pair : activeProjects) {
|
||||
final ProjectFileIndex fileIndex = pair.first;
|
||||
final FSState fsState = pair.second.fsState;
|
||||
pair.second.requestQueue.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (String filePath : paths) {
|
||||
// todo: estimate performance, probably add a way to obtain all data from file index in a single call
|
||||
final VirtualFile vFile = lfs.findFileByPath(filePath);
|
||||
if (vFile == null) {
|
||||
continue;
|
||||
}
|
||||
final Module module = fileIndex.getModuleForFile(vFile);
|
||||
if (module == null) {
|
||||
continue;
|
||||
}
|
||||
final String moduleName = module.getName();
|
||||
if (!fsState.isInitialized(moduleName)) { // todo: proper sync!
|
||||
continue;
|
||||
}
|
||||
final VirtualFile srcRoot = fileIndex.getSourceRootForFile(vFile);
|
||||
if (srcRoot == null) {
|
||||
return;
|
||||
}
|
||||
final boolean inTestSources = fileIndex.isInTestSourceContent(vFile);
|
||||
if (!inTestSources && !fileIndex.isInSourceContent(vFile)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
final File file = new File(vFile.getPath());
|
||||
if (notifyDeletion) {
|
||||
fsState.registerDeleted(moduleName, file, inTestSources, null);
|
||||
}
|
||||
else {
|
||||
fsState.markDirty(file, new RootDescriptor(moduleName, new File(srcRoot.getPath()), inTestSources, false), null);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clearState(Project project) {
|
||||
final String projectPath = getProjectPath(project);
|
||||
myProjectDataMap.remove(projectPath);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -274,7 +346,6 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// todo: avoid FS scan on every start
|
||||
|
||||
@Nullable
|
||||
@@ -284,7 +355,7 @@ public class BuildManager implements ApplicationComponent{
|
||||
final Collection<String> modules,
|
||||
final Collection<String> artifacts,
|
||||
final Collection<String> paths,
|
||||
final Map<String, String> userData, final BuildMessageHandler handler) {
|
||||
final Map<String, String> userData, DefaultMessageHandler handler) {
|
||||
|
||||
final String projectPath = getProjectPath(project);
|
||||
final UUID sessionId = UUID.randomUUID();
|
||||
@@ -294,13 +365,27 @@ public class BuildManager implements ApplicationComponent{
|
||||
globals = buildGlobalSettings();
|
||||
myGlobals = globals;
|
||||
}
|
||||
|
||||
final SequentialTaskExecutor sequential;
|
||||
final FSState fsState;
|
||||
synchronized (myProjectDataMap) {
|
||||
ProjectData data = myProjectDataMap.get(projectPath);
|
||||
if (data == null) {
|
||||
data = new ProjectData(new SequentialTaskExecutor(myPooledThreadExecutor), new FSState());
|
||||
myProjectDataMap.put(projectPath, data);
|
||||
}
|
||||
sequential = data.requestQueue;
|
||||
fsState = data.fsState;
|
||||
handler = new FSStateMessageHandler(data.fsState, handler);
|
||||
}
|
||||
|
||||
if (isRebuild) {
|
||||
params = CmdlineProtoUtil.createRebuildRequest(projectPath, userData, globals);
|
||||
params = CmdlineProtoUtil.createRebuildRequest(projectPath, userData, globals, fsState);
|
||||
}
|
||||
else {
|
||||
params = isMake ?
|
||||
CmdlineProtoUtil.createMakeRequest(projectPath, modules, artifacts, userData, globals) :
|
||||
CmdlineProtoUtil.createForceCompileRequest(projectPath, modules, artifacts, paths, userData, globals);
|
||||
CmdlineProtoUtil.createMakeRequest(projectPath, modules, artifacts, userData, globals, fsState) :
|
||||
CmdlineProtoUtil.createForceCompileRequest(projectPath, modules, artifacts, paths, userData, globals, fsState);
|
||||
}
|
||||
|
||||
myMessageDispatcher.registerBuildMessageHandler(sessionId, handler, params);
|
||||
@@ -318,22 +403,13 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
}
|
||||
|
||||
final RequestFuture<BuildMessageHandler> future = new RequestFuture<BuildMessageHandler>(handler, sessionId, new RequestFuture.CancelAction<com.intellij.compiler.server.BuildMessageHandler>() {
|
||||
final RequestFuture<BuilderMessageHandler> future = new RequestFuture<BuilderMessageHandler>(handler, sessionId, new RequestFuture.CancelAction<BuilderMessageHandler>() {
|
||||
@Override
|
||||
public void cancel(RequestFuture<BuildMessageHandler> future) throws Exception {
|
||||
public void cancel(RequestFuture<BuilderMessageHandler> future) throws Exception {
|
||||
myMessageDispatcher.cancelSession(future.getRequestID());
|
||||
}
|
||||
});
|
||||
|
||||
SequentialTaskExecutor sequential;
|
||||
synchronized (myProjectToExecutorMap) {
|
||||
sequential = myProjectToExecutorMap.get(projectPath);
|
||||
if (sequential == null) {
|
||||
sequential = new SequentialTaskExecutor(myPooledThreadExecutor);
|
||||
myProjectToExecutorMap.put(projectPath, sequential);
|
||||
}
|
||||
}
|
||||
|
||||
sequential.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -352,7 +428,7 @@ public class BuildManager implements ApplicationComponent{
|
||||
processHandler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void processTerminated(ProcessEvent event) {
|
||||
final BuildMessageHandler handler = myMessageDispatcher.unregisterBuildMessageHandler(sessionId);
|
||||
final BuilderMessageHandler handler = myMessageDispatcher.unregisterBuildMessageHandler(sessionId);
|
||||
if (handler != null) {
|
||||
handler.sessionTerminated();
|
||||
}
|
||||
@@ -372,8 +448,8 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
myMessageDispatcher.unregisterBuildMessageHandler(sessionId);
|
||||
handler.handleFailure(CmdlineProtoUtil.createFailure(e.getMessage(), e));
|
||||
handler.sessionTerminated();
|
||||
future.getMessageHandler().handleFailure(CmdlineProtoUtil.createFailure(e.getMessage(), e));
|
||||
future.getMessageHandler().sessionTerminated();
|
||||
}
|
||||
finally {
|
||||
future.setDone();
|
||||
@@ -684,103 +760,6 @@ public class BuildManager implements ApplicationComponent{
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static class AutoMakeMessageHandler extends BuildMessageHandler {
|
||||
private CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status myBuildStatus;
|
||||
private final Project myProject;
|
||||
private final WolfTheProblemSolver myWolf;
|
||||
|
||||
public AutoMakeMessageHandler(Project project) {
|
||||
myProject = project;
|
||||
myBuildStatus = CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.Status.SUCCESS;
|
||||
myWolf = WolfTheProblemSolver.getInstance(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBuildEvent(CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
|
||||
if (myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
switch (event.getEventType()) {
|
||||
case BUILD_COMPLETED:
|
||||
if (event.hasCompletionStatus()) {
|
||||
myBuildStatus = event.getCompletionStatus();
|
||||
}
|
||||
return;
|
||||
|
||||
case FILES_GENERATED:
|
||||
final CompilationStatusListener publisher = myProject.getMessageBus().syncPublisher(CompilerTopics.COMPILATION_STATUS);
|
||||
for (CmdlineRemoteProto.Message.BuilderMessage.BuildEvent.GeneratedFile generatedFile : event.getGeneratedFilesList()) {
|
||||
final String root = FileUtil.toSystemIndependentName(generatedFile.getOutputRoot());
|
||||
final String relativePath = FileUtil.toSystemIndependentName(generatedFile.getRelativePath());
|
||||
publisher.fileGenerated(root, relativePath);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompileMessage(CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
|
||||
if (myProject.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
final CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind kind = message.getKind();
|
||||
if (kind == CmdlineRemoteProto.Message.BuilderMessage.CompileMessage.Kind.ERROR) {
|
||||
informWolf(myProject, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(CmdlineRemoteProto.Message.Failure failure) {
|
||||
CompilerManager.NOTIFICATION_GROUP.createNotification("Auto make failure: " + failure.getDescription(), MessageType.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionTerminated() {
|
||||
String statusMessage = null/*"Auto make completed"*/;
|
||||
switch (myBuildStatus) {
|
||||
case SUCCESS:
|
||||
//statusMessage = "Auto make completed successfully";
|
||||
break;
|
||||
case UP_TO_DATE:
|
||||
//statusMessage = "All files are up-to-date";
|
||||
break;
|
||||
case ERRORS:
|
||||
statusMessage = "Auto make completed with errors";
|
||||
break;
|
||||
case CANCELED:
|
||||
//statusMessage = "Auto make has been canceled";
|
||||
break;
|
||||
}
|
||||
if (statusMessage != null) {
|
||||
final Notification notification = CompilerManager.NOTIFICATION_GROUP.createNotification(statusMessage, MessageType.INFO);
|
||||
if (!myProject.isDisposed()) {
|
||||
notification.notify(myProject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void informWolf(Project project, CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
|
||||
final String srcPath = message.getSourceFilePath();
|
||||
if (srcPath != null && !project.isDisposed()) {
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(srcPath);
|
||||
if (vFile != null) {
|
||||
final int line = (int)message.getLine();
|
||||
final int column = (int)message.getColumn();
|
||||
if (line > 0 && column > 0) {
|
||||
final Problem problem = myWolf.convertToProblem(vFile, line, column, new String[]{message.getText()});
|
||||
myWolf.weHaveGotProblems(vFile, Collections.singletonList(problem));
|
||||
}
|
||||
else {
|
||||
myWolf.queue(vFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ProjectWatcher extends ProjectManagerAdapter {
|
||||
private final Map<Project, MessageBusConnection> myConnections = new HashMap<Project, MessageBusConnection>();
|
||||
|
||||
@@ -806,7 +785,7 @@ public class BuildManager implements ApplicationComponent{
|
||||
|
||||
@Override
|
||||
public void projectClosed(Project project) {
|
||||
myProjectToExecutorMap.remove(getProjectPath(project));
|
||||
clearState(project);
|
||||
final MessageBusConnection conn = myConnections.remove(project);
|
||||
if (conn != null) {
|
||||
conn.disconnect();
|
||||
@@ -814,146 +793,13 @@ public class BuildManager implements ApplicationComponent{
|
||||
}
|
||||
}
|
||||
|
||||
private static class BuildMessageDispatcher extends SimpleChannelHandler {
|
||||
private final Map<UUID, SessionData> myMessageHandlers = new ConcurrentHashMap<UUID, SessionData>();
|
||||
private final Set<UUID> myCanceledSessions = new ConcurrentHashSet<UUID>();
|
||||
private static class ProjectData {
|
||||
final SequentialTaskExecutor requestQueue;
|
||||
final FSState fsState;
|
||||
|
||||
public void registerBuildMessageHandler(UUID sessionId,
|
||||
BuildMessageHandler handler,
|
||||
CmdlineRemoteProto.Message.ControllerMessage params) {
|
||||
myMessageHandlers.put(sessionId, new SessionData(sessionId, handler, params));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BuildMessageHandler unregisterBuildMessageHandler(UUID sessionId) {
|
||||
myCanceledSessions.remove(sessionId);
|
||||
final SessionData data = myMessageHandlers.remove(sessionId);
|
||||
return data != null? data.handler : null;
|
||||
}
|
||||
|
||||
public void cancelSession(UUID sessionId) {
|
||||
if (myCanceledSessions.add(sessionId)) {
|
||||
final SessionData data = myMessageHandlers.get(sessionId);
|
||||
if (data != null) {
|
||||
final Channel channel = data.channel;
|
||||
if (channel != null) {
|
||||
Channels.write(channel, CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createCancelCommand()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
final CmdlineRemoteProto.Message message = (CmdlineRemoteProto.Message)e.getMessage();
|
||||
|
||||
SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
|
||||
UUID sessionId;
|
||||
if (sessionData == null) {
|
||||
// this is the first message for this session, so fill session data with missing info
|
||||
final CmdlineRemoteProto.Message.UUID id = message.getSessionId();
|
||||
sessionId = new UUID(id.getMostSigBits(), id.getLeastSigBits());
|
||||
|
||||
sessionData = myMessageHandlers.get(sessionId);
|
||||
if (sessionData != null) {
|
||||
sessionData.channel = ctx.getChannel();
|
||||
ctx.setAttachment(sessionData);
|
||||
}
|
||||
if (myCanceledSessions.contains(sessionId)) {
|
||||
Channels.write(ctx.getChannel(), CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createCancelCommand()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sessionId = sessionData.sessionId;
|
||||
}
|
||||
|
||||
final BuildMessageHandler handler = sessionData != null? sessionData.handler : null;
|
||||
if (handler == null) {
|
||||
// todo
|
||||
LOG.info("No message handler registered for session " + sessionId);
|
||||
return;
|
||||
}
|
||||
|
||||
final CmdlineRemoteProto.Message.Type messageType = message.getType();
|
||||
switch (messageType) {
|
||||
case FAILURE:
|
||||
handler.handleFailure(message.getFailure());
|
||||
break;
|
||||
|
||||
case BUILDER_MESSAGE:
|
||||
final CmdlineRemoteProto.Message.BuilderMessage builderMessage = message.getBuilderMessage();
|
||||
final CmdlineRemoteProto.Message.BuilderMessage.Type responseType = builderMessage.getType();
|
||||
if (responseType == CmdlineRemoteProto.Message.BuilderMessage.Type.PARAM_REQUEST) {
|
||||
final CmdlineRemoteProto.Message.ControllerMessage params = sessionData.params;
|
||||
if (params != null) {
|
||||
sessionData.params = null;
|
||||
Channels.write(ctx.getChannel(), CmdlineProtoUtil.toMessage(sessionId, params));
|
||||
}
|
||||
else {
|
||||
cancelSession(sessionId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.handleBuildMessage(builderMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG.info("Unsupported message type " + messageType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
try {
|
||||
super.channelClosed(ctx, e);
|
||||
}
|
||||
finally {
|
||||
final SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
if (sessionData != null) {
|
||||
final BuildMessageHandler handler = unregisterBuildMessageHandler(sessionData.sessionId);
|
||||
if (handler != null) {
|
||||
// notify the handler only if it has not been notified yet
|
||||
handler.sessionTerminated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
try {
|
||||
super.channelDisconnected(ctx, e);
|
||||
}
|
||||
finally {
|
||||
final SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
if (sessionData != null) { // this is the context corresponding to some session
|
||||
final Channel channel = e.getChannel();
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final class SessionData {
|
||||
final UUID sessionId;
|
||||
final BuildMessageHandler handler;
|
||||
volatile CmdlineRemoteProto.Message.ControllerMessage params;
|
||||
volatile Channel channel;
|
||||
|
||||
private SessionData(UUID sessionId, BuildMessageHandler handler, CmdlineRemoteProto.Message.ControllerMessage params) {
|
||||
this.sessionId = sessionId;
|
||||
this.handler = handler;
|
||||
this.params = params;
|
||||
private ProjectData(SequentialTaskExecutor requestQueue, FSState fsState) {
|
||||
this.requestQueue = requestQueue;
|
||||
this.fsState = fsState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.compiler.server;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.containers.ConcurrentHashSet;
|
||||
import org.jboss.netty.channel.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.api.CmdlineProtoUtil;
|
||||
import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/25/12
|
||||
*/
|
||||
class BuildMessageDispatcher extends SimpleChannelHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.server.BuildMessageDispatcher");
|
||||
private final Map<UUID, SessionData> myMessageHandlers = new ConcurrentHashMap<UUID, SessionData>();
|
||||
private final Set<UUID> myCanceledSessions = new ConcurrentHashSet<UUID>();
|
||||
|
||||
public void registerBuildMessageHandler(UUID sessionId,
|
||||
BuilderMessageHandler handler,
|
||||
CmdlineRemoteProto.Message.ControllerMessage params) {
|
||||
myMessageHandlers.put(sessionId, new SessionData(sessionId, handler, params));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BuilderMessageHandler unregisterBuildMessageHandler(UUID sessionId) {
|
||||
myCanceledSessions.remove(sessionId);
|
||||
final SessionData data = myMessageHandlers.remove(sessionId);
|
||||
return data != null? data.handler : null;
|
||||
}
|
||||
|
||||
public void cancelSession(UUID sessionId) {
|
||||
if (myCanceledSessions.add(sessionId)) {
|
||||
final SessionData data = myMessageHandlers.get(sessionId);
|
||||
if (data != null) {
|
||||
final Channel channel = data.channel;
|
||||
if (channel != null) {
|
||||
Channels.write(channel, CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createCancelCommand()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
final CmdlineRemoteProto.Message message = (CmdlineRemoteProto.Message)e.getMessage();
|
||||
|
||||
SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
|
||||
UUID sessionId;
|
||||
if (sessionData == null) {
|
||||
// this is the first message for this session, so fill session data with missing info
|
||||
final CmdlineRemoteProto.Message.UUID id = message.getSessionId();
|
||||
sessionId = new UUID(id.getMostSigBits(), id.getLeastSigBits());
|
||||
|
||||
sessionData = myMessageHandlers.get(sessionId);
|
||||
if (sessionData != null) {
|
||||
sessionData.channel = ctx.getChannel();
|
||||
ctx.setAttachment(sessionData);
|
||||
}
|
||||
if (myCanceledSessions.contains(sessionId)) {
|
||||
Channels.write(ctx.getChannel(), CmdlineProtoUtil.toMessage(sessionId, CmdlineProtoUtil.createCancelCommand()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sessionId = sessionData.sessionId;
|
||||
}
|
||||
|
||||
final BuilderMessageHandler handler = sessionData != null? sessionData.handler : null;
|
||||
if (handler == null) {
|
||||
// todo
|
||||
LOG.info("No message handler registered for session " + sessionId);
|
||||
return;
|
||||
}
|
||||
|
||||
final CmdlineRemoteProto.Message.Type messageType = message.getType();
|
||||
switch (messageType) {
|
||||
case FAILURE:
|
||||
handler.handleFailure(message.getFailure());
|
||||
break;
|
||||
|
||||
case BUILDER_MESSAGE:
|
||||
final CmdlineRemoteProto.Message.BuilderMessage builderMessage = message.getBuilderMessage();
|
||||
final CmdlineRemoteProto.Message.BuilderMessage.Type msgType = builderMessage.getType();
|
||||
if (msgType == CmdlineRemoteProto.Message.BuilderMessage.Type.PARAM_REQUEST) {
|
||||
final CmdlineRemoteProto.Message.ControllerMessage params = sessionData.params;
|
||||
if (params != null) {
|
||||
sessionData.params = null;
|
||||
Channels.write(ctx.getChannel(), CmdlineProtoUtil.toMessage(sessionId, params));
|
||||
}
|
||||
else {
|
||||
cancelSession(sessionId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.handleBuildMessage(builderMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG.info("Unsupported message type " + messageType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
try {
|
||||
super.channelClosed(ctx, e);
|
||||
}
|
||||
finally {
|
||||
final SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
if (sessionData != null) {
|
||||
final BuilderMessageHandler handler = unregisterBuildMessageHandler(sessionData.sessionId);
|
||||
if (handler != null) {
|
||||
// notify the handler only if it has not been notified yet
|
||||
handler.sessionTerminated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||
try {
|
||||
super.channelDisconnected(ctx, e);
|
||||
}
|
||||
finally {
|
||||
final SessionData sessionData = (SessionData)ctx.getAttachment();
|
||||
if (sessionData != null) { // this is the context corresponding to some session
|
||||
final Channel channel = e.getChannel();
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SessionData {
|
||||
final UUID sessionId;
|
||||
final BuilderMessageHandler handler;
|
||||
volatile CmdlineRemoteProto.Message.ControllerMessage params;
|
||||
volatile Channel channel;
|
||||
|
||||
private SessionData(UUID sessionId, BuilderMessageHandler handler, CmdlineRemoteProto.Message.ControllerMessage params) {
|
||||
this.sessionId = sessionId;
|
||||
this.handler = handler;
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.compiler.server;
|
||||
|
||||
import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/25/12
|
||||
*/
|
||||
public interface BuilderMessageHandler {
|
||||
void handleBuildMessage(CmdlineRemoteProto.Message.BuilderMessage msg);
|
||||
|
||||
void handleFailure(CmdlineRemoteProto.Message.Failure failure);
|
||||
|
||||
void sessionTerminated();
|
||||
}
|
||||
+8
-6
@@ -21,12 +21,8 @@ import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/18/12
|
||||
*/
|
||||
public abstract class BuildMessageHandler {
|
||||
|
||||
public abstract void sessionTerminated();
|
||||
|
||||
public abstract void handleFailure(CmdlineRemoteProto.Message.Failure failure);
|
||||
|
||||
public abstract class DefaultMessageHandler implements BuilderMessageHandler {
|
||||
@Override
|
||||
public final void handleBuildMessage(CmdlineRemoteProto.Message.BuilderMessage msg) {
|
||||
switch (msg.getType()) {
|
||||
case BUILD_EVENT:
|
||||
@@ -35,9 +31,15 @@ public abstract class BuildMessageHandler {
|
||||
case COMPILE_MESSAGE:
|
||||
handleCompileMessage(msg.getCompileMessage());
|
||||
break;
|
||||
case FS_STATE:
|
||||
handleFSStateMessage(msg.getFsstateMessage());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleFSStateMessage(CmdlineRemoteProto.Message.FSStateMessage message) {
|
||||
}
|
||||
|
||||
protected abstract void handleCompileMessage(CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message);
|
||||
|
||||
protected abstract void handleBuildEvent(CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event);
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.compiler.server;
|
||||
|
||||
import org.jetbrains.jps.api.CmdlineRemoteProto;
|
||||
import org.jetbrains.jps.incremental.fs.FSState;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: 4/18/12
|
||||
*/
|
||||
public class FSStateMessageHandler extends DefaultMessageHandler {
|
||||
private final FSState myFsState;
|
||||
private final DefaultMessageHandler myDelegate;
|
||||
|
||||
protected FSStateMessageHandler(FSState fsState, DefaultMessageHandler delegate) {
|
||||
myFsState = fsState;
|
||||
myDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFailure(CmdlineRemoteProto.Message.Failure failure) {
|
||||
myDelegate.handleFailure(failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sessionTerminated() {
|
||||
myDelegate.sessionTerminated();
|
||||
}
|
||||
|
||||
protected void handleFSStateMessage(CmdlineRemoteProto.Message.FSStateMessage message) {
|
||||
try {
|
||||
myDelegate.handleFSStateMessage(message);
|
||||
}
|
||||
finally {
|
||||
final String moduleName = message.getModuleName();
|
||||
final List<String> deleteProduction = message.getDeletedProductionList();
|
||||
final List<String> deletedTests = message.getDeletedTestsList();
|
||||
|
||||
final Map<File,Set<File>> recompileProduction = new HashMap<File, Set<File>>();
|
||||
final Map<File, Set<File>> recompileTests = new HashMap<File, Set<File>>();
|
||||
for (CmdlineRemoteProto.Message.FSStateMessage.RootDelta delta : message.getRecompileDeltaList()) {
|
||||
final File root = new File(delta.getRoot());
|
||||
final Map<File, Set<File>> map = delta.getTestSources()? recompileTests : recompileProduction;
|
||||
Set<File> files = map.get(root);
|
||||
if (files == null) {
|
||||
files = new HashSet<File>();
|
||||
map.put(root, files);
|
||||
}
|
||||
for (String path : delta.getPathList()) {
|
||||
files.add(new File(path));
|
||||
}
|
||||
}
|
||||
|
||||
myFsState.init(moduleName, deleteProduction, deletedTests, recompileProduction, recompileTests);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleCompileMessage(CmdlineRemoteProto.Message.BuilderMessage.CompileMessage message) {
|
||||
myDelegate.handleCompileMessage(message);
|
||||
}
|
||||
|
||||
protected void handleBuildEvent(CmdlineRemoteProto.Message.BuilderMessage.BuildEvent event) {
|
||||
myDelegate.handleBuildEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.packaging.impl.artifacts;
|
||||
|
||||
import com.intellij.compiler.CompileServerManager;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
@@ -371,6 +372,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
|
||||
updateWatchedRoots();
|
||||
if (hasChanges) {
|
||||
CompileServerManager.getInstance().sendReloadRequest(myProject);
|
||||
BuildManager.getInstance().clearState(myProject);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user