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 java.util.ArrayList; |
23 | import java.util.List; |
24 | |
25 | import org.apache.continuum.configuration.BuildAgentConfigurationException; |
26 | import org.apache.continuum.release.distributed.manager.DistributedReleaseManager; |
27 | import org.apache.continuum.web.util.AuditLog; |
28 | import org.apache.continuum.web.util.AuditLogConstants; |
29 | import org.apache.maven.continuum.ContinuumException; |
30 | import org.apache.maven.continuum.utils.WorkingDirectoryService; |
31 | import org.apache.maven.continuum.model.project.Project; |
32 | import org.apache.maven.continuum.release.ContinuumReleaseManager; |
33 | import org.apache.maven.continuum.release.ContinuumReleaseManagerListener; |
34 | import org.apache.maven.continuum.release.DefaultReleaseManagerListener; |
35 | import org.apache.maven.continuum.web.exception.AuthorizationRequiredException; |
36 | import org.codehaus.plexus.util.StringUtils; |
37 | |
38 | /** |
39 | * @author Edwin Punzalan |
40 | * @version $Id: ReleaseRollbackAction.java 781924 2009-06-05 06:42:54Z ctan $ |
41 | * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseRollback" |
42 | */ |
43 | public class ReleaseRollbackAction |
44 | extends ContinuumActionSupport |
45 | { |
46 | /** |
47 | * @plexus.requirement |
48 | */ |
49 | private WorkingDirectoryService workingDirectoryService; |
50 | |
51 | private int projectId; |
52 | |
53 | private String releaseId; |
54 | |
55 | private String projectGroupName = ""; |
56 | |
57 | private String releaseGoal; |
58 | |
59 | public String execute() |
60 | throws Exception |
61 | { |
62 | try |
63 | { |
64 | checkBuildProjectInGroupAuthorization( getProjectGroupName() ); |
65 | } |
66 | catch ( AuthorizationRequiredException e ) |
67 | { |
68 | return REQUIRES_AUTHORIZATION; |
69 | } |
70 | |
71 | if ( getContinuum().getConfiguration().isDistributedBuildEnabled() ) |
72 | { |
73 | DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager(); |
74 | |
75 | try |
76 | { |
77 | releaseManager.releaseRollback( releaseId, projectId ); |
78 | } |
79 | catch ( BuildAgentConfigurationException e ) |
80 | { |
81 | List<String> args = new ArrayList<String>(); |
82 | args.add( e.getMessage() ); |
83 | |
84 | addActionError( getText( "releaseRollback.error", args ) ); |
85 | return ERROR; |
86 | } |
87 | } |
88 | else |
89 | { |
90 | ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager(); |
91 | |
92 | ContinuumReleaseManagerListener listener = new DefaultReleaseManagerListener(); |
93 | |
94 | Project project = getContinuum().getProject( projectId ); |
95 | |
96 | releaseManager.rollback( releaseId, workingDirectoryService.getWorkingDirectory( project ).getPath(), listener ); |
97 | |
98 | //recurse until rollback is finished |
99 | while ( listener.getState() != ContinuumReleaseManagerListener.FINISHED ) |
100 | { |
101 | try |
102 | { |
103 | Thread.sleep( 1000 ); |
104 | } |
105 | catch ( InterruptedException e ) |
106 | { |
107 | //do nothing |
108 | } |
109 | } |
110 | |
111 | AuditLog event = new AuditLog( "Release id=" + releaseId, AuditLogConstants.ROLLBACK_RELEASE ); |
112 | event.setCategory( AuditLogConstants.PROJECT ); |
113 | event.setCurrentUser( getPrincipal() ); |
114 | event.log(); |
115 | |
116 | releaseManager.getPreparedReleases().remove( releaseId ); |
117 | } |
118 | |
119 | return SUCCESS; |
120 | } |
121 | |
122 | public String warn() |
123 | throws Exception |
124 | { |
125 | try |
126 | { |
127 | checkBuildProjectInGroupAuthorization( getProjectGroupName() ); |
128 | } |
129 | catch ( AuthorizationRequiredException e ) |
130 | { |
131 | return REQUIRES_AUTHORIZATION; |
132 | } |
133 | |
134 | return SUCCESS; |
135 | } |
136 | |
137 | public int getProjectId() |
138 | { |
139 | return projectId; |
140 | } |
141 | |
142 | public void setProjectId( int projectId ) |
143 | { |
144 | this.projectId = projectId; |
145 | } |
146 | |
147 | public String getReleaseId() |
148 | { |
149 | return releaseId; |
150 | } |
151 | |
152 | public void setReleaseId( String releaseId ) |
153 | { |
154 | this.releaseId = releaseId; |
155 | } |
156 | |
157 | public String getProjectGroupName() |
158 | throws ContinuumException |
159 | { |
160 | if ( StringUtils.isEmpty( projectGroupName ) ) |
161 | { |
162 | projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName(); |
163 | } |
164 | |
165 | return projectGroupName; |
166 | } |
167 | |
168 | public String getReleaseGoal() |
169 | { |
170 | return releaseGoal; |
171 | } |
172 | |
173 | public void setReleaseGoal( String releaseGoal ) |
174 | { |
175 | this.releaseGoal = releaseGoal; |
176 | } |
177 | } |