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.artifact.ArtifactUtils;
25  import org.apache.maven.continuum.ContinuumException;
26  import org.apache.maven.continuum.model.project.Project;
27  import org.apache.maven.continuum.release.ContinuumReleaseManager;
28  import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
29  import org.apache.maven.shared.release.config.ReleaseDescriptor;
30  import org.codehaus.plexus.util.StringUtils;
31  
32  import java.util.ArrayList;
33  import java.util.List;
34  import java.util.Map;
35  
36  /**
37   * @author Edwin Punzalan
38   * @version $Id: ReleaseProjectAction.java 755103 2009-03-17 03:14:30Z ctan $
39   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseProject"
40   */
41  public class ReleaseProjectAction
42      extends ContinuumActionSupport
43  {
44      private int projectId;
45  
46      private String projectName;
47  
48      private String preparedReleaseName;
49  
50      private String preparedReleaseId;
51  
52      private String goal;
53  
54      private String scmUrl;
55  
56      private Project project;
57  
58      private List releaseList;
59  
60      private String projectGroupName = "";
61  
62      protected static final String REQUIRES_CONFIGURATION = "releaseOutputDir-required";
63  
64      public String promptReleaseGoal()
65          throws Exception
66      {
67          try
68          {
69              checkBuildProjectInGroupAuthorization( getProjectGroupName() );
70          }
71          catch ( AuthorizationRequiredException e )
72          {
73              return REQUIRES_AUTHORIZATION;
74          }
75  
76          // check if releaseOutputDirectory is already set
77          if ( getContinuum().getConfiguration().getReleaseOutputDirectory() == null )
78          {
79              return REQUIRES_CONFIGURATION;
80          }
81          
82          project = getContinuum().getProjectWithAllDetails( projectId );
83  
84          String releaseId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
85  
86          if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
87          {
88              DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager();
89  
90              preparedReleaseName = releaseManager.getPreparedReleaseName( releaseId );
91  
92              if ( StringUtils.isNotBlank( preparedReleaseName ) )
93              {
94                  preparedReleaseId = releaseId;
95              }
96              else
97              {
98                  preparedReleaseName = null;
99              }
100         }
101         else
102         {
103             ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager();
104     
105             Map preparedReleases = releaseManager.getPreparedReleases();
106             if ( preparedReleases.containsKey( releaseId ) )
107             {
108                 ReleaseDescriptor descriptor = (ReleaseDescriptor) preparedReleases.get( releaseId );
109     
110                 preparedReleaseName = descriptor.getReleaseVersions().get( releaseId ).toString();
111     
112                 preparedReleaseId = releaseId;
113             }
114         }
115 
116         projectName = project.getName();
117 
118         return SUCCESS;
119     }
120 
121     public String execute()
122         throws Exception
123     {
124         try
125         {
126             checkBuildProjectInGroupAuthorization( getProjectGroupName() );
127         }
128         catch ( AuthorizationRequiredException e )
129         {
130             return REQUIRES_AUTHORIZATION;
131         }
132 
133         if ( "prepare".equals( goal ) )
134         {
135             return "prepareRelease";
136         }
137         else if ( "perform".equals( goal ) )
138         {
139             if ( "".equals( preparedReleaseId ) )
140             {
141                 return "performReleaseFromScm";
142             }
143             else
144             {
145                 return "performRelease";
146             }
147         }
148         else
149         {
150             return "prompt";
151         }
152     }
153 
154     public int getProjectId()
155     {
156         return projectId;
157     }
158 
159     public void setProjectId( int projectId )
160     {
161         this.projectId = projectId;
162     }
163 
164     public String getPreparedReleaseName()
165     {
166         return preparedReleaseName;
167     }
168 
169     public void setPreparedReleaseName( String preparedReleaseName )
170     {
171         this.preparedReleaseName = preparedReleaseName;
172     }
173 
174     public String getGoal()
175     {
176         return goal;
177     }
178 
179     public void setGoal( String goal )
180     {
181         this.goal = goal;
182     }
183 
184     public Project getProject()
185     {
186         return project;
187     }
188 
189     public void setProject( Project project )
190     {
191         this.project = project;
192     }
193 
194     public String getScmUrl()
195     {
196         return scmUrl;
197     }
198 
199     public void setScmUrl( String scmUrl )
200     {
201         this.scmUrl = scmUrl;
202     }
203 
204     public List getReleaseList()
205     {
206         return releaseList;
207     }
208 
209     public void setReleaseList( List releaseList )
210     {
211         this.releaseList = releaseList;
212     }
213 
214     public String getPreparedReleaseId()
215     {
216         return preparedReleaseId;
217     }
218 
219     public void setPreparedReleaseId( String preparedReleaseId )
220     {
221         this.preparedReleaseId = preparedReleaseId;
222     }
223 
224     public String getProjectName()
225     {
226         return projectName;
227     }
228 
229     public void setProjectName( String projectName )
230     {
231         this.projectName = projectName;
232     }
233 
234     public String getProjectGroupName()
235         throws ContinuumException
236     {
237         if ( StringUtils.isEmpty( projectGroupName ) )
238         {
239             projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
240         }
241 
242         return projectGroupName;
243     }
244 }