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 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
40
41
42
43 public class ReleaseRollbackAction
44 extends ContinuumActionSupport
45 {
46
47
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
99 while ( listener.getState() != ContinuumReleaseManagerListener.FINISHED )
100 {
101 try
102 {
103 Thread.sleep( 1000 );
104 }
105 catch ( InterruptedException e )
106 {
107
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 }