[jboss-cvs] JBossAS SVN: r95611 - in projects/vfs/branches/Branch_2_2: .settings and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Oct 27 11:11:07 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-10-27 11:11:07 -0400 (Tue, 27 Oct 2009)
New Revision: 95611

Added:
   projects/vfs/branches/Branch_2_2/.settings/
   projects/vfs/branches/Branch_2_2/.settings/org.eclipse.jdt.core.prefs
   projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/VFSOutputterTestCase.java
Modified:
   projects/vfs/branches/Branch_2_2/.classpath
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java
Log:
[JBVFS-126] Utility method to output files and folders in a virtual file

Modified: projects/vfs/branches/Branch_2_2/.classpath
===================================================================
--- projects/vfs/branches/Branch_2_2/.classpath	2009-10-27 13:53:37 UTC (rev 95610)
+++ projects/vfs/branches/Branch_2_2/.classpath	2009-10-27 15:11:07 UTC (rev 95611)
@@ -1,13 +1,12 @@
 <classpath>
-  <classpathentry kind="src" path="src/main/java"/>
-  <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
   <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
+  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
   <classpathentry kind="output" path="target/classes"/>
-  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.0/ant-1.7.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
-  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.9.GA/jboss-common-core-2.2.9.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.9.GA/jboss-common-core-2.2.9.GA-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/jboss/jboss-common-core/2.2.16.GA/jboss-common-core-2.2.16.GA.jar" sourcepath="M2_REPO/org/jboss/jboss-common-core/2.2.16.GA/jboss-common-core-2.2.16.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-log4j/2.0.5.GA/jboss-logging-log4j-2.0.5.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar" sourcepath="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
@@ -15,4 +14,5 @@
   <classpathentry kind="var" path="M2_REPO/org/jboss/test/jboss-test/1.1.0.GA/jboss-test-1.1.0.GA.jar" sourcepath="M2_REPO/org/jboss/test/jboss-test/1.1.0.GA/jboss-test-1.1.0.GA-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar" sourcepath="M2_REPO/junit/junit/4.4/junit-4.4-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 </classpath>
\ No newline at end of file

Added: projects/vfs/branches/Branch_2_2/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/vfs/branches/Branch_2_2/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/vfs/branches/Branch_2_2/.settings/org.eclipse.jdt.core.prefs	2009-10-27 15:11:07 UTC (rev 95611)
@@ -0,0 +1,5 @@
+#Tue Oct 27 13:03:52 GMT 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java	2009-10-27 13:53:37 UTC (rev 95610)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java	2009-10-27 15:11:07 UTC (rev 95611)
@@ -60,6 +60,7 @@
  *
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
 public class VFSUtils
@@ -1153,4 +1154,64 @@
       URI uri = context.getRootURI();
       return stripProtocol(uri);
    }
+   
+   /**
+    * Returns a string of the contents of the virtual file, showing the names of all 
+    * the nested directories and names, useful for debugging
+    * 
+    * @param file the virtual file to display the contents of
+    * @return A string containing the contents of the virtual file
+    * @throws RuntimeException if an error happened
+    */
+   public static String outputContents(VirtualFile file)
+   {
+      try
+      {
+         VirtualFileOutputter outputter = new VirtualFileOutputter(file.toURI().toString());
+         outputter.outputContents(0, file);
+         return outputter.getOutput();
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException("ERROR displaying the contents of " + file.getName(), e);
+      }
+   }
+   
+   
+   private static class VirtualFileOutputter
+   {
+      StringBuilder sb;
+
+      private VirtualFileOutputter(String uri)
+      {
+         sb = new StringBuilder("Contents of " + uri + "\n");
+      }
+      
+      private String getOutput()
+      {
+         return sb.toString();
+      }
+      
+      private void outputContents(int level, VirtualFile file) throws Exception
+      {
+         String suffix = file.isLeaf() ? "" : "/";
+         writeToBuffer(level, file.getName() + suffix);
+         if (!file.isLeaf())
+         {
+            for (VirtualFile child : file.getChildren())
+            {
+               outputContents(level + 1, child);
+            }
+         }
+      }
+      
+      private void writeToBuffer(int level, String s)
+      {
+         for (int i = 0 ; i < level ; i++)
+            sb.append("  ");
+         
+         sb.append(s);
+         sb.append("\n");
+      }
+   }
 }

Added: projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/VFSOutputterTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/VFSOutputterTestCase.java	                        (rev 0)
+++ projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/VFSOutputterTestCase.java	2009-10-27 15:11:07 UTC (rev 95611)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.test;
+
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSOutputterTestCase extends AbstractVFSTest
+{
+   public VFSOutputterTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(VFSOutputterTestCase.class);
+   }
+
+
+   public void testOutputJarContents() throws Exception
+   {
+      URL url = getResource("/vfs/test/jar1.jar");
+      VirtualFile jar = VFS.getRoot(url);
+      
+      String output = VFSUtils.outputContents(jar);
+      
+      String expected = "jar1.jar/\n" +
+      		"  META-INF/\n" +
+      		"    MANIFEST.MF\n" +
+      		"  org/\n" +
+      		"    jboss/\n" +
+      		"      test/\n" +
+      		"        vfs/\n" +
+            "          support/\n" +
+            "            jar1/\n" +
+            "              ClassInJar1$InnerClass.class\n" +
+            "              ClassInJar1.class";      
+
+      assertTrue("expected:\n" + expected + "\nwas:\n" + output, output.contains(expected));
+   }
+}




More information about the jboss-cvs-commits mailing list