From b3fc0a30c177fcaa40017610654967c8be663c86 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 30 May 2013 13:25:52 +0400 Subject: [PATCH] jps model: don't load and parse each iml file twice --- .../model/serialization/JpsProjectLoader.java | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java index 3b9345274ecf..d36e603bdad2 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java @@ -17,6 +17,7 @@ package org.jetbrains.jps.model.serialization; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; @@ -226,8 +227,8 @@ public class JpsProjectLoader extends JpsLoaderBase { if (componentRoot == null) return; final Element modules = componentRoot.getChild("modules"); List> futures = new ArrayList>(); - final List paths = new ArrayList(); - final List classpathDirs = new ArrayList(); + + List>> futureModuleFiles = new ArrayList>>(); for (Element moduleElement : JDOMUtil.getChildren(modules, "module")) { final String path = moduleElement.getAttributeValue("filepath"); final File file = new File(path); @@ -236,23 +237,34 @@ public class JpsProjectLoader extends JpsLoaderBase { continue; } - final JpsMacroExpander expander = createModuleMacroExpander(myPathVariables, file); - final Element moduleRoot = loadRootElement(file, expander); - final String classpathDir = moduleRoot.getAttributeValue(CLASSPATH_DIR_ATTRIBUTE); - if (classpathDir != null) { - classpathDirs.add(classpathDir); - } - paths.add(path); - } - for (final String path : paths) { - futures.add(ourThreadPool.submit(new Callable() { + futureModuleFiles.add(ourThreadPool.submit(new Callable>() { @Override - public JpsModule call() throws Exception { - return loadModule(path, classpathDirs, projectSdkType); + public Pair call() throws Exception { + final JpsMacroExpander expander = createModuleMacroExpander(myPathVariables, file); + final Element moduleRoot = loadRootElement(file, expander); + return Pair.create(file, moduleRoot); } })); } + try { + final List classpathDirs = new ArrayList(); + for (Future> moduleFile : futureModuleFiles) { + final String classpathDir = moduleFile.get().getSecond().getAttributeValue(CLASSPATH_DIR_ATTRIBUTE); + if (classpathDir != null) { + classpathDirs.add(classpathDir); + } + } + + for (final Future> futureModuleFile : futureModuleFiles) { + final Pair moduleFile = futureModuleFile.get(); + futures.add(ourThreadPool.submit(new Callable() { + @Override + public JpsModule call() throws Exception { + return loadModule(moduleFile.getFirst(), moduleFile.getSecond(), classpathDirs, projectSdkType); + } + })); + } for (Future future : futures) { JpsModule module = future.get(); if (module != null) { @@ -267,21 +279,13 @@ public class JpsProjectLoader extends JpsLoaderBase { } @Nullable - private JpsModule loadModule(@NotNull String path, List paths, @Nullable JpsSdkType projectSdkType) { - final File file = new File(path); + private JpsModule loadModule(@NotNull File file, @NotNull Element moduleRoot, List paths, @Nullable JpsSdkType projectSdkType) { String name = FileUtil.getNameWithoutExtension(file); - if (!file.exists()) { - LOG.info("Module '" + name + "' is skipped: " + file.getAbsolutePath() + " doesn't exist"); - return null; - } - - final JpsMacroExpander expander = createModuleMacroExpander(myPathVariables, file); - final Element moduleRoot = loadRootElement(file, expander); final String typeId = moduleRoot.getAttributeValue("type"); final JpsModulePropertiesSerializer serializer = getModulePropertiesSerializer(typeId); final JpsModule module = createModule(name, moduleRoot, serializer); module.getContainer().setChild(JpsModuleSerializationDataExtensionImpl.ROLE, - new JpsModuleSerializationDataExtensionImpl(file.getParentFile())); + new JpsModuleSerializationDataExtensionImpl(file.getParentFile())); for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) { extension.loadModuleOptions(module, moduleRoot); @@ -298,6 +302,7 @@ public class JpsProjectLoader extends JpsLoaderBase { JpsModuleClasspathSerializer classpathSerializer = extension.getClasspathSerializer(); if (classpathSerializer != null && classpathSerializer.getClasspathId().equals(classpath)) { String classpathDir = moduleRoot.getAttributeValue(CLASSPATH_DIR_ATTRIBUTE); + final JpsMacroExpander expander = createModuleMacroExpander(myPathVariables, file); classpathSerializer.loadClasspath(module, classpathDir, baseModulePath, expander, paths, projectSdkType); } }