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 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   * @author Edwin Punzalan
35   * @version $Id: ReleaseCleanupAction.java 1395451 2012-10-08 05:06:18Z brett $
36   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseCleanup"
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 }