Search in sources :

Example 16 with ConfigurationException

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

the class SourcePathsStep method validate.

public boolean validate() throws ConfigurationException {
    if (!super.validate()) {
        return false;
    }
    if (CREATE_SOURCE_PANEL.equals(myCurrentMode) && myRbCreateSource.isSelected()) {
        final String sourceDirectoryPath = getSourceDirectoryPath();
        final String relativePath = myTfSourceDirectoryName.getText().trim();
        if (relativePath.length() == 0) {
            String text = IdeBundle.message("prompt.relative.path.to.sources.empty", FileUtil.toSystemDependentName(sourceDirectoryPath));
            final int answer = Messages.showYesNoCancelDialog(myTfSourceDirectoryName, text, IdeBundle.message("title.mark.source.directory"), IdeBundle.message("action.mark"), IdeBundle.message("action.do.not.mark"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
            if (answer == Messages.CANCEL) {
                // cancel
                return false;
            }
            if (answer == Messages.NO) {
                // don't mark
                myRbNoSource.doClick();
            }
        }
        if (sourceDirectoryPath != null) {
            final File rootDir = new File(getContentRootPath());
            final File srcDir = new File(sourceDirectoryPath);
            if (!FileUtil.isAncestor(rootDir, srcDir, false)) {
                Messages.showErrorDialog(myTfSourceDirectoryName, IdeBundle.message("error.source.directory.should.be.under.module.content.root.directory"), CommonBundle.getErrorTitle());
                return false;
            }
            try {
                VfsUtil.createDirectories(srcDir.getPath());
            } catch (IOException e) {
                throw new ConfigurationException(e.getMessage());
            }
        }
    }
    return true;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 17 with ConfigurationException

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

the class CreateModuleFromSourcesMode method validate.

@Override
public boolean validate() throws ConfigurationException {
    final String path = myPathPanel.getText().trim();
    final File file = new File(path);
    if (!file.exists()) {
        throw new ConfigurationException("File \'" + path + "\' doesn't exist");
    }
    if (!file.isDirectory()) {
        throw new ConfigurationException("\'" + path + "\' is not a directory");
    }
    return super.validate();
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) File(java.io.File)

Example 18 with ConfigurationException

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

the class WrapReturnValueDialog method canRun.

@Override
protected void canRun() throws ConfigurationException {
    final Project project = sourceMethod.getProject();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    if (myCreateInnerClassButton.isSelected()) {
        final String innerClassName = getInnerClassName().trim();
        if (!nameHelper.isIdentifier(innerClassName))
            throw new ConfigurationException("\'" + innerClassName + "\' is invalid inner class name");
        final PsiClass containingClass = sourceMethod.getContainingClass();
        if (containingClass != null && containingClass.findInnerClassByName(innerClassName, false) != null) {
            throw new ConfigurationException("Inner class with name \'" + innerClassName + "\' already exist");
        }
    } else if (useExistingClassButton.isSelected()) {
        final String className = existingClassField.getText().trim();
        if (className.length() == 0 || !nameHelper.isQualifiedName(className)) {
            throw new ConfigurationException("\'" + className + "\' is invalid qualified wrapper class name");
        }
        final Object item = myFieldsCombo.getSelectedItem();
        if (item == null) {
            throw new ConfigurationException("Wrapper field not found");
        }
    } else {
        final String className = getClassName();
        if (className.length() == 0 || !nameHelper.isIdentifier(className)) {
            throw new ConfigurationException("\'" + className + "\' is invalid wrapper class name");
        }
        final String packageName = getPackageName();
        if (packageName.length() == 0 || !nameHelper.isQualifiedName(packageName)) {
            throw new ConfigurationException("\'" + packageName + "\' is invalid wrapper class package name");
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 19 with ConfigurationException

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

the class SdkSettingsStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    JdkComboBox.JdkComboBoxItem item = myJdkComboBox.getSelectedItem();
    if (myJdkComboBox.getSelectedJdk() == null && !(item instanceof JdkComboBox.ProjectJdkComboBoxItem) && !(item instanceof JdkComboBox.SuggestedJdkItem)) {
        if (Messages.showDialog(getNoSdkMessage(), IdeBundle.message("title.no.jdk.specified"), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }
    }
    try {
        if (item instanceof JdkComboBox.SuggestedJdkItem) {
            SdkType type = ((JdkComboBox.SuggestedJdkItem) item).getSdkType();
            String path = ((JdkComboBox.SuggestedJdkItem) item).getPath();
            myModel.addSdk(type, path, sdk -> {
                myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), myWizardContext.getProject());
                myJdkComboBox.setSelectedJdk(sdk);
            });
        }
        myModel.apply(null, true);
    } catch (ConfigurationException e) {
        //IDEA-98382 We should allow Next step if user has wrong SDK
        if (Messages.showDialog(e.getMessage() + "/nDo you want to proceed?", e.getTitle(), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }
    }
    return true;
}
Also used : SdkType(com.intellij.openapi.projectRoots.SdkType) ConfigurationException(com.intellij.openapi.options.ConfigurationException) JdkComboBox(com.intellij.openapi.roots.ui.configuration.JdkComboBox)

Example 20 with ConfigurationException

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

the class ModulesConfigurator method apply.

public void apply() throws ConfigurationException {
    // validate content and source roots 
    final Map<VirtualFile, String> contentRootToModuleNameMap = new HashMap<>();
    final Map<VirtualFile, VirtualFile> srcRootsToContentRootMap = new HashMap<>();
    for (final ModuleEditor moduleEditor : myModuleEditors.values()) {
        final ModifiableRootModel rootModel = moduleEditor.getModifiableRootModel();
        final ContentEntry[] contents = rootModel.getContentEntries();
        final String moduleName = moduleEditor.getName();
        Set<VirtualFile> sourceRoots = new HashSet<>();
        for (ContentEntry content : contents) {
            for (VirtualFile root : content.getSourceFolderFiles()) {
                if (!sourceRoots.add(root)) {
                    throw new ConfigurationException(ProjectBundle.message("module.paths.validation.duplicate.source.root.in.same.module.error", root.getPresentableUrl(), moduleName));
                }
            }
        }
        for (ContentEntry contentEntry : contents) {
            final VirtualFile contentRoot = contentEntry.getFile();
            if (contentRoot == null) {
                continue;
            }
            final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName);
            if (previousName != null && !previousName.equals(moduleName)) {
                throw new ConfigurationException(ProjectBundle.message("module.paths.validation.duplicate.content.error", contentRoot.getPresentableUrl(), previousName, moduleName));
            }
            for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) {
                final VirtualFile anotherContentRoot = srcRootsToContentRootMap.put(srcRoot, contentRoot);
                if (anotherContentRoot != null) {
                    final String problematicModule;
                    final String correctModule;
                    if (VfsUtilCore.isAncestor(anotherContentRoot, contentRoot, true)) {
                        problematicModule = contentRootToModuleNameMap.get(anotherContentRoot);
                        correctModule = contentRootToModuleNameMap.get(contentRoot);
                    } else {
                        problematicModule = contentRootToModuleNameMap.get(contentRoot);
                        correctModule = contentRootToModuleNameMap.get(anotherContentRoot);
                    }
                    throw new ConfigurationException(ProjectBundle.message("module.paths.validation.duplicate.source.root.error", problematicModule, srcRoot.getPresentableUrl(), correctModule));
                }
            }
        }
    }
    // additional validation: directories marked as src roots must belong to the same module as their corresponding content root
    for (Map.Entry<VirtualFile, VirtualFile> entry : srcRootsToContentRootMap.entrySet()) {
        final VirtualFile srcRoot = entry.getKey();
        final VirtualFile correspondingContent = entry.getValue();
        final String expectedModuleName = contentRootToModuleNameMap.get(correspondingContent);
        for (VirtualFile candidateContent = srcRoot; candidateContent != null && !candidateContent.equals(correspondingContent); candidateContent = candidateContent.getParent()) {
            final String moduleName = contentRootToModuleNameMap.get(candidateContent);
            if (moduleName != null && !moduleName.equals(expectedModuleName)) {
                throw new ConfigurationException(ProjectBundle.message("module.paths.validation.source.root.belongs.to.another.module.error", srcRoot.getPresentableUrl(), expectedModuleName, moduleName));
            }
        }
    }
    for (ModuleEditor moduleEditor : myModuleEditors.values()) {
        moduleEditor.canApply();
    }
    final Map<Sdk, Sdk> modifiedToOriginalMap = new THashMap<>();
    final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel();
    for (Map.Entry<Sdk, Sdk> entry : projectJdksModel.getProjectSdks().entrySet()) {
        modifiedToOriginalMap.put(entry.getValue(), entry.getKey());
    }
    final Ref<ConfigurationException> exceptionRef = Ref.create();
    ApplicationManager.getApplication().runWriteAction(() -> {
        final List<ModifiableRootModel> models = new ArrayList<>(myModuleEditors.size());
        try {
            for (final ModuleEditor moduleEditor : myModuleEditors.values()) {
                final ModifiableRootModel model = moduleEditor.apply();
                if (model != null) {
                    if (!model.isSdkInherited()) {
                        // make sure the sdk is set to original SDK stored in the JDK Table
                        final Sdk modelSdk = model.getSdk();
                        if (modelSdk != null) {
                            final Sdk original = modifiedToOriginalMap.get(modelSdk);
                            if (original != null) {
                                model.setSdk(original);
                            }
                        }
                    }
                    models.add(model);
                }
            }
            myFacetsConfigurator.applyEditors();
        } catch (ConfigurationException e) {
            exceptionRef.set(e);
            return;
        }
        try {
            ModifiableModelCommitter.multiCommit(models, myModuleModel);
            myModuleModelCommitted = true;
            myFacetsConfigurator.commitFacets();
        } finally {
            ModuleStructureConfigurable.getInstance(myProject).getFacetEditorFacade().clearMaps(false);
            myFacetsConfigurator = createFacetsConfigurator();
            myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel();
            myModuleModelCommitted = false;
        }
    });
    if (!exceptionRef.isNull()) {
        throw exceptionRef.get();
    }
    myModified = false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) HashMap(com.intellij.util.containers.HashMap) THashMap(gnu.trove.THashMap) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) THashMap(gnu.trove.THashMap) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ContentEntry(com.intellij.openapi.roots.ContentEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) HashMap(com.intellij.util.containers.HashMap) THashMap(gnu.trove.THashMap)

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