[jboss-cvs] JBossAS SVN: r83896 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins/copy and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 5 08:21:18 EST 2009
Author: alesj
Date: 2009-02-05 08:21:18 -0500 (Thu, 05 Feb 2009)
New Revision: 83896
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarCleanupUnitTestCase.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarTestCase.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
Add legacy unjar.
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2009-02-05 11:41:30 UTC (rev 83895)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -46,6 +46,7 @@
import org.jboss.virtual.plugins.copy.CopyMechanism;
import org.jboss.virtual.plugins.copy.ExplodedCopyMechanism;
import org.jboss.virtual.plugins.copy.TempCopyMechanism;
+import org.jboss.virtual.plugins.copy.UnjarCopyMechanism;
import org.jboss.virtual.plugins.copy.UnpackCopyMechanism;
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.VFSContext;
@@ -828,6 +829,19 @@
}
/**
+ * Unjar.
+ *
+ * @param file the file to unjar
+ * @return temp file
+ * @throws IOException for any io error
+ * @throws URISyntaxException for any uri error
+ */
+ public static VirtualFile unjar(VirtualFile file) throws IOException, URISyntaxException
+ {
+ return copy(file, UnjarCopyMechanism.INSTANCE);
+ }
+
+ /**
* Create temp.
*
* @param file the file to unpack/explode
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-02-05 11:41:30 UTC (rev 83895)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempCopyMechanism.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -21,12 +21,10 @@
*/
package org.jboss.virtual.plugins.copy;
-import java.io.IOException;
import java.io.File;
+import java.io.IOException;
import org.jboss.virtual.plugins.context.jar.NestedJarHandler;
-import org.jboss.virtual.plugins.context.jar.JarHandler;
-import org.jboss.virtual.plugins.context.zip.ZipEntryHandler;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
@@ -51,15 +49,8 @@
protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
{
// leave top level archives or leaves in one piece
- boolean directRewrite = handler.isLeaf();
- if (directRewrite == false)
+ if (handler.isArchive() || handler.isLeaf())
{
- VirtualFileHandler unwrapped = unwrap(handler);
- directRewrite = unwrapped instanceof JarHandler || (unwrapped instanceof ZipEntryHandler && unwrapped.isNested() == false);
- }
-
- if (directRewrite)
- {
File temp = new File(guidDir, handler.getName());
temp.deleteOnExit();
rewrite(handler, temp);
Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java (from rev 83550, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnpackCopyMechanism.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -0,0 +1,72 @@
+/*
+* 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.virtual.plugins.copy;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.util.file.JarUtils;
+import org.jboss.virtual.plugins.context.file.FileHandler;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * Unjar file into temp dir.
+ * Uses old JarUtils.unjar method
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class UnjarCopyMechanism extends AbstractCopyMechanism
+{
+ public static final UnjarCopyMechanism INSTANCE = new UnjarCopyMechanism();
+
+ protected String getType()
+ {
+ return "unjared";
+ }
+
+ protected boolean isAlreadyModified(VirtualFileHandler handler) throws IOException
+ {
+ return handler instanceof FileHandler || handler.isLeaf();
+ }
+
+ @Override
+ protected File copy(File guidDir, VirtualFileHandler handler) throws IOException
+ {
+ File copy = createTempDirectory(guidDir, handler.getName());
+ InputStream in = handler.openStream();
+ try
+ {
+ JarUtils.unjar(in, copy);
+ }
+ finally
+ {
+ in.close();
+ }
+ return copy;
+ }
+
+ protected boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler) throws IOException
+ {
+ return false;
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/UnjarCopyMechanism.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java 2009-02-05 11:41:30 UTC (rev 83895)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTest.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -265,7 +265,7 @@
VirtualFile l3url = VFS.getRoot(url);
assertEquals(l3, l3url);
- assertTempFiles(2);
+ assertTempFiles(getTempFiles());
assertCopyMechanismFiles(1);
earCopy.cleanup();
@@ -273,6 +273,11 @@
assertCopyMechanismFiles(0);
}
+ protected int getTempFiles()
+ {
+ return 2;
+ }
+
// TODO - move this test
public void testTempUrls() throws Exception
{
@@ -285,15 +290,20 @@
assertEquals(getProtocol() + urlString + "level1.zip/", earCopy.toURL().toExternalForm());
VirtualFile l2 = earCopy.getChild("level2.zip");
- assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/", l2.toURL().toExternalForm());
+ assertEquals(getNestedProtocol() + urlString + "level1.zip/level2.zip/", l2.toURL().toExternalForm());
VirtualFile l2sub = l2.getChild("test2.txt");
- assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/test2.txt", l2sub.toURL().toExternalForm());
+ assertEquals(getNestedProtocol() + urlString + "level1.zip/level2.zip/test2.txt", l2sub.toURL().toExternalForm());
VirtualFile l3 = l2.getChild("level3.zip");
- assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip/", l3.toURL().toExternalForm());
+ assertEquals(getNestedProtocol() + urlString + "level1.zip/level2.zip/level3.zip/", l3.toURL().toExternalForm());
VirtualFile l3sub = l3.getChild("test3.txt");
- assertEquals(getProtocol() + urlString + "level1.zip/level2.zip/level3.zip/test3.txt", l3sub.toURL().toExternalForm());
+ assertEquals(getNestedProtocol() + urlString + "level1.zip/level2.zip/level3.zip/test3.txt", l3sub.toURL().toExternalForm());
ear.cleanup();
}
+
+ protected String getNestedProtocol()
+ {
+ return getProtocol();
+ }
}
\ No newline at end of file
Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarCleanupUnitTestCase.java (from rev 83795, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempCleanupUnitTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarCleanupUnitTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarCleanupUnitTestCase.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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 junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test file closing - unjar
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class UnjarCleanupUnitTestCase extends FileCleanupUnitTest
+{
+ public UnjarCleanupUnitTestCase(String name)
+ {
+ super(name, true, true);
+ }
+
+ public static Test suite()
+ {
+ VFS.init();
+ return suite(UnjarCleanupUnitTestCase.class);
+ }
+
+ protected VirtualFile modify(VirtualFile original) throws Exception
+ {
+ return VFSUtils.unjar(original);
+ }
+
+ protected String getProtocol()
+ {
+ return "vfsfile:";
+ }
+
+ @Override
+ protected int getTempFiles()
+ {
+ return 1;
+ }
+
+ @Override
+ protected String getNestedProtocol()
+ {
+ return "vfszip:";
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarCleanupUnitTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarTestCase.java (from rev 83455, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/TempTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarTestCase.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarTestCase.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -0,0 +1,61 @@
+/*
+* 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 junit.framework.Test;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Unpack tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class UnjarTestCase extends DetachedCopyTest
+{
+ public UnjarTestCase(String s)
+ {
+ super(s);
+ }
+
+ public static Test suite()
+ {
+ return suite(UnjarTestCase.class);
+ }
+
+ protected VirtualFile modify(VirtualFile file) throws Exception
+ {
+ return VFSUtils.unjar(file);
+ }
+
+ protected boolean isExploded() throws Exception
+ {
+ return true;
+ }
+
+ protected boolean isSame(VirtualFile original) throws Exception
+ {
+ // should almost never be same
+ // except if file was already nested jar copy
+ return false;
+ }
+}
\ No newline at end of file
Property changes on: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/UnjarTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-02-05 11:41:30 UTC (rev 83895)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java 2009-02-05 13:21:18 UTC (rev 83896)
@@ -79,6 +79,7 @@
suite.addTest(UnpackTestCase.suite());
suite.addTest(ExplodeTestCase.suite());
suite.addTest(TempTestCase.suite());
+ suite.addTest(UnjarTestCase.suite());
// visitor
suite.addTest(VisitorUnitTestCase.suite());
// utils
@@ -98,6 +99,7 @@
// operations
suite.addTest(TempCleanupUnitTestCase.suite());
suite.addTest(ExplodeCleanupUnitTestCase.suite());
+ suite.addTest(UnjarCleanupUnitTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list