diff --git a/platform/core-impl/src/com/intellij/core/CoreEnvironment.java b/platform/core-impl/src/com/intellij/core/CoreEnvironment.java index 9d79de825bf8..e26952f34fbf 100644 --- a/platform/core-impl/src/com/intellij/core/CoreEnvironment.java +++ b/platform/core-impl/src/com/intellij/core/CoreEnvironment.java @@ -81,23 +81,25 @@ public class CoreEnvironment { protected final CoreJarFileSystem myJarFileSystem; protected final MockFileIndexFacade myFileIndexFacade; protected final PsiManagerImpl myPsiManager; + private final Disposable myParentDisposable; public CoreEnvironment(Disposable parentDisposable) { - Extensions.cleanRootArea(parentDisposable); + myParentDisposable = parentDisposable; + Extensions.cleanRootArea(myParentDisposable); myFileTypeRegistry = new CoreFileTypeRegistry(); myEncodingRegistry = new CoreEncodingRegistry(); - myApplication = new MockApplication(parentDisposable); + myApplication = new MockApplication(myParentDisposable); ApplicationManager.setApplication(myApplication, new StaticGetter(myFileTypeRegistry), new StaticGetter(myEncodingRegistry), - parentDisposable); + myParentDisposable); myLocalFileSystem = new CoreLocalFileSystem(); myJarFileSystem = new CoreJarFileSystem(); Extensions.registerAreaClass("IDEA_PROJECT", null); - myProject = new MockProject(myApplication.getPicoContainer(), parentDisposable); + myProject = new MockProject(myApplication.getPicoContainer(), myParentDisposable); final MutablePicoContainer appContainer = myApplication.getPicoContainer(); registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(new Function() { @@ -145,7 +147,7 @@ public class CoreEnvironment { registerProjectExtensionPoint(PsiTreeChangePreprocessor.EP_NAME, PsiTreeChangePreprocessor.class); myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, null, modificationTracker); ((FileManagerImpl) myPsiManager.getFileManager()).markInitialized(); - registerComponentInstance(projectContainer, PsiManager.class, myPsiManager); + registerProjectComponent(PsiManager.class, myPsiManager); myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager)); myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager))); @@ -174,6 +176,14 @@ public class CoreEnvironment { }; } + public Disposable getParentDisposable() { + return myParentDisposable; + } + + public void registerProjectComponent(final Class interfaceClass, final T implementation) { + registerComponentInstance(myProject.getPicoContainer(), interfaceClass, implementation); + } + public Project getProject() { return myProject; } diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java index 3196a5319fa7..2e7f8cc826b5 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java @@ -35,6 +35,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.project.impl.ProjectLifecycleListener; import com.intellij.util.messages.MessageBus; +import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.messages.MessageHandler; import java.io.IOException; @@ -54,9 +55,13 @@ import java.util.List; public class ModuleManagerComponent extends ModuleManagerImpl { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.module.impl.ModuleManagerComponent"); private final ProgressManager myProgressManager; + private final MessageBus myMessageBus; + private final MessageBusConnection myConnection; public ModuleManagerComponent(Project project, ProgressManager progressManager, MessageBus bus) { - super(project, bus); + super(project); + myMessageBus = bus; + myConnection = bus.connect(project); myProgressManager = progressManager; myConnection.setDefaultHandler(new MessageHandler() { public void handle(Method event, Object... params) { @@ -163,4 +168,8 @@ public class ModuleManagerComponent extends ModuleManagerImpl { runnableWithProgress.run(); } } + + protected void deliverPendingEvents() { + myConnection.deliverImmediately(); + } } diff --git a/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java b/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java new file mode 100644 index 000000000000..e25ae7ab4100 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/core/CoreModuleManagerTest.java @@ -0,0 +1,42 @@ +/* + * 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.core; + +import com.intellij.openapi.application.ex.PathManagerEx; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.vfs.StandardFileSystems; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.UsefulTestCase; +import org.jdom.JDOMException; + +import java.io.IOException; + +/** + * @author yole + */ +public class CoreModuleManagerTest extends UsefulTestCase { + public void _testLoadingModules() throws IOException, JDOMException { + CoreEnvironment env = new CoreEnvironment(getTestRootDisposable()); + ProjectModelEnvironment.register(env); + final String projectPath = PathManagerEx.getTestDataPath("/compileServer/incremental/annotations/addAnnotationTarget"); + VirtualFile vFile = StandardFileSystems.local().findFileByPath(projectPath); + CoreProjectLoader.loadProject(env.getProject(), vFile); + final ModuleManager moduleManager = ModuleManager.getInstance(env.getProject()); + final Module[] modules = moduleManager.getModules(); + assertEquals(1, modules.length); + } +} diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java new file mode 100644 index 000000000000..aa9fd7471318 --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java @@ -0,0 +1,153 @@ +/* + * 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.core; + +import com.intellij.mock.MockComponentManager; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.module.impl.ModuleEx; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; + +/** + * @author yole + */ +public class CoreModule extends MockComponentManager implements ModuleEx { + private final Project myProject; + + public CoreModule(@NotNull Disposable parentDisposable, Project project) { + super(project.getPicoContainer(), parentDisposable); + myProject = project; + } + + @Override + public void init() { + } + + @Override + public void loadModuleComponents() { + } + + @Override + public void moduleAdded() { + } + + @Override + public void projectOpened() { + } + + @Override + public void projectClosed() { + } + + @Override + public void rename(String newName) { + } + + @Override + public VirtualFile getModuleFile() { + throw new UnsupportedOperationException(); + } + + @NotNull + @Override + public String getModuleFilePath() { + throw new UnsupportedOperationException(); + } + + @NotNull + @Override + public Project getProject() { + return myProject; + } + + @NotNull + @Override + public String getName() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public boolean isLoaded() { + return true; + } + + @Override + public void setOption(@NotNull String optionName, @NotNull String optionValue) { + throw new UnsupportedOperationException(); + } + + @Override + public void clearOption(@NotNull String optionName) { + throw new UnsupportedOperationException(); + } + + @Override + public String getOptionValue(@NotNull String optionName) { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleScope(boolean includeTests) { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleWithLibrariesScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleWithDependenciesScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleContentScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleContentWithDependenciesScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleWithDependenciesAndLibrariesScope(boolean includeTests) { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleWithDependentsScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleTestsWithDependentsScope() { + throw new UnsupportedOperationException(); + } + + @Override + public GlobalSearchScope getModuleRuntimeScope(boolean includeTests) { + throw new UnsupportedOperationException(); + } +} diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java b/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java new file mode 100644 index 000000000000..3ab18a7a8865 --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java @@ -0,0 +1,52 @@ +/* + * 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.core; + +import com.intellij.openapi.Disposable; +import com.intellij.openapi.module.impl.ModuleEx; +import com.intellij.openapi.module.impl.ModuleManagerImpl; +import com.intellij.openapi.project.Project; + +import java.io.IOException; + +/** + * @author yole + */ +public class CoreModuleManager extends ModuleManagerImpl { + private final Disposable myParentDisposable; + + public CoreModuleManager(Project project, Disposable parentDisposable) { + super(project); + myParentDisposable = parentDisposable; + } + + @Override + protected ModuleEx createModule(String filePath) { + return new CoreModule(myParentDisposable, myProject); + } + + @Override + protected ModuleEx createAndLoadModule(String filePath) throws IOException { + return new CoreModule(myParentDisposable, myProject); + } + + protected void deliverPendingEvents() { + } + + public void loadModules() { + loadModules(myModuleModel); + } +} diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java new file mode 100644 index 000000000000..ddd68ba7abed --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/core/CoreProjectLoader.java @@ -0,0 +1,69 @@ +/* + * 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.core; + +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.module.impl.ModuleManagerImpl; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.vfs.VirtualFile; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +/** + * @author yole + */ +public class CoreProjectLoader { + public static void loadProject(Project project, @NotNull VirtualFile virtualFile) throws IOException, JDOMException { + if (virtualFile.isDirectory() && virtualFile.findChild(".idea") != null) { + loadDirectoryProject(project, virtualFile); + } + else { + // TODO load .ipr + throw new UnsupportedOperationException(); + } + } + + private static void loadDirectoryProject(Project project, VirtualFile projectDir) throws IOException, JDOMException { + VirtualFile dotIdea = projectDir.findChild(".idea"); + VirtualFile modulesXml = dotIdea.findChild("modules.xml"); + final Document document = JDOMUtil.loadDocument(new ByteArrayInputStream(modulesXml.contentsToByteArray())); + final Element moduleManagerState = getComponentState(document, "ProjectModuleManager"); + if (moduleManagerState == null) { + throw new JDOMException("cannot find ProjectModuleManager state in modules.xml"); + } + final CoreModuleManager moduleManager = (CoreModuleManager)ModuleManager.getInstance(project); + moduleManager.loadState(moduleManagerState); + moduleManager.loadModules(); + } + + @Nullable + private static Element getComponentState(Document document, String componentName) { + final Element[] elements = JDOMUtil.getElements(document.getRootElement()); + for (Element element : elements) { + if (element.getName().equals("component") && componentName.equals(element.getAttributeValue("name"))) { + return element; + } + } + return null; + } +} diff --git a/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java b/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java new file mode 100644 index 000000000000..4680fbd13d6b --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/core/ProjectModelEnvironment.java @@ -0,0 +1,27 @@ +/* + * 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.core; + +import com.intellij.openapi.module.ModuleManager; + +/** + * @author yole + */ +public class ProjectModelEnvironment { + public static void register(CoreEnvironment env) { + env.registerProjectComponent(ModuleManager.class, new CoreModuleManager(env.getProject(), env.getParentDisposable())); + } +} diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 812d084e2829..510b837457ba 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -42,8 +42,6 @@ import com.intellij.util.graph.CachingSemiGraph; import com.intellij.util.graph.DFSTBuilder; import com.intellij.util.graph.Graph; import com.intellij.util.graph.GraphGenerator; -import com.intellij.util.messages.MessageBus; -import com.intellij.util.messages.MessageBusConnection; import gnu.trove.THashMap; import org.jdom.Element; import org.jdom.JDOMException; @@ -75,8 +73,6 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project @NonNls public static final String ATTRIBUTE_FILEPATH = "filepath"; @NonNls private static final String ATTRIBUTE_GROUP = "group"; private long myModificationCount; - protected final MessageBusConnection myConnection; - protected final MessageBus myMessageBus; public static ModuleManagerImpl getInstanceImpl(Project project) { return (ModuleManagerImpl)getInstance(project); @@ -87,10 +83,8 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project myCachedSortedModules = null; } - public ModuleManagerImpl(Project project, MessageBus bus) { + public ModuleManagerImpl(Project project) { myProject = project; - myMessageBus = bus; - myConnection = bus.connect(project); } @@ -433,7 +427,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project @NotNull public Module[] getSortedModules() { ApplicationManager.getApplication().assertReadAccessAllowed(); - myConnection.deliverImmediately(); + deliverPendingEvents(); if (myCachedSortedModules == null) { myCachedSortedModules = myModuleModel.getSortedModules(); } @@ -450,13 +444,16 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Project @NotNull public Comparator moduleDependencyComparator() { ApplicationManager.getApplication().assertReadAccessAllowed(); - myConnection.deliverImmediately(); + deliverPendingEvents(); if (myCachedModuleComparator == null) { myCachedModuleComparator = myModuleModel.moduleDependencyComparator(); } return myCachedModuleComparator; } + protected void deliverPendingEvents() { + } + @NotNull public Graph moduleGraph() { return moduleGraph(true);