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