This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-jspc-maven-plugin.git
commit 7f98682d6da02d8c00c669377d263e04818bb956 Author: Robert Munteanu <[email protected]> AuthorDate: Wed Jul 24 18:13:22 2013 +0000 SLING-2978 - Create tooling top-level directory and move maven and ide under it * moved the maven directory under tooling maven * adjusted module paths in pom.xml * updated the scm information in the pom.xml files * updated the scm information in the README.txt files git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1506645 13f79535-47bb-0310-9956-ffa450edef68 --- README.txt | 27 + pom.xml | 135 ++++ .../apache/sling/maven/jspc/JspCServletConfig.java | 57 ++ .../sling/maven/jspc/JspCServletContext.java | 377 +++++++++++ .../java/org/apache/sling/maven/jspc/JspcMojo.java | 741 +++++++++++++++++++++ .../resources/org/apache/sling/maven/jspc/web.xml | 25 + 6 files changed, 1362 insertions(+) diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..ac34ff0 --- /dev/null +++ b/README.txt @@ -0,0 +1,27 @@ +Apache Sling JSP Compiler Maven Plugin + +Maven Plugin compiling JSPs + +Getting Started +=============== + +This component uses a Maven 2 (http://maven.apache.org/) build +environment. It requires a Java 5 JDK (or higher) and Maven (http://maven.apache.org/) +2.0.7 or later. We recommend to use the latest Maven version. + +If you have Maven 2 installed, you can compile and +package the jar using the following command: + + mvn package + +See the Maven 2 documentation for other build features. + +The latest source code for this component is available in the +Subversion (http://subversion.tigris.org/) source repository of +the Apache Software Foundation. If you have Subversion installed, +you can checkout the latest source using the following command: + + svn checkout http://svn.apache.org/repos/asf/sling/trunk/tooling/maven/maven-jspc-plugin + +See the Subversion documentation for other source control features. + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..75d9207 --- /dev/null +++ b/pom.xml @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>17</version> + <relativePath>../../parent/pom.xml</relativePath> + </parent> + + <groupId>org.apache.sling</groupId> + <artifactId>maven-jspc-plugin</artifactId> + <version>2.0.7-SNAPSHOT</version> + <packaging>maven-plugin</packaging> + + <name>Apache Sling Maven Plugin for Compiling JSP Sources into Bundles</name> + <description> + Maven Plugin compiling JSPs + </description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/maven/maven-jspc-plugin</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/maven-jspc-plugin</developerConnection> + <url>http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-jspc-plugin</url> + </scm> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>2.5.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <!-- No javadocs --> + <excludePackageNames> + org.apache.sling + </excludePackageNames> + </configuration> + </plugin> + </plugins> + </reporting> + + <dependencies> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.2.2</version> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.scripting.jsp</artifactId> + <version>2.0.18</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.servlet.jsp</groupId> + <artifactId>jsp-api</artifactId> + <version>2.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.4</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.4</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-archiver</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.5.2</version> + <scope>compile</scope> + </dependency> + </dependencies> +</project> diff --git a/src/main/java/org/apache/sling/maven/jspc/JspCServletConfig.java b/src/main/java/org/apache/sling/maven/jspc/JspCServletConfig.java new file mode 100644 index 0000000..e741bfd --- /dev/null +++ b/src/main/java/org/apache/sling/maven/jspc/JspCServletConfig.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.sling.maven.jspc; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; + +public class JspCServletConfig implements ServletConfig { + + private final ServletContext servletContext; + + private String servletName; + + private final Map<String, String> properties; + + public JspCServletConfig(final ServletContext servletContext) { + this.servletContext = servletContext; + + this.servletName = "JSPC Script Handler"; + this.properties = new HashMap<String, String>(); + } + + public String getInitParameter(String name) { + return properties.get(name); + } + + public Enumeration<String> getInitParameterNames() { + return Collections.enumeration(properties.keySet()); + } + + public ServletContext getServletContext() { + return servletContext; + } + + public String getServletName() { + return servletName; + } +} \ No newline at end of file diff --git a/src/main/java/org/apache/sling/maven/jspc/JspCServletContext.java b/src/main/java/org/apache/sling/maven/jspc/JspCServletContext.java new file mode 100644 index 0000000..bf4897e --- /dev/null +++ b/src/main/java/org/apache/sling/maven/jspc/JspCServletContext.java @@ -0,0 +1,377 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.sling.maven.jspc; + +import java.io.File; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; + +import org.apache.maven.plugin.logging.Log; + +/** + * Simple <code>ServletContext</code> implementation without HTTP-specific + * methods. + * <p> + * This class has been copied from the JspCServletContext of the + * Jasper 5.5.20 distribution and reformated to match the formating rules of + * Sling. Additionally, the {@link #getResource(String)} method has special + * knowledge of the <em>/WEB-INF/web.xml</em> file, which is not required by + * the JspC plugin but by the TldLocationsCache. Hence this method simulates + * the <em>web.xml</em> with an embedded empty resource. + */ + +public class JspCServletContext implements ServletContext { + + /** + * The path of the standard <em>web.xml</em> file, which is handled by the + * embedded file by the {@link #getResource(String)} method (value is + * "/WEB-INF/web.xml"). + */ + private static final String WEB_XML = "/WEB-INF/web.xml"; + + /** + * Servlet context attributes. + */ + protected Hashtable<String, Object> attributes; + + /** + * The log writer we will write log messages to. + */ + protected Log log; + + /** + * The base URL (document root) for this context. + */ + protected URL resourceBaseURL; + + /** + * Create a new instance of this ServletContext implementation. + * + * @param log The Log which is used for <code>log()</code> calls + * @param resourceBaseURL Resource base URL + */ + public JspCServletContext(Log log, URL resourceBaseURL) { + attributes = new Hashtable<String, Object>(); + this.log = log; + this.resourceBaseURL = resourceBaseURL; + } + + // --------------------------------------------------------- Public Methods + + /** + * Return the specified context attribute, if any. + * + * @param name Name of the requested attribute + */ + public Object getAttribute(String name) { + return attributes.get(name); + } + + /** + * Return an enumeration of context attribute names. + */ + public Enumeration<String> getAttributeNames() { + return attributes.keys(); + } + + /** + * Return the servlet context for the specified path. + * + * @param uripath Server-relative path starting with '/' + */ + public ServletContext getContext(String uripath) { + return null; + } + + /** + * Return the specified context initialization parameter. + * + * @param name Name of the requested parameter + */ + public String getInitParameter(String name) { + return null; + } + + /** + * Return an enumeration of the names of context initialization parameters. + */ + public Enumeration<String> getInitParameterNames() { + return new Vector<String>().elements(); + } + + /** + * Return the Servlet API major version number. + */ + public int getMajorVersion() { + return 2; + } + + /** + * Return the MIME type for the specified filename. + * + * @param file Filename whose MIME type is requested + */ + public String getMimeType(String file) { + return null; + } + + /** + * Return the Servlet API minor version number. + */ + public int getMinorVersion() { + return 3; + } + + /** + * Return a request dispatcher for the specified servlet name. + * + * @param name Name of the requested servlet + */ + public RequestDispatcher getNamedDispatcher(String name) { + return null; + } + + /** + * Return the real path for the specified context-relative virtual path. + * + * @param path The context-relative virtual path to resolve + */ + public String getRealPath(String path) { + if (!resourceBaseURL.getProtocol().equals("file")) { + return null; + } + + if (!path.startsWith("/")) { + return null; + } + + try { + return getResource(path).getFile().replace('/', File.separatorChar); + } catch (Throwable t) { + return null; + } + } + + /** + * Return a request dispatcher for the specified context-relative path. + * + * @param path Context-relative path for which to acquire a dispatcher + */ + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + /** + * Return a URL object of a resource that is mapped to the specified + * context-relative path. + * + * @param path Context-relative path of the desired resource + * @exception MalformedURLException if the resource path is not properly + * formed + */ + public URL getResource(String path) throws MalformedURLException { + + // catch for dummy web.xml + if (WEB_XML.equals(path)) { + return this.getClass().getResource("web.xml"); + } + + if (!path.startsWith("/")) { + throw new MalformedURLException("Path '" + path + + "' does not start with '/'"); + } + + URL url = new URL(resourceBaseURL, path.substring(1)); + InputStream is = null; + try { + is = url.openStream(); + } catch (Throwable t) { + url = null; + } finally { + if (is != null) { + try { + is.close(); + } catch (Throwable t2) { + // Ignore + } + } + } + return url; + } + + /** + * Return an InputStream allowing access to the resource at the specified + * context-relative path. + * + * @param path Context-relative path of the desired resource + */ + public InputStream getResourceAsStream(String path) { + try { + return getResource(path).openStream(); + } catch (Throwable t) { + return null; + } + } + + /** + * Return the set of resource paths for the "directory" at the specified + * context path. + * + * @param path Context-relative base path + */ + public Set<String> getResourcePaths(String path) { + Set<String> thePaths = new HashSet<String>(); + + if (!path.endsWith("/")) { + path += "/"; + } + + String basePath = getRealPath(path); + if (basePath == null) { + return (thePaths); + } + + File theBaseDir = new File(basePath); + if (!theBaseDir.exists() || !theBaseDir.isDirectory()) { + return (thePaths); + } + + String theFiles[] = theBaseDir.list(); + for (int i = 0; i < theFiles.length; i++) { + File testFile = new File(basePath + File.separator + theFiles[i]); + if (testFile.isFile()) { + thePaths.add(path + theFiles[i]); + } else if (testFile.isDirectory()) { + thePaths.add(path + theFiles[i] + "/"); + } + } + + return thePaths; + } + + /** + * Return descriptive information about this server. + */ + public String getServerInfo() { + return "JspCServletContext/1.0"; + } + + /** + * Return a null reference for the specified servlet name. + * + * @param name Name of the requested servlet + * @deprecated This method has been deprecated with no replacement + */ + @Deprecated + public Servlet getServlet(String name) { + return null; + } + + /** + * Return the name of this servlet context. + */ + public String getServletContextName() { + return getServerInfo(); + } + + /** + * Return "/" as the context path for compilation. + */ + public String getContextPath() { + return "/"; + } + + /** + * Return an empty enumeration of servlet names. + * + * @deprecated This method has been deprecated with no replacement + */ + @Deprecated + public Enumeration<String> getServletNames() { + return new Vector<String>().elements(); + } + + /** + * Return an empty enumeration of servlets. + * + * @deprecated This method has been deprecated with no replacement + */ + @Deprecated + public Enumeration<Servlet> getServlets() { + return new Vector<Servlet>().elements(); + } + + /** + * Log the specified message. + * + * @param message The message to be logged + */ + public void log(String message) { + log.info(message); + } + + /** + * Log the specified message and exception. + * + * @param exception The exception to be logged + * @param message The message to be logged + * @deprecated Use log(String,Throwable) instead + */ + @Deprecated + public void log(Exception exception, String message) { + this.log(message, exception); + } + + /** + * Log the specified message and exception. + * + * @param message The message to be logged + * @param exception The exception to be logged + */ + public void log(String message, Throwable exception) { + log.error(message, exception); + } + + /** + * Remove the specified context attribute. + * + * @param name Name of the attribute to remove + */ + public void removeAttribute(String name) { + attributes.remove(name); + } + + /** + * Set or replace the specified context attribute. + * + * @param name Name of the context attribute to set + * @param value Corresponding attribute value + */ + public void setAttribute(String name, Object value) { + attributes.put(name, value); + } +} diff --git a/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java b/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java new file mode 100644 index 0000000..1ae3a38 --- /dev/null +++ b/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java @@ -0,0 +1,741 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.sling.maven.jspc; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.servlet.ServletContext; + +import org.apache.commons.logging.impl.LogFactoryImpl; +import org.apache.commons.logging.impl.SimpleLog; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.sling.scripting.jsp.jasper.JasperException; +import org.apache.sling.scripting.jsp.jasper.JspCompilationContext; +import org.apache.sling.scripting.jsp.jasper.Options; +import org.apache.sling.scripting.jsp.jasper.compiler.Compiler; +import org.apache.sling.scripting.jsp.jasper.compiler.JspConfig; +import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext; +import org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache; +import org.apache.sling.scripting.jsp.jasper.compiler.TagPluginManager; +import org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache; +import org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper; +import org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode; +import org.codehaus.plexus.util.DirectoryScanner; + +/** + * The <code>JspcMojo</code> is implements the Sling Maven JspC goal + * <code>jspc</code> compiling JSP into the target and creating a component + * descriptor for Declarative Services to use the JSP with the help of the + * appropriate adapter as component. + * + * @goal jspc + * @phase compile + * @description Compile JSP Files into Servlet Classes using the same JSP + * Compiler as is used at runtime to compile Repository based JSP + * into classes. + * @requiresDependencyResolution compile + */ +public class JspcMojo extends AbstractMojo implements Options { + + /** + * The Maven project. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * Location of JSP source files. + * + * @parameter expression="${jspc.sourceDirectory}" + * default-value="${project.build.scriptSourceDirectory}" + */ + private File sourceDirectory; + + /** + * Target folder for the compiled classes. + * + * @parameter expression="${jspc.outputDirectory}" + * default-value="${project.build.outputDirectory}" + * @required + */ + private String outputDirectory; + + /** + * @parameter expression="${jspc.jasper.classdebuginfo}" + * default-value="true" + */ + private boolean jasperClassDebugInfo; + + /** + * @parameter expression="${jspc.jasper.enablePooling}" default-value="true" + */ + private boolean jasperEnablePooling; + + /** + * @parameter expression="${jspc.jasper.ieClassId}" + * default-value="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" + */ + private String jasperIeClassId; + + /** + * @parameter expression="${jspc.jasper.genStringAsCharArray}" + * default-value="false" + */ + private boolean jasperGenStringAsCharArray; + + /** + * @parameter expression="${jspc.jasper.keepgenerated}" default-value="true" + */ + private boolean jasperKeepGenerated; + + /** + * @parameter expression="${jspc.jasper.mappedfile}" default-value="true" + */ + private boolean jasperMappedFile; + + /** + * @parameter expression="${jspc.jasper.trimSpaces}" default-value="false" + */ + private boolean jasperTrimSpaces; + + /** + * @parameter expression="${jspc.failOnError}" default-value="true" + */ + private boolean failOnError; + + /** + * @parameter expression="${jspc.showSuccess}" default-value="false" + */ + private boolean showSuccess; + + /** + * @parameter expression="${jspc.compilerTargetVM}" default-value="1.5" + */ + private String compilerTargetVM; + + /** + * @parameter expression="${jspc.compilerSourceVM}" default-value="1.5" + */ + private String compilerSourceVM; + + /** + * Comma separated list of extensions of files to be compiled by the plugin. + * + * @parameter expression="${jspc.jspFileExtensions}" + * default-value="jsp,jspx" + */ + private String jspFileExtensions; + + /** + * @parameter expression="${jspc.servletPackage}" + * default-value="org.apache.jsp" + */ + private String servletPackage; + + /** + * Included JSPs, defaults to <code>"**/*.jsp"</code> + * @parameter + */ + private String[] includes; + + /** + * Excluded JSPs, empty by default + * @parameter + */ + private String[] excludes; + + private Set<String> jspFileExtensionSet; + + private boolean compile = true; + + private String uriSourceRoot; + + private List<String> pages = new ArrayList<String>(); + + private ServletContext context; + + private JspRuntimeContext rctxt; + + private URLClassLoader loader = null; + + private Map<String, TreeNode> tldCache; + + /** + * Cache for the TLD locations + */ + private TldLocationsCache tldLocationsCache = null; + + private JspConfig jspConfig = null; + + private TagPluginManager tagPluginManager = null; + + /* + * (non-Javadoc) + * + * @see org.apache.maven.plugin.Mojo#execute() + */ + public void execute() throws MojoExecutionException { + + try { + uriSourceRoot = sourceDirectory.getCanonicalPath(); + } catch (Exception e) { + uriSourceRoot = sourceDirectory.getAbsolutePath(); + } + + // ensure output directory + File outputDirectoryFile = new File(outputDirectory); + if (!outputDirectoryFile.isDirectory()) { + if (outputDirectoryFile.exists()) { + throw new MojoExecutionException(outputDirectory + + " exists but is not a directory"); + } + + if (!outputDirectoryFile.mkdirs()) { + throw new MojoExecutionException( + "Cannot create output directory " + outputDirectory); + } + } + + // have the files compiled + String oldValue = System.getProperty(LogFactoryImpl.LOG_PROPERTY); + try { + // ensure the JSP Compiler does not try to use Log4J + System.setProperty(LogFactoryImpl.LOG_PROPERTY, + SimpleLog.class.getName()); + + executeInternal(); + } catch (JasperException je) { + getLog().error("Compilation Failure", je); + throw new MojoExecutionException(je.getMessage(), je); + } finally { + if (oldValue == null) { + System.clearProperty(LogFactoryImpl.LOG_PROPERTY); + } else { + System.setProperty(LogFactoryImpl.LOG_PROPERTY, oldValue); + } + } + + project.addCompileSourceRoot(outputDirectory); + } + + /** + * Locate all jsp files in the webapp. Used if no explicit jsps are + * specified. + */ + public void scanFiles(File base) { + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(base); + scanner.setIncludes(includes); + scanner.setExcludes(excludes); + scanner.scan(); + + for (String included : scanner.getIncludedFiles()) { + pages.add(included); + } + } + + /** + * Executes the compilation. + * + * @throws JasperException If an error occurs + */ + private void executeInternal() throws JasperException { + if (getLog().isDebugEnabled()) { + getLog().debug("execute() starting for " + pages.size() + " pages."); + } + + try { + if (context == null) { + initServletContext(); + } + + if (includes == null) { + includes = new String[]{ "**/*.jsp" }; + } + + // No explicit pages, we'll process all .jsp in the webapp + if (pages.size() == 0) { + scanFiles(sourceDirectory); + } + + File uriRootF = new File(uriSourceRoot); + if (!uriRootF.exists() || !uriRootF.isDirectory()) { + throw new JasperException("The source location '" + + uriSourceRoot + "' must be an existing directory"); + } + + for (String nextjsp : pages) { + File fjsp = new File(nextjsp); + if (!fjsp.isAbsolute()) { + fjsp = new File(uriRootF, nextjsp); + } + if (!fjsp.exists()) { + if (getLog().isWarnEnabled()) { + getLog().warn("JSP file " + fjsp + " does not exist"); + } + continue; + } + String s = fjsp.getAbsolutePath(); + if (s.startsWith(uriSourceRoot)) { + nextjsp = s.substring(uriSourceRoot.length()); + } + if (nextjsp.startsWith("." + File.separatorChar)) { + nextjsp = nextjsp.substring(2); + } + + processFile(nextjsp); + } + + } catch (JasperException je) { + Throwable rootCause = je; + while (rootCause instanceof JasperException + && ((JasperException) rootCause).getRootCause() != null) { + rootCause = ((JasperException) rootCause).getRootCause(); + } + if (rootCause != je) { + rootCause.printStackTrace(); + } + throw je; + + } catch (/* IO */Exception ioe) { + throw new JasperException(ioe); + } + } + + private void processFile(final String file) throws JasperException { + ClassLoader originalClassLoader = null; + + try { + final String jspUri = file.replace('\\', '/'); + final JspServletWrapper wrapper = new JspServletWrapper(new JspCServletConfig(context), this, jspUri, + false, rctxt); + + final JspCompilationContext clctxt = new JspCompilationContext(jspUri, + false, this, context, wrapper, rctxt); + + // write to a specific servlet package + clctxt.setServletPackageName(servletPackage); + + originalClassLoader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + initClassLoader(); + } + Thread.currentThread().setContextClassLoader(loader); + + Compiler clc = clctxt.createCompiler(); + + // If compile is set, generate both .java and .class, if + // .jsp file is newer than .class file; + // Otherwise only generate .java, if .jsp file is newer than + // the .java file + if (clc.isOutDated(compile)) { + clc.compile(compile, true); + + if (showSuccess) { + getLog().info("Built File: " + file); + } + } else if (showSuccess) { + getLog().info("File up to date: " + file); + } + + } catch (final JasperException je) { + Throwable rootCause = je; + while (rootCause instanceof JasperException + && ((JasperException) rootCause).getRootCause() != null) { + rootCause = ((JasperException) rootCause).getRootCause(); + } + if (rootCause != je) { + getLog().error("General problem compiling " + file, rootCause); + } + + // Bugzilla 35114. + if (failOnError) { + throw je; + } + + // just log otherwise + getLog().error(je.getMessage()); + + } catch (Exception e) { + if ((e instanceof FileNotFoundException) + && getLog().isWarnEnabled()) { + getLog().warn("Missing file: " + e.getMessage()); + } + throw new JasperException(e); + } finally { + if (originalClassLoader != null) { + Thread.currentThread().setContextClassLoader( + originalClassLoader); + } + } + } + + // ---------- Additional Settings ------------------------------------------ + + private Set<String> getExtensions() { + if (jspFileExtensionSet == null) { + jspFileExtensionSet = new HashSet<String>(); + + // fallback default value, should actually be set by Maven + if (jspFileExtensions == null) { + jspFileExtensions = "jsp,jspx"; + } + + StringTokenizer st = new StringTokenizer(jspFileExtensions, ","); + while (st.hasMoreTokens()) { + String ext = st.nextToken().trim(); + if (ext.length() > 0) { + jspFileExtensionSet.add(ext); + } + } + } + + return jspFileExtensionSet; + } + + private void initServletContext() { + try { + context = new JspCServletContext(getLog(), new URL("file:" + + uriSourceRoot.replace('\\', '/') + '/')); + tldLocationsCache = new OriginalTldLocationsCache(context, true); + } catch (MalformedURLException me) { + getLog().error("Cannot setup ServletContext", me); + } + + rctxt = new JspRuntimeContext(context, this); + jspConfig = new JspConfig(context); + tagPluginManager = new TagPluginManager(context); + } + + /** + * Initializes the classloader as/if needed for the given compilation + * context. + * + * @param clctxt The compilation context + * @throws IOException If an error occurs + */ + private void initClassLoader() throws IOException, + DependencyResolutionRequiredException { + List artifacts = project.getCompileArtifacts(); + URL[] path = new URL[artifacts.size() + 1]; + int i = 0; + for (Iterator ai=artifacts.iterator(); ai.hasNext(); ) { + Artifact a = (Artifact) ai.next(); + path[i++] = a.getFile().toURI().toURL(); + } + final String targetDirectory = project.getBuild().getOutputDirectory(); + path[path.length - 1] = new File(targetDirectory).toURI().toURL(); + loader = new URLClassLoader(path, this.getClass().getClassLoader()); + } + + // ---------- Options interface -------------------------------------------- + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#genStringAsCharArray() + */ + public boolean genStringAsCharArray() { + return jasperGenStringAsCharArray; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#isCaching() + */ + public boolean isCaching() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getCache() + */ + public Map<String, TreeNode> getCache() { + if (tldCache == null) { + tldCache = new HashMap<String, TreeNode>(); + } + + return tldCache; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getCheckInterval() + */ + public int getCheckInterval() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getClassDebugInfo() + */ + public boolean getClassDebugInfo() { + return jasperClassDebugInfo; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getClassPath() + */ + public String getClassPath() { + // no extra classpath + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getCompiler() + */ + public String getCompiler() { + // use JDTCompiler, which is the default + return null; + } + + public String getCompilerClassName() { + // use JDTCompiler, which is the default + return null; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getCompilerSourceVM() + */ + public String getCompilerSourceVM() { + return compilerSourceVM; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getCompilerTargetVM() + */ + public String getCompilerTargetVM() { + return compilerTargetVM; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getDevelopment() + */ + public boolean getDevelopment() { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getErrorOnUseBeanInvalidClassAttribute() + */ + public boolean getErrorOnUseBeanInvalidClassAttribute() { + // not configurable + return true; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getFork() + */ + public boolean getFork() { + // certainly don't fork (not required anyway) + return false; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getIeClassId() + */ + public String getIeClassId() { + return jasperIeClassId; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getJavaEncoding() + */ + public String getJavaEncoding() { + return "UTF-8"; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getJspClassLoader() + */ + public ClassLoader getJspClassLoader() { + return this.loader; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getJspConfig() + */ + public JspConfig getJspConfig() { + return jspConfig; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getKeepGenerated() + */ + public boolean getKeepGenerated() { + return jasperKeepGenerated; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getMappedFile() + */ + public boolean getMappedFile() { + return jasperMappedFile; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getModificationTestInterval() + */ + public int getModificationTestInterval() { + return 0; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getScratchDir() + */ + public String getScratchDir() { + return outputDirectory; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getSendErrorToClient() + */ + public boolean getSendErrorToClient() { + // certainly output any problems + return true; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getTagPluginManager() + */ + public TagPluginManager getTagPluginManager() { + return tagPluginManager; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getTldLocationsCache() + */ + public TldLocationsCache getTldLocationsCache() { + return tldLocationsCache; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#getTrimSpaces() + */ + public boolean getTrimSpaces() { + return jasperTrimSpaces; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#isPoolingEnabled() + */ + public boolean isPoolingEnabled() { + return jasperEnablePooling; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#isSmapDumped() + */ + public boolean isSmapDumped() { + // always include the SMAP (optionally, limit to if debugging) + return true; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#isSmapSuppressed() + */ + public boolean isSmapSuppressed() { + // require SMAP + return false; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jasper.Options#isXpoweredBy() + */ + public boolean isXpoweredBy() { + // no XpoweredBy setting please + return false; + } + + public boolean getDisplaySourceFragment() { + // Display the source fragment on errors for maven compilation + return true; + } +} diff --git a/src/main/resources/org/apache/sling/maven/jspc/web.xml b/src/main/resources/org/apache/sling/maven/jspc/web.xml new file mode 100644 index 0000000..e5f65a6 --- /dev/null +++ b/src/main/resources/org/apache/sling/maven/jspc/web.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +--> +<web-app version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <!-- This empty file exists to satisfy the JSP Compiler --> +</web-app> -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
