maven-embedder-2.0.4/0000755000175000001440000000000011120055670013247 5ustar ludousersmaven-embedder-2.0.4/notes.txt0000644000175000001440000000160510320112646015140 0ustar ludousers- surefire needs to feed into the logging - maven/plexus archiver needs to be fixed -- to generate source folders for eclipse project from m2 pom.xml we need to run generate-sources phase, so all plugins registered for this phase will be kicked of and will register target folders for compilation. Ideally it would be nice to ask these plugins for the target folders, but Brett said it will be only in 2.1, so I guess we'll have to actually run these plugins and generate code. -- In order to nicely show all the errors and events in the IDE UI We need to have two messages for EACH event/error: -- the short description (in Eclipse it can be used in Problems view) -- detailed description (can be used in annotation/editors markers) -- What are all the settings that must be provided? Ones that can be set and what the default values would be if they aren't set. maven-embedder-2.0.4/src/0000755000175000001440000000000011120055670014036 5ustar ludousersmaven-embedder-2.0.4/src/test/0000755000175000001440000000000011120055670015015 5ustar ludousersmaven-embedder-2.0.4/src/test/java/0000755000175000001440000000000011120055670015736 5ustar ludousersmaven-embedder-2.0.4/src/test/java/org/0000755000175000001440000000000011120055670016525 5ustar ludousersmaven-embedder-2.0.4/src/test/java/org/apache/0000755000175000001440000000000011120055670017746 5ustar ludousersmaven-embedder-2.0.4/src/test/java/org/apache/maven/0000755000175000001440000000000011120055670021054 5ustar ludousersmaven-embedder-2.0.4/src/test/java/org/apache/maven/embedder/0000755000175000001440000000000011120055670022623 5ustar ludousersmaven-embedder-2.0.4/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java0000644000175000001440000001210310324571625027031 0ustar ludouserspackage org.apache.maven.embedder; import junit.framework.TestCase; import org.apache.maven.artifact.Artifact; import org.apache.maven.cli.ConsoleDownloadMonitor; import org.apache.maven.model.Model; import org.apache.maven.monitor.event.DefaultEventMonitor; import org.apache.maven.monitor.event.EventMonitor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.util.Collections; import java.util.List; import java.util.Properties; import java.util.Set; public class MavenEmbedderTest extends TestCase { private String basedir; private MavenEmbedder maven; protected void setUp() throws Exception { super.setUp(); basedir = System.getProperty( "basedir" ); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); maven = new MavenEmbedder(); maven.setClassLoader( classLoader ); maven.setLogger( new MavenEmbedderConsoleLogger() ); maven.start(); } protected void tearDown() throws Exception { maven.stop(); } public void testMavenEmbedder() throws Exception { modelReadingTest(); projectReadingTest(); } // ---------------------------------------------------------------------- // Goal/Phase execution tests // ---------------------------------------------------------------------- public void testPhaseExecution() throws Exception { File testDirectory = new File( basedir, "src/test/embedder-test-project" ); File targetDirectory = new File( basedir, "target/embedder-test-project" ); FileUtils.copyDirectoryStructure( testDirectory, targetDirectory ); File pomFile = new File( targetDirectory, "pom.xml" ); MavenProject pom = maven.readProjectWithDependencies( pomFile ); EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) ); maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), new Properties(), targetDirectory ); File jar = new File( targetDirectory, "target/embedder-test-project-1.0-SNAPSHOT.jar" ); assertTrue( jar.exists() ); } // ---------------------------------------------------------------------- // Test mock plugin metadata // ---------------------------------------------------------------------- public void testMockPluginMetadata() throws Exception { List plugins = maven.getAvailablePlugins(); SummaryPluginDescriptor spd = (SummaryPluginDescriptor) plugins.get( 0 ); assertNotNull( spd ); PluginDescriptor pd = maven.getPluginDescriptor( spd ); assertNotNull( pd ); assertEquals( "org.apache.maven.plugins", pd.getGroupId() ); } // ---------------------------------------------------------------------- // Lifecycle phases // ---------------------------------------------------------------------- public void testRetrievingLifecyclePhases() throws Exception { List phases = maven.getLifecyclePhases(); assertEquals( "validate", (String) phases.get( 0 ) ); assertEquals( "initialize", (String) phases.get( 1 ) ); assertEquals( "generate-sources", (String) phases.get( 2 ) ); } // ---------------------------------------------------------------------- // Repository // ---------------------------------------------------------------------- public void testLocalRepositoryRetrieval() throws Exception { assertNotNull( maven.getLocalRepository().getBasedir() ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- protected void modelReadingTest() throws Exception { // ---------------------------------------------------------------------- // Test model reading // ---------------------------------------------------------------------- Model model = maven.readModel( getPomFile() ); assertEquals( "org.apache.maven", model.getGroupId() ); } protected void projectReadingTest() throws Exception { MavenProject project = maven.readProjectWithDependencies( getPomFile() ); assertEquals( "org.apache.maven", project.getGroupId() ); Set artifacts = project.getArtifacts(); assertEquals( 1, artifacts.size() ); Artifact artifact = (Artifact) artifacts.iterator().next(); } // ---------------------------------------------------------------------- // Internal Utilities // ---------------------------------------------------------------------- protected File getPomFile() { return new File( basedir, "src/test/resources/pom.xml" ); } } maven-embedder-2.0.4/src/test/embedder-test-project/0000755000175000001440000000000011120055670021205 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/0000755000175000001440000000000011120055670021774 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/0000755000175000001440000000000011120055670022753 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/java/0000755000175000001440000000000011120055670023674 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/java/org/0000755000175000001440000000000011120055670024463 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/java/org/apache/0000755000175000001440000000000011120055670025704 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/java/org/apache/maven/0000755000175000001440000000000011120055670027012 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/test/java/org/apache/maven/AppTest.java0000644000175000001440000000120410316072357031241 0ustar ludouserspackage org.apache.maven; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } } maven-embedder-2.0.4/src/test/embedder-test-project/src/main/0000755000175000001440000000000011120055670022720 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/main/java/0000755000175000001440000000000011120055670023641 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/main/java/org/0000755000175000001440000000000011120055670024430 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/main/java/org/apache/0000755000175000001440000000000011120055670025651 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/main/java/org/apache/maven/0000755000175000001440000000000011120055670026757 5ustar ludousersmaven-embedder-2.0.4/src/test/embedder-test-project/src/main/java/org/apache/maven/App.java0000644000175000001440000000026310316072357030352 0ustar ludouserspackage org.apache.maven; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); } } maven-embedder-2.0.4/src/test/embedder-test-project/pom.xml0000644000175000001440000000124510316072357022533 0ustar ludousers 4.0.0 org.apache.maven embedder-test-project jar 1.0-SNAPSHOT Maven Quick Start Archetype http://maven.apache.org junit junit 3.8.1 test maven-embedder-2.0.4/src/test/resources/0000755000175000001440000000000011120055670017027 5ustar ludousersmaven-embedder-2.0.4/src/test/resources/pom.xml0000644000175000001440000000174110315541067020354 0ustar ludousers 4.0.0 org.apache.maven maven-model Maven Model 2.0-beta-2-SNAPSHOT Maven Model org.codehaus.modello modello-maven-plugin xpp3-writer java xpp3-reader xsd 4.0.0 maven.mdo plexus plexus-utils 1.0.2 maven-embedder-2.0.4/src/main/0000755000175000001440000000000011120055670014762 5ustar ludousersmaven-embedder-2.0.4/src/main/assembly/0000755000175000001440000000000011120055670016601 5ustar ludousersmaven-embedder-2.0.4/src/main/assembly/dep.xml0000644000175000001440000000177010362110266020100 0ustar ludousers dep jar false target/classes / / true runtime junit:junit commons-lang:commons-lang commons-logging:commons-logging commons-cli:commons-cli plexus:plexus-container-default maven-embedder-2.0.4/src/main/java/0000755000175000001440000000000011120055670015703 5ustar ludousersmaven-embedder-2.0.4/src/main/java/org/0000755000175000001440000000000011120055670016472 5ustar ludousersmaven-embedder-2.0.4/src/main/java/org/apache/0000755000175000001440000000000011120055670017713 5ustar ludousersmaven-embedder-2.0.4/src/main/java/org/apache/maven/0000755000175000001440000000000011120055670021021 5ustar ludousersmaven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/0000755000175000001440000000000011120055670022570 5ustar ludousersmaven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/MavenEmbedderConsoleLogger.java0000644000175000001440000000544710317361660030634 0ustar ludouserspackage org.apache.maven.embedder;/* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Logger sending everything to the standard output streams. * This is mainly for the cases when you have a utility that * does not have a logger to supply. * * @author Avalon Development Team * @version $Id: MavenEmbedderConsoleLogger.java 292888 2005-10-01 01:17:36Z jvanzyl $ */ public final class MavenEmbedderConsoleLogger extends AbstractMavenEmbedderLogger { public void debug( String message, Throwable throwable ) { if ( isDebugEnabled() ) { System.out.print( "[ maven embedder DEBUG] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void info( String message, Throwable throwable ) { if ( isInfoEnabled() ) { System.out.print( "[ maven embedder INFO] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void warn( String message, Throwable throwable ) { if ( isWarnEnabled() ) { System.out.print( "[ maven embedder WARNING] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void error( String message, Throwable throwable ) { if ( isErrorEnabled() ) { System.out.print( "[ maven embedder ERROR] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } public void fatalError( String message, Throwable throwable ) { if ( isFatalErrorEnabled() ) { System.out.print( "[ maven embedder FATAL ERROR] " ); System.out.println( message ); if ( null != throwable ) { throwable.printStackTrace( System.out ); } } } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/PlexusLoggerAdapter.java0000644000175000001440000000543110320271410027350 0ustar ludouserspackage org.apache.maven.embedder; import org.codehaus.plexus.logging.Logger;/* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @version $Id: PlexusLoggerAdapter.java 293410 2005-10-03 18:06:00Z jdcasey $ */ public class PlexusLoggerAdapter implements Logger { private MavenEmbedderLogger logger; public PlexusLoggerAdapter( MavenEmbedderLogger logger ) { this.logger = logger; } public void debug( String message ) { logger.debug( message ); } public void debug( String message, Throwable throwable ) { logger.debug( message, throwable ); } public boolean isDebugEnabled() { return logger.isDebugEnabled(); } public void info( String message ) { logger.info( message ); } public void info( String message, Throwable throwable ) { logger.info( message, throwable ); } public boolean isInfoEnabled() { return logger.isInfoEnabled(); } public void warn( String message ) { logger.warn( message ); } public void warn( String message, Throwable throwable ) { logger.warn( message, throwable ); } public boolean isWarnEnabled() { return logger.isWarnEnabled(); } public void error( String message ) { logger.error( message ); } public void error( String message, Throwable throwable ) { logger.error( message ); } public boolean isErrorEnabled() { return logger.isErrorEnabled(); } public void fatalError( String message ) { logger.fatalError( message ); } public void fatalError( String message, Throwable throwable ) { logger.fatalError( message, throwable ); } public boolean isFatalErrorEnabled() { return logger.isFatalErrorEnabled(); } public void setThreshold( int i ) { logger.setThreshold( i ); } public int getThreshold() { return logger.getThreshold(); } public String getName() { return toString(); } public Logger getChildLogger( String name ) { return this; } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/AbstractMavenEmbedderLogger.java0000644000175000001440000000521610317361660030767 0ustar ludouserspackage org.apache.maven.embedder; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Trygve Laugstøl * @version $Id: AbstractMavenEmbedderLogger.java 292888 2005-10-01 01:17:36Z jvanzyl $ */ public abstract class AbstractMavenEmbedderLogger implements MavenEmbedderLogger { private int threshold = MavenEmbedderLogger.LEVEL_INFO; private String name; public int getThreshold() { return threshold; } public void setThreshold( int threshold ) { this.threshold = threshold; } public String getName() { return name; } public void debug( String message ) { debug( message, null ); } public boolean isDebugEnabled() { return threshold <= LEVEL_DEBUG; } public void info( String message ) { info( message, null ); } public boolean isInfoEnabled() { return threshold <= LEVEL_INFO; } public void warn( String message ) { warn( message, null ); } public boolean isWarnEnabled() { return threshold <= LEVEL_WARN; } public void error( String message ) { error( message, null ); } public boolean isErrorEnabled() { return threshold <= LEVEL_ERROR; } public void fatalError( String message ) { fatalError( message, null ); } public boolean isFatalErrorEnabled() { return threshold <= LEVEL_FATAL; } protected boolean isValidThreshold( int threshold ) { if ( threshold == LEVEL_DEBUG ) { return true; } if ( threshold == LEVEL_INFO ) { return true; } if ( threshold == LEVEL_WARN ) { return true; } if ( threshold == LEVEL_ERROR ) { return true; } if ( threshold == LEVEL_FATAL ) { return true; } if ( threshold == LEVEL_DISABLED ) { return true; } return false; } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/MavenEmbedderLoggerManager.java0000644000175000001440000000761410317361660030602 0ustar ludouserspackage org.apache.maven.embedder; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.codehaus.plexus.logging.AbstractLoggerManager; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.LoggerManager; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; /** * This is a simple logger manager that will only write the logging statements to the console. *

* Sample configuration: *

 * 
 *   org.codehaus.plexus.logging.ConsoleLoggerManager
 *   
 *     DEBUG
 *   
 * 
 * 
* * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: MavenEmbedderLoggerManager.java 292888 2005-10-01 01:17:36Z jvanzyl $ */ public class MavenEmbedderLoggerManager extends AbstractLoggerManager implements LoggerManager, Initializable { /** * Message of this level or higher will be logged. *

* This field is set by the plexus container thus the name is 'threshold'. The field * currentThreshold contains the current setting of the threshold. */ private String threshold = "info"; private int currentThreshold; private Logger logger; public MavenEmbedderLoggerManager( Logger logger ) { this.logger = logger; } public void initialize() { debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." ); currentThreshold = parseThreshold( threshold ); if ( currentThreshold == -1 ) { debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." ); currentThreshold = Logger.LEVEL_DEBUG; } } public void setThreshold( int currentThreshold ) { this.currentThreshold = currentThreshold; } /** * @return Returns the threshold. */ public int getThreshold() { return currentThreshold; } public void setThreshold( String role, String roleHint, int threshold ) { } public int getThreshold( String role, String roleHint ) { return currentThreshold; } public Logger getLoggerForComponent( String role, String roleHint ) { return logger; } public void returnComponentLogger( String role, String roleHint ) { } public int getActiveLoggerCount() { return 1; } private int parseThreshold( String text ) { text = text.trim().toLowerCase(); if ( text.equals( "debug" ) ) { return ConsoleLogger.LEVEL_DEBUG; } else if ( text.equals( "info" ) ) { return ConsoleLogger.LEVEL_INFO; } else if ( text.equals( "warn" ) ) { return ConsoleLogger.LEVEL_WARN; } else if ( text.equals( "error" ) ) { return ConsoleLogger.LEVEL_ERROR; } else if ( text.equals( "fatal" ) ) { return ConsoleLogger.LEVEL_FATAL; } return -1; } /** * Remove this method and all references when this code is verified. * * @param msg */ private void debug( String msg ) { } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/SummaryPluginDescriptor.java0000644000175000001440000000246710317246246030327 0ustar ludouserspackage org.apache.maven.embedder;/* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @version $Id: SummaryPluginDescriptor.java 292750 2005-09-30 14:33:10Z jdcasey $ */ public class SummaryPluginDescriptor { private String groupId; private String artifactId; private String name; public SummaryPluginDescriptor( String groupId, String artifactId, String name ) { this.groupId = groupId; this.artifactId = artifactId; this.name = name; } public String getGroupId() { return groupId; } public String getArtifactId() { return artifactId; } public String getName() { return name; } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/MavenEmbedderException.java0000644000175000001440000000210110315404641030003 0ustar ludouserspackage org.apache.maven.embedder; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @version $Id:$ */ public class MavenEmbedderException extends Exception { public MavenEmbedderException( String message ) { super( message ); } public MavenEmbedderException( Throwable cause ) { super( cause ); } public MavenEmbedderException( String message, Throwable cause ) { super( message, cause ); } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/MavenEmbedder.java0000644000175000001440000006301010376677202026146 0ustar ludouserspackage org.apache.maven.embedder; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.maven.BuildFailureException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.ReactorManager; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.monitor.event.DefaultEventDispatcher; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventMonitor; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.DuplicateProjectException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.settings.MavenSettingsBuilder; import org.apache.maven.settings.RuntimeInfo; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.events.TransferListener; import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.DuplicateRealmException; import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.embed.Embedder; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.dag.CycleDetectedException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Properties; /** * Class intended to be used by clients who wish to embed Maven into their applications * * @author Jason van Zyl */ public class MavenEmbedder { public static final String userHome = System.getProperty( "user.home" ); // ---------------------------------------------------------------------- // Embedder // ---------------------------------------------------------------------- private Embedder embedder; // ---------------------------------------------------------------------- // Components // ---------------------------------------------------------------------- private MavenProjectBuilder mavenProjectBuilder; private ArtifactRepositoryFactory artifactRepositoryFactory; private MavenSettingsBuilder settingsBuilder; private LifecycleExecutor lifecycleExecutor; private WagonManager wagonManager; private MavenXpp3Reader modelReader; private MavenXpp3Writer modelWriter; private ProfileManager profileManager; private PluginDescriptorBuilder pluginDescriptorBuilder; private ArtifactFactory artifactFactory; private ArtifactResolver artifactResolver; private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- private Settings settings; private ArtifactRepository localRepository; private File localRepositoryDirectory; private ClassLoader classLoader; private MavenEmbedderLogger logger; // ---------------------------------------------------------------------- // User options // ---------------------------------------------------------------------- // release plugin uses this but in IDE there will probably always be some form of interaction. private boolean interactiveMode; private boolean offline; private String globalChecksumPolicy; /** * This option determines whether the embedder is to be aligned to the user * installation. */ private boolean alignWithUserInstallation; // ---------------------------------------------------------------------- // Accessors // ---------------------------------------------------------------------- public void setInteractiveMode( boolean interactiveMode ) { this.interactiveMode = interactiveMode; } public boolean isInteractiveMode() { return interactiveMode; } public void setOffline( boolean offline ) { this.offline = offline; } public boolean isOffline() { return offline; } public void setGlobalChecksumPolicy( String globalChecksumPolicy ) { this.globalChecksumPolicy = globalChecksumPolicy; } public String getGlobalChecksumPolicy() { return globalChecksumPolicy; } public boolean isAlignWithUserInstallation() { return alignWithUserInstallation; } public void setAlignWithUserInstallation( boolean alignWithUserInstallation ) { this.alignWithUserInstallation = alignWithUserInstallation; } /** * Set the classloader to use with the maven embedder. * * @param classLoader */ public void setClassLoader( ClassLoader classLoader ) { this.classLoader = classLoader; } public ClassLoader getClassLoader() { return classLoader; } public void setLocalRepositoryDirectory( File localRepositoryDirectory ) { this.localRepositoryDirectory = localRepositoryDirectory; } public File getLocalRepositoryDirectory() { return localRepositoryDirectory; } public ArtifactRepository getLocalRepository() { return localRepository; } public MavenEmbedderLogger getLogger() { return logger; } public void setLogger( MavenEmbedderLogger logger ) { this.logger = logger; } // ---------------------------------------------------------------------- // Embedder Client Contract // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Model // ---------------------------------------------------------------------- public Model readModel( File model ) throws XmlPullParserException, FileNotFoundException, IOException { return modelReader.read( new FileReader( model ) ); } public void writeModel( Writer writer, Model model ) throws IOException { modelWriter.write( writer, model ); } // ---------------------------------------------------------------------- // Project // ---------------------------------------------------------------------- public MavenProject readProject( File mavenProject ) throws ProjectBuildingException { return mavenProjectBuilder.build( mavenProject, localRepository, profileManager ); } public MavenProject readProjectWithDependencies( File mavenProject, TransferListener transferListener ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException { return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager, transferListener ); } public MavenProject readProjectWithDependencies( File mavenProject ) throws ProjectBuildingException, ArtifactResolutionException, ArtifactNotFoundException { return mavenProjectBuilder.buildWithDependencies( mavenProject, localRepository, profileManager ); } public List collectProjects( File basedir, String[] includes, String[] excludes ) throws MojoExecutionException { List projects = new ArrayList(); List poms = getPomFiles( basedir, includes, excludes ); for ( Iterator i = poms.iterator(); i.hasNext(); ) { File pom = (File) i.next(); try { MavenProject p = readProject( pom ); projects.add( p ); } catch ( ProjectBuildingException e ) { throw new MojoExecutionException( "Error loading " + pom, e ); } } return projects; } // ---------------------------------------------------------------------- // Artifacts // ---------------------------------------------------------------------- public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) { return artifactFactory.createArtifact( groupId, artifactId, version, scope, type ); } public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier ) { return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); } public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactResolutionException, ArtifactNotFoundException { artifactResolver.resolve( artifact, remoteRepositories, localRepository ); } // ---------------------------------------------------------------------- // Plugins // ---------------------------------------------------------------------- public List getAvailablePlugins() { List plugins = new ArrayList(); plugins.add( makeMockPlugin( "org.apache.maven.plugins", "maven-jar-plugin", "Maven Jar Plug-in" ) ); plugins.add( makeMockPlugin( "org.apache.maven.plugins", "maven-compiler-plugin", "Maven Compiler Plug-in" ) ); return plugins; } public PluginDescriptor getPluginDescriptor( SummaryPluginDescriptor summaryPluginDescriptor ) throws MavenEmbedderException { PluginDescriptor pluginDescriptor; try { InputStream is = classLoader.getResourceAsStream( "/plugins/" + summaryPluginDescriptor.getArtifactId() + ".xml" ); pluginDescriptor = pluginDescriptorBuilder.build( new InputStreamReader( is ) ); } catch ( PlexusConfigurationException e ) { throw new MavenEmbedderException( "Error retrieving plugin descriptor.", e ); } return pluginDescriptor; } private SummaryPluginDescriptor makeMockPlugin( String groupId, String artifactId, String name ) { return new SummaryPluginDescriptor( groupId, artifactId, name ); } // ---------------------------------------------------------------------- // Execution of phases/goals // ---------------------------------------------------------------------- // TODO: should we allow the passing in of a settings object so that everything can be taken from the client env // TODO: transfer listener // TODO: logger public void execute( MavenProject project, List goals, EventMonitor eventMonitor, TransferListener transferListener, Properties properties, File executionRootDirectory ) throws CycleDetectedException, LifecycleExecutionException, BuildFailureException, DuplicateProjectException { execute( Collections.singletonList( project ), goals, eventMonitor, transferListener, properties, executionRootDirectory ); } public void execute( List projects, List goals, EventMonitor eventMonitor, TransferListener transferListener, Properties properties, File executionRootDirectory ) throws CycleDetectedException, LifecycleExecutionException, BuildFailureException, DuplicateProjectException { ReactorManager rm = new ReactorManager( projects ); EventDispatcher eventDispatcher = new DefaultEventDispatcher(); eventDispatcher.addEventMonitor( eventMonitor ); // If this option is set the exception seems to be hidden ... //rm.setFailureBehavior( ReactorManager.FAIL_AT_END ); rm.setFailureBehavior( ReactorManager.FAIL_FAST ); MavenSession session = new MavenSession( embedder.getContainer(), settings, localRepository, eventDispatcher, rm, goals, executionRootDirectory.getAbsolutePath(), properties, new Date() ); session.setUsingPOMsFromFilesystem( true ); if ( transferListener != null ) { wagonManager.setDownloadMonitor( transferListener ); } // ---------------------------------------------------------------------- // Maven should not be using system properties internally but because // it does for now I'll just take properties that are handed to me // and set them so that the plugin expression evaluator will work // as expected. // ---------------------------------------------------------------------- if ( properties != null ) { for ( Iterator i = properties.keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); String value = properties.getProperty( key ); System.setProperty( key, value ); } } lifecycleExecutor.execute( session, rm, session.getEventDispatcher() ); } // ---------------------------------------------------------------------- // Lifecycle information // ---------------------------------------------------------------------- public List getLifecyclePhases() throws MavenEmbedderException { List phases = new ArrayList(); ComponentDescriptor descriptor = embedder.getContainer().getComponentDescriptor( LifecycleExecutor.ROLE ); PlexusConfiguration configuration = descriptor.getConfiguration(); PlexusConfiguration[] phasesConfigurations = configuration.getChild( "lifecycles" ).getChild( 0 ).getChild( "phases" ).getChildren( "phase" ); try { for ( int i = 0; i < phasesConfigurations.length; i++ ) { phases.add( phasesConfigurations[i].getValue() ); } } catch ( PlexusConfigurationException e ) { throw new MavenEmbedderException( "Cannot retrieve default lifecycle phasesConfigurations.", e ); } return phases; } // ---------------------------------------------------------------------- // Remote Repository // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Local Repository // ---------------------------------------------------------------------- public static final String DEFAULT_LOCAL_REPO_ID = "local"; public static final String DEFAULT_LAYOUT_ID = "default"; public ArtifactRepository createLocalRepository( File localRepository ) throws ComponentLookupException { return createLocalRepository( localRepository.getAbsolutePath(), DEFAULT_LOCAL_REPO_ID ); } public ArtifactRepository createLocalRepository( Settings settings ) throws ComponentLookupException { return createLocalRepository( settings.getLocalRepository(), DEFAULT_LOCAL_REPO_ID ); } public ArtifactRepository createLocalRepository( String url, String repositoryId ) throws ComponentLookupException { if ( !url.startsWith( "file:" ) ) { url = "file://" + url; } return createRepository( url, repositoryId ); } public ArtifactRepository createRepository( String url, String repositoryId ) throws ComponentLookupException { // snapshots vs releases // offline = to turning the update policy off //TODO: we'll need to allow finer grained creation of repositories but this will do for now String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy ); } // ---------------------------------------------------------------------- // Internal utility code // ---------------------------------------------------------------------- private RuntimeInfo createRuntimeInfo( Settings settings ) { RuntimeInfo runtimeInfo = new RuntimeInfo( settings ); runtimeInfo.setPluginUpdateOverride( Boolean.FALSE ); return runtimeInfo; } private List getPomFiles( File basedir, String[] includes, String[] excludes ) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( basedir ); scanner.setIncludes( includes ); scanner.setExcludes( excludes ); scanner.scan(); List poms = new ArrayList(); for ( int i = 0; i < scanner.getIncludedFiles().length; i++ ) { poms.add( new File( basedir, scanner.getIncludedFiles()[i] ) ); } return poms; } // ---------------------------------------------------------------------- // Lifecycle // ---------------------------------------------------------------------- public void start() throws MavenEmbedderException { detectUserInstallation(); // ---------------------------------------------------------------------- // Set the maven.home system property which is need by components like // the plugin registry builder. // ---------------------------------------------------------------------- if ( classLoader == null ) { throw new IllegalStateException( "A classloader must be specified using setClassLoader(ClassLoader)." ); } embedder = new Embedder(); if ( logger != null ) { embedder.setLoggerManager( new MavenEmbedderLoggerManager( new PlexusLoggerAdapter( logger ) ) ); } try { ClassWorld classWorld = new ClassWorld(); classWorld.newRealm( "plexus.core", classLoader ); embedder.start( classWorld ); // ---------------------------------------------------------------------- // Lookup each of the components we need to provide the desired // client interface. // ---------------------------------------------------------------------- modelReader = new MavenXpp3Reader(); modelWriter = new MavenXpp3Writer(); pluginDescriptorBuilder = new PluginDescriptorBuilder(); profileManager = new DefaultProfileManager( embedder.getContainer() ); mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE ); // ---------------------------------------------------------------------- // Artifact related components // ---------------------------------------------------------------------- artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE ); artifactFactory = (ArtifactFactory) embedder.lookup( ArtifactFactory.ROLE ); artifactResolver = (ArtifactResolver) embedder.lookup( ArtifactResolver.ROLE ); defaultArtifactRepositoryLayout = (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, DEFAULT_LAYOUT_ID ); lifecycleExecutor = (LifecycleExecutor) embedder.lookup( LifecycleExecutor.ROLE ); wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE ); createMavenSettings(); profileManager.loadSettingsProfiles( settings ); localRepository = createLocalRepository( settings ); } catch ( PlexusContainerException e ) { throw new MavenEmbedderException( "Cannot start Plexus embedder.", e ); } catch ( DuplicateRealmException e ) { throw new MavenEmbedderException( "Cannot create Classworld realm for the embedder.", e ); } catch ( ComponentLookupException e ) { throw new MavenEmbedderException( "Cannot lookup required component.", e ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private void detectUserInstallation() { if ( new File( userHome, ".m2" ).exists() ) { alignWithUserInstallation = true; } } /** * Create the Settings that will be used with the embedder. If we are aligning with the user * installation then we lookup the standard settings builder and use that to create our * settings. Otherwise we constructs a settings object and populate the information * ourselves. * * @throws MavenEmbedderException * @throws ComponentLookupException */ private void createMavenSettings() throws MavenEmbedderException, ComponentLookupException { if ( alignWithUserInstallation ) { // ---------------------------------------------------------------------- // We will use the standard method for creating the settings. This // method reproduces the method of building the settings from the CLI // mode of operation. // ---------------------------------------------------------------------- settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE ); try { settings = settingsBuilder.buildSettings(); } catch ( IOException e ) { throw new MavenEmbedderException( "Error creating settings.", e ); } catch ( XmlPullParserException e ) { throw new MavenEmbedderException( "Error creating settings.", e ); } } else { if ( localRepository == null ) { throw new IllegalArgumentException( "When not aligning with a user install you must specify a local repository location using the setLocalRepositoryDirectory( File ) method." ); } settings = new Settings(); settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() ); settings.setRuntimeInfo( createRuntimeInfo( settings ) ); settings.setOffline( offline ); settings.setInteractiveMode( interactiveMode ); } } // ---------------------------------------------------------------------- // Lifecycle // ---------------------------------------------------------------------- public void stop() throws MavenEmbedderException { try { embedder.release( mavenProjectBuilder ); embedder.release( artifactRepositoryFactory ); embedder.release( settingsBuilder ); embedder.release( lifecycleExecutor ); } catch ( ComponentLifecycleException e ) { throw new MavenEmbedderException( "Cannot stop the embedder.", e ); } } } maven-embedder-2.0.4/src/main/java/org/apache/maven/embedder/MavenEmbedderLogger.java0000644000175000001440000000321410320271410027262 0ustar ludouserspackage org.apache.maven.embedder; /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @author Jason van Zyl * @version $Id: MavenEmbedderLogger.java 293410 2005-10-03 18:06:00Z jdcasey $ */ public interface MavenEmbedderLogger { int LEVEL_DEBUG = 0; int LEVEL_INFO = 1; int LEVEL_WARN = 2; int LEVEL_ERROR = 3; int LEVEL_FATAL = 4; int LEVEL_DISABLED = 5; void debug( String message ); void debug( String message, Throwable throwable ); boolean isDebugEnabled(); void info( String message ); void info( String message, Throwable throwable ); boolean isInfoEnabled(); void warn( String message ); void warn( String message, Throwable throwable ); boolean isWarnEnabled(); void error( String message ); void error( String message, Throwable throwable ); boolean isErrorEnabled(); void fatalError( String message ); void fatalError( String message, Throwable throwable ); boolean isFatalErrorEnabled(); void setThreshold( int threshold ); int getThreshold(); } maven-embedder-2.0.4/src/main/resources/0000755000175000001440000000000011120055670016774 5ustar ludousersmaven-embedder-2.0.4/src/main/resources/plugins/0000755000175000001440000000000011120055670020455 5ustar ludousersmaven-embedder-2.0.4/src/main/resources/plugins/maven-compiler-plugin.xml0000644000175000001440000003712010317062351025415 0ustar ludousers org.apache.maven.plugins maven-compiler-plugin 2.0-beta-2-SNAPSHOT compiler false true testCompile test false true false false false true test-compile org.apache.maven.plugin.TestCompilerMojo java per-lookup once-per-session basedir java.io.File true false The directory to run the compiler from if fork is true. buildDirectory java.io.File true false The target directory of the compiler if fork is true. classpathElements java.util.List true false Project test classpath. compileSourceRoots java.util.List true false The source directories containing the test-source to be compiled. compilerArguments java.util.LinkedHashMap false true Arguments to be passed to the compiler if fork is set to true. <p/> This is because the list of valid arguments passed to a Java compiler varies based on the compiler version. compilerId java.lang.String false true The compiler id of the compiler to use. compilerVersion java.lang.String false true Version of the compiler to use, ex. "1.3", "1.5" debug boolean false true Whether to include debugging information in the compiled class files. The default value is true. encoding java.lang.String false true The -encoding argument for the Java compiler executable java.lang.String false true The executable of the compiler to use. fork boolean false true Runs the compiler in a separate process. <p/> If not set the compiler will default to a executable. outputDirectory java.io.File true false The directory where compiled test classes go. outputFileName java.lang.String false true Used to control the name of the output file when compiling a set of sources to a single file. showDeprecation boolean false true Output source locations where deprecated APIs are used showWarnings boolean false true Output warnings source java.lang.String false true The -source argument for the Java compiler staleMillis int false true The granularity in milliseconds of the last modification date for testing whether a source needs recompilation target java.lang.String false true The -target argument for the Java compiler testExcludes java.util.Set false true A list of exclusion filters for the compiler. testIncludes java.util.Set false true A list of inclusion filters for the compiler. ${maven.compiler.debug} ${project.build.testOutputDirectory} ${project.build.directory} ${project.testClasspathElements} ${project.build.finalName} ${project.testCompileSourceRoots} ${lastModGranularityMs} ${basedir} org.codehaus.plexus.compiler.manager.CompilerManager compilerManager compile compile false true false false false true compile org.apache.maven.plugin.CompilerMojo java per-lookup once-per-session basedir java.io.File true false The directory to run the compiler from if fork is true. buildDirectory java.io.File true false The target directory of the compiler if fork is true. classpathElements java.util.List true false Project classpath. compileSourceRoots java.util.List true false The source directories containing the sources to be compiled. compilerArguments java.util.LinkedHashMap false true Arguments to be passed to the compiler if fork is set to true. <p/> This is because the list of valid arguments passed to a Java compiler varies based on the compiler version. compilerId java.lang.String false true The compiler id of the compiler to use. compilerVersion java.lang.String false true Version of the compiler to use, ex. "1.3", "1.5" debug boolean false true Whether to include debugging information in the compiled class files. The default value is true. encoding java.lang.String false true The -encoding argument for the Java compiler excludes java.util.Set false true A list of exclusion filters for the compiler. executable java.lang.String false true The executable of the compiler to use. fork boolean false true Runs the compiler in a separate process. <p/> If not set the compiler will default to a executable. includes java.util.Set false true A list of inclusion filters for the compiler. outputDirectory java.io.File true false The directory for compiled classes. outputFileName java.lang.String false true Used to control the name of the output file when compiling a set of sources to a single file. projectArtifact org.apache.maven.artifact.Artifact true false Project artifacts. showDeprecation boolean false true Output source locations where deprecated APIs are used showWarnings boolean false true Output warnings source java.lang.String false true The -source argument for the Java compiler staleMillis int false true The granularity in milliseconds of the last modification date for testing whether a source needs recompilation target java.lang.String false true The -target argument for the Java compiler ${maven.compiler.debug} ${project.build.outputDirectory} ${project.artifact} ${project.build.directory} ${project.compileClasspathElements} ${project.build.finalName} ${project.compileSourceRoots} ${lastModGranularityMs} ${basedir} org.codehaus.plexus.compiler.manager.CompilerManager compilerManager maven-embedder-2.0.4/src/main/resources/plugins/maven-jar-plugin.xml0000644000175000001440000000525010317062351024356 0ustar ludousers org.apache.maven.plugins maven-jar-plugin 2.0-beta-2-SNAPSHOT jar false true jar false true false false false true package org.apache.maven.plugin.jar.JarMojo java per-lookup once-per-session archive org.apache.maven.archiver.MavenArchiveConfiguration false true The maven archiver to use. basedir java.lang.String true false Directory containing the generated JAR. finalName jarName java.lang.String true true Name of the generated JAR. outputDirectory java.lang.String true false Directory containing the classes. project org.apache.maven.project.MavenProject true false The maven project. ${project.build.outputDirectory} ${project} ${project.build.directory} ${project.build.finalName} maven-embedder-2.0.4/pom.xml0000644000175000001440000000225110416554254014575 0ustar ludousers maven org.apache.maven 2.0 4.0.0 org.apache.maven maven-embedder Maven Embedder 2.0.4 maven-assembly-plugin src/main/assembly/dep.xml org.apache.maven maven-core ${mavenVersion} maven-checkstyle-plugin maven-pmd-plugin maven-project-info-reports-plugin 2.0.4 maven-embedder-2.0.4/run.sh0000755000175000001440000000026110375374542014426 0ustar ludousers#!/bin/sh mvn clean:clean assembly:assembly CLASSPATH=target/maven-embedder-2.1-SNAPSHOT-dep.jar javac -classpath $CLASSPATH Plugin.java java -classpath $CLASSPATH:. Plugin maven-embedder-2.0.4/Plugin.java0000644000175000001440000000316110320356305015351 0ustar ludousersimport org.apache.maven.cli.ConsoleDownloadMonitor; import org.apache.maven.embedder.*; import org.apache.maven.project.*; import org.apache.maven.monitor.event.*; import java.io.*; import java.util.*; import org.codehaus.plexus.logging.*; import org.codehaus.plexus.logging.console.*; public class Plugin { public Plugin() throws Exception { MavenEmbedder maven = new MavenEmbedder(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); maven.setClassLoader( classLoader ); maven.setLogger( new MavenEmbedderConsoleLogger() ); maven.start(); System.out.println( "Happy happy joy joy!" ); 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 ); EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) ); System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<"); maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), null, targetDirectory ); System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<"); } public static void main( String[] args ) throws Exception { Plugin plugin = new Plugin(); } }