diff --git a/docs/manual/OptionalTasks/jspc.html b/docs/manual/OptionalTasks/jspc.html new file mode 100644 index 000000000..dac586762 --- /dev/null +++ b/docs/manual/OptionalTasks/jspc.html @@ -0,0 +1,109 @@ + + +
+ +Ant task to run the 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. + +
Attribute | +Description | +Required | +
destdir | +Where to place the generated files. They are located + under here according to the given package name. | +Yes | +
srcdir | +Where to look for source jsp files. | +Yes | +
verbose | +The verbose flag to pass to the compiler. | +No | +
package | +Name of the destination package for generated java + classes. | +No | +
ieplugin | +Java Plugin classid for Internet Explorer. | +No | +
mapped | +(boolean) Generate separate write() calls for each HTML + line in the JSP. | +No | +
classpath | +The classpath to use to run the jsp compiler, if the
+ compiler is not already in the ant classpath. This can also be specified
+ by the nested element classpath (a
+ Path). |
+ No | +
classpathref | +A Reference. As
+ per classpath |
+ No | +
This task is a directory based task, like +javac, so the jsp files to be compiled are located as java +files are by javac. + +
+<jspc srcdir="${basedir}/src/war" + destdir="${basedir}/gensrc" + package="com.i3sp.jsp" + verbose="9"> + <include name="**\/*.jsp" /> +</jspc> + ++ +
At present, this task only supports the jasper compiler. In future, +other compilers will be supported by setting the jsp.compiler property. +
The jasper compiler option -webapp
is not supported. Using
+the package
attribute it is possible to identify the resulting
+java files and thus do full dependency checking - this task only rebuilds
+java files if their jsp file has been modified.
+
+
Copyright © 2000,2001 Apache Software Foundation. All rights +Reserved.
+ + + + diff --git a/docs/manual/optionaltasklist.html b/docs/manual/optionaltasklist.html index 4e28c28ed..0d097749c 100644 --- a/docs/manual/optionaltasklist.html +++ b/docs/manual/optionaltasklist.html @@ -22,6 +22,7 @@ IContractThis 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. + * + *
At present, this task only supports the jasper compiler. In future, + other compilers will be supported by setting the jsp.compiler property. + * + *
+ * <jspc srcdir="${basedir}/src/war" + * destdir="${basedir}/gensrc" + * package="com.i3sp.jsp" + * verbose="9"> + * <include name="**\/*.jsp" /> + * </jspc> + *+ * + * @version $Revision$ $Date$ + * @author Matthew Watson + *
Large Amount of cutting and pasting from the Javac task...
+ * @author James Davidson duncan@x180.com
+ * @author Robin Green greenrd@hotmail.com
+ * @author Stefan Bodewig
+ * @author J D Glanville
+ */
+public class JspC extends MatchingTask
+{
+ /* ------------------------------------------------------------ */
+ private Path classpath;
+ private Path src;
+ private File destDir;
+ private String packageName ;
+ private String iepluginid ;
+ private boolean mapped ;
+ private int verbose = 0;
+ protected Vector compileList = new Vector();
+ protected boolean failOnError = true;
+ private static final String FAIL_MSG
+ = "Compile failed, messages should have been provided.";
+ /* ------------------------------------------------------------ */
+ /**
+ * Set the source dirs to find the source JSP files.
+ */
+ public void setSrcdir(Path srcDir) {
+ if (src == null) {
+ src = srcDir;
+ } else {
+ src.append(srcDir);
+ }
+ }
+ public Path getSrcDir(){
+ return src;
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Set the destination directory into which the JSP source
+ * files should be compiled.
+ */
+ public void setDestdir(File destDir) {
+ this.destDir = destDir;
+ }
+ public File getDestdir(){
+ return destDir;
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Set the name of the package the compiled jsp files should be in
+ */
+ public void setPackage(String pkg){
+ this.packageName = pkg;
+ }
+ public String getPackage(){
+ return packageName;
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Set the verbose level of the compiler
+ */
+ public void setVerbose(int i){
+ verbose = i;
+ }
+ public int getVerbose(){
+ return verbose;
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Throw a BuildException if compilation fails
+ */
+ public void setFailonerror(boolean fail) {
+ failOnError = fail;
+ }
+ /**
+ * Gets the failonerror flag.
+ */
+ public boolean getFailonerror() {
+ return failOnError;
+ }
+ /* ------------------------------------------------------------ */
+ public String getIeplugin()
+ {
+ return iepluginid;
+ }
+ /** Set the ieplugin id */
+ public void setIeplugin(String iepluginid_)
+ {
+ iepluginid = iepluginid_;
+ }
+ /* ------------------------------------------------------------ */
+ public boolean isMapped()
+ {
+ return mapped;
+ }
+ /** set the mapped flag */
+ public void setMapped(boolean mapped_)
+ {
+ mapped = mapped_;
+ }
+ /* ------------------------------------------------------------ */
+ /** Set the classpath to be used for this compilation */
+ public void setClasspath(Path cp) {
+ if (classpath == null)
+ classpath = cp;
+ else
+ classpath.append(cp);
+ }
+ /** Maybe creates a nested classpath element. */
+ public Path createClasspath() {
+ if (classpath == null)
+ classpath = new Path(project);
+ return classpath.createPath();
+ }
+ /** Adds a reference to a CLASSPATH defined elsewhere */
+ public void setClasspathRef(Reference r) {
+ createClasspath().setRefid(r);
+ }
+ public Path getClasspath(){
+ return classpath;
+ }
+ /* ------------------------------------------------------------ */
+ public Vector getCompileList(){
+ return compileList;
+ }
+ /* ------------------------------------------------------------ */
+ public void execute()
+ throws BuildException
+ {
+ // first off, make sure that we've got a srcdir
+ if (src == null) {
+ throw new BuildException("srcdir attribute must be set!",
+ location);
+ }
+ String [] list = src.list();
+ if (list.length == 0) {
+ throw new BuildException("srcdir attribute must be set!",
+ location);
+ }
+
+ if (destDir != null && !destDir.isDirectory()) {
+ throw new
+ BuildException("destination directory \"" + destDir +
+ "\" does not exist or is not a directory",
+ location);
+ }
+
+ // calculate where the files will end up:
+ File dest = null;
+ if (packageName == null)
+ dest = destDir;
+ else {
+ String path = destDir.getPath() + File.separatorChar +
+ packageName.replace('.', File.separatorChar);
+ dest = new File(path);
+ }
+
+ // scan source directories and dest directory to build up both copy
+ // lists and compile lists
+ resetFileLists();
+ for (int i = 0; i < list.length; i++) {
+ File srcDir = (File)project.resolveFile(list[i]);
+ if (!srcDir.exists()) {
+ throw new BuildException("srcdir \"" + srcDir.getPath() +
+ "\" does not exist!", location);
+ }
+
+ DirectoryScanner ds = this.getDirectoryScanner(srcDir);
+
+ String[] files = ds.getIncludedFiles();
+
+ scanDir(srcDir, dest, files);
+ }
+
+ // compile the source files
+
+ String compiler = project.getProperty("jsp.compiler");
+ if (compiler == null) {
+ compiler = "jasper";
+ }
+
+ if (compileList.size() > 0) {
+
+ CompilerAdapter adapter =
+ CompilerAdapterFactory.getCompiler(compiler, this);
+ log("Compiling " + compileList.size() +
+ " source file"
+ + (compileList.size() == 1 ? "" : "s")
+ + (destDir != null ? " to " + destDir : ""));
+
+ // now we need to populate the compiler adapter
+ adapter.setJspc( this );
+
+ // finally, lets execute the compiler!!
+ if (!adapter.execute()) {
+ if (failOnError) {
+ throw new BuildException(FAIL_MSG, location);
+ }
+ else {
+ log(FAIL_MSG, Project.MSG_ERR);
+ }
+ }
+ }
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Clear the list of files to be compiled and copied..
+ */
+ protected void resetFileLists() {
+ compileList.removeAllElements();
+ }
+ /* ------------------------------------------------------------ */
+ /**
+ * Scans the directory looking for source files to be compiled.
+ * The results are returned in the class variable compileList
+ */
+ protected void scanDir(File srcDir, File destDir, String files[]) {
+
+ long now = (new Date()).getTime();
+
+ for (int i = 0; i < files.length; i++) {
+ File srcFile = new File(srcDir, files[i]);
+ if (files[i].endsWith(".jsp")) {
+ // drop leading path (if any)
+ int fileStart =
+ files[i].lastIndexOf(File.separatorChar) + 1;
+ File javaFile = new File(destDir, files[i].substring(fileStart,
+ files[i].indexOf(".jsp")) + ".java");
+
+ if (srcFile.lastModified() > now) {
+ log("Warning: file modified in the future: " +
+ files[i], Project.MSG_WARN);
+ }
+
+ if (!javaFile.exists() ||
+ srcFile.lastModified() > javaFile.lastModified())
+ {
+ if (!javaFile.exists()) {
+ log("Compiling " + srcFile.getPath() +
+ " because java file "
+ + javaFile.getPath() + " does not exist",
+ Project.MSG_DEBUG);
+ } else {
+ log("Compiling " + srcFile.getPath() +
+ " because it is out of date with respect to "
+ + javaFile.getPath(), Project.MSG_DEBUG);
+ }
+ compileList.addElement(srcFile.getAbsolutePath());
+ }
+ }
+ }
+ }
+ /* ------------------------------------------------------------ */
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapter.java
new file mode 100644
index 000000000..5aac85bb8
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapter.java
@@ -0,0 +1,86 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *
A compiler adapter is an adapter that interprets the jspc's + * parameters in preperation to be passed off to the compier this + * adapter represents. As all the necessary values are stored in the + * Jspc task itself, the only thing all adapters need is the jsp + * task, the execute command and a parameterless constructor (for + * reflection).
+ * + * @author Jay Dickon Glanville jayglanville@home.com + * @author Matthew Watson mattw@i3sp.com + */ + +public interface CompilerAdapter { + + /** + * Sets the compiler attributes, which are stored in the Jspc task. + */ + public void setJspc( JspC attributes ); + + /** + * Executes the task. + * + * @return has the compilation been successful + */ + public boolean execute() throws BuildException; +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapterFactory.java new file mode 100644 index 000000000..424bf5f2c --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapterFactory.java @@ -0,0 +1,125 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Ant", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + *