Author: musachy
Date: Fri Aug 14 17:17:31 2009
New Revision: 804302

URL: http://svn.apache.org/viewvc?rev=804302&view=rev
Log:
Improve classpath building and add "bean" test

Added:
    
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/SoyBean.java
    
struts/sandbox/trunk/struts2-jsp-plugin/src/test/resources/org/apache/struts2/beans.jsp
Modified:
    
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
    
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java

Modified: 
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java?rev=804302&r1=804301&r2=804302&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
 (original)
+++ 
struts/sandbox/trunk/struts2-jsp-plugin/src/main/java/org/apache/struts2/JSPLoader.java
 Fri Aug 14 17:17:31 2009
@@ -59,7 +59,6 @@
  */
 public class JSPLoader {
     private static final Logger LOG = LoggerFactory.getLogger(JSPLoader.class);
-    public static final File JSP_DIR = new 
File(System.getProperty("java.io.tmpdir"), "struts_jsps");
 
     private static MemoryClassLoader classLoader = new MemoryClassLoader();
     private static final String DEFAULT_PACKAGE = "org.apache.struts2.jsp";
@@ -148,12 +147,14 @@
         };
 
         //build classpath
+        //some entries will be added multiple times, hence the set
         List<String> optionList = new ArrayList<String>();
         Set<String> classPath = new HashSet<String>();
 
         //find available jars
-        UrlSet urlSet = new UrlSet(getClassLoaderInterface());
-        urlSet = urlSet.matching(".*?\\.jar(!/)?$");
+        ClassLoaderInterface classLoaderInterface = getClassLoaderInterface();
+        UrlSet urlSet = new UrlSet(classLoaderInterface);
+
         List<URL> urls = urlSet.getUrls();
         if (urls != null) {
             for (URL url : urls) {
@@ -162,13 +163,20 @@
             }
         }
 
-
-        //this jar
-        classPath.add(getJarUrl(EmbeddedJSPResult.class));
-        //servlet api
-        classPath.add(getJarUrl(Servlet.class));
-        //jsp api
-        classPath.add(getJarUrl(JspPage.class));
+        //UrlSet searches for dirs that end in WEB-INF/classes, so when 
running test
+        //from maven, it won't find test-classes dir
+        //find directories in the classpath
+        Enumeration<URL> rootUrls = classLoaderInterface.getResources("");
+        while (rootUrls.hasMoreElements()) {
+            URL url = rootUrls.nextElement();
+            URL normalized = URLUtil.normalizeToFileProtocol(url);
+            if (normalized == null) {
+                //this means that it is directory, not a jar, double check
+                File file = FileUtils.toFile(url);
+                if (file.exists() && file.isDirectory())
+                    classPath.add(file.getAbsolutePath());
+            }
+        }
 
         //add extra classpath entries (jars where tlds were found will be here)
         for (Iterator<String> iterator = extraClassPath.iterator(); 
iterator.hasNext();) {
@@ -176,8 +184,12 @@
             classPath.add(entry);
         }
 
-        optionList.addAll(Arrays.asList("-classpath", 
StringUtils.join(classPath, ";")));
+        String classPathString = StringUtils.join(classPath, ";");
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Compiling [#0] with classpath [#1]", className, 
classPathString);
+        }
 
+        optionList.addAll(Arrays.asList("-classpath", classPathString));
 
         //compile
         JavaCompiler.CompilationTask task = compiler.getTask(

Modified: 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java?rev=804302&r1=804301&r2=804302&view=diff
==============================================================================
--- 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java
 (original)
+++ 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java
 Fri Aug 14 17:17:31 2009
@@ -147,6 +147,13 @@
         }
     }
 
+     public void testBeans() throws Exception {
+        result.setLocation("org/apache/struts2/beans.jsp");
+        result.execute(null);
+
+        assertEquals("WhoamI?", cleanup(response.getContentAsString()));
+    }
+
     private String cleanup(String str) {
         return str.replaceAll("\\s", "");
     }
@@ -204,9 +211,6 @@
         actionContext.setValueStack(valueStack);
 
         //XWorkConverter conv = 
((Container)stack.getContext().get(ActionContext.CONTAINER)).getInstance(XWorkConverter.class);
-
-        if (JSPLoader.JSP_DIR.exists())
-            FileUtils.forceDelete(JSPLoader.JSP_DIR);
     }
 }
 

Added: 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/SoyBean.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/SoyBean.java?rev=804302&view=auto
==============================================================================
--- 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/SoyBean.java
 (added)
+++ 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/java/org/apache/struts2/SoyBean.java
 Fri Aug 14 17:17:31 2009
@@ -0,0 +1,33 @@
+/*
+ * $Id$
+ *
+ * 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.struts2;
+
+public class SoyBean {
+    private String message = "Who am I?";
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

Added: 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/resources/org/apache/struts2/beans.jsp
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-jsp-plugin/src/test/resources/org/apache/struts2/beans.jsp?rev=804302&view=auto
==============================================================================
--- 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/resources/org/apache/struts2/beans.jsp
 (added)
+++ 
struts/sandbox/trunk/struts2-jsp-plugin/src/test/resources/org/apache/struts2/beans.jsp
 Fri Aug 14 17:17:31 2009
@@ -0,0 +1,2 @@
+<jsp:useBean id="mybean" class="org.apache.struts2.SoyBean" scope="page" />
+<jsp:getProperty name="mybean" property="message" />


Reply via email to