de.enough.polish.emulator
Class Emulator

java.lang.Object
  extended by de.enough.polish.Extension
      extended by de.enough.polish.emulator.Emulator
All Implemented Interfaces:
OutputFilter, Runnable
Direct Known Subclasses:
AndroidEmulator, BlackBerryEmulator, DoJaEmulator, GenericEmulator, JavaMeSdkEmulator, MicroEmulator, MotorolaEmulator, MppEmulator, PalmEmulator, WtkEmulator

public abstract class Emulator
extends Extension
implements Runnable, OutputFilter

Excutes an emulator.

Copyright Enough Software 2004 - 2011

 history
        04-Sep-2004 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  Device device
           
protected  EmulatorSetting emulatorSetting
           
protected  boolean isFinished
           
 
Fields inherited from class de.enough.polish.Extension
antProject, autoStartCondition, environment, extensionDefinition, extensionManager, extensionSetting, extensionTypeDefinition, isBuildStarted
 
Constructor Summary
Emulator()
          Creates a new emulator instance.
 
Method Summary
protected  void addDebugArguments(ArrayList argsList, Debugger debugger)
          Adds the debugging settings to the arguments list.
static Emulator createEmulator(Device device, EmulatorSetting setting, Environment environment, File[] sourceDirs, ExtensionManager extensionManager)
          Creates the emulator for the given device.
protected  int exec(String[] arguments, String info, boolean wait, OutputFilter filter, File executionDir)
          Executes the actual emulator.
 void execute(Device dev, Locale locale, Environment env)
          Executes this extension.
 void filter(String logMessage, PrintStream output)
          Filters the given message.
abstract  String[] getArguments()
          Retrieves the arguments which are used to start the emulator.
protected  File getExecutionDir()
          Retrieves the directory in which the emulator should be executed.
protected  Variable getParameter(String name, Variable[] parameters)
          Gets a specific parameter
protected  Variable[] getParameters(EmulatorSetting setting, Environment env)
          Gets the parameters for this emulator.
protected  String getParameterValue(String name, Variable[] parameters)
          Gets a specific parameter-value
abstract  boolean init(Device dev, EmulatorSetting setting, Environment env)
          Starts the emulator for the given device.
 boolean isFinished()
          Determines whether this emulator is finished.
 void run()
           
protected  void run(String[] arguments, boolean retryOnError)
           
protected  boolean supportsDebugger(Debugger debugger)
          Defines whether this emulator supports the given debugger.
protected  Variable[] writeProperties(Variable[] variables, Environment properties)
          Writes all properties for the given parameters.
 
Methods inherited from class de.enough.polish.Extension
configure, executeAntTarget, executeAntTarget, finalize, getAntProject, getAutoStartCondition, getEnvironment, getExtensionDefinition, getExtensionSetting, getInstance, getParameterValue, getType, init, initialize, isConditionFulfilled, notifyBuildEnd, notifyBuildStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emulatorSetting

protected EmulatorSetting emulatorSetting

isFinished

protected boolean isFinished

device

protected Device device
Constructor Detail

Emulator

public Emulator()
Creates a new emulator instance. The actual initialisation is done in the init-method.

See Also:
init(Device, EmulatorSetting, Environment)
Method Detail

init

public abstract boolean init(Device dev,
                             EmulatorSetting setting,
                             Environment env)
Starts the emulator for the given device.

Parameters:
dev - the current device
setting - the setting
env - all Ant- and polish-properties for the parameter-values
Returns:
true when an emulator could be detected

getArguments

public abstract String[] getArguments()
Retrieves the arguments which are used to start the emulator.

Returns:
an array with the arguments for starting the emulator.

run

public void run()
Specified by:
run in interface Runnable

run

protected void run(String[] arguments,
                   boolean retryOnError)

addDebugArguments

protected void addDebugArguments(ArrayList argsList,
                                 Debugger debugger)
Adds the debugging settings to the arguments list. By default the UEI arguments -Xdebug and -Xrunjdwp arguments are added by calling debugger.addDebugArguments( List ).

Parameters:
argsList - the arguments list
debugger - the debugger

supportsDebugger

protected boolean supportsDebugger(Debugger debugger)
Defines whether this emulator supports the given debugger. Subclasses can use this for influencing the debugging process.

Returns:
true when the debugger is supported. This defaults to true.

exec

protected int exec(String[] arguments,
                   String info,
                   boolean wait,
                   OutputFilter filter,
                   File executionDir)
            throws IOException
Executes the actual emulator.

Parameters:
arguments - all command line arguments
info - the info block for output messages
wait - true when the current thread should block
filter - the output filter
executionDir - the director for executing the emulator
Returns:
the result code from the emulator
Throws:
IOException - when the emulator process could not be invoked

getExecutionDir

protected File getExecutionDir()
Retrieves the directory in which the emulator should be executed.

Returns:
null when the emulator should be started from the current directory or a file pointing to the actual needed execution dir.

isFinished

public boolean isFinished()
Determines whether this emulator is finished.

Returns:
true when this emulator is finished or when J2ME Polish should not wait for it.

writeProperties

protected Variable[] writeProperties(Variable[] variables,
                                     Environment properties)
Writes all properties for the given parameters.

Parameters:
variables - the input parameters
properties - the map containing all properties
Returns:
an array of parameters with the written properties

getParameters

protected Variable[] getParameters(EmulatorSetting setting,
                                   Environment env)
Gets the parameters for this emulator.

Parameters:
setting - the emulator setting
env - all Ant- and J2ME Polish-properties.
Returns:
an array of initialised parameters.

getParameter

protected Variable getParameter(String name,
                                Variable[] parameters)
Gets a specific parameter

Parameters:
name - the name of the parameter
parameters - all parameters
Returns:
the found parameter or null, when none was found

getParameterValue

protected String getParameterValue(String name,
                                   Variable[] parameters)
Gets a specific parameter-value

Parameters:
name - the name of the parameter
parameters - all parameters
Returns:
the found parameter-value or null, when none was found

createEmulator

public static Emulator createEmulator(Device device,
                                      EmulatorSetting setting,
                                      Environment environment,
                                      File[] sourceDirs,
                                      ExtensionManager extensionManager)
Creates the emulator for the given device.

Parameters:
device - the current device
setting - the configuration for the emulator
environment - the variables for the parameter-values
sourceDirs - the directories containing the original source files.
extensionManager - manager for extensions
Returns:
true when an emulator could be detected

execute

public void execute(Device dev,
                    Locale locale,
                    Environment env)
             throws BuildException
Description copied from class: Extension
Executes this extension. Not all extension types are executed.

Specified by:
execute in class Extension
Parameters:
dev - the current device
locale - the current locale, can be null
env - the environment/configuration
Throws:
BuildException - when the execution failed

filter

public void filter(String logMessage,
                   PrintStream output)
Filters the given message.

Specified by:
filter in interface OutputFilter
Parameters:
logMessage - the message
output - the stream to which the message should be written (if not filtered)