[jboss-cvs] JBossAS SVN: r83354 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 23 11:29:09 EST 2009


Author: alesj
Date: 2009-01-23 11:29:09 -0500 (Fri, 23 Jan 2009)
New Revision: 83354

Added:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/AbstractModificationTypeMatcher.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/FileModificationTypeMatcher.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeMatcher.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeStructureDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/RootModificationTypeMatcher.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/TempTopModificationTypeMatcher.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/StructureContext.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
Log:
[JBDEPLOY-154]; initial modification type setting work.


Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/AbstractModificationTypeMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/AbstractModificationTypeMatcher.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/AbstractModificationTypeMatcher.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -0,0 +1,95 @@
+/*
+ * 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.modify;
+
+import org.jboss.deployers.spi.structure.ModificationType;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Abstract modification type matcher.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractModificationTypeMatcher implements ModificationTypeMatcher
+{
+   protected Logger log = Logger.getLogger(getClass());
+   
+   private boolean applyModificationToTop;
+   private ModificationType modificationType;
+
+   public boolean determineModification(StructureContext structureContext)
+   {
+      boolean result = isModificationDetermined(structureContext);
+      if (result)
+      {
+         StructureContext context = structureContext;
+         if (applyModificationToTop && structureContext.isTopLevel() == false)
+            context = getTopStructureContext(context);
+
+         context.setModificationType(modificationType);
+      }
+      return result;
+   }
+
+   /**
+    * Do we have a modification match.
+    *
+    * @param structureContext the structure context
+    * @return true if we should apply the modification
+    */
+   protected abstract boolean isModificationDetermined(StructureContext structureContext);
+
+   /**
+    * Get top structure context.
+    *
+    * @param context the current structure context
+    * @return the top structure context
+    */
+   protected StructureContext getTopStructureContext(StructureContext context)
+   {
+      while (context.getParentContext() != null)
+         context = context.getParentContext();
+
+      return context;
+   }
+
+   /**
+    * Do we apply modification to the top structure context.
+    *
+    * @param applyModificationToTop the apply to top flag
+    */
+   public void setApplyModificationToTop(boolean applyModificationToTop)
+   {
+      this.applyModificationToTop = applyModificationToTop;
+   }
+
+   /**
+    * Set the modification type.
+    *
+    * @param modificationType the modification type
+    */
+   public void setModificationType(ModificationType modificationType)
+   {
+      this.modificationType = modificationType;
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/FileModificationTypeMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/FileModificationTypeMatcher.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/FileModificationTypeMatcher.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -0,0 +1,72 @@
+/*
+ * 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.modify;
+
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * File modification type matcher.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class FileModificationTypeMatcher extends AbstractModificationTypeMatcher
+{
+   private String[] paths;
+
+   public FileModificationTypeMatcher(String... paths)
+   {
+      if (paths == null || paths.length == 0)
+         throw new IllegalArgumentException("Null or empty paths");
+
+      this.paths = paths;
+   }
+
+   /**
+    * Get the starting file.
+    *
+    * @param structureContext the structure context
+    * @return the startting file; where do we start checking for paths
+    */
+   protected VirtualFile getStartingFile(StructureContext structureContext)
+   {
+      return structureContext.getFile();
+   }
+
+   protected boolean isModificationDetermined(StructureContext structureContext)
+   {
+      VirtualFile startingFile = getStartingFile(structureContext);
+      for (String path : paths)
+      {
+         try
+         {
+            if (startingFile.getChild(path) != null)
+               return true;
+         }
+         catch (Exception e)
+         {
+            log.debug("Cannot determine modification type, cause: " + e);
+         }
+      }
+      return false;
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeMatcher.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeMatcher.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -0,0 +1,40 @@
+/*
+ * 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.modify;
+
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+
+/**
+ * Determine if we need some modification.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ModificationTypeMatcher
+{
+   /**
+    * Should we modify the file.
+    *
+    * @param structureContext the structure context
+    * @return true if we determined modification
+    */
+   boolean determineModification(StructureContext structureContext);
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeStructureDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeStructureDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/ModificationTypeStructureDeployer.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -0,0 +1,104 @@
+/*
+ * 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.modify;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
+
+/**
+ * Determine if we need some modification.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ModificationTypeStructureDeployer implements StructureDeployer
+{
+   private List<ModificationTypeMatcher> matchers;
+
+   public boolean determineStructure(StructureContext context) throws DeploymentException
+   {
+      if (matchers != null && matchers.isEmpty() == false)
+      {
+         for (ModificationTypeMatcher matcher : matchers)
+         {
+            if (matcher.determineModification(context))
+            {
+               break;
+            }
+         }
+      }
+      return false;
+   }
+
+   /**
+    * Set modification type matchers.
+    *
+    * @param matchers the modification type matchers.
+    */
+   public void setMatchers(List<ModificationTypeMatcher> matchers)
+   {
+      this.matchers = matchers;
+   }
+
+   /**
+    * Add modification type matcher.
+    *
+    * @param matcher the modification type matcher
+    */
+   public void addMatcher(ModificationTypeMatcher matcher)
+   {
+      if (matchers == null)
+         matchers = new ArrayList<ModificationTypeMatcher>();
+
+      matchers.add(matcher);
+   }
+
+   /**
+    * Remove modification type matcher.
+    *
+    * @param matcher the modification type matcher
+    */
+   public void removeMatcher(ModificationTypeMatcher matcher)
+   {
+      if (matchers != null)
+      {
+         matchers.remove(matcher);
+      }
+   }
+
+   public boolean isSupportsCandidateAnnotations()
+   {
+      return false;
+   }
+
+   public int getRelativeOrder()
+   {
+      return 1;
+   }
+
+   public void setRelativeOrder(int order)
+   {
+   }
+}

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/RootModificationTypeMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/RootModificationTypeMatcher.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/RootModificationTypeMatcher.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -0,0 +1,54 @@
+/*
+ * 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.modify;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.deployers.vfs.spi.structure.StructureContext;
+
+/**
+ * Root modification type matcher.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class RootModificationTypeMatcher extends FileModificationTypeMatcher
+{
+   public RootModificationTypeMatcher(String... paths)
+   {
+      super(paths);
+      setApplyModificationToTop(true);
+   }
+
+   @Override
+   protected VirtualFile getStartingFile(StructureContext structureContext)
+   {
+      return structureContext.getRoot();
+   }
+
+   @Override
+   protected boolean isModificationDetermined(StructureContext structureContext)
+   {
+      if (structureContext.isTopLevel() == false)
+         return false;
+
+      return super.isModificationDetermined(structureContext);
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/TempTopModificationTypeMatcher.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/TempTopModificationTypeMatcher.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/structure/modify/TempTopModificationTypeMatcher.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -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.plugins.structure.modify;
+
+import org.jboss.deployers.spi.structure.ModificationType;
+
+/**
+ * Temp top modification type matcher.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TempTopModificationTypeMatcher extends FileModificationTypeMatcher
+{
+   public TempTopModificationTypeMatcher(String... paths)
+   {
+      super(paths);
+      setApplyModificationToTop(true);
+      setModificationType(ModificationType.TEMP);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/StructureContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/StructureContext.java	2009-01-23 16:25:15 UTC (rev 83353)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/StructureContext.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -21,12 +21,13 @@
 */
 package org.jboss.deployers.vfs.spi.structure;
 
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.spi.structure.ModificationType;
 import org.jboss.deployers.spi.structure.StructureMetaData;
 import org.jboss.virtual.VirtualFile;
 
@@ -63,6 +64,9 @@
    /** The callbacks */
    private Set<Object> callbacks;
 
+   /** The modification type */
+   private ModificationType modificationType;
+
    /**
     * Helper method to check parent is not null before retrieving parameters
     * 
@@ -319,4 +323,24 @@
       
       getMetaData().removeContext(child);
    }
+
+   /**
+    * Get modification type.
+    *
+    * @return the modification type
+    */
+   public ModificationType getModificationType()
+   {
+      return modificationType;
+   }
+
+   /**
+    * Set modification type.
+    *
+    * @param modificationType the modification type
+    */
+   public void setModificationType(ModificationType modificationType)
+   {
+      this.modificationType = modificationType;
+   }
 }
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2009-01-23 16:25:15 UTC (rev 83353)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/helpers/AbstractStructureDeployer.java	2009-01-23 16:29:09 UTC (rev 83354)
@@ -33,6 +33,7 @@
 import org.jboss.deployers.spi.structure.ContextInfo;
 import org.jboss.deployers.spi.structure.StructureMetaData;
 import org.jboss.deployers.spi.structure.StructureMetaDataFactory;
+import org.jboss.deployers.spi.structure.ModificationType;
 import org.jboss.deployers.vfs.spi.structure.CandidateAnnotationsCallback;
 import org.jboss.deployers.vfs.spi.structure.StructureContext;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
@@ -525,7 +526,14 @@
     */
    protected void applyContextInfo(StructureContext context, ContextInfo result)
    {
-      if (result != null && contextInfoOrder != null)
-         result.setRelativeOrder(contextInfoOrder);
+      if (result != null)
+      {
+         if (contextInfoOrder != null)
+            result.setRelativeOrder(contextInfoOrder);
+
+         ModificationType modificationType = context.getModificationType();
+         if (modificationType != null && result.getModificationType() == null)
+            result.setModificationType(modificationType);
+      }
    }
 }




More information about the jboss-cvs-commits mailing list