From 0cb8cf2879eefce11d50bc3e744105e068eb41a4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 9 Jun 2011 16:23:01 +0000 Subject: [PATCH] I think I'm back to figth again with classLoader and this sisu git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1133962 13f79535-47bb-0310-9956-ffa450edef68 --- .../common/plexusbridge/PlexusSisuBridge.java | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridge.java b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridge.java index 9ad803049..cf774fe0d 100644 --- a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridge.java +++ b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridge.java @@ -26,10 +26,14 @@ import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.lang.reflect.Method; import java.net.URL; +import java.net.URLClassLoader; import java.util.List; import java.util.Map; @@ -44,6 +48,8 @@ import java.util.Map; public class PlexusSisuBridge { + private Logger log = LoggerFactory.getLogger( getClass() ); + private boolean containerAutoWiring = false; private String containerClassPathScanning = PlexusConstants.SCANNING_OFF; @@ -70,14 +76,19 @@ public class PlexusSisuBridge ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - ClassRealm classRealm = new ClassRealm( classWorld, "maven", tccl ) - { - public URL[] getURLs() - { - return super.getURLs(); - } + ClassRealm classRealm = new ClassRealm( classWorld, "maven", tccl ); + + // olamy hackhish but plexus-sisu need a URLClassLoader with URL filled + + if ( tccl instanceof URLClassLoader ) + { + URL[] urls = ( (URLClassLoader) tccl ).getURLs(); + for ( URL url : urls ) + { + classRealm.addURL( url ); + } + } - }; conf.setRealm( classRealm ); conf.setClassWorld( classWorld ); @@ -92,6 +103,26 @@ public class PlexusSisuBridge } } + + private URL[] getClassLoaderURLs( ClassLoader classLoader ) + { + try + { + // can be WebappClassLoader when using tomcat maven plugin + //java.net.URL[] getURLs + Method method = classLoader.getClass().getMethod( "getURLs", new Class[]{ } ); + if ( method != null ) + { + return (URL[]) method.invoke( classLoader, null ); + } + } + catch ( Exception e ) + { + log.info( "ignore issue trying to find url[] from classloader {}", e.getMessage() ); + } + return new URL[]{ }; + } + public T lookup( Class clazz ) throws PlexusSisuBridgeException {