[jboss-cvs] JBossAS SVN: r72614 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 23 05:00:39 EDT 2008


Author: alesj
Date: 2008-04-23 05:00:39 -0400 (Wed, 23 Apr 2008)
New Revision: 72614

Added:
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyJAREntryTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JAREntryTestCase.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java
Log:
Source cleanup.
Adding [JBVFS-7] test, but it's hacked atm.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java	2008-04-23 08:48:22 UTC (rev 72613)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -127,7 +127,9 @@
       List<ArrayList<ZipEntryWrapper<T>>> levelMapList = new ArrayList<ArrayList<ZipEntryWrapper<T>>>();
       entries = new ArrayList<VirtualFileHandler>();
       entryMap = new HashMap<String, VirtualFileHandler>();
+
       boolean trace = log.isTraceEnabled();
+
       while (enumeration.hasMoreElements())
       {
          ZipEntryWrapper<T> wrapper = enumeration.nextElement();
@@ -153,8 +155,7 @@
          for (ZipEntryWrapper<T> wrapper : levels)
          {
             String name = wrapper.getName();
-            int slash = wrapper.isDirectory() ? name.lastIndexOf('/', name.length() - 2) :
-                    name.lastIndexOf('/', name.length() - 1);
+            int slash = wrapper.isDirectory() ? name.lastIndexOf('/', name.length() - 2) : name.lastIndexOf('/', name.length() - 1);
             VirtualFileHandler parent = this;
             if (slash >= 0)
             {
@@ -220,10 +221,9 @@
       StringBuilder pathName = new StringBuilder();
       for (String path : paths)
       {
-         VirtualFileHandler next;
          pathName.append(path);
          pathName.append('/');
-         next = parent.getChild(path);
+         VirtualFileHandler next = parent.getChild(path);
          if (next == null)
             next = createSynthenticParent(parent, path, wrapper);
          parentMap.put(pathName.toString(), next);
@@ -235,9 +235,10 @@
    protected VirtualFileHandler createSynthenticParent(VirtualFileHandler parent, String path, ZipEntryWrapper<T> wrapper)
          throws IOException
    {
-      VirtualFileHandler next;// Create a synthetic parent
       URL url = getURL(parent, path, true);
-      next = new SynthenticDirEntryHandler(getVFSContext(), parent, path, wrapper.getTime(), url);
+      // Create a synthetic parent
+      VirtualFileHandler next = new SynthenticDirEntryHandler(getVFSContext(), parent, path, wrapper.getTime(), url);
+
       if (parent == this)
       {
          // This is an immeadiate child of the jar handler

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2008-04-23 08:48:22 UTC (rev 72613)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -105,6 +105,8 @@
       if (entryChildren == null)
          entryChildren = new ArrayList<VirtualFileHandler>();
       entryChildren.add(child);
+      if (entryMap != null)
+         entryMap.put(child.getName(), child);
    }
 
    @Override

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java	2008-04-23 08:48:22 UTC (rev 72613)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -105,11 +105,10 @@
    }
 
    @Override
-   public long getLastModified()
+   public long getLastModified() throws IOException
    {
-      if (cachedLastModified == 0)
-         cachedLastModified = System.currentTimeMillis();
-      return cachedLastModified;
+      checkParentExists();
+      return getParent().getLastModified();
    }
 
    @Override

Added: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyJAREntryTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyJAREntryTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/CopyJAREntryTestCase.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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;
+
+/**
+ * copy jar entry tests.
+ *
+ * @author Ales.Justin at jboss.org
+ */
+public class CopyJAREntryTestCase extends JAREntryTestCase
+{
+   public CopyJAREntryTestCase(String name)
+   {
+      super(name, true);
+   }
+
+   public static Test suite()
+   {
+      return suite(CopyJAREntryTestCase.class);
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-04-23 08:48:22 UTC (rev 72613)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileVFSUnitTestCase.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -703,10 +703,9 @@
       assertEquals("There were 2 classes", 2, count);
 
       // Make sure we can walk path-wise to the class
-      VirtualFile jar1 = vfs.getRoot();
-      VirtualFile parent = jar1;
+      VirtualFile parent = vfs.getRoot();
       String className = "org/jboss/test/vfs/support/jar1/ClassInJar1.class";
-      VirtualFile ClassInJar1 = vfs.findChild(className);
+      VirtualFile classInJar1 = vfs.findChild(className);
       String[] paths = className.split("/");
       StringBuilder vfsPath = new StringBuilder();
       for(String path : paths)
@@ -714,11 +713,13 @@
          vfsPath.append(path);
          VirtualFile vf = parent.findChild(path);
          if( path.equals("ClassInJar1.class") )
-            assertEquals("ClassInJar1.class", ClassInJar1, vf);
+            assertEquals("ClassInJar1.class", classInJar1, vf);
          else
          {
             assertEquals("vfsPath", vfsPath.toString(), vf.getPathName());
-            assertEquals("lastModified", ClassInJar1.getLastModified(), vf.getLastModified());
+            // why should this be equal?
+            // assertEquals("lastModified", classInJar1.getLastModified(), vf.getLastModified());
+            assertTrue("lastModified", classInJar1.getLastModified() <= vf.getLastModified());
          }
          vfsPath.append('/');
          parent = vf;

Copied: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JAREntryTestCase.java (from rev 72234, projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/URLExistsUnitTestCase.java)
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JAREntryTestCase.java	                        (rev 0)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JAREntryTestCase.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.io.FileOutputStream;
+import java.util.List;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * jar entry tests.
+ *
+ * @author Ales.Justin at jboss.org
+ */
+public class JAREntryTestCase extends OSAwareVFSTest
+{
+   public JAREntryTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected JAREntryTestCase(String name, boolean forceCopy)
+   {
+      super(name, forceCopy);
+   }
+
+   public static Test suite()
+   {
+      return suite(JAREntryTestCase.class);
+   }
+
+   public void testEntryModified() throws Exception
+   {
+      File tmp = File.createTempFile("testJarEntry", ".jar");
+      Manifest mf = new Manifest();
+      mf.getMainAttributes().putValue("Created-By", getClass().getName() + "." + "testEntryModified");
+      FileOutputStream fos = new FileOutputStream(tmp);
+      JarOutputStream jos = new JarOutputStream(fos, mf);
+      try
+      {
+         jos.setComment("testJarURLs");
+         jos.setLevel(0);
+         jos.flush();
+      }
+      finally
+      {
+         jos.close();
+      }
+
+      VFS vfs = VFS.getVFS(tmp.toURI());
+      VirtualFile root = vfs.getRoot();
+      VirtualFile metainf = root.findChild("META-INF");
+      List<VirtualFile> children = metainf.getChildren();
+      assertEquals(1, children.size());
+
+      fos = new FileOutputStream(tmp);
+      jos = new JarOutputStream(fos, mf);
+      try
+      {
+         ZipEntry entry = new ZipEntry("META-INF/some.txt");
+         entry.setComment("some_comment");
+         entry.setExtra("qwerty".getBytes());
+         entry.setSize(1);
+         jos.putNextEntry(entry);
+         jos.closeEntry();
+
+         entry = new ZipEntry("META-INF/other.txt");
+         entry.setComment("other_comment");
+         entry.setExtra("foobar".getBytes());
+         entry.setSize(1);
+         jos.putNextEntry(entry);
+         jos.closeEntry();
+      }
+      finally
+      {
+         jos.close();
+      }
+
+      // TODO - JBVFS-7 ... should work w/o creating new vfs 
+      vfs = VFS.getVFS(tmp.toURI());
+      metainf = vfs.findChild("META-INF");
+      System.out.println("root = " + root.hasBeenModified());
+      System.out.println("metainf = " + metainf.hasBeenModified());
+      children = metainf.getChildren();
+      assertEquals(3, children.size());
+   }
+}
\ No newline at end of file

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	2008-04-23 08:48:22 UTC (rev 72613)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSAllTestSuite.java	2008-04-23 09:00:39 UTC (rev 72614)
@@ -64,6 +64,8 @@
       suite.addTest(JARVirtualFileHandlerUnitTestCase.suite());
       suite.addTest(JARSerializationUnitTestCase.suite());
       suite.addTest(CopyJARSerializationUnitTestCase.suite());
+      suite.addTest(JAREntryTestCase.suite());
+      suite.addTest(CopyJAREntryTestCase.suite());
       // contexts
       suite.addTest(AssembledContextTestCase.suite());
       suite.addTest(MemoryTestCase.suite());




More information about the jboss-cvs-commits mailing list