[jboss-svn-commits] JBoss Common SVN: r3523 - in shrinkwrap/trunk/impl-base/src: test/java/org/jboss/shrinkwrap/impl/base/export and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 15 19:32:25 EDT 2009
Author: johnbailey
Date: 2009-09-15 19:32:25 -0400 (Tue, 15 Sep 2009)
New Revision: 3523
Added:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterUtil.java
Modified:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExportDelegate.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java
Log:
[SHRINKWRAP-12] - removed starting slash from zip entry paths to resolve issues in certain zip clients
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExportDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExportDelegate.java 2009-09-15 22:04:37 UTC (rev 3522)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExportDelegate.java 2009-09-15 23:32:25 UTC (rev 3523)
@@ -103,7 +103,8 @@
@Override
protected void processAsset(Path path, Asset asset)
{
- final String pathName = path.get();
+ final String pathName = ZipExporterUtil.toZipEntryPath(path);
+
final ZipEntry entry = new ZipEntry(pathName);
final InputStream in = asset.getStream();
Added: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterUtil.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterUtil.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterUtil.java 2009-09-15 23:32:25 UTC (rev 3523)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.impl.base.export;
+
+import org.jboss.shrinkwrap.api.Path;
+
+/**
+ * ZipExporterUtil
+ *
+ * Utility used to assist exporting to Zip format.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class ZipExporterUtil
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Slash character
+ */
+ static final String SLASH = "/";
+
+ /**
+ * Empty String
+ */
+ static final String EMPTY = "";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * No instantiation
+ */
+ private ZipExporterUtil()
+ {
+ throw new UnsupportedOperationException("Constructor should never be invoked; this is a static util class");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Utilities --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Converts a Path to a ZipEntry path name
+ *
+ * @param path to convert
+ * @return String representing a ZipEntry path
+ */
+ public static String toZipEntryPath(Path path)
+ {
+
+ String context = path.get();
+ if (context.startsWith(SLASH))
+ {
+ context = context.substring(1);
+ }
+ return context;
+ }
+}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java 2009-09-15 22:04:37 UTC (rev 3522)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/export/ZipExporterTestCase.java 2009-09-15 23:32:25 UTC (rev 3523)
@@ -112,8 +112,11 @@
// Validate nested archive entries were written out
Path nestedArchivePath = new BasicPath(NAME_NESTED_ARCHIVE);
+ // Get Zip entry path
+ String nestedArchiveZipEntryPath = ZipExporterUtil.toZipEntryPath(nestedArchivePath);
+
// Get nested archive entry from exported zip
- ZipEntry nestedArchiveEntry = expectedZip.getEntry(nestedArchivePath.get());
+ ZipEntry nestedArchiveEntry = expectedZip.getEntry(nestedArchiveZipEntryPath);
// Get inputstream for entry
InputStream nesterArchiveStream = expectedZip.getInputStream(nestedArchiveEntry);
@@ -127,8 +130,11 @@
// Validate nested archive entries were written out
Path nestedArchiveTwoPath = new BasicPath(NESTED_PATH, NAME_NESTED_ARCHIVE_2);
+ // Get Zip entry path
+ String nestedArchiveTwoZipEntryPath = ZipExporterUtil.toZipEntryPath(nestedArchiveTwoPath);
+
// Get second nested archive entry from exported zip
- ZipEntry nestedArchiveTwoEntry = expectedZip.getEntry(nestedArchiveTwoPath.get());
+ ZipEntry nestedArchiveTwoEntry = expectedZip.getEntry(nestedArchiveTwoZipEntryPath);
// Get inputstream for entry
InputStream nesterArchiveTwoStream = expectedZip.getInputStream(nestedArchiveTwoEntry);
@@ -190,7 +196,8 @@
private void assertAssetInZip(ZipFile expectedZip, Path path, Asset asset) throws IllegalArgumentException,
IOException
{
- ZipEntry entry = expectedZip.getEntry(path.get());
+ String entryPath = ZipExporterUtil.toZipEntryPath(path);
+ ZipEntry entry = expectedZip.getEntry(entryPath);
Assert.assertNotNull(entry);
byte[] expectedContents = IOUtil.asByteArray(asset.getStream());
byte[] actualContents = IOUtil.asByteArray(expectedZip.getInputStream(entry));
More information about the jboss-svn-commits
mailing list