Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
383 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/main/java/org/jboss/virtual/plugins/copy/DeleteOnExitTempStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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.virtual.plugins.copy; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.virtual.spi.TempStore; | ||
import org.jboss.virtual.VirtualFile; | ||
|
||
/** | ||
* Delete on exit temp store wrapper. | ||
* | ||
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a> | ||
*/ | ||
public class DeleteOnExitTempStore implements TempStore | ||
{ | ||
private TempStore delegate; | ||
|
||
public DeleteOnExitTempStore(TempStore delegate) | ||
{ | ||
if (delegate == null) | ||
throw new IllegalArgumentException("Null delegate"); | ||
this.delegate = delegate; | ||
} | ||
|
||
public File createTempFolder(VirtualFile file) | ||
{ | ||
File dir = delegate.createTempFolder(file); | ||
dir.deleteOnExit(); | ||
return dir; | ||
} | ||
|
||
public File createTempFolder(String outerName, String innerName) | ||
{ | ||
File dir = delegate.createTempFolder(outerName, innerName); | ||
dir.deleteOnExit(); | ||
return dir; | ||
} | ||
|
||
public void clear() | ||
{ | ||
// do nothing | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/jboss/virtual/plugins/copy/MkdirTempStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.virtual.plugins.copy; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.virtual.spi.TempStore; | ||
import org.jboss.virtual.VirtualFile; | ||
|
||
/** | ||
* Mkdir temp store wrapper. | ||
* | ||
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a> | ||
*/ | ||
public class MkdirTempStore implements TempStore | ||
{ | ||
private TempStore delegate; | ||
|
||
public MkdirTempStore(TempStore delegate) | ||
{ | ||
if (delegate == null) | ||
throw new IllegalArgumentException("Null delegate"); | ||
this.delegate = delegate; | ||
} | ||
|
||
/** | ||
* Assert directory creation. | ||
* | ||
* @param dir the current directory | ||
*/ | ||
protected void assertMkdir(File dir) | ||
{ | ||
if (dir.mkdir() == false) | ||
throw new IllegalArgumentException("Cannot create directory: " + dir); | ||
} | ||
|
||
public File createTempFolder(VirtualFile file) | ||
{ | ||
File dir = delegate.createTempFolder(file); | ||
assertMkdir(dir); | ||
return dir; | ||
} | ||
|
||
public File createTempFolder(String outerName, String innerName) | ||
{ | ||
File dir = delegate.createTempFolder(outerName, innerName); | ||
assertMkdir(dir); | ||
return dir; | ||
} | ||
|
||
public void clear() | ||
{ | ||
delegate.clear(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/jboss/virtual/plugins/copy/TrackingTempStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.virtual.plugins.copy; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.jboss.util.collection.ConcurrentSet; | ||
import org.jboss.util.file.Files; | ||
import org.jboss.virtual.VirtualFile; | ||
import org.jboss.virtual.spi.TempStore; | ||
|
||
/** | ||
* Track files temp store. | ||
* | ||
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a> | ||
*/ | ||
public class TrackingTempStore implements TempStore | ||
{ | ||
private TempStore delegate; | ||
private Set<File> files; | ||
|
||
public TrackingTempStore(TempStore delegate) | ||
{ | ||
if (delegate == null) | ||
throw new IllegalArgumentException("Null delegate"); | ||
this.delegate = delegate; | ||
this.files = new ConcurrentSet<File>(); | ||
} | ||
|
||
/** | ||
* Get files. | ||
* | ||
* @return the files | ||
*/ | ||
public Set<File> getFiles() | ||
{ | ||
return Collections.unmodifiableSet(files); | ||
} | ||
|
||
public File createTempFolder(VirtualFile file) | ||
{ | ||
File dir = delegate.createTempFolder(file); | ||
files.add(dir); | ||
return dir; | ||
} | ||
|
||
public File createTempFolder(String outerName, String innerName) | ||
{ | ||
File dir = delegate.createTempFolder(outerName, innerName); | ||
files.add(dir); | ||
return dir; | ||
} | ||
|
||
public void clear() | ||
{ | ||
Set<File> copy = new HashSet<File>(files); | ||
files.clear(); | ||
for (File dir : copy) | ||
Files.delete(dir); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/jboss/test/virtual/support/MockTempStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.virtual.support; | ||
|
||
import java.io.File; | ||
|
||
import org.jboss.virtual.VirtualFile; | ||
import org.jboss.virtual.plugins.copy.AbstractCopyMechanism; | ||
import org.jboss.virtual.spi.TempStore; | ||
|
||
/** | ||
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a> | ||
*/ | ||
public class MockTempStore implements TempStore | ||
{ | ||
private File tempRoot = AbstractCopyMechanism.getTempDirectory(); | ||
private long seed; | ||
|
||
public MockTempStore(long seed) | ||
{ | ||
this.seed = seed; | ||
} | ||
|
||
public File createTempFolder(VirtualFile file) | ||
{ | ||
String name = file.getName(); | ||
return new File(tempRoot, name + '_' + seed); | ||
} | ||
|
||
public File createTempFolder(String outerName, String innerName) | ||
{ | ||
return new File(tempRoot, innerName + '_' + seed); | ||
} | ||
|
||
public void clear() | ||
{ | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src/test/java/org/jboss/test/virtual/test/TempStoreTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2006, 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.virtual.test; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
|
||
import junit.framework.Test; | ||
import org.jboss.test.virtual.support.MockTempStore; | ||
import org.jboss.virtual.VFS; | ||
import org.jboss.virtual.VirtualFile; | ||
import org.jboss.virtual.VFSUtils; | ||
import org.jboss.virtual.plugins.copy.AbstractCopyMechanism; | ||
import org.jboss.virtual.plugins.copy.DeleteOnExitTempStore; | ||
import org.jboss.virtual.plugins.copy.MkdirTempStore; | ||
import org.jboss.virtual.plugins.copy.TrackingTempStore; | ||
import org.jboss.virtual.spi.TempStore; | ||
|
||
/** | ||
* Test TempStore usage. | ||
* | ||
* @author <a href="mailto:ales.justin@jboss.com">Ales Justin</a> | ||
*/ | ||
public class TempStoreTestCase extends AbstractVFSTest | ||
{ | ||
public TempStoreTestCase(String s) | ||
{ | ||
super(s); | ||
} | ||
|
||
public static Test suite() | ||
{ | ||
return suite(TempStoreTestCase.class); | ||
} | ||
|
||
public void testCopyMechanism() throws Throwable | ||
{ | ||
long seed = System.nanoTime(); | ||
URL url = getResource("/vfs/test"); | ||
VFS vfs = VFS.getVFS(url); | ||
TempStore store = new MkdirTempStore(new DeleteOnExitTempStore(new MockTempStore(seed))); | ||
vfs.setTempStore(store); | ||
VirtualFile file = vfs.getChild("jar1.jar"); | ||
VirtualFile temp = VFSUtils.explode(file); | ||
try | ||
{ | ||
File tempRoot = AbstractCopyMechanism.getTempDirectory(); | ||
File test = new File(tempRoot, "jar1.jar" + '_' + seed); | ||
assertTrue(test.exists()); // should be created by MockTS | ||
} | ||
finally | ||
{ | ||
temp.cleanup(); | ||
} | ||
} | ||
|
||
public void testNestedZip() throws Throwable | ||
{ | ||
long seed = System.nanoTime(); | ||
URL url = getResource("/vfs/test/nested"); | ||
VFS vfs = VFS.getVFS(url); | ||
VFSUtils.enableCopy(vfs); | ||
TempStore store = new MkdirTempStore(new TrackingTempStore(new MockTempStore(seed))); | ||
try | ||
{ | ||
vfs.setTempStore(store); | ||
VirtualFile file = vfs.getChild("nested.jar"); | ||
assertNotNull(file.getChild("complex.jar/subfolder/subchild")); | ||
try | ||
{ | ||
File tempRoot = AbstractCopyMechanism.getTempDirectory(); | ||
File test = new File(tempRoot, "complex.jar" + '_' + seed); | ||
assertTrue(test.exists()); // should be created by MockTS | ||
} | ||
finally | ||
{ | ||
file.cleanup(); | ||
} | ||
} | ||
finally | ||
{ | ||
store.clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters