in src/main/java/org/apache/maven/shared/verifier/Embedded3xLauncher.java [62:118]
public static Embedded3xLauncher createFromMavenHome( String mavenHome, String classworldConf, List<URL> classpath )
throws LauncherException
{
if ( mavenHome == null || mavenHome.length() <= 0 )
{
throw new LauncherException( "Invalid Maven home directory " + mavenHome );
}
System.setProperty( "maven.home", mavenHome );
File config;
if ( classworldConf != null )
{
config = new File( classworldConf );
}
else
{
config = new File( mavenHome, "bin/m2.conf" );
}
ClassLoader bootLoader = getBootLoader( mavenHome, classpath );
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( bootLoader );
try
{
Class<?> launcherClass = bootLoader.loadClass( "org.codehaus.plexus.classworlds.launcher.Launcher" );
Object launcher = launcherClass.newInstance();
Method configure = launcherClass.getMethod( "configure", new Class[] { InputStream.class } );
configure.invoke( launcher, new Object[] { new FileInputStream( config ) } );
Method getWorld = launcherClass.getMethod( "getWorld" );
Object classWorld = getWorld.invoke( launcher );
Method getMainClass = launcherClass.getMethod( "getMainClass" );
Class<?> cliClass = (Class<?>) getMainClass.invoke( launcher );
Constructor<?> newMavenCli = cliClass.getConstructor( new Class[] { classWorld.getClass() } );
Object mavenCli = newMavenCli.newInstance( new Object[] { classWorld } );
Class<?>[] parameterTypes = { String[].class, String.class, PrintStream.class, PrintStream.class };
Method doMain = cliClass.getMethod( "doMain", parameterTypes );
return new Embedded3xLauncher( mavenCli, doMain );
}
catch ( ReflectiveOperationException | IOException e )
{
throw new LauncherException( "Failed to initialize Laucher", e );
}
finally
{
Thread.currentThread().setContextClassLoader( oldClassLoader );
}
}