com.sun.javatest
public abstract class Script extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Script.TimeoutProvider
Interface for extended testTimeout control.
|
Modifier and Type | Field and Description |
---|---|
protected static Timer |
alarmTimer
A timer that may be used to set up timeouts.
|
protected BackupPolicy |
backupPolicy
A backup policy object that specifies how files should be backed up,
if a file is found to exist when a new one of the same name is to be
written.
|
protected java.lang.String |
cmdOut1Name
The default name for the TestResult section used to save the data written to the out1 stream
for a command.
|
protected java.lang.String |
cmdOut2Name
The default name for the TestResult section used to save the data written to the out2 stream
for a command.
|
protected TestEnvironment |
env
The test environment for the test being performed.
|
protected static Status |
error_badExecuteArgs
A status that may be used to indicate problems in the executeArgs field
of a test description.
|
protected static Status |
error_badTestClassDir
A status that may be used to indicate a problem with a test's class directory.
|
protected static Status |
error_compFailUnexp
A status that may be used to indicate that a compilation failed unexpectedly.
|
protected static Status |
error_noActionSpecified
A status that may be used to indicate that no action was specified.
|
protected static Status |
error_noExecuteClass
A status that may be used to indicate that no execute class was specified in a test description.
|
protected static Status |
error_noExtnInSource
A status that may be used to indicate that no extension was found in a source file.
|
protected static Status |
error_noRMIClasses
A status that may be used to indicate that no rmi classes were specified in a test description.
|
protected static Status |
error_noSource
A status that may be used to indicate that no sources were specified in a test description.
|
protected java.lang.String[] |
excludedTestCases
The set of test cases to be excluded for this test.
|
protected static Status |
fail_compFailUnexp
A status that may be used to indicate the a compilation failed unexpectedly.
|
protected static Status |
fail_compSuccUnexp
A status that may be used to indicate that a compilation did not fail as was expected.
|
protected static Status |
fail_execSuccUnexp
A status that may be used to indicate that a test execution step did not fail as wqas expected.
|
protected java.lang.ClassLoader |
loader
The class loader to be used to load additional user-specified classes
as required in the execution of the script.
|
protected static Status |
noExtnInSource
A status that may be used to indicate that no extension was found in a source file.
|
protected static Status |
noSource
A status that may be used to indicate that no source files were found in the test description.
|
protected Harness.Observer |
notifier
Notifier of starting/finishing tests.
|
protected static Status |
pass_compFailExp
A status that may be used to indicate that a compilation failed as expected.
|
protected static Status |
pass_compSuccExp
A status that may be used to indicate that a compilation succeeded as expected.
|
protected static Status |
pass_execFailExp
A status that may be used to indicate that an execution step failed, as was expected.
|
protected java.lang.String[] |
scriptArgs
The initialization args for the script.
|
protected TestDescription |
td
The test description for the test being performed.
|
protected java.io.PrintWriter |
trOut
The reporting channel for the test being performed.
|
protected WorkDirectory |
workDir
The work directory for the test run.
|
Constructor and Description |
---|
Script() |
Modifier and Type | Method and Description |
---|---|
protected Status |
compileIfNecessary(java.io.File[] srcs,
java.lang.String classDir)
Compile those source files for which the corresponding class file appears to
be out of date.
|
protected Status |
compileIfNecessary(java.lang.String[] srcs,
java.lang.String classDir)
Compile those source files for which the corresponding class file appears to
be out of date.
|
protected Status |
compileIfNecessary(java.lang.String command,
java.io.File[] srcs,
java.lang.String classDir)
Compile those source files for which the corresponding class file appears to
be out of date.
|
protected Status |
compileIfNecessary(java.lang.String command,
java.lang.String[] srcs,
java.lang.String classDir)
Compile those source files for which the corresponding class file appears to
be out of date.
|
protected Status |
compileIndividually(java.io.File[] srcs)
Compile the given source files individually.
|
protected Status |
compileIndividually(java.lang.String[] srcs)
Compile the given source files individually.
|
protected Status |
compileIndividually(java.lang.String command,
java.io.File[] srcs)
Compile the given source files individually.
|
protected Status |
compileIndividually(java.lang.String command,
java.lang.String[] srcs)
Compile the given source files individually.
|
protected Status |
compileOne(java.io.File src)
Compiles the given source file.
|
protected Status |
compileOne(java.lang.String src)
Compile the given source file.
|
protected Status |
compileOne(java.lang.String command,
java.io.File src)
Compiles the given source file.
|
protected Status |
compileOne(java.lang.String command,
java.lang.String src)
Compile the given source file.
|
protected Status |
compileTogether(java.io.File[] srcs)
Compile the given source files together.
|
protected Status |
compileTogether(java.lang.String[] srcs)
Compile the given source files together.
|
protected Status |
compileTogether(java.lang.String command,
java.io.File[] srcs)
Compile the given source files together.
|
protected Status |
compileTogether(java.lang.String command,
java.lang.String[] srcs)
Compile the given source files together.
|
protected java.lang.String[] |
exclude(java.lang.String[] args,
java.lang.String[] testCases)
Modify the args for a test to be executed, according to a set
of test cases to be excluded.
|
protected Status |
execute(java.lang.String executeClass,
java.lang.String executeArgs)
Execute the given class with the given arguments, which need to be passed
to the environment for $ substitution and for splitting into separate strings.
|
protected Status |
execute(java.lang.String executeClass,
java.lang.String[] executeArgs)
Execute the given class with the given arguments.
|
protected Status |
execute(java.lang.String command,
java.lang.String executeClass,
java.lang.String executeArgs)
Execute the given class with the given arguments, which need to be passed
to the environment for $ substitution and for splitting into separate strings.
|
protected Status |
execute(java.lang.String command,
java.lang.String executeClass,
java.lang.String[] executeArgs)
Execute the given class with the given arguments.
|
protected static java.lang.String[] |
filesToStrings(java.io.File[] files)
Utility routine to convert an array of filenames to a corresponding
array of strings.
|
boolean |
getJTRIfPassed()
Get the flag that indicates whether a result (.jtr) file should be written
even if the test has passed.
|
TestDescription |
getTestDescription()
Get the test description for the test which this script will run.
|
TestResult |
getTestResult()
Get the test result object to be used for the results of the test run.
|
protected int |
getTestTimeout()
Get the timeout to be used for a test.
|
Script.TimeoutProvider |
getTimeoutProvider()
Getter for TimeoutProvider.
|
void |
initArgs(java.lang.String[] args)
Initialize any custom args for the script.
|
void |
initBackupPolicy(BackupPolicy backupPolicy)
Initialize the backup policy to be used when creating a test result
file in which to store the results of running this test.
|
void |
initClassLoader(java.lang.ClassLoader loader)
Initialize the class loader for any commands to be loaded.
|
protected void |
initDelegate(Script s,
java.lang.String[] scriptArgs)
Initialize a delegate script object.
|
void |
initExcludedTestCases(java.lang.String[] excludedTestCases)
Initialize the list of test cases to be excluded from the test.
|
void |
initTestDescription(TestDescription td)
Initialize the test description to be run by the script.
|
void |
initTestEnvironment(TestEnvironment env)
Initialize the environment to be used when running the test.
|
protected void |
initTestResult(TestResult tr)
Initialize the test result for the result of the script execution.
|
void |
initWorkDir(WorkDirectory workDir)
Initialize the work directory to be used to store the results
obtained when running the test,
and to store any temporary files that may be required by the test.
|
protected Status |
invokeCommand(java.lang.String key)
Invoke a command in the environment identified by a given key.
|
protected Status |
rmiCompile(java.lang.String[] classes)
RMI Compile the given class files.
|
protected Status |
rmiCompile(java.lang.String command,
java.lang.String[] classes)
RMI Compile the given class files.
|
void |
run()
Run the script, to fill out the test results for the test description
given to
init . |
abstract Status |
run(java.lang.String[] args,
TestDescription td,
TestEnvironment env)
The primary method to be provided by Scripts.
|
protected void |
setAlarm(int timeout)
Set an alarm that will interrupt the calling thread after
a specified delay (in milliseconds), and repeatedly thereafter
until cancelled.
|
protected void |
setAlarm(int timeout,
java.lang.Thread threadToInterrupt)
Set an alarm that will interrupt a given thread after
a specified delay (in milliseconds), and repeatedly thereafter
until cancelled.
|
protected void |
setDefaultCommandStreamNames(java.lang.String out1Name,
java.lang.String out2Name)
Set the default names of the two default output streams used when executing a
command.
|
void |
setJTRIfPassed(boolean b)
Set the flag that indicates whether a result (.jtr) file should be written
even if the test has passed.
|
void |
setNotifier(Harness.Observer notifier)
Sets notifier to be used to inform listeners of events of a test
starting/finishing.
|
void |
setTimeoutProvider(Script.TimeoutProvider provider)
Set TimeoutProvider used to control test timeouts.
|
boolean |
useNotifier()
Returns true if the Script uses own way of notifying the Harness
of starting/finishing test, false otherwise (by default).
|
protected TestDescription td
protected java.lang.String[] excludedTestCases
protected TestEnvironment env
protected java.lang.String[] scriptArgs
protected WorkDirectory workDir
protected java.lang.String cmdOut1Name
protected java.lang.String cmdOut2Name
protected BackupPolicy backupPolicy
protected java.lang.ClassLoader loader
protected java.io.PrintWriter trOut
protected static final Status error_badExecuteArgs
protected static final Status error_badTestClassDir
protected static final Status error_compFailUnexp
protected static final Status error_noActionSpecified
protected static final Status error_noExecuteClass
protected static final Status error_noExtnInSource
protected static final Status error_noRMIClasses
protected static final Status error_noSource
protected static final Status fail_compFailUnexp
protected static final Status fail_compSuccUnexp
protected static final Status fail_execSuccUnexp
protected static final Status pass_compFailExp
protected static final Status pass_compSuccExp
protected static final Status pass_execFailExp
protected static final Status noSource
protected static final Status noExtnInSource
protected static Timer alarmTimer
protected Harness.Observer notifier
useNotifier()
,
setNotifier(com.sun.javatest.Harness.Observer)
public void initArgs(java.lang.String[] args)
args
- custom args for the scriptpublic void initTestDescription(TestDescription td)
td
- the test description for the test to be runpublic void initExcludedTestCases(java.lang.String[] excludedTestCases)
excludedTestCases
- a list of test cases within the test that
should not be runpublic void initTestEnvironment(TestEnvironment env)
env
- the environment to be used when running the testpublic void initWorkDir(WorkDirectory workDir)
workDir
- the work directory to be used to store the test's results.public void initBackupPolicy(BackupPolicy backupPolicy)
backupPolicy
- A backup policy object to be used when
creating test result files.public void initClassLoader(java.lang.ClassLoader loader)
loader
- a class loader to be used to load any commands or other
user-specified classes that may be required.protected void initDelegate(Script s, java.lang.String[] scriptArgs)
s
- The delegate to be initializedscriptArgs
- the arguments to be passed to the delegate objectprotected void initTestResult(TestResult tr)
tr
- The test result to set as the result of the script's execution.java.lang.IllegalStateException
- if the test result has already been set.initTestDescription(com.sun.javatest.TestDescription)
public void run()
init
. Most implementations will use the default
implementation of this method, which delegates to a simpler (abstract)
method @link(run(String[],TestDescription, TestEnvironment))public abstract Status run(java.lang.String[] args, TestDescription td, TestEnvironment env)
args
- Any script-specific options specified in the script propertytd
- The test description for the test to be performedenv
- The test environment giving the details of how to run the testcompileIndividually(java.lang.String[])
,
compileTogether(java.lang.String[])
,
execute(java.lang.String, java.lang.String)
,
invokeCommand(java.lang.String)
public TestDescription getTestDescription()
public TestResult getTestResult()
public boolean getJTRIfPassed()
setJTRIfPassed(boolean)
public void setJTRIfPassed(boolean b)
b
- the flag that indicates whether a result (.jtr) file should be written
even if the test has passed.getJTRIfPassed()
protected void setAlarm(int timeout)
try { setAlarm(delay); ... } finally { setAlarm(0); }
timeout
- the interval (in milliseconds) after which the calling
thread will be interrupted, if not cancelled in the meantime.protected void setAlarm(int timeout, java.lang.Thread threadToInterrupt)
try { setAlarm(delay); ... } finally { setAlarm(0); }
timeout
- the interval (in milliseconds) after which the calling
thread will be interrupted, if not cancelled in the meantime.threadToInterrupt
- which thread to interruptpublic void setTimeoutProvider(Script.TimeoutProvider provider)
provider
- null to use default test timeout value (10 sec).Script.TimeoutProvider
,
getTestTimeout()
,
getTimeoutProvider()
public Script.TimeoutProvider getTimeoutProvider()
setTimeoutProvider(com.sun.javatest.Script.TimeoutProvider)
,
getTestTimeout()
,
Script.TimeoutProvider
protected int getTestTimeout()
getTimeoutProvider()
,
setTimeoutProvider(com.sun.javatest.Script.TimeoutProvider)
,
Script.TimeoutProvider
protected Status compileIndividually(java.lang.String[] srcs)
srcs
- The names of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileIndividually(java.lang.String command, java.lang.String[] srcs)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileIndividually(java.io.File[] srcs)
srcs
- The names of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileIndividually(java.lang.String command, java.io.File[] srcs)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileOne(java.lang.String src)
src
- The name of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileOne(java.lang.String command, java.lang.String src)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrc
- The name of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileOne(java.io.File src)
src
- The name of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileOne(java.lang.String command, java.io.File src)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrc
- The name of the file to be compiled.compileTogether(java.lang.String[])
protected Status compileTogether(java.lang.String[] srcs)
env.env.compile.extn.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI, and extn is
the extension of the first source file. The names of the files to be compiled
are added to the end of the arguments retrieved from the environment.srcs
- The names of the file to be compiled.invokeCommand(java.lang.String)
protected Status compileTogether(java.lang.String command, java.lang.String[] srcs)
env.env.command.command.extn.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI, and extn is
the extension of the first source file. The names of the files to be compiled
are added to the end of the arguments retrieved from the environment.command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the file to be compiled.invokeCommand(java.lang.String)
protected Status compileTogether(java.io.File[] srcs)
env.env.command.compile.extn.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI, and extn is
the extension of the first source file. The names of the files to be compiled
are added to the end of the arguments retrieved from the environment.srcs
- The names of the file to be compiled.invokeCommand(java.lang.String)
protected Status compileTogether(java.lang.String command, java.io.File[] srcs)
env.env.command.command.extn.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI, and extn is
the extension of the first source file. The names of the files to be compiled
are added to the end of the arguments retrieved from the environment.command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the file to be compiled.invokeCommand(java.lang.String)
protected Status compileIfNecessary(java.lang.String[] srcs, java.lang.String classDir)
srcs
- The names of the source files to be compiled if necessaryclassDir
- The class directory in which the corresponding class files
(if any) will be found.compileTogether(java.lang.String[])
protected Status compileIfNecessary(java.lang.String command, java.lang.String[] srcs, java.lang.String classDir)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the source files to be compiled if necessaryclassDir
- The class directory in which the corresponding class files
(if any) will be found.compileTogether(java.lang.String[])
protected Status compileIfNecessary(java.io.File[] srcs, java.lang.String classDir)
srcs
- The names of the source files to be compiled if necessaryclassDir
- The class directory in which the corresponding class files
(if any) will be found.compileTogether(java.lang.String[])
protected Status compileIfNecessary(java.lang.String command, java.io.File[] srcs, java.lang.String classDir)
command
- the base name of the command entry in the environment to be used
to compile any necessary sources. The complete entry name will be
command.
command.
extnsrcs
- The names of the source files to be compiled if necessaryclassDir
- The class directory in which the corresponding class files
(if any) will be found.compileTogether(java.lang.String[])
protected Status execute(java.lang.String executeClass, java.lang.String executeArgs)
executeClass
- The name of the class to be executedexecuteArgs
- The arguments to be evaluated before passing to
the class to be executedexecute(java.lang.String, java.lang.String, java.lang.String)
protected Status execute(java.lang.String command, java.lang.String executeClass, java.lang.String executeArgs)
command
- The name of the command containing the template to be executedexecuteClass
- The name of the class to be executedexecuteArgs
- The arguments to be evaluated before passing to
the class to be executedprotected Status execute(java.lang.String executeClass, java.lang.String[] executeArgs)
env.env.execute.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI. The class to be executed and
its arguments are added to the end of the arguments retrieved from the environment.executeClass
- The name of the class to be executed.executeArgs
- Any arguments to be passed to the class to be executed.execute(java.lang.String, java.lang.String, java.lang.String[])
protected Status execute(java.lang.String command, java.lang.String executeClass, java.lang.String[] executeArgs)
env.env.command.*
'
properties in the script's environment, where env
is the name of the environment specified to the GUI. The class to be executed and
its arguments are added to the end of the arguments retrieved from the environment.command
- The name of the command containing the template to be executedexecuteClass
- The name of the class to be executed.executeArgs
- Any arguments to be passed to the class to be executed.invokeCommand(java.lang.String)
protected Status rmiCompile(java.lang.String[] classes)
env.env.command.rmic
'
property in the script's environment, where env
is the name of the environment specified to the GUI.
The name of the classes to be compiled by rmic is obtained from the
test description.classes
- The names of the classes to be compiled by rmic.invokeCommand(java.lang.String)
protected Status rmiCompile(java.lang.String command, java.lang.String[] classes)
env.env.command.command
'
property in the script's environment, where env
is the name of the environment specified to the GUI.
The name of the classes to be compiled by rmic is obtained from the
test description.command
- The name of the command containing the template to be compiledclasses
- The names of the classes to be compiled by rmic.invokeCommand(java.lang.String)
protected Status invokeCommand(java.lang.String key)
command.key
'
property in the environment. The first word of this property identifies
the name of a class that should be an implementation of Command
,
and the subsequent words are the arguments to be passed to a fresh instance
of that class, via its run
method.
Standard library implementations of Command
are available,
such as:
The use of `command.key
' supercedes an earlier
mechanism involving multiple properties. For backwards compatibility,
if the `command.key
' property is not found, the
properties for the earlier mechanism are checked as well.
key
- The tag for the command to be executedCommand
protected void setDefaultCommandStreamNames(java.lang.String out1Name, java.lang.String out2Name)
out1Name
- Name of the first stream.out2Name
- Name of the second stream.protected java.lang.String[] exclude(java.lang.String[] args, java.lang.String[] testCases)
args
- The basic list of args for the testtestCases
- the set of test cases to be excluded, or null if noneprotected static java.lang.String[] filesToStrings(java.io.File[] files)
files
- The filenames to be convertedpublic boolean useNotifier()
true
. In this case the notifier field will
be initialized and the Harness will no longer notify the listeners when
a test starts/stops.public void setNotifier(Harness.Observer notifier)
useNotifier()
Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.