From 8c72d0441541454e764e91402080c42b93be22df Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 8 Jul 2015 11:08:46 +1000 Subject: 471076 Apache jspc ignores empty list of files to precompile and scans anyway --- .../org/eclipse/jetty/jspc/plugin/JspcMojo.java | 132 +++++++++++---------- 1 file changed, 70 insertions(+), 62 deletions(-) (limited to 'jetty-jspc-maven-plugin') diff --git a/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java b/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java index ac199805d1..d9f3326e6c 100644 --- a/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java +++ b/jetty-jspc-maven-plugin/src/main/java/org/eclipse/jetty/jspc/plugin/JspcMojo.java @@ -26,7 +26,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.net.MalformedURLException; -import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; @@ -35,7 +34,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; -import java.util.regex.Pattern; import org.apache.jasper.JspC; import org.apache.jasper.servlet.JspCServletContext; @@ -50,18 +48,14 @@ import org.apache.tomcat.util.scan.StandardJarScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.PatternMatcher; import org.eclipse.jetty.util.resource.Resource; /** * This goal will compile jsps for a webapp so that they can be included in a * war. *

- * 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 jetty plugin for executing - * webapps). + * At runtime, the plugin will use the jspc compiler to precompile jsps and tags. + *

*

* Note that the same java compiler will be used as for on-the-fly compiled * jsps, which will be the Eclipse java compiler. @@ -69,7 +63,7 @@ import org.eclipse.jetty.util.resource.Resource; * See Usage * Guide for instructions on using this plugin. - * + *

* @goal jspc * @phase process-classes * @requiresDependencyResolution compile+runtime @@ -353,16 +347,25 @@ public class JspcMojo extends AbstractMojo // JspC#setExtensions() does not exist, so // always set concrete list of files that will be processed. String jspFiles = getJspFiles(webAppSourceDirectory); - getLog().info("Compiling "+jspFiles); - getLog().info("Includes="+includes); - getLog().info("Excludes="+excludes); - jspc.setJspFiles(jspFiles); - - getLog().info("Files selected to precompile: " + jspFiles); - - jspc.execute(); + + try + { + if (jspFiles == null | jspFiles.equals("")) + { + getLog().info("No files selected to precompile"); + } + else + { + getLog().info("Compiling "+jspFiles+" from includes="+includes+" excludes="+excludes); + jspc.setJspFiles(jspFiles); + jspc.execute(); + } + } + finally + { - Thread.currentThread().setContextClassLoader(currentClassLoader); + Thread.currentThread().setContextClassLoader(currentClassLoader); + } } private String getJspFiles(String webAppSourceDirectory) @@ -438,57 +441,62 @@ public class JspcMojo extends AbstractMojo return; } - File fragmentWebXml = new File(webXmlFragment); - if (!fragmentWebXml.exists()) + File fragmentWebXml = new File(webXmlFragment); + File mergedWebXml = new File(fragmentWebXml.getParentFile(), "web.xml"); + + try (BufferedReader webXmlReader = new BufferedReader(new FileReader(webXml)); + PrintWriter mergedWebXmlWriter = new PrintWriter(new FileWriter(mergedWebXml))) { - getLog().info("No fragment web.xml file generated"); - } - File mergedWebXml = new File(fragmentWebXml.getParentFile(), - "web.xml"); - try (BufferedReader webXmlReader = new BufferedReader(new FileReader( - webXml)); - PrintWriter mergedWebXmlWriter = new PrintWriter(new FileWriter( - mergedWebXml))) { - - // read up to the insertion marker or the if there is no - // marker - boolean atInsertPoint = false; - boolean atEOF = false; - String marker = (insertionMarker == null - || insertionMarker.equals("") ? END_OF_WEBAPP : insertionMarker); - while (!atInsertPoint && !atEOF) + + if (!fragmentWebXml.exists()) { - String line = webXmlReader.readLine(); - if (line == null) - atEOF = true; - else if (line.indexOf(marker) >= 0) - { - atInsertPoint = true; - } - else + getLog().info("No fragment web.xml file generated"); + //just copy existing web.xml to expected position + IO.copy(webXmlReader, mergedWebXmlWriter); + } + else + { + // read up to the insertion marker or the if there is no + // marker + boolean atInsertPoint = false; + boolean atEOF = false; + String marker = (insertionMarker == null + || insertionMarker.equals("") ? END_OF_WEBAPP : insertionMarker); + while (!atInsertPoint && !atEOF) { - mergedWebXmlWriter.println(line); + String line = webXmlReader.readLine(); + if (line == null) + atEOF = true; + else if (line.indexOf(marker) >= 0) + { + atInsertPoint = true; + } + else + { + mergedWebXmlWriter.println(line); + } } - } - - if (atEOF && !atInsertPoint) - throw new IllegalStateException("web.xml does not contain insertionMarker "+insertionMarker); - - //put in a context init-param to flag that the contents have been precompiled - mergedWebXmlWriter.println(""+PRECOMPILED_FLAG+"true"); - - // put in the generated fragment - try (BufferedReader fragmentWebXmlReader = new BufferedReader( - new FileReader(fragmentWebXml))) { - IO.copy(fragmentWebXmlReader, mergedWebXmlWriter); + if (atEOF && !atInsertPoint) + throw new IllegalStateException("web.xml does not contain insertionMarker "+insertionMarker); - // if we inserted just before the , put it back in - if (marker.equals(END_OF_WEBAPP)) - mergedWebXmlWriter.println(END_OF_WEBAPP); + //put in a context init-param to flag that the contents have been precompiled + mergedWebXmlWriter.println(""+PRECOMPILED_FLAG+"true"); - // copy in the rest of the original web.xml file - IO.copy(webXmlReader, mergedWebXmlWriter); + + // put in the generated fragment + try (BufferedReader fragmentWebXmlReader = + new BufferedReader(new FileReader(fragmentWebXml))) + { + IO.copy(fragmentWebXmlReader, mergedWebXmlWriter); + + // if we inserted just before the , put it back in + if (marker.equals(END_OF_WEBAPP)) + mergedWebXmlWriter.println(END_OF_WEBAPP); + + // copy in the rest of the original web.xml file + IO.copy(webXmlReader, mergedWebXmlWriter); + } } } } -- cgit v1.2.3