From 1dc96566ff62a130cf1b914d899f761ffbc608b8 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 22 Sep 2011 13:31:25 +0400 Subject: [PATCH] IdeaProjectManagerImpl merged into ProjectManagerImpl --- .../projectWizard/ExistingModuleLoader.java | 1 - .../impl/ConversionServiceImpl.java | 5 ++ .../project/impl/IdeaProjectManagerImpl.java | 79 ------------------- .../conversion/ConversionListener.java | 0 .../intellij/conversion/ConversionResult.java | 0 .../conversion/ConversionService.java | 4 +- .../conversion/DummyConversionService.java | 68 ++++++++++++++++ .../openapi/project/ex/ProjectManagerEx.java | 3 - .../project/impl/ProjectManagerImpl.java | 51 +++++++----- .../PlatformProjectOpenProcessor.java | 2 +- .../src/componentSets/Platform.xml | 5 ++ .../src/componentSets/PlatformComponents.xml | 4 - .../componentSets/PlatformLangComponents.xml | 4 - .../src/componentSets/IdeaComponents.xml | 4 - 14 files changed, 112 insertions(+), 118 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/openapi/project/impl/IdeaProjectManagerImpl.java rename platform/{lang-impl => platform-impl}/src/com/intellij/conversion/ConversionListener.java (100%) rename platform/{lang-impl => platform-impl}/src/com/intellij/conversion/ConversionResult.java (100%) rename platform/{lang-impl => platform-impl}/src/com/intellij/conversion/ConversionService.java (89%) create mode 100644 platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java diff --git a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java index 3da5832d12c5..b0a84be1215b 100644 --- a/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java +++ b/java/idea-ui/src/com/intellij/ide/util/projectWizard/ExistingModuleLoader.java @@ -16,7 +16,6 @@ package com.intellij.ide.util.projectWizard; import com.intellij.CommonBundle; -import com.intellij.application.options.PathMacrosCollector; import com.intellij.application.options.PathMacrosImpl; import com.intellij.conversion.ConversionResult; import com.intellij.conversion.ConversionService; diff --git a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionServiceImpl.java b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionServiceImpl.java index 78a170d29ac8..9c9f758b3cb4 100644 --- a/platform/lang-impl/src/com/intellij/conversion/impl/ConversionServiceImpl.java +++ b/platform/lang-impl/src/com/intellij/conversion/impl/ConversionServiceImpl.java @@ -19,6 +19,7 @@ package com.intellij.conversion.impl; import com.intellij.conversion.*; import com.intellij.conversion.impl.ui.ConvertProjectDialog; import com.intellij.ide.IdeBundle; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.impl.stores.IProjectStore; import com.intellij.openapi.diagnostic.Logger; @@ -166,6 +167,10 @@ public class ConversionServiceImpl extends ConversionService { } public static boolean isConversionNeeded(String projectPath) throws CannotConvertException { + if (projectPath == null || !new File(projectPath).exists() || ApplicationManager.getApplication().isHeadlessEnvironment()) { + return false; + } + final ConversionContextImpl context = new ConversionContextImpl(projectPath); final List runners = getSortedConverters(context); if (runners.isEmpty()) { diff --git a/platform/lang-impl/src/com/intellij/openapi/project/impl/IdeaProjectManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/project/impl/IdeaProjectManagerImpl.java deleted file mode 100644 index ba84982b6c85..000000000000 --- a/platform/lang-impl/src/com/intellij/openapi/project/impl/IdeaProjectManagerImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2000-2009 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.openapi.project.impl; - -import com.intellij.conversion.ConversionResult; -import com.intellij.conversion.ConversionService; -import com.intellij.conversion.impl.ConversionResultImpl; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.startup.StartupManager; -import com.intellij.openapi.util.Ref; -import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; - -/** - * @author mike - */ -public class IdeaProjectManagerImpl extends ProjectManagerImpl { - public IdeaProjectManagerImpl(VirtualFileManagerEx virtualFileManagerEx, ProgressManager progressManager) { - super(virtualFileManagerEx, progressManager); - } - - @NotNull - private static ConversionResult convertProject(final String filePath) throws ProcessCanceledException { - final String fp = canonicalize(filePath); - - final File f = new File(fp); - if (fp != null && f.exists() && !ApplicationManager.getApplication().isHeadlessEnvironment()) { - return ConversionService.getInstance().convert(fp); - } - return ConversionResultImpl.CONVERSION_NOT_NEEDED; - } - - @Nullable - public Project convertAndLoadProject(String filePath, boolean convert, Ref cancelled) throws IOException { - final ConversionResult conversionResult; - if (convert) { - conversionResult = convertProject(filePath); - if (conversionResult.openingIsCanceled()) { - cancelled.set(true); - return null; - } - } - else { - conversionResult = null; - } - - final Project project = loadProjectWithProgress(filePath); - if (project == null) return null; - - if (conversionResult != null && !conversionResult.conversionNotNeeded()) { - StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() { - public void run() { - conversionResult.postStartupActivity(project); - } - }); - } - return project; - } -} diff --git a/platform/lang-impl/src/com/intellij/conversion/ConversionListener.java b/platform/platform-impl/src/com/intellij/conversion/ConversionListener.java similarity index 100% rename from platform/lang-impl/src/com/intellij/conversion/ConversionListener.java rename to platform/platform-impl/src/com/intellij/conversion/ConversionListener.java diff --git a/platform/lang-impl/src/com/intellij/conversion/ConversionResult.java b/platform/platform-impl/src/com/intellij/conversion/ConversionResult.java similarity index 100% rename from platform/lang-impl/src/com/intellij/conversion/ConversionResult.java rename to platform/platform-impl/src/com/intellij/conversion/ConversionResult.java diff --git a/platform/lang-impl/src/com/intellij/conversion/ConversionService.java b/platform/platform-impl/src/com/intellij/conversion/ConversionService.java similarity index 89% rename from platform/lang-impl/src/com/intellij/conversion/ConversionService.java rename to platform/platform-impl/src/com/intellij/conversion/ConversionService.java index 4c79b51b86c7..e9992f6207b2 100644 --- a/platform/lang-impl/src/com/intellij/conversion/ConversionService.java +++ b/platform/platform-impl/src/com/intellij/conversion/ConversionService.java @@ -27,8 +27,10 @@ import java.io.File; */ public abstract class ConversionService { + @NotNull public static ConversionService getInstance() { - return ServiceManager.getService(ConversionService.class); + ConversionService service = ServiceManager.getService(ConversionService.class); + return service == null ? new DummyConversionService() : service; } @NotNull diff --git a/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java b/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java new file mode 100644 index 000000000000..76ffd0de11de --- /dev/null +++ b/platform/platform-impl/src/com/intellij/conversion/DummyConversionService.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2011 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.conversion; + +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +/** + * @author Dmitry Avdeev + * Date: 9/22/11 + */ +public class DummyConversionService extends ConversionService { + + private static final ConversionResult CONVERSION_RESULT = new ConversionResult() { + @Override + public boolean conversionNotNeeded() { + return true; + } + + @Override + public boolean openingIsCanceled() { + return false; + } + + @Override + public void postStartupActivity(@NotNull Project project) { + } + }; + + @NotNull + @Override + public ConversionResult convertSilently(@NotNull String projectPath) { + return CONVERSION_RESULT; + } + + @NotNull + @Override + public ConversionResult convertSilently(@NotNull String projectPath, @NotNull ConversionListener conversionListener) { + return CONVERSION_RESULT; + } + + @NotNull + @Override + public ConversionResult convert(@NotNull String projectPath) { + return CONVERSION_RESULT; + } + + @NotNull + @Override + public ConversionResult convertModule(@NotNull Project project, @NotNull File moduleFile) { + return CONVERSION_RESULT; + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java index 0ad0edc7ed59..06c42c95fa93 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectManagerEx.java @@ -61,9 +61,6 @@ public abstract class ProjectManagerEx extends ProjectManager { @TestOnly public abstract void setCurrentTestProject(@Nullable Project project); - @Nullable - public abstract Project loadAndOpenProject(String filePath, boolean convert) throws IOException, JDOMException, InvalidDataException; - // returns true on success public abstract boolean closeAndDispose(@NotNull Project project); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index 515b5038071b..1faf066c4d6a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -15,6 +15,8 @@ */ package com.intellij.openapi.project.impl; +import com.intellij.conversion.ConversionResult; +import com.intellij.conversion.ConversionService; import com.intellij.ide.AppLifecycleListener; import com.intellij.ide.highlighter.WorkspaceFileType; import com.intellij.ide.impl.ProjectUtil; @@ -320,9 +322,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt return project; } - @Nullable - protected static String canonicalize(final String filePath) { - if (filePath == null) return null; + @NotNull + private static String canonicalize(final @NotNull String filePath) { try { return FileUtil.resolveShortWindowsName(filePath); } @@ -475,38 +476,28 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt myOpenProjectsArrayCache = myOpenProjects.toArray(new Project[myOpenProjects.size()]); } - public Project loadAndOpenProject(@NotNull String filePath) throws IOException, JDOMException, InvalidDataException { - return loadAndOpenProject(filePath, true); - } - - @Nullable - public Project convertAndLoadProject(String filePath, boolean convert, Ref cancelled) throws IOException { - return loadProjectWithProgress(filePath, cancelled); - } - - @Nullable - public Project loadAndOpenProject(final String filePath, final boolean convert) throws IOException, JDOMException, InvalidDataException { + public Project loadAndOpenProject(@NotNull final String filePath) throws IOException, JDOMException, InvalidDataException { final Ref projectRef = new Ref(); final Ref exceptionRef = new Ref(); myProgressManager.runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { try { - final Project project = convertAndLoadProject(filePath, convert, new Ref()); + final Project project = convertAndLoadProject(filePath, new Ref()); if (project == null) { return; } - + if (!openProject(project)) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { Disposer.dispose(project); } }); - + return; } - + projectRef.set(project); } catch (StateStorageException e) { @@ -517,7 +508,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } } }, ProjectBundle.message("project.load.progress"), true, null); - + if (!exceptionRef.isNull()) { throw exceptionRef.get(); } @@ -525,8 +516,26 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } @Nullable - public Project loadProjectWithProgress(final String filePath) throws IOException { - return loadProjectWithProgress(filePath, new Ref()); + public Project convertAndLoadProject(String filePath, Ref cancelled) throws IOException { + final ConversionResult conversionResult; + final String fp = canonicalize(filePath); + conversionResult = ConversionService.getInstance().convert(fp); + if (conversionResult.openingIsCanceled()) { + cancelled.set(true); + return null; + } + + final Project project = loadProjectWithProgress(filePath, new Ref()); + if (project == null) return null; + + if (!conversionResult.conversionNotNeeded()) { + StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() { + public void run() { + conversionResult.postStartupActivity(project); + } + }); + } + return project; } @Nullable diff --git a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java index c48072f9bcae..daea27f7812a 100644 --- a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java +++ b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java @@ -113,7 +113,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor { Ref cancelled = new Ref(); if (projectDir.exists()) { try { - project = ((ProjectManagerImpl) projectManager).convertAndLoadProject(baseDir.getPath(), true, cancelled); + project = ((ProjectManagerImpl) projectManager).convertAndLoadProject(baseDir.getPath(), cancelled); } catch (Exception e) { // ignore diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index 098fb01e245a..8f2cc32d2a47 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -5,6 +5,11 @@ com.intellij.openapi.application.impl.ApplicationInfoImpl + + com.intellij.openapi.project.ProjectManager + com.intellij.openapi.project.impl.ProjectManagerImpl + + com.intellij.openapi.fileTypes.FileTypeManager com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl diff --git a/platform/platform-resources/src/componentSets/PlatformComponents.xml b/platform/platform-resources/src/componentSets/PlatformComponents.xml index b41d2643a2e6..29037ab0a7e3 100644 --- a/platform/platform-resources/src/componentSets/PlatformComponents.xml +++ b/platform/platform-resources/src/componentSets/PlatformComponents.xml @@ -15,10 +15,6 @@ com.intellij.openapi.project.impl.ProjectStoreClassProvider com.intellij.openapi.components.impl.stores.PlatformProjectStoreClassProvider - - com.intellij.openapi.project.ProjectManager - com.intellij.openapi.project.impl.ProjectManagerImpl - com.intellij.ide.RecentProjectsManagerBase com.intellij.ide.RecentDirectoryProjectsManager diff --git a/platform/platform-resources/src/componentSets/PlatformLangComponents.xml b/platform/platform-resources/src/componentSets/PlatformLangComponents.xml index fd3392089f42..15111aa95056 100644 --- a/platform/platform-resources/src/componentSets/PlatformLangComponents.xml +++ b/platform/platform-resources/src/componentSets/PlatformLangComponents.xml @@ -16,10 +16,6 @@ com.intellij.openapi.components.impl.stores.PlatformLangProjectStoreClassProvider - com.intellij.openapi.project.ProjectManager - com.intellij.openapi.project.impl.IdeaProjectManagerImpl - - com.intellij.ide.RecentProjectsManagerBase com.intellij.ide.RecentDirectoryProjectsManager diff --git a/resources/src/componentSets/IdeaComponents.xml b/resources/src/componentSets/IdeaComponents.xml index 1bd50dd65b27..6d3c6b76943a 100644 --- a/resources/src/componentSets/IdeaComponents.xml +++ b/resources/src/componentSets/IdeaComponents.xml @@ -15,10 +15,6 @@ com.intellij.openapi.project.impl.ProjectStoreClassProvider com.intellij.openapi.components.impl.stores.IdeaProjectStoreClassProvider - - com.intellij.openapi.project.ProjectManager - com.intellij.openapi.project.impl.IdeaProjectManagerImpl -