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

Commit 19ea2e7

Browse files
author
Nikhil Bhoski
committed
Added support to verify valid MATLAB path.
1 parent a74c602 commit 19ea2e7

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mathworks.ci;
2+
3+
import java.io.FileNotFoundException;
4+
5+
public class MatlabNotFoundError extends Error {
6+
7+
/**
8+
*
9+
*/
10+
private static final long serialVersionUID = 7918595075502022644L;
11+
12+
MatlabNotFoundError(String errorMessage){
13+
super(errorMessage);
14+
}
15+
16+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ public class MatlabVersionNotFoundException extends Exception {
1010
MatlabVersionNotFoundException(String errorMessage, Throwable err) {
1111
super(errorMessage, err);
1212
}
13+
MatlabVersionNotFoundException(String errorMessage) {
14+
super(errorMessage);
15+
}
1316
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import java.io.File;
12+
import java.io.FileNotFoundException;
1213
import java.io.IOException;
1314
import java.util.ArrayList;
1415
import java.util.List;
@@ -133,18 +134,24 @@ public synchronized void setUp(Context context, Run<?, ?> build, FilePath worksp
133134
// Set Environment variable
134135

135136
setEnv(initialEnvironment);
136-
String nodeSpecificFileSep = getNodeSpecificFileSeperator(launcher);
137+
138+
FilePath matlabExecutablePath = new FilePath(launcher.getChannel(),
139+
getLocalMatlab() + "/bin/" + getNodeSpecificExecutable(launcher));
140+
141+
if (!matlabExecutablePath.exists()) {
142+
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
143+
}
137144
// Add "matlabroot" without bin as env variable which will be available across the build.
138145
context.env("matlabroot", getLocalMatlab());
139146
// Add matlab bin to path to invoke MATLAB directly on command line.
140-
context.env("PATH+matlabroot", getLocalMatlab() + nodeSpecificFileSep + "bin");
147+
context.env("PATH+matlabroot", getLocalMatlab() + "/bin");
141148
}
142-
143-
private String getNodeSpecificFileSeperator(Launcher launcher) {
149+
150+
private String getNodeSpecificExecutable(Launcher launcher) {
144151
if (launcher.isUnix()) {
145-
return "/";
152+
return "matlab";
146153
} else {
147-
return "\\";
154+
return "matlab.exe";
148155
}
149156
}
150157
}

src/main/resources/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Builder.matlab.test.support.error = To run tests with the Jenkins plugin, use MA
1212
builder.matlab.automatictestoption.display.name = Automatic
1313
builder.matlab.customcommandoption.display.name = Custom
1414
Releaseinfo.matlab.version.not.found.error = Error finding MATLAB release for given MATLAB root. Verify MATLAB root path.
15+
matlab.not.found.error = Error finding MATLAB at given location. Verify MATLAB root path.
1516
Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model coverage report, use MATLAB R2018b or a newer release.
1617
Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release.
1718
Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh

src/test/java/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jvnet.hudson.test.JenkinsRule;
2222
import com.gargoylesoftware.htmlunit.WebAssert;
2323
import com.gargoylesoftware.htmlunit.html.HtmlPage;
24+
import hudson.model.FreeStyleBuild;
2425
import hudson.model.FreeStyleProject;
2526
import hudson.tasks.BuildWrapper;
2627

@@ -90,17 +91,32 @@ public void verifyBuildEnvForMatlab() throws Exception {
9091

9192
/*
9293
* Verify if given MATLAB root is added in the PATH.
94+
* Should be added to integration test.
9395
*/
94-
@Test
96+
9597
public void verifyPATHupdated() throws Exception {
9698
this.buildWrapper.setMatlabRootFolder("/test/MATLAB/R2019a");
9799
project.getBuildWrappersList().add(this.buildWrapper);
98100
RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("","");
99101
project.getBuildersList().add(buildTester);
100-
project.scheduleBuild2(0).get();
102+
FreeStyleBuild build = project.scheduleBuild2(0).get();
101103
Assert.assertTrue("Build does not have MATLAB build environment", this.buildWrapper.getMatlabRootFolder().equalsIgnoreCase(buildTester.getMatlabRoot()));
102104
}
103105

106+
/*
107+
* Verify if invalid MATLAB path throes error on console.
108+
*/
109+
@Test
110+
public void verifyInvalidPATHError() throws Exception {
111+
this.buildWrapper.setMatlabRootFolder("/test/MATLAB/R2019a");
112+
project.getBuildWrappersList().add(this.buildWrapper);
113+
RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("","");
114+
project.getBuildersList().add(buildTester);
115+
project.scheduleBuild2(0).get();
116+
FreeStyleBuild build = project.scheduleBuild2(0).get();
117+
jenkins.assertLogContains("MatlabNotFoundError", build);
118+
}
119+
104120
/*
105121
* Test To verify if UI throws an error when MATLAB root is empty.
106122
*

0 commit comments

Comments
 (0)