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 java.util.HashMap; |
23 | import java.util.Map; |
24 | |
25 | import org.apache.continuum.dao.ProjectDao; |
26 | import org.apache.continuum.taskqueue.CheckOutTask; |
27 | import org.apache.maven.continuum.core.action.AbstractContinuumAction; |
28 | import org.apache.maven.continuum.core.action.CheckoutProjectContinuumAction; |
29 | import org.apache.maven.continuum.model.project.Project; |
30 | import org.apache.maven.continuum.store.ContinuumStoreException; |
31 | import org.codehaus.plexus.action.ActionManager; |
32 | import org.codehaus.plexus.taskqueue.Task; |
33 | import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; |
34 | import org.codehaus.plexus.taskqueue.execution.TaskExecutor; |
35 | import org.slf4j.Logger; |
36 | import org.slf4j.LoggerFactory; |
37 | |
38 | /** |
39 | * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> |
40 | * @version $Id: CheckOutTaskExecutor.java 771177 2009-05-04 05:02:26Z evenisse $ |
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 | try |
100 | { |
101 | actionManager.lookup( "checkout-project" ).execute( context ); |
102 | |
103 | actionManager.lookup( "store-checkout-scm-result" ).execute( context ); |
104 | } |
105 | catch ( Exception e ) |
106 | { |
107 | throw new TaskExecutionException( "Error checking out project.", e ); |
108 | } |
109 | } |
110 | } |