Index: JspC.java =================================================================== RCS file: /home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v --- JspC.java 29 Apr 2005 17:18:22 -0000 1.96 +++ JspC.java 1 Jul 2005 19:48:07 -0000 @@ -47,6 +47,8 @@ import org.apache.jasper.compiler.TldLocationsCache; import org.apache.jasper.servlet.JspCServletContext; import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; /** * Shell for the jspc compiler. Handles all options associated with the @@ -146,6 +148,7 @@ private String targetClassName; private String uriBase; private String uriRoot; + private Project project; private int dieLevel; private boolean helpNeeded = false; private boolean compile = false; @@ -596,6 +599,14 @@ } /** + * Ant project. Set by Ant when this class is invoked as a + * Task, so that the uriRoot can be resolved correctly. + */ + public void setProject( Project p ) { + project=p; + } + + /** * Base dir for the webapp. Used to generate class names and resolve * includes */ @@ -605,7 +616,7 @@ return; } try { - uriRoot=new File( s ).getCanonicalPath(); + uriRoot=resolveFile( s ).getCanonicalPath(); } catch( Exception ex ) { uriRoot=s; } @@ -648,7 +659,7 @@ public void setOutputDir( String s ) { if( s!= null ) { - scratchDir = new File(s).getAbsoluteFile(); + scratchDir=resolveFile( s ).getAbsoluteFile(); } else { scratchDir=null; } @@ -671,7 +682,7 @@ * File where we generate a web.xml fragment with the class definitions. */ public void setWebXmlFragment( String s ) { - webxmlFile=s; + webxmlFile=resolveFile( s ).getAbsolutePath(); webxmlLevel=INC_WEBXML; } @@ -679,7 +690,7 @@ * File where we generate a complete web.xml with the class definitions. */ public void setWebXml( String s ) { - webxmlFile=s; + webxmlFile=resolveFile( s ).getAbsolutePath(); webxmlLevel=ALL_WEBXML; } @@ -1257,4 +1268,20 @@ // pass straight through } } + + /** + * Resolves the relative or absolute pathname correctly + * in both Ant and command-line situations. If Ant launched + * us, we should use the basedir of the current project + * to resolve relative paths. + */ + protected File resolveFile( String s ) + { + if( null==project ) { + return FileUtils.getFileUtils().resolveFile(null, s); + } else { + return FileUtils.getFileUtils().resolveFile(project.getBaseDir(), s); + } + } + }