[jboss-cvs] JBossAS SVN: r92379 - in projects/jboss-deployers/trunk: deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 14 11:17:26 EDT 2009
Author: alesj
Date: 2009-08-14 11:17:25 -0400 (Fri, 14 Aug 2009)
New Revision: 92379
Removed:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractResourceMatcher.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/PathMatcher.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/PathMatchersResourceFilter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/ExposedPMRFilter.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/PathMatchersTestCase.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/VFSMatchersTestSuite.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java
Log:
[JBDEPLOY-210]; move StructureCache to VirtualFile's as keys.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/VFSMatchersTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/VFSMatchersTestSuite.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/VFSMatchersTestSuite.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -26,7 +26,6 @@
import junit.textui.TestRunner;
import org.jboss.test.deployers.vfs.matchers.test.FileMatchersTestCase;
import org.jboss.test.deployers.vfs.matchers.test.JarExtensionsTestCase;
-import org.jboss.test.deployers.vfs.matchers.test.PathMatchersTestCase;
/**
* Matchers test suite.
@@ -45,7 +44,6 @@
TestSuite suite = new TestSuite("VFS Matchers Tests");
suite.addTest(FileMatchersTestCase.suite());
- suite.addTest(PathMatchersTestCase.suite());
suite.addTest(JarExtensionsTestCase.suite());
return suite;
Deleted: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/ExposedPMRFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/ExposedPMRFilter.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/ExposedPMRFilter.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,65 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.deployers.vfs.matchers.support;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.beans.metadata.api.annotations.Install;
-import org.jboss.beans.metadata.api.annotations.Uninstall;
-import org.jboss.deployers.vfs.spi.deployer.PathMatcher;
-import org.jboss.deployers.vfs.spi.structure.modified.PathMatchersResourceFilter;
-import org.jboss.virtual.VirtualFileFilter;
-
-/**
- * Exposes matchers.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class ExposedPMRFilter extends PathMatchersResourceFilter
-{
- protected Set<PathMatcher> matchers = new HashSet<PathMatcher>();
-
- public ExposedPMRFilter(VirtualFileFilter delegate)
- {
- super(delegate);
- }
-
- public Set<PathMatcher> getMatchers()
- {
- return matchers;
- }
-
- @Install
- public boolean addPathMatcher(PathMatcher pm)
- {
- super.addPathMatcher(pm);
- return matchers.add(pm);
- }
-
- @Uninstall
- public boolean removePathMatcher(PathMatcher pm)
- {
- matchers.remove(pm);
- return super.removePathMatcher(pm);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/PathMatchersTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/PathMatchersTestCase.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/PathMatchersTestCase.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,146 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.deployers.vfs.matchers.test;
-
-import java.util.Set;
-
-import junit.framework.Test;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
-import org.jboss.deployers.spi.deployer.Deployers;
-import org.jboss.deployers.vfs.spi.deployer.FileMatcher;
-import org.jboss.deployers.vfs.spi.deployer.PathMatcher;
-import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.test.deployers.vfs.matchers.support.ExposedFileStructure;
-import org.jboss.test.deployers.vfs.matchers.support.ExposedPMRFilter;
-import org.jboss.test.deployers.vfs.matchers.support.FeedbackDeployer;
-import org.jboss.test.deployers.vfs.matchers.support.TestBeanDeployer;
-import org.jboss.test.deployers.vfs.matchers.support.TestNameDeployer;
-import org.jboss.virtual.VirtualFileFilter;
-
-/**
- * Path matchers tests.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class PathMatchersTestCase extends KernelHolderDeployersTest
-{
- public PathMatchersTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(PathMatchersTestCase.class);
- }
-
- public void testMatchers() throws Throwable
- {
- KernelController controller = getController();
-
- MainDeployerImpl main = new MainDeployerImpl();
- main.setStructuralDeployers(createStructuralDeployers());
-
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("JARStructure", JARStructure.class.getName());
- controller.install(builder.getBeanMetaData());
- builder = BeanMetaDataBuilder.createBuilder("FileStructure", ExposedFileStructure.class.getName());
- controller.install(builder.getBeanMetaData());
-
- ControllerContext jarContext = controller.getInstalledContext("JARStructure");
- assertNotNull(jarContext);
- JARStructure jarStructure = (JARStructure)jarContext.getTarget();
- assertNotNull(jarStructure);
- addStructureDeployer(main, jarStructure);
-
- builder = BeanMetaDataBuilder.createBuilder("PMRF", ExposedPMRFilter.class.getName());
- builder.addConstructorParameter(VirtualFileFilter.class.getName(), builder.createInject("FileStructure"));
- controller.install(builder.getBeanMetaData());
-
- ControllerContext fileContext = controller.getInstalledContext("FileStructure");
- assertNotNull(fileContext);
- ExposedFileStructure fileStructure = (ExposedFileStructure)fileContext.getTarget();
- assertNotNull(fileStructure);
- addStructureDeployer(main, fileStructure);
-
- ControllerContext filterContext = controller.getInstalledContext("PMRF");
- assertNotNull(filterContext);
- ExposedPMRFilter filter = (ExposedPMRFilter) filterContext.getTarget();
- assertNotNull(filter);
-
- Set<FileMatcher> matchers = fileStructure.getMatchers();
- assertNotNull(matchers);
- assertEmpty(matchers);
-
- Set<PathMatcher> pms = filter.getMatchers();
- assertNotNull(pms);
- assertEmpty(pms);
-
- builder = BeanMetaDataBuilder.createBuilder("BeanDeployer", TestBeanDeployer.class.getName());
- controller.install(builder.getBeanMetaData());
- assertEquals(1, matchers.size());
- assertEquals(1, pms.size());
-
- builder = BeanMetaDataBuilder.createBuilder("ExactNameDeployer", TestNameDeployer.class.getName());
- builder.addConstructorParameter(String.class.getName(), "some.bsh");
- controller.install(builder.getBeanMetaData());
- assertEquals(2, matchers.size());
- assertEquals(2, pms.size());
-
- Deployers deployers = createDeployers();
- main.setDeployers(deployers);
-
- FeedbackDeployer beanDeployer = addDeployer(main, "BeanDeployer");
- FeedbackDeployer nameDeployer = addDeployer(main, "ExactNameDeployer");
-
- Deployment deploymentBeans = createDeployment("/matchers", "qwert.beans");
- assertDeploy(main, deploymentBeans);
- Deployment deploymentShells = createDeployment("/matchers", "beanshell.jar");
- assertDeploy(main, deploymentShells);
-
- assertNotNull(beanDeployer.getFiles());
- assertEquals(new String[]{"some-beans.xml"}, beanDeployer.getFiles().toArray());
-
- assertNotNull(nameDeployer.getFiles());
- assertEquals(new String[]{"some.bsh"}, nameDeployer.getFiles().toArray());
-
- // test path matching
-
- assertTrue(filter.accepts("foobar-beans.xml"));
- assertTrue(filter.accepts("/foobar-beans.xml"));
- assertTrue(filter.accepts("/org/jboss/foobar-beans.xml"));
- assertTrue(filter.accepts("some.bsh"));
- assertTrue(filter.accepts("/some.bsh"));
- assertTrue(filter.accepts("/org/jboss/some.bsh"));
-
- assertFalse(filter.accepts("jboss-service.xml"));
- assertFalse(filter.accepts("foobar.txt"));
- assertFalse(filter.accepts("/foobar.txt"));
- assertFalse(filter.accepts("/com/foo/foobar.txt"));
- assertFalse(filter.accepts("/justpath"));
- assertFalse(filter.accepts("/justpath/"));
- assertFalse(filter.accepts("/qwert/justpath/"));
- }
-}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,17 +21,18 @@
*/
package org.jboss.test.deployers.vfs.structure.modified.support;
-import org.jboss.deployers.vfs.spi.structure.modified.AbstractPathNameFilter;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFile;
/**
* Include only .xml files.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class XmlIncludeVirtualFileFilter extends AbstractPathNameFilter
+public class XmlIncludeVirtualFileFilter implements VirtualFileFilter
{
- public boolean accepts(String path)
+ public boolean accepts(VirtualFile file)
{
- return path.endsWith(".xml");
+ return file.getName().endsWith(".xml");
}
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,10 +21,12 @@
*/
package org.jboss.test.deployers.vfs.structure.modified.test;
-import java.util.Set;
+import java.util.List;
import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
import org.jboss.test.deployers.BootstrapDeployersTest;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
/**
* AbstractStructureCache tests.
@@ -42,28 +44,41 @@
public void testCacheBehavior() throws Throwable
{
+ VirtualFile root = createDeploymentRoot("/annotations", "basic-scan");
+
StructureCache<Long> cache = createStructureCache();
- cache.initializeCache("acme1.jar");
+ cache.initializeCache(root);
- Set<String> leaves = cache.getLeaves("acme1.jar/META-INF");
+ VirtualFile meta_inf = root.getChild("META-INF");
+ List<VirtualFile> leaves = cache.getLeaves(meta_inf);
assertNull(leaves);
- cache.putCacheValue("acme1.jar/META-INF/a.xml", 1l);
- cache.putCacheValue("acme1.jar/META-INF/b.xml", 2l);
+ VirtualFile a = meta_inf.getChild("application.properties");
+ VirtualFile b = meta_inf.getChild("jboss-scanning.xml");
+ cache.putCacheValue(a, 1l);
+ cache.putCacheValue(b, 2l);
- cache.putCacheValue("acme1.jar/META-INF", 1l);
+ cache.putCacheValue(meta_inf, 1l);
- leaves = cache.getLeaves("acme1.jar/META-INF");
+ leaves = cache.getLeaves(meta_inf);
assertEquals(2, leaves.size());
+ leaves = cache.getLeaves(meta_inf, new VirtualFileFilter()
+ {
+ public boolean accepts(VirtualFile file)
+ {
+ return file.getName().endsWith(".xml");
+ }
+ });
+ assertEquals(1, leaves.size());
- assertNotNull(cache.getCacheValue("acme1.jar/META-INF/a.xml"));
- assertNotNull(cache.getCacheValue("acme1.jar/META-INF/b.xml"));
- assertNotNull(cache.getCacheValue("acme1.jar/META-INF"));
+ assertNotNull(cache.getCacheValue(a));
+ assertNotNull(cache.getCacheValue(b));
+ assertNotNull(cache.getCacheValue(meta_inf));
- leaves = cache.getLeaves("acme1.jar/META-INF");
+ leaves = cache.getLeaves(meta_inf);
assertEquals(2, leaves.size());
- cache.invalidateCache("acme1.jar");
+ cache.invalidateCache(root);
}
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -51,7 +51,6 @@
MetaDataStructureModificationChecker mdsmc = new MetaDataStructureModificationChecker(mainDeployerInternals);
mdsmc.setFilter(filter);
- mdsmc.start();
SynchWrapperModificationChecker synch = new SynchWrapperModificationChecker(mdsmc, synchAdapter);
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractResourceMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractResourceMatcher.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractResourceMatcher.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,38 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.deployers.vfs.spi.deployer;
-
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Abstract resource matcher.
- * File matcher delegates to path matcher.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public abstract class AbstractResourceMatcher implements PathMatcher, FileMatcher
-{
- public boolean isDeployable(VirtualFile file)
- {
- return isDeployable(file.getPathName());
- }
-}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -44,7 +44,7 @@
* @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public abstract class AbstractVFSParsingDeployer<T> extends AbstractParsingDeployerWithOutput<T> implements FileMatcher, PathMatcher
+public abstract class AbstractVFSParsingDeployer<T> extends AbstractParsingDeployerWithOutput<T> implements FileMatcher
{
/** The alt mappings key */
private static final String ALT_MAPPINGS_MAP_KEY = "AltMappingsMap";
@@ -69,19 +69,6 @@
return matchFileName(fileName);
}
- public boolean isDeployable(String path)
- {
- int p = path.lastIndexOf("/");
-
- String fileName;
- if (p >= 0)
- fileName = path.substring(p + 1);
- else
- fileName = path;
-
- return matchFileName(fileName);
- }
-
/**
* Match file name.
*
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/PathMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/PathMatcher.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/PathMatcher.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,38 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.deployers.vfs.spi.deployer;
-
-/**
- * Matches path to check if it can be deployed.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface PathMatcher
-{
- /**
- * Check if path param is deployable.
- *
- * @param path the path
- * @return true if we have a match, false otherwise
- */
- boolean isDeployable(String path);
-}
\ No newline at end of file
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.deployers.vfs.spi.structure.modified;
-
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Abstract path name filter.
- *
- * VirtualFileFilter delegates the work to StructureCacheFilter.
- * It takes file's path name as an argument.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public abstract class AbstractPathNameFilter implements StructureCacheFilter, VirtualFileFilter
-{
- public boolean accepts(VirtualFile file)
- {
- return accepts(file.getPathName());
- }
-}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,8 +21,10 @@
*/
package org.jboss.deployers.vfs.spi.structure.modified;
-import java.util.Set;
+import java.util.List;
+import org.jboss.virtual.VirtualFile;
+
/**
* Abstract structure cache.
* Used as a bridge between possible changes/updates.
@@ -32,8 +34,8 @@
*/
public abstract class AbstractStructureCache<T> implements StructureCache<T>
{
- public Set<String> getLeaves(String pathName)
+ public List<VirtualFile> getLeaves(VirtualFile file)
{
- return getLeaves(pathName, null);
+ return getLeaves(file, null);
}
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -124,7 +124,7 @@
boolean result = hasRootBeenModified(root);
if (result)
{
- getCache().invalidateCache(root.getPathName());
+ getCache().invalidateCache(root);
}
return result;
}
@@ -197,8 +197,7 @@
if (result)
{
- String pathName = root.getPathName();
- getCache().invalidateCache(pathName);
+ getCache().invalidateCache(root);
}
return result;
}
@@ -231,8 +230,7 @@
if (root == null)
throw new IllegalArgumentException("Null root");
- String pathName = root.getPathName();
- getCache().initializeCache(pathName);
+ getCache().initializeCache(root);
}
public void removeStructureRoot(VirtualFile root)
@@ -240,7 +238,6 @@
if (root == null)
throw new IllegalArgumentException("Null root");
- String pathName = root.getPathName();
- getCache().removeCache(pathName);
+ getCache().removeCache(root);
}
}
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -61,7 +61,7 @@
{
// original was added
long timestamp = getSynchAdapter().add(file, tempRoot, pathName);
- getCache().putCacheValue(originalPathName, timestamp);
+ getCache().putCacheValue(file, timestamp);
}
}
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,14 +21,17 @@
*/
package org.jboss.deployers.vfs.spi.structure.modified;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Pattern;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
/**
* Default structure cache.
*
@@ -37,61 +40,107 @@
*/
public class DefaultStructureCache<T> extends AbstractStructureCache<T>
{
- private Map<String, T> map = new ConcurrentHashMap<String, T>();
+ private Map<VirtualFile, T> map = new ConcurrentHashMap<VirtualFile, T>();
- public void initializeCache(String pathName)
+ public void initializeCache(VirtualFile root)
{
}
- public T putCacheValue(String pathName, T value)
+ public T putCacheValue(VirtualFile file, T value)
{
- return map.put(pathName, value);
+ return map.put(file, value);
}
- public T getCacheValue(String pathName)
+ public T getCacheValue(VirtualFile file)
{
- return map.get(pathName);
+ return map.get(file);
}
- public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
+ public List<VirtualFile> getLeaves(VirtualFile file, VirtualFileFilter filter)
{
- Set<String> result = null;
- Pattern pattern = Pattern.compile(pathName + "/[^/]+");
- for (String key : map.keySet())
+ try
{
- // first the pattern should match, only then we check the filter
- if (pattern.matcher(key).matches() && (filter == null || filter.accepts(key)))
+ List<VirtualFile> result = null;
+ for (VirtualFile key : map.keySet())
{
- if (result == null)
- result = new HashSet<String>();
+ VirtualFile parent = key.getParent();
+ if (parent != null && parent.equals(file) && (filter == null || filter.accepts(key)))
+ {
+ if (result == null)
+ result = new ArrayList<VirtualFile>();
- result.add(key);
+ result.add(key);
+ }
}
+ if (result != null)
+ return result;
+ else
+ return (map.containsKey(file) ? Collections.<VirtualFile>emptyList() : null);
}
- if (result != null)
- return result;
- else
- return (map.containsKey(pathName) ? Collections.<String>emptySet() : null);
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
}
- public void invalidateCache(String pathName)
+ public void invalidateCache(VirtualFile file)
{
- removeCache(pathName);
+ removeCache(file);
}
- public void removeCache(String pathName)
+ public void removeCache(VirtualFile file)
{
- Iterator<Map.Entry<String, T>> iter = map.entrySet().iterator();
+ Iterator<Map.Entry<VirtualFile, T>> iter = map.entrySet().iterator();
while (iter.hasNext())
{
- Map.Entry<String, T> entry = iter.next();
- if (entry.getKey().startsWith(pathName))
+ Map.Entry<VirtualFile, T> entry = iter.next();
+ if (isAncestorOrEquals(file, entry.getKey()))
{
iter.remove();
}
}
}
+ public void removeCache(VirtualFile root, String path)
+ {
+ Iterator<Map.Entry<VirtualFile, T>> iter = map.entrySet().iterator();
+ while (iter.hasNext())
+ {
+ Map.Entry<VirtualFile, T> entry = iter.next();
+ VirtualFile key = entry.getKey();
+ if (isAncestorOrEquals(root, key) && key.getPathName().startsWith(path))
+ {
+ iter.remove();
+ }
+ }
+ }
+
+ /**
+ * Is ref ancestor or equal to file param.
+ *
+ * @param ref the ref to check against
+ * @param file the file to check
+ * @return true if ref is ancestor or equal to file, false otherwise
+ */
+ protected boolean isAncestorOrEquals(VirtualFile ref, VirtualFile file)
+ {
+ try
+ {
+ while(file != null)
+ {
+ if (file.equals(ref))
+ return true;
+
+ file = file.getParent();
+ }
+ return false;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public void flush()
{
map.clear();
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -54,9 +54,6 @@
/** The metadata filter */
private VirtualFileFilter filter;
- /** The structure cache filter */
- private StructureCacheFilter cacheFilter;
-
public MetaDataStructureModificationChecker(MainDeployerInternals mainDeployer)
{
super(mainDeployer);
@@ -72,40 +69,10 @@
this.filter = filter;
}
- /**
- * Set the structure cache filter.
- *
- * @param cacheFilter the cache filter
- */
- public void setCacheFilter(StructureCacheFilter cacheFilter)
- {
- this.cacheFilter = cacheFilter;
- }
-
- /**
- * Check filters.
- */
- public void start()
- {
- if (cacheFilter == null)
- {
- if (filter instanceof StructureCacheFilter)
- cacheFilter = (StructureCacheFilter) filter;
- else
- log.warn("No cache filter specified, possible non match on leaves.");
- }
- else if (cacheFilter != filter)
- {
- // not the same instance
- log.debug("VFS filter and structure cache filter are not the same instance, possible compatibility issue?");
- }
- }
-
@Override
protected boolean hasRootBeenModified(VirtualFile root) throws IOException
{
- String pathName = root.getPathName();
- Long cachedValue = getCache().getCacheValue(pathName);
+ Long cachedValue = getCache().getCacheValue(root);
long lastModified = root.getLastModified();
if (cachedValue != null)
{
@@ -113,7 +80,7 @@
}
else
{
- getCache().putCacheValue(pathName, lastModified);
+ getCache().putCacheValue(root, lastModified);
return false;
}
}
@@ -182,8 +149,7 @@
if (mdpVF != null)
{
List<VirtualFile> children = mdpVF.getChildren(filter);
- String mdpPathName = mdpVF.getPathName();
- Set<String> leaves = getCache().getLeaves(mdpPathName, cacheFilter);
+ List<VirtualFile> leaves = getCache().getLeaves(mdpVF, filter);
// do we have some new files or some were deleted
if (leaves != null && children != null && leaves.size() != children.size())
{
@@ -196,17 +162,15 @@
{
for (VirtualFile child : children)
{
- String pathName = child.getPathName();
-
// we tried to remove non existing leaf - it's new == modified
- if (leaves != null && leaves.remove(pathName) == false)
+ if (leaves != null && leaves.remove(child) == false)
{
if (log.isTraceEnabled())
log.trace("Found new metadata file: " + child);
return true;
}
- Long timestamp = getCache().getCacheValue(pathName);
+ Long timestamp = getCache().getCacheValue(child);
long lastModified = child.getLastModified();
if (timestamp != null)
{
@@ -220,14 +184,14 @@
else
{
// only put if not modified
- getCache().putCacheValue(pathName, lastModified);
+ getCache().putCacheValue(child, lastModified);
}
}
}
else
{
// mark empty metadata path
- getCache().putCacheValue(mdpPathName, System.currentTimeMillis());
+ getCache().putCacheValue(mdpVF, System.currentTimeMillis());
}
// not all previous leaves were removed - we're missing some == modified
if (leaves != null && leaves.isEmpty() == false)
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/PathMatchersResourceFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/PathMatchersResourceFilter.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/PathMatchersResourceFilter.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.deployers.vfs.spi.structure.modified;
-
-import java.util.Set;
-
-import org.jboss.deployers.vfs.spi.deployer.PathMatcher;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.util.collection.ConcurrentSet;
-
-/**
- * For virtual file filter we use delegate,
- * as we already have FileStructure that collects all FileMatchers
- * which is what we want to use to check if file is accepted.
- *
- * For structure cache filer we use PathMatchers.
- * They should be injected via MC's IoC incallback.
- *
- * Note: delegate's file matchers and this class' path matchers should be the same instance
- * otherwise there might be potential compatibility issue on VFS children and StructureCache nodes.
- * @see org.jboss.deployers.vfs.spi.deployer.AbstractResourceMatcher
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class PathMatchersResourceFilter implements StructureCacheFilter, VirtualFileFilter
-{
- /** The path matchers */
- private Set<PathMatcher> pathMatchers = new ConcurrentSet<PathMatcher>();
-
- /** The virtual file filter delegate */
- private VirtualFileFilter delegate;
-
- public PathMatchersResourceFilter(VirtualFileFilter delegate)
- {
- if (delegate == null)
- throw new IllegalArgumentException("Null delegate");
-
- this.delegate = delegate;
- }
-
- public boolean accepts(String path)
- {
- for (PathMatcher pm : pathMatchers)
- {
- if (pm.isDeployable(path))
- return true;
- }
- return false;
- }
-
- public boolean accepts(VirtualFile file)
- {
- return delegate.accepts(file);
- }
-
- /**
- * Add path matcher.
- *
- * @param pm the path matcher
- * @return Set#add
- */
- public boolean addPathMatcher(PathMatcher pm)
- {
- return pathMatchers.add(pm);
- }
-
- /**
- * Remove path matcher.
- *
- * @param pm the path matcher
- * @return Set#remove
- */
- public boolean removePathMatcher(PathMatcher pm)
- {
- return pathMatchers.remove(pm);
- }
-}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,8 +21,11 @@
*/
package org.jboss.deployers.vfs.spi.structure.modified;
-import java.util.Set;
+import java.util.List;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
/**
* Simple structure cache.
*
@@ -34,67 +37,75 @@
/**
* Initialize cache.
*
- * @param pathName the path name
+ * @param root the root to initialize
*/
- void initializeCache(String pathName);
+ void initializeCache(VirtualFile root);
/**
* Put cache value.
*
- * @param pathName the path name
+ * @param file the file key
* @param value the value
* @return previous value
*/
- T putCacheValue(String pathName, T value);
+ T putCacheValue(VirtualFile file, T value);
/**
* Get cache value.
*
- * @param pathName the path name
+ * @param file the file key
* @return the cache value
*/
- T getCacheValue(String pathName);
+ T getCacheValue(VirtualFile file);
/**
- * Get leaves for this path name parameter.
- * Only exact sub path nodes count in.
+ * Get leaves for this file parameter.
+ * Only first level children count in.
*
* This method should return a mutable Set copy
* as we intend to modify it in checker processing.
*
- * @param pathName the path name
- * @return sub-paths nodes or null if no such match yet
+ * @param file the file key
+ * @return first level children or null if no such match yet
*/
- Set<String> getLeaves(String pathName);
+ List<VirtualFile> getLeaves(VirtualFile file);
/**
- * Get filtered leaves for this path name parameter.
- * Only exact sub path nodes count in.
+ * Get leaves for this file parameter.
+ * Only first level children count in.
*
* This method should return a mutable Set copy
* as we intend to modify it in checker processing.
*
- * @param pathName the path name
- * @param filter the leaves path filter
- * @return sub-paths nodes or null if no such match yet
+ * @param file the file key
+ * @param filter the file filter
+ * @return first level children or null if no such match yet
*/
- Set<String> getLeaves(String pathName, StructureCacheFilter filter);
+ List<VirtualFile> getLeaves(VirtualFile file, VirtualFileFilter filter);
/**
- * Invalidate cache for path name.
+ * Invalidate cache for file and all of its subs.
*
- * @param pathName the path name
+ * @param file the file key
*/
- void invalidateCache(String pathName);
+ void invalidateCache(VirtualFile file);
/**
- * Remove cache for path name.
+ * Remove cache for file and all of its subs.
*
- * @param pathName the path name
+ * @param file the file key
*/
- void removeCache(String pathName);
+ void removeCache(VirtualFile file);
/**
+ * Remove cache for file and all of its subs.
+ *
+ * @param root the root
+ * @param path the path of non-existing file
+ */
+ void removeCache(VirtualFile root, String path);
+
+ /**
* Flush the cache.
*/
void flush();
Deleted: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.deployers.vfs.spi.structure.modified;
-
-/**
- * Simple structure cache filter.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public interface StructureCacheFilter
-{
- /**
- * Do we accept the path.
- *
- * @param path the full path
- * @return true if the path is accepted, false otherwise
- */
- boolean accepts(String path);
-}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -21,16 +21,18 @@
*/
package org.jboss.deployers.vfs.spi.structure.modified;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
/**
@@ -51,7 +53,7 @@
*/
protected Node<T> createRoot()
{
- return new Node<T>("", getDefaultValue(), null);
+ return new Node<T>(null, getDefaultValue(), null);
}
/**
@@ -64,48 +66,43 @@
return null;
}
- public void initializeCache(String pathName)
+ public void initializeCache(VirtualFile root)
{
- initializeNode(pathName);
+ initializeNode(root);
}
- public T putCacheValue(String pathName, T value)
+ public T putCacheValue(VirtualFile file, T value)
{
// we try to initialize it if it doesn't exist
- Node<T> node = initializeNode(pathName);
+ Node<T> node = initializeNode(file);
T previous = node.getValue();
node.setValue(value);
return previous;
}
- public T getCacheValue(String pathName)
+ public T getCacheValue(VirtualFile file)
{
- Node<T> node = getNode(pathName);
+ Node<T> node = getNode(file);
return (node != null ? node.getValue() : null);
}
- public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
+ public List<VirtualFile> getLeaves(VirtualFile file, VirtualFileFilter filter)
{
- Node<T> node = getNode(pathName);
+ Node<T> node = getNode(file);
if (node != null)
{
- Set<String> children = node.getChildrenNames();
- if (filter != null && children != null && children.isEmpty() == false)
+ List<VirtualFile> result = new ArrayList<VirtualFile>();
+ Collection<Node<T>> children = node.getChildren();
+ if (children != null && children.isEmpty() == false)
{
- Set<String> result = new HashSet<String>();
- for (String child : children)
+ for (Node<T> child : children)
{
- if (filter.accepts(child))
- {
- result.add(child);
- }
+ VirtualFile vf = child.getFile();
+ if (filter == null || filter.accepts(vf))
+ result.add(vf);
}
- return result;
}
- else
- {
- return children;
- }
+ return result;
}
else
{
@@ -113,14 +110,14 @@
}
}
- public void invalidateCache(String pathName)
+ public void invalidateCache(VirtualFile file)
{
- removeCache(pathName);
+ removeCache(file);
}
- public void removeCache(String pathName)
+ public void removeCache(VirtualFile file)
{
- Node<T> node = getNode(pathName);
+ Node<T> node = getNode(file);
if (node != null)
{
Node<T> parent = node.getParent();
@@ -131,6 +128,51 @@
}
}
+ public void removeCache(VirtualFile root, String path)
+ {
+ Node<T> node = getNode(root);
+ if (node != null)
+ {
+ List<String> tokens = PathTokenizer.getTokens(path);
+ Node<T> child = findNode(0, tokens, node);
+ if (child != null)
+ {
+ Node<T> parent = child.getParent();
+ if (parent != null)
+ parent.removeChild(node);
+ else // clear root
+ flush();
+ }
+ }
+ }
+
+ /**
+ * Find node.
+ *
+ * @param index the current token index
+ * @param tokens the tokens
+ * @param node the current node
+ * @return found node or null if no match
+ */
+ protected Node<T> findNode(int index, List<String> tokens, Node<T> node)
+ {
+ if (index == tokens.size())
+ return node;
+
+ Collection<Node<T>> nodes = node.getChildren();
+ if (nodes == null || nodes.isEmpty())
+ return null;
+
+ String token = tokens.get(index);
+ for (Node<T> child : nodes)
+ {
+ VirtualFile file = child.getFile();
+ if (token.equals(file.getName()))
+ return findNode(index + 1, tokens, child);
+ }
+ return null;
+ }
+
public void flush()
{
synchronized (root)
@@ -140,18 +182,42 @@
}
/**
+ * Get file tokens.
+ *
+ * @param file the file to tokenize
+ * @return file's tokens
+ */
+ protected List<VirtualFile> tokens(VirtualFile file)
+ {
+ try
+ {
+ List<VirtualFile> tokens = new ArrayList<VirtualFile>();
+ while(file != null)
+ {
+ tokens.add(0, file);
+ file = file.getParent();
+ }
+ return tokens;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* Get the path's node.
*
- * @param path the path
+ * @param file the file key
* @return node or null if it doesn't exist
*/
- protected Node<T> getNode(String path)
+ protected Node<T> getNode(VirtualFile file)
{
- List<String> tokens = PathTokenizer.getTokens(path);
+ List<VirtualFile> tokens = tokens(file);
synchronized (root)
{
Node<T> node = root;
- for (String token : tokens)
+ for (VirtualFile token : tokens)
{
node = node.getChild(token);
if (node == null)
@@ -164,17 +230,17 @@
/**
* Initialize node for pathName param.
*
- * @param pathName the path name
+ * @param file the file key
* @return initialized node
*/
- protected Node<T> initializeNode(String pathName)
+ protected Node<T> initializeNode(VirtualFile file)
{
- List<String> tokens = PathTokenizer.getTokens(pathName);
+ List<VirtualFile> tokens = tokens(file);
synchronized (root)
{
Node<T> node = root;
boolean newNode = false;
- for (String token : tokens)
+ for (VirtualFile token : tokens)
{
if (newNode)
{
@@ -205,17 +271,15 @@
{
private ReadWriteLock lock = new ReentrantReadWriteLock();
- private String name;
- private String fullName;
+ private VirtualFile file;
private Node<U> parent;
private U value;
- private Map<String, Node<U>> children;
- private Set<String> names;
+ private Map<VirtualFile, Node<U>> children;
- private Node(String name, U value, Node<U> parent)
+ private Node(VirtualFile file, U value, Node<U> parent)
{
- this.name = name;
+ this.file = file;
this.value = value;
this.parent = parent;
if (parent != null)
@@ -223,38 +287,16 @@
}
/**
- * The node name.
+ * The node file.
*
- * @return the node name
+ * @return the node file
*/
- public String getName()
+ public VirtualFile getFile()
{
- return name;
+ return file;
}
/**
- * Get full name.
- *
- * @return the full name
- */
- public String getFullName()
- {
- if (fullName == null)
- {
- Node<U> parent = getParent();
- if (parent != null && parent.getParent() != null)
- {
- fullName = parent.getFullName() + "/" + getName();
- }
- else
- {
- fullName = getName();
- }
- }
- return fullName;
- }
-
- /**
* Get node value.
*
* @return the node value
@@ -295,12 +337,9 @@
try
{
if (children == null)
- children = new HashMap<String, Node<U>>();
+ children = new HashMap<VirtualFile, Node<U>>();
- children.put(node.getName(), node);
-
- if (names != null)
- names.add(node.getFullName());
+ children.put(node.getFile(), node);
}
finally
{
@@ -321,15 +360,10 @@
if (children == null)
return;
- children.remove(node.getName());
+ children.remove(node.getFile());
- if (names != null)
- names.remove(node.getFullName());
-
if (children.isEmpty())
children = null;
- if (names != null && names.isEmpty())
- names = null;
}
finally
{
@@ -347,7 +381,6 @@
{
value = null;
children = null;
- names = null;
}
finally
{
@@ -358,15 +391,15 @@
/**
* Get child.
*
- * @param name the child name
+ * @param file the child file
* @return child node or null if not found
*/
- public Node<U> getChild(String name)
+ public Node<U> getChild(VirtualFile file)
{
lock.readLock().lock();
try
{
- return (children != null) ? children.get(name) : null;
+ return (children != null) ? children.get(file) : null;
}
finally
{
@@ -375,36 +408,6 @@
}
/**
- * Get children names.
- *
- * @return the children names
- */
- public Set<String> getChildrenNames()
- {
- lock.writeLock().lock();
- try
- {
- if (children == null)
- return Collections.emptySet();
-
- // TODO; I don't understand how can I get non-null names, but not equal to children
- if (names == null || (names.size() != children.size()))
- {
- names = new HashSet<String>();
- for (Node<U> child : children.values())
- {
- names.add(child.getFullName());
- }
- }
- return names;
- }
- finally
- {
- lock.writeLock().unlock();
- }
- }
-
- /**
* Get children.
*
* @return the children
@@ -425,7 +428,7 @@
@Override
public String toString()
{
- return getFullName();
+ return String.valueOf(file);
}
}
}
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2009-08-14 15:08:15 UTC (rev 92378)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2009-08-14 15:17:25 UTC (rev 92379)
@@ -62,12 +62,12 @@
// original was deleted, try deleting the temp
if (getSynchAdapter().delete(file))
{
- getCache().removeCache(originalPathName);
+ getCache().removeCache(originalRoot, originalPathName);
}
}
else
{
- Long previous = getCache().getCacheValue(originalPathName);
+ Long previous = getCache().getCacheValue(child);
long lastModified = child.getLastModified();
boolean updateCache = false;
@@ -83,7 +83,7 @@
if (updateCache)
{
- getCache().putCacheValue(originalPathName, lastModified);
+ getCache().putCacheValue(child, lastModified);
}
}
}
More information about the jboss-cvs-commits
mailing list