[jboss-cvs] JBossAS SVN: r100824 - in projects/vfs/trunk/src: main/java/org/jboss/vfs/spi and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 10 17:00:18 EST 2010
Author: johnbailey
Date: 2010-02-10 17:00:17 -0500 (Wed, 10 Feb 2010)
New Revision: 100824
Removed:
projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFileAssembly.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualJarInputStream.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/Automounter.java
projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/MountOption.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java
Log:
Some VFS3 cleanup.
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -29,7 +29,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.Random;
-import java.security.SecureRandom;
/**
* A provider for temporary physical files and directories.
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -21,7 +21,6 @@
*/
package org.jboss.vfs;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -747,58 +746,8 @@
public static InputStream emptyStream() {
return EMPTY_STREAM;
}
-
-
- /**
- * Determine the relative path between a root and a target.
- *
- * @param mountPoint
- * @param target
- * @return
- */
- public static List<String> getRelativePath(VirtualFile mountPoint, VirtualFile target) {
- List<String> pathParts = new LinkedList<String>();
- collectPathParts(mountPoint, target, pathParts);
- return pathParts;
- }
/**
- * Determine the relative path between a root and a target as a string.
- *
- * @param mountPoint
- * @param target
- * @return
- */
- public static String getRelativePathString(VirtualFile mountPoint, VirtualFile target) {
- List<String> pathParts = getRelativePath(mountPoint, target);
- if(!pathParts.isEmpty()) {
- return PathTokenizer.getRemainingPath(pathParts, 0);
- } else {
- return "";
- }
- }
-
-
-
- /**
- * Recursively work from the target to the mount-point and collect the path elements.
- *
- * @param mountPoint
- * @param current
- * @param pathParts
- */
- private static void collectPathParts(VirtualFile mountPoint, VirtualFile current, List<String> pathParts) {
- if (current == null) {
- throw new IllegalArgumentException("VirtualFile not a child of provided mount point");
- }
- if (current.equals(mountPoint)) {
- return;
- }
- collectPathParts(mountPoint, current.getParent(), pathParts);
- pathParts.add(current.getName());
- }
-
- /**
* Expand a zip file to a destination directory. The directory must exist. If an error occurs, the destination
* directory may contain a partially-extracted archive, so cleanup is up to the caller.
*
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -110,6 +110,9 @@
}
private void getPathNameRelativeTo(VirtualFile parent, StringBuilder builder) {
+ if(this == parent) {
+ return;
+ }
if (this.parent == null) {
throw new IllegalArgumentException("Given parent is not an ancestor of this virtual file");
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFileAssembly.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFileAssembly.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFileAssembly.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -62,7 +62,7 @@
*/
public void add(VirtualFile virtualFile) {
String path = virtualFile.getName();
- AssemblyNode assemblyNode = rootNode.findOrBuild(new Path(path));
+ AssemblyNode assemblyNode = rootNode.findOrBuild(path);
assemblyNode.setTarget(virtualFile);
}
@@ -73,7 +73,7 @@
* @param virtualFile
*/
public void add(String path, VirtualFile virtualFile) {
- AssemblyNode assemblyNode = rootNode.findOrBuild(new Path(path));
+ AssemblyNode assemblyNode = rootNode.findOrBuild(path);
assemblyNode.setTarget(virtualFile);
}
@@ -101,8 +101,8 @@
* @throws IOException
*/
public VirtualFile getFile(VirtualFile mountPoint, VirtualFile target) {
- Path path = new Path(VFSUtils.getRelativePath(mountPoint, target));
- return rootNode.getFile(path, mountPoint);
+ final String path = target.getPathNameRelativeTo(mountPoint);
+ return rootNode.getFile(new Path(path), mountPoint);
}
/**
@@ -115,7 +115,7 @@
if(mountPoint.equals(target)) {
targetNode = rootNode;
} else {
- targetNode = rootNode.find(new Path(VFSUtils.getRelativePath(mountPoint, target)));
+ targetNode = rootNode.find(target.getPathNameRelativeTo(mountPoint));
}
if(targetNode != null) {
for(AssemblyNode childNode : targetNode.children.values()) {
@@ -126,7 +126,7 @@
}
public boolean contains(VirtualFile mountPoint, VirtualFile target) {
- Path path = new Path(VFSUtils.getRelativePath(mountPoint, target));
+ final String path = target.getPathNameRelativeTo(mountPoint);
return rootNode.find(path) != null;
}
@@ -165,10 +165,6 @@
parts.addAll(tokens);
}
- private Path(List<String> parts) {
- this.parts = new LinkedList<String>(parts);
- }
-
private boolean isEndOfPath() {
return parts.isEmpty();
}
@@ -198,8 +194,8 @@
* @param path
* @return
*/
- public AssemblyNode find(Path path) {
- return find(path, false);
+ public AssemblyNode find(String path) {
+ return find(new Path(path), false);
}
/**
@@ -208,8 +204,8 @@
* @param path
* @return
*/
- public AssemblyNode findOrBuild(Path path) {
- return find(path, true);
+ public AssemblyNode findOrBuild(String path) {
+ return find(new Path(path), true);
}
/**
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualJarInputStream.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualJarInputStream.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualJarInputStream.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -38,8 +38,6 @@
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
-import org.jboss.vfs.util.PathTokenizer;
-
/**
* Virtual JarInputStream used for representing any VFS directory as a JarInputStream.
*
@@ -74,7 +72,7 @@
public VirtualJarInputStream(VirtualFile root) throws IOException {
super(VFSUtils.emptyStream());
this.root = root;
- VirtualFile manifest = root.getChild(JarFile.MANIFEST_NAME);
+ final VirtualFile manifest = root.getChild(JarFile.MANIFEST_NAME);
if(manifest.exists()) {
entryItr.add(Collections.singleton(manifest).iterator());
this.manifest = VFSUtils.readManifest(manifest);
@@ -95,7 +93,7 @@
public JarEntry getNextJarEntry() throws IOException {
closeEntry();
- Iterator<VirtualFile> topItr = entryItr.peekFirst();
+ final Iterator<VirtualFile> topItr = entryItr.peekFirst();
if (topItr == null) {
return null;
}
@@ -104,7 +102,7 @@
return getNextJarEntry();
}
- VirtualFile nextEntry = topItr.next();
+ final VirtualFile nextEntry = topItr.next();
String entryName = getEntryName(nextEntry);
if (nextEntry.isDirectory()) {
List<VirtualFile> children = nextEntry.getChildren();
@@ -117,7 +115,7 @@
openCurrent(nextEntry);
Attributes attributes = null;
- Manifest manifest = getManifest();
+ final Manifest manifest = getManifest();
if (manifest != null) {
attributes = manifest.getAttributes(entryName);
}
@@ -220,8 +218,7 @@
* @return
*/
private String getEntryName(VirtualFile entry) {
- List<String> pathParts = VFSUtils.getRelativePath(root, entry);
- return PathTokenizer.getRemainingPath(pathParts, 0);
+ return entry.getPathNameRelativeTo(root);
}
/**
@@ -279,11 +276,11 @@
/** {@inheritDoc} **/
@Override
public Certificate[] getCertificates() {
- CodeSigner[] signers = getCodeSigners();
+ final CodeSigner[] signers = getCodeSigners();
if (signers == null) {
return null;
}
- List<Certificate> certs = new ArrayList<Certificate>();
+ final List<Certificate> certs = new ArrayList<Certificate>();
for (CodeSigner signer : signers) {
certs.addAll(signer.getSignerCertPath().getCertificates());
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -27,11 +27,9 @@
import java.io.FileNotFoundException;
import java.security.CodeSigner;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VirtualFileAssembly;
import org.jboss.logging.Logger;
@@ -59,7 +57,7 @@
/** {@inheritDoc} */
public boolean delete(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
return assemblyFile != null && assemblyFile.delete();
}
@@ -69,7 +67,7 @@
{
return true;
}
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
if(assemblyFile != null) {
return assemblyFile.exists();
}
@@ -78,17 +76,17 @@
/** {@inheritDoc} */
public boolean isFile(final VirtualFile mountPoint, final VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
return assemblyFile != null && assemblyFile.isFile();
}
/** {@inheritDoc} */
public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
if (assemblyFile == null) {
return new ArrayList<String>(assembly.getChildNames(mountPoint, target));
}
- List<String> directoryEntries = new LinkedList<String>();
+ final List<String> directoryEntries = new LinkedList<String>();
for (VirtualFile child : assemblyFile.getChildren()) {
directoryEntries.add(child.getName());
}
@@ -97,13 +95,13 @@
/** {@inheritDoc} */
public long getLastModified(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
return assemblyFile == null ? 0L : assemblyFile.getLastModified();
}
/** {@inheritDoc} */
public long getSize(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
return assemblyFile == null ? 0L : assemblyFile.getSize();
}
@@ -111,7 +109,7 @@
public boolean isDirectory(VirtualFile mountPoint, VirtualFile target) {
if(mountPoint.equals(target))
return true;
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
if(assemblyFile != null)
return assemblyFile.isDirectory();
return assembly.contains(mountPoint, target);
@@ -135,7 +133,7 @@
/** {@inheritDoc} */
public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
if (assemblyFile == null) {
return null;
}
@@ -143,7 +141,7 @@
}
private VirtualFile getExistingFile(final VirtualFile mountPoint, final VirtualFile target) throws FileNotFoundException {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
if (assemblyFile == null) {
throw new FileNotFoundException(target.getPathName());
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -149,7 +149,7 @@
// nope, create a cached temp
final JarEntry zipEntry = zipNode.entry;
- String name = VFSUtils.getRelativePathString(mountPoint, target);
+ String name = target.getPathNameRelativeTo(mountPoint);
cachedFile = buildFile(contentsDir, name);
if(zipEntry == null) {
cachedFile.mkdir();
@@ -267,15 +267,6 @@
return jarEntry.getCodeSigners();
}
- private JarEntry getNodeEntry(ZipNode zipNode)
- throws IOException {
- final JarEntry entry = zipNode.entry;
- if (entry == null) {
- throw new IOException("Cannot call this operation on a directory");
- }
- return entry;
- }
-
private ZipNode getZipNode(VirtualFile mountPoint, VirtualFile target) {
final ZipNode zipNode = rootNode.find(mountPoint, target);
if (zipNode == null) {
Deleted: projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/OneWaySynchronizedCopyFileSystem.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -1,319 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.vfs.spi;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.CodeSigner;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.jboss.vfs.VFSUtils;
-import org.jboss.vfs.VirtualFile;
-
-/**
- * {@inheritDoc}
- * <p/>
- * An implementation {@link FileSystem} that represents a temporary copy of an existing {@link VirtualFile} as its root.
- * The temporary {@link FileSystem} will be synchronized with changes to the original {@link VirtualFile} root and children.
- *
- * @author <a href="jbailey at redhat.com">John Bailey</a>
- */
-public class OneWaySynchronizedCopyFileSystem implements FileSystem
-{
- /* The original root to use as a base for synchronization */
- private final VirtualFile originalRoot;
-
- /* Temporary file system holding local copies */
- private final RealFileSystem temporaryFileSystem;
-
- /* Map holding information about the state of a giving temporary file location */
- private final ConcurrentMap<String, SynchInfo> synchInfoMap = new ConcurrentHashMap<String, SynchInfo>();
-
- /**
- * Constructs a new {@link OneWaySynchronizedCopyFileSystem}.
- *
- * @param originalRoot the root file to base the synchronization
- * @param temporaryRoot the file to use as the root of the temporary file system
- */
- public OneWaySynchronizedCopyFileSystem(VirtualFile originalRoot, File temporaryRoot)
- {
- this.originalRoot = originalRoot;
- this.temporaryFileSystem = new RealFileSystem(temporaryRoot);
- }
-
- /** {@inheritDoc} */
- public boolean delete(VirtualFile mountPoint, VirtualFile target)
- {
- getSynchInfo(mountPoint, target).setState(SynchState.DELETED_LOCAL);
- return temporaryFileSystem.delete(mountPoint, target);
- }
-
- /** {@inheritDoc} */
- public boolean exists(VirtualFile mountPoint, VirtualFile target)
- {
- return getFile(mountPoint, target).exists();
- }
-
- /** {@inheritDoc} */
- public File getFile(VirtualFile mountPoint, VirtualFile target)
- {
- File file = temporaryFileSystem.getFile(mountPoint, target);
- VirtualFile originalChild = getOriginalTarget(mountPoint, target);
- synch(originalChild, file, getSynchInfo(mountPoint, target));
- return file;
- }
-
- /**
- * Synchronize the temporary file with the contents of the original.
- *
- * @param original the original {@link VirtualFile} to synchronize with the temporary file
- * @param file the temporary file to synchronize with the original
- * @param info the synchronization info for this file location
- */
- private void synch(VirtualFile original, File file, SynchInfo info)
- {
- if (file.exists()) {
-
- if (original.exists()) {
- long origModTime = original.getLastModified();
- long copyModTime = file.lastModified();
- if (origModTime > copyModTime) {
- copyOriginal(original, file, info);
- }
- } else {
- if (info.isInState(SynchState.COPIED)) {
- file.delete();
- } else {
- info.setState(SynchState.ADDED_LOCAL);
- }
- }
- } else if (info.isInState(SynchState.DELETED_LOCAL) == false) {
- if (original.exists() && info.isInState(SynchState.UNKNOWN)) {
- if (original.isDirectory()) {
- file.mkdirs();
- info.setState(SynchState.COPIED);
- } else {
- copyOriginal(original, file, info);
- }
- }
- }
-
- }
-
- /**
- * Copy the original content over to the temporary location
- *
- * @param original the original {@link VirtualFile} to copy contents from
- * @param file the temporary file to copy contents to
- * @param info the synchronization info for the file locaiton
- */
- private void copyOriginal(VirtualFile original, File file, SynchInfo info)
- {
- try {
- VFSUtils.copyStreamAndClose(original.openStream(), new FileOutputStream(file));
- file.setLastModified(original.getLastModified());
- info.setState(SynchState.COPIED);
- }
- catch (IOException e) {
- throw new RuntimeException("Failed to create temporary copy of file: " + original, e);
- }
- }
-
- /** {@inheritDoc} */
- public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target)
- {
- File file = getFile(mountPoint, target);
- if (file.isFile()) {
- return null;
- }
-
- List<String> directoryEntries = new LinkedList<String>();
-
- VirtualFile originalTarget = getOriginalTarget(mountPoint, target);
- for (VirtualFile origChild : originalTarget.getChildren()) {
- directoryEntries.add(origChild.getName());
- }
-
- String[] tempedFiles = file.list();
- for (String name : tempedFiles) {
- SynchInfo info = getSynchInfo(mountPoint, target, name);
- if (directoryEntries.contains(name) == false && info.isInState(SynchState.COPIED) == false) {
- directoryEntries.add(name);
- }
- }
- return directoryEntries;
- }
-
- /** {@inheritDoc} */
- public long getLastModified(VirtualFile mountPoint, VirtualFile target)
- {
- return getFile(mountPoint, target).lastModified();
- }
-
- /** {@inheritDoc} */
- public long getSize(VirtualFile mountPoint, VirtualFile target)
- {
- return getFile(mountPoint, target).length();
- }
-
- /** {@inheritDoc} */
- public boolean isDirectory(VirtualFile mountPoint, VirtualFile target)
- {
- return getFile(mountPoint, target).isDirectory();
- }
-
- /** {@inheritDoc} */
- public boolean isFile(VirtualFile mountPoint, VirtualFile target)
- {
- return getFile(mountPoint, target).isDirectory();
- }
-
- /** {@inheritDoc} */
- public boolean isReadOnly()
- {
- return false;
- }
-
- /** {@inheritDoc} */
- public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException
- {
- return new FileInputStream(getFile(mountPoint, target));
- }
-
- /** {@inheritDoc} */
- public void close() throws IOException
- {
- temporaryFileSystem.close();
- }
-
- /** {@inheritDoc} */
- public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target)
- {
- return null;
- }
-
- /**
- * Get the synchronization info for a target
- *
- * @param mountPoint the mount for this {@link FileSystem}
- * @param target the target {@link VirtualFile} to get info for
- * @return the synchronization info
- */
- private SynchInfo getSynchInfo(VirtualFile mountPoint, VirtualFile target)
- {
- return getSynchInfo(mountPoint, target, null);
- }
-
- /**
- * Get the synchronization info for the child of a target
- *
- * @param mountPoint the mount for this {@link FileSystem}
- * @param target the target {@link VirtualFile} to get info for
- * @param targetChild the name of a child of the target
- * @return the synchronization info
- */
- private SynchInfo getSynchInfo(VirtualFile mountPoint, VirtualFile target, String targetChild)
- {
- String path = getRelativePath(mountPoint, target);
- if (targetChild != null) {
- path = path.equals("") ? targetChild : path + "/" + targetChild;
- }
- return getSynchInfo(path);
- }
-
- /**
- * Get the synchronization info for a raw file path key
- *
- * @param path the file path
- * @return the synchronization info
- */
- private SynchInfo getSynchInfo(String path)
- {
- synchInfoMap.putIfAbsent(path, new SynchInfo());
- return synchInfoMap.get(path);
- }
-
- /**
- * Get the relative file path between the mount point and the target
- *
- * @param mountPoint the mount point for the {@link FileSystem}
- * @param target the target {@link VirtualFile}
- * @return the relative path between
- */
- private String getRelativePath(VirtualFile mountPoint, VirtualFile target)
- {
- if (mountPoint.equals(target)) {
- return "";
- }
- return target.getPathNameRelativeTo(mountPoint);
- }
-
- /**
- * Return the original target {@link VirtualFile} that should be used to back this temporary target.
- *
- * @param mountPoint the mount point for the {@link FileSystem}
- * @param target the target {@link VirtualFile}
- * @return the {@link VirtualFile} from the original {@link FileSystem}
- */
- private VirtualFile getOriginalTarget(VirtualFile mountPoint, VirtualFile target)
- {
- VirtualFile originalChild = null;
- if (target.equals(mountPoint)) {
- originalChild = originalRoot;
- } else {
- originalChild = originalRoot.getChild(getRelativePath(mountPoint, target));
- }
- return originalChild;
- }
-
- /**
- * An enumeration of synchronizations states.
- */
- private enum SynchState {
- UNKNOWN, COPIED, DELETED_LOCAL, ADDED_LOCAL
- };
-
- /**
- * Holder for synchronization states
- */
- private class SynchInfo
- {
- private SynchState state = SynchState.UNKNOWN;
-
- private boolean isInState(SynchState synchState)
- {
- return synchState.equals(state);
- }
-
- public void setState(SynchState state)
- {
- this.state = state;
- }
- }
-
-}
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/Automounter.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/Automounter.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/Automounter.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -43,8 +43,6 @@
/**
* Utility used to manage mounting Virtual FileSystems.
*
- * TODO - Make this thread safe.............
- *
* @author <a href="jbailey at redhat.com">John Bailey</a>
*/
public class Automounter
@@ -131,7 +129,7 @@
private static MountConfig getMountConfig(MountOption[] mountOptions) {
final MountConfig config = new MountConfig();
for(MountOption option : mountOptions) {
- option.apply(config);
+ option.applyTo(config);
}
return config;
}
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/MountOption.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/MountOption.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/util/automount/MountOption.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -29,13 +29,13 @@
public enum MountOption {
EXPANDED {
- void apply(MountConfig config)
+ void applyTo(MountConfig config)
{
config.setMountExpanded(true);
}
},
COPY {
- void apply(MountConfig config)
+ void applyTo(MountConfig config)
{
config.setCopyTarget(true);
}
@@ -46,5 +46,5 @@
*
* @param config MountConfig to apply settings to
*/
- abstract void apply(MountConfig config);
+ abstract void applyTo(MountConfig config);
}
Deleted: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/OneWaySynchronizedCopyFileSystemTestCase.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -1,350 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.vfs;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.Executors;
-
-import org.apache.tools.ant.filters.StringInputStream;
-import org.jboss.vfs.TempDir;
-import org.jboss.vfs.TempFileProvider;
-import org.jboss.vfs.VFS;
-import org.jboss.vfs.VFSUtils;
-import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.spi.OneWaySynchronizedCopyFileSystem;
-import org.junit.Test;
-import org.junit.internal.ArrayComparisonFailure;
-
-/**
- * TestCase to verify the functionality of a {@link OneWaySynchronizedCopyFileSystem}.
- *
- * @author <a href="jbailey at redhat.com">John Bailey</a>
- */
-public class OneWaySynchronizedCopyFileSystemTestCase extends AbstractVFSTest
-{
-
- private TempFileProvider tempFileProvider;
-
- public OneWaySynchronizedCopyFileSystemTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Verify files are correctly copied from the original root
- *
- * @throws Exception
- */
- @Test
- public void testExistingFiles() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
-
- TempDir dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
-
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
- assertFalse(new File(dirRoot, "META-INF").exists());
- assertTrue(newVirtualFile.getChild("META-INF").exists());
- assertTrue(new File(dirRoot, "META-INF").exists());
- assertTrue(newVirtualFile.getChild("META-INF").isDirectory());
-
- assertFalse(newVirtualFile.getChild("missing.txt").exists());
-
- File manifest = newVirtualFile.getChild("META-INF/MANIFEST.MF").getPhysicalFile();
- assertTrue(manifest.exists());
-
-
- assertCoppied(existing.getChild("META-INF/MANIFEST.MF"), newVirtualFile.getChild("META-INF/MANIFEST.MF"));
-
- List<VirtualFile> children = newVirtualFile.getChildren();
- assertEquals(2, children.size());
- assertTrue(children.contains(newVirtualFile.getChild("org")));
- assertTrue(children.contains(newVirtualFile.getChild("META-INF")));
-
- assertFalse(new File(dirRoot, "org").exists());
- assertTrue(newVirtualFile.getChild("org").exists());
- assertTrue(new File(dirRoot, "org").exists());
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- /**
- * Verify that copies that are added to the original are copied to the temporary location
- *
- * @throws Exception
- */
- @Test
- public void testAddFilesToOriginal() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
- File existingDir = dir.getRoot();
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
- mounts.add(VFS.mountReal(existingDir, existing));
-
- dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
- assertEmpty(newVirtualFile.getChildren());
-
- File addedDir = new File(existingDir, "META-INF");
- addedDir.mkdir();
-
- assertTrue(newVirtualFile.getChild("META-INF").exists());
- assertTrue(new File(dirRoot, "META-INF").exists());
- assertTrue(newVirtualFile.getChild("META-INF").isDirectory());
-
- assertFalse(newVirtualFile.getChild("test.txt").exists());
-
- File addedFile = new File(existingDir, "test.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertTrue(existing.getChild("test.txt").exists());
-
- assertFalse(new File(dirRoot, "test.txt").exists());
-
- List<VirtualFile> children = newVirtualFile.getChildren();
- assertEquals(2, children.size());
- assertTrue(children.contains(newVirtualFile.getChild("test.txt")));
- assertTrue(children.contains(newVirtualFile.getChild("META-INF")));
-
- assertFalse(new File(dirRoot, "test.txt").exists());
-
- assertTrue(newVirtualFile.getChild("test.txt").exists());
- assertTrue(new File(dirRoot, "test.txt").exists());
-
- assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
-
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- /**
- * Verify that files added to the temporary copy are not delete because they are missing in the original
- *
- * @throws Exception
- */
- @Test
- public void testAddFilesToCopy() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
- File existingDir = dir.getRoot();
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
- mounts.add(VFS.mountReal(existingDir, existing));
-
- dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
- assertEmpty(newVirtualFile.getChildren());
-
- File addedDir = new File(dirRoot, "META-INF");
- addedDir.mkdir();
- assertTrue(addedDir.exists());
-
- assertTrue(newVirtualFile.getChild("META-INF").exists());
-
- File addedFile = new File(dirRoot, "test.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertFalse(existing.getChild("test.txt").exists());
-
- assertTrue(newVirtualFile.getChild("test.txt").exists());
-
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- /**
- * Verify that changes made to the original are correctly made to the copy
- *
- * @throws Exception
- */
- @Test
- public void testUpdateFilesFromOriginal() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
- File existingDir = dir.getRoot();
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
- mounts.add(VFS.mountReal(existingDir, existing));
-
- dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
-
- File addedFile = new File(existingDir, "test.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertTrue(newVirtualFile.getChild("test.txt").exists());
- assertTrue(new File(dirRoot, "test.txt").exists());
- assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
-
- Thread.sleep(1000);
-
- VFSUtils.copyStreamAndClose(new StringInputStream("Some other text"), new FileOutputStream(addedFile));
-
- assertCoppied(existing.getChild("test.txt"), newVirtualFile.getChild("test.txt"));
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- /**
- * Verify that files deleted from the original are deleted from the copy
- *
- * @throws Exception
- */
- @Test
- public void testDeleteFilesFromOriginal() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
- File existingDir = dir.getRoot();
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
- mounts.add(VFS.mountReal(existingDir, existing));
-
- dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
- File addedFile = new File(existingDir, "test.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertTrue(existing.getChild("test.txt").exists());
-
- assertTrue(newVirtualFile.getChild("test.txt").exists());
- assertTrue(new File(dirRoot, "test.txt").exists());
-
- addedFile.delete();
- assertFalse(addedFile.exists());
- assertFalse(existing.getChild("test.txt").exists());
-
- // Still in local temp.
- assertTrue(new File(dirRoot, "test.txt").exists());
-
- List<VirtualFile> children = newVirtualFile.getChildren();
- assertEquals(0, children.size());
-
- assertFalse(newVirtualFile.getChild("test.txt").exists());
- assertFalse(new File(dirRoot, "test.txt").exists());
-
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- /**
- * Verify that files deleted from the copy are not re-copied from the original
- * @throws Exception
- */
- @Test
- public void testDeleteFilesFromCopy() throws Exception
- {
- List<Closeable> mounts = new LinkedList<Closeable>();
- try {
- TempDir dir = getTempFileProvider().createTempDir("existing-jar1");
- File existingDir = dir.getRoot();
- VirtualFile existing = getVirtualFile("/vfs/test/jar1");
- mounts.add(VFS.mountReal(existingDir, existing));
-
- dir = getTempFileProvider().createTempDir("new-jar1");
- File dirRoot = dir.getRoot();
- OneWaySynchronizedCopyFileSystem fs = new OneWaySynchronizedCopyFileSystem(existing, dirRoot);
-
- VirtualFile newVirtualFile = VFS.getChild("/vfs/new-jar");
- mounts.add(VFS.mount(newVirtualFile, fs));
-
- File addedFile = new File(existingDir, "test.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertTrue(existing.getChild("test.txt").exists());
-
- assertTrue(newVirtualFile.getChild("test.txt").exists());
- assertTrue(new File(dirRoot, "test.txt").exists());
-
- newVirtualFile.getChild("test.txt").delete();
- assertFalse(newVirtualFile.getChild("test.txt").exists());
- assertTrue(existing.getChild("test.txt").exists());
-
- addedFile = new File(existingDir, "test2.txt");
- VFSUtils.copyStreamAndClose(new StringInputStream("Some text"), new FileOutputStream(addedFile));
- assertTrue(addedFile.exists());
- assertTrue(existing.getChild("test2.txt").exists());
-
- assertTrue(newVirtualFile.getChild("test2.txt").exists());
-
- File copiedFIle = new File(dirRoot, "test2.txt");
- copiedFIle.delete();
-
- assertFalse(newVirtualFile.getChild("test2.txt").exists());
- } finally {
- VFSUtils.safeClose(mounts);
- }
- }
-
- private void assertCoppied(VirtualFile expected, VirtualFile actual) throws ArrayComparisonFailure, IOException
- {
- assertContentEqual(expected, actual);
- assertEquals(expected.getLastModified(), actual.getLastModified());
- }
-
- private TempFileProvider getTempFileProvider() throws IOException {
- if(tempFileProvider == null)
- tempFileProvider = TempFileProvider.create("Test", Executors.newSingleThreadScheduledExecutor());
- return tempFileProvider;
- }
-}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/URLConnectionUnitTestCase.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -30,7 +30,6 @@
import junit.framework.Test;
-import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
/**
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java 2010-02-10 20:41:49 UTC (rev 100823)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/VFSUtilsTestCase.java 2010-02-10 22:00:17 UTC (rev 100824)
@@ -21,12 +21,9 @@
*/
package org.jboss.test.vfs;
-import static org.junit.Assert.*;
-import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
-import java.io.InputStream;
import java.util.concurrent.Executors;
import org.jboss.vfs.TempFileProvider;
More information about the jboss-cvs-commits
mailing list