[jboss-svn-commits] JBoss Common SVN: r3828 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Dec 4 11:52:52 EST 2009


Author: ALRubinger
Date: 2009-12-04 11:52:51 -0500 (Fri, 04 Dec 2009)
New Revision: 3828

Removed:
   shrinkwrap/trunk/spi/src/main/java/org/jboss/shrinkwrap/spi/PathProvider.java
Modified:
   shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java
   shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java
   shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/path/BasicPathTestCase.java
Log:
[SHRINKWRAP-95] Move Path.parent() support into ZipExportDelegate; does not need to be exposed further out

Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExportDelegate.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -33,8 +33,8 @@
 import org.jboss.shrinkwrap.impl.base.io.IOUtil;
 import org.jboss.shrinkwrap.impl.base.io.StreamErrorHandler;
 import org.jboss.shrinkwrap.impl.base.io.StreamTask;
+import org.jboss.shrinkwrap.impl.base.path.BasicPath;
 import org.jboss.shrinkwrap.impl.base.path.PathUtil;
-import org.jboss.shrinkwrap.spi.PathProvider;
 
 public class ZipExportDelegate extends AbstractExporterDelegate<InputStream>
 {
@@ -60,7 +60,7 @@
     * ZipOutputStream used to write the zip entries
     */
    private ZipOutputStream zipOutputStream;
-   
+
    /**
     * A Set of Paths we've exported so far (so that we don't write
     * any entries twice)
@@ -126,23 +126,14 @@
       {
          throw new IllegalArgumentException("Path must be specified");
       }
-      
+
       /*
        * SHRINKWRAP-94
        * Add entries for all parents of this Path
        * by recursing first and adding parents that
        * haven't already been written.
        */
-      final Path parent;
-      try
-      {
-         parent = ((PathProvider) path).parent();
-      }
-      catch (final ClassCastException cce)
-      {
-         throw new RuntimeException("Path implementation provided does not implement the SPI "
-               + PathProvider.class.getName(), cce);
-      }
+      final Path parent = getParent(path);
       if (parent != null && !this.pathsExported.contains(parent))
       {
          // Process the parent without any asset (it's a directory)
@@ -154,7 +145,7 @@
       // Get Asset InputStream if the asset is specified (else it's a directory so use null)
       final InputStream assetStream = !isDirectory ? asset.openStream() : null;
       final String pathName = PathUtil.optionallyRemovePrecedingSlash(path.get());
-      
+
       // Make a task for this stream and close when done
       IOUtil.closeOnComplete(assetStream, new StreamTask<InputStream>()
       {
@@ -168,13 +159,13 @@
             {
                resolvedPath = PathUtil.optionallyAppendSlash(resolvedPath);
             }
-            
+
             // Make a ZipEntry
             final ZipEntry entry = new ZipEntry(resolvedPath);
 
             // Write the Asset under the same Path name in the Zip
             zipOutputStream.putNextEntry(entry);
-            
+
             // Mark that we've written this Path 
             pathsExported.add(path);
 
@@ -221,4 +212,37 @@
       return inputStream;
    }
 
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the parent of this Path, if exists, else null.
+    * For instance if the Path is "/my/path", the parent 
+    * will be "/my".  Each call will result in a new object reference,
+    * though subsequent calls upon the same Path will be equal by value.
+    * @return
+    * 
+    * @param path The path whose parent context we should return
+    */
+   static Path getParent(final Path path)
+   {
+      // Precondition checks
+      assert path != null : "Path must be specified";
+
+      // Get the last index of "/"
+      final String resolvedContext = PathUtil.optionallyRemoveFollowingSlash(path.get());
+      final int lastIndex = resolvedContext.lastIndexOf(PathUtil.SLASH);
+      // If it either doesn't occur or is the root
+      if (lastIndex == -1 || (lastIndex == 0 && resolvedContext.length() == 1))
+      {
+         // No parent present, return null
+         return null;
+      }
+      // Get the parent context
+      final String sub = resolvedContext.substring(0, lastIndex);
+      // Return
+      return new BasicPath(sub);
+   }
+
 }

Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -20,7 +20,6 @@
 import java.util.logging.Logger;
 
 import org.jboss.shrinkwrap.api.Path;
-import org.jboss.shrinkwrap.spi.PathProvider;
 
 /**
  * BasicPath
@@ -32,7 +31,7 @@
  * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
  * @version $Revision: $
  */
-public class BasicPath implements PathProvider, Comparable<Path>
+public class BasicPath implements Path, Comparable<Path>
 {
 
    //-------------------------------------------------------------------------------------||
@@ -79,7 +78,7 @@
       if (log.isLoggable(Level.FINER))
       {
          log.finer("Resolved \"" + context + "\" to absolute form: " + resolvedContext);
-      }      
+      }
       this.context = resolvedContext;
    }
 
@@ -150,28 +149,6 @@
       return path.get().compareTo(this.get());
    }
 
-   /**
-    * {@inheritDoc}
-    * @see org.jboss.shrinkwrap.spi.PathProvider#parent()
-    */
-   @Override
-   public Path parent()
-   {
-      // Get the last index of "/"
-      final String resolvedContext = PathUtil.optionallyRemoveFollowingSlash(this.context);
-      final int lastIndex = resolvedContext.lastIndexOf(PathUtil.SLASH);
-      // If it either doesn't occur or is the root
-      if (lastIndex == -1 || (lastIndex == 0 && resolvedContext.length() == 1))
-      {
-         // No parent present, return null
-         return null;
-      }
-      // Get the parent context
-      final String sub = resolvedContext.substring(0, lastIndex);
-      // Return
-      return new BasicPath(sub);
-   }
-
    //-------------------------------------------------------------------------------------||
    // Overridden Implementations ---------------------------------------------------------||
    //-------------------------------------------------------------------------------------||

Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -38,12 +38,12 @@
    /**
     * Slash character
     */
-   static final char SLASH = '/';
+   public static final char SLASH = '/';
 
    /**
     * Empty String
     */
-   static final String EMPTY = "";
+   public static final String EMPTY = "";
 
    //-------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
@@ -67,7 +67,7 @@
     * "base" and context of "context" will
     * result in form "/base/context".
     */
-   static String composeAbsoluteContext(final String base, final String context)
+   public static String composeAbsoluteContext(final String base, final String context)
    {
       // Precondition checks
       assertSpecified(base);
@@ -92,7 +92,7 @@
     * 
     * @param path
     */
-   static String adjustToRelativeDirectoryContext(final String path)
+   public static String adjustToRelativeDirectoryContext(final String path)
    {
       // Return nulls
       if (path == null)
@@ -119,7 +119,7 @@
     * 
     * @param path
     */
-   static String adjustToAbsoluteDirectoryContext(String path)
+   public static String adjustToAbsoluteDirectoryContext(String path)
    {
       // Return nulls
       if (path == null)
@@ -166,7 +166,7 @@
     * @param path
     * @return
     */
-   static String optionallyRemoveFollowingSlash(final String path)
+   public static String optionallyRemoveFollowingSlash(final String path)
    {
       // Precondition check
       assertSpecified(path);
@@ -214,7 +214,7 @@
     * @param path
     * @return
     */
-   static String optionallyPrependSlash(final String path)
+   public static String optionallyPrependSlash(final String path)
    {
       // Adjust null
       String resolved = path;

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ZipExporterTestCase.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -25,6 +25,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import junit.framework.TestCase;
+
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.Asset;
 import org.jboss.shrinkwrap.api.Path;
@@ -84,13 +86,12 @@
       // Validate entries were written out
       assertAssetInZip(expectedZip, PATH_ONE, ASSET_ONE);
       assertAssetInZip(expectedZip, PATH_TWO, ASSET_TWO);
-      
+
       // Validate all paths were written
       // SHRINKWRAP-94
       getEntryFromZip(expectedZip, NESTED_PATH);
    }
 
-
    /**
     * Test to make sue an archive can be exported to Zip and nested archives are also in exported as nested Zip.
     * @throws Exception
@@ -209,7 +210,7 @@
       byte[] actualContents = IOUtil.asByteArray(expectedZip.getInputStream(entry));
       Assert.assertArrayEquals(expectedContents, actualContents);
    }
-   
+
    /**
     * Obtains the entry from the specified ZIP file at the specified Path, ensuring
     * it exists along the way
@@ -240,4 +241,35 @@
       IOUtil.copyWithClose(inputStream, fileOutputStream);
    }
 
+   /**
+    * Ensures the contract of {@link PathProvider#parent()}
+    * is intact
+    */
+   @Test
+   public void testParent()
+   {
+      // Log
+      log.info("testParent");
+
+      // Create new paths
+      final String rootString = "/";
+      final String subpathString = "subpath";
+      final String contextString = "context";
+      final String context2String = "context/";
+      final BasicPath root = new BasicPath(rootString);
+      final BasicPath subpath = new BasicPath(subpathString);
+      final BasicPath context = new BasicPath(subpath, contextString);
+      final BasicPath contextWithFollowingSlash = new BasicPath(subpath, context2String);
+
+      // Test
+      TestCase.assertEquals("The parent of the context path should be equal to the initial subpath", subpath,
+            ZipExportDelegate.getParent(context));
+      TestCase.assertEquals(
+            "The parent of the context path with a following slash should be equal to the initial subpath", subpath,
+            ZipExportDelegate.getParent(contextWithFollowingSlash));
+      TestCase.assertEquals("The parent of the subpath should be the root", root, ZipExportDelegate.getParent(subpath));
+      TestCase.assertNull("The parent of the root should be null", ZipExportDelegate.getParent(root));
+
+   }
+
 }

Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/path/BasicPathTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/path/BasicPathTestCase.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/path/BasicPathTestCase.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -18,10 +18,7 @@
 
 import java.util.logging.Logger;
 
-import junit.framework.TestCase;
-
 import org.jboss.shrinkwrap.api.Path;
-import org.jboss.shrinkwrap.spi.PathProvider;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -252,35 +249,4 @@
       Assert.assertTrue("Paths with different contexts should not be equal by value", !path1.equals(path2));
       log.info(path1 + " not equal by value to " + path2);
    }
-
-   /**
-    * Ensures the contract of {@link PathProvider#parent()}
-    * is intact
-    */
-   @Test
-   public void testParent()
-   {
-      // Log
-      log.info("testParent");
-
-      // Create new paths
-      final String rootString = "/";
-      final String subpathString = "subpath";
-      final String contextString = "context";
-      final String context2String = "context/";
-      final BasicPath root= new BasicPath(rootString);
-      final BasicPath subpath = new BasicPath(subpathString);
-      final BasicPath context = new BasicPath(subpath, contextString);
-      final BasicPath contextWithFollowingSlash = new BasicPath(subpath, context2String);
-
-      // Test
-      TestCase.assertEquals("The parent of the context path should be equal to the initial subpath", subpath, context
-            .parent());
-      TestCase.assertEquals(
-            "The parent of the context path with a following slash should be equal to the initial subpath", subpath,
-            contextWithFollowingSlash.parent());
-      TestCase.assertEquals("The parent of the subpath should be the root", root, subpath.parent());
-      TestCase.assertNull("The parent of the root should be null", root.parent());
-
-   }
 }

Deleted: shrinkwrap/trunk/spi/src/main/java/org/jboss/shrinkwrap/spi/PathProvider.java
===================================================================
--- shrinkwrap/trunk/spi/src/main/java/org/jboss/shrinkwrap/spi/PathProvider.java	2009-12-04 06:00:21 UTC (rev 3827)
+++ shrinkwrap/trunk/spi/src/main/java/org/jboss/shrinkwrap/spi/PathProvider.java	2009-12-04 16:52:51 UTC (rev 3828)
@@ -1,41 +0,0 @@
-/*
- * 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.spi;
-
-import org.jboss.shrinkwrap.api.Path;
-
-/**
- * Service Provider Interface of implementations of a
- * {@link Path}; exposes support that need not be visible to \
- * end users.
- * 
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface PathProvider extends Path
-{
-
-   /**
-    * Obtains the parent of this Path, if exists, else null.
-    * For instance if the Path is "/my/path", the parent 
-    * will be "/my".  Each call will result in a new object reference,
-    * though subsequent calls upon the same Path will be equal by value.
-    * @return
-    */
-   Path parent();
-
-}



More information about the jboss-svn-commits mailing list