[jboss-svn-commits] JBoss Common SVN: r3676 - in shrinkwrap/trunk: impl-base/src/main/java/org/jboss/shrinkwrap/impl/base and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 12 03:13:17 EST 2009
Author: aslak
Date: 2009-11-12 03:13:17 -0500 (Thu, 12 Nov 2009)
New Revision: 3676
Added:
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archives.java
shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/SecurityActions.java
Removed:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Archives.java
Modified:
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImplTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImplTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImplTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImplTestCase.java
Log:
SHRINKWRAP-74 Moved Archives factory to API. Uses reflection to load MemoryMapArchive
Copied: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archives.java (from rev 3669, shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Archives.java)
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archives.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/Archives.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.api;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Generic unified factory for archive creation.
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class Archives
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final String ARCHIVE_IMPL = "org.jboss.shrinkwrap.impl.base.MemoryMapArchiveImpl";
+
+ /**
+ * Create a archive as a specific type.
+ *
+ * @param archiveName The name of the archive
+ * @return A {@link Specializer} archive base
+ */
+ public static <T extends Specializer> T create(String archiveName, Class<T> type)
+ {
+ if(archiveName == null)
+ {
+ throw new IllegalArgumentException("ArchiveName must be specified");
+ }
+ if(type == null)
+ {
+ throw new IllegalArgumentException("Type must be specified");
+ }
+ try
+ {
+ return createArchive(archiveName).as(type);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not create new archive, missing impl package from classpath?", e);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members - Internal Helpers ---------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Load and create a new archive instance.
+ */
+ private static Archive<?> createArchive(String archiveName) throws Exception
+ {
+ return (Archive<?>) findConstructor(
+ loadClass(ARCHIVE_IMPL)).newInstance(archiveName);
+ }
+
+ /**
+ * Load the specified class using Thread Current Class Loader in a privileged block.
+ */
+ private static Class<?> loadClass(String archiveImplClassName) throws Exception
+ {
+ return SecurityActions.getThreadContextClassLoader().loadClass(archiveImplClassName);
+ }
+
+ /**
+ * Find the archive implementations String based constructor.
+ */
+ private static Constructor<?> findConstructor(Class<?> archiveImplClazz) throws Exception
+ {
+ return archiveImplClazz.getConstructor(String.class);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * No instantiation
+ */
+ private Archives() {}
+}
Added: shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/SecurityActions.java
===================================================================
--- shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/SecurityActions.java (rev 0)
+++ shrinkwrap/trunk/api/src/main/java/org/jboss/shrinkwrap/api/SecurityActions.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.shrinkwrap.api;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+final class SecurityActions
+{
+
+ //-------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * No external instantiation
+ */
+ private SecurityActions()
+ {
+
+ }
+
+ //-------------------------------------------------------------------------------||
+ // Utility Methods --------------------------------------------------------------||
+ //-------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the Thread Context ClassLoader
+ */
+ static ClassLoader getThreadContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
Deleted: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Archives.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Archives.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/Archives.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.shrinkwrap.impl.base;
-
-import org.jboss.shrinkwrap.api.Specializer;
-
-/**
- * Generic unified factory for archive creation.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-public class Archives
-{
- //-------------------------------------------------------------------------------------||
- // Class Members ----------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * Create a Specialized archive base from where any other archive type can be made.
- *
- * @param archiveName The name of the archive
- * @return A {@link Specializer} archive base
- */
- public static <T extends Specializer> T create(String archiveName, Class<T> type) {
- return new MemoryMapArchiveImpl(archiveName).as(type);
- }
-
- //-------------------------------------------------------------------------------------||
- // Constructor ------------------------------------------------------------------------||
- //-------------------------------------------------------------------------------------||
-
- /**
- * No instantiation
- */
- private Archives() {}
-}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/ArchivesTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -18,6 +18,7 @@
import junit.framework.Assert;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ExplodedImporterTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -17,9 +17,9 @@
package org.jboss.shrinkwrap.impl.base.importer;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.junit.Assert;
import org.junit.Test;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/importer/ZipImporterImplTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -31,10 +31,10 @@
import junit.framework.Assert;
import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImplTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/EnterpriseArchiveImplTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -18,6 +18,7 @@
import java.util.UUID;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.container.ClassContainer;
import org.jboss.shrinkwrap.api.container.EnterpriseContainer;
@@ -25,7 +26,6 @@
import org.jboss.shrinkwrap.api.container.ManifestContainer;
import org.jboss.shrinkwrap.api.container.ResourceContainer;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.test.ArchiveType;
import org.jboss.shrinkwrap.impl.base.test.DynamicEnterpriseContainerTestBase;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImplTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/JavaArchiveImplTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -18,13 +18,13 @@
import java.util.UUID;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.container.ClassContainer;
import org.jboss.shrinkwrap.api.container.LibraryContainer;
import org.jboss.shrinkwrap.api.container.ManifestContainer;
import org.jboss.shrinkwrap.api.container.ResourceContainer;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.test.ArchiveType;
import org.jboss.shrinkwrap.impl.base.test.DynamicContainerTestBase;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImplTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/ResourceAdapterArchiveImplTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -18,6 +18,7 @@
import java.util.UUID;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.container.ClassContainer;
import org.jboss.shrinkwrap.api.container.LibraryContainer;
@@ -25,7 +26,6 @@
import org.jboss.shrinkwrap.api.container.ResourceAdapterContainer;
import org.jboss.shrinkwrap.api.container.ResourceContainer;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.test.ArchiveType;
import org.jboss.shrinkwrap.impl.base.test.DynamicResourceAdapterContainerTestBase;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImplTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImplTestCase.java 2009-11-12 08:03:06 UTC (rev 3675)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/spec/WebArchiveImplTestCase.java 2009-11-12 08:13:17 UTC (rev 3676)
@@ -18,6 +18,7 @@
import java.util.UUID;
+import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.container.ClassContainer;
import org.jboss.shrinkwrap.api.container.LibraryContainer;
@@ -25,7 +26,6 @@
import org.jboss.shrinkwrap.api.container.ResourceContainer;
import org.jboss.shrinkwrap.api.container.WebContainer;
import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.impl.base.Archives;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.jboss.shrinkwrap.impl.base.test.ArchiveType;
import org.jboss.shrinkwrap.impl.base.test.DynamicWebContainerTestBase;
More information about the jboss-svn-commits
mailing list