exportinterview.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 243 行
JAVA
243 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.interview;import java.io.File;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import java.util.Map;import com.sun.interview.ChoiceQuestion;import com.sun.interview.DirectoryFileFilter;import com.sun.interview.FileQuestion;import com.sun.interview.FinalQuestion;import com.sun.interview.Interview;import com.sun.interview.NullQuestion;import com.sun.interview.Question;import com.sun.interview.StringQuestion;import com.sun.javatest.InterviewParameters;import com.sun.javatest.interview.BasicInterviewParameters;import com.sun.tck.j2me.interview.util.StringEncoder;import com.sun.tck.j2me.javatest.TestExportInfo;public class ExportInterview extends Interview { /** Creates a new instance of ExportInterview */ public ExportInterview(Interview parent) throws InterviewParameters.Fault { super(parent, "export"); setHelpSet("help/vm"); setResourceBundle("export"); setFirstQuestion(qExportIntro); } /** * Determines whether export mode is on * * @return <code>true</code> if the user explicitly selected test export * mode in the interview, <code>false</code> otherwise. */ boolean isTestExportMode() { // Comparing Strings with '==' is ok here return (qExportMode.getValue() == TestExportInfo.EXPORT_MODE) && !runExportedTest; } boolean isRunnintExportedTests() { // Comparing Strings with '==' is ok here return runExportedTest; } String getExportDir() { return qExportDir.getStringValue(); } private NullQuestion qExportIntro = new NullQuestion(this, "exportIntro") { protected Question getNext() { return qExportMode; } }; private ChoiceQuestion qExportMode = new ChoiceQuestion(this, "exportMode"){ { runExportedTest = System.getProperty("run.exported.test") != null; setChoices(new String[] { TestExportInfo.NOEXPORT_MODE, TestExportInfo.EXPORT_MODE, }, true); setDefaultValue(TestExportInfo.NOEXPORT_MODE); clear(); } protected Question getNext() { // Compare Strings with '==' is ok here if (!runExportedTest && (value == TestExportInfo.EXPORT_MODE)) { return qExportDir; } else { return qEnd; } } protected void export(Map data) { if (runExportedTest) { data.put(TestExportInfo.TEST_EXPORT_MODE_KEY, TestExportInfo.RUN_EXPORTED_TEST_MODE); data.put(TestExportInfo.EXPORTED_TEST_KEY, System.getProperty("run.exported.test")); } else { data.put(TestExportInfo.TEST_EXPORT_MODE_KEY, getStringValue()); // Compare Strings with '==' is ok here if (value == TestExportInfo.EXPORT_MODE) { data.put("agentPreinstalled", "false"); data.put("clientPreinstalled", "false"); if (getParent() instanceof CldcBaseCommInterview) { ((CldcBaseCommInterview) getParent()).exportFinalValues(data); } exportFinalValues(data); } } } }; private FileQuestion qExportDir = new FileQuestion(this, "exportDir") { { setFilter(new DirectoryFileFilter("Export directory")); } /** * Valid response on this question is only an existing directory, * or the value of defaultExportDir variable, which will be known * after the completion of interview. */ public boolean isValueValid() { File file = getValue(); return (file != null) && file.isDirectory(); } protected Question getNext() { return qExportContent; } protected void export(Map data) { File file = getValue(); data.put(TestExportInfo.EXPORT_DIR_KEY, StringEncoder.encode(file.getAbsolutePath())); } }; private StringQuestion qJarURLPrefix = new StringQuestion(this, "jarURLPrefix") { { setDefaultValue("http://localhost:8080/export/"); } protected Question getNext() { return qEnd; } public boolean isValueValid() { try { new URI(getValue()); } catch (URISyntaxException e) { return false; } return true; } protected void export(Map data) { data.put(TestExportInfo.JAR_URL_PREFIX_KEY, getValue()); } }; private ChoiceQuestion qExportContent = new ChoiceQuestion(this, "exportContent") { { setChoices(new String[] { "binaries", "sources", "netbeans" }, true); setDefaultValue(getChoices()[1]); clear(); } protected Question getNext() { return qJarURLPrefix; } protected void export(Map data) { String value = null; if (getValue() == getChoices()[0]) { value = "" + TestExportInfo.EXPORT_BINARIES; } else if (getValue() == getChoices()[1]) { value = "" + TestExportInfo.EXPORT_SOURCES; } else if (getValue() == getChoices()[2]){ value = "" + TestExportInfo.EXPORT_NETBEANS; } data.put(TestExportInfo.CONTENT_TO_EXPORT_KEY, value); } }; private FinalQuestion qEnd = new FinalQuestion(this); private BasicInterviewParameters getBasicInterviewParameters() { Interview i = this; while (i != null && !(i instanceof BasicInterviewParameters)) { i = i.getParent(); } return (BasicInterviewParameters) i; } private void exportFinalValues(Map data) { BasicInterviewParameters params = getBasicInterviewParameters(); data.put(TestExportInfo.COMM_INTERVIEW_TAG_KEY, getParent().getTag() + ".comm"); try { data.put(TestExportInfo.TEST_SUITE_DIR_KEY, StringEncoder.encode( params.getTestSuite().getRootDir().getCanonicalPath())); } catch (IOException e) {} data.put(TestExportInfo.WORK_DIR_KEY, StringEncoder.encode(params.getWorkDirectory().getPath())); // Save configuration .jti file in export directory. File exportDir = qExportDir.getValue(); if (exportDir.exists() || exportDir.mkdirs()) { File exportConfig = new File(exportDir, "config.jti"); try { params.saveAs(exportConfig); } catch (IOException e) { } catch (Interview.Fault fault) {} data.put(TestExportInfo.CONFIG_FILE_KEY, StringEncoder.encode(exportConfig.getPath())); } } private boolean runExportedTest;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?