001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools;
016    
017    import java.util.Map;
018    
019    /**
020     * @author Shuyang Zhou
021     * @author Raymond Augé
022     */
023    public class ArgumentsUtil {
024    
025            public static Map<String, String> parseArguments(String[] args) {
026                    Map<String, String> arguments = new ArgumentsMap();
027    
028                    for (String arg : args) {
029                            int pos = arg.indexOf('=');
030    
031                            if (pos <= 0) {
032                                    throw new IllegalArgumentException("Bad argument " + arg);
033                            }
034    
035                            String key = arg.substring(0, pos).trim();
036                            String value = arg.substring(pos + 1).trim();
037    
038                            if (key.startsWith("-D")) {
039                                    key = key.substring(2);
040    
041                                    System.setProperty(key, value);
042                            }
043                            else {
044                                    arguments.put(key, value);
045                            }
046                    }
047    
048                    return arguments;
049            }
050    
051    }