Class CommandContext

    • Constructor Detail

      • CommandContext

        public CommandContext()
        Create a new context object. The output stream, used by the printXXX methods, is set to System.err.
      • CommandContext

        public CommandContext​(java.io.PrintWriter out)
        Create a new context object, using a specified PrintWriter for the output stream, used by the printXXX methods.
        Parameters:
        out - the output stream to be used by the printXXX methods.
    • Method Detail

      • addCommand

        public void addCommand​(Command cmd)
        Add a new command to the set of commands to be executed by this object.
        Parameters:
        cmd - The command to be added
        See Also:
        runCommands()
      • runCommands

        public void runCommands()
                         throws CommandContext.Fault
        Run the set of commands that have been registered with this object. If none of the commands executed are action commands, and if an "auto-run" command has been registered, it will be executed after all the other commands have been executed.
        Throws:
        CommandContext.Fault - if any of the commands executed throw Command.Fault
      • addHarnessObserver

        public void addHarnessObserver​(Harness.Observer o)
        Add an observer to the set of observers maintained by this object.
        Parameters:
        o - the observer to be added
        See Also:
        getHarnessObservers()
      • getAutoRunCommand

        public Command getAutoRunCommand()
        Get the "auto run" command registered with this object. If not null, this command will be executed after the other commands executed by this object, and if none of those commands are action commands.
        Returns:
        the "auto run" command registered with this object
        See Also:
        setAutoRunCommand(com.sun.javatest.tool.Command), runCommands()
      • setAutoRunCommand

        public void setAutoRunCommand​(Command c)
        Set the "auto run" command registered with this object. If not null, this command will be executed after the other commands executed by this object, and if none of those commands are action commands.
        Parameters:
        c - the "auto run" command to be registered with this object
        See Also:
        getAutoRunCommand(), runCommands()
      • getAutoRunReportDir

        public java.io.File getAutoRunReportDir()
        Get the "auto run report directory" registered with this object. This is primarily to support backwards compatibility with JT Harness 2.x behavior.
        Returns:
        the "auto run report directory" registered with this object
        See Also:
        setAutoRunReportDir(java.io.File)
      • setAutoRunReportDir

        public void setAutoRunReportDir​(java.io.File dir)
        Set the "auto run report directory" registered with this object. This is primarily to support backwards compatibility with JT Harness 2.x behavior.
        Parameters:
        dir - the "auto run report directory" to be registered with this object
        See Also:
        getAutoRunReportDir()
      • addTestStats

        public void addTestStats​(int[] stats)
        Add test run statistics into the cumulative counts.
        Parameters:
        stats - an array of test counts, indexed by the standard Status.XXX values.
      • getTestStats

        public int[] getTestStats()
        Get the cumulative test run statistics.
        Returns:
        an array of test counts, indexed by the standard Status.XXX values.
      • isCloseDesktopWhenDoneEnabled

        public boolean isCloseDesktopWhenDoneEnabled()
        Check whether this object indicates that the desktop should be closed when all commands are done.
        Returns:
        true if this object indicates that the desktop should be closed when all commands are done, and false otherwise
        See Also:
        setCloseDesktopWhenDoneEnabled(boolean)
      • setCloseDesktopWhenDoneEnabled

        public void setCloseDesktopWhenDoneEnabled​(boolean b)
        Specify whether this object should remember that the desktop should be closed when all commands are done.
        Parameters:
        b - true if this object should remember that the desktop should be closed when all commands are done, and false otherwise
        See Also:
        isCloseDesktopWhenDoneEnabled()
      • isTestSuiteSet

        public boolean isTestSuiteSet()
        Check whether the test suite has been set yet.
        Returns:
        true if the test suite has been set, and false otherwise
      • setTestSuite

        public void setTestSuite​(java.io.File path)
                          throws CommandContext.Fault
        Set the path for the test suite to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the work directory and configuration file.
        Parameters:
        path - the path for the test suite to be associated with this object
        Throws:
        CommandContext.Fault - if the test suite has already ben set
        See Also:
        getTestSuite()
      • setTestSuite

        public void setTestSuite​(TestSuite ts)
                          throws CommandContext.Fault,
                                 TestSuite.Fault
        Set the test suite to be associated with this object.
        Parameters:
        ts - the test suite to be associated with this object
        Throws:
        CommandContext.Fault - if the test suite has already been set to something else, or if there is a problem evaluating related parameters, such as a configuration file or template, or a work directory.
        TestSuite.Fault - if there is a problem evaluating related parameters.
        See Also:
        getTestSuite()
      • isWorkDirectorySet

        public boolean isWorkDirectorySet()
        Check whether the work directory has been set yet.
        Returns:
        true if the work directory has been set, and false otherwise
      • setWorkDirectory

        public void setWorkDirectory​(java.io.File path)
                              throws CommandContext.Fault
        Set the path for the work directory to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and configuration file. The path must identify a work directory that already exists.
        Parameters:
        path - the path for the work directory to be associated with this object
        Throws:
        CommandContext.Fault - if the work directory has already been set
        See Also:
        getWorkDirectory()
      • setWorkDirectory

        public void setWorkDirectory​(java.io.File path,
                                     boolean create)
                              throws CommandContext.Fault
        Set the path for the work directory to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and configuration file. The work directory identified by this path may be created if necessary.
        Parameters:
        path - the path for the work directory to be associated with this object
        create - create the work directory if it does not already exist
        Throws:
        CommandContext.Fault - if the work directory has already been set
        See Also:
        getWorkDirectory()
      • hasConfig

        public boolean hasConfig()
        Check whether a configuration has been set yet.
        Returns:
        true if a configuration has been set, and false otherwise
      • setConfig

        public void setConfig​(java.io.File path)
                       throws CommandContext.Fault
        Set the path for the configuration information to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and work directory.
        Parameters:
        path - the path for the configuration information to be associated with this object.
        Throws:
        CommandContext.Fault - if the configuration has already been evaluated
        See Also:
        getConfig()
      • isDesktopRequired

        public boolean isDesktopRequired()
        Check if a desktop is required by the commands registered with this object. A desktop is not required if and only if one or more commands have a desktop mode of "desktop not required", and none have a mode of "desktop required". In other words, "desktop not required" wins over "default", but "desktop required" wins over "desktop not required".
        Returns:
        whether or not a desktop is required by the commands registered with this object
      • setDesktop

        public void setDesktop​(Desktop d)
        Set the desktop associated with this object.
        Parameters:
        d - the desktop to be associated with this object
        Throws:
        java.lang.NullPointerException - if the argument is null
        See Also:
        getDesktop()
      • setVerboseMax

        public void setVerboseMax​(boolean on)
        Specify whether or not to override the setting of all other verbose options to true.
        Parameters:
        on - If true, the value of all other verbose options will be given as true.
      • setVerboseQuiet

        public void setVerboseQuiet​(boolean on)
        Specify whether or not to override the setting of all other verbose options to false.
        Parameters:
        on - If true, the value of all other verbose options will be given as false.
      • isVerboseQuiet

        public boolean isVerboseQuiet()
        Should all verbose output be quieted. This generally overrides any other requests for verbosity.
        Returns:
        True if verboseness should be quieted.
      • setVerboseTimestampEnabled

        public void setVerboseTimestampEnabled​(boolean on)
        Configure whether timestamps are printed with verbose output.
        Parameters:
        on - False for no timestamps.
      • setVerboseOptionValue

        public void setVerboseOptionValue​(java.lang.String name,
                                          boolean on)
        Specify the value of a verbose option.
        Parameters:
        name - the name of the verbose option
        on - the value of the verbose option
        See Also:
        getVerboseOptionValue(java.lang.String)
      • getVerboseOptionValue

        public boolean getVerboseOptionValue​(java.lang.String name)
        Get the value of a verbose option. If the max verbose flag has been set to true, the result will be true. Otherwise, if the quiet verbose flag, the result will be false. Otherwise, if the value has been set with setVerboseOptionValue, the result will be the value that was set Otherwise the result will be false.
        Parameters:
        name - the name of the verbose option
        Returns:
        the value of the named option
        See Also:
        setVerboseOptionValue(java.lang.String, boolean)
      • getVerboseOptionValue

        public boolean getVerboseOptionValue​(java.lang.String name,
                                             boolean defaultValue)
        Get the value of a verbose option. If the max verbose flag has been set to true, the result will be true. Otherwise, if the quiet verbose flag, the result will be false. Otherwise, if the value has been set with setVerboseOptionValue, the result will be the value that was set Otherwise the result will be specified default value.
        Parameters:
        name - the name of the verbose option
        defaultValue - the default value to be used if necessary
        Returns:
        the value of the named option
        See Also:
        setVerboseOptionValue(java.lang.String, boolean)
      • isVerboseOptionSet

        public boolean isVerboseOptionSet​(java.lang.String name)
        Check if a verbose option has been set explicitly with setVerboseOptionValue.
        Parameters:
        name - the name of the option to be checked
        Returns:
        true if the option has a value that has been explicitly set, and false otherwise
      • isVerboseTimestampEnabled

        public boolean isVerboseTimestampEnabled()
        Check whether timestamps should be printed with verbose output.
        Returns:
        False for no timestamps.
        See Also:
        setVerboseTimestampEnabled(boolean)
      • setLogWriter

        public void setLogWriter​(java.io.PrintWriter out)
        Set the log stream associated with this object.
        Parameters:
        out - the log stream to be associated with this object
        See Also:
        getLogWriter()
      • getLogWriter

        public java.io.PrintWriter getLogWriter()
        Get the log stream associated with this object.
        Returns:
        the log stream associated with this object
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printMessage

        public void printMessage​(I18NResourceBundle i18n,
                                 java.lang.String key)
        Write a message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printMessage

        public void printMessage​(I18NResourceBundle i18n,
                                 java.lang.String key,
                                 java.lang.Object arg)
        Write a message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        arg - an argument to be formatted into the localized message
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printMessage

        public void printMessage​(I18NResourceBundle i18n,
                                 java.lang.String key,
                                 java.lang.Object[] args)
        Write a message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        args - an array of arguments to be formatted into the localized message
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printErrorMessage

        public void printErrorMessage​(I18NResourceBundle i18n,
                                      java.lang.String key)
        Write an error message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printErrorMessage

        public void printErrorMessage​(I18NResourceBundle i18n,
                                      java.lang.String key,
                                      java.lang.Object arg)
        Write an error message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        arg - an argument to be formatted into the localized message
        See Also:
        setLogWriter(java.io.PrintWriter)
      • printErrorMessage

        public void printErrorMessage​(I18NResourceBundle i18n,
                                      java.lang.String key,
                                      java.lang.Object[] args)
        Write an error message to the log stream associated with this object.
        Parameters:
        i18n - the resource bundle containing the localized text of the message
        key - the key for the required message in the bundle
        args - an array of arguments to be formatted into the localized message
        See Also:
        setLogWriter(java.io.PrintWriter)
      • dispose

        public void dispose()