View Javadoc

1   package org.rundeck.api;
2   
3   import java.io.InputStream;
4   import java.util.Properties;
5   
6   /**
7    * A builder to build a {@link RunAdhocScript}, use the {@link #builder()} to build a builder, then {@link #build()}
8    * to build an RunAdhocScript
9    */
10  public class RunAdhocScriptBuilder {
11      private DefaultRunAdhocScript script;
12  
13      private RunAdhocScriptBuilder() {
14          script = new DefaultRunAdhocScript();
15      }
16  
17      public RunAdhocScriptBuilder(final RunAdhocScript oldScript) {
18          script = new DefaultRunAdhocScript();
19          setAsUser(oldScript.getAsUser());
20          setArgString(oldScript.getArgString());
21          setProject(oldScript.getProject());
22          setScript(oldScript.getScript());
23          setNodeFilters(oldScript.getNodeFilters());
24          setNodeKeepgoing(oldScript.getNodeKeepgoing());
25          setNodeThreadcount(oldScript.getNodeThreadcount());
26          setScriptInterpreter(oldScript.getScriptInterpreter());
27          setInterpreterArgsQuoted(oldScript.getInterpreterArgsQuoted());
28      }
29  
30      /**
31       * Create a new builder
32       *
33       * @return
34       */
35      public static RunAdhocScriptBuilder builder() {
36          return new RunAdhocScriptBuilder();
37      }
38  
39      /**
40       * Create a builder initialized with an existing {@link RunAdhocScript}
41       *
42       * @param script
43       *
44       * @return this builder
45       */
46      public static RunAdhocScriptBuilder builder(final RunAdhocScript script) {
47          return new RunAdhocScriptBuilder(script);
48      }
49  
50      public RunAdhocScriptBuilder setProject(final String project) {
51          script.setProject(project);
52          return this;
53      }
54  
55      public RunAdhocScriptBuilder setScript(final InputStream stream) {
56          script.setScript(stream);
57          return this;
58      }
59  
60      public RunAdhocScriptBuilder setArgString(final String argString) {
61          script.setArgString(argString);
62          return this;
63      }
64  
65      public RunAdhocScriptBuilder setNodeFilters(final Properties nodeFilters) {
66          script.setNodeFilters(nodeFilters);
67          return this;
68      }
69  
70      public RunAdhocScriptBuilder setNodeThreadcount(final Integer nodeThreadcount) {
71          script.setNodeThreadcount(nodeThreadcount);
72          return this;
73      }
74  
75      public RunAdhocScriptBuilder setNodeKeepgoing(final Boolean nodeKeepgoing) {
76          script.setNodeKeepgoing(nodeKeepgoing);
77          return this;
78      }
79  
80      public RunAdhocScriptBuilder setAsUser(final String asUser) {
81          script.setAsUser(asUser);
82          return this;
83      }
84  
85      public RunAdhocScriptBuilder setScriptInterpreter(final String scriptInterpreter) {
86          script.setScriptInterpreter(scriptInterpreter);
87          return this;
88      }
89  
90      public RunAdhocScriptBuilder setInterpreterArgsQuoted(final Boolean interpreterArgsQuoted) {
91          script.setInterpreterArgsQuoted(interpreterArgsQuoted);
92          return this;
93      }
94  
95      public RunAdhocScript build() {
96          final DefaultRunAdhocScript built = script;
97          script = new DefaultRunAdhocScript();
98          return built;
99      }
100 }