1 /*
2 * LICENSE
3 *
4 * "THE BEER-WARE LICENSE" (Revision 43):
5 * "Sven Strittmatter" <weltraumschaf@googlemail.com> wrote this file.
6 * As long as you retain this notice you can do whatever you want with
7 * this stuff. If we meet some day, and you think this stuff is worth it,
8 * you can buy me a non alcohol-free beer in return.
9 *
10 * Copyright (C) 2012 "Sven Strittmatter" <weltraumschaf@googlemail.com>
11 */
12 package org.jenkinsci.plugins.darcs.cmd;
13
14 import hudson.util.ArgumentListBuilder;
15 import org.apache.commons.lang.Validate;
16
17 /**
18 * Builder for `darcs get` command.
19 *
20 * Example: {@literal `darcs get FROM TO`}
21 *
22 * @author Sven Strittmatter <weltraumschaf@googlemail.com>
23 */
24 public class DarcsGetBuilder extends DarcsBaseCommandBuilder implements DarcsCommandCreator {
25
26 /**
27 * Darcs subcommand.
28 */
29 private static final String COMMAND = "get";
30 /**
31 * From where to get.
32 */
33 private String from = "";
34 /**
35 * To where to get.
36 */
37 private String to = "";
38
39 /**
40 * Initializes the {@link DarcsBaseCommandBuilder#command} with {@value #COMMAND}.
41 *
42 * @param darcsExe name of Darcs executable, e.g. "darcs" or "/usr/local/bin/darcs"
43 */
44 DarcsGetBuilder(final String darcsExe) {
45 super(darcsExe, COMMAND);
46 }
47
48 /**
49 * From where to get the repository.
50 *
51 * @param location file or URI
52 * @return the builder itself
53 * CHECKSTYLE:OFF
54 * @throws IllegalArgumentException if location is {@code null} or empty
55 * CHECKSTYLE:ON
56 */
57 public DarcsGetBuilder from(final String location) {
58 Validate.notEmpty(location);
59 from = location;
60 return this;
61 }
62
63 /**
64 * To where the repository will be checked out.
65 *
66 * @param location file path
67 * @return the builder itself
68 * CHECKSTYLE:OFF
69 * @throws IllegalArgumentException if location is {@code null}
70 * CHECKSTYLE:ON
71 */
72 public DarcsGetBuilder to(final String location) {
73 Validate.notNull(location);
74 to = location;
75 return this;
76 }
77
78 @Override
79 public DarcsCommand create() {
80 Validate.notEmpty(from, "Set from where to get the repo!");
81 final ArgumentListBuilder arguments = createArgumentList();
82 arguments.add(from);
83
84 if (to.length() > 0) {
85 arguments.add(to);
86 }
87
88 return new DarcsCommand(arguments);
89 }
90
91 }