/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Vitaly A. Provodin */ /** * Created on 26.01.2005 */ package org.apache.harmony.jpda.tests.framework; import java.util.HashMap; /** * This class provides access to options for running JPDA tests. *
* The settings are presented as a set of getters and setters for test options, * which can be implemented in different ways. In this implementation test * options are implemented via VM system properties, which can be specified * using option '-D' in VM command line. *
* The following options are currently recognized: *
jpda.settings.debuggeeJavaHome
* - path to Java bundle to run debuggee on
* jpda.settings.debuggeeJavaExec
* - name of Java executable to run debuggee on
* jpda.settings.debuggeeJavaPath
* - full path to Java executable to run debuggee on
* jpda.settings.debuggeeAgentName
* - name of agent native library
* jpda.settings.debuggeeAgentExtraOptions
* - extra options for agent
* jpda.settings.debuggeeClassName
* - full name of class to run debuggee with
* jpda.settings.debuggeeVMExtraOptions
* - extra options to run debuggee with
* jpda.settings.debuggeeSuspend
* - debuggee suspend mode ("y"|"n")
* jpda.settings.transportWrapperClass
* - class name of TransportWrapper implementation
* jpda.settings.transportAddress
* - address for JDWP connection
* jpda.settings.connectorKind
* - type of JDWP connection (attach or listen)
* jpda.settings.syncPort
* - port number for sync connection
* jpda.settings.timeout
* - timeout used in JPDA tests
* jpda.settings.waitingTime
* - timeout for waiting events
* jpda.settings.verbose
* - flag that disables (default) or enables writing messages to the log
*
* All options have default values, if they are not specified.
*
*/
public class TestOptions {
/** Default timeout value for various operations. */
public static final int DEFAULT_TIMEOUT = 1 * 60 * 1000; // 1 minute
/** Default time interval for waiting for various events. */
public static final int DEFAULT_WAITING_TIME = DEFAULT_TIMEOUT;
/** Default static address for transport connection. */
public static final String DEFAULT_ATTACHING_ADDRESS = "127.0.0.1:9898";
/** Default port number for sync connection. */
public static final String DEFAULT_STATIC_SYNC_PORT = "9797";
/** Default port number for sync connection. */
public static final int DEFAULT_SYNC_PORT = 0;
/** Default class name for transport wrapper. */
public static final String DEFAULT_TRANSPORT_WRAPPER
= "org.apache.harmony.jpda.tests.framework.jdwp.SocketTransportWrapper";
/** Default aclass name for debuggee application. */
public static final String DEFAULT_DEBUGGEE_CLASS_NAME
= "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
// current waiting time value (negative means using default value)
private long waitingTime = -1;
// current timeout value (negative means using default value)
private long timeout = -1;
// internally set property values
private HashMap internalProperties = new HashMap();
/**
* Constructs an instance of this class.
*/
public TestOptions() {
super();
}
/**
* Returns path to Java bundle to run debuggee on.
*
* @return option "jpda.settings.debuggeeJavaHome" or system property
* "java.home" by default.
*/
public String getDebuggeeJavaHome() {
return getProperty("jpda.settings.debuggeeJavaHome", getProperty("java.home", null));
}
/**
* Returns name of Java executable to run debuggee on.
*
* @return option "jpda.settings.debuggeeJavaExec" or "java" by default.
*/
public String getDebuggeeJavaExec() {
return getProperty("jpda.settings.debuggeeJavaExec", "java");
}
/**
* Returns full path to Java executable to run debuggee on.
*
* @return option "jpda.settings.debuggeeJavaPath" or construct path from
* getDebuggeeJavaHome() and getDebuggeeJavaExec() by default.
*/
public String getDebuggeeJavaPath() {
return getProperty("jpda.settings.debuggeeJavaPath",
getDebuggeeJavaHome() + "/bin/" + getDebuggeeJavaExec());
}
/**
* Returns class name of TransportWrapper implementation.
*
* @return option "jpda.settings.transportWrapperClass" or
* DEFAULT_TRANSPORT_WRAPPER by default.
*/
public String getTransportWrapperClassName() {
return getProperty("jpda.settings.transportWrapperClass",
DEFAULT_TRANSPORT_WRAPPER);
}
/**
* Returns address for JDWP connection or null for dynamic address.
*
* @return option "jpda.settings.transportAddress" or null by default.
*/
public String getTransportAddress() {
return getProperty("jpda.settings.transportAddress", null);
}
/**
* Sets address to attach to debuggee.
*
* @param address to attach
*/
public void setTransportAddress(String address) {
setProperty("jpda.settings.transportAddress", address);
}
/**
* Returns name of JDWP agent library.
*
* @return option "jpda.settings.debuggeeAgentName" or "jdwp" by default
*/
public String getDebuggeeAgentName() {
return getProperty("jpda.settings.debuggeeAgentName", "jdwp");
}
/**
* Returns string with extra options for agent.
*
* @return option "jpda.settings.debuggeeAgentExtraOptions" or "" by default
*/
public String getDebuggeeAgentExtraOptions() {
return getProperty("jpda.settings.debuggeeAgentExtraOptions", "");
}
/**
* Returns string with all options for agent including specified connection
* address.
*
* @param address - address to attach
* @param isDebuggerListen - true if debugger is listening for connection
*
* @return string with all agent options
*/
public String getDebuggeeAgentOptions(String address, boolean isDebuggerListen) {
String serv;
if (isDebuggerListen) {
serv = "n";
} else {
serv = "y";
}
// add ',' to agent extra options if required
String agentExtraOptions = getDebuggeeAgentExtraOptions();
if (agentExtraOptions.length() > 0 && agentExtraOptions.charAt(0) != ',') {
agentExtraOptions = "," + agentExtraOptions;
}
return getProperty("jpda.settings.debuggeeAgentOptions",
"transport=dt_socket,address=" + address + ",server=" + serv
+ ",suspend=" + getDebuggeeSuspend() + agentExtraOptions);
}
/**
* Returns string with all options for agent including specified connection
* address (only for debugger in listening mode). It just calls
* getDebuggeeAgentOptions(address, true)