Search in sources :

Example 11 with RunnerAndConfigurationSettings

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

the class SphinxConfigurationProducer method createConfigurationByElement.

protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
    PsiElement element = location.getPsiElement();
    if (!(element instanceof PsiDirectory))
        return null;
    mySourceFile = (PsiDirectory) element;
    boolean hasRstFile = false;
    boolean hasConf = false;
    for (PsiFile file : mySourceFile.getFiles()) {
        if ("conf.py".equals(file.getName()))
            hasConf = true;
        if (file instanceof RestFile) {
            hasRstFile = true;
        }
    }
    if (!hasRstFile || !hasConf)
        return null;
    final Project project = mySourceFile.getProject();
    RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context);
    SphinxRunConfiguration configuration = (SphinxRunConfiguration) settings.getConfiguration();
    final VirtualFile vFile = mySourceFile.getVirtualFile();
    configuration.setInputFile(vFile.getPath());
    configuration.setName(((PsiDirectory) element).getName());
    if (configuration.getTask().isEmpty())
        configuration.setTask("html");
    final VirtualFile parent = vFile.getParent();
    if (parent != null) {
        configuration.setWorkingDirectory(parent.getPath());
    }
    configuration.setName(configuration.suggestedName());
    Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module != null) {
        configuration.setUseModuleSdk(true);
        configuration.setModule(module);
    }
    return settings;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) RestFile(com.jetbrains.rest.RestFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 12 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings 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 13 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings 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 14 with RunnerAndConfigurationSettings

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

the class RunConfigurationsNode method doBuildChildren.

@NotNull
@Override
protected List<? extends ExternalSystemNode> doBuildChildren() {
    List<ExternalSystemNode> runConfigurationNodes = ContainerUtil.newArrayList();
    final AbstractExternalSystemTaskConfigurationType configurationType = ExternalSystemUtil.findConfigurationType(myModuleData.getOwner());
    if (configurationType == null)
        return Collections.emptyList();
    Set<RunnerAndConfigurationSettings> settings = new THashSet<>(RunManager.getInstance(myProject).getConfigurationSettingsList(configurationType));
    String directory = PathUtil.getCanonicalPath(myModuleData.getLinkedExternalProjectPath());
    for (RunnerAndConfigurationSettings cfg : settings) {
        ExternalSystemRunConfiguration externalSystemRunConfiguration = (ExternalSystemRunConfiguration) cfg.getConfiguration();
        if (directory.equals(PathUtil.getCanonicalPath(externalSystemRunConfiguration.getSettings().getExternalProjectPath()))) {
            runConfigurationNodes.add(new RunConfigurationNode(getExternalProjectsView(), this, cfg));
        }
    }
    return runConfigurationNodes;
}
Also used : RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractExternalSystemTaskConfigurationType(com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with RunnerAndConfigurationSettings

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

the class ExternalSystemKeymapExtension method updateRunConfigurationActions.

public static void updateRunConfigurationActions(Project project, ProjectSystemId systemId) {
    final AbstractExternalSystemTaskConfigurationType configurationType = ExternalSystemUtil.findConfigurationType(systemId);
    if (configurationType == null)
        return;
    ActionManager actionManager = ActionManager.getInstance();
    for (String eachAction : actionManager.getActionIds(getActionPrefix(project, null))) {
        AnAction action = actionManager.getAction(eachAction);
        if (action instanceof ExternalSystemRunConfigurationAction) {
            actionManager.unregisterAction(eachAction);
        }
    }
    Set<RunnerAndConfigurationSettings> settings = new THashSet<>(RunManager.getInstance(project).getConfigurationSettingsList(configurationType));
    final ExternalSystemShortcutsManager shortcutsManager = ExternalProjectsManager.getInstance(project).getShortcutsManager();
    for (RunnerAndConfigurationSettings configurationSettings : settings) {
        ExternalSystemRunConfigurationAction runConfigurationAction = new ExternalSystemRunConfigurationAction(project, configurationSettings);
        String id = runConfigurationAction.getId();
        actionManager.unregisterAction(id);
        if (shortcutsManager.hasShortcuts(id)) {
            actionManager.registerAction(id, runConfigurationAction);
        }
    }
}
Also used : RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AbstractExternalSystemTaskConfigurationType(com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType) THashSet(gnu.trove.THashSet)

Aggregations

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)104 Project (com.intellij.openapi.project.Project)24 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)16 RunManagerEx (com.intellij.execution.RunManagerEx)14 Nullable (org.jetbrains.annotations.Nullable)14 RunManager (com.intellij.execution.RunManager)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)9 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)7 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)7 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)7 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)6 Executor (com.intellij.execution.Executor)4 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)4 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)4 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)4 RunConfigurationNode (com.intellij.openapi.externalSystem.view.RunConfigurationNode)4 PsiElement (com.intellij.psi.PsiElement)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3