Search in sources :

Example 41 with ConfigurationException

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

the class AndroidGradleTestCase method importProject.

protected void importProject(@NotNull String projectName, @NotNull File projectRoot, @Nullable GradleSyncListener listener) throws Exception {
    Ref<Throwable> throwableRef = new Ref<>();
    SyncListener syncListener = new SyncListener();
    Project project = getProject();
    GradleSyncState.subscribe(project, syncListener);
    runWriteCommandAction(project, () -> {
        try {
            // When importing project for tests we do not generate the sources as that triggers a compilation which finishes asynchronously.
            // This causes race conditions and intermittent errors. If a test needs source generation this should be handled separately.
            GradleProjectImporter.Request request = new GradleProjectImporter.Request();
            request.setProject(project).setGenerateSourcesOnSuccess(false);
            GradleProjectImporter.getInstance().importProject(projectName, projectRoot, request, listener);
        } catch (Throwable e) {
            throwableRef.set(e);
        }
    });
    Throwable throwable = throwableRef.get();
    if (throwable != null) {
        if (throwable instanceof IOException) {
            throw (IOException) throwable;
        } else if (throwable instanceof ConfigurationException) {
            throw (ConfigurationException) throwable;
        } else {
            throw new RuntimeException(throwable);
        }
    }
    syncListener.await();
    if (syncListener.failureMessage != null && listener == null) {
        fail(syncListener.failureMessage);
    }
}
Also used : Projects.isLegacyIdeaAndroidProject(com.android.tools.idea.gradle.util.Projects.isLegacyIdeaAndroidProject) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) IOException(java.io.IOException)

Example 42 with ConfigurationException

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

the class IdeSdksConfigurable method validate.

public boolean validate() throws ConfigurationException {
    String msg = validateAndroidSdkPath();
    if (msg != null) {
        throw new ConfigurationException(msg);
    }
    if (!useEmbeddedJdk()) {
        File validJdkLocation = validateJdkPath(getJdkLocation());
        if (validJdkLocation == null) {
            throw new ConfigurationException(CHOOSE_VALID_JDK_DIRECTORY_ERR);
        }
    }
    msg = validateAndroidNdkPath();
    if (msg != null) {
        throw new ConfigurationException(msg);
    }
    return true;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 43 with ConfigurationException

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

the class FlexBCConfigurator method copy.

public void copy(final CompositeConfigurable configurable, final Runnable treeNodeNameUpdater) {
    try {
        configurable.apply();
    } catch (ConfigurationException ignored) {
    /**/
    }
    ModifiableFlexBuildConfiguration existingBC = myConfigurablesMap.getKeysByValue(configurable).get(0);
    FlexBCConfigurable unwrapped = FlexBCConfigurable.unwrap(configurable);
    final String title = FlexBundle.message("copy.build.configuration", existingBC.getName(), unwrapped.getModule().getName());
    Module module = unwrapped.getModule();
    AddBuildConfigurationDialog dialog = new AddBuildConfigurationDialog(module.getProject(), title, getUsedNames(module), existingBC.getNature(), true);
    dialog.reset("", existingBC.getAndroidPackagingOptions().isEnabled(), existingBC.getIosPackagingOptions().isEnabled());
    if (!dialog.showAndGet()) {
        return;
    }
    final String newBCName = dialog.getBCName();
    final String fileName = PathUtil.suggestFileName(newBCName);
    final BuildConfigurationNature newNature = dialog.getNature();
    ModifiableFlexBuildConfiguration newBC = myConfigEditor.copyConfiguration(existingBC, newNature);
    newBC.setName(newBCName);
    newBC.setOutputFileName(fileName + (newBC.getOutputType() == OutputType.Library ? ".swc" : ".swf"));
    updatePackageFileName(newBC, fileName);
    if (newNature.isApp() && newNature.isMobilePlatform()) {
        newBC.getAndroidPackagingOptions().setEnabled(dialog.isAndroidEnabled());
        newBC.getIosPackagingOptions().setEnabled(dialog.isIOSEnabled());
    }
    createConfigurableNode(newBC, unwrapped.getModule(), treeNodeNameUpdater);
}
Also used : BuildConfigurationNature(com.intellij.flex.model.bc.BuildConfigurationNature) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FlexBCConfigurable(com.intellij.lang.javascript.flex.projectStructure.ui.FlexBCConfigurable) Module(com.intellij.openapi.module.Module) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) AddBuildConfigurationDialog(com.intellij.lang.javascript.flex.projectStructure.ui.AddBuildConfigurationDialog)

Example 44 with ConfigurationException

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

the class AdtImportLocationStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    WizardContext context = getWizardContext();
    GradleImport importer = AdtImportProvider.getImporter(context);
    if (importer != null) {
        List<String> errors = importer.getErrors();
        if (!errors.isEmpty()) {
            throw new ConfigurationException(errors.get(0));
        }
    }
    // The following code is based on similar code in com.intellij.ide.util.newProjectWizard.ProjectNameStep
    String projectFileDirectory = getProjectFileDirectory();
    if (projectFileDirectory.length() == 0) {
        throw new ConfigurationException(String.format("Enter %1$s file location", context.getPresentationName()));
    }
    boolean shouldPromptCreation = myIsPathChangedByUser;
    if (!ProjectWizardUtil.createDirectoryIfNotExists(String.format("The %1$s file directory\n", context.getPresentationName()), projectFileDirectory, shouldPromptCreation)) {
        return false;
    }
    boolean shouldContinue = true;
    File projectFile = new File(getProjectFileDirectory());
    String title = "New Project";
    if (projectFile.isFile()) {
        shouldContinue = false;
        String message = String.format("%s exists and is a file.\nPlease specify a different project location", projectFile.getAbsolutePath());
        Messages.showErrorDialog(message, title);
    } else if (projectFile.isDirectory()) {
        File[] files = projectFile.listFiles();
        if (files != null && files.length > 0) {
            String message = String.format("%1$s folder already exists and is not empty.\nIts content may be overwritten.\nContinue?", projectFile.getAbsolutePath());
            int answer = Messages.showYesNoDialog(message, title, Messages.getQuestionIcon());
            shouldContinue = answer == 0;
        }
    }
    return shouldContinue;
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 45 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)

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