Search in sources :

Example 1 with ConversionResult

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;
}
Also used : ConversionResult(com.intellij.conversion.ConversionResult) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) File(java.io.File)

Example 2 with ConversionResult

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;
}
Also used : ConversionResult(com.intellij.conversion.ConversionResult) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ConversionResult

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;
}
Also used : ConversionResult(com.intellij.conversion.ConversionResult) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException)

Aggregations

ConversionResult (com.intellij.conversion.ConversionResult)3 IOException (java.io.IOException)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 File (java.io.File)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 Nullable (org.jetbrains.annotations.Nullable)1