[jboss-cvs] JBossAS SVN: r93802 - in projects/jboss-deployers/branches/Branch_2_0: deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 21 07:30:14 EDT 2009


Author: alesj
Date: 2009-09-21 07:30:13 -0400 (Mon, 21 Sep 2009)
New Revision: 93802

Added:
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/ModificationCheckerFilter.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/dir/GroupingStructure.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/EsbStructureUnitTestCase.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/GroupingStructureUnitTestCase.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/SubDirectoryStructureTest.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/META-INF/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/META-INF/empty.txt
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/META-INF/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/META-INF/empty.txt
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/WEB-INF/
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/WEB-INF/empty.txt
Modified:
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/DirStructureUnitTestCase.java
Log:
Port JBDEPLOY-207, JBDEPLOY-208.

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/dir/GroupingStructure.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/dir/GroupingStructure.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/dir/GroupingStructure.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1,268 @@
+/*
+ * 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.plugins.structure.dir;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.vfs.plugins.structure.AbstractVFSStructureDeployer;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+import org.jboss.util.collection.CollectionsFactory;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * Similar to jar or directory structure,
+ * being able to handle sub-dirs, but a bit more strict then dir structure.
+ * Only listed sub-directories are candidates for potential sub-deployments.
+ *
+ * It also allows you to set metadata paths, libs and should the root be part of classpath.
+ * Each of sub-dirs can be filtered per path or by default per lib or group.
+ *
+ * In order to accept anything one must first set shortCircuitFilter instance.
+ *
+ * @see org.jboss.deployers.vfs.plugins.structure.jar.JARStructure
+ * @see org.jboss.deployers.vfs.plugins.structure.dir.DirectoryStructure
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GroupingStructure extends AbstractVFSStructureDeployer
+{
+   private static final String[] META_INF = {"META-INF"};
+
+   private VirtualFileFilter shortCircuitFilter; // by default null, so we don't accept anything
+   private boolean rootClasspathEntry;
+
+   // paths
+   private String[] metaDataPaths;
+   private Set<String> libs;
+   private Set<String> groups;
+
+   // filters
+   private VirtualFileFilter libFilter;
+   private VirtualFileFilter groupFilter;
+   private Map<String, VirtualFileFilter> filters; // filter per path
+
+   public GroupingStructure()
+   {
+      setRelativeOrder(9000); // before jar structure
+      setRootClasspathEntry(true); // by default root is part of classpath
+      setLibs(Collections.<String>emptySet()); // empty libs
+      setMetaDataPaths(META_INF); // default metadata locations
+      setGroups(CollectionsFactory.<String>createLazySet()); // lazy groups
+      setFilters(Collections.<String, VirtualFileFilter>emptyMap()); // empty filters
+   }
+
+   public boolean determineStructure(StructureContext structureContext) throws DeploymentException
+   {
+      VirtualFile file = structureContext.getFile();
+
+      if (shortCircuitFileCheck(file) == false)
+         return false;
+
+      ContextInfo context = null;
+      try
+      {
+         context = createContext(structureContext, metaDataPaths);
+
+         if (rootClasspathEntry)
+            addClassPath(structureContext, file, true, true, context);
+
+         // add any archives in libs
+         for (String lib : libs)
+         {
+            VirtualFile libVF = file.getChild(lib);
+            if (libVF != null)
+            {
+               VirtualFileFilter lf = filters.get(lib);
+               if (lf == null)
+                  lf = libFilter;
+
+               List<VirtualFile> archives = libVF.getChildren(lf);
+               for (VirtualFile archive : archives)
+                  addClassPath(structureContext, archive, true, true, context);
+            }
+            else
+            {
+               if (log.isTraceEnabled())
+                  log.trace("No such lib: " + lib + ", " + file);
+            }
+         }
+
+         // check only children of defined sub-dirs / groups
+         for (String group : groups)
+         {
+            VirtualFile groupVF = file.getChild(group);
+            if (groupVF != null)
+            {
+               VirtualFileFilter gf = filters.get(group);
+               if (gf == null)
+                  gf = groupFilter;
+
+               List<VirtualFile> children = groupVF.getChildren(gf);
+               for (VirtualFile child : children)
+                  structureContext.determineChildStructure(child);
+            }
+            else
+            {
+               if (log.isTraceEnabled())
+                  log.trace("No such group: " + group + ", " + file);
+            }
+         }
+
+         return true;
+      }
+      catch (Exception e)
+      {
+         // Remove the invalid context
+         if (context != null)
+            structureContext.removeChild(context);
+
+         throw DeploymentException.rethrowAsDeploymentException("Error determining structure: " + file.getName(), e);
+      }
+   }
+
+   /**
+    * Do short circuit file check.
+    *
+    * @param file the file
+    * @return true if we accept the file
+    */
+   protected boolean shortCircuitFileCheck(VirtualFile file)
+   {
+      return shortCircuitFilter != null && shortCircuitFilter.accepts(file);
+   }
+
+   /**
+    * Set short circuit file filter.
+    *
+    * @param shortCircuitFilter the short circuit file filter
+    */
+   public void setShortCircuitFilter(VirtualFileFilter shortCircuitFilter)
+   {
+      this.shortCircuitFilter = shortCircuitFilter;
+   }
+
+   /**
+    * Is root part of classpath.
+    *
+    * @param rootClasspathEntry root cp flag
+    */
+   public void setRootClasspathEntry(boolean rootClasspathEntry)
+   {
+      this.rootClasspathEntry = rootClasspathEntry;
+   }
+
+   /**
+    * Set libs; added as cp entries.
+    *
+    * @param libs the libs
+    */
+   public void setLibs(Set<String> libs)
+   {
+      if (libs == null)
+         throw new IllegalArgumentException("Null libs");
+
+      this.libs = libs;
+   }
+
+   /**
+    * Set default lib filter.
+    *
+    * @param libFilter the filter
+    */
+   public void setLibFilter(VirtualFileFilter libFilter)
+   {
+      this.libFilter = libFilter;
+   }
+
+   /**
+    * Set the default metadata paths.
+    *
+    * @param metaDataPaths the meta data paths
+    */
+   public void setMetaDataPaths(String[] metaDataPaths)
+   {
+      this.metaDataPaths = metaDataPaths;
+   }
+
+   /**
+    * Set groups.
+    * Aka grouping sub-directories.
+    *
+    * @param groups the groups
+    */
+   public void setGroups(Set<String> groups)
+   {
+      if (groups == null)
+         throw new IllegalArgumentException("Null groups");
+
+      this.groups = groups;
+   }
+
+   /**
+    * Add group.
+    *
+    * @param group the group
+    */
+   public void addGroup(String group)
+   {
+      groups.add(group);
+   }
+
+   /**
+    * Remove group.
+    *
+    * @param group the group
+    */
+   public void removeGroup(String group)
+   {
+      groups.remove(group);
+   }
+
+   /**
+    * Set default group filter.
+    *
+    * @param groupFilter the filter
+    */
+   public void setGroupFilter(VirtualFileFilter groupFilter)
+   {
+      this.groupFilter = groupFilter;
+   }
+
+   /**
+    * Set filter per path.
+    *
+    * @param filters the filters
+    */
+   public void setFilters(Map<String, VirtualFileFilter> filters)
+   {
+      if (filters == null)
+         throw new IllegalArgumentException("Null filters");
+
+      this.filters = filters;
+   }
+}

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java	2009-09-21 10:57:20 UTC (rev 93801)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/AbstractStructureTest.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -69,13 +69,28 @@
 
    protected void assertChildContexts(VFSDeploymentContext context, String... paths)
    {
+      assertChildContexts(context, false, paths);
+   }
+
+   protected void assertChildContexts(VFSDeploymentContext context, boolean flatten, String... paths)
+   {
       List<String> expected = new ArrayList<String>();
       if (paths != null)
       {
          for (String path : paths)
             expected.add(path);
       }
-      List<DeploymentContext> children = context.getChildren();
+
+      List<DeploymentContext> children;
+      if (flatten)
+      {
+         children = new ArrayList<DeploymentContext>();
+         flattenContexts(children, context);
+      }
+      else
+      {
+         children = context.getChildren();
+      }
       assertNotNull(children);
       assertEquals("Expected " + expected + " got " + simplePrint(children), expected.size(), children.size());
       
@@ -84,14 +99,47 @@
          boolean found = false;
          for (DeploymentContext child : children)
          {
-            if (path.equals(child.getRelativePath()))
+            String childPath = child.getRelativePath();
+            if (path.equals(childPath))
+            {
                found = true;
+               break;
+            }
+            if (flatten)
+            {
+               DeploymentContext parent = child.getParent();
+               if (parent != null)
+               {
+                  String parentPath = parent.getRelativePath();
+                  if (parentPath.endsWith("/") == false && childPath.startsWith("/") == false)
+                     parentPath += "/";
+
+                  if (path.equals(parentPath + childPath))
+                  {
+                     found = true;
+                     break;
+                  }
+               }
+            }
          }
          if (found == false)
             fail("Expected " + path + " in " + children);
       }
    }
-   
+
+   protected void flattenContexts(List<DeploymentContext> contexts, DeploymentContext context)
+   {
+      List<DeploymentContext> children = context.getChildren();
+      if (children != null)
+      {
+         for (DeploymentContext dc : children)
+         {
+            contexts.add(dc);
+            flattenContexts(contexts, dc);
+         }
+      }
+   }
+
    protected String simplePrint(List<DeploymentContext> children)
    {
       StringBuilder builder = new StringBuilder();

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java	2009-09-21 10:57:20 UTC (rev 93801)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -25,6 +25,8 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 import org.jboss.test.deployers.vfs.structure.dir.test.DirStructureUnitTestCase;
+import org.jboss.test.deployers.vfs.structure.dir.test.EsbStructureUnitTestCase;
+import org.jboss.test.deployers.vfs.structure.dir.test.GroupingStructureUnitTestCase;
 import org.jboss.test.deployers.vfs.structure.dir.test.RealDirStructureUnitTestCase;
 import org.jboss.test.deployers.vfs.structure.ear.test.EARStructureRecognizeTestCase;
 import org.jboss.test.deployers.vfs.structure.ear.test.EARStructureUnitTestCase;
@@ -84,6 +86,8 @@
       suite.addTest(InnerModificationUnitTestCase.suite());
       suite.addTest(DirStructureUnitTestCase.suite());
       suite.addTest(RealDirStructureUnitTestCase.suite());
+      suite.addTest(GroupingStructureUnitTestCase.suite());
+      suite.addTest(EsbStructureUnitTestCase.suite());
       suite.addTest(MetaDataStructureModificationTestCase.suite());
       suite.addTest(MetaDataStructureModificationTreeCacheTestCase.suite());
       suite.addTest(SynchModificationTestCase.suite());

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/DirStructureUnitTestCase.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/DirStructureUnitTestCase.java	2009-09-21 10:57:20 UTC (rev 93801)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/DirStructureUnitTestCase.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -22,11 +22,10 @@
 package org.jboss.test.deployers.vfs.structure.dir.test;
 
 import junit.framework.Test;
+import org.jboss.deployers.vfs.plugins.structure.dir.DirectoryStructure;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
-import org.jboss.deployers.vfs.plugins.structure.dir.DirectoryStructure;
-import org.jboss.test.deployers.vfs.structure.AbstractStructureTest;
 import org.jboss.test.deployers.vfs.structure.ear.support.MockEarStructureDeployer;
 
 /**
@@ -35,7 +34,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class DirStructureUnitTestCase extends AbstractStructureTest
+public class DirStructureUnitTestCase extends SubDirectoryStructureTest
 {
    public DirStructureUnitTestCase(String name)
    {
@@ -47,33 +46,14 @@
       return suite(DirStructureUnitTestCase.class);
    }
 
+   protected boolean shouldFlattenContext()
+   {
+      return false;  // this one already produces flat view
+   }
+
    @SuppressWarnings("deprecation")
    protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
    {
       return determineStructureWithStructureDeployers(deployment, new MockEarStructureDeployer(), new JARStructure(), new DirectoryStructure());
    }
-
-   public void testSarWithLib() throws Throwable
-   {
-      VFSDeploymentContext context = assertDeploy("/structure/dir", "test-in-lib.sar");
-      assertChildContexts(context, "lib/test.jar");
-   }
-
-   public void testSarWithNestedLib() throws Throwable
-   {
-      VFSDeploymentContext context = assertDeploy("/structure/dir", "test-in-lib-nested.sar");
-      assertChildContexts(context, "lib/nested/test.jar");
-   }
-
-   public void testEarSarWithLib() throws Throwable
-   {
-      VFSDeploymentContext context = assertDeploy("/structure/dir", "simple.ear");
-      assertChildContexts(context, "test-in-lib.sar", "test-in-lib.sar/lib/test.jar");
-   }
-
-   public void testEarSarWithNestedLib() throws Throwable
-   {
-      VFSDeploymentContext context = assertDeploy("/structure/dir", "nested.ear");
-      assertChildContexts(context, "test-in-lib-nested.sar", "test-in-lib-nested.sar/lib/nested/test.jar");
-   }
 }

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/EsbStructureUnitTestCase.java (from rev 91963, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/EsbStructureUnitTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/EsbStructureUnitTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/EsbStructureUnitTestCase.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1,72 @@
+/*
+* 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.structure.dir.test;
+
+import junit.framework.Test;
+import org.jboss.deployers.vfs.plugins.structure.dir.GroupingStructure;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.plugins.structure.war.WARStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.test.deployers.vfs.structure.AbstractStructureTest;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * Esb example test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class EsbStructureUnitTestCase extends AbstractStructureTest
+{
+   public EsbStructureUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(EsbStructureUnitTestCase.class);
+   }
+   
+   protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
+   {
+      GroupingStructure gs = new GroupingStructure();
+      VirtualFileFilter top = new VirtualFileFilter()
+      {
+         public boolean accepts(VirtualFile file)
+         {
+            return file.getName().endsWith(".esb");
+         }
+      };
+      gs.setShortCircuitFilter(top);
+      gs.addGroup("jars");
+      gs.addGroup("wars");
+      return determineStructureWithStructureDeployers(deployment, new JARStructure(), new WARStructure(), gs);
+   }
+
+   public void testEsbStructure() throws Throwable
+   {
+      VFSDeploymentContext context = assertDeploy("/structure/dir", "beve.esb");
+      assertChildContexts(context, "jars/j1.jar", "wars/w1.war");
+   }
+}
\ 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/dir/test/GroupingStructureUnitTestCase.java (from rev 91963, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/GroupingStructureUnitTestCase.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/GroupingStructureUnitTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/GroupingStructureUnitTestCase.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1,71 @@
+/*
+* 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.structure.dir.test;
+
+import junit.framework.Test;
+import org.jboss.deployers.vfs.plugins.structure.dir.GroupingStructure;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.test.deployers.vfs.structure.ear.support.MockEarStructureDeployer;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test grouping examples.
+ * Substitute for legacy DirectoryStrucutre.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GroupingStructureUnitTestCase extends SubDirectoryStructureTest
+{
+   public GroupingStructureUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(GroupingStructureUnitTestCase.class);
+   }
+
+   protected boolean shouldFlattenContext()
+   {
+      return true;
+   }
+
+   protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
+   {
+      GroupingStructure gs = new GroupingStructure();
+      VirtualFileFilter top = new VirtualFileFilter()
+      {
+         public boolean accepts(VirtualFile file)
+         {
+            return file.getName().endsWith(".sar");
+         }
+      };
+      gs.setShortCircuitFilter(top);
+      gs.addGroup("lib");
+      gs.addGroup("lib/nested");
+      return determineStructureWithStructureDeployers(deployment, new MockEarStructureDeployer(), new JARStructure(), gs);
+   }
+}
\ 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/dir/test/SubDirectoryStructureTest.java (from rev 91963, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/SubDirectoryStructureTest.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/SubDirectoryStructureTest.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/dir/test/SubDirectoryStructureTest.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1,64 @@
+/*
+* 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.structure.dir.test;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.test.deployers.vfs.structure.AbstractStructureTest;
+
+/**
+ * Test sub dir handling.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class SubDirectoryStructureTest extends AbstractStructureTest
+{
+   protected SubDirectoryStructureTest(String name)
+   {
+      super(name);
+   }
+
+   protected abstract boolean shouldFlattenContext();
+
+   public void testSarWithLib() throws Throwable
+   {
+      VFSDeploymentContext context = assertDeploy("/structure/dir", "test-in-lib.sar");
+      assertChildContexts(context, "lib/test.jar");
+   }
+
+   public void testSarWithNestedLib() throws Throwable
+   {
+      VFSDeploymentContext context = assertDeploy("/structure/dir", "test-in-lib-nested.sar");
+      assertChildContexts(context, "lib/nested/test.jar");
+   }
+
+   public void testEarSarWithLib() throws Throwable
+   {
+      VFSDeploymentContext context = assertDeploy("/structure/dir", "simple.ear");
+      assertChildContexts(context, shouldFlattenContext(), "test-in-lib.sar", "test-in-lib.sar/lib/test.jar");
+   }
+
+   public void testEarSarWithNestedLib() throws Throwable
+   {
+      VFSDeploymentContext context = assertDeploy("/structure/dir", "nested.ear");
+      assertChildContexts(context, shouldFlattenContext(), "test-in-lib-nested.sar", "test-in-lib-nested.sar/lib/nested/test.jar");
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/META-INF/empty.txt
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/META-INF/empty.txt	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/META-INF/empty.txt	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1 @@
+empty

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/META-INF/empty.txt
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/META-INF/empty.txt	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/jars/j1.jar/META-INF/empty.txt	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1 @@
+empty

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/WEB-INF/empty.txt
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/WEB-INF/empty.txt	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/structure/dir/beve.esb/wars/w1.war/WEB-INF/empty.txt	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1 @@
+empty

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java	2009-09-21 10:57:20 UTC (rev 93801)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -46,8 +46,11 @@
    /** The main deployer structure */
    private MainDeployerStructure mainDeployer;
 
+   /** The root filter */
+   private ModificationCheckerFilter rootFilter;
+
    /** The structure cache */
-   private StructureCache<T> cache;
+   private volatile StructureCache<T> cache;
 
    protected AbstractStructureModificationChecker()
    {
@@ -62,8 +65,38 @@
    }
 
    /**
+    * Get root filter.
+    *
+    * Use DefaultRootFilter if no explicit config
+    *
+    * @return
+    */
+   protected ModificationCheckerFilter getRootFilter()
+   {
+      if (rootFilter == null)
+         rootFilter = new DefaultRootFilter();
+
+      return rootFilter;
+   }
+
+   /**
+    * Set root filter.
+    *
+    * @param rootFilter the root filter
+    */
+   public void setRootFilter(ModificationCheckerFilter rootFilter)
+   {
+      if (rootFilter == null)
+         throw new IllegalArgumentException("Null root filter");
+
+      this.rootFilter = rootFilter;
+   }
+
+   /**
     * Get the structure cache.
     *
+    * Use DefaultStructureCache if no explict config.
+    *
     * @return the structure cache
     */
    protected StructureCache<T> getCache()
@@ -118,15 +151,15 @@
       if (root == null)
          throw new IllegalArgumentException("Null root");
 
-      // skip vfs deployment context lookup if archive or file
-      if (root.isArchive() || root.isLeaf())
+      // skip vfs deployment context lookup accepted by filter
+      if (getRootFilter().accepts(root))
       {
          boolean result = hasRootBeenModified(root);
-         if (result)
+         if (result || getRootFilter().checkRootOnly(root))
          {
             getCache().invalidateCache(root.getPathName());
+            return result;
          }
-         return result;
       }
 
       VFSDeploymentContext deploymentContext;
@@ -184,13 +217,16 @@
       VirtualFile root = vfsDeployment.getRoot();
 
       boolean result = false;
+      boolean skip = false; // skip futher check
 
-      if (checkRoot && (root.isArchive() || root.isLeaf()))
+      if (checkRoot && getRootFilter().accepts(root))
       {
          result = hasRootBeenModified(root);
+         if (result || getRootFilter().checkRootOnly(root))
+            skip = true;
       }
 
-      if (result == false)
+      if (skip == false)
       {
          result = hasStructureBeenModifed(root, deploymentContext);
       }
@@ -243,4 +279,27 @@
       String pathName = root.getPathName();
       getCache().removeCache(pathName);
    }
+
+   /**
+    * Default root check constraints.
+    */
+   private static class DefaultRootFilter implements ModificationCheckerFilter
+   {
+      public boolean accepts(VirtualFile file)
+      {
+         try
+         {
+            return file.isLeaf() || file.isArchive();
+         }
+         catch (IOException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+
+      public boolean checkRootOnly(VirtualFile root)
+      {
+         return true; // no point in checking entries 
+      }
+   }
 }

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/ModificationCheckerFilter.java (from rev 92386, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/ModificationCheckerFilter.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/ModificationCheckerFilter.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/ModificationCheckerFilter.java	2009-09-21 11:30:13 UTC (rev 93802)
@@ -0,0 +1,45 @@
+/*
+ * 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.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+
+/**
+ * ModificationCheckerFilter.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ModificationCheckerFilter extends VirtualFileFilter
+{
+   /**
+    * Decide whether we should continue with checking for modification
+    * where this filter accepted the root, but root's modification result was false.
+    *
+    * e.g. no point in checking anything further in archives and leaves,
+    * but we should check further if root is a directory
+    *
+    * @param root the current root
+    * @return true if we only check root, false otherwise
+    */
+   boolean checkRootOnly(VirtualFile root);
+}




More information about the jboss-cvs-commits mailing list