diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 019131d051b8..cc2f2c7b8d61 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -29,7 +29,10 @@ import com.intellij.execution.process.*; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.ide.PowerSaveMode; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.*; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.diagnostic.Logger; @@ -212,6 +215,7 @@ public class BuildManager implements ApplicationComponent{ private final BuildMessageDispatcher myMessageDispatcher = new BuildMessageDispatcher(); private volatile int myListenPort = -1; private volatile CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings myGlobals; + private int myGlobalsStamp = -1; @Nullable private final Charset mySystemCharset; @@ -534,11 +538,7 @@ public class BuildManager implements ApplicationComponent{ return; } - CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings globals = myGlobals; - if (globals == null) { - globals = buildGlobalSettings(); - myGlobals = globals; - } + final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings globals = buildGlobalSettings(); CmdlineRemoteProto.Message.ControllerMessage.FSEvent currentFSChanges; final SequentialTaskExecutor projectTaskQueue; synchronized (myProjectDataMap) { @@ -687,14 +687,22 @@ public class BuildManager implements ApplicationComponent{ return "com.intellij.compiler.server.BuildManager"; } - private static CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings buildGlobalSettings() { + private CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings buildGlobalSettings() { + final PathMacrosImpl pathVars = PathMacrosImpl.getInstanceEx(); + + final CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings cached = myGlobals; + if (cached != null && myGlobalsStamp == pathVars.getModificationStamp()) { + return cached; + } + myGlobals = null; // ensure the cache is cleared and stamp is current + myGlobalsStamp = pathVars.getModificationStamp(); + final Map data = new HashMap(); for (Map.Entry entry : PathMacrosImpl.getGlobalSystemMacros().entrySet()) { data.put(entry.getKey(), FileUtil.toSystemIndependentName(entry.getValue())); } - final PathMacros pathVars = PathMacros.getInstance(); for (String name : pathVars.getAllMacroNames()) { final String path = pathVars.getValue(name); if (path != null) { @@ -717,7 +725,7 @@ public class BuildManager implements ApplicationComponent{ } } - return cmdBuilder.build(); + return myGlobals = cmdBuilder.build(); } private OSProcessHandler launchBuildProcess(Project project, final int port, final UUID sessionId) throws ExecutionException { diff --git a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java index cc0ab83b813e..ed100e4dfed5 100644 --- a/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java +++ b/platform/projectModel-impl/src/com/intellij/application/options/PathMacrosImpl.java @@ -46,6 +46,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, private static final Logger LOG = Logger.getInstance("#com.intellij.application.options.PathMacrosImpl"); private final Map myLegacyMacros = new HashMap(); private final Map myMacros = new HashMap(); + private int myModificationStamp = 0; private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock(); private final List myIgnoredMacros = ContainerUtil.createLockFreeCopyOnWriteList(); @@ -196,6 +197,16 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, if (!myIgnoredMacros.contains(name)) myIgnoredMacros.add(name); } + public int getModificationStamp() { + myLock.readLock().lock(); + try { + return myModificationStamp; + } + finally { + myLock.readLock().unlock(); + } + } + public static Map getGlobalSystemMacros() { final Map map = new HashMap(); map.put(APPLICATION_HOME_MACRO_NAME, PathManager.getHomePath()); @@ -236,6 +247,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, myMacros.clear(); } finally { + myModificationStamp++; myLock.writeLock().unlock(); } } @@ -259,6 +271,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, myMacros.put(name, value); } finally { + myModificationStamp++; myLock.writeLock().unlock(); } } @@ -271,6 +284,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, myMacros.remove(name); } finally { + myModificationStamp++; myLock.writeLock().unlock(); } } @@ -283,6 +297,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, LOG.assertTrue(value != null); } finally { + myModificationStamp++; myLock.writeLock().unlock(); } } @@ -322,6 +337,7 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent, } } finally { + myModificationStamp++; myLock.writeLock().unlock(); } }