org.openide.util.Utilities.parseParameters()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.openide.util.Utilities.parseParameters()方法的一些代码示例,展示了Utilities.parseParameters()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.parseParameters()方法的具体详情如下:
包路径:org.openide.util.Utilities
类名称:Utilities
方法名:parseParameters

Utilities.parseParameters介绍

[英]Parses parameters from a given string in shell-like manner. Users of the Bourne shell (e.g. on Unix) will already be familiar with the behavior. For example, when using org.openide.execution.NbProcessDescriptor (Execution API) you should be able to:

  • Include command names with embedded spaces, such as c:\Program Files\jdk\bin\javac.
  • Include extra command arguments, such as -Dname=value.
  1. Do anything else which might require unusual characters or processing. For example:

``

"c:\program files\jdk\bin\java" -Dmessage="Hello /\\/\\ there!" -Xmx128m

This example would create the following executable name and arguments:

  1. c:\program files\jdk\bin\java
    1. -Dmessage=Hello /\/\ there!
    2. -Xmx128m
      Note that the command string does not escape its backslashes--under the assumption that Windows users will not think to do this, meaningless escapes are just left as backslashes plus following character.
      Caveat: even after parsing, Windows programs (such as the Java launcher) may not fully honor certain characters, such as quotes, in command names or arguments. This is because programs under Windows frequently perform their own parsing and unescaping (since the shell cannot be relied on to do this). On Unix, this problem should not occur.
      [中]以类似于shell的方式解析给定字符串中的参数。Bourne shell的用户(例如在Unix上)已经熟悉了这种行为。例如,当使用org.openide.execution.NbProcessDescriptor(执行API)时,您应该能够:
      *包含带有嵌入空格的命令名,例如c:\Program Files\jdk\bin\javac
      *包括额外的命令参数,例如[$2$]。
      1.做任何可能需要特殊字符或处理的事情。例如:
      ``
"c:\program files\jdk\bin\java" -Dmessage="Hello /\\/\\ there!" -Xmx128m

此示例将创建以下可执行文件名和参数:

  1. c:\program files\jdk\bin\java
  2. -Dmessage=Hello /\/\ there!
  3. -Xmx128m
    请注意,命令字符串不会转义它的反斜杠——假设Windows用户不会这么做,无意义的转义只会保留为反斜杠加上后面的字符。
    警告:即使在解析之后,Windows程序(如Java launcher)也可能无法完全支持命令名或参数中的某些字符,如引号。这是因为Windows下的程序经常执行它们自己的解析和逃避(因为不能依赖shell来完成这项工作)。在Unix上,不应出现此问题。

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-platform

/**
 * Arguments to be prepended <em>BEFORE</em> the target. Usually arguments
 * and options for the Ruby interpreter.
 */
public String[] getInitialArgs() {
  return initialArgs == null ? null : Utilities.parseParameters(initialArgs);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-platform

/** Arguments to be passed to the JVM running the JRuby process. */
public String[] getJVMArguments() {
  return jvmArgs == null ? null : Utilities.parseParameters(jvmArgs);
}

代码示例来源:origin: org.netbeans.api/org-openide-execution

/** Parses given string to an array of arguments.
* @param sargs is tokenized by spaces unless a space is part of "" token
* @return tokenized string
*/
private static String[] parseArguments(String sargs) {
  return Utilities.parseParameters(sargs);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private List<String> getParams() {
  List<String> params = new ArrayList<>();
  if (StringUtils.hasText(phpArgs)) {
    params.addAll(Arrays.asList(Utilities.parseParameters(phpArgs)));
  }
  params.add(file.getAbsolutePath());
  if (StringUtils.hasText(fileArgs)) {
    params.addAll(Arrays.asList(Utilities.parseParameters(fileArgs)));
  }
  return params;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject

public String[] getArgsArray() {
  return Utilities.parseParameters(getArgsFlat());
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-project

protected String[] getApplicationArguments() {
    String applicationArgs = project.evaluator().getProperty(SharedRubyProjectProperties.APPLICATION_ARGS);
    return (applicationArgs == null || applicationArgs.trim().length() == 0)
        ? null : Utilities.parseParameters(applicationArgs);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-api-framework

public CommandDescriptor(FrameworkCommand task, String params, boolean debug) {
  Parameters.notNull("task", task);
  Parameters.notNull("params", params);
  this.task = task;
  this.params = Utilities.parseParameters(params.trim());
  this.debug = debug;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-css-prep

static Pair<String, List<String>> parseCommand(String command) {
  if (command == null) {
    // avoid NPE
    command = ""; // NOI18N
  }
  // try to find program (search for " -" or " /" after space)
  String[] tokens = command.split(" * (?=\\-|/)", 2); // NOI18N
  if (tokens.length == 1) {
    LOGGER.log(Level.FINE, "Only program given (no parameters): {0}", command);
    return Pair.of(tokens[0].trim(), Collections.<String>emptyList());
  }
  Pair<String, List<String>> parsedCommand = Pair.of(tokens[0].trim(), Arrays.asList(Utilities.parseParameters(tokens[1].trim())));
  LOGGER.log(Level.FINE, "Parameters parsed: {0} {1}", new Object[] {parsedCommand.first(), parsedCommand.second()});
  return parsedCommand;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

private String[] getDebugCommand() {
  String command = DebuggerOption.DEBUG_COMMAND.getCurrValue(options);
  if (config != null && config instanceof MakeConfiguration) {
    return Utilities.parseParameters(
         ProjectActionEvent.getRunCommandAsString(
          command, 
          (MakeConfiguration) config, 
          NativeDebuggerImpl.getPathMapFromConfig(config)
        )
    );
  } else {
    return Utilities.parseParameters("");
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-api-executable

static Pair<String, List<String>> parseCommand(String command) {
  if (command == null) {
    // avoid NPE
    command = ""; // NOI18N
  }
  // try to find program (search for " -" or " /" after space)
  String[] tokens = command.split(" * (?=\\-|/)", 2); // NOI18N
  if (tokens.length == 1) {
    LOGGER.log(Level.FINE, "Only program given (no parameters): {0}", command);
    return Pair.of(tokens[0].trim(), Collections.<String>emptyList());
  }
  Pair<String, List<String>> parsedCommand = Pair.of(tokens[0].trim(), Arrays.asList(Utilities.parseParameters(tokens[1].trim())));
  LOGGER.log(Level.FINE, "Parameters parsed: {0} {1}", new Object[] {parsedCommand.first(), parsedCommand.second()});
  return parsedCommand;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-css-prep

public static List<String> parseCompilerOptions(@NullAllowed String compilerOptions, @NullAllowed FileObject webRoot) {
  if (!StringUtils.hasText(compilerOptions)) {
    return Collections.emptyList();
  }
  String[] parsedCompilerParams = Utilities.parseParameters(processCompilerOptions(compilerOptions, webRoot));
  return Arrays.asList(parsedCompilerParams);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd

shellCommand = ShellSettings.getDefault().getDefaultShellCommand();
argvParsed = Utilities.parseParameters(shellCommand);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-railsprojects

for (String arg : Utilities.parseParameters(extraArgs)) {
  result.add(arg);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-client-tools-common

NbProcessDescriptor newP = null;
String [] args = Utilities.parseParameters(p.getArguments());
if (args.length > 1) {
  StringBuffer newArgs = new StringBuffer ();

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-docker-ui

String[] parsed = command == null ? new String[]{} : Utilities.parseParameters(command);
config.put("Image", getImage(tag));
JSONArray cmdArray = new JSONArray();

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-project

static void runTask(final RubyBaseProject project, final RakeTask task,
    final String taskParams, final boolean debug) {
  RakeRunner runner = new RakeRunner(project);
  runner.showWarnings(true);
  if (taskParams != null) {
    runner.setParameters(Utilities.parseParameters(taskParams));
  }
  runner.setDebug(debug);
  runner.run(task);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject

private String[] getRunCommand() {
  if (runCommandCache == null || runCommandCache.length == 0) {
    // not clear what is the difference between getPlatformInfo
    // and getDevelopmentHost.
    // TODO: get rid off one of ifs below
    assert(configuration.getPlatformInfo().isLocalhost() == configuration.getDevelopmentHost().isLocalhost());
    runCommandCache = Utilities.parseParameters(getRunCommandAsString());
  }
  return runCommandCache;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-project

private void doRun(File file, RunFileArgs runFileArgs, boolean debug) {
  File workDir = new File(runFileArgs.getWorkDir());
  RubyExecutionDescriptor desc = new RubyExecutionDescriptor(runFileArgs.getPlatform(), file.getName(), workDir);
  if (runFileArgs.getRunArgs() != null) {
    desc.additionalArgs(Utilities.parseParameters(runFileArgs.getRunArgs()));
  }
  desc.jvmArguments(runFileArgs.getJvmArgs());
  desc.initialArgs(runFileArgs.getRubyOpts());
  desc.debug(debug);
  desc.script(file.getAbsolutePath());
  RubyProcessCreator rpc = new RubyProcessCreator(desc);
  if (rpc.isAbleToCreateProcess()) {
    ExecutionService.newService(rpc, desc.toExecutionDescriptor(), file.getName()).run();
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-project

String[] args = Utilities.parseParameters(extraArgs);
if (args != null) {
  for (String arg : args) {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-project

desc.additionalArgs(Utilities.parseParameters(args.getRunArgs()));

相关文章