001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }