Return-Path: Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: (qmail 76676 invoked from network); 13 Jul 2009 16:58:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Jul 2009 16:58:29 -0000 Received: (qmail 81835 invoked by uid 500); 13 Jul 2009 16:58:38 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 81788 invoked by uid 500); 13 Jul 2009 16:58:38 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 81778 invoked by uid 99); 13 Jul 2009 16:58:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Jul 2009 16:58:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Jul 2009 16:58:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0F1FD23888CC; Mon, 13 Jul 2009 16:58:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@struts.apache.org From: musachy@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090713165809.0F1FD23888CC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ *
  • Set "struts.devMode" to "true"
  • *
  • Set "struts.class.reloading.watchList" to a comma separated list of directories, or jar files (absolute paths)

    *
  • Add this to web.xml: - *
    + * 
      *  <context-param>
      *       <param-name>contextClass</param-name>
      *       <param-value>org.apache.struts2.spring.ClassReloadingXMLWebApplicationContext</param-value>
    @@ -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 patterns = new HashSet(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