1 18 19 package org.apache.tools.ant.taskdefs.optional.jsp.compilers; 20 21 import java.io.File ; 22 import org.apache.tools.ant.AntClassLoader; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.taskdefs.Java; 26 import org.apache.tools.ant.taskdefs.optional.jsp.JspC; 27 import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler; 28 import org.apache.tools.ant.types.CommandlineJava; 29 import org.apache.tools.ant.types.Path; 30 31 37 public class JasperC extends DefaultJspCompilerAdapter { 38 39 41 44 JspMangler mangler; 45 46 48 52 public JasperC(JspMangler mangler) { 53 this.mangler = mangler; 54 } 55 56 61 public boolean execute() 62 throws BuildException { 63 getJspc().log("Using jasper compiler", Project.MSG_VERBOSE); 64 CommandlineJava cmd = setupJasperCommand(); 65 66 try { 67 Java java = new Java(owner); 70 Path p = getClasspath(); 71 if (getJspc().getClasspath() != null) { 72 getProject().log("using user supplied classpath: " + p, 73 Project.MSG_DEBUG); 74 } else { 75 getProject().log("using system classpath: " + p, 76 Project.MSG_DEBUG); 77 } 78 java.setClasspath(p); 79 java.setDir(getProject().getBaseDir()); 80 java.setClassname("org.apache.jasper.JspC"); 81 String []args = cmd.getJavaCommand().getArguments(); 83 for (int i = 0; i < args.length; i++) { 84 java.createArg().setValue(args[i]); 85 } 86 java.setFailonerror(getJspc().getFailonerror()); 87 java.setFork(true); 90 java.setTaskName("jasperc"); 91 java.execute(); 92 return true; 93 } catch (Exception ex) { 94 if (ex instanceof BuildException) { 95 throw (BuildException) ex; 96 } else { 97 throw new BuildException("Error running jsp compiler: ", 98 ex, getJspc().getLocation()); 99 } 100 } finally { 101 getJspc().deleteEmptyJavaFiles(); 102 } 103 } 104 105 106 107 111 private CommandlineJava setupJasperCommand() { 112 CommandlineJava cmd = new CommandlineJava(); 113 JspC jspc = getJspc(); 114 addArg(cmd, "-d", jspc.getDestdir()); 115 addArg(cmd, "-p", jspc.getPackage()); 116 117 if (!isTomcat5x()) { 118 addArg(cmd, "-v" + jspc.getVerbose()); 119 } else { 120 getProject().log("this task doesn't support Tomcat 5.x properly, " 121 + "please use the Tomcat provided jspc task " 122 + "instead"); 123 } 124 125 addArg(cmd, "-uriroot", jspc.getUriroot()); 126 addArg(cmd, "-uribase", jspc.getUribase()); 127 addArg(cmd, "-ieplugin", jspc.getIeplugin()); 128 addArg(cmd, "-webinc", jspc.getWebinc()); 129 addArg(cmd, "-webxml", jspc.getWebxml()); 130 addArg(cmd, "-die9"); 131 132 if (jspc.isMapped()) { 133 addArg(cmd, "-mapped"); 134 } 135 if (jspc.getWebApp() != null) { 136 File dir = jspc.getWebApp().getDirectory(); 137 addArg(cmd, "-webapp", dir); 138 } 139 logAndAddFilesToCompile(getJspc(), getJspc().getCompileList(), cmd); 140 return cmd; 141 } 142 143 146 147 public JspMangler createMangler() { 148 return mangler; 149 } 150 151 154 private Path getClasspath() { 155 Path p = getJspc().getClasspath(); 156 if (p == null) { 157 p = new Path(getProject()); 158 return p.concatSystemClasspath("only"); 159 } else { 160 return p.concatSystemClasspath("ignore"); 161 } 162 } 163 164 167 private boolean isTomcat5x() { 168 AntClassLoader l = null; 169 try { 170 l = getProject().createClassLoader(getClasspath()); 171 l.loadClass("org.apache.jasper.tagplugins.jstl.If"); 172 return true; 173 } catch (ClassNotFoundException e) { 174 return false; 175 } finally { 176 if (l != null) { 177 l.cleanup(); 178 } 179 } 180 } 181 } 182 | Popular Tags |