1 package org.apache.maven.scm.provider.synergy.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.log.ScmLogger;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class SynergyTaskManager
38 {
39
40
41
42 private static final short TASK_STATE_NONE = 0;
43
44
45
46
47 private static final short TASK_STATE_CREATED = 1;
48
49
50
51
52 private static final short TASK_STATE_COMPLETED = 2;
53
54
55
56
57 private static final SynergyTaskManager INSTANCE = new SynergyTaskManager();
58
59
60
61
62 private int currentTaskNumber;
63
64
65
66
67 private short currentTaskState = TASK_STATE_NONE;
68
69
70
71
72 public static SynergyTaskManager getInstance()
73 {
74 return INSTANCE;
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88 public int createTask( ScmLogger logger, String synopsis, String release, boolean defaultTask, String ccmAddr )
89 throws ScmException
90 {
91 if ( logger.isDebugEnabled() )
92 {
93 logger.debug( "Synergy : Entering createTask method of SynergyTaskManager" );
94 }
95 switch ( currentTaskState )
96 {
97 case TASK_STATE_CREATED:
98 if ( defaultTask )
99 {
100
101 if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != currentTaskNumber )
102 {
103 SynergyUtil.setDefaultTask( logger, currentTaskNumber, ccmAddr );
104 }
105 }
106 break;
107 case TASK_STATE_NONE:
108 case TASK_STATE_COMPLETED:
109 currentTaskNumber = SynergyUtil.createTask( logger, synopsis, release, defaultTask, ccmAddr );
110 currentTaskState = TASK_STATE_CREATED;
111 break;
112 default:
113 throw new IllegalStateException( "Programming error: SynergyTaskManager is in unkown state." );
114 }
115 if ( logger.isDebugEnabled() )
116 {
117 logger.debug( "createTask returns " + currentTaskNumber );
118 }
119 return currentTaskNumber;
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 public void checkinDefaultTask( ScmLogger logger, String comment, String ccmAddr )
137 throws ScmException
138 {
139 if ( logger.isDebugEnabled() )
140 {
141 logger.debug( "Synergy : Entering checkinDefaultTask method of SynergyTaskManager" );
142 }
143 switch ( currentTaskState )
144 {
145 case TASK_STATE_NONE:
146
147
148 if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != 0 )
149 {
150 SynergyUtil.checkinDefaultTask( logger, comment, ccmAddr );
151 }
152 else
153 {
154 throw new ScmException( "Check in not possible: no default task is set and "
155 + "no task has been created with SynergyTaskManager." );
156 }
157 break;
158 case TASK_STATE_CREATED:
159 SynergyUtil.checkinTask( logger, currentTaskNumber, comment, ccmAddr );
160 currentTaskState = TASK_STATE_COMPLETED;
161 break;
162 case TASK_STATE_COMPLETED:
163
164
165
166 if ( SynergyUtil.getDefaultTask( logger, ccmAddr ) != 0 )
167 {
168 SynergyUtil.checkinDefaultTask( logger, comment, ccmAddr );
169 }
170 else
171 {
172 if ( logger.isDebugEnabled() )
173 {
174 logger.debug( "Synergy : No check in necessary as default task and "
175 + "all tasks created with SynergyTaskManager have already been checked in." );
176 }
177 }
178 break;
179 default:
180 throw new IllegalStateException( "Programming error: SynergyTaskManager is in unkown state." );
181 }
182 }
183 }