View Javadoc

1   /**
2    * Copyright (C) 2012 White Source Ltd.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.whitesource.teamcity.common;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.regex.Pattern;
23  
24  /**
25   * Class to hold common utility helper methods.
26   *
27   * @author Edo.Shor
28   */
29  public final class WssUtils {
30  
31      /* --- Static members --- */
32  
33      private static final Pattern PARAM_LIST_SPLIT_PATTERN = Pattern.compile(",|$", Pattern.MULTILINE);
34      private static final Pattern KEY_VALUE_SPLIT_PATTERN = Pattern.compile("=");
35  
36      /* --- Public methods --- */
37  
38      public static String logMsg(String component, String msg) {
39          return "[whitesource]::" + component + ": " + msg;
40      }
41  
42      public static boolean isMavenRunType(String runType) {
43          return Constants.RUNNER_MAVEN.equals(runType);
44      }
45  
46      public static List<String> splitParameters(String paramList) {
47          List<String> params = new ArrayList<String>();
48  
49          if (paramList != null) {
50              String[] split = PARAM_LIST_SPLIT_PATTERN.split(paramList);
51              if (split != null) {
52                  for (String param : split) {
53                      if (!(param == null || param.trim().length() == 0)) {
54                          params.add(param.trim());
55                      }
56                  }
57              }
58          }
59  
60          return params;
61      }
62  
63      public static Map<String, String> splitParametersMap(String paramList) {
64          Map<String, String> params = new HashMap<String, String>();
65  
66          List<String> kvps = splitParameters(paramList);
67          if (kvps != null) {
68              for (String kvp : kvps) {
69                  String[] split = KEY_VALUE_SPLIT_PATTERN.split(kvp);
70                  if (split.length == 2) {
71                      params.put(split[0], split[1]);
72                  }
73              }
74          }
75  
76          return params;
77      }
78  
79  }