Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SynergyTaskManager |
|
| 6.666666666666667;6,667 |
1 | package org.apache.maven.scm.provider.synergy.util; | |
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.maven.scm.ScmException; | |
23 | import org.apache.maven.scm.log.ScmLogger; | |
24 | ||
25 | /** | |
26 | * In some Synergy versions (ie. 6.5) closing a session results in de-selecting | |
27 | * the current (default) task. Therefore, the maven release-plugin fails, as the | |
28 | * Synergy commands, as implemented in the Synergy-SCM-Provider, always close | |
29 | * their session after being executed.<br> | |
30 | * This manager circumvents this problem by storing the last created task which | |
31 | * causes all check outs to be associated with it. Then, when this task gets | |
32 | * checked in, all associated files get checked in as well. | |
33 | * | |
34 | * @author <a href="jan.malcomess@steria-mummert.de">Jan Malcomess</a> | |
35 | * @since 1.5 | |
36 | */ | |
37 | 0 | public class SynergyTaskManager |
38 | { | |
39 | /** | |
40 | * No Synergy-Task was created yet. | |
41 | */ | |
42 | private final static short TASK_STATE_NONE = 0; | |
43 | ||
44 | /** | |
45 | * The current Synergy-Task is created but not yet completed. | |
46 | */ | |
47 | private final static short TASK_STATE_CREATED = 1; | |
48 | ||
49 | /** | |
50 | * The current Synergy-Task is completed. | |
51 | */ | |
52 | private final static short TASK_STATE_COMPLETED = 2; | |
53 | ||
54 | /** | |
55 | * singleton instance. | |
56 | */ | |
57 | 0 | private final static SynergyTaskManager INSTANCE = new SynergyTaskManager(); |
58 | ||
59 | /** | |
60 | * The number of the current Synergy-Task. | |
61 | */ | |
62 | private int currentTaskNumber; | |
63 | ||
64 | /** | |
65 | * The state of the current Synergy-Task. | |
66 | */ | |
67 | 0 | private short currentTaskState = TASK_STATE_NONE; |
68 | ||
69 | /** | |
70 | * @return singleton instance. | |
71 | */ | |
72 | public static SynergyTaskManager getInstance() | |
73 | { | |
74 | 0 | return INSTANCE; |
75 | } | |
76 | ||
77 | /** | |
78 | * If necessary create a new task. Otherwise return the current task. | |
79 | * | |
80 | * @param logger a logger. | |
81 | * @param synopsis short description of task. | |
82 | * @param release release. | |
83 | * @param defaultTask should this task become the default task? | |
84 | * @param ccmAddr current Synergy session ID. Used to run in multi-session. | |
85 | * @return Task number | |
86 | * @throws ScmException | |
87 | */ | |
88 | public int createTask( ScmLogger logger, String synopsis, String release, boolean defaultTask, String ccmAddr ) | |
89 | throws ScmException | |
90 | { | |
91 | 0 | if ( logger.isDebugEnabled() ) |
92 | { | |
93 | 0 | logger.debug( "Synergy : Entering createTask method of SynergyTaskManager" ); |
94 | } | |
95 | 0 | switch ( currentTaskState ) |
96 | { | |
97 | case TASK_STATE_CREATED: | |
98 | 0 | if ( defaultTask ) |
99 | { | |
100 | // make sure the current task is the default task | |
101 | 0 | if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != currentTaskNumber ) |
102 | { | |
103 | 0 | SynergyUtil.setDefaultTask( logger, currentTaskNumber, ccmAddr ); |
104 | } | |
105 | } | |
106 | break; | |
107 | case TASK_STATE_NONE: // fall through | |
108 | case TASK_STATE_COMPLETED: | |
109 | 0 | currentTaskNumber = SynergyUtil.createTask( logger, synopsis, release, defaultTask, ccmAddr ); |
110 | 0 | currentTaskState = TASK_STATE_CREATED; |
111 | 0 | break; |
112 | default: | |
113 | 0 | throw new IllegalStateException( "Programming error: SynergyTaskManager is in unkown state." ); |
114 | } | |
115 | 0 | if ( logger.isDebugEnabled() ) |
116 | { | |
117 | 0 | logger.debug( "createTask returns " + currentTaskNumber ); |
118 | } | |
119 | 0 | return currentTaskNumber; |
120 | } | |
121 | ||
122 | /** | |
123 | * Check in (that is: complete) the default task. This is either the current task managed by | |
124 | * <code>SynergyTaskManager</code> or, if none is managed, the default task.<br> | |
125 | * In case no task has yet been created by <code>SynergyTaskManager</code> AND no default task is set, then this is | |
126 | * an error.<br> | |
127 | * However, if the task that was created by <code>SynergyTaskManager</code> has already been checked in AND no | |
128 | * default task is set, then it is assumed that all files that were checked out are already checked in because | |
129 | * checking in a task checks in all files associated with it. | |
130 | * | |
131 | * @param logger a logger. | |
132 | * @param comment a comment for checkin. | |
133 | * @param ccmAddr current Synergy session ID. Used to run in multi-session. | |
134 | * @throws ScmException | |
135 | */ | |
136 | public void checkinDefaultTask( ScmLogger logger, String comment, String ccmAddr ) | |
137 | throws ScmException | |
138 | { | |
139 | 0 | if ( logger.isDebugEnabled() ) |
140 | { | |
141 | 0 | logger.debug( "Synergy : Entering checkinDefaultTask method of SynergyTaskManager" ); |
142 | } | |
143 | 0 | switch ( currentTaskState ) |
144 | { | |
145 | case TASK_STATE_NONE: | |
146 | // if a default task is set, then check in that | |
147 | // otherwise we have an error | |
148 | 0 | if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != 0 ) |
149 | { | |
150 | 0 | SynergyUtil.checkinDefaultTask( logger, comment, ccmAddr ); |
151 | } | |
152 | else | |
153 | { | |
154 | 0 | throw new ScmException( |
155 | "Check in not possible: no default task is set and no task has been created with SynergyTaskManager." ); | |
156 | } | |
157 | break; | |
158 | case TASK_STATE_CREATED: | |
159 | 0 | SynergyUtil.checkinTask( logger, currentTaskNumber, comment, ccmAddr ); |
160 | 0 | currentTaskState = TASK_STATE_COMPLETED; |
161 | 0 | break; |
162 | case TASK_STATE_COMPLETED: | |
163 | // if a default task is set, then check in that | |
164 | // otherwise do nothing, as all tasks and all files with them have | |
165 | // been checked in | |
166 | 0 | if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != 0 ) |
167 | { | |
168 | 0 | SynergyUtil.checkinDefaultTask( logger, comment, ccmAddr ); |
169 | } | |
170 | else | |
171 | { | |
172 | 0 | if ( logger.isDebugEnabled() ) |
173 | { | |
174 | 0 | logger.debug( "Synergy : No check in necessary as default task and all tasks created with SynergyTaskManager have already been checked in." ); |
175 | } | |
176 | } | |
177 | break; | |
178 | default: | |
179 | 0 | throw new IllegalStateException( "Programming error: SynergyTaskManager is in unkown state." ); |
180 | } | |
181 | 0 | } |
182 | } |