Search in sources :

Example 21 with ConfigurationException

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

the class IntroduceParameterObjectDialog method canRun.

@Override
protected void canRun() throws ConfigurationException {
    super.canRun();
    final Project project = mySourceMethod.getProject();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    if (myCreateInnerClassRadioButton.isSelected()) {
        final String innerClassName = getInnerClassName();
        if (!nameHelper.isIdentifier(innerClassName))
            throw new ConfigurationException("\'" + innerClassName + "\' is invalid inner class name");
        if (mySourceMethod.getContainingClass().findInnerClassByName(innerClassName, false) != null)
            throw new ConfigurationException("Inner class with name \'" + innerClassName + "\' already exist");
    } else if (!useExistingClass()) {
        final String className = getClassName();
        if (className.length() == 0 || !nameHelper.isIdentifier(className)) {
            throw new ConfigurationException("\'" + className + "\' is invalid parameter class name");
        }
        final String packageName = getPackageName();
        if (packageName.length() == 0 || !nameHelper.isQualifiedName(packageName)) {
            throw new ConfigurationException("\'" + packageName + "\' is invalid parameter class package name");
        }
    } else {
        final String className = getExistingClassName();
        if (className.length() == 0 || !nameHelper.isQualifiedName(className)) {
            throw new ConfigurationException("\'" + className + "\' is invalid qualified parameter class name");
        }
        if (JavaPsiFacade.getInstance(getProject()).findClass(className, GlobalSearchScope.allScope(getProject())) == null) {
            throw new ConfigurationException("\'" + className + "\' does not exist");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 22 with ConfigurationException

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

the class JsonSchemaConfigurable method doValidation.

private void doValidation() throws ConfigurationException {
    final File file = new File(myProject.getBasePath(), myView.getSchemaSubPath());
    VirtualFile vFile = null;
    if (!file.exists() || (vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file)) == null) {
        throw new ConfigurationException((!StringUtil.isEmptyOrSpaces(myDisplayName) ? (myDisplayName + ": ") : "") + "Schema file does not exist");
    }
    final String filename = file.getName();
    if (StringUtil.isEmptyOrSpaces(myDisplayName))
        throw new ConfigurationException(filename + ": Schema name is empty");
    if (StringUtil.isEmptyOrSpaces(myView.getSchemaSubPath()))
        throw new ConfigurationException(filename + ": Schema path is empty");
    final CollectConsumer<String> collectConsumer = new CollectConsumer<>();
    final JsonSchemaService service = JsonSchemaService.Impl.get(myProject);
    if (service != null && !service.isSchemaFile(vFile, collectConsumer)) {
        final String message;
        if (collectConsumer.getResult().isEmpty())
            message = filename + ": Can not read JSON schema from file (Unknown reason)";
        else
            message = filename + ": Can not read JSON schema from file: " + StringUtil.join(collectConsumer.getResult(), "; ");
        logErrorForUser(message);
        throw new RuntimeConfigurationWarning(message);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConfigurationException(com.intellij.openapi.options.ConfigurationException) CollectConsumer(com.intellij.util.CollectConsumer) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JsonSchemaService(com.jetbrains.jsonSchema.ide.JsonSchemaService)

Example 23 with ConfigurationException

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

the class VcsConfigurationsDialog method doOKAction.

protected void doOKAction() {
    for (String vcsName : myVcsNameToConfigurableMap.keySet()) {
        UnnamedConfigurable configurable = myVcsNameToConfigurableMap.get(vcsName);
        if (configurable != null && configurable.isModified()) {
            try {
                configurable.apply();
            } catch (ConfigurationException e) {
                Messages.showErrorDialog(VcsBundle.message("message.text.unable.to.save.settings", e.getMessage()), VcsBundle.message("message.title.unable.to.save.settings"));
            }
        }
    }
    final JComboBox vcsesToUpdate = myVcsesToUpdate;
    if (vcsesToUpdate != null) {
        final VcsDescriptor wrapper = (VcsDescriptor) myVcses.getSelectedValue();
        vcsesToUpdate.setSelectedItem(wrapper);
        final ComboBoxModel model = vcsesToUpdate.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            final Object vcsWrapper = model.getElementAt(i);
            if (vcsWrapper instanceof VcsDescriptor) {
                final VcsDescriptor defaultVcsWrapper = (VcsDescriptor) vcsWrapper;
                if (defaultVcsWrapper.equals(wrapper)) {
                    vcsesToUpdate.setSelectedIndex(i);
                    break;
                }
            }
        }
    }
    super.doOKAction();
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) VcsDescriptor(com.intellij.openapi.vcs.impl.VcsDescriptor)

Example 24 with ConfigurationException

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

the class GradleModuleBuilder method saveFile.

private static void saveFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
    FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
    FileTemplate template = manager.getInternalTemplate(templateName);
    try {
        appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
    } catch (IOException e) {
        LOG.warn(String.format("Unexpected exception on applying template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
        throw new ConfigurationException(e.getMessage(), String.format("Can't apply %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) IOException(java.io.IOException)

Example 25 with ConfigurationException

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

the class GradleModuleBuilder method appendToFile.

private static void appendToFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
    FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
    FileTemplate template = manager.getInternalTemplate(templateName);
    try {
        appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
    } catch (IOException e) {
        LOG.warn(String.format("Unexpected exception on appending template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
        throw new ConfigurationException(e.getMessage(), String.format("Can't append %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) IOException(java.io.IOException)

Aggregations

ConfigurationException (com.intellij.openapi.options.ConfigurationException)86 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 File (java.io.File)17 Module (com.intellij.openapi.module.Module)16 Project (com.intellij.openapi.project.Project)15 IOException (java.io.IOException)12 NotNull (org.jetbrains.annotations.NotNull)9 Nullable (org.jetbrains.annotations.Nullable)8 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)7 Sdk (com.intellij.openapi.projectRoots.Sdk)6 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5 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 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)3 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)3 FlexBCConfigurable (com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable)3 Disposable (com.intellij.openapi.Disposable)3 Library (com.intellij.openapi.roots.libraries.Library)3