[jboss-cvs] JBossAS SVN: r101041 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 16 15:48:01 EST 2010
Author: johnbailey
Date: 2010-02-16 15:47:58 -0500 (Tue, 16 Feb 2010)
New Revision: 101041
Added:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeOverrideSynchAdapter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeSynchAdapter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
Log:
[JBDEPLOY-241] - Recovered and VFS3 enabled the SynchWrappedModificationChecker
Copied: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractSynchTest.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -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.test.deployers.vfs.structure.modified.test;
+
+import org.jboss.deployers.structure.spi.main.MainDeployerInternals;
+import org.jboss.deployers.vfs.spi.structure.modified.MetaDataStructureModificationChecker;
+import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
+import org.jboss.deployers.vfs.spi.structure.modified.SynchAdapter;
+import org.jboss.deployers.vfs.spi.structure.modified.SynchWrapperModificationChecker;
+import org.jboss.test.deployers.BootstrapDeployersTest;
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VisitorAttributes;
+
+/**
+ * AbstractSynchTest.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractSynchTest extends BootstrapDeployersTest
+{
+ protected AbstractSynchTest(String name)
+ {
+ super(name);
+ }
+
+ protected StructureModificationChecker createStructureModificationChecker()
+ {
+ MainDeployerInternals mainDeployerInternals = getMainDeployerInternals();
+ VirtualFileFilter filter = createFilter();
+ VirtualFileFilter recurseFilter = createRecurseFilter();
+ SynchAdapter synchAdapter = createSynchAdapter();
+
+ MetaDataStructureModificationChecker mdsmc = new MetaDataStructureModificationChecker(mainDeployerInternals);
+ mdsmc.setFilter(filter);
+
+ SynchWrapperModificationChecker synch = new SynchWrapperModificationChecker(mdsmc, synchAdapter);
+
+ VisitorAttributes attributes = new VisitorAttributes();
+ attributes.setLeavesOnly(true);
+ attributes.setRecurseFilter(recurseFilter);
+
+ synch.setOriginalAttributes(attributes);
+ synch.setTempAttributes(attributes);
+
+ return synch;
+ }
+
+ protected abstract VirtualFileFilter createFilter();
+
+ protected abstract VirtualFileFilter createRecurseFilter();
+
+ protected abstract SynchAdapter createSynchAdapter();
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,261 @@
+/*
+ * 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.io.BufferedWriter;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.net.URI;
+import java.net.URL;
+import java.util.concurrent.Executors;
+import java.util.logging.Handler;
+
+import junit.framework.Test;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.modified.OverrideSynchAdapter;
+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.vfs.TempFileProvider;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilter;
+
+/**
+ * Test file synch.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SynchModificationTestCase extends AbstractSynchTest
+{
+ private TempFileProvider tempFileProvider;
+ private VirtualFile copiesDir;
+ private Closeable copiesDirHandle;
+
+ public SynchModificationTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(SynchModificationTestCase.class);
+ }
+
+
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ tempFileProvider = TempFileProvider.create("temp", Executors.newScheduledThreadPool(2));
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ VFSUtils.safeClose(copiesDirHandle, tempFileProvider);
+ super.tearDown();
+ }
+
+ protected VirtualFileFilter createFilter()
+ {
+ return new XmlIncludeVirtualFileFilter();
+ }
+
+ protected VirtualFileFilter createRecurseFilter()
+ {
+ return new VirtualFileFilter()
+ {
+ public boolean accepts(VirtualFile file)
+ {
+ 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);
+ }
+ }
+ };
+ }
+
+ protected SynchAdapter createSynchAdapter()
+ {
+ return new OverrideSynchAdapter();
+ }
+
+ public void testWAR() throws Exception
+ {
+ VirtualFile originalRoot = createDeploymentRoot("/synch/war", "simple.war");
+ File rootFile = originalRoot.getPhysicalFile();
+
+ VirtualFile deploymentCopy = createCopy(originalRoot);
+
+ VFSDeploymentUnit deploymentUnit = assertDeploy(deploymentCopy);
+ try
+ {
+ String deploymentName = deploymentUnit.getName();
+
+ VirtualFile tempRoot = deploymentUnit.getRoot();
+ StructureModificationChecker checker = createStructureModificationChecker();
+ assertFalse(checker.hasStructureBeenModified(deploymentName,originalRoot));
+
+ // add new file
+
+ File newFile = newFile(rootFile, "newfile.txt");
+ try
+ {
+ assertFalse(tempRoot.getChild("newfile.txt").exists());
+ assertFalse(checker.hasStructureBeenModified(deploymentName,originalRoot));
+ assertNotNull(tempRoot.getChild("newfile.txt"));
+
+ // try deleting this one now
+ assertTrue(newFile.delete());
+ assertFalse(checker.hasStructureBeenModified(deploymentName,originalRoot));
+ assertFalse(tempRoot.getChild("newfile.txt").exists());
+ }
+ finally
+ {
+ if (newFile.exists())
+ assertTrue(newFile.delete());
+ }
+
+ // update some file
+ File updateFile = new File(rootFile, "test.jsp");
+ assertTrue(updateFile.exists());
+ assertTrue(updateFile.setLastModified(System.currentTimeMillis() + 1500l));
+ VirtualFile testJsp = tempRoot.getChild("test.jsp");
+ long tempTimestamp = testJsp.getLastModified();
+ // Platform dependent precision for last modified, let's wait a minimum of 1 sec
+ Thread.sleep(1500l);
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+ long lastModified = testJsp.getLastModified();
+ long diff = lastModified - tempTimestamp;
+ assertTrue("Last modified diff is not bigger then 0, diff: " + diff, diff > 0);
+
+ // update something outside recurse filter
+ VirtualFile someProps = originalRoot.getChild("WEB-INF/classes/some.properties");
+ assertTrue(someProps.exists());
+ updateFile = someProps.getPhysicalFile();
+ assertTrue(updateFile.exists());
+ assertTrue(updateFile.setLastModified(System.currentTimeMillis() + 1500l));
+ VirtualFile tempProps = tempRoot.getChild("WEB-INF/classes/some.properties");
+ tempTimestamp = tempProps.getLastModified();
+ // Platform dependent precision for last modified, let's wait a minimum of 1 sec
+ Thread.sleep(1500l);
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+ assertEquals(tempTimestamp, tempProps.getLastModified());
+
+ // add new file into WEB-INF
+ VirtualFile webInfo = originalRoot.getChild("WEB-INF");
+ File webInfFile = webInfo.getPhysicalFile();
+ File newWebInfFile = newFile(webInfFile, "newfile.txt");
+ try
+ {
+ assertFalse(tempRoot.getChild("WEB-INF/newfile.txt").exists());
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+ assertTrue(tempRoot.getChild("WEB-INF/newfile.txt").exists());
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+
+ // try deleting this one now
+ assertTrue(newWebInfFile.delete());
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+ assertFalse(tempRoot.getChild("WEB-INF/newfile.txt").exists());
+ }
+ finally
+ {
+ if (newWebInfFile.exists())
+ assertTrue(newWebInfFile.delete());
+ }
+
+ // check we don't update for nothing
+ VirtualFile xhtml = tempRoot.getChild("test.xhtml");
+ long xhtmlTimestamp = xhtml.getLastModified();
+ // Platform dependent precision for last modified, let's wait a minimum of 1 sec
+ Thread.sleep(1500l);
+ assertFalse(checker.hasStructureBeenModified(deploymentName, originalRoot));
+ assertEquals(xhtmlTimestamp, xhtml.getLastModified());
+ }
+ finally
+ {
+ undeploy(deploymentUnit);
+ }
+ }
+
+ public void testEAR() throws Exception
+ {
+ VFSDeploymentUnit deploymentUnit = assertDeploy("/synch/ear", "simple.ear");
+ try
+ {
+ VirtualFile root = deploymentUnit.getRoot();
+ StructureModificationChecker checker = createStructureModificationChecker();
+ assertFalse(checker.hasStructureBeenModified(root));
+ }
+ finally
+ {
+ undeploy(deploymentUnit);
+ }
+ }
+
+ protected File newFile(File parent, String name) throws IOException
+ {
+ File newFile = new File(parent, name);
+ FileOutputStream fos = new FileOutputStream(newFile);
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos));
+ try
+ {
+ writer.write("sometext");
+ return newFile;
+ }
+ finally
+ {
+ writer.close();
+ }
+ }
+
+ protected VirtualFile getCopiesDir() throws IOException
+ {
+ if(copiesDir == null) {
+ copiesDir = VFS.getChild("copies");
+ copiesDirHandle = VFS.mountTemp(copiesDir, tempFileProvider);
+ }
+ return copiesDir;
+ }
+
+ protected VirtualFile createCopy(VirtualFile original) throws IOException
+ {
+ VirtualFile copy = getCopiesDir().getChild(original.getName());
+ File copyFile = copy.getPhysicalFile();
+ copyFile.mkdir();
+ VFSUtils.copyChildrenRecursive(original, copy);
+ return copy;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java 2010-02-16 19:36:05 UTC (rev 101040)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractStructureModificationChecker.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -24,10 +24,8 @@
import java.io.IOException;
import java.net.URISyntaxException;
-import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.main.MainDeployerInternals;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
import org.jboss.logging.Logger;
import org.jboss.vfs.VirtualFile;
@@ -136,7 +134,6 @@
* @param name the deployment context name
* @return vfs deployment context or null if doesn't exist or not vfs based
*/
- @SuppressWarnings("deprecation")
protected VFSDeploymentContext getDeploymentContext(String name)
{
DeploymentContext deploymentContext = getMainDeployerInternals().getDeploymentContext(name);
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,83 @@
+/*
+ * 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.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.jboss.logging.Logger;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Abstract synch adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractSynchAdapter implements SynchAdapter
+{
+ /** The log */
+ protected static Logger log = Logger.getLogger(AbstractSynchAdapter.class);
+
+ public long add(VirtualFile fileToAdd, VirtualFile tempRoot, String pathToFile) throws IOException
+ {
+ File rootDir = tempRoot.getPhysicalFile();
+ File newFile = new File(rootDir, pathToFile);
+ return copy(fileToAdd, newFile);
+ }
+
+ /**
+ * Do copy.
+ *
+ * @param fileToAdd file to add
+ * @param newFile new file location
+ * @return new timestamp
+ * @throws IOException for any error
+ */
+ protected static long copy(VirtualFile fileToAdd, File newFile) throws IOException
+ {
+ FileOutputStream out = new FileOutputStream(newFile);
+ VFSUtils.copyStreamAndClose(fileToAdd.openStream(), out);
+ return newFile.lastModified();
+ }
+
+ public boolean delete(VirtualFile fileToDelete) throws IOException
+ {
+ return fileToDelete.delete();
+ }
+
+ /**
+ * Merge exception
+ */
+ static class MergeException extends IOException
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 5228888050899870372L;
+
+ MergeException(VirtualFile dest, VirtualFile source, Exception cause)
+ {
+ super("Conflict merging files, dest: " + dest + ", source: " + source);
+ initCause(cause);
+ }
+ }
+}
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AddVisitor.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,64 @@
+/*
+ * 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.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VisitorAttributes;
+
+/**
+ * Synch on add file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AddVisitor extends SynchVisitor
+{
+ private VirtualFile originalRoot;
+ private VirtualFile tempRoot;
+
+ public AddVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot, VirtualFile tempRoot)
+ {
+ this(null, attributes, cache, synchAdapter, originalRoot, tempRoot);
+ }
+
+ public AddVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot, VirtualFile tempRoot)
+ {
+ super(filter, attributes, cache, synchAdapter);
+ if (tempRoot == null)
+ throw new IllegalArgumentException("Null temp root");
+
+ this.originalRoot = originalRoot;
+ this.tempRoot = tempRoot;
+ }
+
+ public void doVisit(VirtualFile file) throws Exception
+ {
+ String path = file.getPathNameRelativeTo(originalRoot);
+ VirtualFile child = tempRoot.getChild(path);
+ if (child.exists() == false)
+ {
+ // original was added
+ long timestamp = getSynchAdapter().add(file, tempRoot, path);
+ getCache().putCacheValue(file, timestamp);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2010-02-16 19:36:05 UTC (rev 101040)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/DefaultStructureCache.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -21,7 +21,6 @@
*/
package org.jboss.deployers.vfs.spi.structure.modified;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeOverrideSynchAdapter.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeOverrideSynchAdapter.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeOverrideSynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeOverrideSynchAdapter.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,46 @@
+/*
+ * 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.io.IOException;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Try merge first, fallback to override.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MergeOverrideSynchAdapter extends AbstractSynchAdapter
+{
+ public long update(VirtualFile fileToUpdate, VirtualFile modifiedFile) throws IOException
+ {
+ try
+ {
+ return MergeSynchAdapter.merge(fileToUpdate, modifiedFile);
+ }
+ catch (MergeException e)
+ {
+ return OverrideSynchAdapter.override(fileToUpdate, modifiedFile);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeSynchAdapter.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeSynchAdapter.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeSynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/MergeSynchAdapter.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,53 @@
+/*
+ * 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.io.IOException;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Merge synch adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MergeSynchAdapter extends AbstractSynchAdapter
+{
+ public long update(VirtualFile fileToUpdate, VirtualFile modifiedFile) throws IOException
+ {
+ return merge(fileToUpdate, modifiedFile);
+ }
+
+ /**
+ * Do merge changes.
+ *
+ * @param fileToOverride the file to override
+ * @param modifiedFile the modifed file
+ * @return new timestamp
+ * @throws MergeException for possible merge conflict
+ * @throws java.io.IOException for any error
+ */
+ static long merge(VirtualFile fileToOverride, VirtualFile modifiedFile) throws IOException
+ {
+ return 0; // TODO
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,62 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Override synch adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class OverrideSynchAdapter extends AbstractSynchAdapter
+{
+ public long update(VirtualFile fileToUpdate, VirtualFile modifiedFile) throws IOException
+ {
+ return override(fileToUpdate, modifiedFile);
+ }
+
+ /**
+ * Do override.
+ *
+ * @param fileToOverride the file to override
+ * @param modifiedFile the modifed file
+ * @return new timestamp
+ * @throws IOException for any error
+ */
+ static long override(VirtualFile fileToOverride, VirtualFile modifiedFile) throws IOException
+ {
+ if (fileToOverride.delete())
+ {
+ File newFile = fileToOverride.getPhysicalFile();
+ return copy(modifiedFile, newFile);
+ }
+ else
+ {
+ log.warn("Could not delete previous file: " + fileToOverride + ", no change applied: " + modifiedFile);
+ return fileToOverride.getLastModified();
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,64 @@
+/*
+ * 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.io.IOException;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Synch adapter.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface SynchAdapter
+{
+ /**
+ * Add new file to temp.
+ *
+ * @param fileToAdd file to add
+ * @param tempRoot temp root
+ * @param pathToFile the path to file
+ * @return addition timestamp
+ * @throws IOException for any error
+ */
+ long add(VirtualFile fileToAdd, VirtualFile tempRoot, String pathToFile) throws IOException;
+
+ /**
+ * Update file.
+ *
+ * @param fileToUpdate file to update
+ * @param modifiedFile the modified file
+ * @return the update timestamp
+ * @throws IOException for any error
+ */
+ long update(VirtualFile fileToUpdate, VirtualFile modifiedFile) throws IOException;
+
+ /**
+ * Add new file to temp.
+ *
+ * @param fileToDelete file to delete
+ * @throws IOException for any error
+ * @return true if deleted, false otherwise
+ */
+ boolean delete(VirtualFile fileToDelete) throws IOException;
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchVisitor.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,112 @@
+/*
+ * 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.logging.Logger;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VisitorAttributes;
+import org.jboss.vfs.VirtualFileVisitor;
+
+/**
+ * Synch file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class SynchVisitor implements VirtualFileVisitor
+{
+ 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
+ this.attributes = VisitorAttributes.RECURSE_LEAVES_ONLY;
+ this.cache = cache;
+ this.synchAdapter = synchAdapter;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return attributes;
+ }
+
+ public void visit(VirtualFile file)
+ {
+ try
+ {
+ if (filter == null || filter.accepts(file))
+ {
+ doVisit(file);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Exception synching file: " + file + ", cause: " + e);
+ }
+ }
+
+ /**
+ * Visit a virtual file
+ *
+ * @param file the virtual file being visited
+ * @throws Exception for any error
+ */
+ protected abstract void doVisit(VirtualFile file) throws Exception;
+
+ /**
+ * Get cache.
+ *
+ * @return the cache
+ */
+ protected StructureCache<Long> getCache()
+ {
+ return cache;
+ }
+
+ /**
+ * Get synch adapter.
+ *
+ * @return the syncj adapter
+ */
+ protected SynchAdapter getSynchAdapter()
+ {
+ return synchAdapter;
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchWrapperModificationChecker.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,142 @@
+/*
+ * 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.io.IOException;
+
+import org.jboss.deployers.structure.spi.main.MainDeployerInternals;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VisitorAttributes;
+
+/**
+ * Synch wrapper modification checker.
+ *
+ * If there is no modification, we check if the deployment is perhaps a temp,
+ * only then checking if we need to update some resource.
+ * e.g. some .jsp or .xhtml file for JBossWeb to pick up the change
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SynchWrapperModificationChecker extends AbstractStructureModificationChecker<Long>
+{
+ /** The true checker delegate */
+ private AbstractStructureModificationChecker<Long> delegate;
+
+ /** The filter */
+ private VirtualFileFilter filter;
+
+ /** The synch adapter */
+ private SynchAdapter synchAdapter;
+
+ /** the visitor attributes */
+ private VisitorAttributes originalAttributes;
+ private VisitorAttributes tempAttributes;
+
+ public SynchWrapperModificationChecker(AbstractStructureModificationChecker<Long> delegate, SynchAdapter synchAdapter)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null delegate");
+ if (synchAdapter == null)
+ throw new IllegalArgumentException("Null synch adapter");
+
+ this.delegate = delegate;
+ this.synchAdapter = synchAdapter;
+ }
+
+ @Override
+ protected StructureCache<Long> getCache()
+ {
+ return delegate.getCache();
+ }
+
+ @Override
+ protected MainDeployerInternals getMainDeployerInternals()
+ {
+ return delegate.getMainDeployerInternals();
+ }
+
+ @Override
+ protected boolean hasRootBeenModified(VirtualFile root) throws IOException
+ {
+ return delegate.hasRootBeenModified(root);
+ }
+
+ @Override
+ protected boolean hasDeploymentContextBeenModified(VirtualFile root, VFSDeploymentContext deploymentContext) throws IOException
+ {
+ boolean modified = delegate.hasDeploymentContextBeenModified(root, deploymentContext);
+ // it was not modifed & we're actually temped
+ if (modified == false && root != deploymentContext.getRoot())
+ {
+ // check for update or delete
+ VirtualFile tempRoot = deploymentContext.getRoot();
+ UpdateDeleteVisitor udVisitor = new UpdateDeleteVisitor(filter, tempAttributes, getCache(), synchAdapter, root, tempRoot);
+ tempRoot.visit(udVisitor);
+ // check for addition
+ AddVisitor addVisitor = new AddVisitor(filter, originalAttributes, getCache(), synchAdapter, root, tempRoot);
+ root.visit(addVisitor);
+ }
+ return modified;
+ }
+
+ public void addStructureRoot(VirtualFile root)
+ {
+ delegate.addStructureRoot(root);
+ }
+
+ public void removeStructureRoot(VirtualFile root)
+ {
+ delegate.removeStructureRoot(root);
+ }
+
+ /**
+ * Set the filter.
+ *
+ * @param filter the filter
+ */
+ public void setFilter(VirtualFileFilter filter)
+ {
+ this.filter = filter;
+ }
+
+ /**
+ * Set original visitor attributes.
+ *
+ * @param attributes the attributes
+ */
+ public void setOriginalAttributes(VisitorAttributes attributes)
+ {
+ this.originalAttributes = attributes;
+ }
+
+ /**
+ * Set temp visitor attributes.
+ *
+ * @param attributes the attributes
+ */
+ public void setTempAttributes(VisitorAttributes attributes)
+ {
+ this.tempAttributes = attributes;
+ }
+}
\ No newline at end of file
Copied: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java (from rev 101036, projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2010-02-16 20:47:58 UTC (rev 101041)
@@ -0,0 +1,88 @@
+/*
+ * 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.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilter;
+import org.jboss.vfs.VisitorAttributes;
+
+/**
+ * Synch on update and delete file visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class UpdateDeleteVisitor extends SynchVisitor
+{
+ private VirtualFile originalRoot;
+ private VirtualFile tempRoot;
+
+ public UpdateDeleteVisitor(VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot, VirtualFile tempRoot)
+ {
+ this(null, attributes, cache, synchAdapter, originalRoot, tempRoot);
+ }
+
+ public UpdateDeleteVisitor(VirtualFileFilter filter, VisitorAttributes attributes, StructureCache<Long> cache, SynchAdapter synchAdapter, VirtualFile originalRoot, VirtualFile tempRoot)
+ {
+ super(filter, attributes, cache, synchAdapter);
+ if (originalRoot == null)
+ throw new IllegalArgumentException("Null original root");
+
+ this.originalRoot = originalRoot;
+ this.tempRoot = tempRoot;
+ }
+
+ protected void doVisit(VirtualFile file) throws Exception
+ {
+ String path = file.getPathNameRelativeTo(tempRoot);
+
+ VirtualFile child = originalRoot.getChild(path);
+ if (child.exists() == false)
+ {
+ // original was deleted, try deleting the temp
+ if (getSynchAdapter().delete(file))
+ {
+ getCache().removeCache(originalRoot, path);
+ }
+ }
+ else
+ {
+ Long previous = getCache().getCacheValue(child);
+ long lastModified = child.getLastModified();
+
+ boolean updateCache = false;
+ if (previous == null)
+ {
+ updateCache = true;
+ }
+ else if (lastModified > previous)
+ {
+ lastModified = getSynchAdapter().update(file, child);
+ updateCache = true;
+ }
+
+ if (updateCache)
+ {
+ getCache().putCacheValue(child, lastModified);
+ }
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list