Search in sources :

Example 1 with FileResourceStore

use of com.opensymphony.xwork2.util.classloader.FileResourceStore in project struts by apache.

the class ClassReloadingXMLWebApplicationContext method setupReloading.

public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext, boolean reloadConfig) {
    this.reloadConfig = reloadConfig;
    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<>(splitted.length);
        for (String pattern : splitted) patterns.add(Pattern.compile(pattern));
        classLoader.setAccepClasses(patterns);
    }
    filesystemAlterationMonitor = 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 filesystemAlterationMonitor
            filesystemAlterationMonitor.addListener(file, this);
            LOG.debug("Watching [{}] for changes", file.getAbsolutePath());
        } else {
            // get all subdirs
            List<File> dirs = new ArrayList<>();
            getAllPaths(file, dirs);
            classLoader.addResourceStore(new FileResourceStore(file));
            for (File dir : dirs) {
                // register with the filesystemAlterationMonitor
                filesystemAlterationMonitor.addListener(dir, this);
                LOG.debug("Watching [{}] for changes", dir.getAbsolutePath());
            }
        }
    }
    // setup the bean factory
    beanFactory = new ClassReloadingBeanFactory();
    beanFactory.setInstantiationStrategy(new ClassReloadingInstantiationStrategy());
    beanFactory.setBeanClassLoader(classLoader);
    // start watch thread
    filesystemAlterationMonitor.start();
}
Also used : Pattern(java.util.regex.Pattern) FileResourceStore(com.opensymphony.xwork2.util.classloader.FileResourceStore) ArrayList(java.util.ArrayList) ReloadingClassLoader(com.opensymphony.xwork2.util.classloader.ReloadingClassLoader) FilesystemAlterationMonitor(org.apache.commons.jci.monitor.FilesystemAlterationMonitor) JarResourceStore(com.opensymphony.xwork2.util.classloader.JarResourceStore) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

FileResourceStore (com.opensymphony.xwork2.util.classloader.FileResourceStore)1 JarResourceStore (com.opensymphony.xwork2.util.classloader.JarResourceStore)1 ReloadingClassLoader (com.opensymphony.xwork2.util.classloader.ReloadingClassLoader)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Pattern (java.util.regex.Pattern)1 FilesystemAlterationMonitor (org.apache.commons.jci.monitor.FilesystemAlterationMonitor)1