exporttestsuite.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 298 行
SVN-BASE
298 行
/* * $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.javatest;import com.sun.javatest.Harness;import com.sun.javatest.TestEnvironment;import com.sun.javatest.TestSuite;import com.sun.javatest.util.I18NResourceBundle;import com.sun.tck.j2me.utils.FileUtils;import java.io.File;import java.io.FileFilter;import java.io.IOException;import java.util.Map;import java.util.logging.Logger;/** * <code>TestSuite</code> class for any test suite supporting the Test Export * feature. */public class ExportTestSuite extends UniversalBaseTestSuite { /** * Creates an <code>ExportTestSuite</code> instance. * * @param root The root file for this test suite. * @param tsInfo Test suite properties, typically read from the test suite * properties file. * @param cl A class loader to be used to load additional classes as * required. * @exception TestSuite.Fault if a problem occurs while creating this test * suite. */ public ExportTestSuite(File root, Map tsInfo, ClassLoader cl) throws Fault { super(root, tsInfo, cl); } /** * Loads test export related environment entries. */ protected void loadParameters(TestEnvironment env) throws Fault { testExportInfo = TestExportInfo.fromEnv(env); super.loadParameters(env); if (isExport()) { /* Override jarSourceDir value set by * CldcTCKBaseTestSuite.loadParameters -- in export mode JAR files * will be stored in location specified by user in interview. */ jarSourceDir = testExportInfo.getExportDirName(); /* * Clear the previous content of export dir and create needed * subdirs. */ prepareExportDirectory(); } } /** * Makes Test Export specific initializations which includes creation of * <code>lib</code> subdirectory of the export directory and copying * there Test Export specific library JAR files defined by * <code>TestExportInfo.getExportLibJars()</code>. * <p> * Invokes the super implementation. */ protected void startRun(Harness harness) throws Fault { if (isExport()) { File libDir = new File(testExportInfo.getExportDirName(), "lib"); try { FileUtils.clearDir(libDir); } catch (IOException e) { throw new Fault(i18n, "ets.ioerror", e.getMessage()); } libDir.mkdirs(); String[] libJars = testExportInfo.getExportLibJars(); for (int i = 0; i < libJars.length; i++) { File srcFile = new File(libJars[i]); try { FileUtils.copyFileToDir(srcFile, libDir, true); } catch (IOException e) { throw new Fault(i18n, "ets.cannotCopyFile", new String[] {srcFile.getPath(), libDir.getPath(), e.getMessage()}); } } } /* * It's important to invoke super.startRun after 'lib' subdirectory * of the export directory is created. Super implementation invokes * TestBundler's initialization. On initialization ExportTestBundler * will try to copy some needed files in 'lib' directory. */ super.startRun(harness); } /** * Prepares the export directory for export. This includes cleaning of * previously exported content (if discovered) and creating all needed * subdirectories. After this method is terminated, all code related * to test export may assume, that the export directory and * its subdirectories exist. * <p> * This method invokes <code>cleanExportDir(File exportDir)</code> and * <code>createExportSubdirs(File exportDir)</code>. * * @exception TestSuite.Fault if an I/O error or any other problem occurs. */ private void prepareExportDirectory() throws TestSuite.Fault { File exportDir = new File(testExportInfo.getExportDirName()); if (exportDir.exists()) { cleanExportDir(exportDir); } else { if (!exportDir.mkdirs()) { throw new TestSuite.Fault(i18n, "ets.cannotCreateExportDir", exportDir.getPath()); } } createExportSubdirs(exportDir); } /** * Creates subdirectories of the export directory needed for test export. * Is invoked from within {@link #prepareExportDirectory()}. Assumes * that the specified directory already exists. * <p> * Creates the following subdirectories in the specified directory: * <ul> * <li>classes</li> * <li>lib</li> * </ul> * * @param exportDir Parent directory, where to create the * subdirectories. * * @exception TestSuite.Fault if failed to create subdirectories. */ private void createExportSubdirs(File exportDir) throws TestSuite.Fault { File[] toCreate = new File[] { new File(exportDir, "classes"), new File(exportDir, "lib") }; for (File dir : toCreate) { if (!dir.mkdirs()) { throw new TestSuite.Fault(i18n, "ets.cannotCreateDir", dir.getPath()); } } } /** * Cleans the export directory from previously exported content which may * conflict with new content. Is invoked from within * {@link #prepareExportDirectory()}. Assumes that the specified * directory exists. * <p> * Deletes the following (if found): * <ul> * <li><i>test*.jad</i> files.</li> * <li><i>test*.jar</i> files.</li> * <li><i>test*.properties</i> files.</li> * <li><i>index.html</i> file.</li> * <li><i>java.policy</i> file.</li> * <li><i>build.xml</i> file.</li> * <li><i>build.properties</i> file.</li> * <li><i>config.jti</i> file.</li> * <li><i>classes</i> directory with all its content.</li> * <li><i>lib</i> directory with all its content.</li> * </ul> * * @param exportDir Directory to be cleaned. * * @exception TestSuite.Fault if failed to delete a file or subdirectory. */ private void cleanExportDir(File exportDir) throws TestSuite.Fault { File[] toDelete = exportDir.listFiles(new FileFilter() { public boolean accept(File file) { String name = file.getName(); return file.isFile() && ( name.endsWith(".jad") && name.startsWith("test") || name.endsWith(".jam") && name.startsWith("test") || name.endsWith(".jar") && name.startsWith("test") || name.endsWith(".properties") && name.startsWith("test") || name.equals(ExportBundler.INDEX_FILE_NAME) || name.equals(MidExportBundler.policyFileName) || name.equals(ExportBundler.BUILD_SCRIPT_FILE_NAME) || name.equals(ExportBundler.BUILD_PROPERTIES_FILE_NAME)); } }); for (File f : toDelete) { if (!f.delete()) { throw new TestSuite.Fault(i18n, "ets.cannotDelete", f.getName()); } } toDelete = new File[] { new File(testExportInfo.getConfigFile()) }; for (File f : toDelete) { if (f.exists() && !f.delete()) { throw new TestSuite.Fault(i18n, "ets.cannotDelete", f.getName()); } } toDelete = exportDir.listFiles(new FileFilter() { public boolean accept(File file) { String name = file.getName(); return file.isDirectory() && ( name.equals("classes") || name.equals("lib") || name.startsWith("test") ); } }); for (File f : toDelete) { try { FileUtils.clearDir(f); } catch (IOException e) { throw new Fault(i18n, "ets.ioerror", e.getMessage()); } if (!f.delete()) { throw new TestSuite.Fault(i18n, "ets.cannotDelete", f.getName()); } } } /** * Triggers test export mode on. * * @deprecated All test export related info should be obtained via a * <code>TestExportInfo</code> instance. No setting is allowed. */ public void setExport(boolean export) { log.config("Setting test export mode: " + export); } /** * Returns a boolean that indicates whether the test export mode is on. * * @return <code>true</code> if test export mode is on, <code>false</code> * otherwise. */ public boolean isExport() { return testExportInfo.isExport(); } /** * Returns a boolean that indicates whether the test suite is configured * for running previously exported test. * * @return <code>true</code> if we are running previously exported tests, * <code>false</code> otherwise. */ public boolean isRunningExportedTests() { return testExportInfo.isRunningExportedTests(); } /** * <code>TestExportInfo</code> instance to be used for obtaining all * information related to test export. */ protected TestExportInfo testExportInfo; private static final Logger log = Logger.getLogger( ExportTestSuite.class.getName()); private static final I18NResourceBundle i18n = I18NResourceBundle.getBundleForClass(ExportTestSuite.class); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?