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);
}
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);
}
}
Aggregations