All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.arquillian.container.tomcat.AdditionalJavaOptionsParser Maven / Gradle / Ivy

There is a newer version: 1.2.2.Final
Show newest version
package org.jboss.arquillian.container.tomcat;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Tomas Repel
 *
 */
public class AdditionalJavaOptionsParser {

	private static final String OPTION = "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"|\\S+";
	private static final String QUOTED_CONTENT = "^\"(.*)\"$";

	/**
	 * Parse additional java options. Options are separated by whitespace. In case some option value contains whitespace,
	 * the whole key-value pair has to be quoted. For instance string 'opt0 opt1=val1 "opt2=val2 with space"' results in three
	 * key-value pairs (opt0 option has an empty value).
	 *
	 * @param additionaOptions - options to parse
	 * @return List of parsed options, returns empty list rather that null value
	 */
	public static List parse(String additionalOptions) {
		List options = new ArrayList();
		if (additionalOptions != null) {
            Pattern p = Pattern.compile(OPTION, Pattern.DOTALL);
            Matcher m = p.matcher(additionalOptions);
            while (m.find()) {
                if ( !(m.group().trim().equals("")) ) {
                   options.add(Pattern.compile(QUOTED_CONTENT, Pattern.DOTALL).matcher(m.group().trim()).replaceAll("$1"));
                }
            }
        }
		return options;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy