Skip to content

Commit ac49e1c

Browse files
authored
Merge pull request #6 from jenkinsci/bumpJT400
Bump jt400 + fix NPE in ibmiCommand
2 parents c6bb567 + 354ed39 commit ac49e1c

File tree

5 files changed

+67
-53
lines changed

5 files changed

+67
-53
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ spooledFiles.each { splf -> print "${splf.name} (${splf.number})" }
305305
|:-------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
306306
| getMessages() | [`List`](https://docs.oracle.com/javase/8/docs/api/java/util/List.html)<[AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html)> | Returns the list of [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) generated during the command execution. |
307307
| getMessage(`String` messageId) | [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) | Look for the first [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) whose ID is `messageId` and returns it. Returns `null` if not found. |
308+
| getLastMessage() | [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) | Returns the last [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) generated by the command or `null` if there is no message. |
308309
| getPrettyMessages() | `String` | Returns a `String` resulting from the concatenation of every [AS400Message](https://javadoc.io/doc/net.sf.jt400/jt400/latest/com/ibm/as400/access/AS400Message.html) returned by the command, one per line, formatted using this pattern: `[{id}][{severity}] {text}`. |
309310
| isSuccessful() | `boolean` | Returns `true ` if the command execution was successful, `false` otherwise. |
310311

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<dependency>
7575
<groupId>net.sf.jt400</groupId>
7676
<artifactId>jt400</artifactId>
77+
<classifier>java11</classifier>
7778
<version>21.0.0</version>
7879
</dependency>
7980
<dependency>

src/main/java/org/jenkinsci/plugins/ibmisteps/model/CallResult.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jenkinsci.plugins.ibmisteps.model;
22

33
import com.ibm.as400.access.AS400Message;
4+
import edu.umd.cs.findbugs.annotations.CheckForNull;
45

56
import java.io.Serializable;
67
import java.text.MessageFormat;
@@ -31,6 +32,11 @@ public List<AS400Message> getMessages() {
3132
return messages;
3233
}
3334

35+
@CheckForNull
36+
public AS400Message getLastMessage() {
37+
return messages.isEmpty() ? null : messages.get(messages.size()-1);
38+
}
39+
3440
public String getPrettyMessages() {
3541
return messages.stream()
3642
.map(m -> MessageFormat.format("[{0}][{1}] {2}", m.getID(), m.getSeverity(), m.getText()))
Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.jenkinsci.plugins.ibmisteps.steps;
22

3+
import com.ibm.as400.access.AS400Message;
4+
import edu.umd.cs.findbugs.annotations.NonNull;
5+
import hudson.AbortException;
6+
import hudson.Extension;
37
import org.jenkinsci.plugins.ibmisteps.Messages;
48
import org.jenkinsci.plugins.ibmisteps.model.CallResult;
59
import org.jenkinsci.plugins.ibmisteps.model.IBMi;
@@ -10,68 +14,69 @@
1014
import org.kohsuke.stapler.DataBoundConstructor;
1115
import org.kohsuke.stapler.DataBoundSetter;
1216

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-
1917
public class IBMiCommandStep extends IBMiStep<CallResult> {
20-
private static final long serialVersionUID = 6443392002952411163L;
18+
private static final long serialVersionUID = 6443392002952411163L;
2119

22-
private final String command;
23-
private boolean failOnError;
20+
private final String command;
21+
private boolean failOnError;
2422

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+
}
2927

30-
public String getCommand() {
31-
return command;
32-
}
28+
public String getCommand() {
29+
return command;
30+
}
3331

34-
public boolean isFailOnError() {
35-
return failOnError;
36-
}
32+
public boolean isFailOnError() {
33+
return failOnError;
34+
}
3735

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+
}
4240

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+
}
4947

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+
}
5654

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));
6159

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+
}
7378
}
7479

75-
return result;
76-
}
80+
return result;
81+
}
7782
}

src/main/resources/org/jenkinsci/plugins/ibmisteps/Messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ IBMi.change.iasp.failed=Failed to change current iASP to {0}
2424
IBMICommandStep.description=Run an IBM i command
2525
IBMICommandStep.running=Running IBM i command {0}
2626
IBMICommandStep.succeeded=IBM i command {0} succeeded
27-
IBMICommandStep.failed=IBM i command {0} failed: [{1}] {2}
27+
IBMICommandStep.failed=IBM i command {0} failed
28+
IBMICommandStep.failed.with.message=IBM i command {0} failed: [{1}] {2}
2829

2930
IBMiRunSQLStep.running=Running SQL query {0}
3031
IBMiRunSQLStep.rows=Query returned {0} row(s)

0 commit comments

Comments
 (0)