aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1103854 - in /aries/trunk/application/application-utils/src: main/java/org/apache/aries/application/utils/filesystem/impl/ test/java/org/apache/aries/application/utils/filesystem/
Date Mon, 16 May 2011 19:36:22 GMT
Author: mahrwald
Date: Mon May 16 19:36:21 2011
New Revision: 1103854

URL: http://svn.apache.org/viewvc?rev=1103854&view=rev
Log:
ARIES-652: A couple of additional tests (and fixes) for nested zips in directories

Modified:
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java
    aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/FileSystemTest.java

Modified: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java?rev=1103854&r1=1103853&r2=1103854&view=diff
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java
(original)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java
Mon May 16 19:36:21 2011
@@ -37,7 +37,7 @@ import org.apache.aries.application.file
 public class ZipDirectory extends ZipFileImpl implements IDirectory
 {
   /** The root of the zip FS. */
-  private IDirectory root;
+  private final IDirectory root;
   private final boolean zipRoot;
   
   /**
@@ -51,6 +51,7 @@ public class ZipDirectory extends ZipFil
   {
     super(zip1, entry1, parent);
     zipRoot = false;
+    root = parent.getRoot();
   }
 
   /**
@@ -72,7 +73,7 @@ public class ZipDirectory extends ZipFil
   {
     IFile result = null;
     
-    String entryName = isZipRoot() ? name : getName() + "/" + name;
+    String entryName = isZipRoot() ? name : getNameInZip() + "/" + name;
     
     ZipEntry entryFile = getEntry(entryName);
     
@@ -97,13 +98,13 @@ public class ZipDirectory extends ZipFil
     
     String name = foundEntry.getName();
     
-    name = name.substring(getName().length());
+    name = name.substring(getNameInZip().length());
     
     String[] paths = name.split("/");
     
-    StringBuilder baseBuilderCrapThingToGetRoundFindBugs = new StringBuilder(getName());
+    StringBuilder baseBuilderCrapThingToGetRoundFindBugs = new StringBuilder(getNameInZip());
     
-    if (!!!isRoot()) baseBuilderCrapThingToGetRoundFindBugs.append('/');
+    if (!!!isZipRoot()) baseBuilderCrapThingToGetRoundFindBugs.append('/');
     // Build 'result' as a chain of ZipDirectories. This will only work if java.util.ZipFile
recognises every 
     // directory in the chain as being a ZipEntry in its own right. 
     outer: if (paths != null && paths.length > 1) {
@@ -150,7 +151,7 @@ public class ZipDirectory extends ZipFil
 	  while (entries.hasMoreElements()) {
 		  ZipEntry possibleEntry = entries.nextElement();
 
-		  if (isInDir(possibleEntry, includeFilesInNestedSubdirs)) {
+		  if (isInDir(getNameInZip(), possibleEntry, includeFilesInNestedSubdirs)) {
 			  ZipDirectory parent = includeFilesInNestedSubdirs ? buildParent(possibleEntry) : this;
 			  if (possibleEntry.isDirectory()) {
 				  files.add(new ZipDirectory(zip, possibleEntry, parent));
@@ -172,11 +173,10 @@ public class ZipDirectory extends ZipFil
    * @param whether files in subdirectories are to be included
    * @return true if it is in this directory.
    */
-  private boolean isInDir(ZipEntry possibleEntry, boolean allowSubDirs)
+  protected static boolean isInDir(String parentDir, ZipEntry possibleEntry, boolean allowSubDirs)
   {
     boolean result;
     String name = possibleEntry.getName();
-    String parentDir = getName();
     if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
     result = (name.startsWith(parentDir) && !!!name.equals(parentDir) &&
(allowSubDirs || name.substring(parentDir.length() + 1).indexOf('/') == -1));
     return result;

Modified: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java?rev=1103854&r1=1103853&r2=1103854&view=diff
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java
(original)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java
Mon May 16 19:36:21 2011
@@ -136,6 +136,16 @@ public class ZipFileImpl implements IFil
   {
     return name;
   }
+  
+  public String getNameInZip() 
+  {
+	  if (entry == null) return "";
+	  else {
+		  String name = entry.getName();
+		  if (isDirectory()) return name.substring(0, name.length()-1);
+		  else return name;
+	  }
+  }
 
   @Override
   public IDirectory getParent()

Modified: aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/FileSystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/FileSystemTest.java?rev=1103854&r1=1103853&r2=1103854&view=diff
==============================================================================
--- aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/FileSystemTest.java
(original)
+++ aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/filesystem/FileSystemTest.java
Mon May 16 19:36:21 2011
@@ -136,6 +136,8 @@ public class FileSystemTest
 	
 	// check URLs are correct
 	checkManifest(appMf.toURL().openStream());
+	
+	runBasicDirTest(zip, "fileSystemTest/app2.zip/", appMf.getSize(), appMf.getLastModified());
   }
   
   /**
@@ -261,6 +263,11 @@ public class FileSystemTest
     dir.open();
   }
   
+  private void runBasicDirTest(IDirectory dir, long len, long time) throws IOException
+  {
+	  runBasicDirTest(dir, "", len, time);
+  }
+  
   /**
    * This method makes sure that the data is correctly understood from disk. It
    * is called for both the file and zip versions of the test to ensure we have
@@ -271,7 +278,7 @@ public class FileSystemTest
    * @param time  The time the file was last updated.
    * @throws IOException
    */
-  public void runBasicDirTest(IDirectory dir, long len, long time) throws IOException
+  private void runBasicDirTest(IDirectory dir, String namePrefix, long len, long time) throws
IOException
   {
     assertNull("for some reason our fake app has a fake blueprint file.", dir.getFile("OSGI-INF/blueprint/aries.xml"));
     
@@ -279,11 +286,11 @@ public class FileSystemTest
     
     assertNotNull("we could not find the application manifest", file);
     
-    assertEquals(AppConstants.APPLICATION_MF, file.getName().replace('\\', '/'));
+    assertEquals(namePrefix+AppConstants.APPLICATION_MF, file.getName().replace('\\', '/'));
     assertTrue("The last update time is not within 2 seconds of the expected value. Expected:
" + time + " Actual: " + file.getLastModified(), Math.abs(time - file.getLastModified()) <
2000);
 
     assertEquals(len, file.getSize());
-    assertEquals("META-INF", file.getParent().getName());
+    assertEquals(namePrefix+"META-INF", file.getParent().getName());
     assertFalse(file.isDirectory());
     assertTrue(file.isFile());
     
@@ -295,12 +302,12 @@ public class FileSystemTest
     filterOutSvn(allFiles);    
     assertEquals(3, allFiles.size());
     
-    assertEquals("META-INF", allFiles.get(1).getParent().getName());
+    assertEquals(namePrefix+"META-INF", allFiles.get(1).getParent().getName());
     
     IFile metaInf = files.get(0);
     
     assertTrue(metaInf.isDirectory());
-    assertEquals("META-INF", metaInf.getName());
+    assertEquals(namePrefix+"META-INF", metaInf.getName());
     assertNotNull(metaInf.convert());
     
     files = metaInf.convert().listAllFiles();
@@ -308,9 +315,9 @@ public class FileSystemTest
     assertEquals(2, files.size());    
     
     for (IFile aFile : dir) {
-      if (!aFile.getName().equalsIgnoreCase(".svn")) { 
+      if (!aFile.getName().contains(".svn")) { 
         assertTrue(aFile.isDirectory());
-        assertEquals("META-INF", aFile.getName());
+        assertEquals(namePrefix+"META-INF", aFile.getName());
         assertNotNull(aFile.convert());
       }
     }



Mime
View raw message