Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
Expand All @@ -29,6 +30,7 @@
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;

/**
* Maven starter, from a provided Maven home directory.
Expand All @@ -37,22 +39,51 @@
*/
public class BootstrapMainStarter
{
public void start( String[] args, Path mavenHome )
public void start( String[] args, Path mavenHome, Properties properties )
throws Exception
{
final Path mavenJar = findLauncherJar( mavenHome );
URLClassLoader contextClassLoader = new URLClassLoader( new URL[] { mavenJar.toUri().toURL() },
ClassLoader.getSystemClassLoader().getParent() );
ClassLoader.getSystemClassLoader().getParent() );

// can be useful to leak the classloader with some daemon mojo but generally a wrong idea so off by default
if ( Boolean.parseBoolean( properties.getProperty( getClass().getName() + ".leakClassloader" ) ) )
{
doStart( args, mavenHome, properties, contextClassLoader );
return;
}

try ( final URLClassLoader ref = contextClassLoader )
{
doStart( args, mavenHome, properties, contextClassLoader );
}
}

private void doStart( final String[] args, final Path mavenHome,
final Properties properties,
final URLClassLoader contextClassLoader )
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException
{
Thread.currentThread().setContextClassLoader( contextClassLoader );
Class<?> mainClass = contextClassLoader.loadClass( "org.codehaus.plexus.classworlds.launcher.Launcher" );

System.setProperty( "maven.home", mavenHome.toAbsolutePath().toString() );
System.setProperty( "classworlds.conf", mavenHome.resolve( "bin/m2.conf" ).toAbsolutePath().toString() );
System.setProperty( "classworlds.conf", getClassworldsConf( properties, mavenHome ) );

Method mainMethod = mainClass.getMethod( "main", String[].class );
mainMethod.invoke( null, new Object[] { args } );
}

private String getClassworldsConf( Properties properties, Path mavenHome )
{
final String override = properties.getProperty( "classworlds.conf" );
if ( override != null )
{
return override;
}
return mavenHome.resolve( "bin/m2.conf" ).toAbsolutePath().toString();
}

private Path findLauncherJar( Path mavenHome )
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void execute( String[] args, Installer install, BootstrapMainStarter boot
throws Exception
{
Path mavenHome = install.createDist( config );
bootstrapMainStarter.start( args, mavenHome );
bootstrapMainStarter.start( args, mavenHome, properties );
}

private String getProperty( String propertyName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ public void executeInstallAndLaunch()
{
WrapperExecutor wrapper = WrapperExecutor.forProjectDirectory( propertiesFile );

wrapper.execute( new String[] { "arg" }, install, start );
final String[] args = { "arg" };
wrapper.execute( args, install, start );
verify( install ).createDist( Mockito.any( WrapperConfiguration.class ) );
verify( start ).start( new String[] { "arg" }, mockInstallDir );
verify( start ).start(
Mockito.eq( args ),
Mockito.eq( mockInstallDir ),
Mockito.any( Properties.class ) );
}

@Test( )
Expand Down