Source Code Cross Referenced for TestOptions.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » framework » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */
018:
019:        /**
020:         * @author Vitaly A. Provodin
021:         * @version $Revision: 1.9.2.2 $
022:         */
023:
024:        /**
025:         * Created on 26.01.2005
026:         */package org.apache.harmony.jpda.tests.framework;
027:
028:        import java.util.HashMap;
029:
030:        /**
031:         * This class provides access to options for running JPDA tests.
032:         * <p>
033:         * The settings are presented as a set of getters and setters for test options,
034:         * which can be implemented in different ways. In this implementation test
035:         * options are implemented via VM system properties, which can be specified
036:         * using option '-D' in VM command line.
037:         * <p>
038:         * The following options are currently recognized:
039:         * <ul>
040:         * <li><code>jpda.settings.debuggeeJavaHome</code>
041:         *   - path to Java bundle to run debuggee on
042:         * <li><code>jpda.settings.debuggeeJavaExec</code>
043:         *   - name of Java executable to run debuggee on
044:         * <li><code>jpda.settings.debuggeeJavaPath</code>
045:         *   - full path to Java executable to run debuggee on
046:         * <li><code>jpda.settings.debuggeeAgentName</code>
047:         *   - name of agent native library
048:         * <li><code>jpda.settings.debuggeeAgentExtraOptions</code>
049:         *   - extra options for agent
050:         * <li><code>jpda.settings.debuggeeClassName</code>
051:         *   - full name of class to run debuggee with
052:         * <li><code>jpda.settings.debuggeeVMExtraOptions</code>
053:         *   - extra options to run debuggee with
054:         * <li><code>jpda.settings.debuggeeSuspend</code>
055:         *   - debuggee suspend mode ("y"|"n")
056:         * <li><code>jpda.settings.transportWrapperClass</code>
057:         *   - class name of TransportWrapper implementation
058:         * <li><code>jpda.settings.transportAddress</code>
059:         *   - address for JDWP connection
060:         * <li><code>jpda.settings.connectorKind</code>
061:         *   - type of JDWP connection (attach or listen)
062:         * <li><code>jpda.settings.syncPort</code>
063:         *   - port number for sync connection
064:         * <li><code>jpda.settings.timeout</code>
065:         *   - timeout used in JPDA tests
066:         * <li><code>jpda.settings.waitingTime</code>
067:         *   - timeout for waiting events
068:         * </ul>
069:         * <li><code>jpda.settings.verbose</code>
070:         *   - flag that disables (default) or enables writing messages to the log
071:         * </ul>
072:         * All options have default values, if they are not specified.
073:         *  
074:         */
075:        public class TestOptions {
076:
077:            /** Default timeout value for various operations. */
078:            public static final int DEFAULT_TIMEOUT = 1 * 60 * 1000; // 1 minute
079:
080:            /** Default time interval for waiting for various events. */
081:            public static final int DEFAULT_WAITING_TIME = DEFAULT_TIMEOUT;
082:
083:            /** Default static address for transport connection. */
084:            public static final String DEFAULT_ATTACHING_ADDRESS = "127.0.0.1:9898";
085:
086:            /** Default port number for sync connection. */
087:            public static final String DEFAULT_STATIC_SYNC_PORT = "9797";
088:
089:            /** Default port number for sync connection. */
090:            public static final int DEFAULT_SYNC_PORT = 0;
091:
092:            /** Default class name for transport wrapper. */
093:            public static final String DEFAULT_TRANSPORT_WRAPPER = "org.apache.harmony.jpda.tests.framework.jdwp.SocketTransportWrapper";
094:
095:            /** Default aclass name for debuggee application. */
096:            public static final String DEFAULT_DEBUGGEE_CLASS_NAME = "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
097:
098:            // current waiting time value (negative means using default value)
099:            private long waitingTime = -1;
100:
101:            // current timeout value (negative means using default value)
102:            private long timeout = -1;
103:
104:            // internally set property values
105:            private HashMap internalProperties = new HashMap();
106:
107:            /**
108:             * Constructs an instance of this class.
109:             */
110:            public TestOptions() {
111:                super ();
112:            }
113:
114:            /**
115:             * Returns path to Java bundle to run debuggee on.
116:             * 
117:             * @return option "jpda.settings.debuggeeJavaHome" or system property
118:             *         "java.home" by default.
119:             */
120:            public String getDebuggeeJavaHome() {
121:                return getProperty("jpda.settings.debuggeeJavaHome",
122:                        getProperty("java.home", null));
123:            }
124:
125:            /**
126:             * Returns name of Java executable to run debuggee on.
127:             * 
128:             * @return option "jpda.settings.debuggeeJavaExec" or "java" by default.
129:             */
130:            public String getDebuggeeJavaExec() {
131:                return getProperty("jpda.settings.debuggeeJavaExec", "java");
132:            }
133:
134:            /**
135:             * Returns full path to Java executable to run debuggee on.
136:             * 
137:             * @return option "jpda.settings.debuggeeJavaPath" or construct path from
138:             *         getDebuggeeJavaHome() and getDebuggeeJavaExec() by default.
139:             */
140:            public String getDebuggeeJavaPath() {
141:                return getProperty("jpda.settings.debuggeeJavaPath",
142:                        getDebuggeeJavaHome() + "/bin/" + getDebuggeeJavaExec());
143:            }
144:
145:            /**
146:             * Returns class name of TransportWrapper implementation.
147:             * 
148:             * @return option "jpda.settings.transportWrapperClass" or
149:             *         DEFAULT_TRANSPORT_WRAPPER by default.
150:             */
151:            public String getTransportWrapperClassName() {
152:                return getProperty("jpda.settings.transportWrapperClass",
153:                        DEFAULT_TRANSPORT_WRAPPER);
154:            }
155:
156:            /**
157:             * Returns address for JDWP connection or null for dynamic address.
158:             * 
159:             * @return option "jpda.settings.transportAddress" or null by default.
160:             */
161:            public String getTransportAddress() {
162:                return getProperty("jpda.settings.transportAddress", null);
163:            }
164:
165:            /**
166:             * Sets address to attach to debuggee.
167:             * 
168:             * @param address to attach
169:             */
170:            public void setTransportAddress(String address) {
171:                setProperty("jpda.settings.transportAddress", address);
172:            }
173:
174:            /**
175:             * Returns name of JDWP agent library.
176:             * 
177:             * @return option "jpda.settings.debuggeeAgentName" or "jdwp" by default
178:             */
179:            public String getDebuggeeAgentName() {
180:                return getProperty("jpda.settings.debuggeeAgentName", "jdwp");
181:            }
182:
183:            /**
184:             * Returns string with extra options for agent.
185:             * 
186:             * @return option "jpda.settings.debuggeeAgentExtraOptions" or "" by default
187:             */
188:            public String getDebuggeeAgentExtraOptions() {
189:                return getProperty("jpda.settings.debuggeeAgentExtraOptions",
190:                        "");
191:            }
192:
193:            /**
194:             * Returns string with all options for agent including specified connection
195:             * address.
196:             *  
197:             * @param address - address to attach
198:             * @param isDebuggerListen - true if debugger is listening for connection
199:             * 
200:             * @return string with all agent options
201:             */
202:            public String getDebuggeeAgentOptions(String address,
203:                    boolean isDebuggerListen) {
204:                String serv;
205:                if (isDebuggerListen) {
206:                    serv = "n";
207:                } else {
208:                    serv = "y";
209:                }
210:
211:                // add ',' to agent extra options if required 
212:                String agentExtraOptions = getDebuggeeAgentExtraOptions();
213:                if (agentExtraOptions.length() > 0
214:                        && agentExtraOptions.charAt(0) != ',') {
215:                    agentExtraOptions = "," + agentExtraOptions;
216:                }
217:
218:                return getProperty("jpda.settings.debuggeeAgentOptions",
219:                        "transport=dt_socket,address=" + address + ",server="
220:                                + serv + ",suspend=" + getDebuggeeSuspend()
221:                                + agentExtraOptions);
222:            }
223:
224:            /**
225:             * Returns string with all options for agent including specified connection
226:             * address (only for debugger in listening mode). It just calls
227:             * <ul>
228:             * <li><code>getDebuggeeAgentOptions(address, true)</code></li>
229:             * </ul>
230:             *  
231:             * @deprecated This method is used as workaround for old tests and will be removed soon. 
232:             *  
233:             * @param address - address to attach
234:             * 
235:             * @return string with all agent options
236:             */
237:            public String getDebuggeeAgentOptions(String address) {
238:                return getDebuggeeAgentOptions(address, true);
239:            }
240:
241:            /**
242:             * Returns VM classpath value to run debuggee with.
243:             * 
244:             * @return system property "java.class.path" by default.
245:             */
246:            public String getDebuggeeClassPath() {
247:                return getProperty("java.class.path", null);
248:            }
249:
250:            /**
251:             * Returns full name of the class to start debuggee with.
252:             * 
253:             * @return option "jpda.settings.debuggeeClassName" or
254:             *         "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld" by default
255:             */
256:            public String getDebuggeeClassName() {
257:                return getProperty("jpda.settings.debuggeeClassName",
258:                        DEFAULT_DEBUGGEE_CLASS_NAME);
259:            }
260:
261:            /**
262:             * Sets full name of the class to start debuggee with.
263:             * 
264:             * @param className
265:             *            full class name
266:             */
267:            public void setDebuggeeClassName(String className) {
268:                setProperty("jpda.settings.debuggeeClassName", className);
269:            }
270:
271:            /**
272:             * Returns string with extra options to start debuggee with.
273:             * 
274:             * @return option "jpda.settings.debuggeeVMExtraOptions" or "" by default
275:             */
276:            public String getDebuggeeVMExtraOptions() {
277:                String extOpts = getProperty(
278:                        "jpda.settings.debuggeeVMExtraOptions", "");
279:                extOpts = extOpts + " -Djpda.settings.verbose=" + isVerbose();
280:                return extOpts;
281:            }
282:
283:            /**
284:             * Returns debuggee suspend mode ("y"|"n").
285:             * 
286:             * @return option "jpda.settings.debuggeeSuspend" or "y" by default
287:             */
288:            public String getDebuggeeSuspend() {
289:                return getProperty("jpda.settings.debuggeeSuspend", "y");
290:            }
291:
292:            /**
293:             * Returns debuggee suspend mode ("y"|"n").
294:             * 
295:             * @param mode
296:             *            suspend mode
297:             */
298:            public void setDebuggeeSuspend(String mode) {
299:                setProperty("jpda.settings.debuggeeSuspend", mode);
300:            }
301:
302:            /**
303:             * Checks if debuggee is launched in suspend mode.
304:             * 
305:             * @return true if debuggee is launched in suspend mode
306:             */
307:            public boolean isDebuggeeSuspend() {
308:                return getDebuggeeSuspend().equals("y");
309:            }
310:
311:            /**
312:             * Returns string representation of TCP/IP port for synchronization channel.
313:             * 
314:             * @return string with port number or null
315:             */
316:            public String getSyncPortString() {
317:                return getProperty("jpda.settings.syncPort", null);
318:            }
319:
320:            /**
321:             * Returns type of connection with debuggee.
322:             * 
323:             * @return system property "jpda.settings.connectorKind" or "listen" by default.
324:             */
325:            public String getConnectorKind() {
326:                return getProperty("jpda.settings.connectorKind", "listen");
327:            }
328:
329:            /**
330:             * Checks if attach connection with debuggee.
331:             * 
332:             * @return true, if attach connection, false otherwise.
333:             */
334:            public boolean isAttachConnectorKind() {
335:                return ((getConnectorKind()).equals("attach"));
336:
337:            }
338:
339:            /**
340:             * Checks if listen connection with debuggee.
341:             * 
342:             * @return true, if listen connection, false otherwise.
343:             */
344:            public boolean isListenConnectorKind() {
345:                return (getConnectorKind().equals("listen"));
346:            }
347:
348:            /**
349:             * Sets connectorKind to attach to debuggee.
350:             */
351:            public void setAttachConnectorKind() {
352:                setConnectorKind("attach");
353:            }
354:
355:            /**
356:             * Sets connectorKind to listen connection from debuggee.
357:             */
358:            public void setListenConnectorKind() {
359:                setConnectorKind("listen");
360:            }
361:
362:            /**
363:             * Sets kind of connector (attach or listen).
364:             */
365:            public void setConnectorKind(String kind) {
366:                setProperty("jpda.settings.connectorKind", kind);
367:            }
368:
369:            /**
370:             * Returns kind of launching debuggee VM, which can be "auto" or "manual".
371:             * 
372:             * @return option "jpda.settings.debuggeeLaunchKind" or "auto" by default.
373:             */
374:            public String getDebuggeeLaunchKind() {
375:                return getProperty("jpda.settings.debuggeeLaunchKind", "auto");
376:            }
377:
378:            /**
379:             * Returns TCP/IP port for synchronization channel.
380:             * 
381:             * @return string with port number or null
382:             */
383:            public int getSyncPortNumber() {
384:                String buf = getSyncPortString();
385:                if (buf == null) {
386:                    return DEFAULT_SYNC_PORT;
387:                }
388:
389:                try {
390:                    return Integer.parseInt(buf);
391:                } catch (NumberFormatException e) {
392:                    throw new TestErrorException(e);
393:                }
394:            }
395:
396:            /**
397:             * Returns timeout for JPDA tests in milliseconds.
398:             * 
399:             * @return option "jpda.settings.timeout" or DEFAULT_TIMEOUT by default.
400:             */
401:            public long getTimeout() {
402:                if (timeout < 0) {
403:                    timeout = DEFAULT_TIMEOUT;
404:                    String buf = getProperty("jpda.settings.timeout", null);
405:                    if (buf != null) {
406:                        try {
407:                            timeout = Long.parseLong(buf);
408:                        } catch (NumberFormatException e) {
409:                            throw new TestErrorException(e);
410:                        }
411:                    }
412:                }
413:                return timeout;
414:            }
415:
416:            /**
417:             * Sets timeout for JPDA tests in milliseconds.
418:             * 
419:             * @param timeout
420:             *            timeout to be set
421:             */
422:            public void setTimeout(long timeout) {
423:                if (timeout < 0) {
424:                    throw new TestErrorException(
425:                            "Cannot set negative timeout value: " + timeout);
426:                }
427:                this .timeout = timeout;
428:            }
429:
430:            /**
431:             * Returns waiting time for events in milliseconds.
432:             * 
433:             * @return waiting time
434:             */
435:            public long getWaitingTime() {
436:                if (waitingTime < 0) {
437:                    waitingTime = DEFAULT_WAITING_TIME;
438:                    String buf = getProperty("jpda.settings.waitingTime", null);
439:                    if (buf != null) {
440:                        try {
441:                            waitingTime = Long.parseLong(buf);
442:                        } catch (NumberFormatException e) {
443:                            throw new TestErrorException(e);
444:                        }
445:                    }
446:                }
447:                return waitingTime;
448:            }
449:
450:            /**
451:             * Sets waiting time for events in milliseconds.
452:             * 
453:             * @param waitingTime
454:             *            waiting time to be set
455:             */
456:            public void setWaitingTime(long waitingTime) {
457:                this .waitingTime = waitingTime;
458:            }
459:
460:            /**
461:             * Returns whether print to log is enabled.
462:             * 
463:             * @return false (default) if log is disabled or true otherwise.
464:             */
465:            public boolean isVerbose() {
466:                return isTrue(getProperty("jpda.settings.verbose", "true"));
467:            }
468:
469:            /**
470:             * Converts text to boolean.
471:             * 
472:             * @param str string representing boolean value
473:             * @return boolean
474:             */
475:            static public boolean isTrue(String str) {
476:                return str != null
477:                        && (str.equalsIgnoreCase("true")
478:                                || str.equalsIgnoreCase("yes")
479:                                || str.equalsIgnoreCase("on") || str
480:                                .equals("1"));
481:            }
482:
483:            /**
484:             * Returns value of given property if it was set internally or specified in system properties.
485:             *
486:             * @param name
487:             *           property name
488:             * @param defaultValue
489:             *           default value for given property
490:             * @return string value of given property or default value if no such property found 
491:             */
492:            protected String getProperty(String name, String defaultValue) {
493:                String value = (String) internalProperties.get(name);
494:                if (value != null) {
495:                    return value;
496:                }
497:                return System.getProperty(name, defaultValue);
498:            }
499:
500:            /**
501:             * Sets internal value of given property to override corresponding system property.
502:             *
503:             * @param name
504:             *           proparty name
505:             * @param value
506:             *           value for given property
507:             */
508:            protected void setProperty(String name, String value) {
509:                internalProperties.put(name, value);
510:            }
511:
512:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.