use of com.intellij.conversion.ConversionResult in project intellij-community by JetBrains.
the class ExistingModuleLoader method validate.
@Override
public boolean validate(final Project current, final Project dest) {
if (getName() == null)
return false;
String moduleFilePath = getModuleFilePath();
if (moduleFilePath == null)
return false;
final File file = new File(moduleFilePath);
if (file.exists()) {
try {
final ConversionResult result = ConversionService.getInstance().convertModule(dest, file);
if (result.openingIsCanceled()) {
return false;
}
final Element root = JDOMUtil.load(file);
final Set<String> usedMacros = PathMacrosCollector.getMacroNames(root);
usedMacros.remove("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$");
usedMacros.removeAll(PathMacros.getInstance().getAllMacroNames());
if (usedMacros.size() > 0) {
final boolean ok = ProjectMacrosUtil.showMacrosConfigurationDialog(current, usedMacros);
if (!ok) {
return false;
}
}
} catch (JDOMException | IOException e) {
Messages.showMessageDialog(e.getMessage(), IdeBundle.message("title.error.reading.file"), Messages.getErrorIcon());
return false;
}
} else {
Messages.showErrorDialog(current, IdeBundle.message("title.module.file.does.not.exist", moduleFilePath), CommonBundle.message("title.error"));
return false;
}
return true;
}
use of com.intellij.conversion.ConversionResult in project intellij-community by JetBrains.
the class ProjectManagerImpl method convertAndLoadProject.
/**
* Converts and loads the project at the specified path.
*
* @param filePath the path to open the project.
* @return the project, or null if the user has cancelled opening the project.
*/
@Override
@Nullable
public Project convertAndLoadProject(@NotNull String filePath) throws IOException {
final String fp = toCanonicalName(filePath);
final ConversionResult conversionResult = ConversionService.getInstance().convert(fp);
if (conversionResult.openingIsCanceled()) {
return null;
}
ProjectImpl project = createProject(null, toCanonicalName(filePath), false);
if (!loadProjectWithProgress(project))
return null;
if (!conversionResult.conversionNotNeeded()) {
StartupManager.getInstance(project).registerPostStartupActivity(() -> conversionResult.postStartupActivity(project));
}
return project;
}
use of com.intellij.conversion.ConversionResult in project intellij-community by JetBrains.
the class ProjectManagerImpl method loadAndOpenProject.
@Override
public Project loadAndOpenProject(@NotNull final String originalFilePath) throws IOException {
final String filePath = toCanonicalName(originalFilePath);
final ConversionResult conversionResult = ConversionService.getInstance().convert(filePath);
ProjectImpl project;
if (conversionResult.openingIsCanceled()) {
project = null;
} else {
project = createProject(null, toCanonicalName(filePath), false);
myProgressManager.run(new Task.WithResult<Project, IOException>(project, ProjectBundle.message("project.load.progress"), true) {
@Override
protected Project compute(@NotNull ProgressIndicator indicator) throws IOException {
if (!loadProjectWithProgress(project)) {
return null;
}
if (!conversionResult.conversionNotNeeded()) {
StartupManager.getInstance(project).registerPostStartupActivity(() -> conversionResult.postStartupActivity(project));
}
openProject(project);
return project;
}
});
}
if (project == null) {
WelcomeFrame.showIfNoProjectOpened();
return null;
}
if (!project.isOpen()) {
WelcomeFrame.showIfNoProjectOpened();
ApplicationManager.getApplication().runWriteAction(() -> {
if (!project.isDisposed()) {
Disposer.dispose(project);
}
});
}
return project;
}
Aggregations