Index: api/src/main/java/org/jboss/shrinkwrap/api/Archive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/Archive.java (revision 3977)
+++ api/src/main/java/org/jboss/shrinkwrap/api/Archive.java Fri Feb 05 00:14:29 MST 2010
@@ -20,8 +20,6 @@
import org.jboss.shrinkwrap.api.formatter.Formatter;
import org.jboss.shrinkwrap.api.formatter.Formatters;
-import org.jboss.shrinkwrap.api.formatter.SimpleFormatter;
-import org.jboss.shrinkwrap.api.formatter.VerboseFormatter;
/**
* Archive
@@ -222,7 +220,7 @@
/**
* Acts as a shorthand for {@link Archive#toString(Formatter)}
- * where the {@link SimpleFormatter} is leveraged.
+ * where the {@link Formatters#SIMPLE} is leveraged.
*
* @return
*/
@@ -230,7 +228,8 @@
/**
* If "true" is specified, acts as a shorthand for {@link Archive#toString(Formatter)}
- * where the {@link VerboseFormatter} is leveraged. Otherwise the {@link SimpleFormatter}
+ * where the {@link Formatters#VERBOSE} is leveraged. Otherwise the
+ * {@link Formatters#SIMPLE}
* will be used (equivalent to {@link Archive#toString()}).
*
* @return
Index: impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java
===================================================================
--- impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java Fri Feb 05 00:10:30 MST 2010
+++ impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FullFormatterTestCase.java Fri Feb 05 00:10:30 MST 2010
@@ -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 Jason Porter
+ * @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;
+ }
+}
Index: api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java (revision 3859)
+++ api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java Thu Feb 04 22:59:06 MST 2010
@@ -31,7 +31,7 @@
//-------------------------------------------------------------------------------------||
// Types ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- VERBOSE(VerboseFormatter.INSTANCE), SIMPLE(SimpleFormatter.INSTANCE);
+ VERBOSE(VerboseFormatter.INSTANCE), SIMPLE(SimpleFormatter.INSTANCE), FULL(FullFormatter.INSTANCE);
//-------------------------------------------------------------------------------------||
// Internal Members -------------------------------------------------------------------||
Index: api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java (revision 3859)
+++ api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java Thu Jan 21 16:27:07 MST 2010
@@ -25,7 +25,7 @@
* @author ALR
* @version $Revision: $
*/
-public enum SimpleFormatter implements Formatter {
+enum SimpleFormatter implements Formatter {
INSTANCE;
//-------------------------------------------------------------------------------------||
Index: api/src/main/java/org/jboss/shrinkwrap/api/ArchivePath.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/ArchivePath.java (revision 3931)
+++ api/src/main/java/org/jboss/shrinkwrap/api/ArchivePath.java Thu Feb 04 16:58:29 MST 2010
@@ -31,4 +31,13 @@
* @return
*/
String get();
+
+ /**
+ * 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
+ */
+ ArchivePath getParent();
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java (revision 3931)
+++ api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java Thu Jan 21 16:27:07 MST 2010
@@ -31,7 +31,7 @@
* @author ALR
* @version $Revision: $
*/
-public enum VerboseFormatter implements Formatter {
+enum VerboseFormatter implements Formatter {
INSTANCE;
//-------------------------------------------------------------------------------------||
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java (revision 3945)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/exporter/JdkZipExporterDelegate.java Thu Feb 04 23:06:42 MST 2010
@@ -232,12 +232,12 @@
* by recursing first and adding parents that
* haven't already been written.
*/
- final ArchivePath parent = PathUtil.getParent(path);
+ final ArchivePath parent = path.getParent();
if (parent != null && !this.pathsExported.contains(parent))
{
// If this is not the root
// SHRINKWRAP-96
- final ArchivePath grandParent = PathUtil.getParent(parent);
+ final ArchivePath grandParent = parent.getParent();
final boolean isRoot = grandParent == null;
if (!isRoot)
{
@@ -355,7 +355,7 @@
private boolean isParentOfSpecifiedHierarchy(final ArchivePath path, final ArchivePath compare)
{
// If we've reached the root, we're not a parent of any paths already exported
- final ArchivePath parent = PathUtil.getParent(compare);
+ final ArchivePath parent = compare.getParent();
if (parent == null)
{
return false;
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java (revision 3931)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/BasicPath.java Thu Feb 04 17:03:40 MST 2010
@@ -134,6 +134,16 @@
/**
* {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.ArchivePath#getParent()
+ */
+ @Override
+ public ArchivePath getParent()
+ {
+ return PathUtil.getParent(this);
+ }
+
+ /**
+ * {@inheritDoc}
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
Index: api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java Thu Feb 04 23:44:36 MST 2010
+++ api/src/main/java/org/jboss/shrinkwrap/api/formatter/FullFormatter.java Thu Feb 04 23:44:36 MST 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.Collections;
+import java.util.HashSet;
+import java.util.Set;
+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
+ {
+ StringBuilder sb = new StringBuilder(archive.getName()).append(FormattingConstants.COLON)
+ .append(FormattingConstants.NEWLINE);
+ SortedSet archiveContents = new TreeSet();
+
+ // 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("/");
+ sb.delete(firstLeadingSlash, firstLeadingSlash + 2);
+ sb.deleteCharAt(sb.length() - 1);
+
+ return sb.toString();
+ }
+}
Index: impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java
===================================================================
--- impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java (revision 3859)
+++ impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java Fri Feb 05 00:02:45 MST 2010
@@ -17,10 +17,10 @@
package org.jboss.shrinkwrap.impl.base.formatter;
import org.jboss.shrinkwrap.api.formatter.Formatter;
-import org.jboss.shrinkwrap.api.formatter.VerboseFormatter;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
/**
- * Ensures that the {@link VerboseFormatter} is functioning
+ * Ensures that the {@link Formatters.VERBOSE} is functioning
* as expected
*
* @author ALR
@@ -47,7 +47,7 @@
@Override
Formatter getFormatter()
{
- return VerboseFormatter.INSTANCE;
+ return Formatters.VERBOSE;
}
/**
Index: impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java
===================================================================
--- impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java (revision 3859)
+++ impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java Thu Feb 04 22:47:27 MST 2010
@@ -17,10 +17,10 @@
package org.jboss.shrinkwrap.impl.base.formatter;
import org.jboss.shrinkwrap.api.formatter.Formatter;
-import org.jboss.shrinkwrap.api.formatter.SimpleFormatter;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
/**
- * Ensures that the {@link SimpleFormatter} is functioning
+ * Ensures that the {@link Formatters.SIMPLE} is functioning
* as expected
*
* @author ALR
@@ -49,7 +49,7 @@
@Override
Formatter getFormatter()
{
- return SimpleFormatter.INSTANCE;
+ return Formatters.SIMPLE;
}
/**
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java (revision 3931)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/path/PathUtil.java Thu Feb 04 17:03:40 MST 2010
@@ -235,17 +235,17 @@
// Return as-is
return resolved;
}
-
+
/**
* Obtains the parent of this Path, if exists, else null.
- * For instance if the Path is "/my/path", the parent
+ * 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
*/
- public static ArchivePath getParent(final ArchivePath path)
+ static ArchivePath getParent(final ArchivePath path)
{
// Precondition checks
assert path != null : "Path must be specified";