Search in sources :

Example 76 with ConfigurationException

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

the class SvnConfigureProxiesComponent method createActions.

protected ArrayList<AnAction> createActions(final boolean fromPopup) {
    ArrayList<AnAction> result = new ArrayList<>();
    result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {

        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            addGroup(null);
        }
    });
    result.add(new MyDeleteAction(forAll(o -> {
        if (o instanceof MyNode) {
            final MyNode node = (MyNode) o;
            if (node.getConfigurable() instanceof GroupConfigurable) {
                final ProxyGroup group = ((GroupConfigurable) node.getConfigurable()).getEditableObject();
                return !group.isDefault();
            }
        }
        return false;
    })) {

        public void actionPerformed(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            final MyNode node = (MyNode) path.getLastPathComponent();
            final MyNode parentNode = (MyNode) node.getParent();
            int idx = parentNode.getIndex(node);
            super.actionPerformed(e);
            idx = (idx == parentNode.getChildCount()) ? idx - 1 : idx;
            if (parentNode.getChildCount() > 0) {
                final TreePath newSelectedPath = new TreePath(parentNode.getPath()).pathByAddingChild(parentNode.getChildAt(idx));
                myTree.setSelectionPath(newSelectedPath);
            }
        }
    });
    result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {

        {
            registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            // apply - for update of editable object
            try {
                getSelectedConfigurable().apply();
            } catch (ConfigurationException e) {
            // suppress & wait for OK
            }
            final ProxyGroup selectedGroup = (ProxyGroup) getSelectedObject();
            if (selectedGroup != null) {
                addGroup(selectedGroup);
            }
        }

        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    return result;
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TreePath(javax.swing.tree.TreePath) ConfigurationException(com.intellij.openapi.options.ConfigurationException) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 77 with ConfigurationException

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

the class EclipseClasspathStorageProvider method assertCompatible.

@Override
public void assertCompatible(final ModuleRootModel model) throws ConfigurationException {
    final String moduleName = model.getModule().getName();
    for (OrderEntry entry : model.getOrderEntries()) {
        if (entry instanceof LibraryOrderEntry) {
            final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
            if (libraryEntry.isModuleLevel()) {
                final Library library = libraryEntry.getLibrary();
                if (library == null || libraryEntry.getRootUrls(OrderRootType.CLASSES).length != 1 || library.isJarDirectory(library.getUrls(OrderRootType.CLASSES)[0])) {
                    throw new ConfigurationException("Library \'" + entry.getPresentableName() + "\' from module \'" + moduleName + "\' dependencies is incompatible with eclipse format which supports only one library content root");
                }
            }
        }
    }
    if (model.getContentRoots().length == 0) {
        throw new ConfigurationException("Module \'" + moduleName + "\' has no content roots thus is not compatible with eclipse format");
    }
    final String output = model.getModuleExtension(CompilerModuleExtension.class).getCompilerOutputUrl();
    final String contentRoot = getContentRoot(model);
    if (output == null || !StringUtil.startsWith(VfsUtilCore.urlToPath(output), contentRoot) && PathMacroManager.getInstance(model.getModule()).collapsePath(output).equals(output)) {
        throw new ConfigurationException("Module \'" + moduleName + "\' output path is incompatible with eclipse format which supports output under content root only.\nPlease make sure that \"Inherit project compile output path\" is not selected");
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) Library(com.intellij.openapi.roots.libraries.Library)

Example 78 with ConfigurationException

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

the class CertificateConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    List<X509Certificate> existing = myTrustManager.getCertificates();
    Set<X509Certificate> added = new HashSet<>(myCertificates);
    added.removeAll(existing);
    Set<X509Certificate> removed = new HashSet<>(existing);
    removed.removeAll(myCertificates);
    for (X509Certificate certificate : added) {
        if (!myTrustManager.addCertificate(certificate)) {
            throw new ConfigurationException("Cannot add certificate for " + getCommonName(certificate), "Cannot Add Certificate");
        }
    }
    for (X509Certificate certificate : removed) {
        if (!myTrustManager.removeCertificate(certificate)) {
            throw new ConfigurationException("Cannot remove certificate for " + getCommonName(certificate), "Cannot Remove Certificate");
        }
    }
    CertificateManager.Config state = CertificateManager.getInstance().getState();
    state.ACCEPT_AUTOMATICALLY = myAcceptAutomatically.isSelected();
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) X509Certificate(java.security.cert.X509Certificate) HashSet(com.intellij.util.containers.HashSet)

Example 79 with ConfigurationException

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

the class ExportEclipseProjectsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    // to flush iml files
    if (project == null) {
        return;
    }
    project.save();
    List<Module> modules = new SmartList<>();
    List<Module> incompatibleModules = new SmartList<>();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        if (!EclipseModuleManagerImpl.isEclipseStorage(module)) {
            try {
                ClasspathStorageProvider provider = ClasspathStorage.getProvider(JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
                if (provider != null) {
                    provider.assertCompatible(ModuleRootManager.getInstance(module));
                }
                modules.add(module);
            } catch (ConfigurationException ignored) {
                incompatibleModules.add(module);
            }
        }
    }
    //todo suggest smth with hierarchy modules
    if (incompatibleModules.isEmpty()) {
        if (modules.isEmpty()) {
            Messages.showInfoMessage(project, EclipseBundle.message("eclipse.export.nothing.to.do"), EclipseBundle.message("eclipse.export.dialog.title"));
            return;
        }
    } else if (Messages.showOkCancelDialog(project, "<html><body>Eclipse incompatible modules found:<ul><br><li>" + StringUtil.join(incompatibleModules, module -> module.getName(), "<br><li>") + "</ul><br>Would you like to proceed and possibly lose your configurations?</body></html>", EclipseBundle.message("eclipse.export.dialog.title"), Messages.getWarningIcon()) != Messages.OK) {
        return;
    }
    modules.addAll(incompatibleModules);
    ExportEclipseProjectsDialog dialog = new ExportEclipseProjectsDialog(project, modules);
    if (!dialog.showAndGet()) {
        return;
    }
    if (dialog.isLink()) {
        for (Module module : dialog.getSelectedModules()) {
            ClasspathStorage.setStorageType(ModuleRootManager.getInstance(module), JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID);
        }
    } else {
        LinkedHashMap<Module, String> module2StorageRoot = new LinkedHashMap<>();
        for (Module module : dialog.getSelectedModules()) {
            VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
            String storageRoot = contentRoots.length == 1 ? contentRoots[0].getPath() : ClasspathStorage.getStorageRootFromOptions(module);
            module2StorageRoot.put(module, storageRoot);
            try {
                DotProjectFileHelper.saveDotProjectFile(module, storageRoot);
            } catch (Exception e1) {
                LOG.error(e1);
            }
        }
        for (Module module : module2StorageRoot.keySet()) {
            ModuleRootModel model = ModuleRootManager.getInstance(module);
            String storageRoot = module2StorageRoot.get(module);
            try {
                Element classpathElement = new EclipseClasspathWriter().writeClasspath(null, model);
                File classpathFile = new File(storageRoot, EclipseXml.CLASSPATH_FILE);
                if (!FileUtil.createIfDoesntExist(classpathFile)) {
                    continue;
                }
                EclipseJDOMUtil.output(classpathElement, classpathFile, project);
                final Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
                if (IdeaSpecificSettings.writeIdeaSpecificClasspath(ideaSpecific, model)) {
                    File emlFile = new File(storageRoot, module.getName() + EclipseXml.IDEA_SETTINGS_POSTFIX);
                    if (!FileUtil.createIfDoesntExist(emlFile)) {
                        continue;
                    }
                    EclipseJDOMUtil.output(ideaSpecific, emlFile, project);
                }
            } catch (Exception e1) {
                LOG.error(e1);
            }
        }
    }
    try {
        EclipseUserLibrariesHelper.appendProjectLibraries(project, dialog.getUserLibrariesFile());
    } catch (IOException e1) {
        LOG.error(e1);
    }
    project.save();
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaXml(org.jetbrains.idea.eclipse.IdeaXml) ClasspathStorage(com.intellij.openapi.roots.impl.storage.ClasspathStorage) DotProjectFileHelper(org.jetbrains.idea.eclipse.conversion.DotProjectFileHelper) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) SmartList(com.intellij.util.SmartList) EclipseUserLibrariesHelper(org.jetbrains.idea.eclipse.conversion.EclipseUserLibrariesHelper) EclipseXml(org.jetbrains.idea.eclipse.EclipseXml) Project(com.intellij.openapi.project.Project) EclipseClasspathWriter(org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter) Messages(com.intellij.openapi.ui.Messages) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) DumbAware(com.intellij.openapi.project.DumbAware) JpsEclipseClasspathSerializer(org.jetbrains.jps.eclipse.model.JpsEclipseClasspathSerializer) StringUtil(com.intellij.openapi.util.text.StringUtil) EclipseModuleManagerImpl(org.jetbrains.idea.eclipse.config.EclipseModuleManagerImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) IOException(java.io.IOException) EclipseJDOMUtil(org.jdom.output.EclipseJDOMUtil) IdeaSpecificSettings(org.jetbrains.idea.eclipse.conversion.IdeaSpecificSettings) File(java.io.File) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ClasspathStorageProvider(com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider) Function(com.intellij.util.Function) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) EclipseBundle(org.jetbrains.idea.eclipse.EclipseBundle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) EclipseClasspathWriter(org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter) IOException(java.io.IOException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ClasspathStorageProvider(com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 80 with ConfigurationException

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

the class GradleProjectOpenProcessor method setupGradleProjectSettingsInHeadlessMode.

private boolean setupGradleProjectSettingsInHeadlessMode(GradleProjectImportProvider projectImportProvider, WizardContext wizardContext) {
    final ModuleWizardStep[] wizardSteps = projectImportProvider.createSteps(wizardContext);
    if (wizardSteps.length > 0 && wizardSteps[0] instanceof SelectExternalProjectStep) {
        SelectExternalProjectStep selectExternalProjectStep = (SelectExternalProjectStep) wizardSteps[0];
        wizardContext.setProjectBuilder(getBuilder());
        try {
            selectExternalProjectStep.updateStep();
            final ImportFromGradleControl importFromGradleControl = getBuilder().getControl(wizardContext.getProject());
            GradleProjectSettingsControl gradleProjectSettingsControl = (GradleProjectSettingsControl) importFromGradleControl.getProjectSettingsControl();
            final GradleProjectSettings projectSettings = gradleProjectSettingsControl.getInitialSettings();
            if (GRADLE_DISTRIBUTION_TYPE != null) {
                for (DistributionType type : DistributionType.values()) {
                    if (type.name().equals(GRADLE_DISTRIBUTION_TYPE)) {
                        projectSettings.setDistributionType(type);
                        break;
                    }
                }
            }
            if (GRADLE_HOME != null) {
                projectSettings.setGradleHome(GRADLE_HOME);
            }
            gradleProjectSettingsControl.reset();
            final GradleSystemSettingsControl systemSettingsControl = (GradleSystemSettingsControl) importFromGradleControl.getSystemSettingsControl();
            assert systemSettingsControl != null;
            final GradleSettings gradleSettings = systemSettingsControl.getInitialSettings();
            if (GRADLE_VM_OPTIONS != null) {
                gradleSettings.setGradleVmOptions(GRADLE_VM_OPTIONS);
            }
            if (GRADLE_OFFLINE != null) {
                gradleSettings.setOfflineWork(Boolean.parseBoolean(GRADLE_OFFLINE));
            }
            String serviceDirectory = GRADLE_SERVICE_DIRECTORY;
            if (GRADLE_SERVICE_DIRECTORY != null) {
                gradleSettings.setServiceDirectoryPath(serviceDirectory);
            }
            systemSettingsControl.reset();
            if (!selectExternalProjectStep.validate()) {
                return false;
            }
        } catch (ConfigurationException e) {
            Messages.showErrorDialog(wizardContext.getProject(), e.getMessage(), e.getTitle());
            return false;
        }
        selectExternalProjectStep.updateDataModel();
    }
    return true;
}
Also used : GradleProjectSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleSystemSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleSystemSettingsControl) ImportFromGradleControl(org.jetbrains.plugins.gradle.service.settings.ImportFromGradleControl) SelectExternalProjectStep(com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

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