1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.bugzilla;
17
18 import java.util.List;
19
20 import org.apache.maven.artifact.versioning.ArtifactVersion;
21 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
22 import org.apache.maven.project.MavenProject;
23
24 import de.smartics.maven.bugzilla.AbstractIssueMojo.IssueServer;
25 import de.smartics.maven.bugzilla.AbstractMojoHelperProduct.ProductInfo;
26 import de.smartics.maven.issue.command.AddComponentCommand;
27 import de.smartics.maven.issue.command.AddMilestoneCommand;
28 import de.smartics.maven.issue.command.AddProductCommand;
29 import de.smartics.maven.issue.command.AddVersionCommand;
30 import de.smartics.maven.issue.command.ClassificationNavigationCommand;
31 import de.smartics.maven.issue.command.CommandArgument;
32 import de.smartics.maven.issue.command.CommandFactory;
33 import de.smartics.maven.issue.command.LoginCommand;
34 import de.smartics.maven.issue.command.LogoutCommand;
35 import de.smartics.maven.issue.command.ProductNavigationCommand;
36 import de.smartics.maven.issue.command.UpdateProductCommand;
37 import de.smartics.maven.issue.config.Component;
38
39
40
41
42 final class MavenCommandFactory
43 {
44
45
46
47
48
49
50
51
52
53 private final MavenProject project;
54
55
56
57
58 private final CommandFactory commandFactory;
59
60
61
62
63
64 MavenCommandFactory(final MavenProject project,
65 final CommandFactory commandFactory)
66 {
67 this.project = project;
68 this.commandFactory = commandFactory;
69 }
70
71
72
73
74
75
76
77
78
79
80
81 String calculateNextVersion()
82 {
83 final String version = project.getVersion();
84 final ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);
85 final int nextIncrement = artifactVersion.getIncrementalVersion();
86 final String nextVersion =
87 String.valueOf(artifactVersion.getMajorVersion()) + '.'
88 + artifactVersion.getMajorVersion() + '.' + nextIncrement;
89 return nextVersion;
90 }
91
92 LoginCommand createLoginCommand(final IssueServer server)
93 {
94 final String loginString = server.getUsername();
95 final CommandArgument<LoginCommand> login =
96 CommandArgument.create(LoginCommand.Parameter.LOGIN, loginString);
97 final String passwordString = server.getPassword();
98 final CommandArgument<LoginCommand> password =
99 CommandArgument.create(LoginCommand.Parameter.PASSWORD, passwordString,
100 true);
101 final LoginCommand command =
102 commandFactory.createLoginCommand(login, password);
103 return command;
104 }
105
106 AddVersionCommand createAddVersionCommand(final String productString,
107 final String nextVersionString, final String tokenString)
108 {
109 final CommandArgument<AddVersionCommand> product =
110 CommandArgument.create(AddVersionCommand.Parameter.PRODUCT,
111 productString);
112 final CommandArgument<AddVersionCommand> version =
113 CommandArgument.create(AddVersionCommand.Parameter.VERSION,
114 nextVersionString);
115 final CommandArgument<AddVersionCommand> token =
116 CommandArgument.create(AddVersionCommand.Parameter.TOKEN, tokenString);
117 final AddVersionCommand command =
118 commandFactory.createAddVersionCommand(product, version, token);
119 return command;
120 }
121
122 AddMilestoneCommand createAddMilestoneCommand(final String productString,
123 final String nextMilestoneString, final String sortkeyString,
124 final String tokenString)
125 {
126 final CommandArgument<AddMilestoneCommand> product =
127 CommandArgument.create(AddMilestoneCommand.Parameter.PRODUCT,
128 productString);
129 final CommandArgument<AddMilestoneCommand> milestone =
130 CommandArgument.create(AddMilestoneCommand.Parameter.MILESTONE,
131 nextMilestoneString);
132 final CommandArgument<AddMilestoneCommand> sortkey =
133 CommandArgument.create(AddMilestoneCommand.Parameter.SORTKEY,
134 sortkeyString);
135 final CommandArgument<AddMilestoneCommand> token =
136 CommandArgument
137 .create(AddMilestoneCommand.Parameter.TOKEN, tokenString);
138 final AddMilestoneCommand command =
139 commandFactory.createAddMilestoneCommand(product, milestone, sortkey,
140 token);
141 return command;
142 }
143
144
145 AddProductCommand createAddProductCommand(
146
147 final String classificationString, final String productString,
148 final String descriptionString, final String defaultMilestoneString,
149 final String versionString, final String tokenString,
150 final ProductInfo productInfo, final List<Component> components)
151 {
152 final CommandArgument<AddProductCommand> classification =
153 CommandArgument.create(AddProductCommand.Parameter.CLASSIFICATION,
154 classificationString);
155 final CommandArgument<AddProductCommand> product =
156 CommandArgument.create(AddProductCommand.Parameter.PRODUCT,
157 productString);
158 final CommandArgument<AddProductCommand> description =
159 CommandArgument.create(AddProductCommand.Parameter.DESCRIPTION,
160 descriptionString);
161 final CommandArgument<AddProductCommand> defaultMilestone =
162 CommandArgument.create(AddProductCommand.Parameter.DEFAULT_MILESTONE,
163 defaultMilestoneString);
164 final CommandArgument<AddProductCommand> version =
165 CommandArgument.create(AddProductCommand.Parameter.VERSION,
166 versionString);
167 final CommandArgument<AddProductCommand> token =
168 CommandArgument.create(AddProductCommand.Parameter.TOKEN, tokenString);
169
170 final AddProductCommand command;
171 if (commandFactory.requiresComponentOnProductCreation()
172 && !components.isEmpty())
173 {
174 final Component component = components.get(0);
175 final CommandArgument<AddProductCommand> componentArg =
176 CommandArgument.create(AddProductCommand.Parameter.COMPONENT,
177 component.getName());
178 final CommandArgument<AddProductCommand> componentDescription =
179 CommandArgument.create(
180 AddProductCommand.Parameter.COMPONENT_DESCRIPTION,
181 component.getDescription());
182 final CommandArgument<AddProductCommand> componentInitialOwner =
183 CommandArgument.create(
184 AddProductCommand.Parameter.COMPONENT_INITIAL_OWNER,
185 productInfo.getInitialOwner());
186 command =
187 commandFactory.createAddProductCommand(classification, product,
188 description, defaultMilestone, version, token, componentArg,
189 componentDescription, componentInitialOwner);
190 }
191 else
192 {
193 command =
194 commandFactory.createAddProductCommand(classification, product,
195 description, defaultMilestone, version, token);
196 }
197
198 return command;
199 }
200
201
202
203
204 UpdateProductCommand createUpdateProductCommand(
205
206 final String productOldString, final String productString,
207 final String descriptionString, final String defaultMilestoneString,
208 final String tokenString)
209 {
210 final CommandArgument<UpdateProductCommand> oldProduct =
211 CommandArgument.create(UpdateProductCommand.Parameter.PRODUCT_OLD_NAME,
212 productOldString);
213 final CommandArgument<UpdateProductCommand> product =
214 CommandArgument.create(UpdateProductCommand.Parameter.PRODUCT,
215 productString);
216 final CommandArgument<UpdateProductCommand> description =
217 CommandArgument.create(UpdateProductCommand.Parameter.DESCRIPTION,
218 descriptionString);
219 final CommandArgument<UpdateProductCommand> defaultMilestone =
220 CommandArgument.create(
221 UpdateProductCommand.Parameter.DEFAULT_MILESTONE,
222 defaultMilestoneString);
223 final CommandArgument<UpdateProductCommand> token =
224 CommandArgument.create(UpdateProductCommand.Parameter.TOKEN,
225 tokenString);
226 final UpdateProductCommand command =
227 commandFactory.createUpdateProductCommand(oldProduct, product,
228 description, defaultMilestone, token);
229 return command;
230 }
231
232
233
234 AddComponentCommand createAddComponentCommand(final String productString,
235 final String componentString, final String descriptionString,
236 final String initialOwnerString, final String tokenString)
237 {
238 final CommandArgument<AddComponentCommand> product =
239 CommandArgument.create(AddComponentCommand.Parameter.PRODUCT,
240 productString);
241 final CommandArgument<AddComponentCommand> component =
242 CommandArgument.create(AddComponentCommand.Parameter.COMPONENT,
243 componentString);
244 final CommandArgument<AddComponentCommand> description =
245 CommandArgument.create(AddComponentCommand.Parameter.DESCRIPTION,
246 descriptionString);
247 final CommandArgument<AddComponentCommand> initialOwner =
248 CommandArgument.create(AddComponentCommand.Parameter.INITIAL_OWNER,
249 initialOwnerString);
250 final CommandArgument<AddComponentCommand> token =
251 CommandArgument
252 .create(AddComponentCommand.Parameter.TOKEN, tokenString);
253 final AddComponentCommand command =
254 commandFactory.createAddComponentCommand(product, component,
255 description, initialOwner, token);
256 return command;
257 }
258
259 LogoutCommand createLogoutCommand()
260 {
261 final LogoutCommand command = commandFactory.createLogoutCommand();
262 return command;
263 }
264
265
266 ClassificationNavigationCommand createClassificationNavigationCommand(
267 final String classificationString)
268 {
269 final CommandArgument<ClassificationNavigationCommand> classification =
270 CommandArgument.create(
271 ClassificationNavigationCommand.Parameter.CLASSIFICATION,
272 classificationString);
273 final ClassificationNavigationCommand command =
274 commandFactory.createClassificationNavigationCommand(
275 "editproducts.cgi", classification);
276 return command;
277 }
278
279
280 ProductNavigationCommand createVersionProductNavigationCommand(
281 final String productString)
282 {
283 return createProductNavigationCommand("editversions.cgi", productString);
284 }
285
286
287 ProductNavigationCommand createMilestoneProductNavigationCommand(
288 final String productString)
289 {
290 return createProductNavigationCommand("editmilestones.cgi", productString);
291 }
292
293
294 ProductNavigationCommand createComponentProductNavigationCommand(
295 final String productString)
296 {
297 return createProductNavigationCommand("editcomponents.cgi", productString);
298 }
299
300
301 ProductNavigationCommand createProductNavigationCommand(
302 final String productString)
303 {
304 final CommandArgument<ProductNavigationCommand> action =
305 CommandArgument.create(ProductNavigationCommand.Parameter.ACTION,
306 "edit");
307 final CommandArgument<ProductNavigationCommand> product =
308 CommandArgument.create(ProductNavigationCommand.Parameter.PRODUCT,
309 productString);
310 final ProductNavigationCommand command =
311 commandFactory.createProductNavigationCommand("editproducts.cgi",
312 action, product);
313 return command;
314 }
315
316 private ProductNavigationCommand createProductNavigationCommand(
317 final String service, final String productString)
318 {
319 final CommandArgument<ProductNavigationCommand> product =
320 CommandArgument.create(ProductNavigationCommand.Parameter.PRODUCT,
321 productString);
322 final ProductNavigationCommand command =
323 commandFactory.createProductNavigationCommand(service, product);
324 return command;
325 }
326
327
328
329 }