ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers CompilerAdapter.java CompilerAdapterFactory.java DefaultCompilerAdapter.java JasperC.java
Date Thu, 13 Sep 2001 08:31:22 GMT
donaldp     01/09/13 01:31:22

  Modified:    docs/manual optionaltasklist.html
               src/main/org/apache/tools/ant/taskdefs defaults.properties
  Added:       docs/manual/OptionalTasks jspc.html
               src/main/org/apache/tools/ant/taskdefs/optional/jsp
                        JspC.java
               src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers
                        CompilerAdapter.java CompilerAdapterFactory.java
                        DefaultCompilerAdapter.java JasperC.java
  Log:
  First cut at a generic jspc task/facade system.
  
  Submitted by: Matthew Watson <mattw@mortbay.com>
  
  Revision  Changes    Path
  1.18      +1 -0      jakarta-ant/docs/manual/optionaltasklist.html
  
  Index: optionaltasklist.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/optionaltasklist.html,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- optionaltasklist.html	2001/08/07 22:44:44	1.17
  +++ optionaltasklist.html	2001/09/13 08:31:21	1.18
  @@ -22,6 +22,7 @@
   <a href="OptionalTasks/icontract.html">IContract</a><br>
   <a href="OptionalTasks/javacc.html">JavaCC</a><br>
   <a href="OptionalTasks/javah.html">Javah</a><br>
  +<a href="OptionalTasks/jspc.html">JspC</a><br>
   <a href="OptionalTasks/jdepend.html">JDepend</a><br>
   <a href="OptionalTasks/jjtree.html">JJTree</a><br>
   <a href="OptionalTasks/jlink.html">Jlink</a><br>
  
  
  
  1.1                  jakarta-ant/docs/manual/OptionalTasks/jspc.html
  
  Index: jspc.html
  ===================================================================
  <html>
  
  <head>
  <meta http-equiv="Content-Language" content="en-us">
  <title>Ant User Manual</title>
  </head>
  
  <body>
  
  <h2><a name="jspc">jspc</a></h2>
  <h3>Description</h3>
  
  <p> Ant task to run the jsp compiler.
  
  <p> 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.
  
  <p><h3>Parameters</h3>
  The Task has the following attributes:
  <table border="1" cellpadding="2" cellspacing="0">
    <tr>
      <td valign="top"><b>Attribute</b></td>
      <td valign="top"><b>Description</b></td>
      <td align="center" valign="top"><b>Required</b></td>
    </tr>
    <tr>
      <td valign="top">destdir</td>
      <td valign="top">Where to place the generated files. They are located
      under here according to the given package name.</td>
      <td valign="top" align="center">Yes</td>
    </tr>
    <tr>
      <td valign="top">srcdir</td>
      <td valign="top">Where to look for source jsp files.</td>
      <td valign="top" align="center">Yes</td>
    </tr>
    <tr>
      <td valign="top">verbose</td>
      <td valign="top">The verbose flag to pass to the compiler.</td>
      <td valign="top" align="center">No</td>
    </tr>
    <tr>
      <td valign="top">package</td>
      <td valign="top">Name of the destination package for generated java
      classes.</td>
      <td valign="top" align="center">No</td>
    </tr>
    <tr>
      <td valign="top">ieplugin</td>
      <td valign="top">Java Plugin classid for Internet Explorer.</td>
      <td valign="top" align="center">No</td>
    </tr>
    <tr>
      <td valign="top">mapped</td>
      <td valign="top">(boolean) Generate separate write() calls for each HTML
      line in the JSP.</td>
      <td valign="top" align="center">No</td>
    </tr>
    <tr>
      <td valign="top">classpath</td>
      <td valign="top">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 <code>classpath</code> (a
      <a href="../using.html#path">Path</a>).</td>
      <td valign="top" align="center">No</td>
    </tr>
    <tr>
      <td valign="top">classpathref</td>
      <td valign="top">A <a href="../using.html#references">Reference</a>.
As
      per <code>classpath</code></td>
      <td valign="top" align="center">No</td>
    </tr>
   * classes and classpath (the classpath to use when running the jsp
   * compiler).
   * <p> 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.
  </table>
  <p> This task is a <a href="../dirtasks.html">directory based task</a>,
like
  <strong>javac</strong>, so the jsp files to be compiled are located as java
  files are by <strong>javac</strong>.
  
  <p><h3>Example</h3>
  <pre>
  &lt;jspc srcdir="${basedir}/src/war"
        destdir="${basedir}/gensrc"
        package="com.i3sp.jsp"
        verbose="9"&gt;
    &lt;include name="**\/*.jsp" /&gt;
  &lt;/jspc&gt;
  
  </pre>
  
  <p><h4>Notes</h4>
  <p> At present, this task only supports the jasper compiler. In future,
  other compilers will be supported by setting the jsp.compiler property.
  <p> The jasper compiler option <code>-webapp</code> is not supported.
Using
  the <code>package</code> 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.
  
  <hr>
  <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  Reserved.</p>
  
  </body>
  </html>
  
  
  
  
  1.91      +1 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- defaults.properties	2001/09/11 01:37:47	1.90
  +++ defaults.properties	2001/09/13 08:31:21	1.91
  @@ -122,6 +122,7 @@
   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
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java
  
  Index: JspC.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  
  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.
   * <p> 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.
   *
   * <p> 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).
   * <p> 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.
   *
   * <p><h4>Notes</h4>
   * <p> At present, this task only supports the jasper compiler. In future,
   other compilers will be supported by setting the jsp.compiler property.
   *
   * <p><h4>Usage</h4>
   * <pre>
   * &lt;jspc srcdir="${basedir}/src/war"
   *       destdir="${basedir}/gensrc"
   *       package="com.i3sp.jsp"
   *       verbose="9"&gt;
   *   &lt;include name="**\/*.jsp" /&gt;
   * &lt;/jspc&gt;
   * </pre>
   *
   * @version $Revision: 1.1 $ $Date: 2001/09/13 08:31:21 $
   * @author <a href="mailto:mattw@i3sp.com">Matthew Watson</a>
   * <p> Large Amount of cutting and pasting from the Javac task...
   * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
   * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
   */
  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());
                  }
              }
          }
      }
      /* ------------------------------------------------------------ */
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapter.java
  
  Index: CompilerAdapter.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  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.  
   *
   * <p>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).</p>
   *
   * @author Jay Dickon Glanville <a href="mailto:jayglanville@home.com">jayglanville@home.com</a>
   * @author Matthew Watson <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
   */
  
  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;
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/CompilerAdapterFactory.java
  
  Index: CompilerAdapterFactory.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  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 <a href="mailto:jayglanville@home.com">J D Glanville</a>
   * @author Matthew Watson <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
   */
  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:
       * <ul><li>jasper = jasper compiler (the default)
       * <li><i>a fully quallified classname</i> = the name of a jsp compiler
       * adapter
       * </ul>
       *
       * @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);
          }
      }
  
  }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultCompilerAdapter.java
  
  Index: DefaultCompilerAdapter.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  
  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 <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
   */
  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&quot;
       */
      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;
      }
      /* ------------------------------------------------------------ */
  }
  
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/JasperC.java
  
  Index: JasperC.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  
  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 <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
   */
  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;
      }
      /* ------------------------------------------------------------ */        
  }
  
  
  

Mime
View raw message