aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1104064 - in /aries/trunk/application: application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ application-utils/src/test/java/org/...
Date Tue, 17 May 2011 08:53:05 GMT
Author: mahrwald
Date: Tue May 17 08:53:05 2011
New Revision: 1104064

URL: http://svn.apache.org/viewvc?rev=1104064&view=rev
Log:
ARIES-562: Support for nested zips in zips (I)

Added:
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipDirectory.java
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipFile.java
Modified:
    aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
    aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileSystemImpl.java
    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-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java?rev=1104064&r1=1104063&r2=1104064&view=diff
==============================================================================
--- aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
(original)
+++ aries/trunk/application/application-modeller/src/main/java/org/apache/aries/application/modelling/impl/ModelledResourceManagerImpl.java
Tue May 17 08:53:05 2011
@@ -22,14 +22,9 @@ package org.apache.aries.application.mod
 import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -58,7 +53,7 @@ import org.slf4j.LoggerFactory;
 
 public class ModelledResourceManagerImpl implements ModelledResourceManager
 {
-  private Logger _logger = LoggerFactory.getLogger(ModelledResourceManagerImpl.class);
+  private final Logger _logger = LoggerFactory.getLogger(ModelledResourceManagerImpl.class);
   private ParserProxy _parserProxy;
   private ModellingManager _modellingManager;
 
@@ -96,10 +91,7 @@ public class ModelledResourceManagerImpl
       Collection<IFile> blueprints = findBlueprints(archive);
       InputStream is = null;
       for (IFile bpFile : blueprints) {
-        URL url = bpFile.toURL();
-        URLConnection conn = url.openConnection();
-        is = conn.getInputStream();
-
+    	is = bpFile.open();
         try {
           ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
           services.addAll(pse.getServices());
@@ -133,18 +125,9 @@ public class ModelledResourceManagerImpl
   public ModelledResource getModelledResource(String uri, IDirectory bundle) throws ModellerException{
     _logger.debug(LOG_ENTRY, "getModelledResource", new Object[]{uri, bundle});
 
-    String bundleFile = null;
     if (bundle != null) {
-      try {
-        bundleFile = URLDecoder.decode(bundle.toString(), "UTF-8");
-      } catch (UnsupportedEncodingException uee) {
-        ModellerException me = new ModellerException(MessageUtil.getMessage("INVALID_BUNDLE_LOCATION",
bundle));
-        _logger.debug(LOG_EXIT, "getModelledResource", me);
-        throw me;
-      }
-      if (new File(bundleFile).exists()) {
         ParsedServiceElements pse = getServiceElements(bundle);
-        BundleManifest bm = BundleManifest.fromBundle(new File(bundleFile));
+        BundleManifest bm = BundleManifest.fromBundle(bundle);//new File(bundleFile));
         Attributes attributes = bm.getRawAttributes();
         ModelledResource mbi = null;
         try {
@@ -156,12 +139,6 @@ public class ModelledResourceManagerImpl
         }
         _logger.debug(LOG_EXIT, "getModelledResource", mbi);
         return mbi;
-      } else {
-        // The bundle does not exist
-        ModellerException me = new ModellerException(MessageUtil.getMessage("INVALID_BUNDLE_LOCATION",
bundle));
-        _logger.debug(LOG_EXIT, "getModelledResource", me);
-        throw me;
-      } 
     }
     else {
       // The bundle does not exist
@@ -213,7 +190,7 @@ public class ModelledResourceManagerImpl
         List<IFile> files = appBundle.listAllFiles();
         Iterator<IFile> it = files.iterator();
         while (it.hasNext()) {
-          IFile file = (IFile) it.next();         
+          IFile file = it.next();         
           String directoryFullPath = file.getName(); 
           String directoryName = "";
           String fileName = "";

Modified: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileSystemImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileSystemImpl.java?rev=1104064&r1=1104063&r2=1104064&view=diff
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileSystemImpl.java
(original)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileSystemImpl.java
Tue May 17 08:53:05 2011
@@ -3,41 +3,80 @@ package org.apache.aries.application.uti
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
 
 import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.utils.filesystem.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class FileSystemImpl {
 
-	  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
+	private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
 
-	  /**
-	   * This method gets the IDirectory that represents the root of a virtual file
-	   * system. The provided file can either identify a directory, or a zip file.
-	   * 
-	   * @param fs the zip file.
-	   * @return   the root of the virtual FS.
-	   */
-	  public static IDirectory getFSRoot(File fs, IDirectory parent)
-	  {
-	    IDirectory dir = null;
-	    
-	    if (fs.exists()) {
-	      if (fs.isDirectory()) {
-	        dir = new DirectoryImpl(fs, fs);
-	      } else if (fs.isFile()) {
-	        try {
-	          dir = new ZipDirectory(fs, fs, parent);
-	        } catch (IOException e) {
-	          _logger.error ("IOException in IDirectory.getFSRoot", e);
-	        }
-	      }
-	    }
-	    else {
-	      // since this method does not throw an exception but just returns null, make sure
we do not lose the error
-	      _logger.error("File not found in IDirectory.getFSRoot", new FileNotFoundException(fs.getPath()));
-	    }
-	    return dir;
-	  }
+	/**
+	 * This method gets the IDirectory that represents the root of a virtual file
+	 * system. The provided file can either identify a directory, or a zip file.
+	 * 
+	 * @param fs the zip file.
+	 * @return   the root of the virtual FS.
+	 */
+	public static IDirectory getFSRoot(File fs, IDirectory parent)
+	{
+		IDirectory dir = null;
+
+		if (fs.exists()) {
+			if (fs.isDirectory()) {
+				dir = new DirectoryImpl(fs, fs);
+			} else if (fs.isFile() && isValidZip(fs)) {
+				try {
+					dir = new ZipDirectory(fs, fs, parent);
+				} catch (IOException e) {
+					_logger.error ("IOException in IDirectory.getFSRoot", e);
+				}
+			}
+		}
+		else {
+			// since this method does not throw an exception but just returns null, make sure we do
not lose the error
+			_logger.error("File not found in IDirectory.getFSRoot", new FileNotFoundException(fs.getPath()));
+		}
+		return dir;
+	}
+	
+	/**
+	 * Check whether a file is actually a valid zip
+	 * @param zip
+	 * @return
+	 */
+	public static boolean isValidZip(File zip) {
+		try {
+			ZipFile zf = new ZipFile(zip);
+			zf.close();
+			return true;
+		} catch (IOException e) {
+			_logger.debug("Not a valid zip: "+zip);
+			return false;
+		}
+	}
+	
+	/**
+	 * Check whether a file is actually a valid zip
+	 * @param zip
+	 * @return
+	 */
+	public static boolean isValidZip(IFile zip) {
+		ZipInputStream zis = null;
+		try {
+			// just opening the stream ain't enough, we have to check the first entry
+			zis = new ZipInputStream(zip.open());
+			return zis.getNextEntry() != null;
+		} catch (IOException e) {
+			_logger.debug("Not a valid zip: "+zip);
+			return false;
+		} finally {
+			IOUtils.close(zis);
+		}
+	}
 }

Added: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipDirectory.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipDirectory.java?rev=1104064&view=auto
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipDirectory.java
(added)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipDirectory.java
Tue May 17 08:53:05 2011
@@ -0,0 +1,168 @@
+package org.apache.aries.application.utils.filesystem.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NestedZipDirectory extends NestedZipFile implements IDirectory {
+	
+	private static final Logger logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
+	
+	public NestedZipDirectory(IFile archive, ZipEntry entry, NestedZipDirectory parent) {
+		super(archive, entry, parent);
+	}
+	
+	public NestedZipDirectory(IFile archive, String pathInZip, NestedZipDirectory parent) {
+		super(archive, pathInZip, parent);
+	}
+	
+	public NestedZipDirectory(IFile archive) {
+		super(archive);
+	}
+	
+	@Override
+	public IDirectory convert() {
+		return this;
+	}
+
+	@Override
+	public Iterator<IFile> iterator() {
+		return listFiles().iterator();
+	}
+
+	@Override
+	public List<IFile> listFiles() {
+		return listFiles(false);
+	}
+
+	@Override
+	public List<IFile> listAllFiles() {
+		return listFiles(true);
+	}
+	
+	private List<IFile> listFiles(boolean includeFilesInNestedSubdirs) {
+		ZipInputStream zis = null;
+		
+		try {
+			zis = new ZipInputStream(archive.open());
+			
+			ZipEntry entry = zis.getNextEntry();
+			
+			Map<String, ZipEntry> entriesByName = new LinkedHashMap<String, ZipEntry>();
+			while (entry != null) {
+				if (ZipDirectory.isInDir(getNameInZip(), entry, includeFilesInNestedSubdirs)) {
+					entriesByName.put(entry.getName(), entry);
+				}
+				entry = zis.getNextEntry();
+			}
+
+			List<IFile> files = new ArrayList<IFile>();
+			for (ZipEntry ze : entriesByName.values()) {
+				NestedZipDirectory parent = includeFilesInNestedSubdirs ? buildParent(ze, entriesByName)
: this;
+				if (ze.isDirectory()) files.add(new NestedZipDirectory(archive, ze, parent));
+				else files.add(new NestedZipFile(archive, ze, parent));
+			}
+			
+			return files;
+			
+		} catch (IOException e) {
+			logger.error("IOException reading nested ZipFile", e);
+			return Collections.emptyList();
+		} finally {
+			IOUtils.close(zis);
+		}
+	}
+	
+	private NestedZipDirectory buildParent(ZipEntry entry, Map<String,ZipEntry> entries)
{
+		NestedZipDirectory result = this;
+		
+		String path = entry.getName().substring(getNameInZip().length());
+		String[] segments = path.split("/");
+		
+		if (segments != null && segments.length > 1) {
+			StringBuilder entryPath = new StringBuilder(getNameInZip());
+			for (int i=0; i<segments.length-1; i++) {
+				String p = segments[i];
+				entryPath.append(p).append("/");
+				ZipEntry ze = entries.get(entryPath.toString());
+				
+				if (ze != null) {
+					result = new NestedZipDirectory(archive, ze, result);
+				} else {
+					result = new NestedZipDirectory(archive, entryPath.toString(), result);
+				}
+			}
+		}
+		
+		return result;
+	}
+
+	@Override
+	public IFile getFile(String name) {
+		ZipInputStream zis = null;
+		
+		try {
+			zis = new ZipInputStream(archive.open());
+			
+			Map<String,ZipEntry> entries = new HashMap<String, ZipEntry>();
+			
+			ZipEntry ze = zis.getNextEntry();
+			
+			while (ze != null && !!!ze.getName().equals(name)) {
+				if (name.startsWith(ze.getName())) entries.put(ze.getName(), ze);
+				
+				ze = zis.getNextEntry();
+			}
+			
+			if (ze != null) {
+				NestedZipDirectory parent = buildParent(ze, entries);
+				if (ze.isDirectory()) return new NestedZipDirectory(archive, ze, parent);
+				else return new NestedZipFile(archive, ze, parent);
+			} else {
+				return null;
+			}
+			
+		} catch (IOException e) {
+			logger.error("IOException reading nested ZipFile", e);
+			return null;
+		} finally {
+			IOUtils.close(zis);
+		}
+	}
+
+	
+	@Override
+	public boolean isDirectory() {
+		return true;
+	}
+
+	@Override
+	public InputStream open() throws IOException, UnsupportedOperationException {
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public boolean isFile() {
+		return false;
+	}
+
+	@Override
+	public boolean isRoot() {
+		return false;
+	}
+
+}

Added: aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipFile.java
URL: http://svn.apache.org/viewvc/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipFile.java?rev=1104064&view=auto
==============================================================================
--- aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipFile.java
(added)
+++ aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/NestedZipFile.java
Tue May 17 08:53:05 2011
@@ -0,0 +1,162 @@
+package org.apache.aries.application.utils.filesystem.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+
+public class NestedZipFile implements IFile {
+	private final String name;
+	private final long size;
+	private final long lastModified;
+	private final IDirectory parent;
+	protected final IFile archive;
+	private final String nameInZip;
+	
+	/**
+	 * Construct a nested zip file
+	 * @param archive
+	 * @param entry
+	 * @param parent
+	 */
+	public NestedZipFile(IFile archive, ZipEntry entry, NestedZipDirectory parent) {
+		this.archive = archive;
+		this.parent = parent;
+		this.nameInZip = entry.getName();
+
+		name = archive.getName() + "/" + (nameInZip.endsWith("/") ? nameInZip.substring(0, nameInZip.length()-1)
: nameInZip);
+		size = entry.getSize();
+		lastModified = entry.getTime();
+	}
+	
+	public NestedZipFile(IFile archive, String pathInZip, NestedZipDirectory parent) {
+		this.archive = archive;
+		this.parent = parent;
+		this.nameInZip = pathInZip;
+
+		name = archive.getName() + "/" + (nameInZip.endsWith("/") ? nameInZip.substring(0, nameInZip.length()-1)
: nameInZip);
+		size = -1;
+		lastModified = -1;
+	}
+	
+	
+	public NestedZipFile(IFile archive) {
+		this.archive = archive;
+		this.parent = archive.getParent();
+		this.nameInZip = "";
+
+		name = archive.getName();
+		lastModified = archive.getLastModified();
+		size = archive.getSize();
+	}
+	
+	public String getNameInZip() {
+		return nameInZip;
+	}
+	
+	@Override
+	public String getName() {
+		return name;
+	}
+
+	@Override
+	public boolean isDirectory() {
+		return false;
+	}
+
+	@Override
+	public boolean isFile() {
+		return true;
+	}
+
+	@Override
+	public long getLastModified() {
+		return lastModified;
+	}
+
+	@Override
+	public long getSize() {
+		return size;
+	}
+
+	@Override
+	public IDirectory convert() {
+		return null;
+	}
+
+	@Override
+	public IDirectory convertNested() {
+		if (isDirectory()) return convert();
+		else if (FileSystemImpl.isValidZip(this)) return new NestedZipDirectory(this);
+		else return null;
+	}
+
+	@Override
+	public IDirectory getParent() {
+		return parent;
+	}
+
+	@Override
+	public InputStream open() throws IOException, UnsupportedOperationException {
+		final ZipInputStream zis = new ZipInputStream(archive.open());
+		
+		ZipEntry entry = zis.getNextEntry();
+		while (entry != null && !!!entry.getName().equals(nameInZip)) {
+			entry = zis.getNextEntry();
+		}
+		
+		if (entry != null) {
+			return zis;
+		} else {
+			zis.close();
+			return null;
+		}
+	}
+
+	@Override
+	public IDirectory getRoot() {
+		return archive.getRoot();
+	}
+
+	@Override
+	public URL toURL() throws MalformedURLException
+	{
+		if (nameInZip.isEmpty()) return archive.toURL();
+		else {
+			String entryURL = "jar:" + archive.toURL() + "!/" + nameInZip;
+			return new URL(entryURL);
+		}
+	}
+
+	@Override
+	public boolean equals(Object obj)
+	{
+		if (obj == null) return false;
+		if (obj == this) return true;
+
+		if (obj.getClass() == getClass()) {
+			return toString().equals(obj.toString());
+		}
+
+		return false;
+	}
+
+	@Override
+	public int hashCode()
+	{
+		return toString().hashCode();
+	}
+
+	@Override
+	public String toString()
+	{
+		if (nameInZip.isEmpty()) return archive.toString();
+		return archive.toString() + "/" + nameInZip;
+	}
+
+}

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=1104064&r1=1104063&r2=1104064&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
Tue May 17 08:53:05 2011
@@ -23,7 +23,7 @@ import java.io.File;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.zip.ZipEntry;
@@ -146,11 +146,9 @@ public class ZipDirectory extends ZipFil
 	  List<IFile> files = new ArrayList<IFile>();
 
 	  ZipFile z = openZipFile();
-	  Enumeration<? extends ZipEntry> entries = z.entries();
-
-	  while (entries.hasMoreElements()) {
-		  ZipEntry possibleEntry = entries.nextElement();
+	  List<? extends ZipEntry> entries = Collections.list(z.entries());
 
+	  for (ZipEntry possibleEntry : entries) {
 		  if (isInDir(getNameInZip(), possibleEntry, includeFilesInNestedSubdirs)) {
 			  ZipDirectory parent = includeFilesInNestedSubdirs ? buildParent(possibleEntry) : this;
 			  if (possibleEntry.isDirectory()) {
@@ -161,6 +159,7 @@ public class ZipDirectory extends ZipFil
 		  }
 
 	  }
+	  
 	  closeZipFile(z);
 	  return files;	  
   }

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=1104064&r1=1104063&r2=1104064&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
Tue May 17 08:53:05 2011
@@ -124,6 +124,13 @@ public class ZipFileImpl implements IFil
   {
     return null;
   }
+  
+  @Override
+  public IDirectory convertNested() {
+	  if (isDirectory()) return convert();
+	  else if (FileSystemImpl.isValidZip(this)) return new NestedZipDirectory(this); 
+	  else return null;
+  }	
 
   @Override
   public long getLastModified()
@@ -277,9 +284,4 @@ public class ZipFileImpl implements IFil
     
   }
 
-  @Override
-  public IDirectory convertNested() {
-	// TODO Auto-generated method stub
-	return null;
-  }
 }

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=1104064&r1=1104063&r2=1104064&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
Tue May 17 08:53:05 2011
@@ -101,6 +101,16 @@ public class FileSystemTest
     runBasicRootDirTests(dir, baseDir.length(), baseDir.lastModified());
   }
   
+  @Test
+  public void testInvalidFSRoot() throws IOException
+  {
+	  File baseDir = new File(getTestResourceDir(), "/app1");
+	  File manifest = new File(baseDir, AppConstants.APPLICATION_MF);
+	  IDirectory dir = FileSystem.getFSRoot(manifest);
+	  
+	  assertNull(dir);
+  }
+  
   /**
    * Make sure that operations work on zip files nested in file IDirectories
    * @throws IOException
@@ -141,6 +151,24 @@ public class FileSystemTest
   }
   
   /**
+   * Make sure that the operations work with zip files inside other zip files. Performance
is not going to be great though :)
+   */
+  @Test
+  public void nestedZipInZip() throws IOException
+  {
+	  IDirectory outer = FileSystem.getFSRoot(new File("fileSystemTest/outer.zip"));
+	  
+	  IFile innerFile = outer.getFile("app2.zip");
+	  assertNotNull(innerFile);
+
+	  IDirectory inner = innerFile.convertNested();
+	  assertNotNull(inner);
+	  
+	  File desiredFile = new File(new File(getTestResourceDir(), "/app1"), AppConstants.APPLICATION_MF);
 
+	  runBasicDirTest(inner, "app2.zip/", -1, desiredFile.lastModified());
+  }
+  
+  /**
    * Make sure we correctly understand the directory structure for zips.
    * 
    * @throws IOException
@@ -171,11 +199,19 @@ public class FileSystemTest
     zipFile.getParentFile().mkdirs();
     ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
 
-    int index = new File(getTestResourceDir(), "/app1").getAbsolutePath().length();
-    
+    int index = new File(getTestResourceDir(), "/app1").getAbsolutePath().length();    
     writeEnties(out, new File(getTestResourceDir(), "/app1"), index);
+
+    out.close();
     
+    zipFile = new File("outer.zip");
+    out = new ZipOutputStream(new FileOutputStream(zipFile));
+    index = new File("fileSystemTest").getAbsolutePath().length();    
+    writeEnties(out, new File("fileSystemTest"), index);
+
     out.close();
+    
+    if (!!!zipFile.renameTo(new File("fileSystemTest/outer.zip"))) throw new IOException("Rename
failed");
   }
   
   private static File getTestResourceDir() {
@@ -191,7 +227,7 @@ public class FileSystemTest
   @AfterClass
   public static void destroyZip()
   {
-	  IOUtils.deleteRecursive(new File("fileSystemTest/"));
+	  IOUtils.deleteRecursive(new File("fileSystemTest"));
   }
   
   /**
@@ -286,6 +322,9 @@ public class FileSystemTest
     
     assertNotNull("we could not find the application manifest", file);
     
+    assertNull(file.convert());
+    assertNull(file.convertNested());
+    
     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);
 
@@ -323,7 +362,7 @@ public class FileSystemTest
     }
 
     checkManifest(file.open());
-    
+        
     IFile applicationMF2 = dir.getFile(AppConstants.APPLICATION_MF);
     
     Assert.assertEqualsContract(file, applicationMF2, dir);



Mime
View raw message