Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java
41161 views
/*1* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.share.aod;2425import nsk.share.ArgumentParser;26import nsk.share.TestBug;2728import java.util.ArrayList;29import java.util.List;30import java.util.Set;3132public class AODRunnerArgParser extends ArgumentParser {33private static final String JAR_AGENT_PARAM = "ja";34private static final String NATIVE_AGENT_PARAM = "na";35private static final String TARGET_APP_PARAM = "target";36private static final String JAVA_OPTS_PARAM = "javaOpts";37private static final String TESTED_JDK_PARAM = "jdk";38private static final Set<String> SUPPORTED_OPTIONS = Set.of(39JAR_AGENT_PARAM,40NATIVE_AGENT_PARAM,41TARGET_APP_PARAM,42JAVA_OPTS_PARAM,43TESTED_JDK_PARAM);4445private List<AgentInformation> agents;4647public AODRunnerArgParser(String[] args) {48super(args);49}5051protected boolean checkOption(String option, String value) {52if (super.checkOption(option, value)) {53return true;54}5556if (!SUPPORTED_OPTIONS.contains(option)) {57return false;58}5960if (option.equals(JAR_AGENT_PARAM)) {61addAgentInfo(true, value);62}6364if (option.equals(NATIVE_AGENT_PARAM)) {65addAgentInfo(false, value);66}6768return true;69}7071protected void checkOptions() {72if (agents == null) {73agents = new ArrayList<>();74}75}7677private void addAgentInfo(boolean jarAgent, String unsplittedAgentsString) {78if (agents == null) {79agents = new ArrayList<>();80}8182String[] agentStrings;8384if (unsplittedAgentsString.contains(",")) {85agentStrings = unsplittedAgentsString.split(",");86} else {87agentStrings = new String[]{ unsplittedAgentsString };88}8990for (String agentString : agentStrings) {91int index = agentString.indexOf('=');9293if (index > 0) {94String pathToAgent = agentString.substring(0, index);95String options = agentString.substring(index + 1);96agents.add(new AgentInformation(jarAgent, pathToAgent, options));97} else {98agents.add(new AgentInformation(jarAgent, agentString, null));99}100}101}102103public String getTargetApp() {104if (!options.containsKey(TARGET_APP_PARAM)) {105throw new TestBug("Target application isn't specified");106}107108return options.getProperty(TARGET_APP_PARAM);109}110111public String getTestedJDK() {112if (!options.containsKey(TESTED_JDK_PARAM)) {113throw new TestBug("Tested JDK isn't specified");114}115116return options.getProperty(TESTED_JDK_PARAM);117}118119public String getJavaOpts() {120var value = options.getProperty(JAVA_OPTS_PARAM, "");121if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) {122value = value.substring(1, value.length() - 1);123}124return value.trim();125}126127public List<AgentInformation> getAgents() {128return agents;129}130}131132133