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

Commit 02d33cf

Browse files
authored
Merge pull request #77 from mathworks/matrix-issue-patch
fixed findbug issue and Scratch file copy issue.
2 parents 822eaca + f7adb27 commit 02d33cf

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,25 @@ default void copyFileInWorkspace(String sourceFile, String targetFile, FilePath
7070
targetFilePath.chmod(0755);
7171
}
7272

73-
default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName,FilePath workspace)
73+
default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName, FilePath workspace)
7474
throws IOException, InterruptedException {
7575
/*Use of Computer is not recommended as jenkins hygeine for pipeline support
7676
* https://javadoc.jenkins-ci.org/jenkins/tasks/SimpleBuildStep.html */
7777

78-
Computer cmp = workspace.toComputer();
79-
String tmpDir = (String) cmp.getSystemProperties().get("java.io.tmpdir");
80-
if (launcher.isUnix()) {
81-
tmpDir = tmpDir + "/" + uniqueName;
82-
} else {
83-
tmpDir = tmpDir + "\\" + uniqueName;
84-
}
85-
return new FilePath(launcher.getChannel(), tmpDir);
78+
String tmpDir = getNodeSpecificTmpFolderPath(workspace);
79+
return new FilePath(launcher.getChannel(), tmpDir+"/"+uniqueName);
8680
}
8781

8882
default String getNodeSpecificTmpFolderPath(FilePath workspace) throws IOException, InterruptedException {
8983
Computer cmp = workspace.toComputer();
84+
if (cmp == null) {
85+
throw new IOException(Message.getValue("build.workspace.computer.not.found"));
86+
}
9087
String tmpDir = (String) cmp.getSystemProperties().get("java.io.tmpdir");
9188
return tmpDir;
9289
}
9390

9491
default String getUniqueNameForRunnerFile() {
9592
return UUID.randomUUID().toString();
9693
}
97-
9894
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class MatlabBuilderConstants {
1212
static final double BASE_MATLAB_VERSION_EXPORTSTMRESULTS_SUPPORT = 9.6;
1313

1414
static final String MATLAB_RUNNER_TARGET_FILE = "Builder.matlab.runner.target.file.name";
15+
static final String MATLAB_TESTS_RUNNER_TARGET_FILE = "runMatlabTests.m";
1516
static final String MATLAB_RUNNER_RESOURCE = "com/mathworks/ci/MatlabBuilder/runMatlabTests.m";
1617
static final String AUTOMATIC_OPTION = "RunTestsAutomaticallyOption";
1718

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
292292
// Copy MATLAB scratch file into the workspace.
293293
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
294294
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_RUNNER_RESOURCE,
295-
MatlabBuilderConstants.MATLAB_RUNNER_TARGET_FILE, targetWorkspace);
295+
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
296296
return matlabLauncher.join();
297297
} catch (Exception e) {
298298
listener.getLogger().println(e.getMessage());
@@ -308,8 +308,8 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
308308
}
309309

310310
public String constructCommandForTest(String inputArguments) {
311-
final String matlabFunctionName = FilenameUtils.removeExtension(
312-
Message.getValue(MatlabBuilderConstants.MATLAB_RUNNER_TARGET_FILE));
311+
final String matlabFunctionName =
312+
FilenameUtils.removeExtension(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE);
313313
final String runCommand = "exit(" + matlabFunctionName + "(" + inputArguments + "))";
314314
return runCommand;
315315
}

src/main/resources/config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model cov
1616
Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release.
1717
Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh
1818
Builder.matlab.runner.script.target.file.windows.name = run_matlab_command.bat
19-
19+
build.workspace.computer.not.found = Unable to access the computer for this build.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.gargoylesoftware.htmlunit.WebAssert;
2727
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
2828
import com.gargoylesoftware.htmlunit.html.HtmlPage;
29+
import com.mathworks.ci.MatlabBuilder.RunTestsAutomaticallyOption;
2930
import hudson.FilePath;
3031
import hudson.matrix.Axis;
3132
import hudson.matrix.AxisList;
@@ -307,6 +308,20 @@ public void verifyMatrixBuildPasses() throws Exception {
307308
jenkins.assertLogContains("R2018b completed", build);
308309
jenkins.assertBuildStatus(Result.SUCCESS, build);
309310
}
311+
312+
/*
313+
* Test to verify if MATALB scratch file is generated in workspace.
314+
*/
315+
@Test
316+
public void verifyMATLABscratchFileGenerated() throws Exception {
317+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
318+
project.getBuildWrappersList().add(this.buildWrapper);
319+
setAllTestArtifacts(false, testBuilder);
320+
project.getBuildersList().add(testBuilder);
321+
FreeStyleBuild build = project.scheduleBuild2(0).get();
322+
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
323+
Assert.assertTrue(matlabRunner.exists());
324+
}
310325

311326

312327
/*

0 commit comments

Comments
 (0)