View Javadoc

1   package org.apache.maven.continuum.core.action;
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.BuildDefinitionDao;
23  import org.apache.continuum.dao.ProjectDao;
24  import org.apache.maven.continuum.ContinuumException;
25  import org.apache.maven.continuum.execution.ContinuumBuildExecutor;
26  import org.apache.maven.continuum.execution.ContinuumBuildExecutorException;
27  import org.apache.maven.continuum.execution.manager.BuildExecutorManager;
28  import org.apache.maven.continuum.model.project.BuildDefinition;
29  import org.apache.maven.continuum.model.project.Project;
30  import org.apache.maven.continuum.model.scm.ScmResult;
31  import org.apache.maven.continuum.store.ContinuumStoreException;
32  import org.apache.maven.continuum.utils.WorkingDirectoryService;
33  
34  import java.util.List;
35  import java.util.Map;
36  
37  /**
38   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
39   * @version $Id: UpdateProjectFromWorkingDirectoryContinuumAction.java 1372260 2012-08-13 04:29:09Z brett $
40   * @plexus.component role="org.codehaus.plexus.action.Action"
41   * role-hint="update-project-from-working-directory"
42   */
43  public class UpdateProjectFromWorkingDirectoryContinuumAction
44      extends AbstractContinuumAction
45  {
46      /**
47       * @plexus.requirement
48       */
49      private WorkingDirectoryService workingDirectoryService;
50  
51      /**
52       * @plexus.requirement
53       */
54      private BuildExecutorManager buildExecutorManager;
55  
56      /**
57       * @plexus.requirement
58       */
59      private BuildDefinitionDao buildDefinitionDao;
60  
61      /**
62       * @plexus.requirement
63       */
64      private ProjectDao projectDao;
65  
66      public void execute( Map context )
67          throws ContinuumStoreException, ContinuumException, ContinuumBuildExecutorException
68      {
69          Project project = getProject( context );
70  
71          project = projectDao.getProjectWithAllDetails( project.getId() );
72  
73          getLogger().info( "Updating project '" + project.getName() + "' from checkout." );
74  
75          BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( getBuildDefinitionId( context ) );
76  
77          // ----------------------------------------------------------------------
78          // Make a new descriptor
79          // ----------------------------------------------------------------------
80  
81          ContinuumBuildExecutor builder = buildExecutorManager.getBuildExecutor( project.getExecutorId() );
82  
83          ScmResult scmResult = (ScmResult) context.get( "scmResult" );
84          List<Project> projectsWithCommonScmRoot = getListOfProjectsInGroupWithCommonScmRoot( context );
85          String projectScmRootUrl = getProjectScmRootUrl( context, project.getScmUrl() );
86  
87          builder.updateProjectFromCheckOut( workingDirectoryService.getWorkingDirectory( project, projectScmRootUrl,
88                                                                                          projectsWithCommonScmRoot ),
89                                             project, buildDefinition, scmResult );
90          // ----------------------------------------------------------------------
91          // Store the new descriptor
92          // ----------------------------------------------------------------------
93  
94          projectDao.updateProject( project );
95      }
96  }