Search in sources :

Example 26 with ConfigurationException

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

the class AndroidRenameHandler method performApplicationPackageRenaming.

private static void performApplicationPackageRenaming(@NotNull Project project, @NotNull Editor editor, @NotNull DataContext context) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
    if (!(element instanceof XmlAttributeValue)) {
        return;
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
        return;
    }
    RenameDialog.showRenameDialog(context, new RenameDialog(project, element, null, editor) {

        @NotNull
        @Override
        protected String getLabelText() {
            return "Rename Android application package of module '" + module.getName() + "' to:";
        }

        @Override
        protected void canRun() throws ConfigurationException {
            final String name = getNewName();
            if (name.length() == 0) {
                throw new ConfigurationException(AndroidBundle.message("specify.package.name.error"));
            }
            if (!AndroidUtils.isValidAndroidPackageName(name)) {
                throw new ConfigurationException(AndroidBundle.message("not.valid.package.name.error", name));
            }
            if (!AndroidCommonUtils.contains2Identifiers(name)) {
                throw new ConfigurationException(AndroidBundle.message("package.name.must.contain.2.ids.error"));
            }
            super.canRun();
        }
    });
}
Also used : RenameDialog(com.intellij.refactoring.rename.RenameDialog) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 27 with ConfigurationException

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

the class AndroidFacetEditorTab method apply.

@Override
public void apply() throws ConfigurationException {
    if (!isModified())
        return;
    String absGenPathR = myRGenPathField.getText().trim();
    String absGenPathAidl = myAidlGenPathField.getText().trim();
    boolean runApt = false;
    boolean runIdl = false;
    if (absGenPathR == null || absGenPathR.length() == 0 || absGenPathAidl == null || absGenPathAidl.length() == 0) {
        throw new ConfigurationException("Please specify source root for autogenerated files");
    } else {
        String relativeGenPathR = getAndCheckRelativePath(absGenPathR, false);
        String newAptDestDir = '/' + relativeGenPathR;
        if (!newAptDestDir.equals(myConfiguration.getState().GEN_FOLDER_RELATIVE_PATH_APT)) {
            runApt = true;
        }
        myConfiguration.getState().GEN_FOLDER_RELATIVE_PATH_APT = newAptDestDir;
        String relativeGenPathAidl = getAndCheckRelativePath(absGenPathAidl, false);
        String newIdlDestDir = '/' + relativeGenPathAidl;
        if (!newIdlDestDir.equals(myConfiguration.getState().GEN_FOLDER_RELATIVE_PATH_AIDL)) {
            runIdl = true;
        }
        myConfiguration.getState().GEN_FOLDER_RELATIVE_PATH_AIDL = newIdlDestDir;
    }
    String absManifestPath = myManifestFileField.getText().trim();
    if (absManifestPath.length() == 0) {
        throw new ConfigurationException("Manifest file not specified");
    }
    String manifestRelPath = getAndCheckRelativePath(absManifestPath, true);
    if (!SdkConstants.FN_ANDROID_MANIFEST_XML.equals(AndroidUtils.getSimpleNameByRelativePath(manifestRelPath))) {
        throw new ConfigurationException("Manifest file must have name AndroidManifest.xml");
    }
    myConfiguration.getState().MANIFEST_FILE_RELATIVE_PATH = '/' + manifestRelPath;
    String absResPath = myResFolderField.getText().trim();
    if (absResPath.length() == 0) {
        throw new ConfigurationException("Resources folder not specified");
    }
    myConfiguration.getState().RES_FOLDER_RELATIVE_PATH = '/' + getAndCheckRelativePath(absResPath, false);
    String absAssetsPath = myAssetsFolderField.getText().trim();
    myConfiguration.getState().ASSETS_FOLDER_RELATIVE_PATH = absAssetsPath.length() > 0 ? '/' + getAndCheckRelativePath(absAssetsPath, false) : "";
    String absApkPath = (String) myApkPathCombo.getComboBox().getEditor().getItem();
    if (absApkPath.length() == 0) {
        myConfiguration.getState().APK_PATH = "";
    } else {
        myConfiguration.getState().APK_PATH = '/' + getAndCheckRelativePath(absApkPath, false);
    }
    String absLibsPath = myNativeLibsFolder.getText().trim();
    myConfiguration.getState().LIBS_FOLDER_RELATIVE_PATH = absLibsPath.length() > 0 ? '/' + getAndCheckRelativePath(absLibsPath, false) : "";
    myConfiguration.getState().CUSTOM_DEBUG_KEYSTORE_PATH = getSelectedCustomKeystorePath();
    myConfiguration.getState().PROJECT_TYPE = myIsLibraryProjectCheckbox.isSelected() ? PROJECT_TYPE_LIBRARY : PROJECT_TYPE_APP;
    myConfiguration.getState().RUN_PROCESS_RESOURCES_MAVEN_TASK = myRunProcessResourcesRadio.isSelected();
    myConfiguration.getState().ENABLE_MANIFEST_MERGING = myEnableManifestMerging.isSelected();
    myConfiguration.getState().ENABLE_PRE_DEXING = myPreDexEnabledCheckBox.isSelected();
    myConfiguration.getState().ENABLE_MULTI_DEX = myEnableMultiDexCheckBox.isSelected();
    myConfiguration.getState().MAIN_DEX_LIST = myMainDexList.getText().trim();
    myConfiguration.getState().MINIMAL_MAIN_DEX = myMinimalMainDexCheckBox.isSelected();
    myConfiguration.getState().PACK_TEST_CODE = myIncludeTestCodeAndCheckBox.isSelected();
    myConfiguration.getState().ENABLE_SOURCES_AUTOGENERATION = myEnableSourcesAutogenerationCheckBox.isSelected();
    myConfiguration.setIncludeAssetsFromLibraries(myIncludeAssetsFromLibraries.isSelected());
    if (AndroidMavenUtil.isMavenizedModule(myContext.getModule())) {
        final Set<AndroidImportableProperty> notImportedProperties = myConfiguration.getState().myNotImportedProperties;
        notImportedProperties.clear();
        for (int i = 0; i < myImportedOptionsList.getItemsCount(); i++) {
            final AndroidImportableProperty property = (AndroidImportableProperty) myImportedOptionsList.getItemAt(i);
            if (!myImportedOptionsList.isItemSelected(i)) {
                notImportedProperties.add(property);
            }
        }
    }
    myConfiguration.getState().RUN_PROGUARD = myRunProguardCheckBox.isSelected();
    myConfiguration.getState().myProGuardCfgFiles = myProGuardConfigFilesPanel.getUrls();
    boolean useCustomAptSrc = myUseCustomSourceDirectoryRadio.isSelected();
    myConfiguration.getState().USE_CUSTOM_APK_RESOURCE_FOLDER = useCustomAptSrc;
    myConfiguration.getState().USE_CUSTOM_MANIFEST_PACKAGE = myUseCustomManifestPackage.isSelected();
    myConfiguration.getState().CUSTOM_MANIFEST_PACKAGE = myCustomManifestPackageField.getText().trim();
    myConfiguration.getState().ADDITIONAL_PACKAGING_COMMAND_LINE_PARAMETERS = myAdditionalPackagingCommandLineParametersField.getText().trim();
    String absAptSourcePath = myCustomAptSourceDirField.getText().trim();
    if (useCustomAptSrc) {
        if (absAptSourcePath.length() == 0) {
            throw new ConfigurationException("Resources folder not specified");
        }
        myConfiguration.getState().CUSTOM_APK_RESOURCE_FOLDER = '/' + getAndCheckRelativePath(absAptSourcePath, false);
    } else {
        String relPath = toRelativePath(absAptSourcePath);
        myConfiguration.getState().CUSTOM_APK_RESOURCE_FOLDER = relPath != null ? '/' + relPath : "";
    }
    myConfiguration.getState().UPDATE_PROPERTY_FILES = (String) myUpdateProjectPropertiesCombo.getSelectedItem();
    String absProguardLogsPath = myProguardLogsDirectoryField.getText().trim();
    myConfiguration.getState().PROGUARD_LOGS_FOLDER_RELATIVE_PATH = absProguardLogsPath.length() > 0 ? '/' + getAndCheckRelativePath(absProguardLogsPath, false) : "";
    if (runApt || runIdl) {
        final Module module = myContext.getModule();
        if (runApt) {
            AndroidCompileUtil.generate(module, AndroidAutogeneratorMode.AAPT);
        }
        if (runIdl) {
            AndroidCompileUtil.generate(module, AndroidAutogeneratorMode.AIDL);
        }
    }
}
Also used : AndroidImportableProperty(org.jetbrains.jps.android.model.impl.AndroidImportableProperty) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module)

Example 28 with ConfigurationException

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

the class AdtImportBuilder method commit.

@Nullable
@Override
public List<Module> commit(Project project, @Nullable ModifiableModuleModel model, ModulesProvider modulesProvider, @Nullable ModifiableArtifactModel artifactModel) {
    File destDir = getBaseDirPath(project);
    try {
        if (!destDir.exists()) {
            boolean ok = destDir.mkdirs();
            if (!ok) {
                throw new IOException("Could not create destination directory");
            }
        }
        // Re-read the project here since one of the wizard steps can have modified the importer options,
        // and that affects the imported state (for example, if you enable/disable the replace-lib-with-dependency
        // options, the set of modules can change)
        readProjects();
        if (!myImporter.getErrors().isEmpty()) {
            return null;
        }
        myImporter.exportProject(destDir, true);
        project.getBaseDir().refresh(false, true);
    } catch (IOException e) {
        Logger.getInstance(AdtImportBuilder.class).error(e);
        return null;
    }
    try {
        NewProjectImportGradleSyncListener syncListener = new NewProjectImportGradleSyncListener() {

            @Override
            public void syncSucceeded(@NotNull Project project) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    activateProjectView(project);
                    openSummary(project);
                });
            }

            @Override
            public void syncFailed(@NotNull Project project, @NotNull String errorMessage) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    createTopLevelProjectAndOpen(project);
                    openSummary(project);
                });
            }
        };
        GradleProjectImporter importer = GradleProjectImporter.getInstance();
        if (myCreateProject) {
            GradleProjectImporter.Request request = new GradleProjectImporter.Request().setProject(project);
            importer.importProject(project.getName(), destDir, request, syncListener);
        } else {
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, syncListener);
        }
    } catch (ConfigurationException e) {
        Messages.showErrorDialog(project, e.getMessage(), e.getTitle());
    } catch (Throwable e) {
        Messages.showErrorDialog(project, e.getMessage(), "ADT Project Import");
    }
    return Collections.emptyList();
}
Also used : NewProjectImportGradleSyncListener(com.android.tools.idea.gradle.project.importing.NewProjectImportGradleSyncListener) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with ConfigurationException

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

the class FlexTestUtils method modifyConfigs.

public static void modifyConfigs(Project project, final Consumer<FlexProjectConfigurationEditor> modifier) {
    Module[] modules = ModuleManager.getInstance(project).getModules();
    final FlexProjectConfigurationEditor editor = createConfigEditor(modules);
    try {
        modifier.consume(editor);
        editor.commit();
    } catch (ConfigurationException ex) {
        throw new RuntimeException(ex);
    } finally {
        Disposer.dispose(editor);
    }
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Module(com.intellij.openapi.module.Module)

Example 30 with ConfigurationException

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

the class FlexMoveClassDialog method canRun.

@Override
protected void canRun() throws ConfigurationException {
    final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(JavaScriptSupportLoader.JAVASCRIPT.getLanguage());
    if (myFileLocal) {
        final String className = myClassNameField.getText();
        if (StringUtil.isEmpty(className)) {
            throw new ConfigurationException(FlexBundle.message("element.name.empty", JSBundle.message(JSNamedElementKind.kind(myElements.iterator().next()).humanReadableKey())));
        }
        if (!namesValidator.isIdentifier(className, myProject)) {
            throw new ConfigurationException(FlexBundle.message("invalid.element.name", StringUtil.decapitalize(JSBundle.message(JSNamedElementKind.kind(myElements.iterator().next()).humanReadableKey())), className));
        }
    }
    final String packageName = myTargetPackageField.getText();
    for (final String s : StringUtil.split(packageName, ".")) {
        if (!namesValidator.isIdentifier(s, myProject)) {
            throw new ConfigurationException(JSBundle.message("invalid.package", packageName));
        }
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) NamesValidator(com.intellij.lang.refactoring.NamesValidator)

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