📄 jspcmojo.java
字号:
//========================================================================//$Id: JspcMojo.java 4687 2009-03-02 09:07:46Z janb $//Copyright 2006 Mort Bay Consulting Pty. Ltd.//------------------------------------------------------------------------//Licensed under the Apache License, Version 2.0 (the "License");//you may not use this file except in compliance with the License.//You may obtain a copy of the License at //http://www.apache.org/licenses/LICENSE-2.0//Unless required by applicable law or agreed to in writing, software//distributed under the License is distributed on an "AS IS" BASIS,//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.//See the License for the specific language governing permissions and//limitations under the License.//========================================================================package org.mortbay.jetty.jspc.plugin;import org.apache.jasper.JspC;import org.apache.maven.artifact.Artifact;import org.apache.maven.plugin.AbstractMojo;import org.apache.maven.plugin.MojoExecutionException;import org.apache.maven.plugin.MojoFailureException;import org.apache.maven.project.MavenProject;import org.codehaus.plexus.util.FileUtils;import org.codehaus.plexus.util.StringUtils;import org.mortbay.util.IO;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.FilenameFilter;import java.io.PrintWriter;import java.net.URL;import java.net.URLClassLoader;import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** * <p> * This goal will compile jsps for a webapp so that they can be included in a * war. * </p> * <p> * At runtime, the plugin will use the jsp2.0 jspc compiler if you are running * on a 1.4 or lower jvm. If you are using a 1.5 jvm, then the jsp2.1 compiler * will be selected. (this is the same behaviour as the <a * href="http://jetty.mortbay.org/maven-plugin">jetty plugin</a> for executing * webapps). * </p> * <p> * Note that the same java compiler will be used as for on-the-fly compiled * jsps, which will be the Eclipse java compiler. * </p> * * <p> * See <a * href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Jspc+Plugin">Usage * Guide</a> for instructions on using this plugin. * </p> * * @author janb * * @goal jspc * @phase process-classes * @requiresDependencyResolution compile * @description Runs jspc compiler to produce .java and .class files */public class JspcMojo extends AbstractMojo{ public static final String END_OF_WEBAPP = "</web-app>"; /** * The maven project. * * @parameter expression="${project}" * @required * @readonly */ private MavenProject project; /** * File into which to generate the <servlet> and * <servlet-mapping> tags for the compiled jsps * * @parameter expression="${basedir}/target/webfrag.xml" */ private String webXmlFragment; /** * Optional. A marker string in the src web.xml file which indicates where * to merge in the generated web.xml fragment. Note that the marker string * will NOT be preserved during the insertion. Can be left blank, in which * case the generated fragment is inserted just before the </web-app> * line * * @parameter */ private String insertionMarker; /** * Merge the generated fragment file with the web.xml from * webAppSourceDirectory. The merged file will go into the same directory as * the webXmlFragment. * * @parameter expression="true" */ private boolean mergeFragment; /** * The destination directory into which to put the compiled jsps. * * @parameter expression="${project.build.outputDirectory}" */ private String generatedClasses; /** * Controls whether or not .java files generated during compilation will be * preserved. * * @parameter expression="false" */ private boolean keepSources; /** * Default root package for all generated classes * * @parameter expression="jsp" */ private String packageRoot; /** * Root directory for all html/jsp etc files * * @parameter expression="${basedir}/src/main/webapp" * @required */ private String webAppSourceDirectory; /** * The comma separated list of patterns for file extensions to be processed. By default * will include all .jsp and .jspx files. * * @parameter default-value="**\/*.jsp, **\/*.jspx" */ private String includes; /** * The comma separated list of file name patters to exclude from compilation. * * @parameter default_value="**\/.svn\/**"; */ private String excludes; /** * The location of the compiled classes for the webapp * * @parameter expression="${project.build.outputDirectory}" */ private File classesDirectory; /** * Whether or not to output more verbose messages during compilation. * * @parameter expression="false"; */ private boolean verbose; /** * If true, validates tlds when parsing. * * @parameter expression="false"; */ private boolean validateXml; /** * The encoding scheme to use. * * @parameter expression="UTF-8" */ private String javaEncoding; /** * Whether or not to generate JSR45 compliant debug info * * @parameter expression="true"; */ private boolean suppressSmap; /** * Whether or not to ignore precompilation errors caused by jsp fragments. * * @parameter expression="false" */ private boolean ignoreJspFragmentErrors; /** * Allows a prefix to be appended to the standard schema locations so that * they can be loaded from elsewhere. * * @parameter */ private String schemaResourcePrefix; public void execute() throws MojoExecutionException, MojoFailureException { if (getLog().isDebugEnabled()) { getLog().info("verbose=" + verbose); getLog().info("webAppSourceDirectory=" + webAppSourceDirectory); getLog().info("generatedClasses=" + generatedClasses); getLog().info("webXmlFragment=" + webXmlFragment); getLog().info("validateXml=" + validateXml); getLog().info("packageRoot=" + packageRoot); getLog().info("javaEncoding=" + javaEncoding); getLog().info("insertionMarker="+ (insertionMarker == null || insertionMarker.equals("") ? END_OF_WEBAPP : insertionMarker)); getLog().info("keepSources=" + keepSources); getLog().info("mergeFragment=" + mergeFragment); getLog().info("suppressSmap=" + suppressSmap); getLog().info("ignoreJspFragmentErrors=" + ignoreJspFragmentErrors); getLog().info("schemaResourcePrefix=" + schemaResourcePrefix); } try { prepare(); compile(); cleanupSrcs(); mergeWebXml(); } catch (Exception e) { throw new MojoFailureException(e, "Failure processing jsps","Failure processing jsps"); } } public void compile() throws Exception { ClassLoader currentClassLoader = Thread.currentThread()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -