001
014
015 package com.liferay.portal.tools;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018
019 import java.util.Map;
020
021
026 public class ArgumentsUtil {
027
028 public static Map<String, String> parseArguments(String[] args) {
029 Map<String, String> arguments = new ArgumentsMap();
030
031 for (String arg : args) {
032 int pos = arg.indexOf('=');
033
034 if (pos <= 0) {
035 throw new IllegalArgumentException("Bad argument " + arg);
036 }
037
038 String key = arg.substring(0, pos).trim();
039 String value = arg.substring(pos + 1).trim();
040
041 if (key.startsWith("-D")) {
042 key = key.substring(2);
043
044 System.setProperty(key, value);
045 }
046 else {
047 arguments.put(key, value);
048 }
049 }
050
051 return arguments;
052 }
053
054 public static void processMainException(
055 Map<String, String> arguments, Exception e)
056 throws Exception {
057
058 String throwMainException = arguments.get("tools.throw.main.exception");
059
060 if (GetterUtil.getBoolean(throwMainException, true)) {
061 throw e;
062 }
063
064 e.printStackTrace();
065 }
066
067 }