1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19/** 20 * @author Ivan G. Popov 21 */ 22 23/** 24 * Created on 29.01.2005 25 */ 26package org.apache.harmony.jpda.tests.jdwp.share; 27 28import java.io.BufferedReader; 29import java.io.IOException; 30import java.io.InputStreamReader; 31 32import org.apache.harmony.jpda.tests.framework.LogWriter; 33import org.apache.harmony.jpda.tests.framework.TestErrorException; 34import org.apache.harmony.jpda.tests.share.JPDATestOptions; 35 36/** 37 * This class provides DebuggeeWrapper implementation based on JUnit framework. 38 * Debuggee is always launched on local machine and attaches to debugger. 39 */ 40public class JDWPManualDebuggeeWrapper extends JDWPUnitDebuggeeWrapper { 41 42 private BufferedReader reader = null; 43 44 /** 45 * A constructor that creates new instance with given data. 46 * 47 * @param settings 48 * test run options 49 * @param logWriter 50 * where to print log messages 51 */ 52 public JDWPManualDebuggeeWrapper(JPDATestOptions settings, 53 LogWriter logWriter) { 54 super(settings, logWriter); 55 reader = new BufferedReader(new InputStreamReader(System.in)); 56 } 57 58 /** 59 * Get response from user and check if it is as expected. 60 */ 61 private void checkUserResponse(String expected) throws IOException { 62 String response = reader.readLine(); 63 if (!expected.equals(response)) { 64 throw new TestErrorException("Unexpected user response: " 65 + response + " (expected: " + expected + ")"); 66 } 67 } 68 69 /** 70 * Asks user to launch process with given command line and waits for 71 * confirmation. 72 * 73 * @param cmdLine 74 * command line 75 * @return null instead of associated Process object 76 * @throws IOException 77 * if user does not confirm process launching 78 */ 79 protected Process launchProcess(String cmdLine) throws IOException { 80 getLogWriter().println( 81 "\n>>> Start debuggee VM with this command line:\n" + cmdLine); 82 getLogWriter().println( 83 "\n>>> Confirm that debuggee VM has started [yes/no]:"); 84 checkUserResponse("yes"); 85 return null; 86 } 87 88 /** 89 * Waits for user to confirm that launched process has exited. 90 * 91 * @param process 92 * should be null instead of associated Process object 93 * @throws IOException 94 * if user does not confirm process exit 95 */ 96 protected void WaitForProcessExit(Process process) throws IOException { 97 getLogWriter().println( 98 "\n>>> Confirm that debuggee VM has exited [yes/no]:"); 99 checkUserResponse("yes"); 100 } 101} 102