EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.maven.continuum.web.action]

COVERAGE SUMMARY FOR SOURCE FILE [ReleaseRollbackAction.java]

nameclass, %method, %block, %line, %
ReleaseRollbackAction.java0%   (0/1)0%   (0/10)0%   (0/159)0%   (0/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ReleaseRollbackAction0%   (0/1)0%   (0/10)0%   (0/159)0%   (0/47)
ReleaseRollbackAction (): void 0%   (0/1)0%   (0/6)0%   (0/2)
execute (): String 0%   (0/1)0%   (0/107)0%   (0/28)
getProjectGroupName (): String 0%   (0/1)0%   (0/15)0%   (0/3)
getProjectId (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getReleaseGoal (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getReleaseId (): String 0%   (0/1)0%   (0/3)0%   (0/1)
setProjectId (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
setReleaseGoal (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setReleaseId (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
warn (): String 0%   (0/1)0%   (0/10)0%   (0/5)

1package 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 
22import java.util.ArrayList;
23import java.util.List;
24 
25import org.apache.continuum.configuration.BuildAgentConfigurationException;
26import org.apache.continuum.release.distributed.manager.DistributedReleaseManager;
27import org.apache.continuum.web.util.AuditLog;
28import org.apache.continuum.web.util.AuditLogConstants;
29import org.apache.maven.continuum.ContinuumException;
30import org.apache.maven.continuum.utils.WorkingDirectoryService;
31import org.apache.maven.continuum.model.project.Project;
32import org.apache.maven.continuum.release.ContinuumReleaseManager;
33import org.apache.maven.continuum.release.ContinuumReleaseManagerListener;
34import org.apache.maven.continuum.release.DefaultReleaseManagerListener;
35import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
36import org.codehaus.plexus.util.StringUtils;
37 
38/**
39 * @author Edwin Punzalan
40 * @version $Id: ReleaseRollbackAction.java 781924 2009-06-05 06:42:54Z ctan $
41 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="releaseRollback"
42 */
43public class ReleaseRollbackAction
44    extends ContinuumActionSupport
45{
46    /**
47     * @plexus.requirement
48     */
49    private WorkingDirectoryService workingDirectoryService;
50 
51    private int projectId;
52 
53    private String releaseId;
54 
55    private String projectGroupName = "";
56 
57    private String releaseGoal;
58 
59    public String execute()
60        throws Exception
61    {
62        try
63        {
64            checkBuildProjectInGroupAuthorization( getProjectGroupName() );
65        }
66        catch ( AuthorizationRequiredException e )
67        {
68            return REQUIRES_AUTHORIZATION;
69        }
70 
71        if ( getContinuum().getConfiguration().isDistributedBuildEnabled() )
72        {
73            DistributedReleaseManager releaseManager = getContinuum().getDistributedReleaseManager();
74 
75            try
76            {
77                releaseManager.releaseRollback( releaseId, projectId );
78            }
79            catch ( BuildAgentConfigurationException e )
80            {
81                List<String> args = new ArrayList<String>();
82                args.add( e.getMessage() );
83 
84                addActionError( getText( "releaseRollback.error", args ) );
85                return ERROR;
86            }
87        }
88        else
89        {
90            ContinuumReleaseManager releaseManager = getContinuum().getReleaseManager();
91    
92            ContinuumReleaseManagerListener listener = new DefaultReleaseManagerListener();
93    
94            Project project = getContinuum().getProject( projectId );
95    
96            releaseManager.rollback( releaseId, workingDirectoryService.getWorkingDirectory( project ).getPath(), listener );
97    
98            //recurse until rollback is finished
99            while ( listener.getState() != ContinuumReleaseManagerListener.FINISHED )
100            {
101                try
102                {
103                    Thread.sleep( 1000 );
104                }
105                catch ( InterruptedException e )
106                {
107                    //do nothing
108                }
109            }
110 
111            AuditLog event = new AuditLog( "Release id=" + releaseId, AuditLogConstants.ROLLBACK_RELEASE );
112            event.setCategory( AuditLogConstants.PROJECT );
113            event.setCurrentUser( getPrincipal() );
114            event.log();
115    
116            releaseManager.getPreparedReleases().remove( releaseId );
117        }
118 
119        return SUCCESS;
120    }
121 
122    public String warn()
123        throws Exception
124    {
125        try
126        {
127            checkBuildProjectInGroupAuthorization( getProjectGroupName() );
128        }
129        catch ( AuthorizationRequiredException e )
130        {
131            return REQUIRES_AUTHORIZATION;
132        }
133 
134        return SUCCESS;
135    }
136 
137    public int getProjectId()
138    {
139        return projectId;
140    }
141 
142    public void setProjectId( int projectId )
143    {
144        this.projectId = projectId;
145    }
146 
147    public String getReleaseId()
148    {
149        return releaseId;
150    }
151 
152    public void setReleaseId( String releaseId )
153    {
154        this.releaseId = releaseId;
155    }
156 
157    public String getProjectGroupName()
158        throws ContinuumException
159    {
160        if ( StringUtils.isEmpty( projectGroupName ) )
161        {
162            projectGroupName = getContinuum().getProjectGroupByProjectId( projectId ).getName();
163        }
164 
165        return projectGroupName;
166    }
167 
168    public String getReleaseGoal()
169    {
170        return releaseGoal;
171    }
172 
173    public void setReleaseGoal( String releaseGoal )
174    {
175        this.releaseGoal = releaseGoal;
176    }
177}

[all classes][org.apache.maven.continuum.web.action]
EMMA 2.0.5312 (C) Vladimir Roubtsov