From 945af4835915ac254924a8be367925a979f12d78 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Mon, 26 Sep 2005 21:19:07 +0000 Subject: [PATCH] o doing a quick pass at integrating the fork mojo into the embedder git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291748 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/embedder/MavenEmbedder.java | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 0b15028afa..3d99f6b8c5 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -48,14 +48,15 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti import org.codehaus.plexus.embed.Embedder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.dag.CycleDetectedException; +import org.codehaus.plexus.util.DirectoryScanner; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.List; -import java.util.Collections; import java.util.ArrayList; +import java.util.Iterator; /** * Class intended to be used by clients who wish to embed Maven into their applications @@ -259,7 +260,7 @@ public class MavenEmbedder return runtimeInfo; } - private void execute( MavenProject project, List goals, EventDispatcher eventDispatcher, File executionRootDirectory ) + public void execute( MavenProject project, List goals, EventDispatcher eventDispatcher, File executionRootDirectory ) throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException { List projects = new ArrayList(); @@ -290,6 +291,55 @@ public class MavenEmbedder } } + 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; + } + + 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 // ----------------------------------------------------------------------