Java Code Examples for org.codehaus.plexus.util.cli.CommandLineUtils#translateCommandline()

The following examples show how to use org.codehaus.plexus.util.cli.CommandLineUtils#translateCommandline() . 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: RunMojo.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (optionalRunExtraArgs == null) {
        optionalRunExtraArgs = new ArrayList<>();
    }

    String runArgsProp = System.getProperty("vertx.runArgs");

    if (StringUtils.isNotEmpty(runArgsProp)) {
        getLog().debug("Got command line arguments from property :" + runArgsProp);
        try {
            String[] argValues = CommandLineUtils.translateCommandline(runArgsProp);
            optionalRunExtraArgs.addAll(Arrays.asList(argValues));
        } catch (Exception e) {
            throw new MojoFailureException("Unable to parse system property vertx.runArgs", e);
        }
    } else if (runArgs != null && !runArgs.isEmpty()) {
        optionalRunExtraArgs.addAll(runArgs);
    }

    super.execute();
}
 
Example 2
Source File: MavenSettings.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean hasOption(String longName, String shortName) {
    String defOpts = getDefaultOptions();
    if (defOpts != null) {
        try {
            String[] strs = CommandLineUtils.translateCommandline(defOpts);
            for (String s : strs) {
                s = s.trim();
                if (s.startsWith(shortName) || s.startsWith(longName)) {
                    return true;
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(MavenSettings.class.getName()).log(Level.FINE, "Error parsing global options:{0}", defOpts);
            //will check for contains of -X be enough?
            return defOpts.contains(longName) || defOpts.contains(shortName);
        }
    }
    return false;
}
 
Example 3
Source File: EmbedderFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static Map<String, String> getCustomGlobalUserProperties() {
    //maybe set org.eclipse.aether.ConfigurationProperties.USER_AGENT with netbeans specific value.
    Map<String, String> toRet = new HashMap<String, String>();
    String options = getPreferences().get(PROP_DEFAULT_OPTIONS, "");
    try {
        
        String[] cmdlines = CommandLineUtils.translateCommandline(options);
        if (cmdlines != null) {
            for (String cmd : cmdlines) {
                if (cmd != null && cmd.startsWith("-D")) {
                    cmd = cmd.substring("-D".length());
                    int ind = cmd.indexOf('=');
                    if (ind > -1) {
                        String key = cmd.substring(0, ind);
                        String val = cmd.substring(ind + 1);
                        toRet.put(key, val);
                    }
                }
            }
        }
        return toRet;
    } catch (Exception ex) {
        LOG.log(Level.FINE, "cannot parse " + options, ex);
        return Collections.emptyMap();
    }
}
 
Example 4
Source File: RunMojo.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (optionalRunExtraArgs == null) {
        optionalRunExtraArgs = new ArrayList<>();
    }

    String runArgsProp = System.getProperty("vertx.runArgs");

    if (StringUtils.isNotEmpty(runArgsProp)) {
        getLog().debug("Got command line arguments from property :" + runArgsProp);
        try {
            String[] argValues = CommandLineUtils.translateCommandline(runArgsProp);
            optionalRunExtraArgs.addAll(Arrays.asList(argValues));
        } catch (Exception e) {
            throw new MojoFailureException("Unable to parse system property vertx.runArgs", e);
        }
    } else if (runArgs != null && !runArgs.isEmpty()) {
        optionalRunExtraArgs.addAll(runArgs);
    }

    super.execute();
}
 
Example 5
Source File: AbstractExecMojo.java    From exec-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER.
 * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using
 * ESCAPE_CHAR.
 *
 * @return Array of String representing the arguments
 * @throws MojoExecutionException for wrong formatted arguments
 */
protected String[] parseCommandlineArgs()
    throws MojoExecutionException
{
    if ( commandlineArgs == null )
    {
        return null;
    }
    else
    {
        try
        {
            return CommandLineUtils.translateCommandline( commandlineArgs );
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( e.getMessage() );
        }
    }
}
 
Example 6
Source File: AbstractExecMojo.java    From jprotobuf with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER.
 * PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using
 * ESCAPE_CHAR.
 *
 * @return Array of String representing the arguments
 * @throws MojoExecutionException for wrong formatted arguments
 */
protected String[] parseCommandlineArgs()
    throws MojoExecutionException
{
    if ( commandlineArgs == null )
    {
        return null;
    }
    else
    {
        try
        {
            return CommandLineUtils.translateCommandline( commandlineArgs );
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( e.getMessage() );
        }
    }
}
 
Example 7
Source File: Args.java    From amazon-neptune-tools with Apache License 2.0 5 votes vote down vote up
public Args(String cmd) {
    String[] values;
    try {
        values = CommandLineUtils.translateCommandline(cmd);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    args.addAll(Arrays.asList(values));
}
 
Example 8
Source File: CosChecker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static List<String> extractDebugJVMOptions(String argLine) throws Exception {
    String[] split = CommandLineUtils.translateCommandline(argLine);
    List<String> toRet = new ArrayList<String>();
    for (String arg : split) {
        if ("-Xdebug".equals(arg)) { //NOI18N
            continue;
        }
        if ("-Djava.compiler=none".equals(arg)) { //NOI18N
            continue;
        }
        if ("-Xnoagent".equals(arg)) { //NOI18N
            continue;
        }
        if (arg.startsWith("-Xrunjdwp")) { //NOI18N
            continue;
        }
        if (arg.equals("-agentlib:jdwp")) { //NOI18N
            continue;
        }
        if (arg.startsWith("-agentlib:jdwp=")) { //NOI18N
            continue;
        }
        if (arg.trim().length() == 0) {
            continue;
        }
        toRet.add(arg);
    }
    return toRet;
}
 
Example 9
Source File: ExecMojo.java    From exec-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void handleSystemPropertyArguments( String argsProp, List<String> commandArguments )
    throws MojoExecutionException
{
    getLog().debug( "got arguments from system properties: " + argsProp );

    try
    {
        String[] args = CommandLineUtils.translateCommandline( argsProp );
        commandArguments.addAll( Arrays.asList( args ) );
    }
    catch ( Exception e )
    {
        throw new MojoExecutionException( "Couldn't parse systemproperty 'exec.args'" );
    }
}
 
Example 10
Source File: PhantomJsProcessBuilder.java    From phantomjs-maven-plugin with MIT License 5 votes vote down vote up
@VisibleForTesting
String[] getCommandLineOptions(String commandLineOptions) throws ExecutionException {
  try {
    return CommandLineUtils.translateCommandline(commandLineOptions);
  } catch (Exception e) {
    throw new ExecutionException(UNABLE_TO_BUILD_CMD_LINE_OPTIONS, e);
  }
}
 
Example 11
Source File: StepBeanDefinitionRegistrar.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
private String getCommandLineArgsForTask(String arguments, String taskName, Map<String, Integer> taskSuffixMap, String ctrName ) {
	String result = "";
	if(!StringUtils.hasText(arguments)) {
		return arguments;
	}
	if(arguments.startsWith("\"") && arguments.endsWith("\"")) {
		arguments = arguments.substring(1, arguments.length() - 1);
	}
	arguments = arguments.replace('\n', ' ').replace('\t', ' ');
	this.firstAdd = true;
	try {
		String[] args = CommandLineUtils.translateCommandline(arguments);
		String taskNamePrefix = taskName + ".";
		String taskNameNonIdentify = "--" + taskNamePrefix;
		for(String commandLineArg : Arrays.asList(args)) {
			String userPrefix = getPrefix(commandLineArg);
			String commandLineArgPrefix = ctrName + "-" + userPrefix;
			String commandLineArgToken = commandLineArgPrefix + ".";
			if(commandLineArgToken.equals(taskNameNonIdentify) || commandLineArgToken.equals(taskNamePrefix)) {
				result = addBlankToCommandLineArgs(result);
				if(commandLineArg.startsWith(userPrefix)) {
					result = result.concat(commandLineArg.substring(userPrefix.length() + 1));
				}
				else {
					result = result + "--" + commandLineArg.substring(userPrefix.length() + 3);
				}
				continue;
			}
			if(!taskSuffixMap.containsKey(commandLineArgPrefix)) {
				result = addBlankToCommandLineArgs(result);
				if(commandLineArg.contains(" ")) {
					commandLineArg = commandLineArg.substring(0, commandLineArg.indexOf("=")) +
							"=\"" + commandLineArg.substring(commandLineArg.indexOf("=") + 1 )+ "\"";
				}
				result = result.concat(commandLineArg);
			}
		}
	}
	catch (Exception e) {
		throw new IllegalArgumentException("Unable to extract command line args for task " + taskName, e);
	}

	return result;
}