From fa1eaf9a2c94b50547cfad863c68f11b1f8c4f0e Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 29 Sep 2005 02:47:24 +0000 Subject: [PATCH] o provide the phases in the lifecycle by extracting the component descriptor and pull them out of the configuration. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@292380 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/embedder/MavenEmbedder.java | 61 ++++++++++--------- .../maven/embedder/MavenEmbedderTest.java | 16 +++++ 2 files changed, 48 insertions(+), 29 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 1448b41cac..067eb7a3f4 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 @@ -46,8 +46,10 @@ import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.DuplicateRealmException; import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.embed.Embedder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.dag.CycleDetectedException; @@ -127,8 +129,6 @@ public class MavenEmbedder private String globalChecksumPolicy; - private File mavenHome; - // ---------------------------------------------------------------------- // Accessors // ---------------------------------------------------------------------- @@ -228,16 +228,6 @@ public class MavenEmbedder return localRepositoryDirectory; } - public File getMavenHome() - { - return mavenHome; - } - - public void setMavenHome( File mavenHome ) - { - this.mavenHome = mavenHome; - } - // ---------------------------------------------------------------------- // Embedder Client Contract // ---------------------------------------------------------------------- @@ -379,6 +369,36 @@ public class MavenEmbedder } } + // ---------------------------------------------------------------------- + // 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( "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; + } + // ---------------------------------------------------------------------- // Internal utility code // ---------------------------------------------------------------------- @@ -475,23 +495,6 @@ public class MavenEmbedder // the plugin registry builder. // ---------------------------------------------------------------------- - // TODO: create a maven.home discovery method. - - if ( mavenHome == null ) - { - mavenHome = new File( userHome, "m2" ); - - if ( !mavenHome.exists() ) - { - if ( !mavenHome.mkdirs() ) - { - throw new IllegalStateException( "A maven home directory does not exist and cannot be created." ); - } - } - - System.setProperty( "maven.home", mavenHome.getAbsolutePath() ); - } - if ( classLoader == null ) { throw new IllegalStateException( "A classloader must be specified using setClassLoader(ClassLoader)." ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index e0bbe932f1..3a1d47e6cc 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -97,6 +97,22 @@ public class MavenEmbedderTest 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 ) ); + } + // ---------------------------------------------------------------------- // // ----------------------------------------------------------------------