[jboss-cvs] JBossAS SVN: r87088 - projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 9 12:01:23 EDT 2009
Author: alesj
Date: 2009-04-09 12:01:22 -0400 (Thu, 09 Apr 2009)
New Revision: 87088
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/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
Modified:
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/UpdateDeleteVisitor.java
Log:
[JBAS-6722]; default synch adaptors.
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/AbstractSynchAdapter.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/AbstractSynchAdapter.java 2009-04-09 16:01:22 UTC (rev 87088)
@@ -0,0 +1,92 @@
+/*
+ * 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 java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.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
+ {
+ try
+ {
+ URL realURL = VFSUtils.getRealURL(tempRoot);
+ File rootDir = new File(realURL.toURI());
+ File newFile = new File(rootDir, pathToFile);
+ return copy(fileToAdd, newFile);
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+
+ /**
+ * 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
+ {
+ MergeException(VirtualFile dest, VirtualFile source, Exception cause)
+ {
+ super("Conflict merging files, dest: " + dest + ", source: " + source);
+ initCause(cause);
+ }
+ }
+}
Added: 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 2009-04-09 16:01:22 UTC (rev 87088)
@@ -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.virtual.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
Added: 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 2009-04-09 16:01:22 UTC (rev 87088)
@@ -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.virtual.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
Added: 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 2009-04-09 16:01:22 UTC (rev 87088)
@@ -0,0 +1,74 @@
+/*
+ * 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 java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.virtual.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
+ {
+ try
+ {
+ URI uri = fileToOverride.toURI();
+ if (fileToOverride.delete())
+ {
+ File newFile = new File(uri);
+ return copy(modifiedFile, newFile);
+ }
+ else
+ {
+ log.warn("Could not delete previous file: " + fileToOverride + ", no change applied: " + modifiedFile);
+ return fileToOverride.getLastModified();
+ }
+ }
+ catch (URISyntaxException e)
+ {
+ IOException ioe = new IOException();
+ ioe.initCause(e);
+ throw ioe;
+ }
+ }
+}
\ No newline at end of file
Modified: 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 2009-04-09 15:57:47 UTC (rev 87087)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/SynchAdapter.java 2009-04-09 16:01:22 UTC (rev 87088)
@@ -58,6 +58,7 @@
*
* @param fileToDelete file to delete
* @throws IOException for any error
+ * @return true if deleted, false otherwise
*/
- void delete(VirtualFile fileToDelete) throws IOException;
+ boolean delete(VirtualFile fileToDelete) throws IOException;
}
\ No newline at end of file
Modified: 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 2009-04-09 15:57:47 UTC (rev 87087)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java 2009-04-09 16:01:22 UTC (rev 87088)
@@ -50,9 +50,11 @@
VirtualFile child = originalRoot.getChild(pathName);
if (child == null)
{
- // original was deleted
- getCache().removeCache(pathName);
- getSynchAdapter().delete(file);
+ // original was deleted, try deleting the temp
+ if (getSynchAdapter().delete(file))
+ {
+ getCache().removeCache(pathName);
+ }
}
else
{
More information about the jboss-cvs-commits
mailing list