compile server: support excluded from compilation files

This commit is contained in:
Eugene Zhuravlev
2012-01-11 20:53:50 +01:00
parent 5b65124cba
commit 93e1827a8d
4 changed files with 92 additions and 54 deletions
@@ -31,6 +31,7 @@ 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.project.ex.ProjectEx;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
@@ -97,6 +98,12 @@ public class JpsServerManager implements ApplicationComponent{
mySystemDirectory = system;
projectManager.addProjectManagerListener(new ProjectWatcher());
final MessageBusConnection appConnection = ApplicationManager.getApplication().getMessageBus().connect();
appConnection.subscribe(ProjectEx.ProjectSaved.TOPIC, new ProjectEx.ProjectSaved() {
public void saved(@NotNull Project project) {
sendReloadRequest(project);
}
});
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
@Override
@@ -118,29 +125,55 @@ public class JpsServerManager implements ApplicationComponent{
sendNotification(paths, true);
}
private void sendNotification(Collection<String> paths, final boolean isDeleted) {
final Client client = myClient;
if (client != null && client.isConnected()) {
final Project[] openProjects = myProjectManager.getOpenProjects();
if (openProjects.length > 0) {
final Collection<String> changed, deleted;
if (isDeleted) {
changed = Collections.emptyList();
deleted = paths;
}
else {
changed = paths;
deleted = Collections.emptyList();
}
for (Project project : openProjects) {
try {
client.sendFSEvent(project.getLocation(), changed, deleted);
}
catch (Exception e) {
LOG.info(e);
public void sendReloadRequest(final Project project) {
myTaskExecutor.submit(new Runnable() {
@Override
public void run() {
try {
final Client client = ensureServerRunningAndClientConnected(false);
if (client != null) {
client.sendProjectReloadRequest(Collections.singletonList(project.getLocation()));
}
}
catch (Throwable e) {
LOG.info(e);
}
}
});
}
private void sendNotification(final Collection<String> paths, final boolean isDeleted) {
try {
final Client client = ensureServerRunningAndClientConnected(false);
if (client != null) {
myTaskExecutor.submit(new Runnable() {
public void run() {
final Project[] openProjects = myProjectManager.getOpenProjects();
if (openProjects.length > 0) {
final Collection<String> changed, deleted;
if (isDeleted) {
changed = Collections.emptyList();
deleted = paths;
}
else {
changed = paths;
deleted = Collections.emptyList();
}
for (Project project : openProjects) {
try {
client.sendFSEvent(project.getLocation(), changed, deleted);
}
catch (Exception e) {
LOG.info(e);
}
}
}
}
});
}
}
catch (Throwable th) {
LOG.error(th); // should not happen
}
}
@@ -457,7 +490,7 @@ public class JpsServerManager implements ApplicationComponent{
myConnections.put(project, conn);
conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
public void beforeRootsChange(final ModuleRootEvent event) {
sendReloadRequest(project, false);
sendReloadRequest(project);
}
public void rootsChanged(final ModuleRootEvent event) {
@@ -477,11 +510,10 @@ public class JpsServerManager implements ApplicationComponent{
});
}
});
}
public void projectClosing(Project project) {
sendReloadRequest(project, false);
sendReloadRequest(project);
}
public void projectClosed(Project project) {
@@ -490,22 +522,5 @@ public class JpsServerManager implements ApplicationComponent{
conn.disconnect();
}
}
private void sendReloadRequest(final Project project, final boolean forceRestart) {
myTaskExecutor.submit(new Runnable() {
@Override
public void run() {
try {
final Client client = ensureServerRunningAndClientConnected(forceRestart);
if (client != null) {
client.sendProjectReloadRequest(Collections.singletonList(project.getLocation()));
}
}
catch (Throwable e) {
LOG.info(e);
}
}
});
}
}
}
@@ -107,6 +107,14 @@ public class CompilerErrorTreeView extends NewErrorTreeViewPanel {
ExcludeEntryDescription description = new ExcludeEntryDescription(file, false, true, myProject);
((CompilerConfigurationImpl) CompilerConfiguration.getInstance(myProject)).getExcludedEntriesConfiguration().addExcludeEntryDescription(description);
FileStatusManager.getInstance(myProject).fileStatusesChanged();
final Project project = myProject;
SwingUtilities.invokeLater(new Runnable() { // this will cause jps compile server to reload project configuration
public void run() {
if (!project.isDisposed()) {
project.save();
}
}
});
}
}
@@ -3,6 +3,7 @@ package org.jetbrains.jps.incremental;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.CompilerExcludes;
import org.jetbrains.jps.Module;
import org.jetbrains.jps.incremental.storage.TimestampStorage;
@@ -60,15 +61,21 @@ public class FSState {
final FilesDelta delta = getDelta(rd.module);
final Set<File> files = delta.clearRecompile(rd.root, rd.isTestRoot);
if (files != null) {
final CompilerExcludes excludes = rd.module.getProject().getCompilerConfiguration().getExcludes();
for (File file : files) {
final long stamp = file.lastModified();
if (stamp > compilationStartStamp) {
// if the file was modified after the compilation had started,
// do not save the stamp considering file dirty
delta.markRecompile(rd.root, rd.isTestRoot, file);
if (!excludes.isExcluded(file)) {
final long stamp = file.lastModified();
if (stamp > compilationStartStamp) {
// if the file was modified after the compilation had started,
// do not save the stamp considering file dirty
delta.markRecompile(rd.root, rd.isTestRoot, file);
}
else {
tsStorage.saveStamp(file, stamp);
}
}
else {
tsStorage.saveStamp(file, stamp);
tsStorage.remove(file);
}
}
}
@@ -79,10 +86,14 @@ public class FSState {
final FilesDelta lastRoundDelta = myLastRoundDelta;
final FilesDelta delta = lastRoundDelta != null? lastRoundDelta : getDelta(module);
final Map<File, Set<File>> data = delta.getSourcesToRecompile(forTests);
final CompilerExcludes excludes = module.getProject().getCompilerConfiguration().getExcludes();
synchronized (data) {
for (Map.Entry<File, Set<File>> entry : data.entrySet()) {
final String root = FileUtil.toSystemIndependentName(entry.getKey().getPath());
for (File file : entry.getValue()) {
if (excludes.isExcluded(file)) {
continue;
}
if (!processor.apply(module, file, root)) {
return false;
}
@@ -1,5 +1,7 @@
package org.jetbrains.jps;
import com.intellij.openapi.util.io.FileUtil;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
@@ -25,16 +27,18 @@ public class CompilerExcludes {
return true;
}
File parent = file.getParentFile();
if (myDirectories.contains(parent)) {
return true;
}
while (parent != null) {
if (myRecursivelyExcludedDirectories.contains(parent)) {
if (!myDirectories.isEmpty() || !myRecursivelyExcludedDirectories.isEmpty()) { // optimization
File parent = FileUtil.getParentFile(file);
if (myDirectories.contains(parent)) {
return true;
}
parent = parent.getParentFile();
while (parent != null) {
if (myRecursivelyExcludedDirectories.contains(parent)) {
return true;
}
parent = FileUtil.getParentFile(parent);
}
}
return false;
}