[jboss-svn-commits] JBoss Common SVN: r3477 - in declarchive/trunk: api/src/main/java/org/jboss/declarchive/api/spec and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 24 13:27:05 EDT 2009
Author: aslak
Date: 2009-08-24 13:27:05 -0400 (Mon, 24 Aug 2009)
New Revision: 3477
Added:
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ContainerBase.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseContainerBase.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebContainerBase.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/asset/AssetUtil.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImpl.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImpl.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/WebArchiveImpl.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/asset/AssetUtilTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImplTest.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImplTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/WebArchiveImplTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/donotchange/
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/donotchange/DummyClassUsedForClassResourceTest.java
Modified:
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ClassContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/EnterpriseContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/LibraryContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ManifestContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ResourceContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/WebContainer.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/spec/JavaArchive.java
Log:
TMPARCH-6
- Updated javadoc linking on *Containers
- Added new EnterpriseContainer methods for modules
- Added ContainerBase/WebContainerBase/EnterpriseContainerBase to simplify extensions
- Added JavaArchive/WebArchive/EnterpriseArchive interfaces with impl
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ClassContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ClassContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ClassContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -24,7 +24,7 @@
* Defines the contract for a component capable of storing
* Java Classes.
* <br/><br/>
- * The actual path to the Class resources within the Archive
+ * The actual path to the {@link Class} resources within the {@link Archive}
* is up to the implementations/specifications.
*
* @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
@@ -37,21 +37,21 @@
//-------------------------------------------------------------------------------------||
/**
- * Adds the specified Classes to the archive.
+ * Adds the specified Classes to the {@link Archive}.
*
- * @param classes
+ * @param classes The classes to add to the Archive
* @return This virtual archive
* @throws IllegalArgumentException If no classes were specified
*/
- T add(Class<?>... classes) throws IllegalArgumentException;
+ T addClasses(Class<?>... classes) throws IllegalArgumentException;
/**
- * Adds all classes in the specified Packages to the archive.
+ * Adds all classes in the specified {@link Package}s to the {@link Archive}.
*
- * @param recursive Should the packages be added recursively
+ * @param recursive Should the sub packages be added
* @param packages All the packages to add
* @return This virtual archive
* @throws IllegalArgumentException If no packages were specified
*/
- T add(boolean recursive, Package... packages) throws IllegalArgumentException;
+ T addPackages(boolean recursive, Package... packages) throws IllegalArgumentException;
}
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/EnterpriseContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/EnterpriseContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/EnterpriseContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -25,7 +25,7 @@
* Defines the contract for a component capable of storing
* Enterprise related resources.
* <br/><br/>
- * The actual path to the Enterprise resources within the Archive
+ * The actual path to the Enterprise resources within the {@link Archive}
* is up to the implementations/specifications.
*
* @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
@@ -38,50 +38,72 @@
//-------------------------------------------------------------------------------------||
/**
- * Adds a resource to this Archive as application.xml.
+ * Adds a resource to this {@link Archive}s as application.xml.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" could be placed in
* "/META-INF/application.xml"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
T setApplicationXML(String resourceName) throws IllegalArgumentException;
/**
- * Adds a resource to this Archives application context.
+ * Adds a resource to this {@link Archive}s application context.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" could be placed in
* "/META-INF/test/example.xml"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
T addApplicationResource(String resourceName) throws IllegalArgumentException;
/**
- * Adds a resource to this Archives application context.
+ * Adds a resource to this {@link Archive}s application context.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" and a
* target of "example/myexample.xml" could be placed in
* "/META-INF/example/myexample.xml"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @param newName New name of the resource in the container
* @return This virtual archive
* @throws IllegalArgumentException if target is null
* @throws IllegalArgumentException if resourceName is null
*/
T addApplicationResource(Path target, String resourceName) throws IllegalArgumentException;
+
+ /**
+ * Adds a archive to this {@link Archive}s module context.
+ * <br/><br/>
+ * The {@link Archive} name is used as path.
+ *
+ * @param archive The archive to use
+ * @return This virtual archive
+ * @throws IllegalArgumentException if archive is null
+ */
+ T addModule(Archive<?> archive) throws IllegalArgumentException;
+
+ /**
+ * Adds a resource to this {@link Archive}s module context.
+ * <br/><br/>
+ * The resource name is used as path.
+ *
+ * @param resourceName
+ * @return This virtual archive
+ * @throws IllegalArgumentException if resourceName is null
+ */
+ T addModule(String resourceName);
}
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/LibraryContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/LibraryContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/LibraryContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -25,7 +25,7 @@
* Defines the contract for a component capable of storing
* Libraries.
* <br/><br/>
- * The actual path to the Library resources within the Archive
+ * The actual path to the Library resources within the {@link Archive}
* is up to the implementations/specifications.
*
* @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
@@ -41,14 +41,14 @@
* Adds the resource with the specified name
* as a library to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation. The resource will be placed into
* the Container Library path under the same context from which it was retrieved.
* <br/>
* For instance a resourceName of "test/library.jar" could be placed
* "/lib/test/library.jar".
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
@@ -58,7 +58,7 @@
* Adds the resource with the specified name
* as a library to the container under the target path, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation. The resource will be placed into
* the Containers Library path under the relative target path.
* <br/>
@@ -66,7 +66,7 @@
* "/lib/test/example.jar".
*
* @param target New name of the resource in the container
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if target is null
* @throws IllegalArgumentException if resourceName is null
@@ -74,14 +74,14 @@
T addLibrary(Path target, String resourceName) throws IllegalArgumentException;
/**
- * Add another Archive<?> to this Archive as a Library.
+ * Add another {@link Archive} to this {@link Archive} as a Library.
* <br/><br/>
* For instance a Archive with name 'example.jar' could be placed in
* "/lib/example.jar".
*
- * @param archive The Archive to be added to the Library path
+ * @param archive The {@link Archive} to be added to the Library path
* @return This virtual archive
- * @throws IllegalArgumentException if Archive is null
+ * @throws IllegalArgumentException if {@link Archive} is null
*/
T addLibrary(Archive<?> archive) throws IllegalArgumentException;
}
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ManifestContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ManifestContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ManifestContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -25,7 +25,7 @@
* Defines the contract for a component capable of storing
* Manifest related resources.
* <br/><br/>
- * The actual path to the Manifest resources within the Archive
+ * The actual path to the Manifest resources within the {@link Archive}
* is up to the implementations/specifications.
*
* @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
@@ -39,15 +39,15 @@
//-------------------------------------------------------------------------------------||
/**
- * Adds a resource to this Archive as MEANIFEST.MF.
+ * Adds a resource to this {@link Archive} as MEANIFEST.MF.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.txt" could be placed in
* "/META-INF/MANIFEST.MF"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
@@ -57,30 +57,30 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" could be placed in
* "/META-INF/test/example.xml"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
T addManifestResource(String resourceName) throws IllegalArgumentException;
-
+
/**
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/library.xml" and target of "/test/example.xml" could be placed in
* "/META-INF/test/example.xml".
*
* @param target The target relative to Manifest path within the archive into which we'll place the resource
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if target is null
* @throws IllegalArgumentException if resourceName is null
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ResourceContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ResourceContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/ResourceContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -25,9 +25,9 @@
* ResourceContainer
*
* Defines the contract for a component capable of storing
- * a series of ClassLoader resources
+ * a series of {@link ClassLoader} resources
* <br/><br/>
- * The actual path to the Resources within the Archive
+ * The actual path to the Resources within the {@link Archive}
* is up to the implementations/specifications.
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
@@ -44,14 +44,14 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation. The resource will be placed into
* the Container under the same context from which it was retrieved.
* <br/>
* For instance a resourceName of "META-INF/resource.xml" will be placed
* at the same location within the Container.
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException If the name is null
*/
@@ -61,13 +61,13 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation. The resource will be placed into
* the Container under the same context specified by
* "target"
*
* @param target The target within the archive into which we'll place the resource
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException If the target is null
* @throws IllegalArgumentException If the resourceName is null
@@ -78,13 +78,13 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation. The resource will be placed into
* the Container under the same context specified by
* "target"
*
* @param target The target within the archive into which we'll place the resource
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException If the target is null
* @throws IllegalArgumentException If the resourceName is null
@@ -92,7 +92,7 @@
T addResource(String target, String resourceName) throws IllegalArgumentException;
/**
- * Adds the specified resource to the archive, using the specified ClassLoader
+ * Adds the specified resource to the {@link Archive}, using the specified {@link ClassLoader}
* to load the resource
*
* @param target The target within the archive into which we'll place the resource
@@ -106,26 +106,26 @@
T addResource(Path target, String resourceName, ClassLoader classLoader) throws IllegalArgumentException;
/**
- * Adds the resource located at the specified URL to the archive. The
+ * Adds the resource located at the specified {@link URL} to the {@link Archive}. The
* location within the archive will be equal to the path portion of the
- * specified URL.
+ * specified {@link URL}.
*
- * @param location The location of the resource to load
+ * @param resource The location of the resource to load
* @return This virtual archive
* @throws IllegalArgumentException If the location is null
*/
- T addResource(URL location) throws IllegalArgumentException;
+ T addResource(URL resource) throws IllegalArgumentException;
/**
- * Adds the resource located at the specified URL to
+ * Adds the resource located at the specified {@link URL} to
* the archive at the specified path.
*
* @param newtarget The target within the archive into which we'll place the resource
- * @param location The location of the resource to load
+ * @param resource The location of the resource to load
* @return This virtual archive
* @throws IllegalArgumentException If the target is null
* @throws IllegalArgumentException If the location is null
*/
- T addResource(Path target, URL location) throws IllegalArgumentException;
+ T addResource(Path target, URL resource) throws IllegalArgumentException;
}
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/WebContainer.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/WebContainer.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/container/WebContainer.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -41,13 +41,13 @@
/**
* Adds a resource to this Archive as web.xml.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" could be placed in
* "/WEB-INF/web.xml"
*
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if resourceName is null
*/
@@ -57,7 +57,7 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/example.xml" could be placed in
@@ -73,14 +73,14 @@
* Adds the resource with the specified name
* to the container, returning the container itself.
* <br/><br/>
- * The ClassLoader used to obtain the resource is up to
+ * The {@link ClassLoader} used to obtain the resource is up to
* the implementation.
* <br/>
* For instance a resourceName of "test/library.xml" and target of "/test/example.xml" could be placed in
* "/lib/test/example.xml".
*
* @param target The target relative to Manifest path within the archive into which we'll place the resource
- * @param resourceName Name of the ClassLoader resource to add
+ * @param resourceName Name of the {@link ClassLoader} resource to add
* @return This virtual archive
* @throws IllegalArgumentException if target is null
* @throws IllegalArgumentException if resourceName is null
Modified: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/spec/JavaArchive.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/spec/JavaArchive.java 2009-08-23 18:18:47 UTC (rev 3476)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/spec/JavaArchive.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -24,7 +24,7 @@
/**
* JavaArchive
*
- * Traditional JAR (Java ARchive) structure. Used in
+ * Traditional JAR (Java Archive) structure. Used in
* construction of libraries and applications.
*
* @see http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ContainerBase.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ContainerBase.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/ContainerBase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,492 @@
+/*
+ * 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.declarchive.impl.base;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Asset;
+import org.jboss.declarchive.api.AssetNotFoundException;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.container.ClassContainer;
+import org.jboss.declarchive.api.container.LibraryContainer;
+import org.jboss.declarchive.api.container.ManifestContainer;
+import org.jboss.declarchive.api.container.ResourceContainer;
+import org.jboss.declarchive.impl.base.asset.AssetUtil;
+import org.jboss.declarchive.impl.base.asset.ClassAsset;
+import org.jboss.declarchive.impl.base.asset.ClassLoaderAsset;
+import org.jboss.declarchive.impl.base.asset.UrlAsset;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * ContainerSupport
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <T>
+ */
+public abstract class ContainerBase<T extends Archive<T>> implements
+ Archive<T>, ManifestContainer<T>, ResourceContainer<T>, ClassContainer<T>, LibraryContainer<T>
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ContainerBase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The backing storage engine.
+ */
+ private final Archive<?> archive;
+
+ /**
+ * The exposed archive type.
+ */
+ private final Class<T> actualType;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ protected ContainerBase(Class<T> actualType, Archive<?> archive)
+ {
+ Validate.notNull(actualType, "ActualType should be specified");
+ Validate.notNull(archive, "Archive should be specified");
+
+ this.actualType = actualType;
+ this.archive = archive;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - Archive Delegation --------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Resource[])
+ */
+// @Override
+// public T add(Asset... assets)
+// {
+// archive.add(assets);
+// return covarientReturn();
+// }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, org.jboss.declarchive.api.Asset[])
+ */
+// @Override
+// public T add(Path path, Asset... assets)
+// {
+// archive.add(path, assets);
+// return covarientReturn();
+// }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, org.jboss.declarchive.api.Archive)
+ */
+ @Override
+ public T add(Path path, Archive<?> archive)
+ {
+ this.archive.add(path, archive);
+ return covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, org.jboss.declarchive.api.Asset)
+ */
+ @Override
+ public T add(Path target, Asset asset) throws IllegalArgumentException
+ {
+ archive.add(target, asset);
+ return covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(org.jboss.declarchive.api.Path, java.lang.String, org.jboss.declarchive.api.Asset)
+ */
+ @Override
+ public T add(Path path, String name, Asset asset)
+ {
+ archive.add(path, name, asset);
+ return covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#addContents(org.jboss.declarchive.api.Archive)
+ */
+ @Override
+ public T addContents(Archive<?> source) throws IllegalArgumentException
+ {
+ archive.addContents(source);
+ return covarientReturn();
+ }
+
+ @Override
+ public T addContents(Path path, Archive<?> source) throws IllegalArgumentException
+ {
+ archive.addContents(path, source);
+ return covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#add(java.lang.String, org.jboss.declarchive.api.Asset)
+ */
+ @Override
+ public T add(String name, Asset asset)
+ {
+ archive.add(name, asset);
+ return covarientReturn();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#contains(org.jboss.declarchive.api.Path)
+ */
+ @Override
+ public boolean contains(Path path)
+ {
+ return archive.contains(path);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#delete(org.jboss.declarchive.api.Path)
+ */
+ @Override
+ public boolean delete(Path path)
+ {
+ return archive.delete(path);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#get(org.jboss.declarchive.api.Path)
+ */
+ @Override
+ public Asset get(Path path)
+ {
+ return archive.get(path);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#get(java.lang.String)
+ */
+ @Override
+ public Asset get(String path) throws AssetNotFoundException, IllegalArgumentException
+ {
+ return get(new BasicPath(path));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#getContent()
+ */
+ @Override
+ public Map<Path, Asset> getContent()
+ {
+ return archive.getContent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return archive.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.Archive#toString(boolean)
+ */
+ @Override
+ public String toString(boolean verbose)
+ {
+ return archive.toString(verbose);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - ManifestContainer ---------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Manifest related
+ * resources.
+ *
+ * @return Base Path for the ManifestContainer resources
+ */
+ protected abstract Path getManinfestPath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ManifestContainer#setManifest(java.lang.String)
+ */
+ @Override
+ public final T setManifest(String resourceName)
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ return add(getManinfestPath(), "MANIFEST.MF", new ClassLoaderAsset(resourceName));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ManifestContainer#addManifestResource(java.lang.String)
+ */
+ @Override
+ public final T addManifestResource(String resourceName)
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ // create the Asset
+ Asset asset = new ClassLoaderAsset(resourceName);
+ // relocate the asset, sub path to the container.
+ Path location = new BasicPath(getManinfestPath(), resourceName);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ManifestContainer#addManifestResource(org.jboss.declarchive.api.Path, java.lang.String)
+ */
+ @Override
+ public T addManifestResource(Path target, String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target should be specified");
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getManinfestPath(), target);
+ return add(location, asset);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - ResourceContainer ---------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Resource related
+ * resources.
+ *
+ * @return Base Path for the ResourceContainer resources
+ */
+ protected abstract Path getResourcePath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String)
+ */
+ @Override
+ public final T addResource(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getResourcePath(), resourceName);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.lang.String, java.lang.String)
+ */
+ @Override
+ public final T addResource(String resourceName, String newName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+ Validate.notNull(newName, "NewName should be specified");
+
+ Asset resource = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getResourcePath(), AssetUtil.getPathForClassloaderResource(resourceName));
+ return add(location, newName, resource);
+ };
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(org.jboss.declarchive.api.Path, java.lang.String)
+ */
+ @Override
+ public T addResource(Path target, String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target should be specified");
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getResourcePath(), target);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(org.jboss.declarchive.api.Path, java.lang.String, java.lang.ClassLoader)
+ */
+ @Override
+ public T addResource(Path target, String resourceName, ClassLoader classLoader) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target should be specified");
+ Validate.notNull(resourceName, "ResourceName should be specified");
+ Validate.notNull(classLoader, "ClassLoader should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName, classLoader);
+ Path location = new BasicPath(getResourcePath(), target);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(org.jboss.declarchive.api.Path, java.net.URL)
+ */
+ @Override
+ public T addResource(Path target, URL resource) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target should be specified");
+ Validate.notNull(resource, "Resource should be specified");
+
+ Asset asset = new UrlAsset(resource);
+ Path location = new BasicPath(getResourcePath(), target);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ResourceContainer#addResource(java.net.URL)
+ */
+ @Override
+ public T addResource(URL resource) throws IllegalArgumentException
+ {
+ Validate.notNull(resource, "Location should be specified");
+
+ Asset asset = new UrlAsset(resource);
+ Path location = new BasicPath(getResourcePath(), AssetUtil.getFullPathForURLResource(resource));
+ return add(location, asset);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - ClassContainer ------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Class related
+ * resources.
+ *
+ * @return Base Path for the ClassContainer resources
+ */
+ protected abstract Path getClassesPath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ClassContainer#addClasses(java.lang.Class<?>[])
+ */
+ public T addClasses(Class<?>... classes) throws IllegalArgumentException
+ {
+ Validate.notNull(classes, "Classes must be specified");
+
+ for(Class<?> clazz : classes)
+ {
+ Asset resource = new ClassAsset(clazz);
+ Path location = new BasicPath(getClassesPath(), AssetUtil.getFullPathForClassResource(clazz));
+ add(location, resource);
+ }
+ return covarientReturn();
+ };
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.ClassContainer#addPackages(boolean, java.lang.Package[])
+ */
+ @Override
+ public T addPackages(boolean recursive, Package... packages) throws IllegalArgumentException
+ {
+ Validate.notNull(packages, "Packages must be specified");
+
+ for(Package pack : packages)
+ {
+ URLPackageScanner scanner = new URLPackageScanner(
+ pack, recursive, Thread.currentThread().getContextClassLoader());
+ Set<Class<?>> classes = scanner.getClasses();
+ for(Class<?> clazz : classes)
+ {
+ Asset asset = new ClassAsset(clazz);
+ Path location = new BasicPath(getClassesPath(), AssetUtil.getFullPathForClassResource(clazz));
+ add(location, asset);
+ }
+ }
+ return covarientReturn();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - LibraryContainer ----------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Library related
+ * resources.
+ *
+ * @return Base Path for the LibraryContainer resources
+ */
+ public abstract Path getLibraryPath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.LibraryContainer#addLibrary(org.jboss.declarchive.api.Archive)
+ */
+ public T addLibrary(Archive<?> archive) throws IllegalArgumentException
+ {
+ Validate.notNull(archive, "Archive must be specified");
+
+ Map<Path, Asset> content = archive.getContent();
+ for(Map.Entry<Path, Asset> entry : content.entrySet())
+ {
+ Path location = new BasicPath(getLibraryPath(), entry.getKey());
+ add(location, entry.getValue());
+ }
+ return covarientReturn();
+ };
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.LibraryContainer#addLibrary(java.lang.String)
+ */
+ @Override
+ public T addLibrary(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName must be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getLibraryPath(), resourceName);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.LibraryContainer#addLibrary(org.jboss.declarchive.api.Path, java.lang.String)
+ */
+ @Override
+ public T addLibrary(Path target, String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target must be specified");
+ Validate.notNull(resourceName, "ResourceName must be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getLibraryPath(), target);
+ return add(location, asset);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ protected T covarientReturn()
+ {
+ return getActualClass().cast(this);
+ }
+
+ protected Class<T> getActualClass()
+ {
+ return this.actualType;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseContainerBase.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseContainerBase.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseContainerBase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,138 @@
+/*
+ * 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.declarchive.impl.base;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Asset;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.container.EnterpriseContainer;
+import org.jboss.declarchive.impl.base.asset.AssetUtil;
+import org.jboss.declarchive.impl.base.asset.ClassLoaderAsset;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * EnterpriseContainerSupport
+ *
+ * Abstract class that helps implement the EnterpriseContainer.
+ * Used by specs that extends the EnterpriseContainer.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <T>
+ */
+public abstract class EnterpriseContainerBase<T extends Archive<T>>
+ extends ContainerBase<T>
+ implements EnterpriseContainer<T>
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(EnterpriseContainerBase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ protected EnterpriseContainerBase(Class<T> actualType, Archive<?> archive)
+ {
+ super(actualType, archive);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - EnterpriseContainer - Resources -------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Application related
+ * resources.
+ *
+ * @return Base Path for the EnterpriseContainer application resources
+ */
+ protected abstract Path getApplicationPath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.EnterpriseContainer#setApplicationXML(java.lang.String)
+ */
+ @Override
+ public T setApplicationXML(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName must be specified");
+ return add(getApplicationPath(), "application.xml", new ClassLoaderAsset(resourceName));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.EnterpriseContainer#addApplicationResource(org.jboss.declarchive.api.Path, java.lang.String)
+ */
+ @Override
+ public T addApplicationResource(Path target, String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target must be specified");
+ Validate.notNull(resourceName, "ResourceName must be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getApplicationPath(), target);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.EnterpriseContainer#addApplicationResource(java.lang.String)
+ */
+ @Override
+ public T addApplicationResource(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName must be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getApplicationPath(), resourceName);
+ return add(location, asset);
+ }
+
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - EnterpriseContainer - Modules ---------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Module related
+ * resources.
+ *
+ * @return Base Path for the EnterpriseContainer module resources
+ */
+ protected abstract Path getModulePath();
+
+ @Override
+ public T addModule(Archive<?> archive) throws IllegalArgumentException
+ {
+ Validate.notNull(archive, "Archive must be specified");
+
+ Path location = getModulePath();
+ return add(location, archive);
+ }
+
+ @Override
+ public T addModule(String resourceName)
+ {
+ Validate.notNull(resourceName, "ResourceName must be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getModulePath(), AssetUtil.getNameForClassloaderResource(resourceName));
+ return add(location, asset);
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/URLPackageScanner.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,175 @@
+/*
+ * 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.declarchive.impl.base;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLDecoder;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+/**
+ * Implementation of scanner which can scan a {@link URLClassLoader}
+ *
+ * @author Thomas Heute
+ * @author Gavin King
+ * @author Norman Richards
+ * @author Pete Muir
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ */
+public class URLPackageScanner
+{
+
+ private static final Logger log = Logger.getLogger(URLPackageScanner.class.getName());
+
+ private final String packageName;
+
+ private final String packageNamePath;
+
+ private final boolean addRecursively;
+
+ private final ClassLoader classLoader;
+
+ private final Set<Class<?>> classes = new HashSet<Class<?>>();
+
+ public URLPackageScanner(Package pkg, boolean addRecursively, ClassLoader classLoader)
+ {
+ this(pkg.getName(), addRecursively, classLoader);
+ }
+
+ public URLPackageScanner(String packageName, boolean addRecursively, ClassLoader classLoader)
+ {
+ Validate.notNull(packageName, "PackageName must be specified");
+ Validate.notNull(addRecursively, "AddRecursively must be specified");
+ Validate.notNull(classLoader, "ClassLoader must be specified");
+
+ this.packageName = packageName;
+ this.packageNamePath = packageName.replace(".", "/");
+ this.addRecursively = addRecursively;
+ this.classLoader = classLoader;
+ }
+
+ private void scanPackage()
+ {
+ try
+ {
+ Set<String> paths = new HashSet<String>();
+
+ for (URL url : loadResources(packageNamePath))
+ {
+ String urlPath = url.getFile();
+ urlPath = URLDecoder.decode(urlPath, "UTF-8");
+ if (urlPath.startsWith("file:"))
+ {
+ urlPath = urlPath.substring(5);
+ }
+ if (urlPath.indexOf('!') > 0)
+ {
+ urlPath = urlPath.substring(0, urlPath.indexOf('!'));
+ }
+ paths.add(urlPath);
+ }
+ handle(paths);
+ }
+ catch (IOException ioe)
+ {
+ log.log(Level.WARNING, "could not read: " + packageName, ioe);
+ }
+ catch (ClassNotFoundException ioe)
+ {
+ log.log(Level.WARNING, "Class coud not be loaded in package: " + packageName, ioe);
+ }
+ }
+
+ private void handleArchiveByFile(File file) throws IOException, ClassNotFoundException
+ {
+ try
+ {
+ log.fine("archive: " + file);
+ ZipFile zip = new ZipFile(file);
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while (entries.hasMoreElements())
+ {
+ ZipEntry entry = entries.nextElement();
+ String name = entry.getName();
+ if (name.startsWith(packageNamePath) && name.endsWith(".class")
+ && (addRecursively || !name.substring(packageNamePath.length() + 1).contains("/")))
+ {
+ String className = name.replace("/", ".").replace(".class", "");
+ classes.add(classLoader.loadClass(className));
+ }
+ }
+ }
+ catch (ZipException e)
+ {
+ throw new RuntimeException("Error handling file " + file, e);
+ }
+ }
+
+ private void handle(Set<String> paths) throws IOException, ClassNotFoundException
+ {
+ for (String urlPath : paths)
+ {
+ log.fine("scanning: " + urlPath);
+ File file = new File(urlPath);
+ if (file.isDirectory())
+ {
+ handle(file, packageName);
+ }
+ else
+ {
+ handleArchiveByFile(file);
+ }
+ }
+ }
+
+ private void handle(File file, String packageName) throws ClassNotFoundException
+ {
+ for (File child : file.listFiles())
+ {
+ if (!child.isDirectory() && child.getName().endsWith(".class"))
+ {
+ classes.add(classLoader.loadClass(packageName + "." + child.getName().substring(0, child.getName().lastIndexOf(".class"))));
+ }
+ else if (child.isDirectory() && addRecursively)
+ {
+ handle(child, packageName + "." + child.getName());
+ }
+ }
+ }
+
+ public List<URL> loadResources(String name) throws IOException
+ {
+ return Collections.list(classLoader.getResources(name));
+ }
+
+ public Set<Class<?>> getClasses()
+ {
+ scanPackage();
+ return classes;
+ }
+}
\ No newline at end of file
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebContainerBase.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebContainerBase.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebContainerBase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,106 @@
+/*
+ * 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.declarchive.impl.base;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Asset;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.container.WebContainer;
+import org.jboss.declarchive.impl.base.asset.ClassLoaderAsset;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * WebContainerSupport
+ *
+ * Abstract class that helps implement the WebContainer.
+ * Used by specs that extends the WebContainer.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ * @param <T>
+ */
+public abstract class WebContainerBase<T extends Archive<T>>
+ extends ContainerBase<T>
+ implements WebContainer<T>
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(WebContainerBase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ protected WebContainerBase(Class<T> actualType, Archive<?> archive)
+ {
+ super(actualType, archive);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations - WebContainer --------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Should be implemented to set the path for Manifest related
+ * resources.
+ *
+ * @return Base Path for the ManifestContainer resources
+ */
+ protected abstract Path getWebPath();
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.WebContainer#setWebXML(java.lang.String)
+ */
+ @Override
+ public T setWebXML(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+ return add(getWebPath(), "web.xml", new ClassLoaderAsset(resourceName));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.WebContainer#addWebResource(org.jboss.declarchive.api.Path, java.lang.String)
+ */
+ @Override
+ public T addWebResource(Path target, String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(target, "Target should be specified");
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getWebPath(), target);
+ return add(location, asset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.api.container.WebContainer#addWebResource(java.lang.String)
+ */
+ @Override
+ public T addWebResource(String resourceName) throws IllegalArgumentException
+ {
+ Validate.notNull(resourceName, "ResourceName should be specified");
+
+ Asset asset = new ClassLoaderAsset(resourceName);
+ Path location = new BasicPath(getWebPath(), resourceName);
+ return add(location, asset);
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/asset/AssetUtil.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/asset/AssetUtil.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/asset/AssetUtil.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,131 @@
+/*
+ * 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.declarchive.impl.base.asset;
+
+import java.net.URL;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * AssetUtil
+ *
+ * Util class to help extract name/paths from Assets.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class AssetUtil
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The delimiter used for classes.
+ */
+ public static String DELIMITER_CLASS_NAME_PATH = "\\.";
+
+ /**
+ * The delimiter used for classes represented in resource form.
+ */
+ public static String DELIMITER_RESOURCE_PATH = "/";
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Private constructor for util class, should never be created.
+ */
+ private AssetUtil()
+ {
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // External helpers -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Helper to extract a ClassloaderResources path information.
+ * <br/><br/>
+ * ie: /user/test/file.properties = /user/test/
+ *
+ * @param resourceName The name of the resource
+ * @return A Path representation of the give resource
+ */
+ public static Path getPathForClassloaderResource(String resourceName)
+ {
+ String extractedPath = null;
+ if (resourceName.lastIndexOf('/') != -1)
+ {
+ extractedPath = resourceName.substring(
+ 0,
+ resourceName.lastIndexOf('/'));
+ }
+ return new BasicPath(extractedPath);
+ }
+
+ /**
+ * Helper to extract a ClassloaderResources name.
+ * <br/><br/>
+ * ie: /user/test/file.properties = file.properties
+ *
+ * @param resourceName The name of the resource
+ * @return The name of the given resource
+ */
+ public static String getNameForClassloaderResource(String resourceName)
+ {
+ String fileName = resourceName;
+ if (resourceName.indexOf('/') != -1)
+ {
+ fileName = resourceName.substring(
+ resourceName.lastIndexOf('/') + 1,
+ resourceName.length());
+ }
+ return fileName;
+ }
+
+ /**
+ * Helper to extract a ClassResources full path.
+ * <br/><br/>
+ * ie: package.MyClass = package/MyClass.class
+ *
+ * @param clazz
+ * @return
+ */
+ public static Path getFullPathForClassResource(Class<?> clazz)
+ {
+ String classResourceDelimiter = clazz.getName().replaceAll(
+ DELIMITER_CLASS_NAME_PATH, DELIMITER_RESOURCE_PATH);
+ String classFullPath = classResourceDelimiter + ".class";
+ return new BasicPath(classFullPath);
+ }
+
+ /**
+ * Helper to extract a URLs full path.
+ * <br/><br/>
+ * ie: file:///test/test.properties = /test/test.properties
+ *
+ * @param resource
+ * @return
+ */
+ public static Path getFullPathForURLResource(URL resource)
+ {
+ return new BasicPath(resource.getPath());
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImpl.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,120 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.EnterpriseArchive;
+import org.jboss.declarchive.impl.base.EnterpriseContainerBase;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * EnterpriseArchiveImpl
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class EnterpriseArchiveImpl
+ extends EnterpriseContainerBase<EnterpriseArchive>
+ implements EnterpriseArchive
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
+
+ /**
+ * Path to the manifests inside of the Archive.
+ */
+ private static final Path PATH_MANIFEST = new BasicPath("META-INF");
+
+ /**
+ * Path to the resources inside of the Archive.
+ */
+ private static final Path PATH_RESOURCE = PATH_MANIFEST;
+
+ /**
+ * Path to the application resources.
+ */
+ private static final Path PATH_APPLICATION = PATH_MANIFEST;
+
+ /**
+ * Path to the application libraries.
+ */
+ private static final Path PATH_LIBRARY = new BasicPath("lib");
+
+ /**
+ * Path to the application modules.
+ */
+ private static final Path PATH_MODULE = new BasicPath("/");
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create a new EnterpriseArchive with any type storage engine as backing.
+ *
+ * @param delegate The storage backing.
+ */
+ public EnterpriseArchiveImpl(final Archive<?> delegate)
+ {
+ super(EnterpriseArchive.class, delegate);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+ @Override
+ public Path getLibraryPath()
+ {
+ return PATH_LIBRARY;
+ }
+
+ @Override
+ protected Path getResourcePath()
+ {
+ return PATH_RESOURCE;
+ }
+
+ @Override
+ protected Path getManinfestPath()
+ {
+ return PATH_MANIFEST;
+ }
+
+ @Override
+ protected Path getApplicationPath()
+ {
+ return PATH_APPLICATION;
+ }
+
+ @Override
+ protected Path getModulePath()
+ {
+ return PATH_MODULE;
+ }
+
+ @Override
+ protected Path getClassesPath()
+ {
+ throw new UnsupportedOperationException("EnterpriseArchive does not support classes");
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImpl.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,121 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.ContainerBase;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * JavaArchiveImpl
+ *
+ * Implementation of an archive with JAR-specific support.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class JavaArchiveImpl
+ extends ContainerBase<JavaArchive>
+ implements JavaArchive
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
+
+ /**
+ * Path to the manifests inside of the Archive.
+ */
+ private static final Path PATH_MANIFEST = new BasicPath("META-INF");
+
+ /**
+ * Path to the resources inside of the Archive.
+ */
+ private static final Path PATH_RESOURCE = new BasicPath("/");
+
+ /**
+ * Path to the classes inside of the Archive.
+ */
+ private static final Path PATH_CLASSES = new BasicPath("/");
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create a new JavaArchive with any type storage engine as backing.
+ *
+ * @param delegate The storage backing.
+ */
+ public JavaArchiveImpl(final Archive<?> delegate)
+ {
+ super(JavaArchive.class, delegate);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getManinfestPath()
+ */
+ @Override
+ protected Path getManinfestPath()
+ {
+ return PATH_MANIFEST;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getClassesPath()
+ */
+ @Override
+ protected Path getClassesPath()
+ {
+ return PATH_CLASSES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getResourcePath()
+ */
+ @Override
+ protected Path getResourcePath()
+ {
+ return PATH_RESOURCE;
+ }
+
+ /**
+ * Libraries are not supported by JavaArchive.
+ *
+ * @throws UnsupportedOperationException Libraries are not supported by JavaArchive
+ */
+ @Override
+ public Path getLibraryPath()
+ {
+ throw new UnsupportedOperationException("JavaArchive spec does not support Libraries");
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/WebArchiveImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/WebArchiveImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/spec/WebArchiveImpl.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,135 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.WebArchive;
+import org.jboss.declarchive.impl.base.WebContainerBase;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+
+/**
+ * WebArchiveImpl
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WebArchiveImpl
+ extends WebContainerBase<WebArchive>
+ implements WebArchive
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(JavaArchiveImpl.class.getName());
+
+ /**
+ * Path to the web inside of the Archive.
+ */
+ private static final Path PATH_WEB = new BasicPath("WEB-INF");
+
+ /**
+ * Path to the manifests inside of the Archive.
+ */
+ private static final Path PATH_MANIFEST = new BasicPath("META-INF");
+
+ /**
+ * Path to the resources inside of the Archive.
+ */
+ private static final Path PATH_RESOURCE = new BasicPath("/");
+
+ /**
+ * Path to the libraries inside of the Archive.
+ */
+ private static final Path PATH_LIBRARY = new BasicPath(PATH_WEB, "lib");
+
+ /**
+ * Path to the classes inside of the Archive.
+ */
+ private static final Path PATH_CLASSES = new BasicPath(PATH_WEB, "classes");
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create a new JavaArchive with any type storage engine as backing.
+ *
+ * @param delegate The storage backing.
+ */
+ public WebArchiveImpl(final Archive<?> delegate)
+ {
+ super(WebArchive.class, delegate);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getManinfestPath()
+ */
+ @Override
+ protected Path getManinfestPath()
+ {
+ return PATH_MANIFEST;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getClassesPath()
+ */
+ @Override
+ protected Path getClassesPath()
+ {
+ return PATH_CLASSES;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getResourcePath()
+ */
+ @Override
+ protected Path getResourcePath()
+ {
+ return PATH_RESOURCE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.ContainerSupport#getLibraryPath()
+ */
+ @Override
+ public Path getLibraryPath()
+ {
+ return PATH_LIBRARY;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.declarchive.impl.base.WebContainerSupport#getWebPath()
+ */
+ @Override
+ protected Path getWebPath()
+ {
+ return PATH_WEB;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/asset/AssetUtilTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/asset/AssetUtilTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/asset/AssetUtilTestCase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,83 @@
+/*
+ * 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.declarchive.impl.base.asset;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+import org.junit.Test;
+
+
+/**
+ * AssetUtilTest
+ *
+ * Test case to ensure the correctness of the AssetUtil.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class AssetUtilTestCase
+{
+ private static final String EXISTING_RESOURCE = "org/jboss/declarchive/impl/base/asset/Test.properties";
+
+ @Test
+ public void shouldBeAbleToGetPathForClassloaderResource() throws Exception
+ {
+ Path foundResourcePath = AssetUtil.getPathForClassloaderResource(EXISTING_RESOURCE);
+
+ Assert.assertEquals(
+ "The classloader resource path should not contain the file name",
+ new BasicPath("org/jboss/declarchive/impl/base/asset"),
+ foundResourcePath);
+ }
+
+ @Test
+ public void shouldBeAbleToGetNameForClassloaderResource() throws Exception
+ {
+ String foundResourceName = AssetUtil.getNameForClassloaderResource(EXISTING_RESOURCE);
+
+ Assert.assertEquals(
+ "The classloader resource name should not contain the path",
+ "Test.properties",
+ foundResourceName);
+ }
+
+ @Test
+ public void shouldBeAbleToGetFullPathForClassResoruce() throws Exception
+ {
+ Path foundClassResourcePath = AssetUtil.getFullPathForClassResource(this.getClass());
+
+ Assert.assertEquals(
+ "The class resource should have a / delimiter and a .class extension",
+ new BasicPath("/org/jboss/declarchive/impl/base/asset/AssetUtilTestCase.class"),
+ foundClassResourcePath);
+ }
+
+ @Test
+ public void shouldBeAbleToGetFullPathFromURL() throws Exception
+ {
+ Path foundURLPath = AssetUtil.getFullPathForURLResource(new URL("file:///test/test.properties"));
+
+ Assert.assertEquals(
+ "The url resource should have it's full path",
+ new BasicPath("/test/test.properties"),
+ foundURLPath);
+ }
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImplTest.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImplTest.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/EnterpriseArchiveImplTest.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,146 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.EnterpriseArchive;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.asset.AssetUtil;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * EnterpriseArchiveImplTest
+ *
+ * Test to ensure that EnterpriseArchiveImpl follow to java ear spec.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class EnterpriseArchiveImplTest
+{
+ private static final String TEST_RESOURCE = "org/jboss/declarchive/impl/base/asset/Test.properties";
+
+ private static final Path PATH_APPLICATION = new BasicPath("META-INF");
+
+ private static final Path PATH_LIBRARY = new BasicPath("lib");
+
+ private static final Path PATH_MODULE = new BasicPath("/");
+
+ private EnterpriseArchive archive;
+
+ @Before
+ public void createWebArchive() throws Exception
+ {
+ archive = new EnterpriseArchiveImpl(new MemoryMapArchiveImpl());
+ }
+
+ @After
+ public void ls()
+ {
+ System.out.println("test at jboss:/$ ls -l " + archive.getName());
+ System.out.println(archive.toString(true));
+ }
+
+ @Test
+ public void shouldBeAbleToAddApplicationXML() throws Exception
+ {
+ archive.setApplicationXML(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_APPLICATION, "application.xml");
+
+ Assert.assertTrue(
+ "applicaton.xml should be located in /META-INF/application.xml",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddApplicationResource() throws Exception
+ {
+ archive.addApplicationResource(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_APPLICATION, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A application resource should be located in /META-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddApplicationResourceWithNewName() throws Exception
+ {
+ String newName = "test.txt";
+ archive.addApplicationResource(new BasicPath(newName), TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_APPLICATION, newName);
+
+ Assert.assertTrue(
+ "A application resource should be located in /META-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddLibrary() throws Exception
+ {
+ archive.addLibrary(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_LIBRARY, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A library should be located in /lib/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddModule() throws Exception
+ {
+ archive.addModule(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(
+ PATH_MODULE,
+ AssetUtil.getNameForClassloaderResource(TEST_RESOURCE));
+
+ Assert.assertTrue(
+ "A application module should be located in /",
+ archive.contains(expectedPath));
+ }
+
+ //@Test
+ // TODO: should we be able to add a ArchiveAsset, to add aarchive as a single jar not a exploded jar?
+ public void shouldBeAbleToAddArchiveModule() throws Exception
+ {
+ JavaArchive moduleArchive = new JavaArchiveImpl(new MemoryMapArchiveImpl("test.jar"));
+ moduleArchive.addResource(TEST_RESOURCE);
+ moduleArchive.addResource(new BasicPath("test.txt"), TEST_RESOURCE);
+
+ archive.addModule(moduleArchive);
+
+ Path expectedPath = new BasicPath(
+ PATH_MODULE,
+ moduleArchive.getName());
+
+ Assert.assertTrue(
+ "A application module should be located in /",
+ archive.contains(expectedPath));
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImplTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImplTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/JavaArchiveImplTestCase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,159 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import java.util.logging.Logger;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.asset.AssetUtil;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+import org.jboss.declarchive.impl.base.spec.donotchange.DummyClassUsedForClassResourceTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JavaArchiveImplTestCase
+ *
+ * Test case to ensure that the JavaArchive follows the Jar spec.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class JavaArchiveImplTestCase
+{
+ private static final Logger log = Logger.getLogger(JavaArchiveImplTestCase.class.getName());
+
+ private static final String TEST_RESOURCE = "org/jboss/declarchive/impl/base/asset/Test.properties";
+
+ private static final Path PATH_MANIFEST = new BasicPath("META-INF");
+
+ private static final Path PATH_RESOURCE = new BasicPath("/");
+
+ private static final Path PATH_CLASS = new BasicPath("/");
+
+ private JavaArchive archive;
+
+ @Before
+ public void createArchive()
+ {
+ archive = new JavaArchiveImpl(new MemoryMapArchiveImpl());
+ }
+
+ @After
+ public void ls()
+ {
+ System.out.println("test at jboss:/$ ls -l " + archive.getName());
+ System.out.println(archive.toString(true));
+ }
+
+ @Test
+ public void shouldBeAbleToSetManifestFile() throws Exception
+ {
+ archive.setManifest(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_MANIFEST, "MANIFEST.MF");
+
+ Assert.assertTrue(
+ "The MANIFEST.MF file should be located under /META-INF/MANIFEST.MF",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddManifestResource() throws Exception
+ {
+ archive.addManifestResource(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_MANIFEST, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A manifest resource should be located under /META-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddManifestResourceWithNewName() throws Exception
+ {
+ String newName = "test.txt";
+ archive.addManifestResource(new BasicPath(newName), TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_MANIFEST, newName);
+
+ Assert.assertTrue(
+ "A manifest resoruce should be located under /META-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddResource() throws Exception
+ {
+ archive.addResource(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_RESOURCE, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A resoruce should be located under /",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddResourceWithNewName() throws Exception
+ {
+ String newName = "test.txt";
+ archive.addResource(TEST_RESOURCE, newName);
+
+ Path expectedPath = new BasicPath(
+ PATH_RESOURCE,
+ "/org/jboss/declarchive/impl/base/asset/" + newName);
+
+ Assert.assertTrue(
+ "A resoruce should be located under /",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddClass() throws Exception
+ {
+ archive.addClasses(DummyClassUsedForClassResourceTest.class);
+
+ Path expectedPath = new BasicPath(
+ PATH_CLASS,
+ AssetUtil.getFullPathForClassResource(DummyClassUsedForClassResourceTest.class));
+
+ Assert.assertTrue(
+ "A class should be located under /",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddPackage() throws Exception
+ {
+ archive.addPackages(false, DummyClassUsedForClassResourceTest.class.getPackage());
+
+ Path expectedPath = new BasicPath(
+ PATH_CLASS,
+ AssetUtil.getFullPathForClassResource(DummyClassUsedForClassResourceTest.class));
+
+ Assert.assertTrue(
+ "A class should be located under /",
+ archive.contains(expectedPath));
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/WebArchiveImplTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/WebArchiveImplTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/WebArchiveImplTestCase.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,141 @@
+/*
+ * 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.declarchive.impl.base.spec;
+
+import org.jboss.declarchive.api.Path;
+import org.jboss.declarchive.api.spec.WebArchive;
+import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.asset.AssetUtil;
+import org.jboss.declarchive.impl.base.path.BasicPath;
+import org.jboss.declarchive.impl.base.spec.donotchange.DummyClassUsedForClassResourceTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * WebArchiveImplTestCase
+ *
+ * Test case to ensure that the WebArchive follows the War spec.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WebArchiveImplTestCase
+{
+ private static final String TEST_RESOURCE = "org/jboss/declarchive/impl/base/asset/Test.properties";
+
+ private static final Path PATH_WEBINF = new BasicPath("WEB-INF");
+
+ private static final Path PATH_LIBRARY = new BasicPath(PATH_WEBINF, "lib");
+
+ private static final Path PATH_CLASSES = new BasicPath(PATH_WEBINF, "classes");
+
+ private WebArchive archive;
+
+ @Before
+ public void createWebArchive() throws Exception
+ {
+ archive = new WebArchiveImpl(new MemoryMapArchiveImpl());
+ }
+
+ @After
+ public void ls()
+ {
+ System.out.println("test at jboss:/$ ls -l " + archive.getName());
+ System.out.println(archive.toString(true));
+ }
+
+ @Test
+ public void shouldBeAbleToSetWebXML() throws Exception
+ {
+ archive.setWebXML(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_WEBINF, "web.xml");
+
+ Assert.assertTrue(
+ "web.xml should be located in /WEB-INF/web.xml",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddWebResource() throws Exception {
+
+ archive.addWebResource(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_WEBINF, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A resource should be located in /WEB-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddWebResourceWithNewName() throws Exception {
+
+ String newName = "test.txt";
+ archive.addWebResource(new BasicPath(newName), TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_WEBINF, newName);
+
+ Assert.assertTrue(
+ "A resource should be located in /WEB-INF/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddLibrary() throws Exception
+ {
+ archive.addLibrary(TEST_RESOURCE);
+
+ Path expectedPath = new BasicPath(PATH_LIBRARY, TEST_RESOURCE);
+
+ Assert.assertTrue(
+ "A library should be located in /WEB-INF/lib/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddClasses() throws Exception
+ {
+ archive.addClasses(DummyClassUsedForClassResourceTest.class);
+
+ Path expectedPath = new BasicPath(
+ PATH_CLASSES,
+ AssetUtil.getFullPathForClassResource(
+ DummyClassUsedForClassResourceTest.class));
+
+ Assert.assertTrue(
+ "A class should be located in /WEB-INF/classes/",
+ archive.contains(expectedPath));
+ }
+
+ @Test
+ public void shouldBeAbleToAddPackages() throws Exception
+ {
+ archive.addPackages(true, DummyClassUsedForClassResourceTest.class.getPackage());
+
+ Path expectedPath = new BasicPath(
+ PATH_CLASSES,
+ AssetUtil.getFullPathForClassResource(
+ DummyClassUsedForClassResourceTest.class));
+
+ Assert.assertTrue(
+ "A class should be located in /WEB-INF/classes/",
+ archive.contains(expectedPath));
+ }
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/donotchange/DummyClassUsedForClassResourceTest.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/donotchange/DummyClassUsedForClassResourceTest.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/spec/donotchange/DummyClassUsedForClassResourceTest.java 2009-08-24 17:27:05 UTC (rev 3477)
@@ -0,0 +1,30 @@
+/*
+ * 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.declarchive.impl.base.spec.donotchange;
+
+
+/**
+ * DummyClassUsedForClassResourceTest
+ *
+ * This class is just here for the ClassContainer.addPackage/addClass tests.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class DummyClassUsedForClassResourceTest
+{
+}
More information about the jboss-svn-commits
mailing list