Search in sources :

Example 51 with ConfigurationException

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

the class AdtWorkspaceForm method validate.

@Override
public boolean validate() throws ConfigurationException {
    for (Map.Entry<String, File> entry : myPathMap.entrySet()) {
        String path = entry.getKey();
        File file = entry.getValue();
        if (file == null || file.getPath().trim().isEmpty()) {
            throw new ConfigurationException("Enter a value for workspace path " + path);
        } else if (!file.exists()) {
            throw new ConfigurationException(file.getPath() + " does not exist");
        }
    }
    return super.validate();
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) Map(java.util.Map) File(java.io.File)

Example 52 with ConfigurationException

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

the class NewProjectWizardDynamic method runFinish.

private void runFinish() {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    GradleProjectImporter projectImporter = GradleProjectImporter.getInstance();
    String rootPath = getState().get(PROJECT_LOCATION_KEY);
    if (rootPath == null) {
        LOG.error("No root path specified for project");
        return;
    }
    File rootLocation = new File(rootPath);
    File wrapperPropertiesFilePath = GradleWrapper.getDefaultPropertiesFilePath(rootLocation);
    try {
        GradleWrapper.get(wrapperPropertiesFilePath).updateDistributionUrl(SdkConstants.GRADLE_LATEST_VERSION);
    } catch (IOException e) {
        // Unlikely to happen. Continue with import, the worst-case scenario is that sync fails and the error message has a "quick fix".
        LOG.warn("Failed to update Gradle wrapper file", e);
    }
    String projectName = getState().get(APPLICATION_NAME_KEY);
    if (projectName == null) {
        projectName = "Unnamed Project";
    }
    // Pick the highest language level of all the modules/form factors.
    // We have to pick the language level up front while creating the project rather than
    // just reacting to it during sync, because otherwise the user gets prompted with
    // a changing-language-level-requires-reopening modal dialog box and have to reload
    // the project
    LanguageLevel initialLanguageLevel = null;
    for (FormFactor factor : FormFactor.values()) {
        Object version = getState().get(FormFactorUtils.getLanguageLevelKey(factor));
        if (version != null) {
            LanguageLevel level = LanguageLevel.parse(version.toString());
            if (level != null && (initialLanguageLevel == null || level.isAtLeast(initialLanguageLevel))) {
                initialLanguageLevel = level;
            }
        }
    }
    // This is required for Android plugin in IDEA
    if (!IdeInfo.getInstance().isAndroidStudio()) {
        final Sdk jdk = IdeSdks.getInstance().getJdk();
        if (jdk != null) {
            ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(myProject).setProjectSdk(jdk));
        }
    }
    try {
        GradleSyncListener listener = new PostStartupGradleSyncListener(() -> {
            Iterable<File> targetFiles = myState.get(TARGET_FILES_KEY);
            assert targetFiles != null;
            TemplateUtils.reformatAndRearrange(myProject, targetFiles);
            Collection<File> filesToOpen = myState.get(FILES_TO_OPEN_KEY);
            assert filesToOpen != null;
            TemplateUtils.openEditors(myProject, filesToOpen, true);
        });
        GradleProjectImporter.Request request = new GradleProjectImporter.Request();
        request.setLanguageLevel(initialLanguageLevel).setProject(myProject);
        projectImporter.importProject(projectName, rootLocation, request, listener);
    } catch (IOException | ConfigurationException e) {
        Messages.showErrorDialog(e.getMessage(), ERROR_MSG_TITLE);
        LOG.error(e);
    }
}
Also used : GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) IOException(java.io.IOException) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) LanguageLevel(com.intellij.pom.java.LanguageLevel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File)

Example 53 with ConfigurationException

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

the class AndroidModuleConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    VirtualFile file = getGradleBuildFile(myModule);
    if (file != null && !ensureFilesWritable(myModule.getProject(), file)) {
        throw new ConfigurationException(String.format("Build file %1$s is not writable", file.getPath()));
    }
    myModuleEditor.apply();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 54 with ConfigurationException

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

the class AndroidProjectConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    if (myGradleBuildFile == null) {
        return;
    }
    VirtualFile file = myGradleBuildFile.getFile();
    if (!ReadonlyStatusHandler.ensureFilesWritable(myProject, file)) {
        throw new ConfigurationException(String.format("Build file %1$s is not writable", file.getPath()));
    }
    CommandProcessor.getInstance().runUndoTransparentAction(() -> {
        try {
            ActionRunner.runInsideWriteAction(() -> {
                for (BuildFileKey key : PROJECT_PROPERTIES) {
                    if (key == BuildFileKey.GRADLE_WRAPPER_VERSION || !myModifiedKeys.contains(key)) {
                        continue;
                    }
                    Object value = myProjectProperties.get(key);
                    if (value != null) {
                        myGradleBuildFile.setValue(key, value);
                    } else {
                        myGradleBuildFile.removeValue(null, key);
                    }
                }
                Object wrapperVersion = myProjectProperties.get(BuildFileKey.GRADLE_WRAPPER_VERSION);
                GradleWrapper gradleWrapper = GradleWrapper.find(myProject);
                if (wrapperVersion != null && gradleWrapper != null) {
                    boolean updated = gradleWrapper.updateDistributionUrlAndDisplayFailure(wrapperVersion.toString());
                    if (updated) {
                        VirtualFile virtualFile = gradleWrapper.getPropertiesFile();
                        if (virtualFile != null) {
                            virtualFile.refresh(false, false);
                        }
                    }
                }
                myModifiedKeys.clear();
            });
        } catch (Exception e) {
            LOG.error("Error while applying changes", e);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConfigurationException(com.intellij.openapi.options.ConfigurationException) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) ConfigurationException(com.intellij.openapi.options.ConfigurationException)

Example 55 with ConfigurationException

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

the class FlexTestUtils method createConfigEditor.

public static FlexProjectConfigurationEditor createConfigEditor(final Module... modules) {
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Map<Module, ModifiableRootModel> models = new FactoryMap<Module, ModifiableRootModel>() {

        @Override
        protected ModifiableRootModel create(final Module module) {
            final ModifiableRootModel result = ModuleRootManager.getInstance(module).getModifiableModel();
            Disposer.register(module, new Disposable() {

                @Override
                public void dispose() {
                    if (!result.isDisposed()) {
                        result.dispose();
                    }
                }
            });
            return result;
        }
    };
    return new FlexProjectConfigurationEditor(modules[0].getProject(), new FlexProjectConfigurationEditor.ProjectModifiableModelProvider() {

        @Override
        public Module[] getModules() {
            return modules;
        }

        @Override
        public ModifiableRootModel getModuleModifiableModel(Module module) {
            return models.get(module);
        }

        @Override
        public void addListener(FlexBCConfigurator.Listener listener, Disposable parentDisposable) {
        // ignore
        }

        @Override
        public void commitModifiableModels() throws ConfigurationException {
            ApplicationManager.getApplication().runWriteAction(() -> {
                for (ModifiableRootModel model : models.values()) {
                    if (model.isChanged()) {
                        model.commit();
                    }
                }
            });
        }

        public Library findSourceLibraryForLiveName(final String name, final String level) {
            return findSourceLibrary(name, level);
        }

        public Library findSourceLibrary(final String name, final String level) {
            return getLibrariesTable(level).getLibraryByName(name);
        }

        private LibraryTable getLibrariesTable(final String level) {
            if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
                return ApplicationLibraryTable.getApplicationTable();
            } else {
                assert LibraryTablesRegistrar.PROJECT_LEVEL.equals(level);
                return ProjectLibraryTable.getInstance(modules[0].getProject());
            }
        }
    });
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) Disposable(com.intellij.openapi.Disposable) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) ApplicationLibraryTable(com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ConfigurationException(com.intellij.openapi.options.ConfigurationException) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

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