View Javadoc

1   package org.apache.maven.continuum.web.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.release.distributed.manager.DistributedReleaseManager;
23  import org.apache.maven.continuum.ContinuumException;
24  import org.apache.maven.continuum.model.project.Project;
25  import org.apache.maven.continuum.release.ContinuumReleaseManager;
26  import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * @author Edwin Punzalan
35   * @version $Id: ReleaseProjectAction.java 1392472 2012-10-01 17:46:11Z brett $
36   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseProject"
37   */
38  public class ReleaseProjectAction
39      extends ContinuumActionSupport
40  {
41      private int projectId;
42  
43      private String projectName;
44  
45      private Map<String, String> preparedReleases;
46  
47      private String preparedReleaseId;
48  
49      private String goal;
50  
51      private String scmUrl;
52  
53      private Project project;
54  
55      private List releaseList;
56  
57      private String projectGroupName = "";
58  
59      protected static final String REQUIRES_CONFIGURATION = "releaseOutputDir-required";
60  
61      public String promptReleaseGoal()
62          throws Exception
63      {
64          try
65          {
66              checkBuildProjectInGroupAuthorization( getProjectGroupName() );
67          }
68          catch ( AuthorizationRequiredException e )
69          {
70              return REQUIRES_AUTHORIZATION;
71          }
72  
73          // check if releaseOutputDirectory is already set
74          if ( getContinuum().getConfiguration().getReleaseOutputDirectory() == null )
75          {
76              return REQUIRES_CONFIGURATION;
77          }
78  
79          project = getContinuum().getProjectWithAllDetails( projectId );
80  
81          if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
82          {
83              DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager();
84  
85              preparedReleases = releaseManager.getPreparedReleases( project.getGroupId(), project.getArtifactId() );
86          }
87          else
88          {
89              ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager();
90  
91              this.preparedReleases = releaseManager.getPreparedReleasesForProject( project.getGroupId(),
92                                                                                    project.getArtifactId() );
93          }
94  
95          if ( !preparedReleases.isEmpty() )
96          {
97              // use last release as default choice
98              preparedReleaseId = new ArrayList<String>( preparedReleases.keySet() ).get( preparedReleases.size() - 1 );
99          }
100         else
101         {
102             preparedReleaseId = null;
103         }
104 
105         projectName = project.getName();
106 
107         return SUCCESS;
108     }
109 
110     public String execute()
111         throws Exception
112     {
113         try
114         {
115             checkBuildProjectInGroupAuthorization( getProjectGroupName() );
116         }
117         catch ( AuthorizationRequiredException e )
118         {
119             return REQUIRES_AUTHORIZATION;
120         }
121 
122         if ( "prepare".equals( goal ) )
123         {
124             return "prepareRelease";
125         }
126         else if ( "perform".equals( goal ) )
127         {
128             if ( "".equals( preparedReleaseId ) )
129             {
130                 return "performReleaseFromScm";
131             }
132             else
133             {
134                 return "performRelease";
135             }
136         }
137         else
138         {
139             return "prompt";
140         }
141     }
142 
143     public int getProjectId()
144     {
145         return projectId;
146     }
147 
148     public void setProjectId( int projectId )
149     {
150         this.projectId = projectId;
151     }
152 
153     public String getGoal()
154     {
155         return goal;
156     }
157 
158     public void setGoal( String goal )
159     {
160         this.goal = goal;
161     }
162 
163     public Project getProject()
164     {
165         return project;
166     }
167 
168     public void setProject( Project project )
169     {
170         this.project = project;
171     }
172 
173     public String getScmUrl()
174     {
175         return scmUrl;
176     }
177 
178     public void setScmUrl( String scmUrl )
179     {
180         this.scmUrl = scmUrl;
181     }
182 
183     public List getReleaseList()
184     {
185         return releaseList;
186     }
187 
188     public void setReleaseList( List releaseList )
189     {
190         this.releaseList = releaseList;
191     }
192 
193     public String getPreparedReleaseId()
194     {
195         return preparedReleaseId;
196     }
197 
198     public void setPreparedReleaseId( String preparedReleaseId )
199     {
200         this.preparedReleaseId = preparedReleaseId;
201     }
202 
203     public String getProjectName()
204     {
205         return projectName;
206     }
207 
208     public void setProjectName( String projectName )
209     {
210         this.projectName = projectName;
211     }
212 
213     public String getProjectGroupName()
214         throws ContinuumException
215     {
216         if ( StringUtils.isEmpty( projectGroupName ) )
217         {
218             projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
219         }
220 
221         return projectGroupName;
222     }
223 
224     public Map<String, String> getPreparedReleases()
225     {
226         return preparedReleases;
227     }
228 
229     public void setPreparedReleases( Map<String, String> preparedReleases )
230     {
231         this.preparedReleases = preparedReleases;
232     }
233 }