You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2013/11/13 00:48:20 UTC
svn commit: r1541320 - in /uima/sandbox/uima-ducc/trunk:
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/
uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/
uima-ducc-jd/ uim...
Author: burn
Date: Tue Nov 12 23:48:19 2013
New Revision: 1541320
URL: http://svn.apache.org/r1541320
Log:
UIMA-3428 Remove or & jd dependency on the cli jar (it drags in extra stuff) by moving 2 methods into a new QuotedOptions class in common
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java (with props)
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccUiUtilities.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java
uima/sandbox/uima-ducc/trunk/uima-ducc-jd/pom.xml
uima/sandbox/uima-ducc/trunk/uima-ducc-jd/src/main/java/org/apache/uima/ducc/jd/client/CasSource.java
uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/pom.xml
uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/JobFactory.java
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccUiUtilities.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccUiUtilities.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccUiUtilities.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccUiUtilities.java Tue Nov 12 23:48:19 2013
@@ -18,14 +18,9 @@
*/
package org.apache.uima.ducc.cli;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
@@ -38,7 +33,7 @@ import org.apache.uima.ducc.cli.IUiOptio
import org.apache.uima.ducc.common.TcpStreamHandler;
import org.apache.uima.ducc.common.uima.UimaUtils;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
-import org.apache.uima.ducc.common.utils.Utils;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.ducc.transport.event.sm.IService.ServiceType;
import org.apache.uima.util.XMLInputSource;
import org.w3c.dom.Document;
@@ -67,8 +62,8 @@ public class DuccUiUtilities {
boolean modified = false;
String source = "LD_LIBRARY_PATH";
String target = "DUCC_"+source;
- ArrayList<String> envList = tokenizeList(environment, false); // Don't strip quotes
- Map<String,String> envMap = parseAssignments(envList, false); // Keep all entries
+ ArrayList<String> envList = QuotedOptions.tokenizeList(environment, false); // Don't strip quotes
+ Map<String,String> envMap = QuotedOptions.parseAssignments(envList, false); // Keep all entries
if (envMap.containsKey(source)) {
if (!envMap.containsKey(target)) {
envMap.put(target, envMap.get(source));
@@ -134,117 +129,6 @@ public class DuccUiUtilities {
return "http://" + host + ":" + port + "/" + server.substring(0, 2);
}
- //**********
-
- public static String buildBrokerUrl() {
- String ducc_broker_protocol = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_broker_protocol);
- String ducc_broker_hostname = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_broker_hostname);
- String ducc_broker_port = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_broker_port);
- String ducc_broker_url_decoration = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_broker_url_decoration);
- if(ducc_broker_protocol == null) {
- ducc_broker_protocol = "tcp";
- }
- if(ducc_broker_hostname == null) {
- ducc_broker_hostname = "localhost";
- }
- if(ducc_broker_port == null) {
- ducc_broker_port = "61616";
- }
- StringBuffer sb = new StringBuffer();
- sb.append(ducc_broker_protocol);
- sb.append("://");
- sb.append(ducc_broker_hostname);
- sb.append(":");
- sb.append(ducc_broker_port);
- if( ducc_broker_url_decoration != null ) {
- ducc_broker_url_decoration = ducc_broker_url_decoration.trim();
- if( ducc_broker_url_decoration.length() > 0 ) {
- sb.append("?");
- sb.append(ducc_broker_url_decoration);
- }
- }
- return sb.toString();
- }
-
- /**
- * Resolve all properies in a props from jvmargs and System.properties().
- */
- public static void resolvePropertiesPlaceholders(Properties myprops, Properties jvmargs)
- {
-
- Properties sysprops = System.getProperties();
- for ( Object o : myprops.keySet() ) {
- //
- // We're resolving against serveral properties files. We have to catch and ignore
- // missing-placeholder exceptions until the last one, because missing stuff could be
- // resolved in subsequent attampts.
- //
- String k = (String) o;
- Object vo = myprops.get(k);
- if ( !( vo instanceof String) ) { // some things aren't strings, we bypass them
- continue;
- }
-
- String v = (String) myprops.get(k);
- try {
- v = Utils.resolvePlaceholders(v, sysprops);
- } catch ( IllegalArgumentException e ) {
- // ignore this one if it occurs, not the next one
- }
- if ( jvmargs != null ) {
- v = Utils.resolvePlaceholders(v, jvmargs);
- }
- myprops.put(k, v);
- }
- }
-
- /**
- * Given a jvmargs-like string, turn it into a properties object containing the -D entries
- * and resolve against system properites.
- *
- * Try to only call this once, it's a boot-strap for getting the JVM args.
- */
- public static Properties jvmArgsToProperties(String jvmargs)
- {
- if ( jvmargs == null ) return null;
-
- // We have to make a properties file from the jvm args. Resolve placeholders
- // and return the props file with everything resolved.
- Properties props = new Properties();
-
- //
- // The jvm args look like properties for the most part: k=v pairs
- // We write them into a string and turn them into properies for the resolver
- //
- String[] args = jvmargs.split("\\s+");
- StringWriter sw = new StringWriter();
- for ( String s : args ) sw.write(s + "\n");
- StringReader sr = new StringReader(sw.toString());
- try {
- props.load(sr);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- //
- // Not quite there -- only -D things are props, and they have '-D' stuck to their names!
- //
- Properties goodprops = new Properties();
- Properties sysprops = System.getProperties();
- for ( Object s : props.keySet() ) {
- String k = (String) s;
- if ( k.startsWith("-D") ) {
- String v = (String) props.get(k);
- k = k.substring(2);
- k = Utils.resolvePlaceholders(k, sysprops);
- goodprops.put(k, v);
- }
- }
-
- return goodprops;
- }
-
/**
* Extract the endpoint from the deployment descriptor, resolving names and placeholders against
* the same environment as that of the JVM that will deploy the service
@@ -281,8 +165,8 @@ public class DuccUiUtilities {
String broker = element.getAttribute("brokerURL");
String ep = "UIMA-AS:" + endpoint + ":" + broker;
if (ep.contains("${")) {
- ArrayList<String> jvmargList = tokenizeList(jvmargs, true); // Strip quotes
- Map<String, String> jvmargMap = parseAssignments(jvmargList, true); // only -D entries
+ ArrayList<String> jvmargList = QuotedOptions.tokenizeList(jvmargs, true); // Strip quotes
+ Map<String, String> jvmargMap = QuotedOptions.parseAssignments(jvmargList, true); // only -D entries
ep = resolvePlaceholders(ep, jvmargMap);
}
return ep;
@@ -361,130 +245,4 @@ public class DuccUiUtilities {
return sb.toString();
}
- /*
-
- */
-
- /**
- * Create an array of parameters from a whitespace-delimited list (e.g. JVM args or environment assignments.)
- * Values containing whitespace must be single- or double-quoted:
- * TERM=xterm DISPLAY=:1.0 LD_LIBRARY_PATH="/my/path/with blanks/" EMPTY= -Dxyz="a b c" -Dabc='x y z'
- * Quotes may be stripped or preserved.
- * Values containing both types of quotes are NOT supported.
- *
- * @param options
- * - string of blank-delimited options
- * @param stripQuotes
- * - true if balanced quotes are to be removed
- * @return - array of options
- */
- public static ArrayList<String> tokenizeList(String options, boolean stripQuotes) {
-
- ArrayList<String> tokens = new ArrayList<String>();
- if (options == null) {
- return tokens;
- }
-
- // Pattern matches a non-quoted region or a double-quoted region or a single-quoted region
- // 1st part matches one or more non-whitespace characters but not " or '
- // 2nd part matches a "quoted" region containing any character except "
- // 3rd part matches a 'quoted' region containing any character except '
- // See: http://stackoverflow.com/questions/3366281/tokenizing-a-string-but-ignoring-delimiters-within-quotes
-
- String noSpaceRegex = "[^\\s\"']+";
- String doubleQuoteRegex = "\"([^\"]*)\"";
- String singleQuoteRegex = "'([^']*)'";
- final String regex = noSpaceRegex + "|" + doubleQuoteRegex + "|" + singleQuoteRegex;
- Pattern patn = Pattern.compile(regex);
- Matcher matcher = patn.matcher(options);
- StringBuilder sb = new StringBuilder();
-
- // If stripping quotes extract the capturing group (without the quotes)
- // When preserving quotes extract the full region
- // Combine the pieces of a token until the match ends with whitespace
- if (stripQuotes) {
- while (matcher.find()) {
- if (matcher.group(1) != null) {
- sb.append(matcher.group(1));
- } else if (matcher.group(2) != null) {
- sb.append(matcher.group(2));
- } else {
- sb.append(matcher.group());
- }
- if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
- tokens.add(sb.toString());
- sb.setLength(0);
- }
- }
- } else {
- while (matcher.find()) {
- sb.append(matcher.group());
- if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
- tokens.add(sb.toString());
- sb.setLength(0);
- }
- }
- }
- return tokens;
- }
-
- /*
- * Create a map from an array of environment variable assignments produced by tokenizeList Quotes
- * may have been stripped by tokenizeList The value is optional but the key is NOT, e.g. accept
- * assignments of the form foo=abc & foo= & foo reject =foo & =
- *
- * @param assignments - list of environment or JVM arg assignments
- * @param jvmArgs - true if tokens are JVM args -- process only the -Dprop=value entries
- *
- * @return - map of key/value pairs null if syntax is illegal
- */
- public static Map<String, String> parseAssignments(List<String> assignments, boolean jvmArgs)
- throws IllegalArgumentException {
-
- HashMap<String, String> map = new HashMap<String, String>();
- if (assignments == null || assignments.size() == 0) {
- return map;
- }
- for (String assignment : assignments) {
- String[] parts = assignment.split("=", 2); // Split on first '='
- String key = parts[0];
- if (key.length() == 0) {
- throw new IllegalArgumentException("Missing key in assignment: " + assignment);
- }
- if (jvmArgs) {
- if (!key.startsWith("-D")) {
- continue;
- }
- key = key.substring(2);
- }
- map.put(key, parts.length > 1 ? parts[1] : "");
- }
- return map;
- }
-
- // ====================================================================================================
-
- /*
- * Test the quote handling and optional stripping
- */
- public static void main(String[] args) {
- String[] lists = { "SINGLE_QUOTED='single quoted'\tDOUBLE_QUOTED=\"double quoted\" SINGLE_QUOTE=\"'\" \r DOUBLE_QUOTE='\"'",
- "",
- " ",
- null };
-
- for (String list : lists) {
- System.out.println("List: " + list);
- ArrayList<String> tokens = tokenizeList(list, false);
- System.out.println("\n quotes preserved on " + tokens.size());
- for (String token : tokens) {
- System.out.println("~" + token + "~");
- }
- tokens = tokenizeList(list, true);
- System.out.println("\n quotes stripped from " + tokens.size());
- for (String token : tokens) {
- System.out.println("~" + token + "~");
- }
- }
- }
}
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java Tue Nov 12 23:48:19 2013
@@ -32,11 +32,11 @@ import org.apache.commons.cli.MissingArg
import org.apache.uima.ducc.cli.CliBase;
import org.apache.uima.ducc.cli.DuccJobSubmit;
import org.apache.uima.ducc.cli.DuccManagedReservationSubmit;
-import org.apache.uima.ducc.cli.DuccUiUtilities;
import org.apache.uima.ducc.cli.IDuccCallback;
import org.apache.uima.ducc.cli.aio.IMessageHandler.Level;
import org.apache.uima.ducc.cli.aio.IMessageHandler.Toggle;
import org.apache.uima.ducc.common.utils.DuccSchedulerClasses;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.ducc.transport.event.cli.JobRequestProperties;
public class AllInOneLauncher extends CliBase {
@@ -701,7 +701,7 @@ public class AllInOneLauncher extends Cl
if(process_jvm_args != null) {
// Tokenize and strip quotes
- ArrayList<String> jvmargs = DuccUiUtilities.tokenizeList(process_jvm_args, true);
+ ArrayList<String> jvmargs = QuotedOptions.tokenizeList(process_jvm_args, true);
for(String jvmarg : jvmargs) {
commandArray.add(jvmarg);
}
@@ -730,8 +730,8 @@ public class AllInOneLauncher extends Cl
// Put environment settings in the process's environment
if(environment != null) {
- ArrayList<String> envList = DuccUiUtilities.tokenizeList(environment, true); // Strip quotes
- Map<String,String> envMap = DuccUiUtilities.parseAssignments(envList, false); // Keep all entries
+ ArrayList<String> envList = QuotedOptions.tokenizeList(environment, true); // Strip quotes
+ Map<String,String> envMap = QuotedOptions.parseAssignments(envList, false); // Keep all entries
Map<String,String> env = pb.environment();
env.clear();
env.putAll(envMap);
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java Tue Nov 12 23:48:19 2013
@@ -28,9 +28,9 @@ import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.CAS;
import org.apache.uima.collection.CollectionException;
import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.ducc.cli.DuccUiUtilities;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.uima.UimaUtils;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.resource.ResourceConfigurationException;
import org.apache.uima.resource.ResourceCreationSpecifier;
import org.apache.uima.resource.ResourceInitializationException;
@@ -93,8 +93,8 @@ public class CasGenerator {
if(crOverrides != null) {
// Tokenize override assignments on whitespace, honoring but stripping quotes
// Then create a map from all of them
- ArrayList<String> toks = DuccUiUtilities.tokenizeList(crOverrides, true);
- Map<String,String> map = DuccUiUtilities.parseAssignments(toks, false);
+ ArrayList<String> toks = QuotedOptions.tokenizeList(crOverrides, true);
+ Map<String,String> map = QuotedOptions.parseAssignments(toks, false);
for (Entry<String, String> ent : map.entrySet()) {
String name = ent.getKey();
String value = ent.getValue();
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java Tue Nov 12 23:48:19 2013
@@ -33,9 +33,9 @@ import org.apache.uima.analysis_engine.A
import org.apache.uima.analysis_engine.AnalysisEngineManagement;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
-import org.apache.uima.ducc.cli.DuccUiUtilities;
import org.apache.uima.ducc.cli.IUiOptions.UiOption;
import org.apache.uima.ducc.common.uima.UimaUtils;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.util.XMLInputSource;
@@ -62,7 +62,7 @@ public class CasPipeline {
String mid = "toArrayList";
mh.frameworkTrace(cid, mid, "enter");
// To match other lists tokenize on blanks & strip any quotes around values.
- ArrayList<String> list = DuccUiUtilities.tokenizeList(overrides, true);
+ ArrayList<String> list = QuotedOptions.tokenizeList(overrides, true);
mh.frameworkTrace(cid, mid, "exit");
return list;
}
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java?rev=1541320&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java Tue Nov 12 23:48:19 2013
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.common.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class QuotedOptions {
+ /**
+ * Create an array of parameters from a whitespace-delimited list (e.g. JVM args or environment assignments.)
+ * Values containing whitespace must be single- or double-quoted:
+ * TERM=xterm DISPLAY=:1.0 LD_LIBRARY_PATH="/my/path/with blanks/" EMPTY= -Dxyz="a b c" -Dabc='x y z'
+ * Quotes may be stripped or preserved.
+ * Values containing both types of quotes are NOT supported.
+ *
+ * @param options
+ * - string of blank-delimited options
+ * @param stripQuotes
+ * - true if balanced quotes are to be removed
+ * @return - array of options
+ */
+ public static ArrayList<String> tokenizeList(String options, boolean stripQuotes) {
+
+ ArrayList<String> tokens = new ArrayList<String>();
+ if (options == null) {
+ return tokens;
+ }
+
+ // Pattern matches a non-quoted region or a double-quoted region or a single-quoted region
+ // 1st part matches one or more non-whitespace characters but not " or '
+ // 2nd part matches a "quoted" region containing any character except "
+ // 3rd part matches a 'quoted' region containing any character except '
+ // See: http://stackoverflow.com/questions/3366281/tokenizing-a-string-but-ignoring-delimiters-within-quotes
+
+ String noSpaceRegex = "[^\\s\"']+";
+ String doubleQuoteRegex = "\"([^\"]*)\"";
+ String singleQuoteRegex = "'([^']*)'";
+ final String regex = noSpaceRegex + "|" + doubleQuoteRegex + "|" + singleQuoteRegex;
+ Pattern patn = Pattern.compile(regex);
+ Matcher matcher = patn.matcher(options);
+ StringBuilder sb = new StringBuilder();
+
+ // If stripping quotes extract the capturing group (without the quotes)
+ // When preserving quotes extract the full region
+ // Combine the pieces of a token until the match ends with whitespace
+ if (stripQuotes) {
+ while (matcher.find()) {
+ if (matcher.group(1) != null) {
+ sb.append(matcher.group(1));
+ } else if (matcher.group(2) != null) {
+ sb.append(matcher.group(2));
+ } else {
+ sb.append(matcher.group());
+ }
+ if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
+ tokens.add(sb.toString());
+ sb.setLength(0);
+ }
+ }
+ } else {
+ while (matcher.find()) {
+ sb.append(matcher.group());
+ if (matcher.end() >= options.length() || Character.isWhitespace(options.charAt(matcher.end()))) {
+ tokens.add(sb.toString());
+ sb.setLength(0);
+ }
+ }
+ }
+ return tokens;
+ }
+
+ /*
+ * Create a map from an array of environment variable assignments produced by tokenizeList Quotes
+ * may have been stripped by tokenizeList The value is optional but the key is NOT, e.g. accept
+ * assignments of the form foo=abc & foo= & foo reject =foo & =
+ *
+ * @param assignments - list of environment or JVM arg assignments
+ * @param jvmArgs - true if tokens are JVM args -- process only the -Dprop=value entries
+ *
+ * @return - map of key/value pairs null if syntax is illegal
+ */
+ public static Map<String, String> parseAssignments(List<String> assignments, boolean jvmArgs)
+ throws IllegalArgumentException {
+
+ HashMap<String, String> map = new HashMap<String, String>();
+ if (assignments == null || assignments.size() == 0) {
+ return map;
+ }
+ for (String assignment : assignments) {
+ String[] parts = assignment.split("=", 2); // Split on first '='
+ String key = parts[0];
+ if (key.length() == 0) {
+ throw new IllegalArgumentException("Missing key in assignment: " + assignment);
+ }
+ if (jvmArgs) {
+ if (!key.startsWith("-D")) {
+ continue;
+ }
+ key = key.substring(2);
+ }
+ map.put(key, parts.length > 1 ? parts[1] : "");
+ }
+ return map;
+ }
+
+ // ====================================================================================================
+
+ /*
+ * Test the quote handling and optional stripping
+ */
+ public static void main(String[] args) {
+ String[] lists = { "SINGLE_QUOTED='single quoted'\tDOUBLE_QUOTED=\"double quoted\" SINGLE_QUOTE=\"'\" \r DOUBLE_QUOTE='\"'",
+ "",
+ " ",
+ null };
+
+ for (String list : lists) {
+ System.out.println("List: " + list);
+ ArrayList<String> tokens = tokenizeList(list, false);
+ System.out.println("\n quotes preserved on " + tokens.size());
+ for (String token : tokens) {
+ System.out.println("~" + token + "~");
+ }
+ tokens = tokenizeList(list, true);
+ System.out.println("\n quotes stripped from " + tokens.size());
+ for (String token : tokens) {
+ System.out.println("~" + token + "~");
+ }
+ }
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/src/main/java/org/apache/uima/ducc/common/utils/QuotedOptions.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-jd/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-jd/pom.xml?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-jd/pom.xml (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-jd/pom.xml Tue Nov 12 23:48:19 2013
@@ -56,11 +56,6 @@
<version>${ducc.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uima-ducc-cli</artifactId>
- <version>${ducc.version}</version>
- </dependency>
</dependencies>
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-jd/src/main/java/org/apache/uima/ducc/jd/client/CasSource.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-jd/src/main/java/org/apache/uima/ducc/jd/client/CasSource.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-jd/src/main/java/org/apache/uima/ducc/jd/client/CasSource.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-jd/src/main/java/org/apache/uima/ducc/jd/client/CasSource.java Tue Nov 12 23:48:19 2013
@@ -31,10 +31,10 @@ import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.CAS;
import org.apache.uima.collection.CollectionException;
import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.ducc.cli.DuccUiUtilities;
import org.apache.uima.ducc.common.uima.UimaUtils;
import org.apache.uima.ducc.common.utils.DuccLogger;
import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.ducc.jd.IJobDriver;
import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
import org.apache.uima.resource.ResourceConfigurationException;
@@ -107,8 +107,8 @@ public class CasSource {
if(crcfg!= null) {
// Tokenize override assignments on whitespace, honoring but stripping quotes
// Then create a map from all of them
- ArrayList<String> toks = DuccUiUtilities.tokenizeList(crcfg, true);
- Map<String,String> map = DuccUiUtilities.parseAssignments(toks, false);
+ ArrayList<String> toks = QuotedOptions.tokenizeList(crcfg, true);
+ Map<String,String> map = QuotedOptions.parseAssignments(toks, false);
for (Entry<String, String> ent : map.entrySet()) {
String name = ent.getKey();
String value = ent.getValue();
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/pom.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/pom.xml?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/pom.xml (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/pom.xml Tue Nov 12 23:48:19 2013
@@ -55,11 +55,6 @@
<version>${ducc.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.uima</groupId>
- <artifactId>uima-ducc-cli</artifactId>
- <version>${ducc.version}</version>
- </dependency>
</dependencies>
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/JobFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/JobFactory.java?rev=1541320&r1=1541319&r2=1541320&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/JobFactory.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/JobFactory.java Tue Nov 12 23:48:19 2013
@@ -24,12 +24,14 @@ import java.util.Enumeration;
import java.util.List;
import java.util.Map;
-import org.apache.uima.ducc.cli.DuccUiUtilities;
+import org.apache.uima.ducc.common.IDuccEnv;
import org.apache.uima.ducc.common.NodeIdentity;
import org.apache.uima.ducc.common.config.CommonConfiguration;
import org.apache.uima.ducc.common.utils.DuccLogger;
import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.DuccProperties;
import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
+import org.apache.uima.ducc.common.utils.QuotedOptions;
import org.apache.uima.ducc.common.utils.TimeStamp;
import org.apache.uima.ducc.common.utils.id.DuccId;
import org.apache.uima.ducc.common.utils.id.DuccIdFactory;
@@ -81,7 +83,7 @@ public class JobFactory {
private IDuccIdFactory duccIdFactory = orchestratorCommonArea.getDuccIdFactory();
private JobDriverHostManager hostManager = orchestratorCommonArea.getHostManager();
private DuccIdFactory jdIdFactory = new DuccIdFactory();
-
+
private String java_classpath = System.getProperty("java.class.path");
private String classpath_order = System.getProperty("ducc.orchestrator.job.factory.classpath.order");
@@ -92,10 +94,10 @@ public class JobFactory {
if(environmentVariables != null) {
logger.debug(methodName, job.getDuccId(), environmentVariables);
// Tokenize the list of assignments, dequote, and convert to a map of environment settings
- ArrayList<String> envVarList = DuccUiUtilities.tokenizeList(environmentVariables, true);
+ ArrayList<String> envVarList = QuotedOptions.tokenizeList(environmentVariables, true);
Map<String, String> envMap;
try {
- envMap = DuccUiUtilities.parseAssignments(envVarList, false);
+ envMap = QuotedOptions.parseAssignments(envVarList, false);
} catch (IllegalArgumentException e) {
logger.warn(methodName, job.getDuccId(),"Invalid environment syntax in: " + environmentVariables);
return 0; // Should not happen as CLI should have checked and rejected the request
@@ -126,7 +128,7 @@ public class JobFactory {
String methodName = "toArrayList";
logger.trace(methodName, null, "enter");
// To match other lists tokenize on blanks & strip any quotes around values.
- ArrayList<String> list = DuccUiUtilities.tokenizeList(overrides, true);
+ ArrayList<String> list = QuotedOptions.tokenizeList(overrides, true);
logger.trace(methodName, null, "exit");
return list;
}
@@ -304,7 +306,7 @@ public class JobFactory {
// Add the user-provided JVM args
boolean haveXmx = false;
String driver_jvm_args = jobRequestProperties.getProperty(JobSpecificationProperties.key_driver_jvm_args);
- ArrayList<String> dTokens = DuccUiUtilities.tokenizeList(driver_jvm_args, true);
+ ArrayList<String> dTokens = QuotedOptions.tokenizeList(driver_jvm_args, true);
for(String token : dTokens) {
driverCommandLine.addOption(token);
if (!haveXmx) {
@@ -313,7 +315,7 @@ public class JobFactory {
}
// Add any site-provided JVM args, but not -Xmx if the user has provided one
String siteJvmArgs = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_submit_driver_jvm_args);
- dTokens = DuccUiUtilities.tokenizeList(siteJvmArgs, true); // a null arg is acceptable
+ dTokens = QuotedOptions.tokenizeList(siteJvmArgs, true); // a null arg is acceptable
for (String token : dTokens) {
if (!haveXmx || !token.startsWith("-Xmx")) {
driverCommandLine.addOption(token);
@@ -532,13 +534,13 @@ public class JobFactory {
pipelineCommandLine.setClassName("main:provided-by-Process-Manager");
pipelineCommandLine.setClasspath(processClasspath);
String process_jvm_args = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_jvm_args);
- ArrayList<String> pTokens = DuccUiUtilities.tokenizeList(process_jvm_args, true);
+ ArrayList<String> pTokens = QuotedOptions.tokenizeList(process_jvm_args, true);
for(String token : pTokens) {
pipelineCommandLine.addOption(token);
}
// Add any site-provided JVM args
String siteJvmArgs = DuccPropertiesResolver.get(DuccPropertiesResolver.ducc_submit_process_jvm_args);
- pTokens = DuccUiUtilities.tokenizeList(siteJvmArgs, true); // a null arg is acceptable
+ pTokens = QuotedOptions.tokenizeList(siteJvmArgs, true); // a null arg is acceptable
for(String token : pTokens) {
pipelineCommandLine.addOption(token);
}
@@ -561,7 +563,7 @@ public class JobFactory {
job.setCommandLine(executableProcessCommandLine);
// Tokenize arguments string and strip any quotes, then add to command line.
// Note: placeholders replaced by CLI so can avoid the add method.
- List<String> process_executable_arguments = DuccUiUtilities.tokenizeList(
+ List<String> process_executable_arguments = QuotedOptions.tokenizeList(
jobRequestProperties.getProperty(JobSpecificationProperties.key_process_executable_args), true);
executableProcessCommandLine.getArguments().addAll(process_executable_arguments);
}