[jboss-cvs] JBossAS SVN: r90326 - in projects/jboss-deployers/branches/Branch_2_0: deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 17 09:00:42 EDT 2009
Author: alesj
Date: 2009-06-17 09:00:41 -0400 (Wed, 17 Jun 2009)
New Revision: 90326
Added:
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java
Modified:
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java
projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java
projects/jboss-deployers/branches/Branch_2_0/pom.xml
Log:
Port trunk changes.
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/support/XmlIncludeVirtualFileFilter.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -21,18 +21,17 @@
*/
package org.jboss.test.deployers.vfs.structure.modified.support;
-import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.vfs.spi.structure.modified.AbstractPathNameFilter;
/**
* Include only .xml files.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
-public class XmlIncludeVirtualFileFilter implements VirtualFileFilter
+public class XmlIncludeVirtualFileFilter extends AbstractPathNameFilter
{
- public boolean accepts(VirtualFile file)
+ public boolean accepts(String path)
{
- return file.getName().endsWith(".xml");
+ return path.endsWith(".xml");
}
}
\ No newline at end of file
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,69 @@
+/*
+ * 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.test.deployers.vfs.structure.modified.test;
+
+import java.util.Set;
+
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+import org.jboss.test.deployers.BootstrapDeployersTest;
+
+/**
+ * AbstractStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractStructureCacheTest extends BootstrapDeployersTest
+{
+ protected AbstractStructureCacheTest(String name)
+ {
+ super(name);
+ }
+
+ protected abstract StructureCache<Long> createStructureCache();
+
+ public void testCacheBehavior() throws Throwable
+ {
+ StructureCache<Long> cache = createStructureCache();
+
+ cache.initializeCache("acme1.jar");
+
+ Set<String> leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertNull(leaves);
+
+ cache.putCacheValue("acme1.jar/META-INF/a.xml", 1l);
+ cache.putCacheValue("acme1.jar/META-INF/b.xml", 2l);
+
+ cache.putCacheValue("acme1.jar/META-INF", 1l);
+
+ leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertEquals(2, 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"));
+
+ leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertEquals(2, leaves.size());
+
+ cache.invalidateCache("acme1.jar");
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -51,6 +51,8 @@
MetaDataStructureModificationChecker mdsmc = new MetaDataStructureModificationChecker(mainDeployerStructure);
mdsmc.setFilter(filter);
+ mdsmc.start();
+
SynchWrapperModificationChecker synch = new SynchWrapperModificationChecker(mdsmc, synchAdapter);
VisitorAttributes attributes = new VisitorAttributes();
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,43 @@
+/*
+ * 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.test.deployers.vfs.structure.modified.test;
+
+import org.jboss.deployers.vfs.spi.structure.modified.DefaultStructureCache;
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+
+/**
+ * DefaultStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultStructureCacheTestCase extends AbstractStructureCacheTest
+{
+ public DefaultStructureCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected StructureCache<Long> createStructureCache()
+ {
+ return new DefaultStructureCache<Long>();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -21,12 +21,13 @@
*/
package org.jboss.test.deployers.vfs.structure.modified.test;
+import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.FileOutputStream;
-import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.net.URI;
+import java.net.URL;
import junit.framework.Test;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
@@ -34,9 +35,9 @@
import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
import org.jboss.deployers.vfs.spi.structure.modified.SynchAdapter;
import org.jboss.test.deployers.vfs.structure.modified.support.XmlIncludeVirtualFileFilter;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
-import org.jboss.virtual.VFSUtils;
/**
* Test file synch.
@@ -66,9 +67,17 @@
{
public boolean accepts(VirtualFile file)
{
- String path = file.getPathName();
- // only wars, but not its classes
- return (path.contains(".war") && path.contains("/WEB-INF") == false);
+ try
+ {
+ URL url = file.toURL();
+ String path = url.toExternalForm();
+ // only wars, but not its classes
+ return (path.contains(".war") && path.contains("/WEB-INF/classes") == false);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
};
}
@@ -137,6 +146,28 @@
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertEquals(tempTimestamp, tempProps.getLastModified());
+ // add new file into WEB-INF
+ VirtualFile webInfo = originalRoot.getChild("WEB-INF");
+ File webInfFile = new File(VFSUtils.getCompatibleURI(webInfo));
+ File newWebInfFile = newFile(webInfFile, "newfile.txt");
+ try
+ {
+ assertNull(tempRoot.getChild("WEB-INF/newfile.txt"));
+ assertFalse(checker.hasStructureBeenModified(originalRoot));
+ assertNotNull(tempRoot.getChild("WEB-INF/newfile.txt"));
+ assertFalse(checker.hasStructureBeenModified(originalRoot));
+
+ // try deleting this one now
+ assertTrue(newWebInfFile.delete());
+ assertFalse(checker.hasStructureBeenModified(originalRoot));
+ assertNull(tempRoot.getChild("WEB-INF/newfile.txt"));
+ }
+ finally
+ {
+ if (newWebInfFile.exists())
+ assertTrue(newWebInfFile.delete());
+ }
+
// check we don't update for nothing
@SuppressWarnings("deprecation")
VirtualFile xhtml = tempRoot.findChild("test.xhtml");
@@ -145,7 +176,6 @@
Thread.sleep(1500l);
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertEquals(xhtmlTimestamp, xhtml.getLastModified());
-
}
finally
{
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,43 @@
+/*
+ * 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.test.deployers.vfs.structure.modified.test;
+
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+import org.jboss.deployers.vfs.spi.structure.modified.TreeStructureCache;
+
+/**
+ * TreeStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TreeStructureCacheTestCase extends AbstractStructureCacheTest
+{
+ public TreeStructureCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected StructureCache<Long> createStructureCache()
+ {
+ return new TreeStructureCache<Long>();
+ }
+}
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractPathNameFilter.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,41 @@
+/*
+ * 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
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureCache.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * Abstract structure cache.
+ * Used as a bridge between possible changes/updates.
+ *
+ * @param <T> exact cache value type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractStructureCache<T> implements StructureCache<T>
+{
+ public Set<String> getLeaves(String pathName)
+ {
+ return getLeaves(pathName, null);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -22,6 +22,7 @@
package org.jboss.deployers.vfs.spi.structure.modified;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
/**
@@ -36,7 +37,12 @@
public AddVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile tempRoot, int initialPathLenght)
{
- super(attributes, cache, synchAdapter);
+ this(null, attributes, cache, synchAdapter, tempRoot, initialPathLenght);
+ }
+
+ public AddVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile tempRoot, int initialPathLenght)
+ {
+ super(filter, attributes, cache, synchAdapter);
if (tempRoot == null)
throw new IllegalArgumentException("Null temp root");
if (initialPathLenght < 0)
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -35,7 +35,7 @@
* @param <T> exact cache value type
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class DefaultStructureCache<T> implements StructureCache<T>
+public class DefaultStructureCache<T> extends AbstractStructureCache<T>
{
private Map<String, T> map = new ConcurrentHashMap<String, T>();
@@ -53,13 +53,14 @@
return map.get(pathName);
}
- public Set<String> getLeaves(String pathName)
+ public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
{
Set<String> result = null;
Pattern pattern = Pattern.compile(pathName + "/[^/]+");
for (String key : map.keySet())
{
- if (pattern.matcher(key).matches())
+ // first the pattern should match, only then we check the filter
+ if (pattern.matcher(key).matches() && (filter == null || filter.accepts(key)))
{
if (result == null)
result = new HashSet<String>();
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MetaDataStructureModificationChecker.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -36,6 +36,14 @@
/**
* MetaDataStructureModificationChecker.
*
+ * VFS and structure cache filter must be compatible,
+ * meaning they would return same value for equal files/paths.
+ *
+ * e.g.
+ * VirtualFile file = VFS.getVirtualFile(rootURI, "/my-app.jar/META-INF/somefile.xml");
+ * String cachedPath = "/my-app.jar/META-INF/somefile.xml";
+ * filter.accepts(file) == cacheFilter.accepts(cachedPath)
+ *
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
public class MetaDataStructureModificationChecker extends AbstractStructureModificationChecker<Long>
@@ -46,6 +54,9 @@
/** The metadata filter */
private VirtualFileFilter filter;
+ /** The structure cache filter */
+ private StructureCacheFilter cacheFilter;
+
public MetaDataStructureModificationChecker(MainDeployerStructure mainDeployer)
{
super(mainDeployer);
@@ -61,6 +72,35 @@
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
{
@@ -143,7 +183,7 @@
{
List<VirtualFile> children = mdpVF.getChildren(filter);
String mdpPathName = mdpVF.getPathName();
- Set<String> leaves = getCache().getLeaves(mdpPathName);
+ Set<String> leaves = getCache().getLeaves(mdpPathName, cacheFilter);
// do we have some new files or some were deleted
if (leaves != null && children != null && leaves.size() != children.size())
{
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCache.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -68,6 +68,19 @@
Set<String> getLeaves(String pathName);
/**
+ * Get filtered leaves for this path name parameter.
+ * Only exact sub path nodes 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
+ */
+ Set<String> getLeaves(String pathName, StructureCacheFilter filter);
+
+ /**
* Invalidate cache for path name.
*
* @param pathName the path name
Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java (from rev 90319, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/StructureCacheFilter.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -0,0 +1,38 @@
+/*
+ * 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/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -22,9 +22,10 @@
package org.jboss.deployers.vfs.spi.structure.modified;
import org.jboss.logging.Logger;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VisitorAttributes;
import org.jboss.virtual.VirtualFileVisitor;
-import org.jboss.virtual.VisitorAttributes;
-import org.jboss.virtual.VirtualFile;
/**
* Synch file visitor.
@@ -35,17 +36,24 @@
{
protected final Logger log = Logger.getLogger(getClass());
+ private VirtualFileFilter filter;
private VisitorAttributes attributes;
private StructureCache<Long> cache;
private SynchAdapter synchAdapter;
protected SynchVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter)
{
+ this(null, attributes, cache, synchAdapter);
+ }
+
+ protected SynchVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter)
+ {
if (cache == null)
throw new IllegalArgumentException("Null cache");
if (synchAdapter == null)
throw new IllegalArgumentException("Null synch adapter");
+ this.filter = filter;
if (attributes != null)
this.attributes = attributes;
else
@@ -63,7 +71,10 @@
{
try
{
- doVisit(file);
+ if (filter == null || filter.accepts(file))
+ {
+ doVisit(file);
+ }
}
catch (Exception e)
{
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -23,9 +23,10 @@
import java.io.IOException;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
/**
@@ -42,6 +43,9 @@
/** The true checker delegate */
private AbstractStructureModificationChecker<Long> delegate;
+ /** The filter */
+ private VirtualFileFilter filter;
+
/** The synch adapter */
private SynchAdapter synchAdapter;
@@ -85,11 +89,11 @@
if (modified == false && root != deploymentContext.getRoot())
{
// check for update or delete
- UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(tempAttributes, getCache(), synchAdapter, root);
+ UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(filter, tempAttributes, getCache(), synchAdapter, root);
VirtualFile tempRoot = deploymentContext.getRoot();
tempRoot.visit(udVisitor);
// check for addition
- AddVisitor addVisitor = new AddVisitor(originalAttributes, getCache(), synchAdapter, tempRoot, root.getPathName().length());
+ AddVisitor addVisitor = new AddVisitor(filter, originalAttributes, getCache(), synchAdapter, tempRoot, root.getPathName().length());
root.visit(addVisitor);
}
return modified;
@@ -106,6 +110,16 @@
}
/**
+ * Set the filter.
+ *
+ * @param filter the filter
+ */
+ public void setFilter(VirtualFileFilter filter)
+ {
+ this.filter = filter;
+ }
+
+ /**
* Set original visitor attributes.
*
* @param attributes the attributes
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -24,10 +24,12 @@
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.HashSet;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
@@ -37,7 +39,7 @@
* @param <T> exact value type
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class TreeStructureCache<T> implements StructureCache<T>
+public class TreeStructureCache<T> extends AbstractStructureCache<T>
{
/** The tree root */
private final Node<T> root = createRoot();
@@ -69,10 +71,8 @@
public T putCacheValue(String pathName, T value)
{
- Node<T> node = getNode(pathName);
- if (node == null)
- node = initializeNode(pathName);
-
+ // we try to initialize it if it doesn't exist
+ Node<T> node = initializeNode(pathName);
T previous = node.getValue();
node.setValue(value);
return previous;
@@ -84,10 +84,33 @@
return (node != null ? node.getValue() : null);
}
- public Set<String> getLeaves(String pathName)
+ public Set<String> getLeaves(String pathName, StructureCacheFilter filter)
{
Node<T> node = getNode(pathName);
- return (node != null) ? node.getChildrenNames() : null;
+ if (node != null)
+ {
+ Set<String> children = node.getChildrenNames();
+ if (filter != null && children != null && children.isEmpty() == false)
+ {
+ Set<String> result = new HashSet<String>();
+ for (String child : children)
+ {
+ if (filter.accepts(child))
+ {
+ result.add(child);
+ }
+ }
+ return result;
+ }
+ else
+ {
+ return children;
+ }
+ }
+ else
+ {
+ return null;
+ }
}
public void invalidateCache(String pathName)
@@ -180,6 +203,8 @@
*/
private class Node<U>
{
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+
private String name;
private String fullName;
private Node<U> parent;
@@ -266,13 +291,21 @@
*/
private void addChild(Node<U> node)
{
- if (children == null)
- children = new HashMap<String, Node<U>>();
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ children = new HashMap<String, Node<U>>();
- children.put(node.getName(), node);
+ children.put(node.getName(), node);
- if (names != null)
- names.add(node.getFullName());
+ if (names != null)
+ names.add(node.getFullName());
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -280,20 +313,28 @@
*
* @param node the child node
*/
- public synchronized void removeChild(Node<U> node)
+ public void removeChild(Node<U> node)
{
- if (children == null)
- return;
-
- children.remove(node.getName());
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ return;
- if (names != null)
- names.remove(node.getFullName());
+ children.remove(node.getName());
- if (children.isEmpty())
- children = null;
- if (names != null && names.isEmpty())
- names = null;
+ if (names != null)
+ names.remove(node.getFullName());
+
+ if (children.isEmpty())
+ children = null;
+ if (names != null && names.isEmpty())
+ names = null;
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -301,9 +342,17 @@
*/
void clear()
{
- value = null;
- children = null;
- names = null;
+ lock.writeLock().lock();
+ try
+ {
+ value = null;
+ children = null;
+ names = null;
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -314,7 +363,15 @@
*/
public Node<U> getChild(String name)
{
- return (children != null) ? children.get(name) : null;
+ lock.readLock().lock();
+ try
+ {
+ return (children != null) ? children.get(name) : null;
+ }
+ finally
+ {
+ lock.readLock().unlock();
+ }
}
/**
@@ -322,20 +379,29 @@
*
* @return the children names
*/
- public synchronized Set<String> getChildrenNames()
+ public Set<String> getChildrenNames()
{
- if (children == null)
- return Collections.emptySet();
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ return Collections.emptySet();
- if (names == null)
- {
- names = new HashSet<String>();
- for (Node<U> child : children.values())
+ // 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.add(child.getFullName());
+ names = new HashSet<String>();
+ for (Node<U> child : children.values())
+ {
+ names.add(child.getFullName());
+ }
}
+ return names;
}
- return names;
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -345,7 +411,21 @@
*/
public Collection<Node<U>> getChildren()
{
- return (children != null) ? children.values() : Collections.<Node<U>>emptySet();
+ lock.readLock().lock();
+ try
+ {
+ return (children != null) ? children.values() : Collections.<Node<U>>emptySet();
+ }
+ finally
+ {
+ lock.readLock().unlock();
+ }
}
+
+ @Override
+ public String toString()
+ {
+ return getFullName();
+ }
}
}
Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2009-06-17 13:00:41 UTC (rev 90326)
@@ -22,6 +22,7 @@
package org.jboss.deployers.vfs.spi.structure.modified;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
import org.jboss.virtual.VisitorAttributes;
/**
@@ -36,7 +37,12 @@
public UpdateDeleteVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot)
{
- super(attributes, cache, synchAdapter);
+ this(null, attributes, cache, synchAdapter, originalRoot);
+ }
+
+ public UpdateDeleteVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot)
+ {
+ super(filter, attributes, cache, synchAdapter);
if (originalRoot == null)
throw new IllegalArgumentException("Null original root");
Modified: projects/jboss-deployers/branches/Branch_2_0/pom.xml
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/pom.xml 2009-06-17 12:55:29 UTC (rev 90325)
+++ projects/jboss-deployers/branches/Branch_2_0/pom.xml 2009-06-17 13:00:41 UTC (rev 90326)
@@ -161,7 +161,12 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
- <version>1.0.0</version>
+ <version>2.0.1</version>
+ <configuration>
+ <findbugsXmlOutput>true</findbugsXmlOutput>
+ <!-- Optional directory to put findbugs xml report -->
+ <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>
+ </configuration>
</plugin>
</plugins>
</reporting>
More information about the jboss-cvs-commits
mailing list