Index: api/src/main/java/org/jboss/shrinkwrap/api/ArchiveFactory.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/ArchiveFactory.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/ArchiveFactory.java (working copy)
@@ -20,6 +20,7 @@
*
*
* @author ALR
+ * @author Dan Allen
* @version $Revision: $
*/
public final class ArchiveFactory
@@ -66,30 +67,67 @@
//-------------------------------------------------------------------------------------||
/**
+ * Swapped order of method arguments to allow name to be optional while maintaining
+ * a consistent API.
+ *
+ * @deprecated To be removed before 1.0.0.Final
+ * @see ArchiveFactory#create(Class, String)
+ */
+ public T create(final String archiveName, final Class type)
+ throws IllegalArgumentException
+ {
+ return create(type, archiveName);
+ }
+
+ /**
+ * Creates a new archive of the specified type.
+ *
+ * @param type The {@link Assignable} archive type
+ * @return An {@link Assignable} archive base
+ * @throws IllegalArgumentException If the type is not specified
+ */
+ public T create(final Class type)
+ throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (type == null)
+ {
+ throw new IllegalArgumentException("Type must be specified");
+ }
+
+ final Archive> archive = SecurityActions.newInstance(ARCHIVE_IMPL,
+ new Class>[] { Configuration.class }, new Object[] { configuration },
+ Archive.class);
+ return archive.as(type);
+ }
+
+ /**
* Creates a new archive of the specified type. The archive
* will be be backed by the {@link Configuration}
* specific to this {@link ArchiveFactory}.
*
- * @param archiveName The name of the archive
+ * @param archiveName The (optional) name of the archive
* @return An {@link Assignable} archive base
- * @throws IllegalArgumentException If either argument is not specified
+ * @throws IllegalArgumentException If the type is not specified
*/
- public T create(final String archiveName, final Class type)
+ public T create(final Class type, final String archiveName)
throws IllegalArgumentException
{
// Precondition checks
- if (archiveName == null)
- {
- throw new IllegalArgumentException("ArchiveName must be specified");
- }
if (type == null)
{
throw new IllegalArgumentException("Type must be specified");
}
-
- final Archive> archive = SecurityActions.newInstance(ARCHIVE_IMPL, new Class>[]
- {String.class, Configuration.class}, new Object[]
- {archiveName, configuration}, Archive.class);
+ if (archiveName == null || archiveName.trim().length() == 0)
+ {
+ throw new IllegalArgumentException("ArchiveName must be specified");
+ }
+
+ final Archive> archive = SecurityActions.newInstance(ARCHIVE_IMPL,
+ new Class>[] { String.class, Configuration.class },
+ new Object[] { archiveName, configuration },
+ Archive.class);
return archive.as(type);
}
+
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/spec/WebArchive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/spec/WebArchive.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/spec/WebArchive.java (working copy)
@@ -40,4 +40,5 @@
LibraryContainer,
WebContainer
{
+ public static final String EXTENSION = "war";
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/spec/EnterpriseArchive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/spec/EnterpriseArchive.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/spec/EnterpriseArchive.java (working copy)
@@ -40,5 +40,5 @@
LibraryContainer,
EnterpriseContainer
{
-
+ public static final String EXTENSION = "ear";
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/spec/JavaArchive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/spec/JavaArchive.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/spec/JavaArchive.java (working copy)
@@ -37,4 +37,5 @@
ManifestContainer,
ClassContainer
{
+ public static final String EXTENSION = "jar";
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/spec/ResourceAdapterArchive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/spec/ResourceAdapterArchive.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/spec/ResourceAdapterArchive.java (working copy)
@@ -39,4 +39,5 @@
ResourceContainer,
ResourceAdapterContainer
{
+ public static final String EXTENSION = "rar";
}
Index: api/src/main/java/org/jboss/shrinkwrap/api/Archive.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/Archive.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/Archive.java (working copy)
@@ -42,6 +42,12 @@
String getName();
/**
+ * Obtains the extension for this archive type (i.e., "jar"), which should
+ * be set by the archive implementation
+ */
+ String getExtension();
+
+ /**
* Adds the specified asset under the specified path into the
* target context
*
Index: api/src/main/java/org/jboss/shrinkwrap/api/ShrinkWrap.java
===================================================================
--- api/src/main/java/org/jboss/shrinkwrap/api/ShrinkWrap.java (revision 4330)
+++ api/src/main/java/org/jboss/shrinkwrap/api/ShrinkWrap.java (working copy)
@@ -30,6 +30,7 @@
* {@link ShrinkWrap#createDomain(Configuration)}.
*
* @author ALR
+ * @author Dan Allen
* @version $Revision: $
*/
public final class ShrinkWrap
@@ -121,6 +122,38 @@
}
/**
+ * Swapped order of method arguments to allow name to be optional while maintaining
+ * a consistent API.
+ *
+ * @deprecated To be removed before 1.0.0.Final
+ * @see ShrinkWrap#create(Class, String)
+ */
+ public static T create(final String archiveName, final Class type)
+ throws IllegalArgumentException {
+ return create(type, archiveName);
+ }
+
+ /**
+ * Creates a new archive of the specified type with an auto-generated name.
+ *
+ * @param type The {@link Assignable} archive type
+ * @return An {@link Assignable} archive base
+ * @throws IllegalArgumentException If type is not specified
+ * @see ShrinkWrap#create(Class, String)
+ */
+ public static T create(final Class type)
+ throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (type == null)
+ {
+ throw new IllegalArgumentException("Type must be specified");
+ }
+
+ return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type);
+ }
+
+ /**
* Creates a new archive of the specified type. The archive
* will be be backed by the default {@link Configuration}.
* Invoking this method is functionally equivalent to calling
@@ -130,23 +163,23 @@
*
* @param archiveName The name of the archive
* @return An {@link Assignable} archive base
- * @throws IllegalArgumentException If either argument is not specified
+ * @throws IllegalArgumentException If either type is not specified
*/
- public static T create(final String archiveName, final Class type)
+ public static T create(final Class type, final String archiveName)
throws IllegalArgumentException
{
// Precondition checks
- if (archiveName == null || archiveName.length() == 0)
- {
- throw new IllegalArgumentException("ArchiveName must be specified");
- }
if (type == null)
{
throw new IllegalArgumentException("Type must be specified");
}
+ if (archiveName == null || archiveName.trim().length() == 0)
+ {
+ throw new IllegalArgumentException("ArchiveName must be specified");
+ }
// Delegate to the default domain's archive factory for creation
- return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(archiveName, type);
+ return ShrinkWrap.getDefaultDomain().getArchiveFactory().create(type, archiveName);
}
//-------------------------------------------------------------------------------------||
Index: impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ShrinkWrapTestCase.java
===================================================================
--- impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ShrinkWrapTestCase.java (revision 4330)
+++ impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ShrinkWrapTestCase.java (working copy)
@@ -33,6 +33,7 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.formatter.Formatter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.impl.base.container.ContainerBase;
import org.junit.Test;
@@ -42,6 +43,7 @@
*
* @author ALR
* @author Aslak Knutsen
+ * @author Dan Allen
* @version $Revision: $
*/
public class ShrinkWrapTestCase
@@ -52,18 +54,60 @@
//-------------------------------------------------------------------------------------||
/**
- * Ensures we can create a new archive under the default {@link Domain}
+ * Ensures we can create a new archive under the default {@link Domain} using the deprecated create method
*/
+ @SuppressWarnings("deprecation")
@Test
- public void createNewArchiveUnderDefaultDomain()
+ public void createNewArchiveDeprecatedUnderDefaultDomain()
{
final String archiveName = "test.war";
final JavaArchive archive = ShrinkWrap.create(archiveName, JavaArchive.class);
// Test
Assert.assertNotNull("A archive should have been created", archive);
- Assert.assertEquals("Should have the same name as given imput", archiveName, archive.getName());
+ Assert.assertEquals("Should have the same name as given input", archiveName, archive.getName());
}
+
+ /**
+ * Ensures we can create a new archive under the default {@link Domain}
+ */
+ @Test
+ public void createNewArchiveUnderDefaultDomain()
+ {
+ final String archiveName = "test.war";
+ final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, archiveName);
+
+ // Test
+ Assert.assertNotNull("A archive should have been created", archive);
+ Assert.assertEquals("Should have the same name as given input", archiveName, archive.getName());
+ }
+
+ /**
+ * Ensures we can create a new archive whose extension is automatically appended under the default {@link Domain}
+ */
+ @Test
+ public void createNewArchiveWithAssignedExtensionUnderDefaultDomain()
+ {
+ final String archiveName = "test";
+ final WebArchive archive = ShrinkWrap.create(WebArchive.class, archiveName);
+
+ // Test
+ Assert.assertNotNull("A archive should have been created", archive);
+ Assert.assertEquals("Should have the same name as given input with extension added", archiveName + ".war", archive.getName());
+ }
+
+ /**
+ * Ensures we can create a new archive whose name is defaulted under the default {@link Domain}
+ */
+ @Test
+ public void createNewArchiveWithGeneratedNameUnderDefaultDomain()
+ {
+ final JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
+
+ // Test
+ Assert.assertNotNull("A archive should have been created", archive);
+ Assert.assertTrue("Name should have been generated", archive.getName().startsWith("archive-") && archive.getName().endsWith(".jar"));
+ }
/**
* Ensures that we can create isolated {@link Domain}s
@@ -231,6 +275,12 @@
}
@Override
+ public String getExtension()
+ {
+ return "jar";
+ }
+
+ @Override
protected ArchivePath getClassesPath()
{
return ArchivePaths.root();
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java (working copy)
@@ -26,6 +26,7 @@
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.Assignable;
import org.jboss.shrinkwrap.api.Filter;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.Node;
@@ -96,13 +97,153 @@
// Constructor ------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- protected ContainerBase(Class actualType, Archive> archive)
+ protected ContainerBase(final Class actualType, final Archive> delegate)
{
Validate.notNull(actualType, "ActualType should be specified");
- Validate.notNull(archive, "Archive should be specified");
+ Validate.notNull(delegate, "Archive should be specified");
this.actualType = actualType;
- this.archive = archive;
+ final String name = delegate.getName().lastIndexOf('.') > 0 ? delegate.getName() : delegate.getName() + "." + getExtension();
+ this.archive = new Archive()
+ {
+ @Override
+ public Archive add(Asset asset, ArchivePath target) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target);
+ }
+
+ @Override
+ public Archive add(Asset asset, ArchivePath target, String name) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target, name);
+ }
+
+ @Override
+ public Archive add(Asset asset, String target) throws IllegalArgumentException
+ {
+ return delegate.add(asset, target);
+ }
+
+ @Override
+ public Archive add(Archive archive, ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.add(archive, path);
+ }
+
+ @Override
+ public Archive addDirectories(String... paths) throws IllegalArgumentException
+ {
+ return delegate.addDirectories(paths);
+ }
+
+ @Override
+ public Archive addDirectories(ArchivePath... paths) throws IllegalArgumentException
+ {
+ return delegate.addDirectories(paths);
+ }
+
+ @Override
+ public Archive addDirectory(String path) throws IllegalArgumentException
+ {
+ return delegate.addDirectory(path);
+ }
+
+ @Override
+ public Archive addDirectory(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.addDirectory(path);
+ }
+
+ @Override
+ public boolean contains(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.contains(path);
+ }
+
+ @Override
+ public boolean delete(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.delete(path);
+ }
+
+ @Override
+ public Node get(ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.get(path);
+ }
+
+ @Override
+ public Node get(String path) throws IllegalArgumentException
+ {
+ return delegate.get(path);
+ }
+
+ @Override
+ public Map getContent()
+ {
+ return delegate.getContent();
+ }
+
+ @Override
+ public Map getContent(Filter filter)
+ {
+ return delegate.getContent(filter);
+ }
+
+ @Override
+ public String getExtension()
+ {
+ return ContainerBase.this.getExtension();
+ }
+
+ @Override
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public Archive merge(Archive source) throws IllegalArgumentException
+ {
+ return delegate.merge(source);
+ }
+
+ @Override
+ public Archive merge(Archive source, Filter filter) throws IllegalArgumentException
+ {
+ return delegate.merge(source, filter);
+ }
+
+ @Override
+ public Archive merge(Archive source, ArchivePath path) throws IllegalArgumentException
+ {
+ return delegate.merge(source, path);
+ }
+
+ @Override
+ public Archive merge(Archive source, ArchivePath path, Filter filter) throws IllegalArgumentException
+ {
+ return delegate.merge(source, path, filter);
+ }
+
+ @Override
+ public String toString(boolean verbose)
+ {
+ return delegate.toString(verbose);
+ }
+
+ @Override
+ public String toString(Formatter formatter) throws IllegalArgumentException
+ {
+ return delegate.toString(formatter);
+ }
+
+ @Override
+ public TYPE as(Class clazz)
+ {
+ return delegate.as(clazz);
+ }
+ };
}
//-------------------------------------------------------------------------------------||
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/MemoryMapArchiveBase.java (working copy)
@@ -30,6 +30,7 @@
import org.jboss.shrinkwrap.api.IllegalArchivePathException;
import org.jboss.shrinkwrap.api.Node;
import org.jboss.shrinkwrap.api.Configuration;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.impl.base.asset.ArchiveAsset;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.path.PathUtil;
@@ -76,7 +77,7 @@
*/
public MemoryMapArchiveBase(final Configuration configuration) throws IllegalArgumentException
{
- this("Archive-" + UUID.randomUUID().toString() + ".jar", configuration);
+ this("archive-" + UUID.randomUUID().toString(), configuration);
}
/**
@@ -102,6 +103,11 @@
// Required Implementations - Archive -------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ @Override
+ public String getExtension() {
+ return JavaArchive.EXTENSION;
+ }
+
/**
* {@inheritDoc}
* @see org.jboss.shrinkwrap.api.Archive#add(org.jboss.shrinkwrap.api.Asset, org.jboss.shrinkwrap.api.ArchivePath)
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImpl.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImpl.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImpl.java (working copy)
@@ -87,6 +87,12 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ @Override
+ public String getExtension()
+ {
+ return EXTENSION;
+ }
+
/* (non-Javadoc)
* @see org.jboss.declarchive.impl.base.ContainerBase#getManinfestPath()
*/
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImpl.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImpl.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImpl.java (working copy)
@@ -83,6 +83,12 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ @Override
+ public String getExtension()
+ {
+ return EXTENSION;
+ }
+
/* (non-Javadoc)
* @see org.jboss.declarchive.impl.base.ContainerBase#getLibraryPath()
*/
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImpl.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImpl.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImpl.java (working copy)
@@ -81,6 +81,12 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ @Override
+ public String getExtension()
+ {
+ return EXTENSION;
+ }
+
/* (non-Javadoc)
* @see org.jboss.declarchive.impl.base.ContainerBase#getManinfestPath()
*/
Index: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImpl.java
===================================================================
--- impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImpl.java (revision 4330)
+++ impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImpl.java (working copy)
@@ -73,6 +73,12 @@
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ @Override
+ public String getExtension()
+ {
+ return EXTENSION;
+ }
+
/* (non-Javadoc)
* @see org.jboss.declarchive.impl.base.ContainerBase#getLibraryPath()
*/