|
1 /* |
|
2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package nsk.share.aod; |
|
24 |
|
25 import nsk.share.*; |
|
26 import java.util.*; |
|
27 |
|
28 public class AODRunnerArgParser extends ArgumentParser { |
|
29 |
|
30 public static final String jarAgentParam = "ja"; |
|
31 |
|
32 public static final String nativeAgentParam = "na"; |
|
33 |
|
34 public static final String targetAppParam = "target"; |
|
35 |
|
36 public static final String javaOptsParam = "javaOpts"; |
|
37 |
|
38 public static final String testedJdkParam = "jdk"; |
|
39 |
|
40 private static List<String> supportedOptions; |
|
41 |
|
42 static { |
|
43 supportedOptions = new ArrayList<String>(); |
|
44 supportedOptions.add(jarAgentParam); |
|
45 supportedOptions.add(nativeAgentParam); |
|
46 supportedOptions.add(targetAppParam); |
|
47 supportedOptions.add(javaOptsParam); |
|
48 supportedOptions.add(testedJdkParam); |
|
49 } |
|
50 |
|
51 private List<AgentInformation> agents; |
|
52 |
|
53 public AODRunnerArgParser(String[] args) { |
|
54 super(args); |
|
55 } |
|
56 |
|
57 protected boolean checkOption(String option, String value) { |
|
58 if (super.checkOption(option, value)) |
|
59 return true; |
|
60 |
|
61 if (!supportedOptions.contains(option)) |
|
62 return false; |
|
63 |
|
64 if (option.equals(jarAgentParam)) { |
|
65 addAgentInfo(true, value); |
|
66 } |
|
67 |
|
68 if (option.equals(nativeAgentParam)) { |
|
69 addAgentInfo(false, value); |
|
70 } |
|
71 |
|
72 return true; |
|
73 } |
|
74 |
|
75 protected void checkOptions() { |
|
76 if (agents == null) { |
|
77 agents = new ArrayList<AgentInformation>(); |
|
78 } |
|
79 } |
|
80 |
|
81 private void addAgentInfo(boolean jarAgent, String unsplittedAgentsString) { |
|
82 if (agents == null) { |
|
83 agents = new ArrayList<AgentInformation>(); |
|
84 } |
|
85 |
|
86 String agentStrings[]; |
|
87 |
|
88 if (unsplittedAgentsString.contains(",")) |
|
89 agentStrings = unsplittedAgentsString.split(","); |
|
90 else |
|
91 agentStrings = new String[]{unsplittedAgentsString}; |
|
92 |
|
93 for (String agentString : agentStrings) { |
|
94 int index = agentString.indexOf('='); |
|
95 |
|
96 if (index > 0) { |
|
97 String pathToAgent = agentString.substring(0, index); |
|
98 String options = agentString.substring(index + 1); |
|
99 agents.add(new AgentInformation(jarAgent, pathToAgent, options)); |
|
100 } else { |
|
101 agents.add(new AgentInformation(jarAgent, agentString, null)); |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 public String getTargetApp() { |
|
107 if (!options.containsKey(targetAppParam)) |
|
108 throw new TestBug("Target application isn't specified"); |
|
109 |
|
110 return options.getProperty(targetAppParam); |
|
111 } |
|
112 |
|
113 public String getTestedJDK() { |
|
114 if (!options.containsKey(testedJdkParam)) |
|
115 throw new TestBug("Tested JDK isn't specified"); |
|
116 |
|
117 return options.getProperty(testedJdkParam); |
|
118 } |
|
119 |
|
120 public String getJavaOpts() { |
|
121 return options.getProperty(javaOptsParam, ""); |
|
122 } |
|
123 |
|
124 public List<AgentInformation> getAgents() { |
|
125 return agents; |
|
126 } |
|
127 } |