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 User Manual + + + + +

jspc

+

Description

+ +

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. + +

Parameters

+The Task has the following attributes: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * 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. +

AttributeDescriptionRequired
destdirWhere to place the generated files. They are located + under here according to the given package name.Yes
srcdirWhere to look for source jsp files.Yes
verboseThe verbose flag to pass to the compiler.No
packageName of the destination package for generated java + classes.No
iepluginJava Plugin classid for Internet Explorer.No
mapped(boolean) Generate separate write() calls for each HTML + line in the JSP.No
classpathThe 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
classpathrefA Reference. As + per classpathNo
+

This task is a directory based task, like +javac, so the jsp files to be compiled are located as java +files are by javac. + +

Example

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

Notes

+

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 @@ IContract
JavaCC
Javah
+JspC
JDepend
JJTree
Jlink
diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index 7e5fe0156..9b1ff2041 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -122,6 +122,7 @@ jpcoverage=org.apache.tools.ant.taskdefs.optional.sitraka.Coverage jpcovmerge=org.apache.tools.ant.taskdefs.optional.sitraka.CovMerge jpcovreport=org.apache.tools.ant.taskdefs.optional.sitraka.CovReport p4add=org.apache.tools.ant.taskdefs.optional.perforce.P4Add +jspc=org.apache.tools.ant.taskdefs.optional.jsp.JspC # deprecated ant tasks (kept for back compatibility) javadoc2=org.apache.tools.ant.taskdefs.Javadoc diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java new file mode 100644 index 000000000..174968b3a --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java @@ -0,0 +1,354 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000 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 + * . + */ + +package org.apache.tools.ant.taskdefs.optional.jsp; + +import java.io.File; +import java.util.Date; +import java.util.Enumeration; +import java.util.Vector; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.*; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; + +/** 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. + * + *

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. + * + *

Notes

+ *

At present, this task only supports the jasper compiler. In future, + other compilers will be supported by setting the jsp.compiler property. + * + *

Usage

+ *
+ * <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 + * . + */ +package org.apache.tools.ant.taskdefs.optional.jsp.compilers; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.optional.jsp.JspC; + +/** + * The interface that all jsp compiler adapters must adher to. + * + *

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 + * . + */ +package org.apache.tools.ant.taskdefs.optional.jsp.compilers; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.Project; + +/** + * Creates the necessary compiler adapter, given basic criteria. + * + * @author J D Glanville + * @author Matthew Watson mattw@i3sp.com + */ +public class CompilerAdapterFactory { + + /** This is a singlton -- can't create instances!! */ + private CompilerAdapterFactory() { + } + + /** + * Based on the parameter passed in, this method creates the necessary + * factory desired. + * + * The current mapping for compiler names are as follows: + * + * + * @param compilerType either the name of the desired compiler, or the + * full classname of the compiler's adapter. + * @param task a task to log through. + * @throws BuildException if the compiler type could not be resolved into + * a compiler adapter. + */ + public static CompilerAdapter getCompiler( String compilerType, Task task ) + throws BuildException { + /* If I've done things right, this should be the extent of the + * conditional statements required. + */ + if ( compilerType.equalsIgnoreCase("jasper") ) { + return new JasperC(); + } + return resolveClassName( compilerType ); + } + + /** + * Tries to resolve the given classname into a compiler adapter. + * Throws a fit if it can't. + * + * @param className The fully qualified classname to be created. + * @throws BuildException This is the fit that is thrown if className + * isn't an instance of CompilerAdapter. + */ + private static CompilerAdapter resolveClassName( String className ) + throws BuildException { + try { + Class c = Class.forName( className ); + Object o = c.newInstance(); + return (CompilerAdapter) o; + } catch ( ClassNotFoundException cnfe ) { + throw new BuildException( className + " can\'t be found.", cnfe ); + } catch ( ClassCastException cce ) { + throw new BuildException(className + " isn\'t the classname of " + + "a compiler adapter.", cce); + } catch ( Throwable t ) { + // for all other possibilities + throw new BuildException(className + " caused an interesting " + + "exception.", t); + } + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultCompilerAdapter.java new file mode 100644 index 000000000..9676335aa --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultCompilerAdapter.java @@ -0,0 +1,115 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant.taskdefs.optional.jsp.compilers; + +import org.apache.tools.ant.*; +import org.apache.tools.ant.taskdefs.optional.*; +import org.apache.tools.ant.taskdefs.optional.jsp.JspC; +import org.apache.tools.ant.types.*; + +import java.util.Vector; +import java.util.Enumeration; + +/** + * This is the default implementation for the CompilerAdapter interface. + * This is currently very light on the ground since only one compiler type is + * supported. + * + * @author Matthew Watson mattw@i3sp.com + */ +public abstract class DefaultCompilerAdapter + implements CompilerAdapter +{ + /* ------------------------------------------------------------ */ + private static String lSep = System.getProperty("line.separator"); + /* ------------------------------------------------------------ */ + /** + * Logs the compilation parameters, adds the files to compile and logs the + * &qout;niceSourceList" + */ + protected void logAndAddFilesToCompile(JspC jspc, + Vector compileList, + Commandline cmd) + { + jspc.log("Compilation args: " + cmd.toString(), Project.MSG_VERBOSE); + + StringBuffer niceSourceList = new StringBuffer("File"); + if (compileList.size() != 1) { + niceSourceList.append("s"); + } + niceSourceList.append(" to be compiled:"); + + niceSourceList.append(lSep); + + Enumeration enum = compileList.elements(); + while (enum.hasMoreElements()) { + String arg = (String)enum.nextElement(); + cmd.createArgument().setValue(arg); + niceSourceList.append(" " + arg + lSep); + } + + jspc.log(niceSourceList.toString(), Project.MSG_VERBOSE); + } + /* ------------------------------------------------------------ */ + protected JspC attributes; + public void setJspc( JspC attributes ) { + this.attributes = attributes; + } + public JspC getJspc() { + return attributes; + } + /* ------------------------------------------------------------ */ +} + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java new file mode 100644 index 000000000..92a8d1749 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java @@ -0,0 +1,128 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant.taskdefs.optional.jsp.compilers; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.*; +import org.apache.tools.ant.taskdefs.optional.jsp.JspC; +import org.apache.tools.ant.taskdefs.*; + +/** + * The implementation of the jasper compiler. + * This is a cut-and-paste of the original Jspc task. + * + * @author Matthew Watson mattw@i3sp.com + */ +public class JasperC extends DefaultCompilerAdapter +{ + /* ------------------------------------------------------------ */ + public boolean execute() + throws BuildException + { + getJspc().log("Using jasper compiler", Project.MSG_VERBOSE); + Commandline cmd = setupJasperCommand(); + + try { + // Create an instance of the compiler, redirecting output to + // the project log + Java java = (Java)(getJspc().getProject()).createTask("java"); + if (getJspc().getClasspath() != null) + java.setClasspath(getJspc().getClasspath()); + java.setClassname("org.apache.jasper.JspC"); + String args[] = cmd.getArguments(); + for (int i =0; i < args.length; i++) + java.createArg().setValue(args[i]); + java.setFailonerror(true); + java.execute(); + return true; + } + catch (Exception ex) { + if (ex instanceof BuildException) { + throw (BuildException) ex; + } else { + throw new BuildException("Error running jsp compiler: ", + ex, getJspc().getLocation()); + } + } + } + /* ------------------------------------------------------------ */ + private Commandline setupJasperCommand() { + Commandline cmd = new Commandline(); + JspC jspc = getJspc(); + if (jspc.getDestdir() != null) { + cmd.createArgument().setValue("-d"); + cmd.createArgument().setFile(jspc.getDestdir()); + } + if (jspc.getPackage() != null){ + cmd.createArgument().setValue("-p"); + cmd.createArgument().setValue(jspc.getPackage()); + } + if (jspc.getVerbose() != 0) { + cmd.createArgument().setValue("-v" + jspc.getVerbose()); + } + if (jspc.isMapped()){ + cmd.createArgument().setValue("-mapped"); + } + if (jspc.getIeplugin() != null){ + cmd.createArgument().setValue("-ieplugin"); + cmd.createArgument().setValue(jspc.getIeplugin()); + } + + logAndAddFilesToCompile(getJspc(), getJspc().getCompileList(), cmd); + return cmd; + } + /* ------------------------------------------------------------ */ +}