1 | package org.apache.maven.continuum.core.action; |
2 | |
3 | /* |
4 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license |
5 | * agreements. See the NOTICE file distributed with this work for additional information regarding |
6 | * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance with the License. You may obtain a |
8 | * copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
13 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
14 | * or implied. See the License for the specific language governing permissions and limitations under |
15 | * the License. |
16 | */ |
17 | |
18 | import java.util.List; |
19 | import java.util.Map; |
20 | |
21 | import org.apache.continuum.dao.ProjectDao; |
22 | import org.apache.maven.continuum.model.project.BuildDefinition; |
23 | import org.apache.maven.continuum.model.project.BuildDefinitionTemplate; |
24 | import org.apache.maven.continuum.model.project.Project; |
25 | |
26 | /** |
27 | * AddBuildDefinitionToProjectAction: |
28 | * |
29 | * @author Jesse McConnell <jmcconnell@apache.org> |
30 | * @version $Id: AddBuildDefinitionToProjectAction.java 788260 2009-06-25 05:02:07Z evenisse $ |
31 | * @plexus.component role="org.codehaus.plexus.action.Action" |
32 | * role-hint="add-build-definition-to-project" |
33 | */ |
34 | public class AddBuildDefinitionToProjectAction |
35 | extends AbstractBuildDefinitionContinuumAction |
36 | { |
37 | /** |
38 | * @plexus.requirement |
39 | */ |
40 | private ProjectDao projectDao; |
41 | |
42 | public void execute( Map context ) |
43 | throws Exception |
44 | { |
45 | int projectId = getProjectId( context ); |
46 | Project project = projectDao.getProjectWithAllDetails( projectId ); |
47 | |
48 | BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate( context ); |
49 | |
50 | if ( buildDefinitionTemplate != null ) |
51 | { |
52 | for ( BuildDefinition buildDefinition : (List<BuildDefinition>) buildDefinitionTemplate.getBuildDefinitions() ) |
53 | { |
54 | resolveDefaultBuildDefinitionsForProject( buildDefinition, project ); |
55 | |
56 | project.addBuildDefinition( buildDefinition ); |
57 | |
58 | if ( buildDefinition.isDefaultForProject() ) |
59 | { |
60 | AbstractContinuumAction.setBuildDefinition( context, buildDefinition ); |
61 | } |
62 | } |
63 | } |
64 | else |
65 | { |
66 | BuildDefinition buildDefinition = getBuildDefinition( context ); |
67 | resolveDefaultBuildDefinitionsForProject( buildDefinition, project ); |
68 | |
69 | project.addBuildDefinition( buildDefinition ); |
70 | |
71 | AbstractContinuumAction.setBuildDefinition( context, buildDefinition ); |
72 | } |
73 | |
74 | // Save the project |
75 | projectDao.updateProject( project ); |
76 | } |
77 | } |