maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/project DefaultMavenProjectBuilder.java
Date Sat, 12 Mar 2005 21:54:21 GMT
jvanzyl     2005/03/12 13:54:21

  Modified:    maven-core/src/main/java/org/apache/maven DefaultMaven.java
               maven-core/src/main/java/org/apache/maven/lifecycle
                        DefaultLifecycleExecutor.java
               maven-core/src/main/java/org/apache/maven/plugin
                        DefaultPluginManager.java
               maven-core/src/main/java/org/apache/maven/project
                        DefaultMavenProjectBuilder.java
  Log:
  o allowing the selective execution of a set of mojos inside a plugins by
    specifying a <goals/> section inside a <plugin/> configuration.
  
  Revision  Changes    Path
  1.28      +12 -6     maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
  
  Index: DefaultMaven.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DefaultMaven.java	11 Mar 2005 01:06:48 -0000	1.27
  +++ DefaultMaven.java	12 Mar 2005 21:54:21 -0000	1.28
  @@ -152,18 +152,24 @@
   
                       if ( project.getModules() != null && !project.getModules().isEmpty()
)
                       {
  -                        String includes = StringUtils.join( project.getModules().iterator(),
"/pom.xml," ) +
  -                            "/pom.xml";
  +                        String includes = StringUtils.join( project.getModules().iterator(),
"/pom.xml," ) + "/pom.xml";
  +
                           File baseDir = project.getFile().getParentFile();
  +
                           MavenExecutionRequest reactorRequest = new DefaultMavenExecutionRequest(
  -                            request.getLocalRepository(), request.getUserModel(), request.getEventDispatcher(),
  -                            request.getGoals(), FileUtils.getFiles( baseDir, includes,
null ), baseDir.getPath() );
  +                            request.getLocalRepository(),
  +                            request.getUserModel(),
  +                            request.getEventDispatcher(),
  +                            request.getGoals(),
  +                            FileUtils.getFiles( baseDir, includes, null ),
  +                            baseDir.getPath() );
  +
                           MavenExecutionResponse response = execute( reactorRequest );
  +
                           if ( response != null && response.isExecutionFailure()
)
                           {
                               return response;
                           }
  -
                       }
   
                       if ( !isPom )
  
  
  
  1.21      +88 -25    maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
  
  Index: DefaultLifecycleExecutor.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DefaultLifecycleExecutor.java	10 Mar 2005 23:01:36 -0000	1.20
  +++ DefaultLifecycleExecutor.java	12 Mar 2005 21:54:21 -0000	1.21
  @@ -23,6 +23,7 @@
   import org.apache.maven.execution.MavenSession;
   import org.apache.maven.model.Plugin;
   import org.apache.maven.model.PluginManagement;
  +import org.apache.maven.model.Goal;
   import org.apache.maven.monitor.event.EventDispatcher;
   import org.apache.maven.monitor.event.MavenEvents;
   import org.apache.maven.plugin.PluginExecutionResponse;
  @@ -84,27 +85,35 @@
           {
               MavenProject project = session.getProject();
               
  -            // TODO: should enrich this with the type handler, but for now just
  +            // TODO: should enrich this with the type artifactHandler, but for now just
               // use "type" as is
  -            ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( project.getPackaging()
);
  +            ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(
project.getPackaging() );
   
  -            if ( handler != null )
  +            if ( artifactHandler != null )
               {
                   // TODO: perhaps each type should define their own lifecycle
                   // completely, using the base as a default?
  -                // If so, remove both of these goals from type handler
  -                if ( handler.packageGoal() != null )
  +                // If so, remove both of these goals from type artifactHandler
  +                if ( artifactHandler.packageGoal() != null )
                   {
  -                    verifyMojoPhase( handler.packageGoal(), session );
  +                    verifyMojoPhase( artifactHandler.packageGoal(), session );
                   }
  -                if ( handler.additionalPlugin() != null )
  +
  +                if ( artifactHandler.additionalPlugin() != null )
                   {
                       String additionalPluginGroupId = "maven";
  -                    String additionalPluginArtifactId = "maven-" + handler.additionalPlugin()
+ "-plugin";
  +
  +                    String additionalPluginArtifactId = "maven-" + artifactHandler.additionalPlugin()
+ "-plugin";
   
                       injectHandlerPluginConfiguration( project, additionalPluginGroupId,
additionalPluginArtifactId );
   
  -                    processPluginPhases( "maven", "maven-" + handler.additionalPlugin()
+ "-plugin", session );
  +                    Plugin plugin = new Plugin();
  +
  +                    plugin.setGroupId( additionalPluginGroupId );
  +
  +                    plugin.setArtifactId( additionalPluginArtifactId );
  +
  +                    processPluginPhases( plugin, session );
                   }
               }
   
  @@ -149,18 +158,22 @@
   
       private void injectHandlerPluginConfiguration( MavenProject project, String groupId,
String artifactId )
       {
  -        PluginManagement mgmt = project.getPluginManagement();
  -        if( mgmt != null )
  +        PluginManagement pluginManagement = project.getPluginManagement();
  +
  +        if ( pluginManagement != null )
           {
  -            List pluginList = mgmt.getPlugins();
  +            List pluginList = pluginManagement.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;
                   }
               }
  @@ -180,33 +193,78 @@
           {
               Plugin plugin = (Plugin) i.next();
   
  -            // TODO: should this flag be used in verifyPlugin, completely disabling the
plugin?
  -            if ( Boolean.TRUE != plugin.isDisabled() )
  -            {
  -                processPluginPhases( plugin.getGroupId(), plugin.getArtifactId(), mavenSession
);
  -            }
  +            processPluginPhases( plugin, mavenSession );
           }
       }
   
  +    /**
  +     * Take each mojo contained with a plugin, look to see whether it contributes to a
  +     * phase in the lifecycle and if it does place it at the end of the list of goals
  +     * to execute for that given phase.
  +     *
  +     * @param mavenSession
  +     * @throws Exception
  +     */
       // TODO: don't throw Exception
  -    private void processPluginPhases( String groupId, String artifactId, MavenSession mavenSession
)
  +    private void processPluginPhases( Plugin plugin, MavenSession mavenSession )
           throws Exception
       {
  +        String groupId = plugin.getGroupId();
  +
  +        String artifactId = plugin.getArtifactId();
  +
           pluginManager.verifyPlugin( groupId, artifactId, mavenSession );
  +
           PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( groupId,
artifactId );
  -        for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
  +
  +        // ----------------------------------------------------------------------
  +        // Look to see if the plugin configuration specifies particular mojos
  +        // within the plugin. If this is the case then simply configure the
  +        // mojos the user has specified and ignore the rest.
  +        // ----------------------------------------------------------------------
  +
  +
  +        if ( plugin.getGoals().size() > 0 )
           {
  -            MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
  +            String pluginId = pluginDescriptor.getArtifactId();
   
  -            // TODO: check if the goal exists in the configuration and is
  -            // disabled
  -            if ( mojoDescriptor.getPhase() != null )
  +            pluginId = pluginId.substring( 6 ).substring( 0, 7 );
  +
  +            for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); )
               {
  -                Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
  -                phase.getGoals().add( mojoDescriptor.getId() );
  +                Goal goal = (Goal) i.next();
  +
  +                configureMojo( pluginManager.getMojoDescriptor( pluginId + ":" + goal.getId()
) );
               }
           }
  +        else
  +        {
  +            for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
  +            {
  +                MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
   
  +                configureMojo( mojoDescriptor );
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Take a look at a mojo contained within a plugin, look to see whether it contributes
to a
  +     * phase in the lifecycle and if it does place it at the end of the list of goals
  +     * to execute for the stated phase.
  +     *
  +     * @param mojoDescriptor
  +     * @throws Exception
  +     */
  +    private void configureMojo( MojoDescriptor mojoDescriptor )
  +        throws Exception
  +    {
  +        if ( mojoDescriptor.getPhase() != null )
  +        {
  +            Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
  +
  +            phase.getGoals().add( mojoDescriptor.getId() );
  +        }
       }
   
       private void processGoalChain( String task, MavenSession session )
  @@ -242,10 +300,13 @@
           throws Exception
       {
           MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
  +
           if ( mojoDescriptor == null )
           {
               pluginManager.verifyPluginForGoal( task, session );
  +
               mojoDescriptor = pluginManager.getMojoDescriptor( task );
  +
               if ( mojoDescriptor == null )
               {
                   throw new LifecycleExecutionException( "Required goal not found: " + task
);
  @@ -254,6 +315,7 @@
               if ( mojoDescriptor.getPhase() != null )
               {
                   Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
  +
                   phase.getGoals().add( task );
               }
           }
  @@ -289,6 +351,7 @@
                           if ( pluginResponse.isExecutionFailure() )
                           {
                               response.setExecutionFailure( goal, pluginResponse.getFailureResponse()
);
  +
                               return;
                           }
                       }
  
  
  
  1.48      +2 -1      maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
  
  Index: DefaultPluginManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- DefaultPluginManager.java	12 Mar 2005 06:10:57 -0000	1.47
  +++ DefaultPluginManager.java	12 Mar 2005 21:54:21 -0000	1.48
  @@ -444,7 +444,8 @@
       // Mojo Parameter Handling
       // ----------------------------------------------------------------------
   
  -    public static Map createParameters( MojoDescriptor goal, MavenSession session ) throws
PluginConfigurationException
  +    public static Map createParameters( MojoDescriptor goal, MavenSession session ) 
  +        throws PluginConfigurationException
       {
           Map map = null;
   
  
  
  
  1.44      +1 -1      maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
  
  Index: DefaultMavenProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- DefaultMavenProjectBuilder.java	11 Mar 2005 23:25:00 -0000	1.43
  +++ DefaultMavenProjectBuilder.java	12 Mar 2005 21:54:21 -0000	1.44
  @@ -2,7 +2,7 @@
   
   /*
    * 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
  
  
  

Mime
View raw message