org.schmant.task.template.jdk.java
Class AbstractExtJavaTask<T extends AbstractExtJavaTask<T>>

java.lang.Object
  extended by org.schmant.support.AbstractArgumentChecker
      extended by org.schmant.task.stub.AbstractTask<T>
          extended by org.schmant.task.template.process.AbstractExtProcessTask<T>
              extended by org.schmant.task.template.jdk.java.AbstractExtJvmTask<T>
                  extended by org.schmant.task.template.jdk.java.AbstractExtJavaTask<T>
All Implemented Interfaces:
TaskDependency, LoggingConfigurable<T>, Task, TaskRunnable, TaskSpecification<T>, ExtProcessConfigured, ExtProcessTask<T>
Direct Known Subclasses:
ExtJavaTask, ExtJUnit4Task

public abstract class AbstractExtJavaTask<T extends AbstractExtJavaTask<T>>
extends AbstractExtJvmTask<T>

This is an abstract base class for tasks that run a Java program in an external process.

Since:
0.5
Author:
Karl Gustafsson

Constructor Summary
AbstractExtJavaTask()
           
 
Method Summary
protected  void addArgumentsToCommandList(ArgumentList al)
          Override to add decorator arguments.
protected  void addTaskSpecificJvmArguments(ArgumentList al)
          This is a callback method that can be overridden by subclasses to add their own JVM options.
 void copyProperties(T spec)
          Copy the properties to the target object.
protected  List<Object> getClasspathEntriesFromPathDecorators()
          Get a list of classpath entries from the task factory's registered PathDecorator objects.
protected  List<ExtJavaTaskDecorator<?>> getDecorators()
           
 File getFallbackJavaExecutable()
          Get the fallback Java executable that is used if no executable is set.
protected  JavaVMType getJavaVMType()
           
protected  Collection<?> getTaskSpecificClasspathEntries()
          This is a callback method that can be overridden by subclasses to add their own classpath entries.
protected  Boolean isAssertions()
           
protected  ArgumentList prepareArgumentList(Report r)
          Prepare the command line string up to the point where the Java class to be run (or more JVM arguments) should be added.
protected  Collection<String> validate(Report r)
          This method may be overridden by subclasses to validate their configuration (including their TaskFactory:s) before the task is run.
 
Methods inherited from class org.schmant.task.template.jdk.java.AbstractExtJvmTask
getClasspathDecorators, getClasspathEntries, getJavaExecutable, getJavaHome, getJvmOptions
 
Methods inherited from class org.schmant.task.template.process.AbstractExtProcessTask
execAndWait, getArguments, getEnvironmentVariables, getProcessResult, getStderrStrategy, getStdoutStrategy, getWorkingDirectory, isFailOnErrors, isInheritEnvironmentVariables
 
Methods inherited from class org.schmant.task.stub.AbstractTask
cancel, createTask, getDefaultLogFooter, getDefaultLogHeader, getDependencyForTasksScheduledByThisTask, getDependencyObservable, getFailureCause, getLogFooter, getLogHeader, getSatisfiedStateLock, getThis, isCancelled, isDone, isInterrupted, isRunning, isSatisfied, isSuccessful, run, runInternal, setLogFooter, setLogHeader, setReportLevel, setTraceLogging, toString
 
Methods inherited from class org.schmant.support.AbstractArgumentChecker
check, check, check, check
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.schmant.task.Task
cancel, getDependencyForTasksScheduledByThisTask, getFailureCause, isCancelled, isDone, isInterrupted, isRunning, isSuccessful
 
Methods inherited from interface org.schmant.run.TaskDependency
getDependencyObservable, getSatisfiedStateLock, isSatisfied
 
Methods inherited from interface org.schmant.task.TaskRunnable
run
 

Constructor Detail

AbstractExtJavaTask

public AbstractExtJavaTask()
Method Detail

isAssertions

protected final Boolean isAssertions()

getJavaVMType

protected final JavaVMType getJavaVMType()

getDecorators

protected final List<ExtJavaTaskDecorator<?>> getDecorators()

getFallbackJavaExecutable

public File getFallbackJavaExecutable()
Get the fallback Java executable that is used if no executable is set. First check if the javaHome property is set and try to get the java[.exe] executable from that. If it is not set, search the directories referenced by the JAVA_HOME or PATH environment variables are searched (in that order), and the first java[.exe] executable found is returned.

Returns:
The Java executable that will be used.
Throws:
InvalidTaskConfigurationException - If no Java executable is set and none can be found.

getTaskSpecificClasspathEntries

protected Collection<?> getTaskSpecificClasspathEntries()
This is a callback method that can be overridden by subclasses to add their own classpath entries. The classpath entries are added at the end of the classpath.

The default implementation is empty.

Returns:
Task-specific classpath entries.

addTaskSpecificJvmArguments

protected void addTaskSpecificJvmArguments(ArgumentList al)
This is a callback method that can be overridden by subclasses to add their own JVM options. This implementation is empty.

Parameters:
al - The command line to add options to.

getClasspathEntriesFromPathDecorators

protected List<Object> getClasspathEntriesFromPathDecorators()
Get a list of classpath entries from the task factory's registered PathDecorator objects.

Returns:
A list of classpath entries, possibly empty but never null.

prepareArgumentList

protected ArgumentList prepareArgumentList(Report r)
Prepare the command line string up to the point where the Java class to be run (or more JVM arguments) should be added.

Returns:
A list of command and arguments that the task implementation can extend with task-specific arguments.

addArgumentsToCommandList

protected void addArgumentsToCommandList(ArgumentList al)
Override to add decorator arguments.

Overrides:
addArgumentsToCommandList in class AbstractExtProcessTask<T extends AbstractExtJavaTask<T>>
Parameters:
al - The list of program arguments. Modified by this call.

validate

protected Collection<String> validate(Report r)
Description copied from class: AbstractTask
This method may be overridden by subclasses to validate their configuration (including their TaskFactory:s) before the task is run.

Validation errors are collected as strings. If this method is overridden, always call super.validate.

Overrides:
validate in class AbstractTask<T extends AbstractExtJavaTask<T>>
Parameters:
r - A report to log warning and debug messages to. Validation errors should not be logged, though. They are logged later.
Returns:
A collection of error messages.

copyProperties

public void copyProperties(T spec)
Description copied from class: AbstractTask
Copy the properties to the target object.

Subclasses must override this to copy their properties. The overriding method must call super.copyProperties.

Specified by:
copyProperties in interface TaskSpecification<T extends AbstractExtJavaTask<T>>
Overrides:
copyProperties in class AbstractExtJvmTask<T extends AbstractExtJavaTask<T>>
Parameters:
spec - The specification to copy properties to.