[jboss-svn-commits] JBoss Common SVN: r3830 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 4 14:50:36 EST 2009
Author: aslak
Date: 2009-12-04 14:50:35 -0500 (Fri, 04 Dec 2009)
New Revision: 3830
Modified:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ClassContainer.java
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java
Log:
SHRINKWRAP-92 Added addClass(String) defaults to TCCL. addClass(String, Classloader) null Classloader results in IllegalArgumentException
Modified: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ClassContainer.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ClassContainer.java 2009-12-04 19:29:56 UTC (rev 3829)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/container/ClassContainer.java 2009-12-04 19:50:35 UTC (rev 3830)
@@ -47,16 +47,27 @@
T addClass(Class<?> clazz) throws IllegalArgumentException;
/**
- * Adds the Class with the specified fully-qualified name,
- * loaded by the specified ClassLoader, to the {@link Archive}.
+ * Adds the {@link Class} with the specified fully-qualified name,
+ * loaded by the Thread Context {@link ClassLoader}, to the {@link Archive}.
*
- * @param fullyQualifiedClassName The name of the Class to add
- * @param cl The ClassLoader used to load the Class, or null to denote the
- * Thread Context ClassLoader
+ * @param fullyQualifiedClassName The name of the {@link Class} to add
* @return This archive
- * @throws IllegalArgumentException If no class name was specified, or if the Class
- * could not be loaded by the target ClassLoader
+ * @throws IllegalArgumentException If no class name was specified
+ * @throws IllegalArgumentException If the {@link Class} could not be loaded
*/
+ T addClass(String fullyQualifiedClassName) throws IllegalArgumentException;
+
+ /**
+ * Adds the {@link Class} with the specified fully-qualified name,
+ * loaded by the specified {@link ClassLoader}, to the {@link Archive}.
+ *
+ * @param fullyQualifiedClassName The name of the {@link Class} to add
+ * @param cl The {@link ClassLoader} used to load the Class
+ * @return This archive
+ * @throws IllegalArgumentException If no class name was specified
+ * @throws IllegalArgumentException If no {@link ClassLoader} was specified
+ * @throws IllegalArgumentException If the {@link Class} could not be loaded by the target {@link ClassLoader}
+ */
T addClass(String fullyQualifiedClassName, ClassLoader cl) throws IllegalArgumentException;
/**
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-04 19:29:56 UTC (rev 3829)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/container/ContainerBase.java 2009-12-04 19:50:35 UTC (rev 3830)
@@ -593,35 +593,42 @@
return addClasses(clazz);
}
+ /* (non-Javadoc)
+ * @see org.jboss.shrinkwrap.api.container.ClassContainer#addClass(java.lang.String)
+ */
/**
+ * @see #addClass(String, ClassLoader)
+ */
+ @Override
+ public T addClass(String fullyQualifiedClassName) throws IllegalArgumentException
+ {
+ Validate.notNullOrEmpty(fullyQualifiedClassName, "Fully-qualified class name must be specified");
+
+ return addClass(
+ fullyQualifiedClassName,
+ AccessController.doPrivileged(GetTcclAction.INSTANCE));
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.shrinkwrap.api.container.ClassContainer#addClass(java.lang.String, java.lang.ClassLoader)
*/
@Override
public T addClass(final String fullyQualifiedClassName, final ClassLoader cl) throws IllegalArgumentException
{
// Precondition checks
- if (fullyQualifiedClassName == null || fullyQualifiedClassName.length() == 0)
- {
- throw new IllegalArgumentException("Fully-qualified class name must be specified");
- }
-
- // Default to TCCL if not specified
- ClassLoader loadingCl = cl;
- if (loadingCl == null)
- {
- loadingCl = AccessController.doPrivileged(GetTcclAction.INSTANCE);
- }
-
+ Validate.notNullOrEmpty(fullyQualifiedClassName, "Fully-qualified class name must be specified");
+ Validate.notNull(cl, "ClassLoader must be specified");
+
// Obtain the Class
final Class<?> clazz;
try
{
- clazz = Class.forName(fullyQualifiedClassName, false, loadingCl);
+ clazz = Class.forName(fullyQualifiedClassName, false, cl);
}
catch (final ClassNotFoundException e)
{
throw new IllegalArgumentException("Could not load class of name " + fullyQualifiedClassName + " with "
- + loadingCl, e);
+ + cl, e);
}
// Delegate and return
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java 2009-12-04 19:29:56 UTC (rev 3829)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/test/DynamicContainerTestBase.java 2009-12-04 19:50:35 UTC (rev 3830)
@@ -402,20 +402,24 @@
}
/**
- * Ensure classes can be added to containers by name and ClassLoader
+ * Ensure classes can be added to containers by name
*
* @throws Exception
*/
@Test
@ArchiveType(ClassContainer.class)
- public void testAddClassesByFqnAndClassLoader() throws Exception
+ public void testAddClassesByFqn() throws Exception
{
- // Attempt to load using the TCCL
- this.ensureCanAddClassByNameAndClassLoader(Thread.currentThread().getContextClassLoader());
+ final Class<?> classToAdd = DummyClassUsedForClassResourceTest.class;
+
+ getClassContainer().addClass(classToAdd.getName());
+
+ Path expectedPath = new BasicPath(getClassPath(), AssetUtil.getFullPathForClassResource(classToAdd));
+ Assert.assertTrue("A class should be located at " + expectedPath.get(), getArchive().contains(expectedPath));
}
/**
- * Ensure classes can be added to containers by name and TCCL
+ * Ensure classes can be added to containers by name using a classloader
*
* @throws Exception
*/
@@ -423,23 +427,11 @@
@ArchiveType(ClassContainer.class)
public void testAddClassesByFqnAndTccl() throws Exception
{
- // Using a null CL should signal to default to TCCL
- this.ensureCanAddClassByNameAndClassLoader(null);
- }
-
- /**
- * Ensures that a Class may be added to the ClassContainer by FQN
- * and the specified ClassLoader
- * @param cl
- */
- private void ensureCanAddClassByNameAndClassLoader(final ClassLoader cl)
- {
final Class<?> classToAdd = DummyClassUsedForClassResourceTest.class;
- getClassContainer().addClass(classToAdd.getName(), cl);
+ getClassContainer().addClass(classToAdd.getName(), classToAdd.getClassLoader());
Path expectedPath = new BasicPath(getClassPath(), AssetUtil.getFullPathForClassResource(classToAdd));
-
Assert.assertTrue("A class should be located at " + expectedPath.get(), getArchive().contains(expectedPath));
}
More information about the jboss-svn-commits
mailing list