You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sh...@locus.apache.org on 2000/02/09 07:50:51 UTC
cvs commit: jakarta-tomcat/src/shell jspc.sh
shemnon 00/02/08 22:50:51
Modified: src/share/org/apache/jasper CommandLineContext.java
JspC.java
src/share/org/apache/jasper/compiler
CommandLineCompiler.java Compiler.java
src/share/org/apache/jasper/resources messages.properties
src/shell jspc.sh
Log:
* implemented -c and -p options
* all files under <uriroot>/WEB-INF/lib are added to JSPLoader
* If -uriroot is not specified, jspc will now navigate up until
it finds a parent dir with a WEB-INF direcotry. It will use
either the dir holding the first WEB-INF above it or failing
that it will use the current user/working directory.
Revision Changes Path
1.2 +39 -10 jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java
Index: CommandLineContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommandLineContext.java 2000/02/07 07:51:17 1.1
+++ CommandLineContext.java 2000/02/09 06:50:47 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v 1.1 2000/02/07 07:51:17 shemnon Exp $
- * $Revision: 1.1 $
- * $Date: 2000/02/07 07:51:17 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/CommandLineContext.java,v 1.2 2000/02/09 06:50:47 shemnon Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/02/09 06:50:47 $
*
* ====================================================================
*
@@ -99,6 +99,10 @@
String uriBase;
File uriRoot;
+ boolean packageNameLocked;
+ boolean classNameLocked;
+ boolean outputInDirs;
+
public CommandLineContext(JspLoader newLoader, String newClassPath,
String newJspFile, String newUriBase,
String newUriRoot, boolean newErrPage,
@@ -130,10 +134,6 @@
} else {
uriRoot = new File(tUriRoot);
if (!uriRoot.exists() || !uriRoot.isDirectory()) {
- System.out.println(uriRoot);
- System.out.println(uriRoot.exists());
- System.out.println(uriRoot.isDirectory());
- System.out.println(uriRoot.getAbsolutePath());
throw new JasperException(
Constants.getString("jsp.error.jspc.uriroot_not_dir"));
};
@@ -228,7 +228,12 @@
* generated.
*/
public String getServletJavaFileName() {
- return servletJavaFileName;
+ if (outputInDirs) {
+ return getServletPackageName().replace('.', File.separatorChar)
+ + servletJavaFileName;
+ } else {
+ return servletJavaFileName;
+ }
};
/**
@@ -266,11 +271,19 @@
};
public void setServletClassName(String servletClassName) {
- this.servletClassName = servletClassName;
+ if (classNameLocked) {
+ //System.out.println("Did not change clazz to " + servletClassName);
+ } else {
+ this.servletClassName = servletClassName;
+ };
};
public void setServletPackageName(String servletPackageName) {
- this.servletPackageName = servletPackageName;
+ if (packageNameLocked) {
+ //System.out.println("Did not change pkg to " + servletPackageName);
+ } else {
+ this.servletPackageName = servletPackageName;
+ };
};
public void setServletJavaFileName(String servletJavaFileName) {
@@ -279,6 +292,22 @@
public void setErrorPage(boolean isErrPage) {
errPage = isErrPage;
+ };
+
+ public void lockPackageName() {
+ packageNameLocked = true;
+ };
+
+ public void lockClassName() {
+ classNameLocked = true;
+ };
+
+ public void setOutputInDirs(boolean newValue) {
+ outputInDirs = true;
+ };
+
+ public boolean isOutputInDirs() {
+ return outputInDirs;
};
/**
1.2 +87 -7 jakarta-tomcat/src/share/org/apache/jasper/JspC.java
Index: JspC.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JspC.java 2000/02/07 07:51:17 1.1
+++ JspC.java 2000/02/09 06:50:47 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.1 2000/02/07 07:51:17 shemnon Exp $
- * $Revision: 1.1 $
- * $Date: 2000/02/07 07:51:17 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/JspC.java,v 1.2 2000/02/09 06:50:47 shemnon Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/02/09 06:50:47 $
*
* ====================================================================
*
@@ -84,6 +84,7 @@
public static final String SWITCH_VERBOSE = "-v";
public static final String SWITCH_QUIET = "-q";
public static final String SWITCH_OUTPUT_DIR = "-d";
+ public static final String SWITCH_OUTPUT_SIMPLE_DIR = "-dd";
public static final String SWITCH_IE_CLASS_ID = "-ieplugin";
public static final String SWITCH_PACKAGE_NAME = "-p";
public static final String SWITCH_CLASS_NAME = "-c";
@@ -115,6 +116,7 @@
//JspLoader loader;
+ boolean dirset;
public boolean getKeepGenerated() {
// isn't this why we are running jspc?
@@ -195,12 +197,12 @@
while ((tok = nextArg()) != null) {
if (tok.equals(SWITCH_QUIET)) {
- jspVerbosityLevel = Constants.WARNING;
+ Constants.jspVerbosityLevel = Constants.WARNING;
} else if (tok.equals(SWITCH_VERBOSE)) {
- jspVerbosityLevel = Constants.HIGH_VERBOSITY;
+ Constants.jspVerbosityLevel = Constants.HIGH_VERBOSITY;
} else if (tok.startsWith(SWITCH_VERBOSE)) {
try {
- jspVerbosityLevel = Integer.parseInt(
+ Constants.jspVerbosityLevel = Integer.parseInt(
tok.substring(SWITCH_VERBOSE.length()));
} catch (NumberFormatException nfe) {
log.println(
@@ -212,6 +214,7 @@
tok = nextArg();
if (tok != null) {
scratchDir = new File(tok);
+ dirset = true;
} else {
// either an in-java call with an explicit null
// or a "-d --" sequence should cause this,
@@ -219,6 +222,17 @@
/* no-op */
scratchDir = null;
}
+ } else if (tok.equals(SWITCH_OUTPUT_SIMPLE_DIR)) {
+ tok = nextArg();
+ if (tok != null) {
+ scratchDir = new File(tok);
+ } else {
+ // either an in-java call with an explicit null
+ // or a "-d --" sequence should cause this,
+ // which would mean default handling
+ /* no-op */
+ scratchDir = null;
+ }
} else if (tok.equals(SWITCH_PACKAGE_NAME)) {
targetPackage = nextArg();
} else if (tok.equals(SWITCH_CLASS_NAME)) {
@@ -236,6 +250,7 @@
};
public void parseFiles(PrintStream log) throws JasperException {
+ // set up a scratch/output dir if none is provided
if (scratchDir == null) {
String temp = System.getProperty("java.io.tempdir");
if (temp == null) {
@@ -243,6 +258,36 @@
}
scratchDir = new File(temp);
}
+
+ // set up the uri root if none is explicitly set
+ if (uriRoot == null) {
+ File f = new File(args[argPos]);
+ try {
+ if (f.exists()) {
+ f = new File(f.getCanonicalPath());
+ while (f != null) {
+ File g = new File(f, "WEB-INF");
+ if (g.exists() && g.isDirectory()) {
+ uriRoot = f.getCanonicalPath();
+ Constants.message("jspc.implicit.uriRoot",
+ new Object[] { uriRoot },
+ Constants.MED_VERBOSITY);
+ break;
+ }
+ f = new File(f.getParent());
+ // If there is no acceptible candidate, uriRoot will
+ // remain null to indicate to the CompilerContext to
+ // use the current working/user dir.
+ }
+ }
+ } catch (IOException ioe) {
+ // since this is an optional default and a null value
+ // for uriRoot has a non-error meaning, we can just
+ // pass straight through
+ }
+ }
+
+
String file = nextFile();
while (file != null) {
try {
@@ -251,15 +296,50 @@
CommandLineContext clctxt = new CommandLineContext(
loader, getClassPath(), file, uriBase, uriRoot, false,
this);
- loader.addJar(clctxt.getRealPath("/WEB-INF/classes"));
+ if ((targetClassName != null) && (targetClassName.length() > 0)) {
+ clctxt.setServletClassName(targetClassName);
+ clctxt.lockClassName();
+ }
+ if (targetPackage != null) {
+ clctxt.setServletPackageName(targetPackage);
+ clctxt.lockPackageName();
+ }
+ if (dirset) {
+ clctxt.setOutputInDirs(true);
+ };
+ File uriDir = new File(clctxt.getRealPath("/"));
+ if (uriDir.exists()) {
+ if ((new File(uriDir, "WEB-INF/classes")).exists()) {
+ loader.addJar(clctxt.getRealPath("/WEB-INF/classes"));
+ }
+ File lib = new File(clctxt.getRealPath("WEB-INF/lib"));
+ if (lib.exists() && lib.isDirectory()) {
+ String[] libs = lib.list();
+ for (int i = 0; i < libs.length; i++) {
+ try {
+ loader.addJar(lib.getCanonicalPath()
+ + File.separator
+ + libs[i]);
+ } catch (IOException ioe) {
+ // failing a toCanonicalPath on a file that
+ // exists() should be a JVM regression test,
+ // therefore we have permission to freak out
+ throw new RuntimeException(ioe.toString());
+ }
+ }
+ }
+ };
CommandLineCompiler clc = new CommandLineCompiler(clctxt);
clc.compile();
+
+ targetClassName = null;
} catch (JasperException je) {
je.printStackTrace(System.err);
System.out.print("error:");
System.out.println(je.getMessage());
} catch (Exception e) {
+ e.printStackTrace(System.out);
System.out.print("ERROR:");
System.out.println(e.toString());
};
1.2 +36 -12 jakarta-tomcat/src/share/org/apache/jasper/compiler/CommandLineCompiler.java
Index: CommandLineCompiler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommandLineCompiler.java 2000/02/07 07:51:18 1.1
+++ CommandLineCompiler.java 2000/02/09 06:50:48 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v 1.1 2000/02/07 07:51:18 shemnon Exp $
- * $Revision: 1.1 $
- * $Date: 2000/02/07 07:51:18 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/CommandLineCompiler.java,v 1.2 2000/02/09 06:50:48 shemnon Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/02/09 06:50:48 $
*
* The Apache Software License, Version 1.1
*
@@ -60,9 +60,11 @@
package org.apache.jasper.compiler;
import java.io.File;
+import java.io.IOException;
import org.apache.jasper.Constants;
import org.apache.jasper.JspCompilationContext;
+import org.apache.jasper.CommandLineContext;
/**
* Overrides some methods so that we get the desired effects.
@@ -77,11 +79,27 @@
File jsp;
String outputDir;
- public CommandLineCompiler(JspCompilationContext ctxt) {
+ public CommandLineCompiler(CommandLineContext ctxt) {
super(ctxt);
jsp = new File(ctxt.getJspFile());
outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath();
+ // yes this is kind of messed up ... but it works
+ if (ctxt.isOutputInDirs()) {
+ String tmpDir = outputDir
+ + File.separatorChar
+ + ctxt.getServletPackageName()
+ .replace('.', File.separatorChar);
+ File f = new File(tmpDir);
+ if (!f.exists()) {
+ if (f.mkdirs()) {
+ outputDir = tmpDir;
+ }
+ } else {
+ outputDir = tmpDir;
+ }
+ }
+
setMangler(this);
computePackageName();
@@ -101,7 +119,7 @@
public final void computeJavaFileName() {
- javaFileName = className + ".java";
+ javaFileName = ctxt.getServletClassName() + ".java";
if (outputDir != null && !outputDir.equals(""))
javaFileName = outputDir + File.separatorChar + javaFileName;
}
@@ -134,9 +152,10 @@
StringBuffer modifiedpkgName = new StringBuffer ();
int indexOfSepChar = pathName.lastIndexOf(File.separatorChar);
- if (indexOfSepChar == -1 || indexOfSepChar == 0)
+ if (("".equals(ctxt.getServletPackageName())) ||
+ (indexOfSepChar == -1) || (indexOfSepChar == 0)) {
pkgName = null;
- else {
+ } else {
for (int i = 0; i < keywords.length; i++) {
char fs = File.separatorChar;
int index1 = pathName.indexOf(fs + keywords[i]);
@@ -156,6 +175,9 @@
pkgName = pathName.substring(0, pathName.lastIndexOf(
File.separatorChar)).replace(File.separatorChar, '.');
+ if (ctxt.getServletPackageName() != null) {
+ pkgName = ctxt.getServletPackageName();
+ }
for (int i=0; i<pkgName.length(); i++)
if (Character.isLetter(pkgName.charAt(i)) == true ||
pkgName.charAt(i) == '.') {
@@ -183,12 +205,14 @@
}
private final String getBaseClassName() {
- String className;
+ String className = ctxt.getServletClassName();
- if (jsp.getName().endsWith(".jsp"))
- className = jsp.getName().substring(0, jsp.getName().length() - 4);
- else
- className = jsp.getName();
+ if (className == null) {
+ if (jsp.getName().endsWith(".jsp"))
+ className = jsp.getName().substring(0, jsp.getName().length() - 4);
+ else
+ className = jsp.getName();
+ }
// Fix for invalid characters. If you think of more add to the list.
1.11 +5 -4 jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Compiler.java 2000/02/07 07:51:18 1.10
+++ Compiler.java 2000/02/09 06:50:49 1.11
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.10 2000/02/07 07:51:18 shemnon Exp $
- * $Revision: 1.10 $
- * $Date: 2000/02/07 07:51:18 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v 1.11 2000/02/09 06:50:49 shemnon Exp $
+ * $Revision: 1.11 $
+ * $Date: 2000/02/09 06:50:49 $
*
* ====================================================================
*
@@ -111,7 +111,8 @@
ctxt.setServletJavaFileName(javaFileName);
Constants.message("jsp.message.package_name_is",
- new Object[] { pkgName },
+ new Object[] { (pkgName==null)?
+ "[default package]":pkgName },
Constants.MED_VERBOSITY);
Constants.message("jsp.message.class_name_is",
new Object[] { className },
1.11 +2 -0 jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties
Index: messages.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/resources/messages.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- messages.properties 2000/02/07 07:51:21 1.10
+++ messages.properties 2000/02/09 06:50:50 1.11
@@ -142,11 +142,13 @@
jsp.warning.compiler.class.notfound=Specified compiler plugin class {0} not found. Will default to Sun Java Compiler.
jsp.warning.compiler.path.notfound=Specified compiler path {0} not found. Will default to system PATH.
jsp.error.jspc.uriroot_not_dir=The -uriroot option must specify a pre-existing directory
+jspc.implicit.uriRoot=uriRoot implicitly set to "{0}"
jspc.usage=Usage: jspc <options> [--] <jsp files>\n\
where options include:\n\
\ -q Quite mode (same as -v0)\n\
\ -v[#] Verbose mode (optional number is level, default is 2)\n\
\ -d <dir> Output Directory\n\
+\ -dd <dir> Literal Output Directory. (package dirs will not be made)\n\
\ -ieplugin Java Plugin classid for IE\n\
\ -p <name> Name of target package\n\
\ -c <name> Name of target class name\n\
1.2 +2 -2 jakarta-tomcat/src/shell/jspc.sh
Index: jspc.sh
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/shell/jspc.sh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- jspc.sh 2000/02/07 08:02:14 1.1
+++ jspc.sh 2000/02/09 06:50:50 1.2
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $Id: jspc.sh,v 1.1 2000/02/07 08:02:14 shemnon Exp $
+# $Id: jspc.sh,v 1.2 2000/02/09 06:50:50 shemnon Exp $
# Shell script to runt JspC
@@ -68,7 +68,7 @@
done
CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
-echo XXX $CLASSPATH
+#echo XXX $CLASSPATH
# Backdoor classpath setting for development purposes when all classes