View Javadoc

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   * Common base implementation for sub builders.
19   *
20   * @author Sven Strittmatter <weltraumschaf@googlemail.com>
21   */
22  class DarcsBaseCommandBuilder {
23  
24      /**
25       * Name of Darcs executable.
26       *
27       * Examples: "darcs" or "/usr/local/bin/darcs"
28       */
29      private final String darcsExe;
30      /**
31       * Subcommand such as `pull`, `get` etc.
32       */
33      private final String command;
34  
35      /**
36       * Initializes {@link #command} with empty string.
37       *
38       * @param darcsExe name of Darcs executable, e.g. "darcs" or "/usr/local/bin/darcs"
39       */
40      DarcsBaseCommandBuilder(final String darcsExe) {
41          this(darcsExe, "");
42      }
43  
44      /**
45       * Dedicated constructor.
46       *
47       * @param darcsExe name of Darcs executable, e.g. "darcs" or "/usr/local/bin/darcs"
48       * @param command Darcs subcommand such as `pull`, `get` etc.
49       */
50      DarcsBaseCommandBuilder(final String darcsExe, final String command) {
51          super();
52          Validate.notEmpty(darcsExe, "Command must not be empty!");
53          Validate.notNull(command, "Command must not be null!");
54          this.darcsExe = darcsExe;
55          this.command = command;
56      }
57  
58      /**
59       * Get the Darcs executable.
60       *
61       * @return string of the executable
62       */
63      String getDarcsExe() {
64          return darcsExe;
65      }
66  
67      /**
68       * Generates base argument list with executable and subcommand.
69       *
70       * @return always new instance
71       */
72      ArgumentListBuilder createArgumentList() {
73          final ArgumentListBuilder arguments = new ArgumentListBuilder();
74          arguments.add(darcsExe);
75  
76          if (command.length() > 0) {
77              arguments.add(command);
78          }
79  
80          return arguments;
81      }
82  
83  }