You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/12/05 20:41:36 UTC

svn commit: r601485 - in /incubator/sling/trunk/maven/maven-jspc-plugin: pom.xml src/main/java/org/apache/sling/maven/jspc/JspcMojo.java

Author: fmeschbe
Date: Wed Dec  5 11:41:36 2007
New Revision: 601485

URL: http://svn.apache.org/viewvc?rev=601485&view=rev
Log:
Retarget the plugin to the new Sling JSP project which uses a modified
and refactored Jasper 6.0.14 compiler underneath. Plus do not write the
OSGi Service Component descriptor anymore as the JSP classes are loaded
by the JSP project.

Modified:
    incubator/sling/trunk/maven/maven-jspc-plugin/pom.xml
    incubator/sling/trunk/maven/maven-jspc-plugin/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java

Modified: incubator/sling/trunk/maven/maven-jspc-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/maven/maven-jspc-plugin/pom.xml?rev=601485&r1=601484&r2=601485&view=diff
==============================================================================
--- incubator/sling/trunk/maven/maven-jspc-plugin/pom.xml (original)
+++ incubator/sling/trunk/maven/maven-jspc-plugin/pom.xml Wed Dec  5 11:41:36 2007
@@ -61,21 +61,22 @@
 
     <dependencies>
 
-        <!-- Dependencies for JSP Compiler -->
         <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.jsp</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
-            <artifactId>jsp-api</artifactId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>sling-jasper-sling</artifactId>
-            <version>2.0.0-incubator-SNAPSHOT</version>
+            <groupId>javax.servlet.jsp</groupId>
+            <artifactId>jsp-api</artifactId>
+            <version>2.1</version>
             <scope>compile</scope>
         </dependency>
 

Modified: incubator/sling/trunk/maven/maven-jspc-plugin/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/maven/maven-jspc-plugin/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java?rev=601485&r1=601484&r2=601485&view=diff
==============================================================================
--- incubator/sling/trunk/maven/maven-jspc-plugin/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java (original)
+++ incubator/sling/trunk/maven/maven-jspc-plugin/src/main/java/org/apache/sling/maven/jspc/JspcMojo.java Wed Dec  5 11:41:36 2007
@@ -18,12 +18,7 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -41,20 +36,19 @@
 
 import org.apache.commons.logging.impl.LogFactoryImpl;
 import org.apache.commons.logging.impl.SimpleLog;
-import org.apache.jasper.JasperException;
-import org.apache.jasper.JspCompilationContext;
-import org.apache.jasper.Options;
-import org.apache.jasper.compiler.Compiler;
-import org.apache.jasper.compiler.JspConfig;
-import org.apache.jasper.compiler.JspRuntimeContext;
-import org.apache.jasper.compiler.TagPluginManager;
-import org.apache.jasper.compiler.TldLocationsCache;
-import org.apache.jasper.xmlparser.TreeNode;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.model.Resource;
 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.TagPluginManager;
+import org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache;
+import org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode;
 
 /**
  * The <code>JspcMojo</code> is implements the Sling Maven JspC goal
@@ -208,8 +202,19 @@
             uriSourceRoot = new File(sourceDirectory).getAbsolutePath();
         }
 
-        // scan all JSP file
-        // scanFiles(new File(sourceDirectory));
+        // 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);
@@ -271,8 +276,6 @@
             getLog().debug("execute() starting for " + pages.size() + " pages.");
         }
 
-        StringWriter serviceComponentWriter = new StringWriter();
-
         try {
             if (context == null) {
                 initServletContext();
@@ -308,11 +311,9 @@
                     nextjsp = nextjsp.substring(2);
                 }
 
-                processFile(nextjsp, serviceComponentWriter);
+                processFile(nextjsp);
             }
 
-            printServiceComponents(serviceComponentWriter);
-
         } catch (JasperException je) {
             Throwable rootCause = je;
             while (rootCause instanceof JasperException
@@ -329,8 +330,7 @@
         }
     }
 
-    private void processFile(String file, Writer serviceComponentWriter)
-            throws JasperException {
+    private void processFile(String file) throws JasperException {
         ClassLoader originalClassLoader = null;
 
         try {
@@ -367,11 +367,6 @@
                 getLog().info("File up to date: " + file);
             }
 
-            // write the OSGi component descriptor
-            writeJspServiceComponent(serviceComponentWriter, jspUri,
-                clctxt.getServletPackageName() + "."
-                    + clctxt.getServletClassName());
-
             // remove the java source and smap file
             new File(clctxt.getClassFileName() + ".smap").delete();
             new File(clctxt.getServletJavaFileName()).delete();
@@ -468,99 +463,6 @@
         loader = new URLClassLoader(urlsA, getClass().getClassLoader());
     }
 
-    private void writeJspServiceComponent(Writer out, String componentName,
-            String className) {
-
-        try {
-            out.write("<scr:component enabled=\"true\" immediate=\"true\" name=\"");
-            out.write(componentName);
-            out.write("\">\r\n");
-
-            // the implementation is of course the compiled JSP
-            out.write("<scr:implementation class=\"");
-            out.write(className);
-            out.write("\"/>\r\n");
-
-            // the JSP registers as a Servlet
-            out.write("<scr:service>\r\n");
-            out.write("<scr:provide interface=\"javax.servlet.Servlet\"/>\r\n");
-            out.write("</scr:service>\r\n");
-
-            // use the JSP's id as the service.pid
-            out.write("<scr:property name=\"service.pid\" value=\"");
-            out.write(componentName);
-            out.write("\"/>\r\n");
-
-            // if the project defines an organization name, add it
-            if (project.getOrganization() != null
-                && project.getOrganization().getName() != null) {
-                out.write("<scr:property name=\"service.vendor\" value=\"");
-                out.write(project.getOrganization().getName());
-                out.write("\"/>\r\n");
-            }
-
-            out.write("</scr:component>\r\n");
-
-            out.flush();
-        } catch (IOException ignore) {
-            // don't care
-        }
-    }
-
-    private void printServiceComponents(StringWriter serviceComponentWriter)
-            throws IOException {
-        FileOutputStream out = null;
-        try {
-
-            String target = "OSGI-INF/jspServiceComponents.xml";
-            File targetFile = new File(outputDirectory, target);
-            targetFile.getParentFile().mkdirs();
-
-            out = new FileOutputStream(targetFile);
-            PrintWriter pw = new PrintWriter(new OutputStreamWriter(out,
-                "UTF-8"));
-
-            pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-            pw.println("<components xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.0.0\">");
-
-            pw.print(serviceComponentWriter.toString());
-
-            pw.println("</components>");
-
-            pw.flush();
-            pw.close();
-
-            // now add the descriptor file to the maven resources
-            final String ourRsrcPath = new File(outputDirectory).getAbsolutePath();
-            boolean found = false;
-            final Iterator<?> rsrcIterator = project.getResources().iterator();
-            while (!found && rsrcIterator.hasNext()) {
-                final Resource rsrc = (Resource) rsrcIterator.next();
-                found = rsrc.getDirectory().equals(ourRsrcPath);
-            }
-            if (!found) {
-                final Resource resource = new Resource();
-                resource.setDirectory(new File(outputDirectory).getAbsolutePath());
-                project.addResource(resource);
-            }
-
-            // and set include accordingly
-            String svcComp = project.getProperties().getProperty(
-                "Service-Component");
-            svcComp = (svcComp == null) ? target : svcComp + ", " + target;
-            project.getProperties().setProperty("Service-Component", svcComp);
-
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException ignore) {
-                    // don't care
-                }
-            }
-        }
-    }
-
     // ---------- Options interface --------------------------------------------
 
     /*
@@ -632,6 +534,11 @@
         return null;
     }
 
+    public String getCompilerClassName() {
+        // use JDTCompiler, which is the default
+        return null;
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -826,5 +733,10 @@
     public boolean isXpoweredBy() {
         // no XpoweredBy setting please
         return false;
+    }
+
+    public boolean getDisplaySourceFragment() {
+        // Display the source fragment on errors for maven compilation
+        return true;
     }
 }