Search in sources :

Example 1 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class CreateSnapShotAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (project == null || view == null) {
        return;
    }
    final PsiDirectory dir = view.getOrChooseDirectory();
    if (dir == null)
        return;
    final SnapShotClient client = new SnapShotClient();
    List<RunnerAndConfigurationSettings> appConfigurations = new ArrayList<>();
    RunnerAndConfigurationSettings snapshotConfiguration = null;
    boolean connected = false;
    ApplicationConfigurationType cfgType = ApplicationConfigurationType.getInstance();
    List<RunnerAndConfigurationSettings> racsi = RunManager.getInstance(project).getConfigurationSettingsList(cfgType);
    for (RunnerAndConfigurationSettings config : racsi) {
        if (config.getConfiguration() instanceof ApplicationConfiguration) {
            ApplicationConfiguration appConfig = (ApplicationConfiguration) config.getConfiguration();
            appConfigurations.add(config);
            if (appConfig.ENABLE_SWING_INSPECTOR) {
                SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
                snapshotConfiguration = config;
                if (settings.getLastPort() > 0) {
                    try {
                        client.connect(settings.getLastPort());
                        connected = true;
                    } catch (IOException ex) {
                        connected = false;
                    }
                }
            }
            if (connected)
                break;
        }
    }
    if (snapshotConfiguration == null) {
        snapshotConfiguration = promptForSnapshotConfiguration(project, appConfigurations);
        if (snapshotConfiguration == null)
            return;
    }
    if (!connected) {
        int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.run.prompt"), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == Messages.NO)
            return;
        final ApplicationConfiguration appConfig = (ApplicationConfiguration) snapshotConfiguration.getConfiguration();
        final SnapShooterConfigurationSettings settings = SnapShooterConfigurationSettings.get(appConfig);
        settings.setNotifyRunnable(() -> SwingUtilities.invokeLater(() -> {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.prepare.notice"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
            try {
                client.connect(settings.getLastPort());
            } catch (IOException ex) {
                Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                return;
            }
            runSnapShooterSession(client, project, dir, view);
        }));
        try {
            ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), snapshotConfiguration).buildAndExecute();
        } catch (ExecutionException ex) {
            Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.run.error", ex.getMessage()), UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }
    } else {
        runSnapShooterSession(client, project, dir, view);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IdeView(com.intellij.ide.IdeView) ApplicationConfigurationType(com.intellij.execution.application.ApplicationConfigurationType) Project(com.intellij.openapi.project.Project) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionException(com.intellij.execution.ExecutionException) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 2 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class CreateSnapShotAction method promptForSnapshotConfiguration.

@Nullable
private static RunnerAndConfigurationSettings promptForSnapshotConfiguration(final Project project, final List<RunnerAndConfigurationSettings> configurations) {
    if (configurations.isEmpty()) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.no.configuration.error"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
        return null;
    }
    for (int i = configurations.size() - 1; i >= 0; i--) {
        final JreVersionDetector detector = new JreVersionDetector();
        final ApplicationConfiguration configuration = (ApplicationConfiguration) configurations.get(i).getConfiguration();
        if (!detector.isJre50Configured(configuration) && !detector.isModuleJre50Configured(configuration)) {
            configurations.remove(i);
        }
    }
    if (configurations.isEmpty()) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.no.compatible.configuration.error"), UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
        return null;
    }
    final RunnerAndConfigurationSettings snapshotConfiguration;
    if (configurations.size() == 1) {
        final int rc = Messages.showYesNoDialog(project, UIDesignerBundle.message("snapshot.confirm.configuration.prompt", configurations.get(0).getConfiguration().getName()), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon());
        if (rc == Messages.NO) {
            return null;
        }
        snapshotConfiguration = configurations.get(0);
    } else {
        String[] names = new String[configurations.size()];
        for (int i = 0; i < configurations.size(); i++) {
            names[i] = configurations.get(i).getConfiguration().getName();
        }
        int rc = Messages.showChooseDialog(project, UIDesignerBundle.message("snapshot.choose.configuration.prompt"), UIDesignerBundle.message("snapshot.title"), Messages.getQuestionIcon(), names, names[0]);
        if (rc < 0)
            return null;
        snapshotConfiguration = configurations.get(rc);
    }
    ((ApplicationConfiguration) snapshotConfiguration.getConfiguration()).ENABLE_SWING_INSPECTOR = true;
    return snapshotConfiguration;
}
Also used : RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) JreVersionDetector(com.intellij.execution.util.JreVersionDetector) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testMoveApplication.

public void testMoveApplication() throws IOException {
    PsiClass psiClass = mySource.createClass("Application", APPLICATION_CODE);
    assertNotNull(psiClass);
    ApplicationConfiguration configuration = createConfiguration(psiClass);
    move(psiClass, "pkg");
    try {
        configuration.checkConfiguration();
    } catch (RuntimeConfigurationException e) {
        assertTrue("Unexpected ConfigurationException: " + e, false);
    }
    assertEquals("pkg.Application", configuration.MAIN_CLASS_NAME);
    rename(JavaPsiFacade.getInstance(myProject).findPackage("pkg"), "pkg2");
    assertEquals("pkg2.Application", configuration.MAIN_CLASS_NAME);
}
Also used : RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 4 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testRenameApplication.

public void testRenameApplication() throws IOException {
    PsiClass psiClass = mySource.createClass("Application", APPLICATION_CODE);
    assertNotNull(psiClass);
    ApplicationConfiguration configuration = createConfiguration(psiClass);
    assertNotNull(configuration);
    rename(psiClass, "NewName");
    try {
        configuration.checkConfiguration();
    } catch (RuntimeConfigurationException e) {
        assertTrue("Unexpected ConfigurationException: " + e, false);
    }
    assertEquals("NewName", configuration.MAIN_CLASS_NAME);
}
Also used : RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 5 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class BaseRunConfigurationActionTest method testRunApplicationName.

public void testRunApplicationName() {
    ApplicationConfiguration configuration = new ApplicationConfiguration(null, getProject(), ApplicationConfigurationType.getInstance());
    configuration.MAIN_CLASS_NAME = "com.comp.AClass";
    configuration.setGeneratedName();
    checkSuggestedName("AClass.main()", configuration);
    configuration.setName("Other name");
    configuration.setNameChangedByUser(true);
    checkSuggestedName("Other name", configuration);
    configuration.setName("1234567890123456789012345 other long name");
    checkSuggestedName("12345678901234567890...", configuration);
    configuration.MAIN_CLASS_NAME = "com.comp.A12345678901234567890123LongName";
    configuration.setGeneratedName();
    checkSuggestedName("A1234567890123....main()", configuration);
}
Also used : ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Aggregations

ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)14 Module (com.intellij.openapi.module.Module)4 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 RuntimeConfigurationException (com.intellij.execution.configurations.RuntimeConfigurationException)2 PsiClass (com.intellij.psi.PsiClass)2 MapDataContext (com.intellij.testFramework.MapDataContext)2 Nullable (org.jetbrains.annotations.Nullable)2 DesignerEditorPanelFacade (com.intellij.designer.DesignerEditorPanelFacade)1 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 ApplicationConfigurable (com.intellij.execution.application.ApplicationConfigurable)1 ApplicationConfigurationType (com.intellij.execution.application.ApplicationConfigurationType)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 JUnitConfigurable (com.intellij.execution.junit2.configuration.JUnitConfigurable)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 CommonJavaParametersPanel (com.intellij.execution.ui.CommonJavaParametersPanel)1 JreVersionDetector (com.intellij.execution.util.JreVersionDetector)1 IdeView (com.intellij.ide.IdeView)1 PaletteGroup (com.intellij.ide.palette.PaletteGroup)1 LafManagerListener (com.intellij.ide.ui.LafManagerListener)1