1 package org.apache.maven.continuum.web.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.configuration.BuildAgentConfigurationException;
23 import org.apache.continuum.release.distributed.manager.DistributedReleaseManager;
24 import org.apache.maven.artifact.ArtifactUtils;
25 import org.apache.maven.continuum.ContinuumException;
26 import org.apache.maven.continuum.model.project.Project;
27 import org.apache.maven.continuum.release.ContinuumReleaseManager;
28 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
29 import org.apache.maven.shared.release.config.ReleaseDescriptor;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39
40
41 public class ReleaseProjectAction
42 extends ContinuumActionSupport
43 {
44 private int projectId;
45
46 private String projectName;
47
48 private String preparedReleaseName;
49
50 private String preparedReleaseId;
51
52 private String goal;
53
54 private String scmUrl;
55
56 private Project project;
57
58 private List releaseList;
59
60 private String projectGroupName = "";
61
62 protected static final String REQUIRES_CONFIGURATION = "releaseOutputDir-required";
63
64 public String promptReleaseGoal()
65 throws Exception
66 {
67 try
68 {
69 checkBuildProjectInGroupAuthorization( getProjectGroupName() );
70 }
71 catch ( AuthorizationRequiredException e )
72 {
73 return REQUIRES_AUTHORIZATION;
74 }
75
76
77 if ( getContinuum().getConfiguration().getReleaseOutputDirectory() == null )
78 {
79 return REQUIRES_CONFIGURATION;
80 }
81
82 project = getContinuum().getProjectWithAllDetails( projectId );
83
84 String releaseId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
85
86 if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
87 {
88 DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager();
89
90 preparedReleaseName = releaseManager.getPreparedReleaseName( releaseId );
91
92 if ( StringUtils.isNotBlank( preparedReleaseName ) )
93 {
94 preparedReleaseId = releaseId;
95 }
96 else
97 {
98 preparedReleaseName = null;
99 }
100 }
101 else
102 {
103 ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager();
104
105 Map preparedReleases = releaseManager.getPreparedReleases();
106 if ( preparedReleases.containsKey( releaseId ) )
107 {
108 ReleaseDescriptor descriptor = (ReleaseDescriptor) preparedReleases.get( releaseId );
109
110 preparedReleaseName = descriptor.getReleaseVersions().get( releaseId ).toString();
111
112 preparedReleaseId = releaseId;
113 }
114 }
115
116 projectName = project.getName();
117
118 return SUCCESS;
119 }
120
121 public String execute()
122 throws Exception
123 {
124 try
125 {
126 checkBuildProjectInGroupAuthorization( getProjectGroupName() );
127 }
128 catch ( AuthorizationRequiredException e )
129 {
130 return REQUIRES_AUTHORIZATION;
131 }
132
133 if ( "prepare".equals( goal ) )
134 {
135 return "prepareRelease";
136 }
137 else if ( "perform".equals( goal ) )
138 {
139 if ( "".equals( preparedReleaseId ) )
140 {
141 return "performReleaseFromScm";
142 }
143 else
144 {
145 return "performRelease";
146 }
147 }
148 else
149 {
150 return "prompt";
151 }
152 }
153
154 public int getProjectId()
155 {
156 return projectId;
157 }
158
159 public void setProjectId( int projectId )
160 {
161 this.projectId = projectId;
162 }
163
164 public String getPreparedReleaseName()
165 {
166 return preparedReleaseName;
167 }
168
169 public void setPreparedReleaseName( String preparedReleaseName )
170 {
171 this.preparedReleaseName = preparedReleaseName;
172 }
173
174 public String getGoal()
175 {
176 return goal;
177 }
178
179 public void setGoal( String goal )
180 {
181 this.goal = goal;
182 }
183
184 public Project getProject()
185 {
186 return project;
187 }
188
189 public void setProject( Project project )
190 {
191 this.project = project;
192 }
193
194 public String getScmUrl()
195 {
196 return scmUrl;
197 }
198
199 public void setScmUrl( String scmUrl )
200 {
201 this.scmUrl = scmUrl;
202 }
203
204 public List getReleaseList()
205 {
206 return releaseList;
207 }
208
209 public void setReleaseList( List releaseList )
210 {
211 this.releaseList = releaseList;
212 }
213
214 public String getPreparedReleaseId()
215 {
216 return preparedReleaseId;
217 }
218
219 public void setPreparedReleaseId( String preparedReleaseId )
220 {
221 this.preparedReleaseId = preparedReleaseId;
222 }
223
224 public String getProjectName()
225 {
226 return projectName;
227 }
228
229 public void setProjectName( String projectName )
230 {
231 this.projectName = projectName;
232 }
233
234 public String getProjectGroupName()
235 throws ContinuumException
236 {
237 if ( StringUtils.isEmpty( projectGroupName ) )
238 {
239 projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
240 }
241
242 return projectGroupName;
243 }
244 }