com.intellij.util.execution.ParametersListUtil Java Examples

The following examples show how to use com.intellij.util.execution.ParametersListUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunAnythingCommandProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void runCommand(@Nonnull VirtualFile workDirectory, @Nonnull String commandString, @Nonnull Executor executor, @Nonnull DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  LOG.assertTrue(project != null);

  Collection<String> commands = RunAnythingCache.getInstance(project).getState().getCommands();
  commands.remove(commandString);
  commands.add(commandString);

  dataContext = RunAnythingCommandCustomizer.customizeContext(dataContext);

  GeneralCommandLine initialCommandLine = new GeneralCommandLine(ParametersListUtil.parse(commandString, false, true)).withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withWorkDirectory(workDirectory.getPath());

  GeneralCommandLine commandLine = RunAnythingCommandCustomizer.customizeCommandLine(dataContext, workDirectory, initialCommandLine);
  try {
    RunAnythingRunProfile runAnythingRunProfile = new RunAnythingRunProfile(Registry.is("run.anything.use.pty", false) ? new PtyCommandLine(commandLine) : commandLine, commandString);
    ExecutionEnvironmentBuilder.create(project, executor, runAnythingRunProfile).dataContext(dataContext).buildAndExecute();
  }
  catch (ExecutionException e) {
    LOG.warn(e);
    Messages.showInfoMessage(project, e.getMessage(), IdeBundle.message("run.anything.console.error.title"));
  }
}
 
Example #2
Source File: ChromeSettings.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<String> getAdditionalParameters() {
  if (myCommandLineOptions == null) {
    if (myUseCustomProfile && myUserDataDirectoryPath != null) {
      return Collections.singletonList(USER_DATA_DIR_ARG + FileUtilRt.toSystemDependentName(myUserDataDirectoryPath));
    }
    else {
      return Collections.emptyList();
    }
  }

  List<String> cliOptions = ParametersListUtil.parse(myCommandLineOptions);
  if (myUseCustomProfile && myUserDataDirectoryPath != null) {
    cliOptions.add(USER_DATA_DIR_ARG + FileUtilRt.toSystemDependentName(myUserDataDirectoryPath));
  }
  return cliOptions;
}
 
Example #3
Source File: ExternalDiffToolUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Process execute(@Nonnull String exePath, @Nonnull String parametersTemplate, @Nonnull Map<String, String> patterns)
        throws ExecutionException {
  List<String> parameters = ParametersListUtil.parse(parametersTemplate, true);

  List<String> from = new ArrayList<>();
  List<String> to = new ArrayList<>();
  for (Map.Entry<String, String> entry : patterns.entrySet()) {
    from.add(entry.getKey());
    to.add(entry.getValue());
  }

  List<String> args = new ArrayList<>();
  for (String parameter : parameters) {
    String arg = StringUtil.replace(parameter, from, to);
    if (!StringUtil.isEmptyOrSpaces(arg)) args.add(arg);
  }

  GeneralCommandLine commandLine = new GeneralCommandLine();
  commandLine.setExePath(exePath);
  commandLine.addParameters(args);
  return commandLine.createProcess();
}
 
Example #4
Source File: BlazeParametersListUtil.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Like ParametersListUtil.encode(String) but will quote a param if it contains a single quote.
 *
 * @param param raw parameter to shell-encode for a commandline.
 * @return the encoded param.
 */
public static String encodeParam(String param) {
  // If single quotes are not quoted, it breaks round trip of parse/join if
  // ParametersListUtil.parse() is called with supportSingleQuotes=true. By forcing a space into
  // the parameter, it will force it to be quoted.
  param = param.replace("'", " '");
  // This will effectively return ParametersListUtil.encodeParam(param), which we can't access
  // directly because it is private
  String output = ParametersListUtil.join(param);
  output = output.replace(" '", "'");
  return output;
}
 
Example #5
Source File: ParametersListTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void checkTokenizer(String paramString, String... expected) {
  ParametersList params = new ParametersList();
  params.addParametersString(paramString);
  assertEquals(asList(expected), params.getList());

  List<String> lines = ParametersListUtil.parse(paramString, true);
  assertEquals(paramString, StringUtil.join(lines, " "));
}
 
Example #6
Source File: BlazePyRunConfigurationRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static String getScriptParams(BlazeCommandRunConfigurationCommonState state) {
  List<String> params =
      Lists.newArrayList(state.getExeFlagsState().getFlagsForExternalProcesses());
  params.addAll(state.getTestArgs());
  String filterFlag = state.getTestFilterFlag();
  if (filterFlag != null) {
    String testFilterArg = filterFlag.substring((BlazeFlags.TEST_FILTER + "=").length());
    // testFilterArg is a space-delimited list of filters
    params.addAll(Splitter.on(" ").splitToList(testFilterArg));
  }
  return ParametersListUtil.join(params);
}
 
Example #7
Source File: BlazeJavaRunProfileState.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Appends '--script_path' to blaze flags, then runs 'bash -c blaze build ... && run_script' */
private static List<String> getBashCommandsToRunScript(BlazeCommand.Builder blazeCommand) {
  File scriptFile = BlazeBeforeRunCommandHelper.createScriptPathFile();
  blazeCommand.addBlazeFlags("--script_path=" + scriptFile.getPath());
  String blaze = ParametersListUtil.join(blazeCommand.build().toList());
  return ImmutableList.of("/bin/bash", "-c", blaze + " && " + scriptFile.getPath());
}
 
Example #8
Source File: RunConfigurationFlagsState.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Flags ready to be used directly as args for external processes. */
public List<String> getFlagsForExternalProcesses() {
  List<String> processedFlags =
      flags.stream()
          .map(s -> ParametersListUtil.parse(s, false, true).get(0))
          .collect(Collectors.toList());
  return BlazeFlags.expandBuildFlags(processedFlags);
}
 
Example #9
Source File: BlazeGoRunConfigurationRunner.java    From intellij with Apache License 2.0 4 votes vote down vote up
GoApplicationRunningState toNativeState(ExecutionEnvironment env) throws ExecutionException {
  ExecutableInfo executable = getExecutableInfo(env);
  if (executable == null || StringUtil.isEmptyOrSpaces(executable.binary.getPath())) {
    throw new ExecutionException("Blaze output binary not found");
  }
  Project project = env.getProject();
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null) {
    throw new ExecutionException("Project data not found. Please run blaze sync.");
  }
  GoApplicationConfiguration nativeConfig =
      (GoApplicationConfiguration)
          GoApplicationRunConfigurationType.getInstance()
              .getConfigurationFactories()[0]
              .createTemplateConfiguration(project, RunManager.getInstance(project));
  nativeConfig.setKind(Kind.PACKAGE);
  // prevents binary from being deleted by
  // GoBuildingRunningState$ProcessHandler#processTerminated
  nativeConfig.setOutputDirectory(executable.binary.getParent());
  nativeConfig.setParams(ParametersListUtil.join(getParameters(executable)));
  nativeConfig.setWorkingDirectory(executable.workingDir.getPath());

  Map<String, String> customEnvironment = new HashMap<>(nativeConfig.getCustomEnvironment());
  for (Map.Entry<String, String> entry : executable.envVars.entrySet()) {
    customEnvironment.put(entry.getKey(), entry.getValue());
  }
  String testFilter = getTestFilter();
  if (testFilter != null) {
    customEnvironment.put("TESTBRIDGE_TEST_ONLY", testFilter);
  }
  nativeConfig.setCustomEnvironment(customEnvironment);

  Module module =
      ModuleManager.getInstance(project)
          .findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
  if (module == null) {
    throw new ExecutionException("Workspace module not found");
  }
  GoApplicationRunningState nativeState =
      new GoApplicationRunningState(env, module, nativeConfig) {
        @Override
        public boolean isDebug() {
          return true;
        }

        @Nullable
        @Override
        public List<String> getBuildingTarget() {
          return null;
        }

        @Nullable
        @Override
        public GoExecutor createBuildExecutor() {
          return null;
        }
      };
  nativeState.setOutputFilePath(executable.binary.getPath());
  return nativeState;
}
 
Example #10
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public static List<String> parseCmdParameters(@Nullable String cmdArgsLine) {
  return Optional.ofNullable(cmdArgsLine).map(ParametersListUtil::parse).orElse(new ArrayList<>());
}
 
Example #11
Source File: BlazeIntellijPluginConfiguration.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static void fillParameterList(ParametersList list, @Nullable String parameters) {
  if (parameters == null) {
    return;
  }
  list.addAll(ParametersListUtil.parse(parameters, /* keepQuotes= */ false));
}
 
Example #12
Source File: Messages.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void showTextAreaDialog(final JTextField textField, final String title, @NonNls final String dimensionServiceKey) {
  showTextAreaDialog(textField, title, dimensionServiceKey, ParametersListUtil.DEFAULT_LINE_PARSER, ParametersListUtil.DEFAULT_LINE_JOINER);
}
 
Example #13
Source File: ParametersList.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @see ParametersListUtil#join(java.util.List)
 */
@Nonnull
public static String join(@Nonnull final List<String> parameters) {
  return ParametersListUtil.join(parameters);
}
 
Example #14
Source File: ParametersList.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @see ParametersListUtil#join(java.util.List)
 */
@Nonnull
public static String join(final String... parameters) {
  return ParametersListUtil.join(parameters);
}
 
Example #15
Source File: ParametersList.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @see ParametersListUtil#parseToArray(String)
 */
@Nonnull
public static String[] parse(@Nonnull final String string) {
  return ParametersListUtil.parseToArray(string);
}
 
Example #16
Source File: RawCommandLineEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public RawCommandLineEditor() {
  this(ParametersListUtil.DEFAULT_LINE_PARSER, ParametersListUtil.DEFAULT_LINE_JOINER);
}
 
Example #17
Source File: BlazeParametersListUtil.java    From intellij with Apache License 2.0 4 votes vote down vote up
public static List<String> splitParameters(@Nullable String params) {
  if (params == null) {
    return ImmutableList.of();
  }
  return ParametersListUtil.parse(params, true, true);
}
 
Example #18
Source File: ExternalSystemExecuteTaskTask.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static List<String> parseCmdParameters(@Nullable String cmdArgsLine) {
  return cmdArgsLine != null ? ParametersListUtil.parse(cmdArgsLine) : ContainerUtil.<String>newArrayList();
}
 
Example #19
Source File: MuleBeforeRunTasksProvider.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public boolean executeTask(DataContext dataContext, RunConfiguration runConfiguration, ExecutionEnvironment executionEnvironment, MuleBeforeRunTask muleBeforeRunTask)
{
    final Semaphore targetDone = new Semaphore();
    final List<Boolean> results = new ArrayList<>();

    final Project project = executionEnvironment.getProject();

    MuleConfiguration muleConfiguration = (MuleConfiguration) runConfiguration;

    Module[] modules = muleConfiguration.getModules();

    for (Module nextModule : modules) {
        //final MavenProject mavenProject = getMavenProject(runConfiguration, project);
        final MavenProject mavenProject = getMavenProject(nextModule);
        try {
            ApplicationManager.getApplication().invokeAndWait(new Runnable() {
                public void run() {
                    if (!project.isDisposed() && mavenProject != null) {
                        FileDocumentManager.getInstance().saveAllDocuments();
                        final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
                        final MavenRunner mavenRunner = MavenRunner.getInstance(project);
                        targetDone.down();
                        (new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {
                            public void run(@NotNull ProgressIndicator indicator) {
                                try {
                                    MavenRunnerParameters params =
                                            new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse("package"), explicitProfiles.getEnabledProfiles(),
                                                    explicitProfiles.getDisabledProfiles());
                                    boolean result = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
                                    results.add(result);
                                } finally {
                                    targetDone.up();
                                }
                            }

                            public boolean shouldStartInBackground() {
                                return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
                            }

                            public void processSentToBackground() {
                                MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
                            }
                        }).queue();
                    }
                }
            }, ModalityState.NON_MODAL);
        } catch (Exception exeception) {
            return false;
        }
        targetDone.waitFor();
    }

    boolean endResult = true;

    for (Boolean nextResult : results) {
        endResult = endResult && nextResult;
    }

    return endResult;
}
 
Example #20
Source File: ExpandableTextField.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an expandable text field with the default line parser/joiner,
 * that uses a whitespaces to split a string to several lines.
 */
public ExpandableTextField() {
  this(ParametersListUtil.DEFAULT_LINE_PARSER, ParametersListUtil.DEFAULT_LINE_JOINER);
}