o Moved the default plugin stuff to <pluginManagement/>. Plugin config will be pulled from here and injected into <plugins/> as needed to satisfy type-handlers at runtime.

o Added the ability for DefaultMaven to load only the super-pom in the event that no pom.xml exists to initiate the assembly.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163527 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-10 23:01:38 +00:00
parent cc95065bb7
commit f6c2684903
12 changed files with 296 additions and 160 deletions

View File

@ -97,7 +97,17 @@ public class DefaultMaven
{
MavenSession session = createSession( request );
MavenProject project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() );
List projectFiles = request.getProjectFiles();
MavenProject project = null;
if(projectFiles != null && !projectFiles.isEmpty())
{
project = getProject( (File) request.getProjectFiles().get( 0 ), request.getLocalRepository() );
}
else
{
project = projectBuilder.buildSuperProject( request.getLocalRepository() );
}
session.setProject( project );

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.user.UserModel;
import org.apache.maven.monitor.event.EventDispatcher;
import java.util.Collections;
import java.util.List;
/**
@ -39,6 +40,6 @@ extends AbstractMavenExecutionRequest
public List getProjectFiles()
{
return null;
return Collections.EMPTY_LIST;
}
}

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginExecutionResponse;
@ -81,9 +82,11 @@ public class DefaultLifecycleExecutor
try
{
MavenProject project = session.getProject();
// TODO: should enrich this with the type handler, but for now just
// use "type" as is
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( session.getProject().getPackaging() );
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( project.getPackaging() );
if ( handler != null )
{
@ -96,6 +99,11 @@ public class DefaultLifecycleExecutor
}
if ( handler.additionalPlugin() != null )
{
String additionalPluginGroupId = "maven";
String additionalPluginArtifactId = "maven-" + handler.additionalPlugin() + "-plugin";
injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId );
processPluginPhases( "maven", "maven-" + handler.additionalPlugin() + "-plugin", session );
}
}
@ -139,6 +147,31 @@ public class DefaultLifecycleExecutor
return response;
}
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
{
PluginManagement mgmt = project.getPluginManagement();
if( mgmt != null )
{
List pluginList = mgmt.getPlugins();
Plugin handlerPlugin = null;
for ( Iterator it = pluginList.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
handlerPlugin = plugin;
break;
}
}
if ( handlerPlugin != null )
{
project.addPlugin( handlerPlugin );
}
}
}
// TODO: don't throw Exception
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession )
throws Exception

View File

@ -31,6 +31,7 @@ import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult;
@ -118,6 +119,23 @@ public class DefaultMavenProjectBuilder
previous = current;
}
project = processProjectLogic( project, localRepository, resolveDependencies );
project.setFile( projectDescriptor );
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
return project;
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building project from " + projectDescriptor, e );
}
}
private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository,
boolean resolveDependencies )
throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException
{
Model model = modelInterpolator.interpolate( project.getModel() );
// interpolation is before injection, because interpolation is off-limits in the injected variables
@ -126,7 +144,6 @@ public class DefaultMavenProjectBuilder
MavenProject parentProject = project.getParent();
project = new MavenProject( model );
project.setFile( projectDescriptor );
project.setParent( parentProject );
project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) );
@ -161,21 +178,12 @@ public class DefaultMavenProjectBuilder
throw new ProjectBuildingException( "Exception while building project: " + validationResult.toString() );
}
project.setFile( projectDescriptor );
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
project.addCompileSourceRoot( project.getBuild().getSourceDirectory() );
project.addScriptSourceRoot( project.getBuild().getScriptSourceDirectory() );
project.addTestCompileSourceRoot( project.getBuild().getTestSourceDirectory() );
return project;
}
catch ( Exception e )
{
throw new ProjectBuildingException( "Error building project from " + projectDescriptor, e );
}
}
private MavenProject assembleLineage( File projectDescriptor, ArtifactRepository localRepository,
LinkedList lineage, List aggregatedRemoteWagonRepositories )
@ -245,8 +253,7 @@ public class DefaultMavenProjectBuilder
return repos;
}
private Model readModel( File file )
throws ProjectBuildingException
private Model readModel( File file ) throws ProjectBuildingException
{
try
{
@ -259,12 +266,12 @@ public class DefaultMavenProjectBuilder
catch ( Exception e )
{
throw new ProjectBuildingException(
"Error while reading model from file '" + file.getAbsolutePath() + "'.", e );
"Error while reading model from file '" + file.getAbsolutePath() + "'.",
e );
}
}
private Model readModel( URL url )
throws ProjectBuildingException
private Model readModel( URL url ) throws ProjectBuildingException
{
try
{
@ -293,8 +300,8 @@ public class DefaultMavenProjectBuilder
catch ( ArtifactResolutionException e )
{
// @todo use parent.toString() if modello could generate it, or specify in a code segment
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":" +
parent.getArtifactId() + "-" + parent.getVersion(), e );
throw new ProjectBuildingException( "Missing parent POM: " + parent.getGroupId() + ":"
+ parent.getArtifactId() + "-" + parent.getVersion(), e );
}
return artifact.getFile();
@ -311,8 +318,7 @@ public class DefaultMavenProjectBuilder
* <li>do a topo sort on the graph that remains.</li>
* </ul>
*/
public List getSortedProjects( List projects )
throws CycleDetectedException
public List getSortedProjects( List projects ) throws CycleDetectedException
{
DAG dag = new DAG();
@ -360,12 +366,42 @@ public class DefaultMavenProjectBuilder
return sortedProjects;
}
public MavenProject buildSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException
{
return buildSuperProject( localRepository, false );
}
public MavenProject buildSuperProject( ArtifactRepository localRepository, boolean resolveDependencies )
throws ProjectBuildingException
{
MavenProject project = new MavenProject( getSuperModel() );
try
{
project = processProjectLogic( project, localRepository, resolveDependencies );
File projectFile = new File( ".", "pom.xml" );
project.setFile( projectFile );
pathTranslator.alignToBaseDirectory( project.getModel(), projectFile );
return project;
}
catch ( ModelInterpolationException e )
{
throw new ProjectBuildingException( "Error building super-project", e );
}
catch ( ArtifactResolutionException e )
{
throw new ProjectBuildingException( "Error building super-project", e );
}
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
private Model getSuperModel()
throws ProjectBuildingException
private Model getSuperModel() throws ProjectBuildingException
{
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MavenConstants.MAVEN_MODEL_VERSION + ".xml" );

View File

@ -29,6 +29,8 @@ import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Reports;
import org.apache.maven.model.Scm;
@ -522,5 +524,32 @@ public class MavenProject
}
return model.getBuild().getPlugins();
}
public PluginManagement getPluginManagement()
{
PluginManagement pluginMgmt = null;
Build build = model.getBuild();
if ( build != null )
{
pluginMgmt = build.getPluginManagement();
}
return pluginMgmt;
}
public void addPlugin( Plugin plugin )
{
Build build = model.getBuild();
if ( build == null )
{
build = new Build();
model.setBuild( build );
}
build.addPlugin( plugin );
}
}

View File

@ -33,6 +33,12 @@ public interface MavenProjectBuilder
MavenProject build( File project, ArtifactRepository localRepository, boolean transitive )
throws ProjectBuildingException;
MavenProject buildSuperProject( ArtifactRepository localRepository )
throws ProjectBuildingException;
MavenProject buildSuperProject( ArtifactRepository localRepository, boolean transitive )
throws ProjectBuildingException;
// take this out
List getSortedProjects( List projects )

View File

@ -219,15 +219,31 @@ public class DefaultModelInheritanceAssembler
private void assemblePluginManagementInheritance( Model child, Model parent )
{
PluginManagement parentPluginMgmt = parent.getPluginManagement();
Build parentBuild = parent.getBuild();
Build childBuild = parent.getBuild();
PluginManagement childPluginMgmt = child.getPluginManagement();
if ( childBuild == null )
{
if ( parentBuild != null )
{
child.setBuild( parentBuild );
}
else
{
childBuild = new Build();
}
}
else
{
PluginManagement parentPluginMgmt = parentBuild.getPluginManagement();
PluginManagement childPluginMgmt = childBuild.getPluginManagement();
if ( parentPluginMgmt != null )
{
if ( childPluginMgmt == null )
{
child.setPluginManagement( parentPluginMgmt );
childBuild.setPluginManagement( parentPluginMgmt );
}
else
{
@ -287,6 +303,7 @@ public class DefaultModelInheritanceAssembler
}
}
}
}
private String constructPluginKey( Plugin plugin )
{

View File

@ -42,7 +42,7 @@ public class DefaultModelDefaultsInjector
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
if ( model.getBuild() != null )
{
injectPluginDefaults( model.getBuild().getPlugins(), model.getPluginManagement() );
injectPluginDefaults( model.getBuild().getPlugins(), model.getBuild().getPluginManagement() );
}
}

View File

@ -30,6 +30,7 @@
</testResource>
</testResources>
<!-- Default plugins -->
<pluginManagement>
<plugins>
<plugin>
<groupId>maven</groupId>
@ -77,6 +78,7 @@
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -413,17 +413,6 @@
<type>DependencyManagement</type>
</association>
</field>
<!-- [ jdcasey:06-Mar-2005 ] Added to handle version management, etc. for
| plugins to be used in sub-projects. -->
<field>
<name>pluginManagement</name>
<version>4.0.0</version>
<required>false</required>
<description><![CDATA[Default plugin information for grouped projects inheriting from this one.]]></description>
<association>
<type>PluginManagement</type>
</association>
</field>
<field>
<name>properties</name>
<version>3.0.0</version>
@ -682,6 +671,17 @@
<multiplicity>*</multiplicity>
</association>
</field>
<!-- [ jdcasey:06-Mar-2005 ] Added to handle version management, etc. for
| plugins to be used in sub-projects. -->
<field>
<name>pluginManagement</name>
<version>4.0.0</version>
<required>false</required>
<description><![CDATA[Default plugin information for grouped projects inheriting from this one.]]></description>
<association>
<type>PluginManagement</type>
</association>
</field>
</fields>
</class>
<class>

View File

@ -16,6 +16,7 @@
<plugin>
<groupId>maven</groupId>
<artifactId>maven-modello-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<version>4.0.0</version>
<model>maven.mdo</model>

View File

@ -12,6 +12,7 @@
<plugin>
<groupId>maven</groupId>
<artifactId>maven-modello-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<version>4.0.0</version>
<model>maven-user.mdo</model>