JspC (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs.optional.jsp, class: JspC

# Class JspC

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.MatchingTask
org.apache.tools.ant.taskdefs.optional.jsp.JspC

All Implemented Interfaces:
  `Cloneable, SelectorContainer`

public class JspC extends MatchingTask
Runs a JSP compiler.

This task takes the given jsp files and compiles them into java files. It is then up to the user to compile the java files into classes.

The task requires the srcdir and destdir attributes to be set. This Task is a MatchingTask, so the files to be compiled can be specified using includes/excludes attributes or nested include/exclude elements. Optional attributes are verbose (set the verbosity level passed to jasper), package (name of the destination package for generated java classes and classpath (the classpath to use when running the jsp compiler).

This task supports the nested elements classpath (a Path) and classpathref (a Reference) which can be used in preference to the attribute classpath, if the jsp compiler is not already in the ant classpath.

## Usage

    <jspc srcdir="${basedir}/src/war"
          destdir="${basedir}/gensrc"
          package="com.i3sp.jsp"
          verbose="9">
      <include name="**\/*.jsp" />
    </jspc>

Large amount of cutting and pasting from the Javac task...

Since:
  1.5

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `JspC.WebAppParameter`
  static inner class used as a parameter element

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Vector<String>`
  `compileList`
  `protected boolean`
  `failOnError`
  flag to control action on execution trouble
  `protected JspC.WebAppParameter`
  `webApp`
  web apps

  ### Fields inherited from class MatchingTask

  `fileset`
  Modifier and Type
  Field
  Description
  `protected FileSet`
  `fileset`

  ### Fields inherited from class Task

  `target, taskName, taskType, wrapper`
  Modifier and Type
  Field
  Description
  `protected Target`
  `target`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskName`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskType`
  Deprecated.
  since 1.6.x.
  `protected RuntimeConfigurable`
  `wrapper`
  Deprecated.
  since 1.6.x.

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JspC()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addWebApp(JspC.WebAppParameter webappParam)`
  Adds a single webapp.
  `Path`
  `createClasspath()`
  Adds a path to the classpath.
  `Path`
  `createCompilerclasspath()`
  Support nested compiler classpath, used to locate compiler adapter
  `void`
  `deleteEmptyJavaFiles()`
  delete any java output files that are empty this is to get around a little defect in jasper: when it fails, it leaves incomplete files around.
  `void`
  `execute()`
  execute by building up a list of files that have changed and hand them off to a jsp compiler
  `Path`
  `getClasspath()`
  Get the classpath.
  `Vector<String>`
  `getCompileList()`
  get the list of files to compile
  `Path`
  `getCompilerclasspath()`
  get the classpath used to find the compiler adapter
  `File`
  `getDestdir()`
  Get the destination directory.
  `boolean`
  `getFailonerror()`
  Gets the failonerror flag.
  `String`
  `getIeplugin()`
  Get the IE CLASSID value.
  `String`
  `getPackage()`
  Get the name of the package.
  `Path`
  `getSrcDir()`
  Get the source dir.
  `File`
  `getUribase()`
  Get the uri base value.
  `File`
  `getUriroot()`
  Get the uri root value.
  `int`
  `getVerbose()`
  Get the verbose level.
  `JspC.WebAppParameter`
  `getWebApp()`
  Get the web app.
  `File`
  `getWebinc()`
  Get the webinc attribute.
  `File`
  `getWebxml()`
  Filename for web.xml.
  `boolean`
  `isMapped()`
  If true, generate separate write() calls for each HTML line in the JSP.
  `protected File`
  `mapToJavaFile(JspMangler mangler, File srcFile, File srcDir, File dest)`
  get a filename from our jsp file.
  `protected void`
  `resetFileLists()`
  Clear the list of files to be compiled and copied..
  `protected void`
  `scanDir(File srcDir, File dest, JspMangler mangler, String[] files)`
  Scans the directory looking for source files to be compiled.
  `void`
  `setClasspath(Path cp)`
  Set the classpath to be used for this compilation.
  `void`
  `setClasspathRef(Reference r)`
  Adds a reference to a classpath defined elsewhere
  `void`
  `setCompiler(String compiler)`
  Class name of a JSP compiler adapter.
  `void`
  `setCompilerclasspath(Path cp)`
  Set the classpath to be used to find this compiler adapter
  `void`
  `setDestdir(File destDir)`
  Set the destination directory into which the JSP source files should be compiled.
  `void`
  `setFailonerror(boolean fail)`
  Whether or not the build should halt if compilation fails.
  `void`
  `setIeplugin(String iepluginid)`
  Java Plugin CLASSID for Internet Explorer
  `void`
  `setMapped(boolean mapped)`
  If true, generate separate write() calls for each HTML line in the JSP.
  `void`
  `setPackage(String pkg)`
  Set the name of the package the compiled jsp files should be in.
  `void`
  `setSrcDir(Path srcDir)`
  Set the path for source JSP files.
  `void`
  `setUribase(File uribase)`
  The URI context of relative URI references in the JSP pages.
  `void`
  `setUriroot(File uriroot)`
  The root directory that uri files should be resolved against.
  `void`
  `setVerbose(int i)`
  Set the verbose level of the compiler
  `void`
  `setWebinc(File webinc)`
  output filename for the fraction of web.xml that lists servlets.
  `void`
  `setWebxml(File webxml)`
  Filename for web.xml.

  ### Methods inherited from class MatchingTask

  `add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems`
  Modifier and Type
  Method
  Description
  `void`
  `add(FileSelector selector)`
  add an arbitrary selector
  `void`
  `addAnd(AndSelector selector)`
  add an "And" selector entry on the selector list
  `void`
  `addContains(ContainsSelector selector)`
  add a contains selector entry on the selector list
  `void`
  `addContainsRegexp(ContainsRegexpSelector selector)`
  add a regular expression selector entry on the selector list
  `void`
  `addCustom(ExtendSelector selector)`
  add an extended selector entry on the selector list
  `void`
  `addDate(DateSelector selector)`
  add a selector date entry on the selector list
  `void`
  `addDepend(DependSelector selector)`
  add a depends selector entry on the selector list
  `void`
  `addDepth(DepthSelector selector)`
  add a depth selector entry on the selector list
  `void`
  `addDifferent(DifferentSelector selector)`
  add a type selector entry on the type list
  `void`
  `addFilename(FilenameSelector selector)`
  add a selector filename entry on the selector list
  `void`
  `addMajority(MajoritySelector selector)`
  add a majority selector entry on the selector list
  `void`
  `addModified(ModifiedSelector selector)`
  add the modified selector
  `void`
  `addNone(NoneSelector selector)`
  add a "None" selector entry on the selector list
  `void`
  `addNot(NotSelector selector)`
  add a "Not" selector entry on the selector list
  `void`
  `addOr(OrSelector selector)`
  add an "Or" selector entry on the selector list
  `void`
  `addPresent(PresentSelector selector)`
  add a present selector entry on the selector list
  `void`
  `addSelector(SelectSelector selector)`
  add a "Select" selector entry on the selector list
  `void`
  `addSize(SizeSelector selector)`
  add a selector size entry on the selector list
  `void`
  `addType(TypeSelector selector)`
  add a type selector entry on the type list
  `void`
  `appendSelector(FileSelector selector)`
  Add a new selector into this container.
  `PatternSet.NameEntry`
  `createExclude()`
  add a name entry on the exclude list
  `PatternSet.NameEntry`
  `createExcludesFile()`
  add a name entry on the include files list
  `PatternSet.NameEntry`
  `createInclude()`
  add a name entry on the include list
  `PatternSet.NameEntry`
  `createIncludesFile()`
  add a name entry on the include files list
  `PatternSet`
  `createPatternSet()`
  add a set of patterns
  `protected DirectoryScanner`
  `getDirectoryScanner(File baseDir)`
  Returns the directory scanner needed to access the files to process.
  `protected final FileSet`
  `getImplicitFileSet()`
  Accessor for the implicit fileset.
  `FileSelector[]`
  `getSelectors(Project p)`
  Returns the set of selectors as an array.
  `boolean`
  `hasSelectors()`
  Indicates whether there are any selectors here.
  `int`
  `selectorCount()`
  Gives the count of the number of selectors in this container
  `Enumeration<FileSelector>`
  `selectorElements()`
  Returns an enumerator for accessing the set of selectors.
  `void`
  `setCaseSensitive(boolean isCaseSensitive)`
  Sets case sensitivity of the file system
  `void`
  `setDefaultexcludes(boolean useDefaultExcludes)`
  Sets whether default exclusions should be used or not.
  `void`
  `setExcludes(String excludes)`
  Sets the set of exclude patterns.
  `void`
  `setExcludesfile(File excludesfile)`
  Sets the name of the file containing the includes patterns.
  `void`
  `setFollowSymlinks(boolean followSymlinks)`
  Sets whether or not symbolic links or Windows junctions should be followed.
  `void`
  `setIncludes(String includes)`
  Sets the set of include patterns.
  `void`
  `setIncludesfile(File includesfile)`
  Sets the name of the file containing the includes patterns.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.
  `void`
  `XsetIgnore(String ignoreString)`
  List of filenames and directory names to not include.
  `void`
  `XsetItems(String itemString)`
  Set this to be the items in the base directory that you want to be included.

  ### Methods inherited from class Task

  `bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`
  Modifier and Type
  Method
  Description
  `final void`
  `bindToOwner(Task owner)`
  Bind a task to another; use this when configuring a newly created task to do work on behalf of another.
  `Target`
  `getOwningTarget()`
  Returns the container target of this task.
  `RuntimeConfigurable`
  `getRuntimeConfigurableWrapper()`
  Returns the wrapper used for runtime configuration.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `String`
  `getTaskType()`
  Return the type of task.
  `protected RuntimeConfigurable`
  `getWrapper()`
  Return the runtime configurable structure for this task.
  `protected void`
  `handleErrorFlush(String output)`
  Handles an error line by logging it with the WARN priority.
  `protected void`
  `handleErrorOutput(String output)`
  Handles an error output by logging it with the WARN priority.
  `protected void`
  `handleFlush(String output)`
  Handles output by logging it with the INFO priority.
  `protected int`
  `handleInput(byte[] buffer, int offset, int length)`
  Handle an input request by this task.
  `protected void`
  `handleOutput(String output)`
  Handles output by logging it with the INFO priority.
  `void`
  `init()`
  Called by the project to let the task initialize properly.
  `protected final boolean`
  `isInvalid()`
  Has this task been marked invalid?
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(String msg, Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `maybeConfigure()`
  Configures this task - if it hasn't been done already.
  `final void`
  `perform()`
  Performs this task if it's still valid, or gets a replacement version and performs that otherwise.
  `void`
  `reconfigure()`
  Force the task to be reconfigured from its RuntimeConfigurable.
  `void`
  `setOwningTarget(Target target)`
  Sets the target container of this task.
  `void`
  `setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)`
  Sets the wrapper to be used for runtime configuration.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.
  `void`
  `setTaskType(String type)`
  Sets the name with which the task has been invoked.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, setDescription, setLocation`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### compileList

    protected Vector<String> compileList

  - ### failOnError

    protected boolean failOnError
    flag to control action on execution trouble

  - ### webApp

    protected JspC.WebAppParameter webApp
    web apps

- ## Constructor Details

  - ### JspC

    public JspC()

- ## Method Details

  - ### setSrcDir

    public void setSrcDir(Path srcDir)
    Set the path for source JSP files.
    Parameters:
      `srcDir` - the source path.

  - ### getSrcDir

    public Path getSrcDir()
    Get the source dir.
    Returns:
      the source path.

  - ### setDestdir

    public void setDestdir(File destDir)
    Set the destination directory into which the JSP source files should be compiled.
    Parameters:
      `destDir` - the destination directory.

  - ### getDestdir

    public File getDestdir()
    Get the destination directory.
    Returns:
      the directory.

  - ### setPackage

    public void setPackage(String pkg)
    Set the name of the package the compiled jsp files should be in.
    Parameters:
      `pkg` - the name of the package.

  - ### getPackage

    public String getPackage()
    Get the name of the package.
    Returns:
      the package.

  - ### setVerbose

    public void setVerbose(int i)
    Set the verbose level of the compiler
    Parameters:
      `i` - the verbose level to use.

  - ### getVerbose

    public int getVerbose()
    Get the verbose level.
    Returns:
      the level.

  - ### setFailonerror

    public void setFailonerror(boolean fail)
    Whether or not the build should halt if compilation fails. Defaults to `true`.
    Parameters:
      `fail` - a `boolean` value.

  - ### getFailonerror

    public boolean getFailonerror()
    Gets the failonerror flag.
    Returns:
      the flag.

  - ### getIeplugin

    public String getIeplugin()
    Get the IE CLASSID value.
    Returns:
      the value.

  - ### setIeplugin

    public void setIeplugin(String iepluginid)
    Java Plugin CLASSID for Internet Explorer
    Parameters:
      `iepluginid` - the id to use.

  - ### isMapped

    public boolean isMapped()
    If true, generate separate write() calls for each HTML line in the JSP.
    Returns:
      mapping status

  - ### setMapped

    public void setMapped(boolean mapped)
    If true, generate separate write() calls for each HTML line in the JSP.
    Parameters:
      `mapped` - a `boolean` value.

  - ### setUribase

    public void setUribase(File uribase)
    The URI context of relative URI references in the JSP pages. If it does not exist then it is derived from the location of the file relative to the declared or derived value of uriroot.
    Parameters:
      `uribase` - The new Uribase value

  - ### getUribase

    public File getUribase()
    Get the uri base value.
    Returns:
      the value.

  - ### setUriroot

    public void setUriroot(File uriroot)
    The root directory that uri files should be resolved against. (Default is the directory jspc is invoked from)
    Parameters:
      `uriroot` - The new Uribase value

  - ### getUriroot

    public File getUriroot()
    Get the uri root value.
    Returns:
      the value.

  - ### setClasspath

    public void setClasspath(Path cp)
    Set the classpath to be used for this compilation.
    Parameters:
      `cp` - the path to be used.

  - ### createClasspath

    public Path createClasspath()
    Adds a path to the classpath.
    Returns:
      a path to be configured.

  - ### setClasspathRef

    public void setClasspathRef(Reference r)
    Adds a reference to a classpath defined elsewhere
    Parameters:
      `r` - a reference to a classpath.

  - ### getClasspath

    public Path getClasspath()
    Get the classpath.
    Returns:
      the classpath.

  - ### setCompilerclasspath

    public void setCompilerclasspath(Path cp)
    Set the classpath to be used to find this compiler adapter
    Parameters:
      `cp` - the compiler classpath.

  - ### getCompilerclasspath

    public Path getCompilerclasspath()
    get the classpath used to find the compiler adapter
    Returns:
      the compiler classpath.

  - ### createCompilerclasspath

    public Path createCompilerclasspath()
    Support nested compiler classpath, used to locate compiler adapter
    Returns:
      a path to be configured.

  - ### setWebxml

    public void setWebxml(File webxml)
    Filename for web.xml.
    Parameters:
      `webxml` - The new Webxml value

  - ### getWebxml

    public File getWebxml()
    Filename for web.xml.
    Returns:
      The filename for web.xml.

  - ### setWebinc

    public void setWebinc(File webinc)
    output filename for the fraction of web.xml that lists servlets.
    Parameters:
      `webinc` - The new Webinc value

  - ### getWebinc

    public File getWebinc()
    Get the webinc attribute.
    Returns:
      the webinc attribute.

  - ### addWebApp

    public void addWebApp(JspC.WebAppParameter webappParam) throws BuildException
    Adds a single webapp.
    Parameters:
      `webappParam` - add a web app parameter
    Throws:
      `BuildException` - if more than one webapp is specified.

  - ### getWebApp

    public JspC.WebAppParameter getWebApp()
    Get the web app.
    Returns:
      the web app attribute.

  - ### setCompiler

    public void setCompiler(String compiler)
    Class name of a JSP compiler adapter.
    Parameters:
      `compiler` - the compiler class name.

  - ### getCompileList

    public Vector<String> getCompileList()
    get the list of files to compile
    Returns:
      the list of files.

  - ### execute

    public void execute() throws BuildException
    execute by building up a list of files that have changed and hand them off to a jsp compiler
    Overrides:
      `execute` in class `Task`
    Throws:
      `BuildException` - on error.

  - ### resetFileLists

    protected void resetFileLists()
    Clear the list of files to be compiled and copied..

  - ### scanDir

    protected void scanDir(File srcDir, File dest, JspMangler mangler, String[] files)
    Scans the directory looking for source files to be compiled. The results are returned in the class variable compileList
    Parameters:
      `srcDir` - the source directory.
      `dest` - the destination directory.
      `mangler` - the jsp filename mangler.
      `files` - the file names to mangle.

  - ### mapToJavaFile

    protected File mapToJavaFile(JspMangler mangler, File srcFile, File srcDir, File dest)
    get a filename from our jsp file.
    Parameters:
      `mangler` - the jsp filename manager.
      `srcFile` - the source file.
      `srcDir` - the source directory.
      `dest` - the destination directory.
    Returns:
      the filename.
    To do:
      support packages and subdirs

  - ### deleteEmptyJavaFiles

    public void deleteEmptyJavaFiles()
    delete any java output files that are empty this is to get around a little defect in jasper: when it fails, it leaves incomplete files around.