View Javadoc

1   package org.apache.maven.continuum.scm.queue;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.dao.ProjectDao;
23  import org.apache.continuum.taskqueue.CheckOutTask;
24  import org.apache.maven.continuum.core.action.AbstractContinuumAction;
25  import org.apache.maven.continuum.core.action.CheckoutProjectContinuumAction;
26  import org.apache.maven.continuum.model.project.Project;
27  import org.apache.maven.continuum.store.ContinuumStoreException;
28  import org.codehaus.plexus.action.ActionManager;
29  import org.codehaus.plexus.taskqueue.Task;
30  import org.codehaus.plexus.taskqueue.execution.TaskExecutionException;
31  import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  import java.util.HashMap;
36  import java.util.Map;
37  
38  /**
39   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
40   * @version $Id: CheckOutTaskExecutor.java 1372260 2012-08-13 04:29:09Z brett $
41   * @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor"
42   * role-hint="check-out-project" instantiation-strategy="per-lookup"
43   */
44  public class CheckOutTaskExecutor
45      implements TaskExecutor
46  {
47      private static final Logger log = LoggerFactory.getLogger( CheckOutTaskExecutor.class );
48  
49      /**
50       * @plexus.requirement
51       */
52      private ActionManager actionManager;
53  
54      /**
55       * @plexus.requirement
56       */
57      private ProjectDao projectDao;
58  
59      // ----------------------------------------------------------------------
60      // TaskExecutor Implementation
61      // ----------------------------------------------------------------------
62  
63      public void executeTask( Task t )
64          throws TaskExecutionException
65      {
66          log.info( "Checkout task executor.." );
67  
68          CheckOutTask task = (CheckOutTask) t;
69  
70          int projectId = task.getProjectId();
71  
72          Project project;
73  
74          try
75          {
76              project = projectDao.getProjectWithBuildDetails( projectId );
77          }
78          catch ( ContinuumStoreException ex )
79          {
80              log.error( "Internal error while getting the project.", ex );
81  
82              return;
83          }
84  
85          String workingDirectory = task.getWorkingDirectory().getAbsolutePath();
86  
87          Map<String, Object> context = new HashMap<String, Object>();
88  
89          AbstractContinuumAction.setProjectId( context, projectId );
90  
91          AbstractContinuumAction.setProject( context, project );
92  
93          AbstractContinuumAction.setWorkingDirectory( context, workingDirectory );
94  
95          CheckoutProjectContinuumAction.setScmUsername( context, task.getScmUserName() );
96  
97          CheckoutProjectContinuumAction.setScmPassword( context, task.getScmPassword() );
98  
99          AbstractContinuumAction.setProjectScmRootUrl( context, task.getScmRootUrl() );
100 
101         AbstractContinuumAction.setListOfProjectsInGroupWithCommonScmRoot( context,
102                                                                            task.getProjectsWithCommonScmRoot() );
103 
104         try
105         {
106             actionManager.lookup( "checkout-project" ).execute( context );
107 
108             actionManager.lookup( "store-checkout-scm-result" ).execute( context );
109         }
110         catch ( Exception e )
111         {
112             throw new TaskExecutionException( "Error checking out project.", e );
113         }
114     }
115 }