o very rough start at the embedding api

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291359 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2005-09-25 02:00:04 +00:00
parent c5c6c6b7b1
commit 6c6b24938d
7 changed files with 1053 additions and 0 deletions

4
maven-embedder/notes.txt Normal file
View File

@ -0,0 +1,4 @@
<eu> -- parse xml to in-memory model
<eu> -- run m2 (embedded): including running for downloading dependencies, building, archetypes, etc.
<eu> -- introspect available goals
<eu> -- introspect available plugins (low priority)

154
maven-embedder/pom.xml Normal file
View File

@ -0,0 +1,154 @@
<project>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.0-beta-2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<version>2.0-beta-2-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>RELEASE</version>
<configuration>
<descriptor>src/assemble/bin.xml</descriptor>
<finalName>maven-2.0-beta-1</finalName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<version>1.0-alpha-4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>1.0-alpha-4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-profile</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>1.0-alpha-4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-registry</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-input-handler</artifactId>
<version>1.0-alpha-2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-descriptor</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-monitor</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<version>2.0-beta-2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0-alpha-4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.21</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-clover-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<distributionManagement>
<site>
<id>website</id>
<url>scp://minotaur.apache.org//www/maven.apache.org/m2</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,339 @@
package 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.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.DefaultProfileManager;
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.Settings;
import org.apache.maven.settings.RuntimeInfo;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.classworlds.DuplicateRealmException;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.embed.Embedder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* Class intended to be used by clients who wish to embed Maven into their applications
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*/
public class MavenEmbedder
{
// ----------------------------------------------------------------------
// Embedder
// ----------------------------------------------------------------------
private Embedder embedder;
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactRepositoryFactory artifactRepositoryFactory;
private MavenSettingsBuilder settingsBuilder;
private MavenXpp3Reader modelReader;
private ProfileManager profileManager;
// ----------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------
private Settings settings;
private ArtifactRepository localRepository;
private File localRepositoryDirectory;
private ClassLoader classLoader;
// ----------------------------------------------------------------------
// User options
// ----------------------------------------------------------------------
private boolean pluginUpdateOverride;
private boolean checkLatestPluginVersion;
private boolean interactiveMode;
private boolean usePluginRegistry;
private boolean offline;
private boolean updateSnapshots;
private String globalChecksumPolicy;
public void setPluginUpdateOverride( boolean pluginUpdateOverride )
{
this.pluginUpdateOverride = pluginUpdateOverride;
}
public void setCheckLatestPluginVersion( boolean checkLatestPluginVersion )
{
this.checkLatestPluginVersion = checkLatestPluginVersion;
}
public void setInteractiveMode( boolean interactiveMode )
{
this.interactiveMode = interactiveMode;
}
public void setUsePluginRegistry( boolean usePluginRegistry )
{
this.usePluginRegistry = usePluginRegistry;
}
public void setOffline( boolean offline )
{
this.offline = offline;
}
public void setUpdateSnapshots( boolean updateSnapshots )
{
this.updateSnapshots = updateSnapshots;
}
public void setGlobalChecksumPolicy( String globalChecksumPolicy )
{
this.globalChecksumPolicy = globalChecksumPolicy;
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
/**
* Set the classloader to use with the maven embedder.
*
* @param classLoader
*/
public void setClassLoader( ClassLoader classLoader )
{
this.classLoader = classLoader;
}
public void setLocalRepositoryDirectory( File localRepositoryDirectory )
{
this.localRepositoryDirectory = localRepositoryDirectory;
}
// ----------------------------------------------------------------------
// Embedder Client Contract
// ----------------------------------------------------------------------
public Model readModel( File model )
throws XmlPullParserException, FileNotFoundException, IOException
{
return modelReader.read( new FileReader( model ) );
}
public MavenProject readProject( File mavenProject )
throws ProjectBuildingException
{
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager );
}
// ----------------------------------------------------------------------
// Internal utility code
// ----------------------------------------------------------------------
private ArtifactRepository createLocalRepository( Settings settings )
throws ComponentLookupException
{
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder.lookup( ArtifactRepositoryLayout.ROLE, "default" );
String url = settings.getLocalRepository();
if ( !url.startsWith( "file:" ) )
{
url = "file://" + url;
}
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout );
boolean snapshotPolicySet = false;
if ( offline )
{
settings.setOffline( true );
snapshotPolicySet = true;
}
if ( !snapshotPolicySet && updateSnapshots )
{
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
}
artifactRepositoryFactory.setGlobalChecksumPolicy( globalChecksumPolicy );
return localRepository;
}
private RuntimeInfo createRuntimeInfo( Settings settings )
{
RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
if ( pluginUpdateOverride )
{
runtimeInfo.setPluginUpdateOverride( Boolean.TRUE );
}
else
{
runtimeInfo.setPluginUpdateOverride( Boolean.FALSE );
}
if ( checkLatestPluginVersion )
{
runtimeInfo.setCheckLatestPluginVersion( Boolean.TRUE );
}
else
{
runtimeInfo.setCheckLatestPluginVersion( Boolean.FALSE );
}
return runtimeInfo;
}
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
public void start()
throws MavenEmbedderException
{
if ( classLoader == null )
{
throw new IllegalStateException( "A classloader must be specified using setClassLoader(ClassLoader)." );
}
embedder = new Embedder();
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();
profileManager = new DefaultProfileManager( embedder.getContainer() );
mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE );
artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup( ArtifactRepositoryFactory.ROLE );
// ----------------------------------------------------------------------
// If an explicit local repository has not been set then we will use the
// setting builder to use the maven defaults to help us find one.
// ----------------------------------------------------------------------
if ( localRepositoryDirectory == null )
{
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
{
settings = new Settings();
settings.setLocalRepository( localRepositoryDirectory.getAbsolutePath() );
}
settings.setRuntimeInfo( createRuntimeInfo( settings ) );
settings.setOffline( offline );
settings.setUsePluginRegistry( usePluginRegistry );
settings.setInteractiveMode( interactiveMode );
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 );
}
}
public void stop()
throws MavenEmbedderException
{
try
{
embedder.release( mavenProjectBuilder );
embedder.release( artifactRepositoryFactory );
embedder.release( settingsBuilder );
}
catch ( ComponentLifecycleException e )
{
throw new MavenEmbedderException( "Cannot stop the embedder.", e );
}
}
}

View File

@ -0,0 +1,40 @@
package 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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @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 );
}
}

View File

@ -0,0 +1,376 @@
<component-set>
<components>
<component>
<role>org.apache.maven.plugin.PluginManager</role>
<implementation>org.apache.maven.plugin.DefaultPluginManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.path.PathTranslator</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.MavenPluginCollector</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.version.PluginVersionManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.PluginMappingManager</role>
</requirement>
<requirement>
<role>org.apache.maven.execution.RuntimeInformation</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.extension.ExtensionManager</role>
<implementation>org.apache.maven.extension.DefaultExtensionManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.plugin.PluginMappingManager</role>
<implementation>org.apache.maven.plugin.DefaultPluginMappingManager</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
<!-- Duplicated from Maven core as it is used in the plugin manager -->
<component>
<role>org.apache.maven.project.path.PathTranslator</role>
<implementation>org.apache.maven.project.path.DefaultPathTranslator</implementation>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.Maven</role>
<implementation>org.apache.maven.DefaultMaven</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
<requirement>
<role>org.apache.maven.usability.ErrorDiagnoser</role>
<field-name>errorDiagnosers</field-name>
</requirement>
<requirement>
<role>org.apache.maven.execution.RuntimeInformation</role>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.execution.RuntimeInformation</role>
<implementation>org.apache.maven.execution.DefaultRuntimeInformation</implementation>
</component>
<!--
|
|PluginConfigurationDiagnoser
|
-->
<component>
<role>org.apache.maven.usability.ErrorDiagnoser</role>
<role-hint>PluginConfigurationDiagnoser</role-hint>
<implementation>org.apache.maven.usability.PluginConfigurationDiagnoser</implementation>
</component>
<!--
|
|ArtifactResolverDiagnoser
|
-->
<component>
<role>org.apache.maven.usability.ErrorDiagnoser</role>
<role-hint>ArtifactResolverDiagnoser</role-hint>
<implementation>org.apache.maven.usability.ArtifactResolverDiagnoser</implementation>
</component>
<!--
|
|InvalidArtifactDiagnoser
|
-->
<component>
<role>org.apache.maven.usability.ErrorDiagnoser</role>
<role-hint>InvalidArtifactDiagnoser</role-hint>
<implementation>org.apache.maven.usability.InvalidArtifactDiagnoser</implementation>
</component>
<!--
|
| Lifecycle executor
|
-->
<component>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
<implementation>org.apache.maven.lifecycle.DefaultLifecycleExecutor</implementation>
<requirements>
<requirement>
<role>org.apache.maven.plugin.PluginManager</role>
</requirement>
<requirement>
<role>org.apache.maven.extension.ExtensionManager</role>
</requirement>
<requirement>
<role>org.apache.maven.project.injection.ModelDefaultsInjector</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
</requirements>
<configuration>
<!-- START SNIPPET: lifecyle -->
<phases>
<phase implementation="java.lang.String">validate</phase>
<phase implementation="java.lang.String">initialize</phase>
<phase implementation="java.lang.String">generate-sources</phase>
<phase implementation="java.lang.String">process-sources</phase>
<phase implementation="java.lang.String">generate-resources</phase>
<phase implementation="java.lang.String">process-resources</phase>
<phase implementation="java.lang.String">compile</phase>
<phase implementation="java.lang.String">process-classes</phase>
<phase implementation="java.lang.String">generate-test-sources</phase>
<phase implementation="java.lang.String">process-test-sources</phase>
<phase implementation="java.lang.String">generate-test-resources</phase>
<phase implementation="java.lang.String">process-test-resources</phase>
<phase implementation="java.lang.String">test-compile</phase>
<phase implementation="java.lang.String">test</phase>
<phase implementation="java.lang.String">package</phase>
<phase implementation="java.lang.String">integration-test</phase>
<phase implementation="java.lang.String">verify</phase>
<phase implementation="java.lang.String">install</phase>
<phase implementation="java.lang.String">deploy</phase>
</phases>
<!-- END SNIPPET: lifecycle -->
<!-- START SNIPPET: default-reports -->
<defaultReports>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-project-info-reports-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-checkstyle-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-javadoc-plugin</report>
<!-- TODO: currently in mojo - should they be defaults any more?
<report implementation="java.lang.String">org.apache.maven.plugins:maven-changelog-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-surefire-report-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-jdepend-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-jxr-plugin</report>
<report implementation="java.lang.String">org.apache.maven.plugins:maven-taglist-plugin</report>
-->
</defaultReports>
<!-- END SNIPPET: default-reports -->
<!-- START SNIPPET: default-lifecycle -->
<!-- NOT USED, ACCORDING TO CODE.
<defaultPhases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar,
org.apache.maven.plugins:maven-source-plugin:jar
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</defaultPhases>
-->
<!-- END SNIPPET: default-lifecycle -->
</configuration>
</component>
<!-- TODO: issues with the lifecycle:
- manually configured lifecycles will not pick up any later additions to the defaults where they are intended to extend defaults (have configuration <includeDefaults/> ?)
-->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>pom</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: pom-lifecycle -->
<phases>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: pom-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>jar</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: jar-lifecycle -->
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: jar-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>maven-plugin</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: maven-plugin-lifecycle -->
<phases>
<generate-resources>org.apache.maven.plugins:maven-plugin-plugin:descriptor</generate-resources>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar,
org.apache.maven.plugins:maven-plugin-plugin:addPluginArtifactMetadata
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: maven-plugin-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>ejb</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: ejb-lifecycle -->
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-ejb-plugin:ejb
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: ejb-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>war</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: war-lifecycle -->
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>org.apache.maven.plugins:maven-war-plugin:war</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: war-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>ear</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: ear-lifecycle -->
<phases>
<generate-resources>org.apache.maven.plugins:maven-ear-plugin:generate-application-xml</generate-resources>
<package>org.apache.maven.plugins:maven-ear-plugin:ear</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: ear-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>rar</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<!-- START SNIPPET: rar-lifecycle -->
<phases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
<process-test-resources>org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources>
<test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile>
<test>org.apache.maven.plugins:maven-surefire-plugin:test</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar,
org.apache.maven.plugins:maven-rar-plugin:rar
</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
<!-- END SNIPPET: rar-lifecycle -->
</configuration>
</component>
<component>
<role>org.apache.maven.plugin.version.PluginVersionManager</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.plugin.version.DefaultPluginVersionManager</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
</requirement>
<requirement>
<role>org.apache.maven.plugin.registry.MavenPluginRegistryBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
<requirement>
<role>org.codehaus.plexus.components.inputhandler.InputHandler</role>
</requirement>
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.execution.RuntimeInformation</role>
</requirement>
</requirements>
</component>
</components>
</component-set>

View File

@ -0,0 +1,70 @@
package org.apache.maven.embedder;
import junit.framework.TestCase;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import java.io.File;
public class MavenEmbedderTest
extends TestCase
{
private String basedir;
private MavenEmbedder maven;
protected void setUp()
throws Exception
{
super.setUp();
basedir = System.getProperty( "basedir" );
}
public void testMavenEmbedder()
throws Exception
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
maven = new MavenEmbedder();
maven.setClassLoader( classLoader );
maven.start();
modelReadingTest();
projectReadingTest();
maven.stop();
}
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.readProject( getPomFile() );
assertEquals( "org.apache.maven", project.getGroupId() );
}
// ----------------------------------------------------------------------
// Internal Utilities
// ----------------------------------------------------------------------
protected File getPomFile()
{
return new File( basedir, "src/test/resources/pom.xml" );
}
}

View File

@ -0,0 +1,70 @@
<project>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.0-beta-2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<name>Maven Model</name>
<version>2.0-beta-2-SNAPSHOT</version>
<description>Maven Model</description>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
</execution>
</executions>
<configuration>
<version>4.0.0</version>
<model>maven.mdo</model>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>all-models</id>
<build>
<finalName>${pom.artifactId}-${pom.version}-all</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<executions>
<execution>
<id>v3</id>
<configuration>
<version>3.0.0</version>
<packageWithVersion>true</packageWithVersion>
</configuration>
<goals>
<goal>xpp3-writer</goal>
<goal>java</goal>
<goal>xpp3-reader</goal>
<goal>xsd</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>