View Javadoc

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.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   * @author Edwin Punzalan
35   * @version $Id: ReleaseCleanupAction.java 755103 2009-03-17 03:14:30Z ctan $
36   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseCleanup"
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 }