diff --git a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt index 070cc8c95882..247bd7c45455 100644 --- a/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt +++ b/plugins/performanceTesting/commands-model/src/com/intellij/tools/ide/performanceTesting/commands/generalCommandChain.kt @@ -236,6 +236,13 @@ fun T.inspectCodeEx( addCommand("${CMD_PREFIX}InspectCodeEx" + resultCommand) } +fun T.configureNamedScope( + scopeName: String, + pattern: String, +): T = apply { + addCommand("${CMD_PREFIX}configureNamedScope -scopeName $scopeName -pattern $pattern") +} + fun T.checkOnRedCode(): T = apply { addCommand("${CMD_PREFIX}codeAnalysis ${CodeAnalysisType.CHECK_ON_RED_CODE}") } diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java index 905240f3c210..3ddfb835facc 100644 --- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java @@ -16,6 +16,7 @@ public final class BaseCommandProvider implements CommandProvider { Map.entry(StopProfileCommand.PREFIX, StopProfileCommand::new), Map.entry(InspectionCommand.PREFIX, InspectionCommand::new), Map.entry(InspectionCommandEx.PREFIX, InspectionCommandEx::new), + Map.entry(ConfigureNamedScopeCommand.PREFIX, ConfigureNamedScopeCommand::new), Map.entry(ReformatCommand.PREFIX, ReformatCommand::new), Map.entry(GoToCommand.PREFIX, GoToCommand::new), Map.entry(ScrollEditorCommand.PREFIX, ScrollEditorCommand::new), diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/ConfigureNamedScopeCommand.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/ConfigureNamedScopeCommand.java new file mode 100644 index 000000000000..b539690f9fa9 --- /dev/null +++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/ConfigureNamedScopeCommand.java @@ -0,0 +1,70 @@ +package com.jetbrains.performancePlugin.commands; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.playback.PlaybackContext; +import com.intellij.openapi.ui.playback.commands.AbstractCommand; +import com.intellij.psi.search.scope.packageSet.NamedScope; +import com.intellij.psi.search.scope.packageSet.NamedScopeManager; +import com.intellij.psi.search.scope.packageSet.PackageSetFactory; +import com.intellij.psi.search.scope.packageSet.ParsingException; +import com.sampullara.cli.Args; +import com.sampullara.cli.Argument; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.concurrency.Promise; + +import static org.jetbrains.concurrency.Promises.rejectedPromise; +import static org.jetbrains.concurrency.Promises.resolvedPromise; + +public class ConfigureNamedScopeCommand extends AbstractCommand { + + public static final String PREFIX = CMD_PREFIX + "configureNamedScope"; + + private final Options myOptions = new Options(); + + public ConfigureNamedScopeCommand(String text, int line) { + super(text, line); + if (text.startsWith(PREFIX)) { + Args.parse(myOptions, text.substring(PREFIX.length()).trim().split(" "), false); + } + } + + @Override + protected @NotNull Promise _execute(@NotNull PlaybackContext context) { + String scopeName = myOptions.scopeName; + String pattern = myOptions.pattern; + if (scopeName == null) { + dumpError(context, "Missing scope name."); + return rejectedPromise(); + } + if (pattern == null) { + dumpError(context, "Missing pattern."); + return rejectedPromise(); + } + Project project = context.getProject(); + if (NamedScopeManager.getInstance(project).getScope(scopeName) != null) { + dumpError(context, "Scope " + scopeName + "already exists."); + return rejectedPromise(); + } + try { + NamedScope newScope = NamedScopeManager.getInstance(project).createScope(scopeName, PackageSetFactory.getInstance().compile(pattern)); + NamedScopeManager.getInstance(project).addScope(newScope); + } + catch (ParsingException e) { + dumpError(context, "Failed to parse scope pattern: " + pattern + "\n" + e.getMessage()); + throw new RuntimeException(e); + } + if (NamedScopeManager.getInstance(project).getScope(scopeName) == null) { + dumpError(context, "Failed to create scope " + scopeName); + return rejectedPromise(); + } + return resolvedPromise(); + } + + static class Options { + @Argument + String scopeName; + + @Argument + String pattern; + } +}