keith 02/05/15 20:15:13
Modified: . build.xml
Added: src/share/org/apache/tomcat/ant Tomcat3JSPVersionFile.java
Tomcat3Precompiler.java ant.properties
Log:
Add Tomcat related Ant tasks for precompiling JSPs.
Revision Changes Path
1.178 +25 -1 jakarta-tomcat/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/build.xml,v
retrieving revision 1.177
retrieving revision 1.178
diff -u -r1.177 -r1.178
--- build.xml 24 Apr 2002 12:26:23 -0000 1.177
+++ build.xml 16 May 2002 03:15:13 -0000 1.178
@@ -590,7 +590,7 @@
</jar>
</target>
- <target name="tomcat-jars"
depends="prepare,dep.tomcat-util,tomcat_util,stop-tomcat.jar,tomcat_core,jasper,tomcat_modules,tomcat.jar,facade22,tomcat-startup">
+ <target name="tomcat-jars"
depends="prepare,dep.tomcat-util,tomcat_util,stop-tomcat.jar,tomcat_core,jasper,tomcat_modules,tomcat.jar,facade22,tomcat-startup,tomcat-ant">
</target>
<target name="tomcat-jars-new" depends="tomcat-jars">
@@ -599,6 +599,30 @@
<!-- ==================== J2EE integration ========== -->
<target name="j2ee">
<ant antfile="src/j2ee/build.xml" target="tomcat-j2ee.jar"/>
+ </target>
+
+
+ <!-- ==================== Ant utilities ========== -->
+ <target name="tomcat-ant" >
+ <javac srcdir="src/share"
+ destdir="${tomcat.build}/classes" >
+ <include name="org/apache/tomcat/ant/*.java" />
+ <classpath>
+ <pathelement path="${ant.lib}/ant.jar" />
+ <pathelement path="${ant.lib}/ant-optional.jar" />
+ <pathelement path="${ant.lib}/optional.jar" />
+ </classpath>
+ </javac>
+ <mkdir dir="${tomcat.build}/ant" />
+ <jar jarfile="${tomcat.build}/ant/tomcat-ant.jar"
+ basedir="${tomcat.build}/classes">
+ <include name="org/apache/tomcat/ant/**" />
+ </jar>
+ <jar jarfile="${tomcat.build}/ant/tomcat-ant.jar"
+ basedir="src/share/org/apache/tomcat/ant"
+ update="yes">
+ <include name="*.properties" />
+ </jar>
</target>
<!-- ==================== Build all web applications ==================== -->
1.1
jakarta-tomcat/src/share/org/apache/tomcat/ant/Tomcat3JSPVersionFile.java
Index: Tomcat3JSPVersionFile.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 [EMAIL PROTECTED]
*
* 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.tomcat.ant;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
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.util.regexp.RegexpMatcher;
import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
/**
* Task to create version files used by Tomcat to determine the
* appropriate class to load for a JSP.
*
* This task can accept the following attribute:
* <ul>
* <li>srcdir
* </ul>
* <b>srcdir</b> is required.
* <p>
* When this task executes, it will scan the files in srcdir which have
* the form <i>name_nnn.class</i>. For each class, if a corresponding
* version file of the form <i>name.ver</i> does not exist, it is created
* with version <i>nnn</i>. If the version file exists, this task verifies that
* it contains the correct version <i>nnn</i>. If not, a new version file is
* created.
*
* <p>Use this task with the Tomcat3Precompiler to create the appropriate
* files to pre-populate the Tomcat work directory.
*
* @author Keith Wannamaker <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
*
* @version $Revision: 1.1 $
*
* @since Ant 1.6
*
*/
public class Tomcat3JSPVersionFile extends Task {
private File srcdir;
private RegexpMatcherFactory factory = new RegexpMatcherFactory();
/** Setter for srcdir */
public void setSrcdir(String srcdir) {
this.srcdir = new File(srcdir);
}
/** Execute the task */
public void execute() throws BuildException {
if (srcdir == null) {
throw new BuildException("srcdir attribute required", location);
}
DirectoryScanner ds = new DirectoryScanner();
ds.setIncludes(new String [] {"**_?*.class"});
ds.setBasedir(srcdir);
ds.setCaseSensitive(true);
ds.scan();
String[] files = ds.getIncludedFiles();
int count = 0;
for (int i = 0; i < files.length; i++) {
RegexpMatcher rm = factory.newRegexpMatcher();
rm.setPattern("(.*)_(\\d*).class");
if (rm.matches(files[i])) {
Vector components = rm.getGroups(files[i]);
String base = (String) components.elementAt(1);
String strVersion = (String) components.elementAt(2);
int version = new Integer(strVersion).intValue();
File verFile = new File(srcdir, base + ".ver");
try {
if (verFile.exists()) {
if (readVersionFile(verFile) == version) {
continue;
}
}
log("Creating verion file " + verFile.getAbsolutePath(),
Project.MSG_VERBOSE);
count++;
writeVersionFile(verFile, version);
} catch (IOException ioe) {
throw new BuildException(ioe);
}
}
}
log("Created " + count + " version file" + ((count != 1) ? "s" : ""));
}
/**
* Read Tomcat 3 version file
*/
private int readVersionFile(File verFile) throws IOException {
FileInputStream stream = new FileInputStream(verFile);
try {
return (int) stream.read();
} finally {
stream.close();
}
}
/**
* Write Tomcat 3 version file
*/
private void writeVersionFile(File verFile, int version) throws IOException {
FileOutputStream stream = new FileOutputStream(verFile);
try {
stream.write(version);
} finally {
stream.close();
}
}
}
1.1
jakarta-tomcat/src/share/org/apache/tomcat/ant/Tomcat3Precompiler.java
Index: Tomcat3Precompiler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 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 [EMAIL PROTECTED]
*
* 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.tomcat.ant;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.taskdefs.optional.jsp.JspC;
import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler;
import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler;
import
org.apache.tools.ant.taskdefs.optional.jsp.compilers.DefaultJspCompilerAdapter;
import org.apache.tools.ant.taskdefs.Java;
import java.io.File;
import java.util.Enumeration;
import java.util.Vector;
/**
* This compiler adaptor builds jsps with a naming convention that is
* ready-to-use by Tomcat 3.x. Files are compiled from <i>foo.jsp</i>
* to <i>foo_1.java</i>.
*
* <p>Use this task with the Tomcat3JSPVersionFile to create the appropriate
* files to pre-populate the Tomcat work directory.
*
* @author Keith Wannamaker <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
* @since ant1.6
*/
public class Tomcat3Precompiler extends DefaultJspCompilerAdapter {
/**
* our execute method which does dependency checks
*/
public boolean execute()
throws BuildException {
getJspc().log("Using Tomcat 3 precompiler", Project.MSG_VERBOSE);
Vector sources = getJspc().getCompileList();
Enumeration enum = sources.elements();
while (enum.hasMoreElements()) {
Commandline cmd = setupJasperCommand();
String source = (String) enum.nextElement();
String base = getBase(source);
addArg(cmd, "-c", base + "_1");
cmd.createArgument().setValue(source);
compile(cmd);
}
return true;
}
/** Execute Jasper */
private boolean compile(Commandline cmd) throws BuildException {
try {
// Create an instance of the compiler, redirecting output to
// the project log
// REVISIT. ugly.
Java java = (Java) (getJspc().getProject()).createTask("java");
if (getJspc().getClasspath() != null) {
java.setClasspath(getJspc().getClasspath());
} else {
java.setClasspath(Path.systemClasspath);
}
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(getJspc().getFailonerror());
//don't fork
java.setFork(false);
java.execute();
return true;
} catch (Exception ex) {
//@todo implement failonerror support here?
if (ex instanceof BuildException) {
throw (BuildException) ex;
} else {
throw new BuildException("Error running jsp compiler: ",
ex, getJspc().getLocation());
}
} finally {
getJspc().deleteEmptyJavaFiles();
}
}
/**
* Returns filename sans extension and prefix
*/
private String getBase(String filename) {
int lastslash = filename.lastIndexOf('/');
if (lastslash == -1) {
lastslash = 0;
}
int lastdot = filename.lastIndexOf('.');
if (lastdot == -1) {
lastdot = filename.length();
}
return filename.substring(lastslash + 1, lastdot);
}
/**
* build up a command line
* @return a command line for jasper
*/
private Commandline setupJasperCommand() {
Commandline cmd = new Commandline();
JspC jspc = getJspc();
addArg(cmd, "-d", jspc.getDestdir());
addArg(cmd, "-p", jspc.getPackage());
addArg(cmd, "-v" + jspc.getVerbose());
addArg(cmd, "-uriroot", jspc.getUriroot());
addArg(cmd, "-uribase", jspc.getUribase());
addArg(cmd, "-ieplugin", jspc.getIeplugin());
addArg(cmd, "-die9");
if (jspc.isMapped()){
addArg(cmd, "-mapped");
}
if (jspc.getWebApp() != null) {
File dir = jspc.getWebApp().getDirectory();
addArg(cmd, "-webapp", dir);
}
return cmd;
}
/**
* @return an instance of the mangler this compiler uses
*/
public JspMangler createMangler() {
return new TomcatJSPMangler();
}
/**
* Special mangler which coverts *.jsp -> *_1.java
*/
private class TomcatJSPMangler implements JspMangler {
public TomcatJSPMangler() {
mangler = new JspNameMangler();
}
public String mapJspToJavaName(File jspFile) {
String javaFile = mangler.mapJspToJavaName(jspFile);
int ext = javaFile.lastIndexOf(".java");
if (ext != -1) {
javaFile = javaFile.substring(0, ext) + "_1.java";
}
return javaFile;
}
public String mapPath(String path) {
return mangler.mapPath(path);
}
private JspMangler mangler;
}
}
1.1 jakarta-tomcat/src/share/org/apache/tomcat/ant/ant.properties
Index: ant.properties
===================================================================
#
# jakarta-tomcat custom ant tasks
# <taskdef resource="ant.properties" />
#
jspversion=org.apache.tomcat.ant.Tomcat3JSPVersionFile
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>