IdeaProjectManagerImpl merged into ProjectManagerImpl

This commit is contained in:
Dmitry Avdeev
2011-09-22 14:24:56 +04:00
parent 6749348ba0
commit 1dc96566ff
14 changed files with 112 additions and 118 deletions
@@ -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;
@@ -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<ConversionRunner> runners = getSortedConverters(context);
if (runners.isEmpty()) {
@@ -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<Boolean> 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;
}
}
@@ -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
@@ -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;
}
}
@@ -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);
}
@@ -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<Boolean> 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<Project> projectRef = new Ref<Project>();
final Ref<IOException> exceptionRef = new Ref<IOException>();
myProgressManager.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
try {
final Project project = convertAndLoadProject(filePath, convert, new Ref<Boolean>());
final Project project = convertAndLoadProject(filePath, new Ref<Boolean>());
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<Boolean>());
public Project convertAndLoadProject(String filePath, Ref<Boolean> 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<Boolean>());
if (project == null) return null;
if (!conversionResult.conversionNotNeeded()) {
StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() {
public void run() {
conversionResult.postStartupActivity(project);
}
});
}
return project;
}
@Nullable
@@ -113,7 +113,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor {
Ref<Boolean> cancelled = new Ref<Boolean>();
if (projectDir.exists()) {
try {
project = ((ProjectManagerImpl) projectManager).convertAndLoadProject(baseDir.getPath(), true, cancelled);
project = ((ProjectManagerImpl) projectManager).convertAndLoadProject(baseDir.getPath(), cancelled);
}
catch (Exception e) {
// ignore
@@ -5,6 +5,11 @@
<implementation-class>com.intellij.openapi.application.impl.ApplicationInfoImpl</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.project.ProjectManager</interface-class>
<implementation-class>com.intellij.openapi.project.impl.ProjectManagerImpl</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.fileTypes.FileTypeManager</interface-class>
<implementation-class>com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl</implementation-class>
@@ -15,10 +15,6 @@
<interface-class>com.intellij.openapi.project.impl.ProjectStoreClassProvider</interface-class>
<implementation-class>com.intellij.openapi.components.impl.stores.PlatformProjectStoreClassProvider</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.project.ProjectManager</interface-class>
<implementation-class>com.intellij.openapi.project.impl.ProjectManagerImpl</implementation-class>
</component>
<component>
<interface-class>com.intellij.ide.RecentProjectsManagerBase</interface-class>
<implementation-class>com.intellij.ide.RecentDirectoryProjectsManager</implementation-class>
@@ -16,10 +16,6 @@
<implementation-class>com.intellij.openapi.components.impl.stores.PlatformLangProjectStoreClassProvider</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.project.ProjectManager</interface-class>
<implementation-class>com.intellij.openapi.project.impl.IdeaProjectManagerImpl</implementation-class>
</component>
<component>
<interface-class>com.intellij.ide.RecentProjectsManagerBase</interface-class>
<implementation-class>com.intellij.ide.RecentDirectoryProjectsManager</implementation-class>
</component>
@@ -15,10 +15,6 @@
<interface-class>com.intellij.openapi.project.impl.ProjectStoreClassProvider</interface-class>
<implementation-class>com.intellij.openapi.components.impl.stores.IdeaProjectStoreClassProvider</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.project.ProjectManager</interface-class>
<implementation-class>com.intellij.openapi.project.impl.IdeaProjectManagerImpl</implementation-class>
</component>
</application-components>
<project-components>
<component>