[jboss-svn-commits] JBoss Common SVN: r3988 - in shrinkwrap/trunk: impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Feb 5 16:50:22 EST 2010


Author: ALRubinger
Date: 2010-02-05 16:50:21 -0500 (Fri, 05 Feb 2010)
New Revision: 3988

Added:
   shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java
   shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java
Log:
[SHRINKWRAP-97] Applied patch by Jason Porter for Formatters unification and introduction of Formatters.FULL

Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java	                        (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java	2010-02-05 21:50:21 UTC (rev 3988)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.api.formatter;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
+
+/**
+ * {@link Formatter} implementation to provide the full path (including parents) of
+ * all items within the {@link Archive}.
+ */
+enum FullFormatter implements Formatter
+{
+   INSTANCE;
+
+   @Override
+   public String format(final Archive<?> archive) throws IllegalArgumentException
+   {
+      // Start the output with the name of the archive
+      StringBuilder sb = new StringBuilder(archive.getName()).append(FormattingConstants.COLON)
+         .append(FormattingConstants.NEWLINE);
+      SortedSet<String> archiveContents = new TreeSet<String>();
+
+      // I know it's ugly, but we have to do two iterations per entry so we get everything
+      for (ArchivePath path : archive.getContent().keySet())
+      {
+         archiveContents.add(path.get());
+         ArchivePath parentPath = path.getParent();
+
+         while (parentPath != null)
+         {
+            archiveContents.add(parentPath.get());
+            parentPath = parentPath.getParent();
+         }
+      }
+
+      // spit out the correct format now
+      for (String pathEntry : archiveContents)
+      {
+         sb.append(pathEntry).append(FormattingConstants.NEWLINE);
+      }
+      int firstLeadingSlash = sb.indexOf(String.valueOf(FormattingConstants.SLASH));
+      sb.delete(firstLeadingSlash, firstLeadingSlash + 2);
+      sb.deleteCharAt(sb.length() - 1);
+      
+      return sb.toString();
+   }
+}

Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java	                        (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java	2010-02-05 21:50:21 UTC (rev 3988)
@@ -0,0 +1,66 @@
+/*
+ * 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.formatter;
+
+import org.jboss.shrinkwrap.api.formatter.Formatter;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
+
+/**
+ * Ensures that the {@link Formatters.Full} is functioning
+ * as expected.  Added to fix SHRINKWRAP-97.
+ *
+ * @author <a href="mailto:lightguard.jp at gmail.com">Jason Porter</a>
+ * @version $Revision: $
+ */
+public class FullFormatterTestCase extends FormatterTestBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   private static final String EXPECTED_OUTPUT = NAME_ARCHIVE
+      + ":\n/org/\n/org/jboss/\n/org/jboss/shrinkwrap/\n/org/jboss/shrinkwrap/impl/\n/org/jboss/shrinkwrap/impl/base/\n"
+      + "/org/jboss/shrinkwrap/impl/base/formatter/\n/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.class\n"
+      + "/org/jboss/shrinkwrap/impl/base/test/\n/org/jboss/shrinkwrap/impl/base/test/ArchiveTestBase.class";
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    *
+    * @see org.jboss.shrinkwrap.impl.base.formatter.FormatterTestBase#getFormatter()
+    */
+   @Override
+   Formatter getFormatter()
+   {
+      return Formatters.FULL;
+   }
+
+   /**
+    * {@inheritDoc}
+    *
+    * @see org.jboss.shrinkwrap.impl.base.formatter.FormatterTestBase#getExpectedOutput()
+    */
+   @Override
+   String getExpectedOutput()
+   {
+      return EXPECTED_OUTPUT;
+   }
+}



More information about the jboss-svn-commits mailing list