[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:
Brett Leslie Porter 2006-02-21 11:25:51 +00:00
parent 73ba7305ce
commit 89e6008e13
2 changed files with 48 additions and 22 deletions

View File

@ -1,4 +1,4 @@
# it0094 currently fails. It is testing MNG-1898
it0094 currently fails. It is testing MNG-1898
it0092
# it0091 currrently fails. Not sure if there is an associated JIRA.
it0090

View File

@ -16,23 +16,21 @@
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.MojoExecutionException;
import org.apache.xerces.jaxp.SAXParserFactoryImpl;
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
*
* @requiresDependancyResolution test
* @goal enhance
*
* @phase compile
*/
public class Enhance
@ -60,10 +58,10 @@ public class Enhance
SAXParserFactory spf = SAXParserFactory.newInstance();
this.getLog().info( spf.toString() );
String t = "org/apache/xerces/jaxp/SAXParserFactoryImpl.class";
this.getLog().info(t);
URL url = originalLoader.getResource(t);
this.getLog().info( t );
URL url = originalLoader.getResource( t );
//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() );
}
@ -79,26 +77,54 @@ public class Enhance
URLClassLoader loader = null;
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
this.getLog().info( originalLoader.toString() );
this.getLog().info( "orig classloader:" );
printURLClassPath( Thread.currentThread().getContextClassLoader(), "" );
URL[] urls = new URL[0];
loader = new URLClassLoader( urls, originalLoader );
Thread.currentThread().setContextClassLoader( loader );
printURLClassPath();
this.getLog().info( "new classloader:" );
printURLClassPath( Thread.currentThread().getContextClassLoader(), "" );
return originalLoader;
}
public void printURLClassPath()
public void printURLClassPath( ClassLoader sysClassLoader, String s )
throws MojoExecutionException
{
//Get the Classloader
ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
//Get the URLs
URL[] urls = ( (URLClassLoader) sysClassLoader ).getURLs();
this.getLog().info( "Added to Classpath:" );
URL[] urls;
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++ )
{
this.getLog().info( urls[i].getFile() );
this.getLog().info( s + urls[i].getFile() );
}
if ( sysClassLoader.getParent() != null )
{
printURLClassPath( sysClassLoader.getParent(), s + " " );
}
}