mirror of https://github.com/apache/archiva.git
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
This commit is contained in:
parent
03accd4ffd
commit
0cb8cf2879
|
@ -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> T lookup( Class<T> clazz )
|
||||
throws PlexusSisuBridgeException
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue