Class JspC

  • All Implemented Interfaces:
    Cloneable, Options

    public class JspC
    extends org.apache.tools.ant.Task
    implements Options
    Shell for the jspc compiler. Handles all options associated with the command line and creates compilation contexts which it then compiles according to the specified options. This version can process files from a _single_ webapp at once, i.e. a single docbase can be specified. It can be used as an Ant task using:
       <taskdef classname="org.apache.jasper.JspC" name="jasper" >
          <classpath>
              <pathelement location="${java.home}/../lib/tools.jar"/>
              <fileset dir="${ENV.CATALINA_HOME}/lib">
                  <include name="*.jar"/>
              </fileset>
              <path refid="myjars"/>
           </classpath>
      </taskdef>
    
      <jasper verbose="0"
               package="my.package"
               uriroot="${webapps.dir}/${webapp.name}"
               webXmlFragment="${build.dir}/generated_web.xml"
               outputDir="${webapp.dir}/${webapp.name}/WEB-INF/src/my/package" />
     
    Author:
    Danno Ferrin, Pierre Delisle, Costin Manolache, Yoav Shapira
    • Constructor Detail

      • JspC

        public JspC()
    • Method Detail

      • main

        public static void main​(String[] arg)
      • getKeepGenerated

        public boolean getKeepGenerated()
        In JspC this always returns true.
        Specified by:
        getKeepGenerated in interface Options
        Returns:
        true to keep the generated source
      • setTrimSpaces

        public void setTrimSpaces​(String ts)
        Sets the option to control handling of template text that consists entirely of whitespace.
        Parameters:
        ts - New value
      • setTrimSpaces

        public void setTrimSpaces​(boolean trimSpaces)
      • isPoolingEnabled

        public boolean isPoolingEnabled()
        Specified by:
        isPoolingEnabled in interface Options
        Returns:
        true if tag handler pooling is enabled, false otherwise.
      • setPoolingEnabled

        public void setPoolingEnabled​(boolean poolingEnabled)
        Sets the option to enable the tag handler pooling.
        Parameters:
        poolingEnabled - New value
      • isXpoweredBy

        public boolean isXpoweredBy()
        Specified by:
        isXpoweredBy in interface Options
        Returns:
        true to generate a X-Powered-By response header.
      • setXpoweredBy

        public void setXpoweredBy​(boolean xpoweredBy)
        Sets the option to enable generation of X-Powered-By response header.
        Parameters:
        xpoweredBy - New value
      • getDisplaySourceFragment

        public boolean getDisplaySourceFragment()
        In JspC this always returns true.
        Specified by:
        getDisplaySourceFragment in interface Options
        Returns:
        true to include a source fragment in exception messages.
      • getMaxLoadedJsps

        public int getMaxLoadedJsps()
        Description copied from interface: Options
        The maximum number of loaded jsps per web-application. If there are more jsps loaded, they will be unloaded. If unset or less than 0, no jsps are unloaded.
        Specified by:
        getMaxLoadedJsps in interface Options
        Returns:
        The JSP count
      • getJspIdleTimeout

        public int getJspIdleTimeout()
        Specified by:
        getJspIdleTimeout in interface Options
        Returns:
        the idle time in seconds after which a JSP is unloaded. If unset or less or equal than 0, no jsps are unloaded.
      • getErrorOnUseBeanInvalidClassAttribute

        public boolean getErrorOnUseBeanInvalidClassAttribute()
        Returns true if Jasper issues a compilation error instead of a runtime Instantiation error if the class attribute specified in useBean action is invalid.
        Specified by:
        getErrorOnUseBeanInvalidClassAttribute in interface Options
        Returns:
        true to get an error
      • setErrorOnUseBeanInvalidClassAttribute

        public void setErrorOnUseBeanInvalidClassAttribute​(boolean b)
        Sets the option to issue a compilation error if the class attribute specified in useBean action is invalid.
        Parameters:
        b - New value
      • getMappedFile

        public boolean getMappedFile()
        Specified by:
        getMappedFile in interface Options
        Returns:
        true if HTML mapped Servlets are supported.
      • setMappedFile

        public void setMappedFile​(boolean b)
      • setClassDebugInfo

        public void setClassDebugInfo​(boolean b)
        Sets the option to include debug information in compiled class.
        Parameters:
        b - New value
      • getClassDebugInfo

        public boolean getClassDebugInfo()
        Specified by:
        getClassDebugInfo in interface Options
        Returns:
        true if debug information in included in compiled classes.
      • isCaching

        public boolean isCaching()
        Specified by:
        isCaching in interface Options
        Returns:
        true is caching is enabled (used for precompilation).
      • setCaching

        public void setCaching​(boolean caching)
        Sets the option to enable caching.
        Parameters:
        caching - New value
        See Also:
        Options.isCaching()
      • getCache

        public Map<String,​TagLibraryInfo> getCache()
        The web-application wide cache for the TagLibraryInfo tag library descriptors, used if Options.isCaching() returns true.

        Using this cache avoids the cost of repeating the parsing of a tag library descriptor XML file (performed by TagLibraryInfoImpl.parseTLD).

        Specified by:
        getCache in interface Options
        Returns:
        the Map(String uri, TagLibraryInfo tld) instance.
      • getCheckInterval

        public int getCheckInterval()
        In JspC this always returns 0.
        Specified by:
        getCheckInterval in interface Options
        Returns:
        background compile thread check interval in seconds
      • getModificationTestInterval

        public int getModificationTestInterval()
        In JspC this always returns 0.
        Specified by:
        getModificationTestInterval in interface Options
        Returns:
        modification test interval.
      • getRecompileOnFail

        public boolean getRecompileOnFail()
        In JspC this always returns false.
        Specified by:
        getRecompileOnFail in interface Options
        Returns:
        true if re-compile will occur on a failure.
      • getDevelopment

        public boolean getDevelopment()
        In JspC this always returns false. Main development flag, which enables detailed error reports with sources, as well automatic recompilation of JSPs and tag files. This setting should usually be false when running in production.
        Specified by:
        getDevelopment in interface Options
        Returns:
        true if Jasper is in development mode
      • isSmapSuppressed

        public boolean isSmapSuppressed()
        Specified by:
        isSmapSuppressed in interface Options
        Returns:
        true to suppress generation of SMAP info for JSR45 debugging.
      • setSmapSuppressed

        public void setSmapSuppressed​(boolean smapSuppressed)
        Sets smapSuppressed flag.
        Parameters:
        smapSuppressed - New value
      • isSmapDumped

        public boolean isSmapDumped()
        This setting is ignored if suppressSmap() is true.
        Specified by:
        isSmapDumped in interface Options
        Returns:
        true to write SMAP info for JSR45 debugging to a file.
      • setSmapDumped

        public void setSmapDumped​(boolean smapDumped)
        Sets smapDumped flag.
        Parameters:
        smapDumped - New value
        See Also:
        Options.isSmapDumped()
      • setGenStringAsCharArray

        public void setGenStringAsCharArray​(boolean genStringAsCharArray)
        Determines whether text strings are to be generated as char arrays, which improves performance in some cases.
        Parameters:
        genStringAsCharArray - true if text strings are to be generated as char arrays, false otherwise
      • genStringAsCharArray

        public boolean genStringAsCharArray()
        Indicates whether text strings are to be generated as char arrays.
        Specified by:
        genStringAsCharArray in interface Options
        Returns:
        true if text strings are to be generated as char arrays, false otherwise
      • setIeClassId

        @Deprecated
        public void setIeClassId​(String ieClassId)
        Deprecated.
        Will be removed in Tomcat 10.1
        Sets the class-id value to be sent to Internet Explorer when using <jsp:plugin> tags.
        Parameters:
        ieClassId - Class-id value
      • getIeClassId

        @Deprecated
        public String getIeClassId()
        Deprecated.
        Description copied from interface: Options
        Gets the class-id value that is sent to Internet Explorer when using <jsp:plugin> tags.
        Specified by:
        getIeClassId in interface Options
        Returns:
        Class-id value
      • getScratchDir

        public File getScratchDir()
        Specified by:
        getScratchDir in interface Options
        Returns:
        the work folder
      • getCompiler

        public String getCompiler()
        Compiler to use.

        If null (the default), the java compiler from Eclipse JDT project, bundled with Tomcat, will be used. Otherwise, the javac task from Apache Ant will be used to call an external java compiler and the value of this option will be passed to it. See Apache Ant documentation for the possible values.

        Specified by:
        getCompiler in interface Options
        Returns:
        the compiler name
      • setCompiler

        public void setCompiler​(String c)
        Sets the option to determine what compiler to use.
        Parameters:
        c - New value
        See Also:
        Options.getCompiler()
      • getTldCache

        public TldCache getTldCache()
        The cache that maps URIs, resource paths and parsed TLD files for the various tag libraries 'exposed' by the web application. A tag library is 'exposed' either explicitly in web.xml or implicitly via the uri tag in the TLD of a taglib deployed in a jar file (WEB-INF/lib).
        Specified by:
        getTldCache in interface Options
        Returns:
        the instance of the TldLocationsCache for the web-application.
      • getJavaEncoding

        public String getJavaEncoding()
        Returns the encoding to use for java files. The default is UTF-8.
        Specified by:
        getJavaEncoding in interface Options
        Returns:
        String The encoding
      • setJavaEncoding

        public void setJavaEncoding​(String encodingName)
        Sets the encoding to use for java files.
        Parameters:
        encodingName - The name, e.g. "UTF-8"
      • getFork

        public boolean getFork()
        The boolean flag to tell Ant whether to fork JSP page compilations.

        Is used only when Jasper uses an external java compiler (wrapped through a javac Apache Ant task).

        Specified by:
        getFork in interface Options
        Returns:
        true to fork a process during compilation
      • setFork

        public void setFork​(boolean fork)
      • getClassPath

        public String getClassPath()
        Specified by:
        getClassPath in interface Options
        Returns:
        the classpath used to compile generated Servlets
      • setClassPath

        public void setClassPath​(String s)
        Sets the classpath used while compiling the servlets generated from JSP files
        Parameters:
        s - New value
      • getExtensions

        public List<String> getExtensions()
        Returns the list of file extensions that are treated as JSP files.
        Returns:
        The list of extensions
      • addExtension

        protected void addExtension​(String extension)
        Adds the given file extension to the list of extensions handled as JSP files.
        Parameters:
        extension - The extension to add, e.g. "myjsp"
      • setUriroot

        public void setUriroot​(String s)
        Base dir for the webapp. Used to generate class names and resolve includes.
        Parameters:
        s - New value
      • setJspFiles

        public void setJspFiles​(String jspFiles)
        Parses comma-separated list of JSP files to be processed. If the argument is null, nothing is done.

        Each file is interpreted relative to uriroot, unless it is absolute, in which case it must start with uriroot.

        Parameters:
        jspFiles - Comma-separated list of JSP files to be processed
      • setCompile

        public void setCompile​(boolean b)
        Sets the compile flag.
        Parameters:
        b - Flag value
      • setVerbose

        public void setVerbose​(int level)
        Sets the verbosity level. The actual number doesn't matter: if it's greater than zero, the verbose flag will be true.
        Parameters:
        level - Positive means verbose
      • setValidateTld

        public void setValidateTld​(boolean b)
      • isValidateTld

        public boolean isValidateTld()
      • setValidateXml

        public void setValidateXml​(boolean b)
      • isValidateXml

        public boolean isValidateXml()
      • setBlockExternal

        public void setBlockExternal​(boolean b)
      • isBlockExternal

        public boolean isBlockExternal()
      • setStrictQuoteEscaping

        public void setStrictQuoteEscaping​(boolean b)
      • getStrictQuoteEscaping

        public boolean getStrictQuoteEscaping()
        Specified by:
        getStrictQuoteEscaping in interface Options
        Returns:
        true if the quote escaping required by section JSP.1.6 of the JSP specification should be applied to scriplet expression.
      • setQuoteAttributeEL

        public void setQuoteAttributeEL​(boolean b)
      • getQuoteAttributeEL

        public boolean getQuoteAttributeEL()
        Specified by:
        getQuoteAttributeEL in interface Options
        Returns:
        true if EL expressions used within attributes should have the quoting rules in JSP.1.6 applied to the expression.
      • getThreadCount

        public int getThreadCount()
      • setThreadCount

        public void setThreadCount​(String threadCount)
      • setListErrors

        public void setListErrors​(boolean b)
      • setOutputDir

        public void setOutputDir​(String s)
      • setPackage

        public void setPackage​(String p)
        Sets the package name to be used for the generated servlet classes.
        Parameters:
        p - New value
      • setClassName

        public void setClassName​(String p)
        Class name of the generated file ( without package ). Can only be used if a single file is converted. XXX Do we need this feature ?
        Parameters:
        p - New value
      • setWebXmlInclude

        public void setWebXmlInclude​(String s)
        File where we generate configuration with the class definitions to be included in a web.xml file.
        Parameters:
        s - New value
      • setWebFragmentXml

        public void setWebFragmentXml​(String s)
        File where we generate a complete web-fragment.xml with the class definitions.
        Parameters:
        s - New value
      • setWebXml

        public void setWebXml​(String s)
        File where we generate a complete web.xml with the class definitions.
        Parameters:
        s - New value
      • setWebXmlEncoding

        public void setWebXmlEncoding​(String encoding)
        Sets the encoding to be used to read and write web.xml files.

        If not specified, defaults to UTF-8.

        Parameters:
        encoding - Encoding, e.g. "UTF-8".
      • setAddWebXmlMappings

        public void setAddWebXmlMappings​(boolean b)
        Sets the option to merge generated web.xml fragment into the WEB-INF/web.xml file of the web application that we were processing.
        Parameters:
        b - true to merge the fragment into the existing web.xml file of the processed web application ({uriroot}/WEB-INF/web.xml), false to keep the generated web.xml fragment
      • setFailOnError

        public void setFailOnError​(boolean b)
        Sets the option that throws an exception in case of a compilation error.
        Parameters:
        b - New value
      • getFailOnError

        public boolean getFailOnError()
        Returns:
        true if an exception will be thrown in case of a compilation error.
      • getJspConfig

        public JspConfig getJspConfig()
        Specified by:
        getJspConfig in interface Options
        Returns:
        JSP configuration information specified in web.xml.
      • getGeneratedJavaAddTimestamp

        public boolean getGeneratedJavaAddTimestamp()
        Should the container include the time the file was generated in the comments at the start of a Java file generated from a JSP or tag. Defaults to true.

        Hard-coded to false for pre-compiled code to enable repeatable builds.

        Specified by:
        getGeneratedJavaAddTimestamp in interface Options
        Returns:
        true to include the timestamp, otherwise don't include it
      • generateWebMapping

        public void generateWebMapping​(String file,
                                       JspCompilationContext clctxt)
                                throws IOException
        Adds servlet declaration and mapping for the JSP page servlet to the generated web.xml fragment.
        Parameters:
        file - Context-relative path to the JSP file, e.g. /index.jsp
        clctxt - Compilation context of the servlet
        Throws:
        IOException - An IO error occurred
      • mergeIntoWebXml

        protected void mergeIntoWebXml()
                                throws IOException
        Include the generated web.xml inside the webapp's web.xml.
        Throws:
        IOException - An IO error occurred
      • scanFiles

        public void scanFiles()
        Locate all jsp files in the webapp. Used if no explicit jsps are specified. Scan is performed via the ServletContext and will include any JSPs located in resource JARs.
      • execute

        public void execute()
        Executes the compilation.
        Overrides:
        execute in class org.apache.tools.ant.Task
      • nextArg

        protected String nextArg()
      • nextFile

        protected String nextFile()
      • completeWebXml

        protected void completeWebXml()
      • newTldScanner

        protected TldScanner newTldScanner​(JspCServletContext context,
                                           boolean namespaceAware,
                                           boolean validate,
                                           boolean blockExternal)
      • initClassLoader

        protected ClassLoader initClassLoader()
                                       throws IOException
        Initializes the classloader as/if needed for the given compilation context.
        Returns:
        the classloader that will be used
        Throws:
        IOException - If an error occurs
      • locateUriRoot

        protected void locateUriRoot​(File f)
        Find the WEB-INF dir by looking up in the directory tree. This is used if no explicit docbase is set, but only files.
        Parameters:
        f - The path from which it will start looking
      • resolveFile

        protected File resolveFile​(String s)
        Resolves the relative or absolute pathname correctly in both Ant and command-line situations. If Ant launched us, we should use the basedir of the current project to resolve relative paths. See Bugzilla 35571.
        Parameters:
        s - The file
        Returns:
        The file resolved