mirror of https://github.com/apache/maven.git
[MNG-1898] improve the diagnostics and switch on it0094
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
73ba7305ce
commit
89e6008e13
|
@ -1,4 +1,4 @@
|
||||||
# it0094 currently fails. It is testing MNG-1898
|
it0094 currently fails. It is testing MNG-1898
|
||||||
it0092
|
it0092
|
||||||
# it0091 currrently fails. Not sure if there is an associated JIRA.
|
# it0091 currrently fails. Not sure if there is an associated JIRA.
|
||||||
it0090
|
it0090
|
||||||
|
|
|
@ -16,23 +16,21 @@
|
||||||
|
|
||||||
package org.codehaus.mojo.kodo;
|
package org.codehaus.mojo.kodo;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
|
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.xerces.jaxp.SAXParserFactoryImpl;
|
import org.apache.xerces.jaxp.SAXParserFactoryImpl;
|
||||||
import org.codehaus.classworlds.ClassRealm;
|
import org.codehaus.classworlds.ClassRealm;
|
||||||
|
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Goal that enhances persistant classes
|
* Goal that enhances persistant classes
|
||||||
*
|
*
|
||||||
* @requiresDependancyResolution test
|
* @requiresDependancyResolution test
|
||||||
* @goal enhance
|
* @goal enhance
|
||||||
*
|
|
||||||
* @phase compile
|
* @phase compile
|
||||||
*/
|
*/
|
||||||
public class Enhance
|
public class Enhance
|
||||||
|
@ -55,21 +53,21 @@ public class Enhance
|
||||||
setupClassloader();
|
setupClassloader();
|
||||||
originalLoader = Thread.currentThread().getContextClassLoader();
|
originalLoader = Thread.currentThread().getContextClassLoader();
|
||||||
System.out.println( originalLoader.getClass() );
|
System.out.println( originalLoader.getClass() );
|
||||||
|
|
||||||
SAXParserFactoryImpl spi = new SAXParserFactoryImpl();
|
SAXParserFactoryImpl spi = new SAXParserFactoryImpl();
|
||||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||||
this.getLog().info( spf.toString() );
|
this.getLog().info( spf.toString() );
|
||||||
String t = "org/apache/xerces/jaxp/SAXParserFactoryImpl.class";
|
String t = "org/apache/xerces/jaxp/SAXParserFactoryImpl.class";
|
||||||
this.getLog().info(t);
|
this.getLog().info( t );
|
||||||
URL url = originalLoader.getResource(t);
|
URL url = originalLoader.getResource( t );
|
||||||
//URL url = spf.getClass().getClassLoader().getResource("javax/xml/parsers/SAXParserFactory.class");
|
//URL url = spf.getClass().getClassLoader().getResource("javax/xml/parsers/SAXParserFactory.class");
|
||||||
this.getLog().info("Loaded from: "+url.toString());
|
this.getLog().info( "Loaded from: " + url.toString() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds nessessary items to the classloader.
|
* Adds nessessary items to the classloader.
|
||||||
*
|
*
|
||||||
* @return ClassLoader original Classloader.
|
* @return ClassLoader original Classloader.
|
||||||
* @throws MojoExecutionException
|
* @throws MojoExecutionException
|
||||||
*/
|
*/
|
||||||
|
@ -79,26 +77,54 @@ public class Enhance
|
||||||
|
|
||||||
URLClassLoader loader = null;
|
URLClassLoader loader = null;
|
||||||
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
|
||||||
this.getLog().info( originalLoader.toString() );
|
this.getLog().info( "orig classloader:" );
|
||||||
|
printURLClassPath( Thread.currentThread().getContextClassLoader(), "" );
|
||||||
URL[] urls = new URL[0];
|
URL[] urls = new URL[0];
|
||||||
loader = new URLClassLoader( urls, originalLoader );
|
loader = new URLClassLoader( urls, originalLoader );
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader( loader );
|
Thread.currentThread().setContextClassLoader( loader );
|
||||||
printURLClassPath();
|
this.getLog().info( "new classloader:" );
|
||||||
|
printURLClassPath( Thread.currentThread().getContextClassLoader(), "" );
|
||||||
return originalLoader;
|
return originalLoader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printURLClassPath()
|
public void printURLClassPath( ClassLoader sysClassLoader, String s )
|
||||||
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
//Get the Classloader
|
//Get the Classloader
|
||||||
ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
|
|
||||||
//Get the URLs
|
//Get the URLs
|
||||||
URL[] urls = ( (URLClassLoader) sysClassLoader ).getURLs();
|
URL[] urls;
|
||||||
this.getLog().info( "Added to Classpath:" );
|
if ( sysClassLoader instanceof URLClassLoader )
|
||||||
|
{
|
||||||
|
urls = ( (URLClassLoader) sysClassLoader ).getURLs();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Field f = sysClassLoader.getClass().getDeclaredField( "realm" );
|
||||||
|
f.setAccessible( true );
|
||||||
|
ClassRealm r = (ClassRealm) f.get( sysClassLoader );
|
||||||
|
urls = r.getConstituents();
|
||||||
|
}
|
||||||
|
catch ( NoSuchFieldException e )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException( "mee ", e );
|
||||||
|
}
|
||||||
|
catch ( IllegalAccessException e )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException( "mee ", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
for ( int i = 0; i < urls.length; i++ )
|
for ( int i = 0; i < urls.length; i++ )
|
||||||
{
|
{
|
||||||
this.getLog().info( urls[i].getFile() );
|
this.getLog().info( s + urls[i].getFile() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( sysClassLoader.getParent() != null )
|
||||||
|
{
|
||||||
|
printURLClassPath( sysClassLoader.getParent(), s + " " );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue