Search in sources :

Example 41 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspcMojo method execute.

/*
     * (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();
        if (printCompilationReport) {
            printCompilationReport();
        }
    } 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);
}
Also used : SimpleLog(org.apache.commons.logging.impl.SimpleLog) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

Example 42 with JasperException

use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.

the class JspcMojo method executeInternal.

/**
     * 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);
    }
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

Aggregations

JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)42 IOException (java.io.IOException)31 ServletException (javax.servlet.ServletException)19 PrivilegedActionException (java.security.PrivilegedActionException)17 Method (java.lang.reflect.Method)14 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)6 Iterator (java.util.Iterator)6 InputStream (java.io.InputStream)5 JarFile (java.util.jar.JarFile)5 TagInfo (javax.servlet.jsp.tagext.TagInfo)4 TreeNode (org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode)4 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2