Author: mkleint
Date: Mon Dec  3 11:46:37 2007
New Revision: 600646

URL: http://svn.apache.org/viewvc?rev=600646&view=rev
Log:
backport MavenSetting's currectProject property to 2.0.x, to be used by 
maven-toolchains.

Modified:
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
    
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=600646&r1=600645&r2=600646&view=diff
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
 Mon Dec  3 11:46:37 2007
@@ -58,6 +58,8 @@
     private final Properties executionProperties;
 
     private final Date startTime;
+    
+    private MavenProject currentProject;
 
     public MavenSession( PlexusContainer container, Settings settings, 
ArtifactRepository localRepository,
                          EventDispatcher eventDispatcher, ReactorManager 
reactorManager, List goals,
@@ -169,4 +171,18 @@
     {
         return startTime;
     }
+    
+    public void setCurrentProject( MavenProject currentProject )
+    {
+        this.currentProject = currentProject;
+    }
+
+    /**
+     * Return the current project for use in a mojo execution.
+     */
+    public MavenProject getCurrentProject()
+    {
+        return currentProject;
+    }
+    
 }

Modified: 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=600646&r1=600645&r2=600646&view=diff
==============================================================================
--- 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
 (original)
+++ 
maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
 Mon Dec  3 11:46:37 2007
@@ -216,17 +216,27 @@
 
                     dispatcher.dispatchStart( event, target );
 
-                    // only call once, with the top-level project (assumed to 
be provided as a parameter)...
-                    for ( Iterator goalIterator = 
segment.getTasks().iterator(); goalIterator.hasNext(); )
+                    try
                     {
-                        String task = (String) goalIterator.next();
+                        session.setCurrentProject( rootProject );
 
-                        executeGoalAndHandleFailures( task, session, 
rootProject, dispatcher, event, rm, buildStartTime,
-                                                      target );
-                    }
+                        // only call once, with the top-level project (assumed 
to be provided as a parameter)...
+                        for ( Iterator goalIterator = 
segment.getTasks().iterator(); goalIterator.hasNext(); )
+                        {
+                            String task = (String) goalIterator.next();
 
-                    rm.registerBuildSuccess( rootProject, 
System.currentTimeMillis() - buildStartTime );
+                            executeGoalAndHandleFailures( task, session, 
rootProject, dispatcher, event, rm, buildStartTime,
+                                                          target );
+                        }
+
+                        rm.registerBuildSuccess( rootProject, 
System.currentTimeMillis() - buildStartTime );
 
+                    }
+                    finally
+                    {
+                        session.setCurrentProject( null );
+                    }
+                    
                     dispatcher.dispatchEnd( event, target );
                 }
                 else
@@ -270,15 +280,25 @@
 
                         String target = currentProject.getId() + " ( " + 
segment + " )";
                         dispatcher.dispatchStart( event, target );
-
-                        for ( Iterator goalIterator = 
segment.getTasks().iterator(); goalIterator.hasNext(); )
+                        
+                        try
                         {
-                            String task = (String) goalIterator.next();
+                            session.setCurrentProject( currentProject );
+                        
+                            for ( Iterator goalIterator = 
segment.getTasks().iterator(); goalIterator.hasNext(); )
+                            {
+                                String task = (String) goalIterator.next();
+
+                                executeGoalAndHandleFailures( task, session, 
currentProject, dispatcher, event, rm,
+                                                              buildStartTime, 
target );
+                            }
 
-                            executeGoalAndHandleFailures( task, session, 
currentProject, dispatcher, event, rm,
-                                                          buildStartTime, 
target );
                         }
-
+                        finally
+                        {
+                            session.setCurrentProject( null );
+                        }
+                        
                         rm.registerBuildSuccess( currentProject, 
System.currentTimeMillis() - buildStartTime );
 
                         dispatcher.dispatchEnd( event, target );


Reply via email to