[jboss-svn-commits] JBoss Common SVN: r3859 - in shrinkwrap/trunk: api/src/main/java/org/jboss/shrinkwrap/api/formatter and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 15 13:30:37 EST 2009
Author: ALRubinger
Date: 2009-12-15 13:30:37 -0500 (Tue, 15 Dec 2009)
New Revision: 3859
Added:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatter.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FormattingConstants.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/formatter/
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java
Modified:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archive.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java
Log:
[SHRINKWRAP-107] Allow for custom formatters in Archive.toString (and tests)
Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archive.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archive.java 2009-12-15 16:59:20 UTC (rev 3858)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archive.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -18,6 +18,11 @@
import java.util.Map;
+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
*
@@ -115,7 +120,7 @@
* @return
*/
Map<Path, Asset> getContent();
-
+
/**
* Obtains all assets matching given filter in this archive, along with its respective Path.
* The returned Map will be an immutable view.
@@ -142,7 +147,7 @@
* @throws IllegalArgumentException If the existing archive is not specified
*/
T merge(Archive<?> source) throws IllegalArgumentException;
-
+
/**
* Merge the contents from an existing archive without
* maintaining the archive name in the context path.
@@ -178,14 +183,32 @@
* @throws IllegalArgumentException If the path or existing archive is not specified
*/
T merge(Archive<?> source, Path path, Filter<Path> filter) throws IllegalArgumentException;
+
+ /**
+ * Acts as a shorthand for {@link Archive#toString(Formatter)}
+ * where the {@link SimpleFormatter} is leveraged.
+ *
+ * @return
+ */
+ String toString();
/**
- * Returns a multiline "ls -l"-equse output of the contents of
- * this deployment and (recursively) its children if the verbosity
- * flag is set to "true". Otherwise the no-arg version is invoked
+ * If "true" is specified, acts as a shorthand for {@link Archive#toString(Formatter)}
+ * where the {@link VerboseFormatter} is leveraged. Otherwise the {@link SimpleFormatter}
+ * will be used (equivalent to {@link Archive#toString()}).
*
* @return
*/
String toString(boolean verbose);
+ /**
+ * Returns a view of this {@link Archive} as returned from the
+ * specified {@link Formatter}. Common options may be to use
+ * the predefined formatters located in {@link Formatters}
+ * @param formatter
+ * @return
+ * @throws IllegalArgumentException If the formatter is not specified
+ */
+ String toString(Formatter formatter) throws IllegalArgumentException;
+
}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatter.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatter.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,37 @@
+/*
+ * 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.api.formatter;
+
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * A type capable of formatting an {@link Archive}
+ * into human-readable style.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Formatter
+{
+ /**
+ * Returns a formatted view of the specified archive
+ * @param archive
+ * @return
+ * @throws IllegalArgumentException If the archive is not specified
+ */
+ String format(Archive<?> archive) throws IllegalArgumentException;
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/Formatters.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,71 @@
+/*
+ * 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.api.formatter;
+
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * Available pre-configured {@link Formatter} instances
+ * used in constructing a human-readable form
+ * for a specified {@link Archive}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public enum Formatters implements Formatter {
+
+ //-------------------------------------------------------------------------------------||
+ // Types ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+ VERBOSE(VerboseFormatter.INSTANCE), SIMPLE(SimpleFormatter.INSTANCE);
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal formatter type, used as a delegate to make {@link Formatters} itself a {@link Formatter}
+ */
+ private final Formatter formatter;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a new {@link Formatters} type
+ * using the specfied underlying {@link Formatter}
+ */
+ Formatters(final Formatter formatter)
+ {
+ this.formatter = formatter;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.formatter.Formatter#format(org.jboss.shrinkwrap.api.Archive)
+ */
+ @Override
+ public String format(final Archive<?> archive) throws IllegalArgumentException
+ {
+ return formatter.format(archive);
+ }
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FormattingConstants.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FormattingConstants.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/FormattingConstants.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,41 @@
+/*
+ * 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.api.formatter;
+
+/**
+ * Constants used in the default {@link Formatter} implementations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+interface FormattingConstants
+{
+ /**
+ * Newline character
+ */
+ char NEWLINE = '\n';
+
+ /**
+ * Colon character
+ */
+ char COLON = ':';
+
+ /**
+ * Space character
+ */
+ char SPACE = ' ';
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/SimpleFormatter.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,59 @@
+/*
+ * 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.api.formatter;
+
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * {@link Formatter} implementation to provide a simple, one-line
+ * description of an {@link Archive}, including its name
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public enum SimpleFormatter implements Formatter {
+ INSTANCE;
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * String used to denote assets in the formatted message
+ */
+ private static final String ASSETS = "assets";
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @Override
+ public String format(final Archive<?> archive) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (archive == null)
+ {
+ throw new IllegalArgumentException("archive must be specified");
+ }
+
+ // Format: "name: X assets"
+ return new StringBuilder().append(archive.getName()).append(FormattingConstants.COLON).append(
+ FormattingConstants.SPACE).append(archive.getContent().size()).append(FormattingConstants.SPACE).append(
+ ASSETS).toString();
+ }
+
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/formatter/VerboseFormatter.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,75 @@
+/*
+ * 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.api.formatter;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Path;
+
+/**
+ * {@link Formatter} implementation to provide an "ls -l"-esque
+ * output for an {@link Archive}, listing all internal contents
+ * in sorted order
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public enum VerboseFormatter implements Formatter {
+ INSTANCE;
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @Override
+ public String format(final Archive<?> archive) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (archive == null)
+ {
+ throw new IllegalArgumentException("archive must be specified");
+ }
+
+ // Make a builder
+ final StringBuilder sb = new StringBuilder();
+
+ // Add the name
+ sb.append(archive.getName()).append(FormattingConstants.COLON).append(FormattingConstants.NEWLINE);
+
+ // Sort all paths
+ final List<Path> paths = new ArrayList<Path>(archive.getContent().keySet());
+ Collections.sort(paths);
+ final int numPaths = paths.size();
+ int count = 0;
+ for (final Path path : paths)
+ {
+ count++;
+ sb.append(path.get());
+ if (count != numPaths)
+ {
+ sb.append(FormattingConstants.NEWLINE);
+ }
+ }
+
+ // Return
+ return sb.toString();
+ }
+
+}
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java 2009-12-15 16:59:20 UTC (rev 3858)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/ArchiveBase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -23,11 +23,13 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.api.ExtensionLoader;
import org.jboss.shrinkwrap.api.Filter;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.Path;
-import org.jboss.shrinkwrap.api.Assignable;
+import org.jboss.shrinkwrap.api.formatter.Formatter;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
import org.jboss.shrinkwrap.impl.base.asset.ArchiveAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
@@ -254,7 +256,46 @@
return extensionLoader.load(clazz, this);
}
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.Archive#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return this.toString(Formatters.SIMPLE);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.Archive#toString(boolean)
+ */
+ @Override
+ public String toString(final boolean verbose)
+ {
+ return verbose ? this.toString(Formatters.VERBOSE) : this.toString();
+ }
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.Archive#toString(org.jboss.shrinkwrap.api.formatter.Formatter)
+ */
+ @Override
+ public String toString(final Formatter formatter) throws IllegalArgumentException
+ {
+ // Precondition check
+ if(formatter==null)
+ {
+ throw new IllegalArgumentException("Formatter must be specified");
+ }
+
+ // Delegate
+ return formatter.format(this);
+ }
+
+
+
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java 2009-12-15 16:59:20 UTC (rev 3858)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -16,10 +16,8 @@
*/
package org.jboss.shrinkwrap.impl.base;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
@@ -222,35 +220,6 @@
return filteredContent;
}
- /* {@inheritDoc}
- * @see org.jboss.declarchive.api.Archive#toString(boolean)
- */
- @Override
- public String toString(boolean verbose)
- {
- // If we want verbose output
- if (verbose)
- {
- // Make a builder
- StringBuilder sb = new StringBuilder();
-
- // Add the name
- sb.append(this.getName()).append(COLON).append(NEWLINE);
-
- // Sort all paths
- final List<Path> paths = new ArrayList<Path>(content.keySet());
- Collections.sort(paths);
-
- for (final Path path : paths)
- {
- sb.append(path.get()).append(NEWLINE);
- }
- return sb.toString();
- }
- // Fall back on toString
- return this.toString();
- }
-
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-15 16:59:20 UTC (rev 3858)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -36,6 +36,7 @@
import org.jboss.shrinkwrap.api.container.LibraryContainer;
import org.jboss.shrinkwrap.api.container.ManifestContainer;
import org.jboss.shrinkwrap.api.container.ResourceContainer;
+import org.jboss.shrinkwrap.api.formatter.Formatter;
import org.jboss.shrinkwrap.impl.base.AssignableBase;
import org.jboss.shrinkwrap.impl.base.URLPackageScanner;
import org.jboss.shrinkwrap.impl.base.Validate;
@@ -256,14 +257,35 @@
return archive.getName();
}
- /* (non-Javadoc)
+ /**
+ * {@inheritDoc}
* @see org.jboss.declarchive.api.Archive#toString(boolean)
*/
@Override
- public String toString(boolean verbose)
+ public String toString()
{
+ return archive.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.declarchive.api.Archive#toString(boolean)
+ */
+ @Override
+ public String toString(final boolean verbose)
+ {
return archive.toString(verbose);
}
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.api.Archive#toString(org.jboss.shrinkwrap.api.formatter.Formatter)
+ */
+ @Override
+ public String toString(final Formatter formatter) throws IllegalArgumentException
+ {
+ return archive.toString(formatter);
+ }
//-------------------------------------------------------------------------------------||
// Required Implementations - SpecializedBase -----------------------------------------||
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java 2009-12-15 16:59:20 UTC (rev 3858)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -24,10 +24,11 @@
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.api.ExtensionLoader;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.Paths;
-import org.jboss.shrinkwrap.api.Assignable;
+import org.jboss.shrinkwrap.api.formatter.Formatter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.container.ContainerBase;
import org.jboss.shrinkwrap.impl.base.spec.JavaArchiveImpl;
@@ -172,5 +173,11 @@
{
return Paths.root();
}
+
+ @Override
+ public String toString(final Formatter formatter) throws IllegalArgumentException
+ {
+ return formatter.format(this);
+ }
}
}
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,112 @@
+/*
+ * 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 java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.formatter.Formatter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.test.ArchiveTestBase;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Base support for implementations of {@link Formatter}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class FormatterTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(FormatterTestBase.class.getName());
+
+ /**
+ * Name of the test archive
+ */
+ static final String NAME_ARCHIVE = "testArchive.jar";
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Archive used in testing
+ */
+ private Archive<?> archive;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates the archive used in the test
+ */
+ @Before
+ public void createArchive()
+ {
+ archive = Archives.create(NAME_ARCHIVE, JavaArchive.class).addClasses(FormatterTestBase.class,
+ ArchiveTestBase.class);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the {@link Formatter} is functioning as
+ * contracted given a test archive
+ */
+ @Test
+ public void testFormatter()
+ {
+ // Format
+ final String formatted = archive.toString(getFormatter());
+
+ // Log out, just so we can see
+ log.info(formatted);
+
+ // Ensure expected form
+ TestCase.assertEquals("Formatter output did not match that expected", this.getExpectedOutput(), formatted);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the {@link Formatter} instance to be used for this test
+ */
+ abstract Formatter getFormatter();
+
+ /**
+ * Obtains the output expected of the {@link Formatter} instance returned by {@link FormatterTestBase#getFormatter()}
+ * @return
+ */
+ abstract String getExpectedOutput();
+}
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/SimpleFormatterTestCase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,65 @@
+/*
+ * 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.SimpleFormatter;
+
+/**
+ * Ensures that the {@link SimpleFormatter} is functioning
+ * as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class SimpleFormatterTestCase extends FormatterTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The output expected of the formatter
+ */
+ private static final String EXPECTED_OUTPUT = NAME_ARCHIVE + ": 2 assets";
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.impl.base.formatter.FormatterTestBase#getFormatter()
+ */
+ @Override
+ Formatter getFormatter()
+ {
+ return SimpleFormatter.INSTANCE;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.shrinkwrap.impl.base.formatter.FormatterTestBase#getExpectedOutput()
+ */
+ @Override
+ String getExpectedOutput()
+ {
+ return EXPECTED_OUTPUT;
+ }
+
+}
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/formatter/VerboseFormatterTestCase.java 2009-12-15 18:30:37 UTC (rev 3859)
@@ -0,0 +1,62 @@
+/*
+ * 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.VerboseFormatter;
+
+/**
+ * Ensures that the {@link VerboseFormatter} is functioning
+ * as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VerboseFormatterTestCase extends FormatterTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final String EXPECTED_OUTPUT = NAME_ARCHIVE
+ + ":\n/org/jboss/shrinkwrap/impl/base/formatter/FormatterTestBase.class\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 VerboseFormatter.INSTANCE;
+ }
+
+ /**
+ * {@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