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.maven.continuum.ContinuumException;
28 import org.apache.maven.continuum.release.ContinuumReleaseManager;
29 import org.apache.maven.continuum.release.ContinuumReleaseManagerListener;
30 import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
31 import org.codehaus.plexus.util.StringUtils;
32
33
34
35
36
37
38
39 public class ReleaseCleanupAction
40 extends ContinuumActionSupport
41 {
42 private int projectId;
43
44 private String releaseId;
45
46 private String projectGroupName = "";
47
48 public String execute()
49 throws Exception
50 {
51 try
52 {
53 checkBuildProjectInGroupAuthorization( getProjectGroupName() );
54 }
55 catch ( AuthorizationRequiredException e )
56 {
57 return REQUIRES_AUTHORIZATION;
58 }
59
60 if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
61 {
62 DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager();
63
64 try
65 {
66 String goal = releaseManager.releaseCleanup( releaseId );
67
68 if ( StringUtils.isNotBlank( goal ) )
69 {
70 return goal;
71 }
72 else
73 {
74 throw new Exception( "No listener to cleanup for id " + releaseId );
75 }
76 }
77 catch ( BuildAgentConfigurationException e )
78 {
79 List<String> args = new ArrayList<String>();
80 args.add( e.getMessage() );
81
82 addActionError( getText( "releaseCleanup.error", args ) );
83 return ERROR;
84 }
85 }
86 else
87 {
88 ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager();
89
90 releaseManager.getReleaseResults().remove( releaseId );
91
92 ContinuumReleaseManagerListener listener =
93 (ContinuumReleaseManagerListener) releaseManager.getListeners().remove( releaseId );
94
95 if ( listener != null )
96 {
97 String goal = listener.getGoalName();
98
99 return goal + "Finished";
100 }
101 else
102 {
103 throw new Exception( "No listener to cleanup for id " + releaseId );
104 }
105 }
106 }
107
108 public String getReleaseId()
109 {
110 return releaseId;
111 }
112
113 public void setReleaseId( String releaseId )
114 {
115 this.releaseId = releaseId;
116 }
117
118 public int getProjectId()
119 {
120 return projectId;
121 }
122
123 public void setProjectId( int projectId )
124 {
125 this.projectId = projectId;
126 }
127
128 public String getProjectGroupName()
129 throws ContinuumException
130 {
131 if ( projectGroupName == null || "".equals( projectGroupName ) )
132 {
133 projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
134 }
135
136 return projectGroupName;
137 }
138
139 public int getProjectGroupId()
140 throws ContinuumException
141 {
142 return getContinuum().getProjectGroupByProjectId( projectId ).getId();
143 }
144 }