2005-09-30 21:17:36 -04:00
|
|
|
import org.apache.maven.cli.ConsoleDownloadMonitor;
|
2005-09-26 15:21:34 -04:00
|
|
|
import org.apache.maven.embedder.*;
|
2005-09-27 10:42:04 -04:00
|
|
|
import org.apache.maven.project.*;
|
|
|
|
import org.apache.maven.monitor.event.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
2005-09-30 21:17:36 -04:00
|
|
|
import org.codehaus.plexus.logging.*;
|
|
|
|
import org.codehaus.plexus.logging.console.*;
|
2005-09-26 15:21:34 -04:00
|
|
|
|
|
|
|
public class Plugin
|
|
|
|
{
|
|
|
|
public Plugin()
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
MavenEmbedder maven = new MavenEmbedder();
|
|
|
|
|
|
|
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
|
|
|
|
|
|
maven.setClassLoader( classLoader );
|
2005-09-30 21:17:36 -04:00
|
|
|
|
|
|
|
maven.setLogger( new MavenEmbedderConsoleLogger() );
|
2005-09-26 15:21:34 -04:00
|
|
|
|
|
|
|
maven.start();
|
|
|
|
|
|
|
|
System.out.println( "Happy happy joy joy!" );
|
2005-09-27 10:42:04 -04:00
|
|
|
|
|
|
|
System.out.println( "Now build a project" );
|
|
|
|
|
|
|
|
File targetDirectory = new File( System.getProperty( "user.dir" ), "target/embedder-test-project" );
|
|
|
|
|
|
|
|
System.out.println( ">> " + targetDirectory );
|
|
|
|
|
|
|
|
File pomFile = new File( targetDirectory, "pom.xml" );
|
|
|
|
|
|
|
|
MavenProject pom = maven.readProjectWithDependencies( pomFile );
|
|
|
|
|
2005-09-30 21:17:36 -04:00
|
|
|
EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) );
|
|
|
|
|
|
|
|
System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<");
|
|
|
|
|
2005-10-03 21:37:09 -04:00
|
|
|
maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), null, targetDirectory );
|
2005-09-30 21:17:36 -04:00
|
|
|
|
|
|
|
System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<");
|
2005-09-26 15:21:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void main( String[] args )
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
Plugin plugin = new Plugin();
|
|
|
|
}
|
|
|
|
}
|