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

Commit c1d84de

Browse files
committed
fixed findbug issue and Scratch file copy issue.
1 parent 822eaca commit c1d84de

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.io.IOException;
1010
import java.io.InputStream;
1111
import java.util.UUID;
12+
import javax.annotation.Nonnull;
13+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1214
import hudson.EnvVars;
1315
import hudson.FilePath;
1416
import hudson.Launcher;
@@ -70,7 +72,9 @@ default void copyFileInWorkspace(String sourceFile, String targetFile, FilePath
7072
targetFilePath.chmod(0755);
7173
}
7274

73-
default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName,FilePath workspace)
75+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
76+
justification = "workspace is passed through perform method, which will always have NonNull FilePath")
77+
default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName, FilePath workspace)
7478
throws IOException, InterruptedException {
7579
/*Use of Computer is not recommended as jenkins hygeine for pipeline support
7680
* https://javadoc.jenkins-ci.org/jenkins/tasks/SimpleBuildStep.html */
@@ -85,6 +89,8 @@ default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName
8589
return new FilePath(launcher.getChannel(), tmpDir);
8690
}
8791

92+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
93+
justification = "workspace is passed through perform method, which will always have NonNull FilePath")
8894
default String getNodeSpecificTmpFolderPath(FilePath workspace) throws IOException, InterruptedException {
8995
Computer cmp = workspace.toComputer();
9096
String tmpDir = (String) cmp.getSystemProperties().get("java.io.tmpdir");

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/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)