[jboss-cvs] JBossAS SVN: r75168 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jun 28 10:37:07 EDT 2008
Author: alesj
Date: 2008-06-28 10:37:07 -0400 (Sat, 28 Jun 2008)
New Revision: 75168
Added:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/PatternVirtualFileVisitor.java
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CustomTestCase.java
Log:
[JBVFS-42]; fix nested dir entries.
Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java (from rev 75105, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryWrapper.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipDirWrapper.java 2008-06-28 14:37:07 UTC (rev 75168)
@@ -0,0 +1,100 @@
+/*
+* 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.context.zip;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * ZipDirWrapper - for abstracted access to in-memory directory
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+class ZipDirWrapper extends ZipBytesWrapper
+{
+ private ByteArrayInputStream zisCopy;
+
+ /**
+ * ZipStreamWrapper is not aware of actual zip source so it can not detect
+ * if it's been modified, like ZipFileWrapper does.
+ *
+ * @param zipStream the current zip input stream
+ * @param name the name
+ * @param lastModified passed by zip stream provider - constant value
+ * @param zisCopy zis copy
+ * @throws java.io.IOException for any error
+ */
+ ZipDirWrapper(InputStream zipStream, String name, long lastModified, ByteArrayInputStream zisCopy) throws IOException
+ {
+ super(zipStream, name, lastModified);
+ this.zisCopy = zisCopy;
+ }
+
+ InputStream openStream(ZipEntry ent) throws IOException
+ {
+ return getRootAsStream();
+ }
+
+ Enumeration<? extends ZipEntry> entries() throws IOException
+ {
+ zisCopy.reset();
+ return new DirEnumeration();
+ }
+
+ /**
+ * Zip stream enumeration.
+ */
+ private class DirEnumeration implements Enumeration<ZipEntry>
+ {
+ private ZipInputStream zis;
+ private ZipEntry entry;
+
+ private DirEnumeration()
+ {
+ this.zis = new ZipInputStream(zisCopy);
+ }
+
+ public boolean hasMoreElements()
+ {
+ try
+ {
+ entry = zis.getNextEntry();
+ while (entry != null && entry.getName().startsWith(getName()) == false)
+ entry = zis.getNextEntry();
+ return entry != null;
+ }
+ catch (IOException e)
+ {
+ return false;
+ }
+ }
+
+ public ZipEntry nextElement()
+ {
+ return entry;
+ }
+ }
+}
\ No newline at end of file
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2008-06-28 13:34:03 UTC (rev 75167)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2008-06-28 14:37:07 UTC (rev 75168)
@@ -320,11 +320,10 @@
{
if (match.equals(relative))
{
- // directories and non archives
- if (entry.isDirectory() || JarUtils.isArchive(match) == false)
- {
+ if (entry.isDirectory())
+ return new ZipDirWrapper(zis, entryName, System.currentTimeMillis(), bais);
+ else if (JarUtils.isArchive(match) == false)
return new ZipEntryWrapper(zis, entryName, System.currentTimeMillis());
- }
else
return new ZipStreamWrapper(zis, entryName, System.currentTimeMillis());
}
Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/PatternVirtualFileVisitor.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/PatternVirtualFileVisitor.java (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/PatternVirtualFileVisitor.java 2008-06-28 14:37:07 UTC (rev 75168)
@@ -0,0 +1,77 @@
+/*
+* 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.support;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PatternVirtualFileVisitor implements VirtualFileVisitor
+{
+ private String subPattern = ".class";
+ private List<String> resources = new ArrayList<String>();
+
+ public PatternVirtualFileVisitor()
+ {
+ }
+
+ public PatternVirtualFileVisitor(String subPattern)
+ {
+ this.subPattern = subPattern;
+ }
+
+ public VisitorAttributes getAttributes()
+ {
+ return VisitorAttributes.RECURSE_LEAVES_ONLY;
+ }
+
+ public void visit(VirtualFile vf)
+ {
+ String pathName = vf.getPathName();
+ if (pathName.endsWith(subPattern))
+ resources.add(pathName);
+ }
+
+ public List<String> getResources()
+ {
+ return resources;
+ }
+
+ public int size()
+ {
+ return resources.size();
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("sub-pattern: ").append(subPattern);
+ buffer.append(", resources: ").append(resources);
+ return buffer.toString();
+ }
+}
Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CustomTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CustomTestCase.java 2008-06-28 13:34:03 UTC (rev 75167)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CustomTestCase.java 2008-06-28 14:37:07 UTC (rev 75168)
@@ -22,8 +22,10 @@
package org.jboss.test.virtual.test;
import java.net.URL;
+import java.util.List;
import junit.framework.Test;
+import org.jboss.test.virtual.support.PatternVirtualFileVisitor;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
@@ -54,8 +56,13 @@
URL url = getResource("/vfs/test/spring-ear.ear");
String urlString = url.toExternalForm();
int p = urlString.indexOf(":/");
- url = new URL("vfszip" + urlString.substring(p) + "/lib/spring-beans.jar/org/jboss/test/spring/");
+ url = new URL("vfszip" + urlString.substring(p) + "/lib/spring-beans.jar/org/jboss/test/spring");
VirtualFile file = VFS.getRoot(url);
assertNotNull(file);
+ PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor();
+ file.visit(visitor);
+ List<String> resources = visitor.getResources();
+ assertNotNull(resources);
+ assertTrue("Resources empty", resources.size() > 0);
}
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list