1 /* 2 * Copyright (c) 2009, 2012, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 */ 24 25 package client.test.runner; 26 27 import client.util.CtrUtils; 28 import com.sun.interview.Question; 29 import com.sun.interview.ChoiceQuestion; 30 import com.sun.javatest.Parameters.EnvParameters; 31 import com.sun.javatest.TestEnvironment; 32 import com.sun.javatest.interview.BasicInterviewParameters; 33 import com.sun.interview.StringQuestion; 34 import com.sun.interview.FileQuestion; 35 import com.sun.interview.DirectoryFileFilter; 36 import com.sun.interview.AllFilesFileFilter; 37 import java.util.Map; 38 import java.util.HashMap; 39 import java.io.File; 40 import client.test.runner.interview.PipelineGroupQuestion; 41 import client.test.runner.interview.PipelineQuestion; 42 43 /** 44 * 45 * @author vshubov 46 */ 47 public class DrtInterview extends BasicInterviewParameters 48 implements EnvParameters { 49 50 /** 51 * 52 */ 53 public static String FX_SDK_HOME_PARAM_NAME = "javafx"; 54 55 /** 56 * 57 */ 58 public static String BROWSER_PARAM_NAME = "browserPath"; 59 60 /** 61 * 62 */ 63 public static String PROXY_PARAM_NAME = "proxy"; 64 65 private String javaFXHome; 66 private String browserExec = "firefox"; 67 68 /** 69 * 70 * @throws Fault 71 */ 72 public DrtInterview() throws Fault { 73 super(null); 74 } 75 76 /** 77 * 78 * @return 79 */ 80 @Override 81 protected Question getEnvFirstQuestion() { 82 return qName; 83 } 84 85 /** 86 * 87 * @return 88 */ 89 public EnvParameters getEnvParameters() { 90 return this; 91 } 92 93 /** 94 * 95 * @return 96 */ 97 @Override 98 public TestEnvironment getEnv() { 99 HashMap envProps = new HashMap(); 100 export(envProps); 101 try { 102 String name = qName.getValue(); 103 if (name == null || name.length() == 0) { 104 name = "unknown"; 105 } 106 return new TestEnvironment(name, envProps, "configuration interview"); 107 } catch (TestEnvironment.Fault e) { 108 throw new Error("should not happen" + e); 109 } 110 } 111 private StringQuestion qName = new StringQuestion(this, "name") { 112 113 @Override 114 public String getText() { 115 return getSummary(); 116 } 117 118 @Override 119 public String getSummary() { 120 return "Configuration name"; 121 } 122 123 @Override 124 public Question getNext() { 125 if ("".equals(getValue()) || getValue() == null) { 126 return null; 127 } 128 return qJavaFX; 129 } 130 131 @Override 132 public void export(Map data) { 133 data.put("name", value); 134 } 135 136 @Override 137 public void load(Map data) { 138 setValue((String) data.get("name")); 139 } 140 }; 141 private FileQuestion qJavaFX = new FileQuestion(this, FX_SDK_HOME_PARAM_NAME) { 142 143 { 144 this.setFilter(new DirectoryFileFilter("JavaFX SDK containing directory")); 145 } 146 147 @Override 148 public String getText() { 149 return getSummary(); 150 } 151 152 @Override 153 public String getSummary() { 154 return "JavaFX SDK Home"; 155 } 156 157 @Override 158 public void clear() { 159 if (javaFXHome != null) { 160 setValue(javaFXHome); 161 } else { 162 setValue(""); 163 } 164 } 165 166 @Override 167 public Question getNext() { 168 if (!value.isDirectory()) { 169 return null; 170 } 171 return qBrowser; 172 } 173 174 @Override 175 public void export(Map data) { 176 javaFXHome = value.getPath(); 177 data.put(FX_SDK_HOME_PARAM_NAME, javaFXHome); 178 } 179 180 @Override 181 public void load(Map data) { 182 if (data.containsKey(FX_SDK_HOME_PARAM_NAME)) { 183 javaFXHome = (String) data.get(FX_SDK_HOME_PARAM_NAME); 184 if (javaFXHome != null) { 185 setValue(new File(javaFXHome)); 186 } 187 } 188 } 189 }; 190 191 private FileQuestion qBrowser = new FileQuestion(this, BROWSER_PARAM_NAME) { 192 193 { 194 this.setFilter(new AllFilesFileFilter("Browser executable")); 195 } 196 197 @Override 198 public String getText() { 199 return getSummary(); 200 } 201 202 @Override 203 public String getSummary() { 204 return "Browser executable"; 205 } 206 207 @Override 208 public void clear() { 209 setValue(browserExec); 210 } 211 212 @Override 213 public Question getNext() { 214 if (!value.isFile()) { 215 return null; 216 } 217 return qPipelineGroup; 218 } 219 220 @Override 221 public void export(Map data) { 222 browserExec = value.getPath(); 223 data.put(BROWSER_PARAM_NAME, browserExec); 224 } 225 226 @Override 227 public void load(Map data) { 228 if (data.containsKey(BROWSER_PARAM_NAME)) { 229 browserExec = (String) data.get(BROWSER_PARAM_NAME); 230 if (browserExec != null) { 231 setValue(new File(browserExec)); 232 } 233 } 234 } 235 }; 236 237 private StringQuestion qProxy = new StringQuestion(this, "proxy") { 238 @Override 239 public void clear() { 240 setValue(""); 241 } 242 243 @Override 244 public String getText() { 245 return "Proxy settings in format: host:port\nE.g. someproxy.example.com:80"; 246 } 247 248 @Override 249 public String getSummary() { 250 return "Proxy settings"; 251 } 252 253 @Override 254 public Question getNext() { 255 String val = getValue(); 256 if (val == null || val.trim().length() == 0 || CtrUtils.getProxyUrl(val) != null) { 257 return getEnvSuccessorQuestion(); 258 } else { 259 return null; 260 } 261 } 262 263 @Override 264 public void export(Map data) { 265 data.put(PROXY_PARAM_NAME, value); 266 } 267 268 @Override 269 public void load(Map data) { 270 setValue((String) data.get(PROXY_PARAM_NAME)); 271 } 272 }; 273 274 private ChoiceQuestion qPipelineGroup = new PipelineGroupQuestion (this, qProxy); 275 276 277 } 278