mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
b4a87a494e
commit
fa1eaf9a2c
|
@ -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)." );
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue