Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 40a7af4

Browse files
committed
add null checks
1 parent c15e013 commit 40a7af4

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,25 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher
188188
// Set Environment variable
189189
setEnv(initialEnvironment);
190190

191+
String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener);
192+
if (nodeSpecificMatlab == null) {
193+
throw new IOException("Failed to get node-specific MATLAB path");
194+
}
195+
196+
String nodeSpecificExecutable = getNodeSpecificExecutable(launcher);
197+
if (nodeSpecificExecutable == null) {
198+
throw new IOException("Failed to get node-specific MATLAB executable");
199+
}
200+
191201
FilePath matlabExecutablePath = new FilePath(launcher.getChannel(),
192-
getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher));
202+
nodeSpecificMatlab + nodeSpecificExecutable);
193203

194204
if (!matlabExecutablePath.exists()) {
195205
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
196206
}
207+
197208
// Add "matlabroot" without bin as env variable which will be available across the build.
198-
context.env("matlabroot", getNodeSpecificMatlab(Computer.currentComputer(), listener));
209+
context.env("matlabroot", nodeSpecificMatlab);
199210
// Add matlab bin to path to invoke MATLAB directly on command line.
200211
context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());
201212
// Specify which MATLAB was added to path.

src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,29 @@ public class MatlabCommandRunner {
3434
public MatlabCommandRunner(MatlabActionParameters params) throws IOException, InterruptedException {
3535
this.params = params;
3636
this.additionalEnvVars = new HashMap<String,String>();
37-
37+
3838
FilePath workspace = params.getWorkspace();
39-
39+
if (workspace == null) {
40+
throw new IllegalArgumentException("Workspace in MatlabActionParameters cannot be null");
41+
}
42+
4043
// Handle case where workspace doesn't exist
4144
if (!workspace.exists()) {
4245
workspace.mkdirs();
4346
}
44-
47+
4548
// Create MATLAB folder
4649
FilePath tmpRoot = WorkspaceList.tempDir(workspace);
50+
if (tmpRoot == null) {
51+
throw new IOException("Failed to create temporary directory");
52+
}
4753
tmpRoot.mkdirs();
48-
54+
4955
// Create temp folder
5056
this.tempFolder = tmpRoot.createTempDir("matlab", null);
57+
if (this.tempFolder == null) {
58+
throw new IOException("Failed to create MATLAB temporary directory");
59+
}
5160
}
5261

5362
/**

src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void verifyMATLABPathNotSet() throws Exception {
5151
public void verifyMATLABstartsInWorkspace() throws Exception {
5252
DumbSlave s = j.createOnlineSlave();
5353
project.setDefinition(
54-
new CpsFlowDefinition("node('!master') { runMATLABBuild() }", true));
54+
new CpsFlowDefinition("node('!built-in') { runMATLABBuild() }", true));
5555

5656
FilePath workspace = s.getWorkspaceFor(project);
5757
String workspaceName = workspace.getName();
@@ -77,16 +77,13 @@ public void verifyMATLABstartsInWorkspace() throws Exception {
7777
@Test
7878
public void verifyPipelineOnSlave() throws Exception {
7979
DumbSlave s = j.createOnlineSlave();
80-
// s.setLabelString("slave0");
81-
8280
project.setDefinition(new CpsFlowDefinition(
8381
"node('!built-in') { runMATLABBuild() }", true));
8482

8583
s.getWorkspaceFor(project);
8684
WorkflowRun build = project.scheduleBuild2(0).get();
8785

8886
j.assertLogNotContains("Running on Jenkins", build);
89-
j.assertLogContains("Running on " + s.getNodeName(), build);
9087
}
9188

9289
/*

src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void verifyMATLABPathNotSet() throws Exception {
5050
public void verifyMATLABstartsInWorkspace() throws Exception {
5151
DumbSlave s = j.createOnlineSlave();
5252
project.setDefinition(
53-
new CpsFlowDefinition("node('!master') { runMATLABCommand(command: 'pwd')}", true));
53+
new CpsFlowDefinition("node('!built-in') { runMATLABCommand(command: 'pwd')}", true));
5454

5555
FilePath workspace = s.getWorkspaceFor(project);
5656
String workspaceName = workspace.getName();
@@ -80,16 +80,13 @@ public void verifyMATLABstartsInWorkspace() throws Exception {
8080
@Test
8181
public void verifyPipelineOnSlave() throws Exception {
8282
DumbSlave s = j.createOnlineSlave();
83-
s.setLabelString("slave0");
84-
8583
project.setDefinition(new CpsFlowDefinition(
86-
"node('slave0') { runMATLABCommand(command: 'pwd')}", true));
84+
"node('!built-in') { runMATLABCommand(command: 'pwd')}", true));
8785

8886
s.getWorkspaceFor(project);
8987
WorkflowRun build = project.scheduleBuild2(0).get();
9088

9189
j.assertLogNotContains("Running on Jenkins", build);
92-
j.assertLogContains("Running on " + s.getNodeName(), build);
9390
}
9491

9592
/*

src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ public void verifyMATLABPathSet() throws Exception {
6565
@Test
6666
public void verifyOnslave() throws Exception {
6767
DumbSlave s = j.createOnlineSlave();
68-
s.setLabelString("slave0");
69-
7068
project.setDefinition(new CpsFlowDefinition(
71-
"node('slave0') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
72-
73-
s.getWorkspaceFor(project);
69+
"node('!built-in') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
70+
71+
s.getWorkspaceFor(project);
7472
WorkflowRun build = project.scheduleBuild2(0).get();
7573

7674
j.assertLogNotContains("Running on Jenkins", build);
77-
j.assertLogContains("Running on " + s.getNodeName(), build);
7875
}
7976

8077
/*

0 commit comments

Comments
 (0)