|
1 | 1 | package org.jenkinsci.plugins.ibmisteps.steps; |
2 | 2 |
|
| 3 | +import com.ibm.as400.access.AS400Message; |
| 4 | +import edu.umd.cs.findbugs.annotations.NonNull; |
| 5 | +import hudson.AbortException; |
| 6 | +import hudson.Extension; |
3 | 7 | import org.jenkinsci.plugins.ibmisteps.Messages; |
4 | 8 | import org.jenkinsci.plugins.ibmisteps.model.CallResult; |
5 | 9 | import org.jenkinsci.plugins.ibmisteps.model.IBMi; |
|
10 | 14 | import org.kohsuke.stapler.DataBoundConstructor; |
11 | 15 | import org.kohsuke.stapler.DataBoundSetter; |
12 | 16 |
|
13 | | -import com.ibm.as400.access.AS400Message; |
14 | | - |
15 | | -import edu.umd.cs.findbugs.annotations.NonNull; |
16 | | -import hudson.AbortException; |
17 | | -import hudson.Extension; |
18 | | - |
19 | 17 | public class IBMiCommandStep extends IBMiStep<CallResult> { |
20 | | - private static final long serialVersionUID = 6443392002952411163L; |
| 18 | + private static final long serialVersionUID = 6443392002952411163L; |
21 | 19 |
|
22 | | - private final String command; |
23 | | - private boolean failOnError; |
| 20 | + private final String command; |
| 21 | + private boolean failOnError; |
24 | 22 |
|
25 | | - @DataBoundConstructor |
26 | | - public IBMiCommandStep(final String command) { |
27 | | - this.command = command; |
28 | | - } |
| 23 | + @DataBoundConstructor |
| 24 | + public IBMiCommandStep(final String command) { |
| 25 | + this.command = command; |
| 26 | + } |
29 | 27 |
|
30 | | - public String getCommand() { |
31 | | - return command; |
32 | | - } |
| 28 | + public String getCommand() { |
| 29 | + return command; |
| 30 | + } |
33 | 31 |
|
34 | | - public boolean isFailOnError() { |
35 | | - return failOnError; |
36 | | - } |
| 32 | + public boolean isFailOnError() { |
| 33 | + return failOnError; |
| 34 | + } |
37 | 35 |
|
38 | | - @DataBoundSetter |
39 | | - public void setFailOnError(final boolean failOnError) { |
40 | | - this.failOnError = failOnError; |
41 | | - } |
| 36 | + @DataBoundSetter |
| 37 | + public void setFailOnError(final boolean failOnError) { |
| 38 | + this.failOnError = failOnError; |
| 39 | + } |
42 | 40 |
|
43 | | - @Extension |
44 | | - public static class DescriptorImpl extends IBMiStepDescriptor { |
45 | | - @Override |
46 | | - public String getFunctionName() { |
47 | | - return "ibmiCommand"; |
48 | | - } |
| 41 | + @Extension |
| 42 | + public static class DescriptorImpl extends IBMiStepDescriptor { |
| 43 | + @Override |
| 44 | + public String getFunctionName() { |
| 45 | + return "ibmiCommand"; |
| 46 | + } |
49 | 47 |
|
50 | | - @NonNull |
51 | | - @Override |
52 | | - public String getDisplayName() { |
53 | | - return Messages.IBMICommandStep_description(); |
54 | | - } |
55 | | - } |
| 48 | + @NonNull |
| 49 | + @Override |
| 50 | + public String getDisplayName() { |
| 51 | + return Messages.IBMICommandStep_description(); |
| 52 | + } |
| 53 | + } |
56 | 54 |
|
57 | | - @Override |
58 | | - protected CallResult runOnIBMi(final StepContext context, final LoggerWrapper logger, final IBMi ibmi) |
59 | | - throws Exception { |
60 | | - logger.log(Messages.IBMICommandStep_running(command)); |
| 55 | + @Override |
| 56 | + protected CallResult runOnIBMi(final StepContext context, final LoggerWrapper logger, final IBMi ibmi) |
| 57 | + throws Exception { |
| 58 | + logger.log(Messages.IBMICommandStep_running(command)); |
61 | 59 |
|
62 | | - final CallResult result = ibmi.executeCommand(command); |
63 | | - final AS400Message lastMessage = result.getMessages().get(result.getMessages().size() - 1); |
64 | | - if (result.isSuccessful()) { |
65 | | - logger.log(Messages.IBMICommandStep_succeeded(command)); |
66 | | - } else if (!failOnError) { |
67 | | - logger.log(Messages.IBMICommandStep_failed(command, lastMessage.getID(), lastMessage.getText())); |
68 | | - logger.trace(result.getPrettyMessages()); |
69 | | - } else { |
70 | | - logger.log(result.getPrettyMessages()); |
71 | | - throw new AbortException( |
72 | | - Messages.IBMICommandStep_failed(command, lastMessage.getID(), lastMessage.getText())); |
| 60 | + final CallResult result = ibmi.executeCommand(command); |
| 61 | + final AS400Message lastMessage = result.getLastMessage(); |
| 62 | + if (result.isSuccessful()) { |
| 63 | + logger.log(Messages.IBMICommandStep_succeeded(command)); |
| 64 | + } else { |
| 65 | + final String error; |
| 66 | + if (lastMessage != null) { |
| 67 | + error = Messages.IBMICommandStep_failed_with_message(command, lastMessage.getID(), lastMessage.getText()); |
| 68 | + } else { |
| 69 | + error = Messages.IBMICommandStep_failed(command); |
| 70 | + } |
| 71 | + if (!failOnError) { |
| 72 | + logger.log(error); |
| 73 | + logger.trace(result.getPrettyMessages()); |
| 74 | + } else { |
| 75 | + logger.log(result.getPrettyMessages()); |
| 76 | + throw new AbortException(error); |
| 77 | + } |
73 | 78 | } |
74 | 79 |
|
75 | | - return result; |
76 | | - } |
| 80 | + return result; |
| 81 | + } |
77 | 82 | } |
0 commit comments