struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r793626 - in /struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring: ClassReloadingXMLWebApplicationContext.java StrutsSpringObjectFactory.java
Date Mon, 13 Jul 2009 16:58:08 GMT
Author: musachy
Date: Mon Jul 13 16:58:08 2009
New Revision: 793626

URL: http://svn.apache.org/viewvc?rev=793626&view=rev
Log:
add a constant to limit the classes that can be loaded by the reloading class loader, support
relative paths

Modified:
    struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
    struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java

Modified: struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java?rev=793626&r1=793625&r2=793626&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
(original)
+++ struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
Mon Jul 13 16:58:08 2009
@@ -28,14 +28,19 @@
 import org.apache.commons.jci.monitor.FilesystemAlterationListener;
 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
+import org.apache.commons.lang.xwork.StringUtils;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.BeansException;
 
+import javax.servlet.ServletContext;
 import java.io.File;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.regex.Pattern;
 
 /**
  * This class can be used instead of XmlWebApplicationContext, and it will watch jar files
and directories for changes
@@ -46,7 +51,7 @@
  * <li>Set "struts.devMode" to "true" </li>
  * <li>Set "struts.class.reloading.watchList" to a comma separated list of directories,
or jar files (absolute paths)</p>
  * <li>Add this to web.xml:
- *  <pre>
+ * <pre>
  *  &lt;context-param&gt;
  *       &lt;param-name&gt;contextClass&lt;/param-name&gt;
  *       &lt;param-value&gt;org.apache.struts2.spring.ClassReloadingXMLWebApplicationContext&lt;/param-value&gt;
@@ -67,18 +72,34 @@
 public class ClassReloadingXMLWebApplicationContext extends XmlWebApplicationContext implements
FilesystemAlterationListener {
     private static final Logger LOG = LoggerFactory.getLogger(ClassReloadingXMLWebApplicationContext.class);
 
-    private ReloadingClassLoader classLoader;
-    private FilesystemAlterationMonitor fam;
+    protected ReloadingClassLoader classLoader;
+    protected FilesystemAlterationMonitor fam;
 
-    private ClassReloadingBeanFactory beanFactory;
+    protected ClassReloadingBeanFactory beanFactory;
 
-    public void setupReloading(String[] watchList) {
+    public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext)
{
         classLoader = new ReloadingClassLoader(ClassReloadingXMLWebApplicationContext.class.getClassLoader());
+
+        //make a list of accepted classes
+        if (StringUtils.isNotBlank(acceptClasses)) {
+            String[] splitted =  acceptClasses.split(",");
+            Set<Pattern> patterns = new HashSet<Pattern>(splitted.length);
+            for (String pattern : splitted)
+                patterns.add(Pattern.compile(pattern));
+
+            classLoader.setAccepClasses(patterns);
+        }
+
         fam = new FilesystemAlterationMonitor();
 
         //setup stores
         for (String watch : watchList) {
             File file = new File(watch);
+
+            //make it absolute, if it is a relative path
+            if (!file.isAbsolute())
+                file = new File(servletContext.getRealPath(watch));
+
             if (watch.endsWith(".jar")) {
                 classLoader.addResourceStore(new JarResourceStore(file));
                 //register with the fam
@@ -157,6 +178,8 @@
     }
 
     public void onDirectoryCreate(File file) {
+        if (classLoader != null)
+            classLoader.reload();
     }
 
     public void onDirectoryDelete(File file) {
@@ -168,6 +191,8 @@
     }
 
     public void onFileCreate(File file) {
+        if (classLoader != null)
+            classLoader.reload();
     }
 
     public void onFileDelete(File file) {

Modified: struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java?rev=793626&r1=793625&r2=793626&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
(original)
+++ struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
Mon Jul 13 16:58:08 2009
@@ -68,7 +68,8 @@
             @Inject(value=StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE,required=false)
String useClassCacheStr,
             @Inject ServletContext servletContext,
             @Inject(StrutsConstants.STRUTS_DEVMODE) String devMode,
-            @Inject(value = "struts.class.reloading.watchList", required = false) String
watchList) {
+            @Inject(value = "struts.class.reloading.watchList", required = false) String
watchList,
+            @Inject(value = "struts.class.reloading.acceptClasses", required = false) String
acceptClasses) {
           
         super();
         boolean useClassCache = "true".equals(useClassCacheStr);
@@ -94,7 +95,7 @@
                 && StringUtils.isNotBlank(watchList)
                 && appContext instanceof ClassReloadingXMLWebApplicationContext)
{
             ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext)
appContext;
-            reloadingContext.setupReloading(watchList.split(","));
+            reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext);
             LOG.info("Class reloading is enabled. Make sure this is not used on a production
environment!", watchList);
 
             //we need to reload the context, so our isntance of the factory is picked up



Mime
View raw message