Search in sources :

Example 46 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project intellij-plugins by StepicOrg.

the class StepikProjectManager method refreshCourse.

private void refreshCourse() {
    if (project == null || root == null) {
        return;
    }
    root.setProject(project);
    executor.execute(() -> {
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        if (isAuthenticated()) {
            root.reloadData(project, stepikApiClient);
        }
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Synchronize Project") {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                if (project.isDisposed()) {
                    return;
                }
                repairProjectFiles(root);
                repairSandbox();
                ApplicationManager.getApplication().invokeLater(() -> {
                    VirtualFileManager.getInstance().syncRefresh();
                    setSelected(selected, false);
                });
            }

            private void repairSandbox() {
                VirtualFile projectDir = project.getBaseDir();
                if (projectDir != null && projectDir.findChild(EduNames.SANDBOX_DIR) == null) {
                    Application application = ApplicationManager.getApplication();
                    ModifiableModuleModel model = application.runReadAction((Computable<ModifiableModuleModel>) () -> ModuleManager.getInstance(project).getModifiableModel());
                    application.invokeLater(() -> application.runWriteAction(() -> {
                        try {
                            new SandboxModuleBuilder(projectDir.getPath()).createModule(model);
                            model.commit();
                        } catch (IOException | ConfigurationException | JDOMException | ModuleWithNameAlreadyExists e) {
                            logger.warn("Failed repair Sandbox", e);
                        }
                    }));
                }
            }
        });
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Task(com.intellij.openapi.progress.Task) SandboxModuleBuilder(org.stepik.plugin.projectWizard.idea.SandboxModuleBuilder) ModuleWithNameAlreadyExists(com.intellij.openapi.module.ModuleWithNameAlreadyExists) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Application(com.intellij.openapi.application.Application) Computable(com.intellij.openapi.util.Computable)

Example 47 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.

the class AndroidGradleTestCase method importProject.

protected void importProject(@NotNull String projectName, @NotNull File projectRoot, @Nullable GradleSyncListener listener) throws Exception {
    Ref<Throwable> throwableRef = new Ref<>();
    SyncListener syncListener = new SyncListener();
    Project project = getProject();
    GradleSyncState.subscribe(project, syncListener);
    runWriteCommandAction(project, () -> {
        try {
            // When importing project for tests we do not generate the sources as that triggers a compilation which finishes asynchronously.
            // This causes race conditions and intermittent errors. If a test needs source generation this should be handled separately.
            GradleProjectImporter.Request request = new GradleProjectImporter.Request();
            request.setProject(project).setGenerateSourcesOnSuccess(false);
            GradleProjectImporter.getInstance().importProject(projectName, projectRoot, request, listener);
        } catch (Throwable e) {
            throwableRef.set(e);
        }
    });
    Throwable throwable = throwableRef.get();
    if (throwable != null) {
        if (throwable instanceof IOException) {
            throw (IOException) throwable;
        } else if (throwable instanceof ConfigurationException) {
            throw (ConfigurationException) throwable;
        } else {
            throw new RuntimeException(throwable);
        }
    }
    syncListener.await();
    if (syncListener.failureMessage != null && listener == null) {
        fail(syncListener.failureMessage);
    }
}
Also used : Projects.isLegacyIdeaAndroidProject(com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) IOException(java.io.IOException)

Example 48 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.

the class IdeSdksConfigurable method validate.

public boolean validate() throws ConfigurationException {
    String msg = validateAndroidSdkPath();
    if (msg != null) {
        throw new ConfigurationException(msg);
    }
    if (!useEmbeddedJdk()) {
        File validJdkLocation = validateJdkPath(getJdkLocation());
        if (validJdkLocation == null) {
            throw new ConfigurationException(CHOOSE_VALID_JDK_DIRECTORY_ERR);
        }
    }
    msg = validateAndroidNdkPath();
    if (msg != null) {
        throw new ConfigurationException(msg);
    }
    return true;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 49 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project intellij-plugins by JetBrains.

the class FlexBCConfigurator method copy.

public void copy(final CompositeConfigurable configurable, final Runnable treeNodeNameUpdater) {
    try {
        configurable.apply();
    } catch (ConfigurationException ignored) {
    /**/
    }
    ModifiableFlexBuildConfiguration existingBC = myConfigurablesMap.getKeysByValue(configurable).get(0);
    FlexBCConfigurable unwrapped = FlexBCConfigurable.unwrap(configurable);
    final String title = FlexBundle.message("copy.build.configuration", existingBC.getName(), unwrapped.getModule().getName());
    Module module = unwrapped.getModule();
    AddBuildConfigurationDialog dialog = new AddBuildConfigurationDialog(module.getProject(), title, getUsedNames(module), existingBC.getNature(), true);
    dialog.reset("", existingBC.getAndroidPackagingOptions().isEnabled(), existingBC.getIosPackagingOptions().isEnabled());
    if (!dialog.showAndGet()) {
        return;
    }
    final String newBCName = dialog.getBCName();
    final String fileName = PathUtil.suggestFileName(newBCName);
    final BuildConfigurationNature newNature = dialog.getNature();
    ModifiableFlexBuildConfiguration newBC = myConfigEditor.copyConfiguration(existingBC, newNature);
    newBC.setName(newBCName);
    newBC.setOutputFileName(fileName + (newBC.getOutputType() == OutputType.Library ? ".swc" : ".swf"));
    updatePackageFileName(newBC, fileName);
    if (newNature.isApp() && newNature.isMobilePlatform()) {
        newBC.getAndroidPackagingOptions().setEnabled(dialog.isAndroidEnabled());
        newBC.getIosPackagingOptions().setEnabled(dialog.isIOSEnabled());
    }
    createConfigurableNode(newBC, unwrapped.getModule(), treeNodeNameUpdater);
}
Also used : BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FlexBCConfigurable(com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable) Module(com.intellij.openapi.module.Module) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) AddBuildConfigurationDialog(com.intellij.lang.javascript.flex.projectStructure.ui.AddBuildConfigurationDialog)

Example 50 with ConfigurationException

use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.

the class AdtImportLocationStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    WizardContext context = getWizardContext();
    GradleImport importer = AdtImportProvider.getImporter(context);
    if (importer != null) {
        List<String> errors = importer.getErrors();
        if (!errors.isEmpty()) {
            throw new ConfigurationException(errors.get(0));
        }
    }
    // The following code is based on similar code in com.intellij.ide.util.newProjectWizard.ProjectNameStep
    String projectFileDirectory = getProjectFileDirectory();
    if (projectFileDirectory.length() == 0) {
        throw new ConfigurationException(String.format("Enter %1$s file location", context.getPresentationName()));
    }
    boolean shouldPromptCreation = myIsPathChangedByUser;
    if (!ProjectWizardUtil.createDirectoryIfNotExists(String.format("The %1$s file directory\n", context.getPresentationName()), projectFileDirectory, shouldPromptCreation)) {
        return false;
    }
    boolean shouldContinue = true;
    File projectFile = new File(getProjectFileDirectory());
    String title = "New Project";
    if (projectFile.isFile()) {
        shouldContinue = false;
        String message = String.format("%s exists and is a file.\nPlease specify a different project location", projectFile.getAbsolutePath());
        Messages.showErrorDialog(message, title);
    } else if (projectFile.isDirectory()) {
        File[] files = projectFile.listFiles();
        if (files != null && files.length > 0) {
            String message = String.format("%1$s folder already exists and is not empty.\nIts content may be overwritten.\nContinue?", projectFile.getAbsolutePath());
            int answer = Messages.showYesNoDialog(message, title, Messages.getQuestionIcon());
            shouldContinue = answer == 0;
        }
    }
    return shouldContinue;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ConfigurationException (com.intellij.openapi.options.ConfigurationException)102 File (java.io.File)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Project (com.intellij.openapi.project.Project)22 Module (com.intellij.openapi.module.Module)18 IOException (java.io.IOException)14 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)7 Sdk (com.intellij.openapi.projectRoots.Sdk)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)6 Disposable (com.intellij.openapi.Disposable)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 Pair (com.intellij.openapi.util.Pair)4 GradleProjectImporter (com.android.tools.idea.gradle.project.importing.GradleProjectImporter)3 ExecutionException (com.intellij.execution.ExecutionException)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)3 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)3 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)3