@Override protected RunnerAndConfigurationSettings findExistingByElement( Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations, ConfigurationContext context) { for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final RunConfiguration configuration = existingConfiguration.getConfiguration(); final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration) configuration; final String path = existing.getScriptPath(); if (path != null) { final PsiFile file = location.getPsiElement().getContainingFile(); if (file instanceof GroovyFile) { final VirtualFile vfile = file.getVirtualFile(); if (vfile != null && FileUtil.toSystemIndependentName(path).equals(vfile.getPath())) { if (!((GroovyFile) file).isScript() || GroovyScriptTypeDetector.getScriptType((GroovyFile) file) .isConfigurationByLocation(existing, location)) { return existingConfiguration; } } } } } return null; }
protected static void ensureRunConfigurationExists( Module module, ConfigurationType configurationType, String name) { final RunManagerEx runManager = RunManagerEx.getInstanceEx(module.getProject()); for (final RunConfiguration runConfiguration : runManager.getConfigurations(configurationType)) { if (runConfiguration instanceof MvcRunConfiguration && ((MvcRunConfiguration) runConfiguration).getModule() == module) { return; } } final ConfigurationFactory factory = configurationType.getConfigurationFactories()[0]; final RunnerAndConfigurationSettings runSettings = runManager.createRunConfiguration(name, factory); final MvcRunConfiguration configuration = (MvcRunConfiguration) runSettings.getConfiguration(); configuration.setModule(module); runManager.addConfiguration(runSettings, false); runManager.setActiveConfiguration(runSettings); RunManagerEx.disableTasks( module.getProject(), configuration, CompileStepBeforeRun.ID, CompileStepBeforeRunNoErrorCheck.ID); }
@Override public boolean isConfigurationFromContext( JUnitConfiguration unitConfiguration, ConfigurationContext context) { if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class) .isMultipleElementsSelected(context)) { return false; } final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(JUnitConfigurationType.getInstance()); final Location contextLocation = context.getLocation(); String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null; assert contextLocation != null; Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation); if (location == null) { return false; } final PsiElement element = location.getPsiElement(); final PsiClass testClass = JUnitUtil.getTestClass(element); final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false); final PsiPackage testPackage; if (element instanceof PsiPackage) { testPackage = (PsiPackage) element; } else if (element instanceof PsiDirectory) { testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element)); } else { testPackage = null; } PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null; RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()) .getConfigurationTemplate(getConfigurationFactory()); final Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule(); final String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null; if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false; if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) return false; final TestObject testobject = unitConfiguration.getTestObject(); if (testobject != null) { if (testobject.isConfiguredByElement( unitConfiguration, testClass, testMethod, testPackage, testDir)) { final Module configurationModule = unitConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return true; if (Comparing.equal(predefinedModule, configurationModule)) { return true; } } } return false; }
private ValidationResult getValidationResult() { if (!myValidationResultValid) { myLastValidationResult = null; try { RunnerAndConfigurationSettings snapshot = getSnapshot(); if (snapshot != null) { snapshot.setName(getNameText()); snapshot.checkSettings(); for (ProgramRunner runner : RunnerRegistry.getInstance().getRegisteredRunners()) { for (Executor executor : ExecutorRegistry.getInstance().getRegisteredExecutors()) { if (runner.canRun(executor.getId(), snapshot.getConfiguration())) { checkConfiguration(runner, snapshot); break; } } } } } catch (RuntimeConfigurationException exception) { myLastValidationResult = exception != null ? new ValidationResult( exception.getLocalizedMessage(), exception.getTitle(), exception.getQuickFix()) : null; } catch (ConfigurationException e) { myLastValidationResult = new ValidationResult( e.getLocalizedMessage(), ExecutionBundle.message("invalid.data.dialog.title"), null); } myValidationResultValid = true; } return myLastValidationResult; }
@Override protected RunnerAndConfigurationSettings findExistingByElement( Location location, @NotNull RunnerAndConfigurationSettings[] existingConfigurations, ConfigurationContext context) { final PsiClass aClass = ApplicationConfigurationType.getMainClass(location.getPsiElement()); if (aClass == null) { return null; } final Module predefinedModule = ((ApplicationConfiguration) ((RunManagerImpl) RunManagerEx.getInstanceEx(location.getProject())) .getConfigurationTemplate(getConfigurationFactory()) .getConfiguration()) .getConfigurationModule() .getModule(); for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final ApplicationConfiguration appConfiguration = (ApplicationConfiguration) existingConfiguration.getConfiguration(); if (Comparing.equal( JavaExecutionUtil.getRuntimeQualifiedName(aClass), appConfiguration.MAIN_CLASS_NAME)) { if (Comparing.equal( location.getModule(), appConfiguration.getConfigurationModule().getModule())) { return existingConfiguration; } final Module configurationModule = appConfiguration.getConfigurationModule().getModule(); if (Comparing.equal(location.getModule(), configurationModule)) return existingConfiguration; if (Comparing.equal(predefinedModule, configurationModule)) { return existingConfiguration; } } } return null; }
public void reset() { RunnerAndConfigurationSettings configuration = getSettings(); if (configuration != null) { setNameText(configuration.getName()); } super.reset(); }
private SelectionDialog( RunnerAndConfigurationSettings selectedSettings, @NotNull List<RunnerAndConfigurationSettings> settings) { super(myProject); setTitle(ExecutionBundle.message("before.launch.run.another.configuration.choose")); mySelectedSettings = selectedSettings; mySettings = settings; init(); myJBList.setSelectedValue(mySelectedSettings, true); myJBList.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { doOKAction(); } } }); FontMetrics fontMetrics = myJBList.getFontMetrics(myJBList.getFont()); int maxWidth = fontMetrics.stringWidth("m") * 30; for (RunnerAndConfigurationSettings setting : settings) { maxWidth = Math.max(fontMetrics.stringWidth(setting.getConfiguration().getName()), maxWidth); } maxWidth += 24; // icon and gap myJBList.setMinimumSize(new Dimension(maxWidth, myJBList.getPreferredSize().height)); }
protected RunnerAndConfigurationSettings findExistingByElement( Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations) { for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final RunConfiguration configuration = existingConfiguration.getConfiguration(); if (!(configuration instanceof GoApplicationConfiguration)) { continue; } GoApplicationConfiguration goApplicationConfiguration = (GoApplicationConfiguration) configuration; GoFile goFile = locationToFile(location); if (goFile != null) { VirtualFile virtualFile = goFile.getVirtualFile(); if (virtualFile != null && virtualFile .getPath() .endsWith( FileUtil.toSystemIndependentName(goApplicationConfiguration.scriptName))) { return existingConfiguration; } } } return null; }
private static BaseCreatePolicy choosePolicy(final ConfigurationContext context) { final RunnerAndConfigurationSettings configuration = context.findExisting(); if (configuration == null) return CREATE_AND_EDIT; final RunManagerEx runManager = context.getRunManager(); if (runManager.getSelectedConfiguration() != configuration) return SELECT; if (runManager.isTemporary(configuration.getConfiguration())) return SAVE; return SELECTED_STABLE; }
public ExecutionEnvironment( @NotNull final ProgramRunner runner, @NotNull final RunnerAndConfigurationSettings configuration, final DataContext context) { this( configuration.getConfiguration(), configuration.getRunnerSettings(runner), configuration.getConfigurationSettings(runner), context); }
@Override public boolean canExecuteTask(RunConfiguration configuration, RunConfigurableBeforeRunTask task) { RunnerAndConfigurationSettings settings = task.getSettings(); if (settings == null) { return false; } String executorId = DefaultRunExecutor.getRunExecutorInstance().getId(); final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings); return runner != null && runner.canRun(executorId, settings.getConfiguration()); }
@Override public void writeExternal(Element element) { super.writeExternal(element); if (myConfigurationName != null && myConfigurationType != null) { element.setAttribute("run_configuration_name", myConfigurationName); element.setAttribute("run_configuration_type", myConfigurationType); } else if (mySettings != null) { element.setAttribute("run_configuration_name", mySettings.getName()); element.setAttribute("run_configuration_type", mySettings.getType().getId()); } }
@Nullable private static RunnerAndConfigurationSettings chooseTempSettings(@NotNull Project project) { RunnerAndConfigurationSettings selectedConfiguration = RunManager.getInstance(project).getSelectedConfiguration(); if (selectedConfiguration != null && selectedConfiguration.isTemporary()) { return selectedConfiguration; } Iterator<RunnerAndConfigurationSettings> iterator = RunManager.getInstance(project).getTempConfigurationsList().iterator(); return iterator.hasNext() ? iterator.next() : null; }
private static void checkConfiguration( final ProgramRunner runner, final RunnerAndConfigurationSettings snapshot) throws RuntimeConfigurationException { final RunnerSettings runnerSettings = snapshot.getRunnerSettings(runner); final ConfigurationPerRunnerSettings configurationSettings = snapshot.getConfigurationSettings(runner); try { runner.checkConfiguration(runnerSettings, configurationSettings); } catch (AbstractMethodError e) { // backward compatibility } }
void doReset(RunnerAndConfigurationSettings settings) { myRunConfiguration = settings.getConfiguration(); originalTasks.clear(); RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myRunConfiguration.getProject()); originalTasks.addAll(runManager.getBeforeRunTasks(myRunConfiguration)); myModel.replaceAll(originalTasks); myShowSettingsBeforeRunCheckBox.setSelected(settings.isEditBeforeRun()); myShowSettingsBeforeRunCheckBox.setEnabled(!(isUnknown())); myPanel.setVisible(checkBeforeRunTasksAbility(false)); updateText(); }
private RunnerAndConfigurationSettings createConfiguration( final PsiClass aClass, final ConfigurationContext context, Location location) { final Project project = aClass.getProject(); RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, context); final ApplicationConfiguration configuration = (ApplicationConfiguration) settings.getConfiguration(); configuration.MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(aClass); configuration.setName(configuration.getGeneratedName()); setupConfigurationModule(context, configuration); JavaRunConfigurationExtensionManager.getInstance() .extendCreatedConfiguration(configuration, location); return settings; }
private void initRunConfigurationsMap() { RunManagerEx manager = RunManagerEx.getInstanceEx(myProject); ConfigurationType[] types = manager.getConfigurationFactories(); for (ConfigurationType type : types) { Map<String, List<RunnerAndConfigurationSettings>> structure = manager.getStructure(type); for (Map.Entry<String, List<RunnerAndConfigurationSettings>> e : structure.entrySet()) { for (RunnerAndConfigurationSettings settings : e.getValue()) { myConfigurationsMap.put(settings.getName().hashCode(), settings); } } } }
@Nullable public static ExecutionEnvironmentBuilder createEnvironment( @NotNull Executor executor, @NotNull RunnerAndConfigurationSettings settings) { try { return ExecutionEnvironmentBuilder.create(executor, settings); } catch (ExecutionException e) { handleExecutionError( settings.getConfiguration().getProject(), executor.getToolWindowId(), settings.getConfiguration().getName(), e); return null; } }
/** * Finds an existing run configuration matching the context. * * @return an existing configuration, or null if none was found. */ @Nullable public RunnerAndConfigurationSettings findExisting() { if (myExistingConfiguration != null) return myExistingConfiguration.get(); myExistingConfiguration = new Ref<>(); if (myLocation == null) { return null; } final PsiElement psiElement = myLocation.getPsiElement(); if (!psiElement.isValid()) { return null; } final List<RuntimeConfigurationProducer> producers = findPreferredProducers(); if (myRuntimeConfiguration != null) { if (producers != null) { for (RuntimeConfigurationProducer producer : producers) { final RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(myLocation, this); if (configuration != null && configuration.getConfiguration() == myRuntimeConfiguration) { myExistingConfiguration.set(configuration); } } } for (RunConfigurationProducer producer : RunConfigurationProducer.getProducers(getProject())) { RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(this); if (configuration != null && configuration.getConfiguration() == myRuntimeConfiguration) { myExistingConfiguration.set(configuration); } } } if (producers != null) { for (RuntimeConfigurationProducer producer : producers) { final RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(myLocation, this); if (configuration != null) { myExistingConfiguration.set(configuration); } } } for (RunConfigurationProducer producer : RunConfigurationProducer.getProducers(getProject())) { RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(this); if (configuration != null) { myExistingConfiguration.set(configuration); } } return myExistingConfiguration.get(); }
public SelectConfigAction( final RunnerAndConfigurationSettings configuration, final Project project) { myConfiguration = configuration; myProject = project; String name = configuration.getName(); if (name == null || name.length() == 0) { name = " "; } final Presentation presentation = getTemplatePresentation(); presentation.setText(name, false); final ConfigurationType type = configuration.getType(); if (type != null) { presentation.setDescription( "Select " + type.getConfigurationTypeDescription() + " '" + name + "'"); } updateIcon(presentation); }
public static void runConfiguration( @NotNull RunnerAndConfigurationSettings configuration, @NotNull Executor executor) { ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration); if (builder != null) { ExecutionManager.getInstance(configuration.getConfiguration().getProject()) .restartRunProfile(builder.activeTarget().build()); } }
private boolean checkRunConfiguration( Executor executor, Project project, RunnerAndConfigurationSettings configuration) { ExecutionTarget target = ExecutionTargetManager.getActiveTarget(project); if (!ExecutionTargetManager.canRun(configuration, target)) { ExecutionUtil.handleExecutionError( project, executor.getToolWindowId(), configuration.getConfiguration(), new ExecutionException( StringUtil.escapeXml( "Cannot run '" + configuration.getName() + "' on '" + target.getDisplayName() + "'"))); return false; } if (!RunManagerImpl.canRunConfiguration(configuration, executor) || configuration.isEditBeforeRun()) { if (!RunDialog.editConfiguration(project, configuration, "Edit configuration", executor)) { return false; } while (!RunManagerImpl.canRunConfiguration(configuration, executor)) { if (0 == Messages.showYesNoDialog( project, "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway", Messages.getErrorIcon())) { if (!RunDialog.editConfiguration( project, configuration, "Edit configuration", executor)) { break; } } else { break; } } } return true; }
void init() { if (myInitialized) { return; } if (myConfigurationName != null && myConfigurationType != null) { Collection<RunnerAndConfigurationSettings> configurations = RunManagerImpl.getInstanceImpl(myProject).getSortedConfigurations(); for (RunnerAndConfigurationSettings runConfiguration : configurations) { ConfigurationType type = runConfiguration.getType(); if (myConfigurationName.equals(runConfiguration.getName()) && type != null && myConfigurationType.equals(type.getId())) { setSettings(runConfiguration); return; } } } }
private static RunnerAndConfigurationSettings createRunnerAndConfigurationSettings( MavenGeneralSettings generalSettings, MavenRunnerSettings runnerSettings, MavenRunnerParameters params, Project project) { MavenRunConfigurationType type = ConfigurationTypeUtil.findConfigurationType(MavenRunConfigurationType.class); final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project) .createConfiguration( MavenRunConfigurationType.generateName(project, params), type.getConfigurationFactories()[0]); MavenRunConfiguration runConfiguration = (MavenRunConfiguration) settings.getConfiguration(); runConfiguration.setRunnerParameters(params); if (generalSettings != null) runConfiguration.setGeneralSettings(generalSettings); if (runnerSettings != null) runConfiguration.setRunnerSettings(runnerSettings); return settings; }
@NotNull private static List<RunnerAndConfigurationSettings> getAvailableConfigurations( RunConfiguration runConfiguration) { Project project = runConfiguration.getProject(); if (project == null || !project.isInitialized()) return Collections.emptyList(); final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project); final ArrayList<RunnerAndConfigurationSettings> configurations = new ArrayList<RunnerAndConfigurationSettings>(runManager.getSortedConfigurations()); String executorId = DefaultRunExecutor.getRunExecutorInstance().getId(); for (Iterator<RunnerAndConfigurationSettings> iterator = configurations.iterator(); iterator.hasNext(); ) { RunnerAndConfigurationSettings settings = iterator.next(); final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings); if (runner == null || settings.getConfiguration() == runConfiguration) iterator.remove(); } return configurations; }
@NotNull private static ExecutionEnvironmentBuilder createEnvironmentBuilder( @NotNull Project project, @NotNull Executor executor, @Nullable RunnerAndConfigurationSettings configuration) { ExecutionEnvironmentBuilder builder = new ExecutionEnvironmentBuilder(project, executor); ProgramRunner runner = RunnerRegistry.getInstance() .getRunner( executor.getId(), configuration != null ? configuration.getConfiguration() : null); if (runner == null && configuration != null) { LOG.error("Cannot find runner for " + configuration.getName()); } else if (runner != null) { assert configuration != null; builder.runnerAndSettings(runner, configuration); } return builder; }
public ExternalSystemRunConfigurationAction( Project project, RunnerAndConfigurationSettings configurationSettings) { myConfigurationSettings = configurationSettings; ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) configurationSettings.getConfiguration(); systemId = runConfiguration.getSettings().getExternalSystemId(); ExternalSystemUiAware uiAware = ExternalSystemUiUtil.getUiAware(systemId); myGroup = uiAware.getProjectRepresentationName( runConfiguration.getSettings().getExternalProjectPath(), null); String actionIdPrefix = getActionPrefix(project, runConfiguration.getSettings().getExternalProjectPath()); myId = actionIdPrefix + configurationSettings.getName(); Presentation template = getTemplatePresentation(); template.setText(myConfigurationSettings.getName(), false); template.setIcon(runConfiguration.getIcon()); }
private void runTriggers(Executor executor, RunnerAndConfigurationSettings configuration) { final ConfigurationType configurationType = configuration.getType(); if (configurationType != null) { UsageTrigger.trigger( "execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + executor.getId()); } }
@Override public void update(final AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) { disable(presentation); return; } RunnerAndConfigurationSettings settings = chooseTempSettings(project); if (settings == null) { disable(presentation); } else { presentation.setText( ExecutionBundle.message( "save.temporary.run.configuration.action.name", settings.getName())); presentation.setDescription(presentation.getText()); presentation.setVisible(true); presentation.setEnabled(true); } }
private static void updatePresentation( @Nullable ExecutionTarget target, @Nullable RunnerAndConfigurationSettings settings, @Nullable Project project, @NotNull Presentation presentation) { if (project != null && target != null && settings != null) { String name = settings.getName(); if (target != DefaultExecutionTarget.INSTANCE) { name += " | " + target.getDisplayName(); } else { if (!settings.canRunOn(target)) { name += " | Nothing to run on"; } } presentation.setText(name, false); setConfigurationIcon(presentation, settings, project); } else { presentation.setText(""); // IDEA-21657 presentation.setIcon(null); } }