[jboss-cvs] JBossAS SVN: r104934 - in projects/jboss-deployers/branches/Branch_2_0: deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/matchers and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 18 11:09:21 EDT 2010


Author: alesj
Date: 2010-05-18 11:09:19 -0400 (Tue, 18 May 2010)
New Revision: 104934

Added:
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractIgnoreFilesDeployer.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/SingleNIM.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/matchers/ignore/META-INF/jboss-ignore.txt
Modified:
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractParsingDeployerWithOutput.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/CollectionNameIgnoreMechanism.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/PatternNameIgnoreMechanism.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/matchers/NameIgnoreMechanism.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
   projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/NameIgnoreMechanismTestCase.java
Log:
[JBDEPLOY-220]; port name ignore mechanism.

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractParsingDeployerWithOutput.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractParsingDeployerWithOutput.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractParsingDeployerWithOutput.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -380,7 +380,7 @@
    protected boolean ignoreName(DeploymentUnit unit, String name)
    {
       NameIgnoreMechanism mechanism = unit.getAttachment(NameIgnoreMechanism.class);
-      return mechanism != null && mechanism.ignore(unit, name);
+      return mechanism != null && mechanism.ignoreName(unit, name);
    }
 
    /**

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/CollectionNameIgnoreMechanism.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/CollectionNameIgnoreMechanism.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/CollectionNameIgnoreMechanism.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -27,21 +27,28 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 
 /**
- * Ignore a collection of names.
+ * Ignore a collection of names and paths.
  *
  * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public class CollectionNameIgnoreMechanism implements NameIgnoreMechanism
 {
-   private Collection<String> ignored;
+   private final Collection<String> ignoredNames;
+   private final Collection<String> ignoredPaths;
 
-   public CollectionNameIgnoreMechanism(Collection<String> ignored)
+   public CollectionNameIgnoreMechanism(Collection<String> ignoredNames, Collection<String> ignoredPaths)
    {
-      this.ignored = ignored;
+      this.ignoredNames = ignoredNames;
+      this.ignoredPaths = ignoredPaths;
    }
 
-   public boolean ignore(DeploymentUnit unit, String name)
+   public boolean ignoreName(DeploymentUnit unit, String name)
    {
-      return ignored != null && ignored.contains(name);
+      return ignoredNames != null && ignoredNames.contains(name);
    }
+
+   public boolean ignorePath(DeploymentUnit unit, String path)
+   {
+      return ignoredPaths != null && ignoredPaths.contains(path);
+   }
 }

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/PatternNameIgnoreMechanism.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/PatternNameIgnoreMechanism.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/PatternNameIgnoreMechanism.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -21,8 +21,8 @@
  */
 package org.jboss.deployers.spi.deployer.helpers;
 
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.regex.Matcher;
 
 import org.jboss.deployers.spi.deployer.matchers.NameIgnoreMechanism;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -45,9 +45,19 @@
       ignored = Pattern.compile(regexp);
    }
 
-   public boolean ignore(DeploymentUnit unit, String name)
+   public boolean ignoreName(DeploymentUnit unit, String name)
    {
-      Matcher matcher = ignored.matcher(name);
+      return ignore(unit, name);
+   }
+
+   public boolean ignorePath(DeploymentUnit unit, String path)
+   {
+      return ignore(unit, path);
+   }
+
+   protected boolean ignore(DeploymentUnit unit, String input)
+   {
+      Matcher matcher = ignored.matcher(input);
       return (match) ? matcher.matches() : matcher.find();
    }
 
@@ -61,4 +71,4 @@
    {
       this.match = match;
    }
-}
\ No newline at end of file
+}

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/matchers/NameIgnoreMechanism.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/matchers/NameIgnoreMechanism.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/matchers/NameIgnoreMechanism.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -37,5 +37,14 @@
     * @param name the name to check
     * @return true if we should ignore this name, false otherwise
     */
-   boolean ignore(DeploymentUnit unit, String name);
+   boolean ignoreName(DeploymentUnit unit, String name);
+
+   /**
+    * Do we ignore this relative path.
+    *
+    * @param unit the deployment unit
+    * @param path the relative path to check
+    * @return true if we should ignore this path, false otherwise
+    */
+   boolean ignorePath(DeploymentUnit unit, String path);
 }

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/SingleNIM.java (from rev 104929, projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/NIMDeployer.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/SingleNIM.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/support/SingleNIM.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.matchers.support;
+
+import org.jboss.deployers.spi.deployer.matchers.NameIgnoreMechanism;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SingleNIM implements NameIgnoreMechanism
+{
+   private String ignore;
+
+   public SingleNIM(String ignore)
+   {
+      this.ignore = ignore;
+   }
+
+   public boolean ignoreName(DeploymentUnit unit, String name)
+   {
+      return name.equals(ignore);
+   }
+
+   public boolean ignorePath(DeploymentUnit unit, String path)
+   {
+      return path.equals("META-INF/" + ignore);
+   }
+}

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/NameIgnoreMechanismTestCase.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/NameIgnoreMechanismTestCase.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/matchers/test/NameIgnoreMechanismTestCase.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -22,19 +22,20 @@
 package org.jboss.test.deployers.vfs.matchers.test;
 
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-import junit.framework.Test;
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.deployer.helpers.CollectionNameIgnoreMechanism;
 import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.spi.deployer.AbstractIgnoreFilesDeployer;
 import org.jboss.test.deployers.BaseDeployersVFSTest;
 import org.jboss.test.deployers.vfs.matchers.support.FeedbackDeployer;
 import org.jboss.test.deployers.vfs.matchers.support.NIMDeployer;
+import org.jboss.test.deployers.vfs.matchers.support.SingleNIM;
 
+import junit.framework.Test;
+
 /**
  * Name ignore mechanism tests.
  *
@@ -54,7 +55,7 @@
 
    protected void testNameIgnoreMechanism(FeedbackDeployer fbd, int size) throws Throwable
    {
-      NIMDeployer nimd = new NIMDeployer(new CollectionNameIgnoreMechanism(Collections.singleton("fst.txt")));
+      NIMDeployer nimd = new NIMDeployer(new SingleNIM("fst.txt"));
 
       DeployerClient main = createMainDeployer(fbd, nimd);
       addStructureDeployer(main, new JARStructure());
@@ -72,7 +73,7 @@
       fbd1.setName("empty.txt");
       FeedbackDeployer fbd2 = new FeedbackDeployer();
       fbd2.setName("fst.txt");
-      NIMDeployer nimd = new NIMDeployer(new CollectionNameIgnoreMechanism(Collections.singleton("fst.txt")));
+      NIMDeployer nimd = new NIMDeployer(new SingleNIM("fst.txt"));
 
       DeployerClient main = createMainDeployer(fbd1, fbd2, nimd);
       addStructureDeployer(main, new JARStructure());
@@ -99,7 +100,7 @@
       fbd.setSuffix(".txt");
       fbd.setAllowMultipleFiles(true);
 
-      testNameIgnoreMechanism(fbd, 2);
+      testNameIgnoreMechanism(fbd, 3);
    }
 
    public void testNamesWithSuffix() throws Throwable
@@ -111,4 +112,22 @@
 
       testNameIgnoreMechanism(fbd, 3);
    }
-}
\ No newline at end of file
+
+   public void testRealNIMDeployer() throws Throwable
+   {
+      FeedbackDeployer fbd = new FeedbackDeployer();
+      fbd.setSuffix(".txt");
+      fbd.setAllowMultipleFiles(true);
+
+      AbstractIgnoreFilesDeployer nimd = new AbstractIgnoreFilesDeployer();
+
+      DeployerClient main = createMainDeployer(fbd, nimd);
+      addStructureDeployer(main, new JARStructure());
+
+      Deployment deployment = createDeployment("/matchers", "ignore");
+      main.deploy(deployment);
+
+      assertEquals(2, fbd.getFiles().size());
+      assertFalse(fbd.getFiles().contains("fst.txt"));
+   }
+}

Added: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/matchers/ignore/META-INF/jboss-ignore.txt
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/matchers/ignore/META-INF/jboss-ignore.txt	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs/src/test/resources/matchers/ignore/META-INF/jboss-ignore.txt	2010-05-18 15:09:19 UTC (rev 104934)
@@ -0,0 +1,2 @@
+META-INF/jboss-ignore.txt
+META-INF/fst.txt

Copied: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractIgnoreFilesDeployer.java (from rev 104929, projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractOptionalVFSRealDeployer.java)
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractIgnoreFilesDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractIgnoreFilesDeployer.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.deployer;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.CollectionNameIgnoreMechanism;
+import org.jboss.deployers.spi.deployer.matchers.NameIgnoreMechanism;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Create a path ignore mechanism based on txt file.
+ * The file should include relative paths wrt its owner (sub)deployment.
+ * e.g. META-INF/some-custom.xml or WEB-INF/lib/ui.jar/META-INF/persistence.xml
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AbstractIgnoreFilesDeployer extends AbstractVFSParsingDeployer<NameIgnoreMechanism>
+{
+   public AbstractIgnoreFilesDeployer()
+   {
+      super(NameIgnoreMechanism.class);
+      setStage(DeploymentStages.PRE_PARSE);
+      setName("jboss-ignore.txt");
+   }
+
+   protected NameIgnoreMechanism parse(VFSDeploymentUnit unit, VirtualFile file, NameIgnoreMechanism root) throws Exception
+   {
+      InputStream is = file.openStream();
+      try
+      {
+         Set<String> ignoredPaths = new HashSet<String>();
+
+         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+         String line;
+         while ((line = reader.readLine()) != null)
+         {
+            line = line.trim();
+            if (line.length() > 0)
+               ignoredPaths.add(line);
+         }
+
+         return ignoredPaths.isEmpty() ? null : new CollectionNameIgnoreMechanism(null, ignoredPaths);
+      }
+      finally
+      {
+         is.close();
+      }
+   }
+}

Modified: projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2010-05-18 14:38:00 UTC (rev 104933)
+++ projects/jboss-deployers/branches/Branch_2_0/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2010-05-18 15:09:19 UTC (rev 104934)
@@ -32,8 +32,11 @@
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractParsingDeployerWithOutput;
+import org.jboss.deployers.spi.deployer.matchers.NameIgnoreMechanism;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractStructureBuilder;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -175,7 +178,25 @@
       return altMappingsMap != null ? altMappingsMap.get(fileName) : null;
    }
 
-   @Override
+   /**
+    * Ignore file.
+    *
+    * @param unit the unit
+    * @param file the file
+    * @return true if we should ignore the file, false otherwise
+    */
+   protected boolean ignoreFile(VFSDeploymentUnit unit, VirtualFile file)
+   {
+      NameIgnoreMechanism mechanism = unit.getAttachment(NameIgnoreMechanism.class);
+      if (mechanism != null)
+      {
+         VirtualFile root = unit.getRoot();
+         String path = AbstractStructureDeployer.getRelativePath(root, file);
+         return mechanism.ignorePath(unit, path);
+      }
+      return false;
+   }
+
    protected T parse(DeploymentUnit unit, String name, T root) throws Exception
    {
       if (ignoreName(unit, name))
@@ -185,7 +206,7 @@
       VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
 
       VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput(), name, true);
-      return (file != null) ? parseAndInit(vfsDeploymentUnit, file, root) : null;
+      return (file != null && ignoreFile(vfsDeploymentUnit, file) == false) ? parseAndInit(vfsDeploymentUnit, file, root) : null;
    }
 
    protected T parse(DeploymentUnit unit, Set<String> names, T root) throws Exception
@@ -209,9 +230,16 @@
          {
             VirtualFile file = getMetadataFile(vfsDeploymentUnit, matchFileToClass(unit, name), name, true);
             if (file != null)
-               files.add(file);
+            {
+               if (ignoreFile(vfsDeploymentUnit, file))
+                  ignoredFiles.add(file.getName());
+               else
+                  files.add(file);
+            }
             else
+            {
                missingFiles.add(name);
+            }
          }
       }
 
@@ -276,7 +304,7 @@
     */
    protected T parseAndInit(VFSDeploymentUnit unit, VirtualFile file, T root, boolean checkIgnore) throws Exception
    {
-      if (checkIgnore && ignoreName(unit, file.getName()))
+      if (checkIgnore && ignoreFile(unit, file))
          return null;
 
       T result = parse(unit, file, root);
@@ -310,10 +338,22 @@
             {
                List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
                if (matched != null && matched.isEmpty() == false)
-                  files.addAll(matched);
+               {
+                  for (VirtualFile m : matched)
+                  {
+                     if (ignoreFile(vfsDeploymentUnit, m))
+                        ignoredFiles.add(m.getName());
+                     else
+                        files.add(m);
+                  }
+               }
                else
                   missingFiles.add(name);
             }
+            else if (ignoreFile(vfsDeploymentUnit, file))
+            {
+               ignoredFiles.add(file.getName());
+            }
             else
             {
                files.add(file);
@@ -359,7 +399,7 @@
 
       for (VirtualFile file : files)
       {
-         if (ignoreName(unit, file.getName()) == false)
+         if (ignoreFile(unit, file) == false)
          {
             T result = parse(unit, file, root);
             if (result != null)




More information about the jboss-cvs-commits mailing list