[jboss-svn-commits] JBoss Common SVN: r4315 - in arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld: shrinkwrap and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Apr 21 18:48:12 EDT 2010
Author: aslak
Date: 2010-04-21 18:48:11 -0400 (Wed, 21 Apr 2010)
New Revision: 4315
Added:
arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/shrinkwrap/ShrinkWrapClassLoader.java
Modified:
arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/WeldSEContainer.java
Log:
ARQ-97 Committed prototype, needed by seam 3 drools module
Modified: arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/WeldSEContainer.java
===================================================================
--- arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/WeldSEContainer.java 2010-04-21 21:41:18 UTC (rev 4314)
+++ arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/WeldSEContainer.java 2010-04-21 22:48:11 UTC (rev 4315)
@@ -28,6 +28,7 @@
import org.jboss.arquillian.spi.LifecycleException;
import org.jboss.arquillian.spi.TestMethodExecutor;
import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.weld.shrinkwrap.ShrinkWrapClassLoader;
import org.jboss.arquillian.weld.shrinkwrap.ShrinkwrapBeanDeploymentArchive;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.weld.bootstrap.WeldBootstrap;
@@ -69,6 +70,10 @@
{
final BeanDeploymentArchive beanArchive = archive.as(ShrinkwrapBeanDeploymentArchive.class);
+ ClassLoader cl = new ShrinkWrapClassLoader(archive);
+
+ Thread.currentThread().setContextClassLoader(cl);
+
Deployment deployment = new Deployment()
{
public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
@@ -137,6 +142,7 @@
manager.getServices().get(ContextLifecycle.class).endSession(manager.getId(), null);
holder.getBootstrap().shutdown();
+ Thread.currentThread().setContextClassLoader(Thread.currentThread().getContextClassLoader().getParent());
}
WELD_MANAGER.set(null);
}
Added: arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/shrinkwrap/ShrinkWrapClassLoader.java
===================================================================
--- arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/shrinkwrap/ShrinkWrapClassLoader.java (rev 0)
+++ arquillian/trunk/containers/weld-embedded/src/main/java/org/jboss/arquillian/weld/shrinkwrap/ShrinkWrapClassLoader.java 2010-04-21 22:48:11 UTC (rev 4315)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., 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.arquillian.weld.shrinkwrap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.SecureClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Asset;
+
+/**
+ * A ClassLoader implementation that can locate resources in a ShrinkWrap archive
+ *
+ * <p><strong>NOTE</strong> This is a prototype implementation of this concept. It
+ * does not address all classloading concerns as of yet.</p>
+ *
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ */
+public class ShrinkWrapClassLoader extends SecureClassLoader
+{
+ public static final String ARCHIVE_PROTOCOL = "archive:/";
+
+ private final Archive<?> archive;
+
+ public ShrinkWrapClassLoader(Archive<?> archive)
+ {
+ super();
+ this.archive = archive;
+ }
+
+ @Override
+ protected URL findResource(final String name)
+ {
+ final Asset a = archive.get(name).getAsset();
+ if (a == null)
+ {
+ return null;
+ }
+ try
+ {
+ return new URL(null, ARCHIVE_PROTOCOL + name, new URLStreamHandler()
+ {
+ @Override
+ protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+ {
+ return new URLConnection(u)
+ {
+ @Override
+ public void connect() throws IOException
+ {
+ }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return a.openStream();
+ }
+ };
+ }
+
+ ;
+ });
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException
+ {
+ Iterator<URL> it = new ArrayList<URL>(0).iterator();
+ URL resource = findResource(name);
+ if (resource != null)
+ {
+ it = Arrays.asList(resource).iterator();
+ }
+ final Iterator<URL> i = it;
+ return new Enumeration<URL>()
+ {
+ public boolean hasMoreElements()
+ {
+ return i.hasNext();
+ }
+
+ public URL nextElement()
+ {
+ return i.next();
+ }
+ };
+ }
+}
More information about the jboss-svn-commits
mailing list