From 3d944a7d285f8a4b4d8338f15933c0c1ee109279 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:16:37 +0530 Subject: [PATCH 01/51] Added check for command textbox --- .../ci/freestyle/RunMatlabCommandBuilder.java | 12 +++++++ .../RunMatlabCommandBuilder/config.jelly | 2 +- src/main/resources/config.properties | 1 + .../ci/RunMatlabCommandBuilderTest.java | 33 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java index 758bdf22..33fa0cd1 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java @@ -7,10 +7,13 @@ * */ +import hudson.util.FormValidation; import java.io.IOException; import javax.annotation.Nonnull; +import jenkins.model.Jenkins; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; +import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; import hudson.EnvVars; import hudson.Extension; @@ -33,6 +36,7 @@ import com.mathworks.ci.actions.MatlabActionFactory; import com.mathworks.ci.actions.RunMatlabCommandAction; import com.mathworks.ci.freestyle.options.StartupOptions; +import org.kohsuke.stapler.verb.POST; public class RunMatlabCommandBuilder extends Builder implements SimpleBuildStep { // Deprecated @@ -110,6 +114,14 @@ public boolean isApplicable( @SuppressWarnings("rawtypes") Class jobtype) { return true; } + @POST + public FormValidation doCheckMatlabCommand(@QueryParameter String matlabCommand) { + Jenkins.get().checkPermission(Jenkins.ADMINISTER); + if (matlabCommand.isEmpty()) { + return FormValidation.error(Message.getValue("matlab.empty.command.error")); + } + return FormValidation.ok(); + } } @Override diff --git a/src/main/resources/com/mathworks/ci/freestyle/RunMatlabCommandBuilder/config.jelly b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabCommandBuilder/config.jelly index 58ae5316..132f8298 100644 --- a/src/main/resources/com/mathworks/ci/freestyle/RunMatlabCommandBuilder/config.jelly +++ b/src/main/resources/com/mathworks/ci/freestyle/RunMatlabCommandBuilder/config.jelly @@ -2,7 +2,7 @@ - + diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index f2f8f32c..e64fa092 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -16,6 +16,7 @@ Releaseinfo.matlab.version.not.found.error = Error finding MATLAB release for gi matlab.not.found.error = Unable to launch MATLAB from the specified location. Verify the path to MATLAB root folder. matlab.not.found.error.for.node = Unable to launch MATLAB '%s' on the node '%s'. Verify global tool configuration for the specified node. matlab.execution.exception.prefix = Received a nonzero exit code %d while trying to run MATLAB. +matlab.empty.command.error = Specify at least one script, function, or statement to execute. Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model coverage report, use MATLAB R2018b or a newer release. Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release. Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java index 75c6e8f1..cf28cbed 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java @@ -7,6 +7,9 @@ * */ +import com.gargoylesoftware.htmlunit.WebAssert; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; +import com.gargoylesoftware.htmlunit.html.HtmlPage; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -377,4 +380,34 @@ public void verifyMultispecialChar() throws Exception { jenkins.assertLogContains("Generating MATLAB script with content", build); jenkins.assertLogContains(expectedCommand, build); } + + /* + * Test to verify error message when command is empty. + */ + + @Test + public void verifyErrorMessageOnEmptyCommand() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.scriptBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + + WebAssert.assertTextPresent(page,"Specify at least one script, function, or statement to execute."); + } + + /* + * Test to verify no error message when command is provided. + */ + + @Test + public void verifyWhenCommandNonEmpty() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + project.getBuildWrappersList().add(this.buildWrapper); + this.scriptBuilder.setMatlabCommand("NONEMPTY"); + project.getBuildersList().add(this.scriptBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + + WebAssert.assertTextNotPresent(page,"Specify at least one script, function, or statement to execute."); + } + } From ed8070a83f035146914289817a49ba45968b3034 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:32:40 +0530 Subject: [PATCH 02/51] Updated as per review comment --- .../java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java index 33fa0cd1..97042e60 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java @@ -114,6 +114,7 @@ public boolean isApplicable( @SuppressWarnings("rawtypes") Class jobtype) { return true; } + @POST public FormValidation doCheckMatlabCommand(@QueryParameter String matlabCommand) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); From b88d782ec3437bda227fe7b905f18292b596f2ab Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:22:57 +0530 Subject: [PATCH 03/51] Updated as per review comment --- .../com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java index 97042e60..54b458df 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java @@ -116,9 +116,9 @@ public boolean isApplicable( } @POST - public FormValidation doCheckMatlabCommand(@QueryParameter String matlabCommand) { + public FormValidation doCheckMatlabCommand(@QueryParameter String value) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); - if (matlabCommand.isEmpty()) { + if (value.isEmpty()) { return FormValidation.error(Message.getValue("matlab.empty.command.error")); } return FormValidation.ok(); From 090ee01d3456c8384e7851eca0865a0e6945bdfd Mon Sep 17 00:00:00 2001 From: Kapil Gupta <111856426+mw-kapilg@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:01:42 +0530 Subject: [PATCH 04/51] Add build results support in Run Command step and skipped task logs link in table (#354) * add build table to command step and link to skipped logs * add skipped log link in status as well * fix pipeline failure * temp commit for checkout * update as per review comments * remove MatlabBuild.java and update tests * temp commit for checkout * update as per review * fix pipeline failure * format code * remove teardown method overriding * add super to method calls --- .gitignore | 2 + .../com/mathworks/ci/BuildArtifactAction.java | 16 +- .../com/mathworks/ci/BuildArtifactData.java | 6 +- .../mathworks/ci/BuildConsoleAnnotator.java | 5 + .../com/mathworks/ci/BuildTargetNote.java | 5 + .../com/mathworks/ci/FormValidationUtil.java | 1 + .../mathworks/ci/ListenerLogDecorator.java | 1 + .../java/com/mathworks/ci/MatlabBuild.java | 143 ------------------ .../mathworks/ci/MatlabBuilderConstants.java | 7 + .../ci/MatlabExecutionException.java | 5 + .../com/mathworks/ci/MatlabNotFoundError.java | 2 - .../com/mathworks/ci/MatlabReleaseInfo.java | 4 +- .../mathworks/ci/MatrixPatternResolver.java | 1 + src/main/java/com/mathworks/ci/Message.java | 1 - .../ci/UseMatlabVersionBuildWrapper.java | 2 - src/main/java/com/mathworks/ci/Utilities.java | 3 - .../mathworks/ci/actions/MatlabAction.java | 88 +++++++++++ .../ci/actions/MatlabActionFactory.java | 2 +- .../ci/actions/RunMatlabBuildAction.java | 72 +-------- .../ci/actions/RunMatlabCommandAction.java | 46 ++++-- .../ci/actions/RunMatlabTestsAction.java | 15 +- .../ci/freestyle/RunMatlabCommandBuilder.java | 4 +- .../ci/freestyle/options/SelectByFolder.java | 6 +- .../ci/freestyle/options/SourceFolder.java | 1 - .../ci/freestyle/options/TestFolders.java | 5 + .../ci/parameters/BuildActionParameters.java | 10 +- ...ters.java => CommandActionParameters.java} | 16 +- .../ci/parameters/MatlabActionParameters.java | 11 +- .../ci/parameters/TestActionParameters.java | 10 +- .../pipeline/MatlabCommandStepExecution.java | 4 +- .../ci/pipeline/RunMatlabTestsStep.java | 5 +- .../ci/utilities/MatlabCommandRunner.java | 1 - .../+jenkins/TaskRunProgressPlugin.m | 5 + .../ci/BuildArtifactAction/index.jelly | 7 +- .../ci/BuildArtifactAction/summary.jelly | 17 ++- .../mathworks/ci/BuildArtifactActionTest.java | 14 +- .../mathworks/ci/MatlabInstallationTest.java | 5 + .../ci/RunMatlabCommandStepTest.java | 1 - .../RunMatlabTestBuilderPersistenceTest.java | 2 + .../ci/RunMatlabTestsBuilderTest.java | 2 - .../integ/com/mathworks/ci/TestMessage.java | 4 +- .../ci/UseMatlabVersionBuildWrapperTest.java | 2 +- .../ci/actions/MatlabActionTest.java | 126 +++++++++++++++ .../ci/actions/RunMatlabBuildActionTest.java | 72 +-------- .../actions/RunMatlabCommandActionTest.java | 42 +++-- .../ci/actions/RunMatlabTestsActionTest.java | 7 - .../RunMatlabCommandBuilderUnitTest.java | 12 +- .../RunMatlabTestsBuilderUnitTest.java | 2 - .../MatlabCommandStepExecutionUnitTest.java | 12 +- .../t2}/buildArtifact.json | 0 50 files changed, 423 insertions(+), 409 deletions(-) delete mode 100644 src/main/java/com/mathworks/ci/MatlabBuild.java create mode 100644 src/main/java/com/mathworks/ci/actions/MatlabAction.java rename src/main/java/com/mathworks/ci/parameters/{RunActionParameters.java => CommandActionParameters.java} (61%) create mode 100644 src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java rename src/test/resources/{buildArtifacts.t2 => buildArtifacts/t2}/buildArtifact.json (100%) diff --git a/.gitignore b/.gitignore index 22535b44..61d648e0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ src/main/resources/matlab-script-generator.zip src/main/resources/**/run-matlab-command* src/main/resources/license.txt +.idea/ + **/.DS_Store \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/BuildArtifactAction.java b/src/main/java/com/mathworks/ci/BuildArtifactAction.java index e5151fc4..2e2fd92c 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactAction.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactAction.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import hudson.FilePath; import hudson.model.Action; import hudson.model.Run; @@ -18,7 +23,6 @@ import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; - public class BuildArtifactAction implements Action { private Run build; private int totalCount; @@ -26,7 +30,6 @@ public class BuildArtifactAction implements Action { private int failCount; private String actionID; private static final String ROOT_ELEMENT = "taskDetails"; - private static final String BUILD_ARTIFACT_FILE = "buildArtifact"; public BuildArtifactAction(Run build, String actionID) { this.build = build; @@ -69,10 +72,10 @@ public List getBuildArtifact() throws ParseException, Interru FilePath fl; if(this.actionID == null){ fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + - BUILD_ARTIFACT_FILE + ".json")); + MatlabBuilderConstants.BUILD_ARTIFACT + ".json")); } else { fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + - BUILD_ARTIFACT_FILE + this.actionID + ".json")); + MatlabBuilderConstants.BUILD_ARTIFACT + this.actionID + ".json")); } try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { Object obj = new JSONParser().parse(reader); @@ -141,16 +144,15 @@ public void setOwner(Run owner) { this.build = owner; } - private void setCounts() throws InterruptedException, ParseException { List artifactData = new ArrayList(); FilePath fl; if(this.actionID == null){ fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + - BUILD_ARTIFACT_FILE + ".json")); + MatlabBuilderConstants.BUILD_ARTIFACT + ".json")); } else { fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + - BUILD_ARTIFACT_FILE + this.actionID + ".json")); + MatlabBuilderConstants.BUILD_ARTIFACT + this.actionID + ".json")); } try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) { Object obj = new JSONParser().parse(reader); diff --git a/src/main/java/com/mathworks/ci/BuildArtifactData.java b/src/main/java/com/mathworks/ci/BuildArtifactData.java index d89a5ef9..4b2444ed 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactData.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactData.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + public class BuildArtifactData { private String taskName; @@ -12,7 +17,6 @@ public class BuildArtifactData { public BuildArtifactData() { } - public String getTaskDuration() { return this.taskDuration; } diff --git a/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java b/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java index 21f4abd7..8197b6d8 100644 --- a/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java +++ b/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import com.google.common.base.Charsets; import hudson.console.ConsoleLogFilter; import hudson.console.LineTransformationOutputStream; diff --git a/src/main/java/com/mathworks/ci/BuildTargetNote.java b/src/main/java/com/mathworks/ci/BuildTargetNote.java index 51ec6137..b047105c 100644 --- a/src/main/java/com/mathworks/ci/BuildTargetNote.java +++ b/src/main/java/com/mathworks/ci/BuildTargetNote.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import com.google.common.annotations.VisibleForTesting; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; diff --git a/src/main/java/com/mathworks/ci/FormValidationUtil.java b/src/main/java/com/mathworks/ci/FormValidationUtil.java index 1a29a8a4..8ccba320 100644 --- a/src/main/java/com/mathworks/ci/FormValidationUtil.java +++ b/src/main/java/com/mathworks/ci/FormValidationUtil.java @@ -6,6 +6,7 @@ * This is Utility class which provides commonly used methods for form validations across builders * */ + import java.util.List; import java.util.function.Function; import hudson.util.FormValidation; diff --git a/src/main/java/com/mathworks/ci/ListenerLogDecorator.java b/src/main/java/com/mathworks/ci/ListenerLogDecorator.java index e76f702b..454f843e 100644 --- a/src/main/java/com/mathworks/ci/ListenerLogDecorator.java +++ b/src/main/java/com/mathworks/ci/ListenerLogDecorator.java @@ -1,4 +1,5 @@ package com.mathworks.ci; + /* * Copyright 2018 The MathWorks, Inc. */ diff --git a/src/main/java/com/mathworks/ci/MatlabBuild.java b/src/main/java/com/mathworks/ci/MatlabBuild.java deleted file mode 100644 index 0a21596c..00000000 --- a/src/main/java/com/mathworks/ci/MatlabBuild.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.mathworks.ci; -/** - * Copyright 2019-2023 The MathWorks, Inc. - * - * Build Interface has two default methods. MATLAB builders can override the default behavior. - * - */ - -import java.io.IOException; -import java.io.InputStream; -import java.io.ByteArrayOutputStream; -import org.apache.commons.lang.RandomStringUtils; -import hudson.EnvVars; -import hudson.FilePath; -import hudson.Launcher; -import hudson.Launcher.ProcStarter; -import hudson.util.ArgumentListBuilder; -import hudson.model.TaskListener; - -public interface MatlabBuild { - - /** - * This Method decorates the launcher with MATLAB command provided and returns the Process - * object to launch MATLAB with appropriate startup options like -r or -batch - * - * @param workspace Current build workspace - * @param launcher Current build launcher - * @param listener Current build listener - * @param envVars Environment variables of the current build - * @param matlabCommand MATLAB command to execute on shell - * @return matlabLauncher returns the process launcher to run MATLAB commands - */ - default ProcStarter getProcessToRunMatlabCommand(FilePath workspace, - Launcher launcher, TaskListener listener, EnvVars envVars, String matlabCommand, String startupOpts, String uniqueName) - throws IOException, InterruptedException { - // Get node specific temp .matlab directory to copy matlab runner script - FilePath targetWorkspace; - ProcStarter matlabLauncher; - ArgumentListBuilder args = new ArgumentListBuilder(); - if (launcher.isUnix()) { - targetWorkspace = new FilePath(launcher.getChannel(), - workspace.getRemote() + "/" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME); - - // Determine whether we're on Mac on Linux - ByteArrayOutputStream kernelStream = new ByteArrayOutputStream(); - launcher.launch() - .cmds("uname") - .masks(true) - .stdout(kernelStream) - .join(); - - String binaryName; - String runnerName = uniqueName + "/run-matlab-command"; - if (kernelStream.toString("UTF-8").contains("Linux")) { - binaryName = "glnxa64/run-matlab-command"; - } else { - binaryName = "maci64/run-matlab-command"; - } - - args.add(MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME + "/" + runnerName); - args.add(matlabCommand); - args.add(startupOpts.split(" ")); - - matlabLauncher = launcher.launch().envs(envVars).cmds(args).stdout(listener); - - // Copy runner for linux platform in workspace. - copyFileInWorkspace(binaryName, runnerName, targetWorkspace); - } else { - targetWorkspace = new FilePath(launcher.getChannel(), - workspace.getRemote() + "\\" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME); - - final String runnerName = uniqueName + "\\run-matlab-command.exe"; - - args.add(targetWorkspace.toString() + "\\" + runnerName, "\"" + matlabCommand + "\""); - args.add(startupOpts.split(" ")); - - matlabLauncher = launcher.launch().envs(envVars).cmds(args).stdout(listener); - - // Copy runner for Windows platform in workspace. - copyFileInWorkspace("win64/run-matlab-command.exe", runnerName, - targetWorkspace); - } - return matlabLauncher; - } - - /* - * Method to copy given file from source to target node specific workspace. - */ - default void copyFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) - throws IOException, InterruptedException { - final ClassLoader classLoader = getClass().getClassLoader(); - FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); - InputStream in = classLoader.getResourceAsStream(sourceFile); - targetFilePath.copyFrom(in); - // set executable permission - targetFilePath.chmod(0755); - } - - default FilePath getFilePathForUniqueFolder(Launcher launcher, String uniqueName, - FilePath workspace) throws IOException, InterruptedException { - - String tmpDir = - workspace.getRemote() + "/" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME; - - return new FilePath(launcher.getChannel(), tmpDir + "/" + uniqueName); - } - - default String getUniqueNameForRunnerFile() { - //Using 8 bit long random alphanumeric string - return RandomStringUtils.randomAlphanumeric(8); - } - - // This method prepares the temp folder by coping all helper files in it. - default void prepareTmpFldr(FilePath tmpFldr, String runnerScript) throws IOException, InterruptedException { - // copy genscript package - copyFileInWorkspace(MatlabBuilderConstants.MATLAB_SCRIPT_GENERATOR, - MatlabBuilderConstants.MATLAB_SCRIPT_GENERATOR, tmpFldr); - FilePath zipFileLocation = - new FilePath(tmpFldr, MatlabBuilderConstants.MATLAB_SCRIPT_GENERATOR); - runnerScript=replaceZipPlaceholder(runnerScript, zipFileLocation.getRemote()); - - // Write MATLAB scratch file in temp folder. - FilePath scriptFile = - new FilePath(tmpFldr, getValidMatlabFileName(tmpFldr.getBaseName()) + ".m"); - scriptFile.write(runnerScript, "UTF-8"); - } - - //This method replaces the placeholder with genscript's zip file location URL in temp folder - default String replaceZipPlaceholder(String script, String url) { - script = script.replace("${ZIP_FILE}", url.replaceAll("'","''")); - return script; - } - - default String getRunnerScript(String script, String params, String uniqueTmpFldrName) { - script = script.replace("${PARAMS}", params); - return script; - } - - default String getValidMatlabFileName(String actualName) { - return MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX - + actualName.replaceAll("-", "_"); - } -} diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index 6a84b96f..62b9c130 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -1,4 +1,5 @@ package com.mathworks.ci; + /* * Copyright 2019-2020 The MathWorks, Inc. */ @@ -32,6 +33,12 @@ public class MatlabBuilderConstants { //Temporary MATLAB folder name in workspace public static final String TEMP_MATLAB_FOLDER_NAME = ".matlab"; + + // MATLAB default function/plugin paths + public static final String DEFAULT_PLUGIN = "+ciplugins/+jenkins/getDefaultPlugins.m"; + public static final String BUILD_REPORT_PLUGIN = "+ciplugins/+jenkins/BuildReportPlugin.m"; + public static final String TASK_RUN_PROGRESS_PLUGIN = "+ciplugins/+jenkins/TaskRunProgressPlugin.m"; + public static final String BUILD_ARTIFACT = "buildArtifact"; public static final String NEW_LINE = System.getProperty("line.separator"); diff --git a/src/main/java/com/mathworks/ci/MatlabExecutionException.java b/src/main/java/com/mathworks/ci/MatlabExecutionException.java index d606602d..ca7754bc 100644 --- a/src/main/java/com/mathworks/ci/MatlabExecutionException.java +++ b/src/main/java/com/mathworks/ci/MatlabExecutionException.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2021 The MathWorks, Inc. + * + */ + import java.lang.Exception; public class MatlabExecutionException extends Exception { diff --git a/src/main/java/com/mathworks/ci/MatlabNotFoundError.java b/src/main/java/com/mathworks/ci/MatlabNotFoundError.java index 993fbf48..a495f918 100644 --- a/src/main/java/com/mathworks/ci/MatlabNotFoundError.java +++ b/src/main/java/com/mathworks/ci/MatlabNotFoundError.java @@ -5,8 +5,6 @@ * */ -import java.io.FileNotFoundException; - public class MatlabNotFoundError extends Error { private static final long serialVersionUID = 7918595075502022644L; diff --git a/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java b/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java index 0c86ada8..641a9958 100644 --- a/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java +++ b/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java @@ -1,7 +1,5 @@ package com.mathworks.ci; -import java.io.BufferedReader; - /* * Copyright 2019 The MathWorks, Inc. This Class provides MATLAB release information in the form of * Version numbers. Class constructor requires MATLAB root as input parameter @@ -9,6 +7,7 @@ import java.io.InputStream; import java.io.InputStreamReader; +import java.io.BufferedReader; import java.nio.charset.StandardCharsets; import java.nio.file.NotDirectoryException; import java.util.HashMap; @@ -26,7 +25,6 @@ import org.w3c.dom.NodeList; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.FilePath; -import org.xml.sax.SAXException; public class MatlabReleaseInfo { private FilePath matlabRoot; diff --git a/src/main/java/com/mathworks/ci/MatrixPatternResolver.java b/src/main/java/com/mathworks/ci/MatrixPatternResolver.java index 14eee64e..77611061 100644 --- a/src/main/java/com/mathworks/ci/MatrixPatternResolver.java +++ b/src/main/java/com/mathworks/ci/MatrixPatternResolver.java @@ -1,4 +1,5 @@ package com.mathworks.ci; + /* * Copyright 2019 The MathWorks, Inc. * diff --git a/src/main/java/com/mathworks/ci/Message.java b/src/main/java/com/mathworks/ci/Message.java index 17ef09a0..52e4c3e5 100644 --- a/src/main/java/com/mathworks/ci/Message.java +++ b/src/main/java/com/mathworks/ci/Message.java @@ -1,6 +1,5 @@ package com.mathworks.ci; - /* Copyright 2018 The MathWorks, Inc. * * This Class is wrapper to access the static configuration values across project. Acts as diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index f39f5e3b..eb8f0399 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -9,7 +9,6 @@ */ import hudson.model.Item; -import hudson.security.Permission; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -19,7 +18,6 @@ import hudson.matrix.MatrixProject; import hudson.model.Computer; -import jenkins.model.Jenkins; import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; diff --git a/src/main/java/com/mathworks/ci/Utilities.java b/src/main/java/com/mathworks/ci/Utilities.java index 8e6371b8..900e3565 100644 --- a/src/main/java/com/mathworks/ci/Utilities.java +++ b/src/main/java/com/mathworks/ci/Utilities.java @@ -9,13 +9,10 @@ import hudson.EnvVars; import hudson.FilePath; -import hudson.Launcher; -import hudson.Util; import hudson.model.Computer; import hudson.model.Node; import hudson.model.TaskListener; -import javax.annotation.Nonnull; import java.io.IOException; import java.util.List; import java.util.Objects; diff --git a/src/main/java/com/mathworks/ci/actions/MatlabAction.java b/src/main/java/com/mathworks/ci/actions/MatlabAction.java new file mode 100644 index 00000000..df93b8d0 --- /dev/null +++ b/src/main/java/com/mathworks/ci/actions/MatlabAction.java @@ -0,0 +1,88 @@ +package com.mathworks.ci.actions; + +/** + * Copyright 2024, The MathWorks Inc. + * + */ + +import com.mathworks.ci.BuildArtifactAction; +import com.mathworks.ci.BuildConsoleAnnotator; +import com.mathworks.ci.MatlabBuilderConstants; +import com.mathworks.ci.utilities.MatlabCommandRunner; +import hudson.FilePath; +import hudson.model.Run; +import org.apache.commons.lang.RandomStringUtils; + +import java.io.File; +import java.io.IOException; + +public class MatlabAction { + MatlabCommandRunner runner; + BuildConsoleAnnotator annotator; + String actionID; + + public String getActionID(){ + return (this.actionID == null) ? "" : this.actionID; + } + + public MatlabAction(MatlabCommandRunner runner) { + this.runner = runner; + } + + public MatlabAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator) { + this.runner = runner; + this.actionID = RandomStringUtils.randomAlphanumeric(8); + this.annotator = annotator; + } + + public void copyBuildPluginsToTemp() throws IOException, InterruptedException { + // Copy plugins and override default plugins function + runner.copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + } + + public void setBuildEnvVars() throws IOException, InterruptedException { + // Set environment variable + runner.addEnvironmentVariable( + "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", + "ciplugins.jenkins.getDefaultPlugins"); + runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID()); + runner.addEnvironmentVariable( + "MW_MATLAB_TEMP_FOLDER", + runner.getTempFolder().toString()); + } + + public void teardownAction(Run build) { + // Handle build result + if(this.annotator != null) { + moveJsonArtifactToBuildRoot(build, MatlabBuilderConstants.BUILD_ARTIFACT); + } + + try { + this.runner.removeTempFolder(); + } catch (Exception e) { + System.err.println(e.toString()); + } + } + + private void moveJsonArtifactToBuildRoot(Run build, String artifactBaseName) { + try { + FilePath file = new FilePath(this.runner.getTempFolder(), artifactBaseName + ".json"); + if (file.exists()) { + FilePath rootLocation = new FilePath( + new File( + build.getRootDir().getAbsolutePath(), + artifactBaseName + this.getActionID() + ".json") + ); + file.copyTo(rootLocation); + file.delete(); + build.addAction(new BuildArtifactAction(build, this.getActionID())); + } + } catch (Exception e) { + // Don't want to override more important error + // thrown in catch block + System.err.println(e.toString()); + } + } +} diff --git a/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java b/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java index 15bd6898..d5892789 100644 --- a/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java +++ b/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java @@ -10,7 +10,7 @@ import com.mathworks.ci.parameters.*; public class MatlabActionFactory implements Serializable { - public RunMatlabCommandAction createAction(RunActionParameters params) throws IOException, InterruptedException { + public RunMatlabCommandAction createAction(CommandActionParameters params) throws IOException, InterruptedException { return new RunMatlabCommandAction(params); } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java index 93c2620e..c4e48ef6 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java @@ -5,40 +5,20 @@ * */ -import java.io.File; import java.io.IOException; -import hudson.FilePath; -import hudson.model.Run; - -import com.mathworks.ci.BuildArtifactAction; import com.mathworks.ci.BuildConsoleAnnotator; import com.mathworks.ci.MatlabExecutionException; import com.mathworks.ci.parameters.BuildActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; -import org.apache.commons.lang.RandomStringUtils; -public class RunMatlabBuildAction { - private BuildActionParameters params; - private MatlabCommandRunner runner; - private BuildConsoleAnnotator annotator; +import hudson.model.Run; - private static String DEFAULT_PLUGIN = - "+ciplugins/+jenkins/getDefaultPlugins.m"; - private static String BUILD_REPORT_PLUGIN = - "+ciplugins/+jenkins/BuildReportPlugin.m"; - private static String TASK_RUN_PROGRESS_PLUGIN = - "+ciplugins/+jenkins/TaskRunProgressPlugin.m"; - private String actionID; - - public String getActionID(){ - return this.actionID; - } +public class RunMatlabBuildAction extends MatlabAction { + private BuildActionParameters params; public RunMatlabBuildAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, BuildActionParameters params) { - this.runner = runner; - this.actionID = RandomStringUtils.randomAlphanumeric(8); - this.annotator = annotator; + super(runner, annotator); this.params = params; } @@ -51,20 +31,8 @@ public RunMatlabBuildAction(BuildActionParameters params) throws IOException, In } public void run() throws IOException, InterruptedException, MatlabExecutionException { - // Copy plugins and override default plugins function - runner.copyFileToTempFolder(DEFAULT_PLUGIN, DEFAULT_PLUGIN); - runner.copyFileToTempFolder(BUILD_REPORT_PLUGIN, BUILD_REPORT_PLUGIN); - runner.copyFileToTempFolder(TASK_RUN_PROGRESS_PLUGIN, TASK_RUN_PROGRESS_PLUGIN); - - - // Set environment variable - runner.addEnvironmentVariable( - "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", - "ciplugins.jenkins.getDefaultPlugins"); - runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID()); - runner.addEnvironmentVariable( - "MW_MATLAB_TEMP_FOLDER", - runner.getTempFolder().toString()); + super.copyBuildPluginsToTemp(); + super.setBuildEnvVars(); // Redirect output to the build annotator runner.redirectStdOut(annotator); @@ -93,32 +61,8 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep } finally { annotator.forceEol(); - try { - // Handle build result - Run build = this.params.getBuild(); - FilePath jsonFile = new FilePath(runner.getTempFolder(), "buildArtifact.json"); - if (jsonFile.exists()) { - FilePath rootLocation = new FilePath( - new File( - build.getRootDir().getAbsolutePath(), - "buildArtifact" + this.getActionID() + ".json") - ); - jsonFile.copyTo(rootLocation); - jsonFile.delete(); - build.addAction(new BuildArtifactAction(build, this.getActionID())); - } - } catch (Exception e) { - // Don't want to override more important error - // thrown in catch block - System.err.println(e.toString()); - } finally { - try { - this.runner.removeTempFolder(); - } catch (Exception e) { - System.err.println(e.toString()); - } - } + Run build = this.params.getBuild(); + super.teardownAction(build); } - } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java index 3ec0e1c5..72e942f8 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java @@ -7,38 +7,52 @@ import java.io.IOException; +import com.mathworks.ci.BuildConsoleAnnotator; import com.mathworks.ci.MatlabExecutionException; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; -public class RunMatlabCommandAction { - private RunActionParameters params; - private MatlabCommandRunner runner; +import hudson.model.Run; - public RunMatlabCommandAction(MatlabCommandRunner runner, RunActionParameters params) { - this.runner = runner; +public class RunMatlabCommandAction extends MatlabAction { + private CommandActionParameters params; + + public RunMatlabCommandAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, CommandActionParameters params) { + super(runner, annotator); this.params = params; } - public RunMatlabCommandAction(RunActionParameters params) throws IOException, InterruptedException { - this(new MatlabCommandRunner(params), params); + public RunMatlabCommandAction(CommandActionParameters params) throws IOException, InterruptedException { + this(new MatlabCommandRunner(params), + new BuildConsoleAnnotator( + params.getTaskListener().getLogger(), + params.getBuild().getCharset()), + params); } public void run() throws IOException, InterruptedException, MatlabExecutionException { + super.copyBuildPluginsToTemp(); + super.setBuildEnvVars(); + + // Redirect output to the build annotator + runner.redirectStdOut(annotator); + + // Prepare MATLAB command + String command = "addpath('" + + runner.getTempFolder().getRemote() + + "'); " + this.params.getCommand(); + try { - runner.runMatlabCommand(this.params.getCommand()); + runner.runMatlabCommand(command); } catch (Exception e) { this.params.getTaskListener().getLogger() .println(e.getMessage()); throw(e); } finally { - try { - this.runner.removeTempFolder(); - } catch (Exception e) { - // Don't want to override more important error - // thrown in catch block - System.err.println(e.toString()); - } + annotator.forceEol(); + + Run build = this.params.getBuild(); + super.teardownAction(build); } } } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java index bacf79ad..0156bbb4 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import hudson.FilePath; +import hudson.model.Run; import com.mathworks.ci.Utilities; import com.mathworks.ci.MatlabBuilderConstants; @@ -17,12 +18,11 @@ import com.mathworks.ci.parameters.TestActionParameters; import com.mathworks.ci.utilities.MatlabCommandRunner; -public class RunMatlabTestsAction { - private MatlabCommandRunner runner; +public class RunMatlabTestsAction extends MatlabAction { private TestActionParameters params; public RunMatlabTestsAction(MatlabCommandRunner runner, TestActionParameters params) { - this.runner = runner; + super(runner); this.params = params; } @@ -51,13 +51,8 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep .println(e.getMessage()); throw(e); } finally { - try { - this.runner.removeTempFolder(); - } catch (Exception e) { - // Don't want to override more important error - // thrown in catch block - System.err.println(e.toString()); - } + Run build = this.params.getBuild(); + super.teardownAction(build); } } diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java index 54b458df..c97cb6f3 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java @@ -32,7 +32,7 @@ import net.sf.json.JSONObject; import com.mathworks.ci.Message; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; import com.mathworks.ci.actions.MatlabActionFactory; import com.mathworks.ci.actions.RunMatlabCommandAction; import com.mathworks.ci.freestyle.options.StartupOptions; @@ -133,7 +133,7 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, // Get the environment variables specific to the this build final EnvVars env = build.getEnvironment(listener); - RunActionParameters params = new RunActionParameters( + CommandActionParameters params = new CommandActionParameters( build, workspace, env, launcher, listener, getStartupOptionsAsString(), diff --git a/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java b/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java index 71898991..9482ec7b 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java @@ -1,10 +1,14 @@ package com.mathworks.ci.freestyle.options; +/** + * Copyright 2020-2024 The MathWorks, Inc. + * + */ + import java.util.List; import java.util.stream.Collectors; import org.kohsuke.stapler.DataBoundConstructor; -import org.kohsuke.stapler.DataBoundSetter; import hudson.Extension; import hudson.Util; diff --git a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java index 108e0d09..2f5e4941 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java @@ -13,7 +13,6 @@ import hudson.model.Descriptor; import org.kohsuke.stapler.DataBoundConstructor; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; public class SourceFolder extends AbstractDescribableImpl { diff --git a/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java b/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java index 3162ff9d..b47a3da1 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java @@ -1,5 +1,10 @@ package com.mathworks.ci.freestyle.options; +/** + * Copyright 2020-2024 The MathWorks, Inc. + * + */ + import org.kohsuke.stapler.DataBoundConstructor; import hudson.Extension; diff --git a/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java b/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java index 55e3a1fd..797e9cf3 100644 --- a/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java @@ -1,5 +1,10 @@ package com.mathworks.ci.parameters; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import java.io.IOException; import hudson.FilePath; import hudson.EnvVars; @@ -8,11 +13,6 @@ import hudson.model.TaskListener; import org.jenkinsci.plugins.workflow.steps.StepContext; -/** - * Copyright 2024 The MathWorks, Inc. - * - */ - public class BuildActionParameters extends MatlabActionParameters { private String tasks; private String buildOptions; diff --git a/src/main/java/com/mathworks/ci/parameters/RunActionParameters.java b/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java similarity index 61% rename from src/main/java/com/mathworks/ci/parameters/RunActionParameters.java rename to src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java index 769f2dfa..ec3027a4 100644 --- a/src/main/java/com/mathworks/ci/parameters/RunActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java @@ -1,5 +1,10 @@ package com.mathworks.ci.parameters; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import java.io.IOException; import hudson.FilePath; import hudson.EnvVars; @@ -8,20 +13,15 @@ import hudson.model.TaskListener; import org.jenkinsci.plugins.workflow.steps.StepContext; -/** - * Copyright 2024 The MathWorks, Inc. - * - */ - -public class RunActionParameters extends MatlabActionParameters { +public class CommandActionParameters extends MatlabActionParameters { private String command; - public RunActionParameters(StepContext context, String startupOpts, String command) throws IOException, InterruptedException { + public CommandActionParameters(StepContext context, String startupOpts, String command) throws IOException, InterruptedException { super(context, startupOpts); this.command = command; } - public RunActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts, String command) { + public CommandActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts, String command) { super(build, workspace, env, launcher, listener, startupOpts); this.command = command; } diff --git a/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java b/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java index 65a0623a..9559e801 100644 --- a/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java @@ -1,7 +1,11 @@ package com.mathworks.ci.parameters; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import java.io.IOException; -import java.io.Serializable; import hudson.FilePath; import hudson.EnvVars; import hudson.Launcher; @@ -9,11 +13,6 @@ import hudson.model.TaskListener; import org.jenkinsci.plugins.workflow.steps.StepContext; -/** - * Copyright 2024 The MathWorks, Inc. - * - */ - public class MatlabActionParameters { private Run build; private FilePath workspace; diff --git a/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java b/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java index 5b3cdd56..97343b77 100644 --- a/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java @@ -1,5 +1,10 @@ package com.mathworks.ci.parameters; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ + import java.util.List; import java.util.ArrayList; import java.io.IOException; @@ -10,11 +15,6 @@ import hudson.model.TaskListener; import org.jenkinsci.plugins.workflow.steps.StepContext; -/** - * Copyright 2024 The MathWorks, Inc. - * - */ - public class TestActionParameters extends MatlabActionParameters { private String testResultsPDF; private String testResultsTAP; diff --git a/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java b/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java index fc37a9de..2efaad92 100644 --- a/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java +++ b/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java @@ -11,7 +11,7 @@ import hudson.model.Result; import com.mathworks.ci.actions.MatlabActionFactory; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; import com.mathworks.ci.actions.RunMatlabCommandAction; public class MatlabCommandStepExecution extends SynchronousNonBlockingStepExecution { @@ -34,7 +34,7 @@ public MatlabCommandStepExecution(StepContext context, RunMatlabCommandStep step @Override public Void run() throws Exception { - RunActionParameters params = new RunActionParameters( + CommandActionParameters params = new CommandActionParameters( getContext(), step.getStartupOptions(), step.getCommand()); diff --git a/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java index 6350b8e3..62375800 100644 --- a/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java @@ -1,14 +1,12 @@ package com.mathworks.ci.pipeline; + /** * Copyright 2020-2024 The MathWorks, Inc. * */ import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import org.jenkinsci.plugins.workflow.steps.Step; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -26,7 +24,6 @@ import hudson.Util; import com.mathworks.ci.Message; -import com.mathworks.ci.parameters.TestActionParameters; public class RunMatlabTestsStep extends Step implements Serializable { diff --git a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java index cfbc30a3..a69f9559 100644 --- a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java +++ b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java @@ -23,7 +23,6 @@ import com.mathworks.ci.Utilities; import com.mathworks.ci.MatlabExecutionException; -import com.mathworks.ci.MatlabBuilderConstants; import com.mathworks.ci.parameters.MatlabActionParameters; public class MatlabCommandRunner { diff --git a/src/main/resources/+ciplugins/+jenkins/TaskRunProgressPlugin.m b/src/main/resources/+ciplugins/+jenkins/TaskRunProgressPlugin.m index 5b4740c1..525d99b1 100644 --- a/src/main/resources/+ciplugins/+jenkins/TaskRunProgressPlugin.m +++ b/src/main/resources/+ciplugins/+jenkins/TaskRunProgressPlugin.m @@ -9,5 +9,10 @@ function runTask(plugin, pluginData) disp("[MATLAB-Build-" + pluginData.TaskResults.Name + "-" + getenv('MW_BUILD_PLUGIN_ACTION_ID') +"]"); runTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); end + + function skipTask(plugin, pluginData) + disp("[MATLAB-Build-" + pluginData.TaskResults.Name + "-" + getenv('MW_BUILD_PLUGIN_ACTION_ID') +"]"); + skipTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); + end end end \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly index f9205e21..2b6bdec2 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly @@ -82,7 +82,12 @@ - SKIPPED + + SKIPPED + + + SKIPPED + diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly index 65872cef..eacd464e 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly @@ -12,12 +12,15 @@
Unable to generate a build artifact.
-

Tasks run: ${it.totalCount}

-
- Failed: ${it.failCount} -
-
- Skipped: ${it.skipCount} -
+

+ Tasks run: ${it.totalCount} +

+
+ Failed: ${it.failCount} +
+
+ Skipped: ${it.skipCount} +
+

\ No newline at end of file diff --git a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java index c0601f73..e5dea1b7 100644 --- a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java @@ -1,5 +1,9 @@ package com.mathworks.ci; +/** + * Copyright 2024 The MathWorks, Inc. + * + */ import hudson.FilePath; import hudson.model.FreeStyleBuild; @@ -111,7 +115,7 @@ public void verifySkipCount() throws ExecutionException, InterruptedException, U final String targetFile = "buildArtifact"+ actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts.t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); List ba = ac.getBuildArtifact(); Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped()); } @@ -128,7 +132,7 @@ public void verifyDurationIsAccurate() throws ExecutionException, InterruptedExc final String targetFile = "buildArtifact"+ actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts.t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); List ba = ac.getBuildArtifact(); Assert.assertEquals("The task duration is not matching","00:02:53",ba.get(0).getTaskDuration()); } @@ -145,7 +149,7 @@ public void verifyTaskDescriptionIsAccurate() throws ExecutionException, Interru final String targetFile = "buildArtifact"+ actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts.t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); List ba = ac.getBuildArtifact(); Assert.assertEquals("The task description is not matching","Test show",ba.get(0).getTaskDescription()); } @@ -162,7 +166,7 @@ public void verifyTaskNameIsAccurate() throws ExecutionException, InterruptedExc final String targetFile = "buildArtifact"+ actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts.t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); List ba = ac.getBuildArtifact(); Assert.assertEquals("The task name is not matching","show",ba.get(0).getTaskName()); } @@ -178,7 +182,7 @@ public void verifyTotalTaskCountIsAccurate() throws ExecutionException, Interrup FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts.t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); Assert.assertEquals("Total task count is not correct",1,ac.getTotalCount()); } diff --git a/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java b/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java index 72e3c63e..4012c61f 100644 --- a/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java +++ b/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2020-2021 The MathWorks, Inc. + * + */ + import hudson.matrix.AxisList; import hudson.matrix.MatrixBuild; import hudson.matrix.MatrixProject; diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java index a42f419d..66c8e834 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -6,7 +6,6 @@ import java.io.IOException; -import hudson.model.Result; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java index 3aad1315..4ed50ce3 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java @@ -1,10 +1,12 @@ package com.mathworks.ci; + /** * Copyright 2020-2024 The MathWorks, Inc. * * Test class for RunMatlabTestsBuilder Persistence * */ + import hudson.model.FreeStyleProject; import hudson.model.Item; import org.junit.*; diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java index 97b5fc73..56fc1d51 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java @@ -21,11 +21,9 @@ import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import com.gargoylesoftware.htmlunit.WebAssert; -import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSelect; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSelectElement; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.CoberturaArtifact; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.JunitArtifact; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.ModelCovArtifact; diff --git a/src/test/java/integ/com/mathworks/ci/TestMessage.java b/src/test/java/integ/com/mathworks/ci/TestMessage.java index f8842832..60846be0 100644 --- a/src/test/java/integ/com/mathworks/ci/TestMessage.java +++ b/src/test/java/integ/com/mathworks/ci/TestMessage.java @@ -1,7 +1,5 @@ package com.mathworks.ci; -import java.util.ResourceBundle; - /* * Copyright 2018 The MathWorks, Inc. * @@ -9,6 +7,8 @@ * Utility class to access key & value pairs from testconfig.properties */ +import java.util.ResourceBundle; + public class TestMessage { private static String VERIFY_MATLAB_INVOKES_POSITIVE = "Verify.matlab.invokes.positive"; diff --git a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java index 46a3dbb5..4c2a73d1 100644 --- a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java +++ b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java @@ -1,4 +1,5 @@ package com.mathworks.ci; + /** * Copyright 2019-2020 The MathWorks, Inc. * @@ -25,7 +26,6 @@ import hudson.model.FreeStyleProject; import hudson.tasks.BuildWrapper; - public class UseMatlabVersionBuildWrapperTest { private FreeStyleProject project; diff --git a/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java new file mode 100644 index 00000000..44dadae0 --- /dev/null +++ b/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java @@ -0,0 +1,126 @@ +package unit.com.mathworks.ci.actions; + +/** + * Copyright 2024, The MathWorks Inc. + * + */ + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.nio.file.Files; + +import org.junit.Test; +import org.junit.Before; +import org.junit.runner.RunWith; +import static org.junit.Assert.*; + +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import hudson.FilePath; +import hudson.model.Run; +import hudson.model.TaskListener; + +import com.mathworks.ci.MatlabBuilderConstants; +import com.mathworks.ci.BuildArtifactAction; +import com.mathworks.ci.BuildConsoleAnnotator; +import com.mathworks.ci.MatlabExecutionException; +import com.mathworks.ci.actions.RunMatlabCommandAction; +import com.mathworks.ci.utilities.MatlabCommandRunner; +import com.mathworks.ci.parameters.CommandActionParameters; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class MatlabActionTest { + @Mock CommandActionParameters params; + @Mock BuildConsoleAnnotator annotator; + @Mock MatlabCommandRunner runner; + @Mock PrintStream out; + @Mock TaskListener listener; + @Mock Run build; + + @Mock FilePath tempFolder; + + private boolean setup = false; + private RunMatlabCommandAction action; + + // Not using @BeforeClass to avoid static fields. + @Before + public void init() { + if (!setup) { + setup = true; + action = new RunMatlabCommandAction(runner, annotator, params); + + when(runner.getTempFolder()).thenReturn(tempFolder); + when(tempFolder.getRemote()).thenReturn("/path/less/traveled"); + + when(params.getTaskListener()).thenReturn(listener); + when(listener.getLogger()).thenReturn(out); + + when(params.getBuild()).thenReturn(build); + } + } + + @Test + public void shouldCopyPluginsToTempDirectory() throws IOException, InterruptedException, MatlabExecutionException { + action.run(); + + InOrder inOrder = inOrder(runner); + + inOrder.verify(runner) + .copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); + inOrder.verify(runner) + .copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); + inOrder.verify(runner) + .copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + } + + @Test + public void shouldOverrideDefaultBuildtoolPlugin() throws IOException, InterruptedException, MatlabExecutionException { + action.run(); + + verify(runner).addEnvironmentVariable( + "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", + "ciplugins.jenkins.getDefaultPlugins"); + } + + @Test + public void shouldCopyBuildResultsToRootAndAddAction() throws IOException, InterruptedException, MatlabExecutionException { + File tmp = Files.createTempDirectory("temp").toFile(); + tmp.deleteOnExit(); + + File dest = Files.createTempDirectory("dest").toFile(); + dest.deleteOnExit(); + + File json = new File(tmp, "buildArtifact.json"); + json.createNewFile(); + + doReturn(new FilePath(tmp)).when(runner).getTempFolder(); + doReturn(dest).when(build).getRootDir(); + + action.run(); + + // Should have deleted original file + assertFalse(json.exists()); + // Should have copied file to root dir + assertTrue(new File(dest, "buildArtifact"+ action.getActionID() + ".json").exists()); + } + + @Test + public void shouldNotAddActionIfNoBuildResult() throws IOException, InterruptedException, MatlabExecutionException { + action.run(); + + verify(build, never()).addAction(any(BuildArtifactAction.class)); + } + + @Test + public void shouldRemoveTempFolder() throws IOException, InterruptedException, MatlabExecutionException { + action.run(); + + verify(runner).removeTempFolder(); + } +} diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java index 7831299c..bfd66117 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java @@ -5,10 +5,8 @@ * */ -import java.io.File; import java.io.IOException; import java.io.PrintStream; -import java.nio.file.Files; import org.junit.Test; import org.junit.Before; @@ -16,15 +14,15 @@ import static org.junit.Assert.*; import org.mockito.Mock; -import org.mockito.InOrder; import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; import hudson.FilePath; import hudson.model.Run; import hudson.model.TaskListener; -import com.mathworks.ci.BuildArtifactAction; import com.mathworks.ci.BuildConsoleAnnotator; import com.mathworks.ci.MatlabExecutionException; import com.mathworks.ci.utilities.MatlabCommandRunner; @@ -61,36 +59,6 @@ public void init() { } } - @Test - public void shouldCopyPluginsToTempDirectory() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - String DEFAULT_PLUGIN = - "+ciplugins/+jenkins/getDefaultPlugins.m"; - String BUILD_REPORT_PLUGIN = - "+ciplugins/+jenkins/BuildReportPlugin.m"; - String TASK_RUN_PROGRESS_PLUGIN = - "+ciplugins/+jenkins/TaskRunProgressPlugin.m"; - - InOrder inOrder = inOrder(runner); - - inOrder.verify(runner) - .copyFileToTempFolder(DEFAULT_PLUGIN, DEFAULT_PLUGIN); - inOrder.verify(runner) - .copyFileToTempFolder(BUILD_REPORT_PLUGIN, BUILD_REPORT_PLUGIN); - inOrder.verify(runner) - .copyFileToTempFolder(TASK_RUN_PROGRESS_PLUGIN, TASK_RUN_PROGRESS_PLUGIN); - } - - @Test - public void shouldOverrideDefaultPlugins() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - verify(runner).addEnvironmentVariable( - "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", - "ciplugins.jenkins.getDefaultPlugins"); - } - @Test public void shouldUseCustomAnnotator() throws IOException, InterruptedException, MatlabExecutionException { action.run(); @@ -130,40 +98,4 @@ public void shouldPrintAndRethrowMessage() throws IOException, InterruptedExcept assertEquals(12, e.getExitCode()); }; } - - @Test - public void shouldNotAddActionIfNoBuildResult() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - verify(build, never()).addAction(any(BuildArtifactAction.class)); - } - - @Test - public void shouldCopyBuildResultsToRootAndAddAction() throws IOException, InterruptedException, MatlabExecutionException { - File tmp = Files.createTempDirectory("temp").toFile(); - tmp.deleteOnExit(); - - File dest = Files.createTempDirectory("dest").toFile(); - dest.deleteOnExit(); - - File json = new File(tmp, "buildArtifact.json"); - json.createNewFile(); - - doReturn(new FilePath(tmp)).when(runner).getTempFolder(); - doReturn(dest).when(build).getRootDir(); - - action.run(); - - // Should have deleted original file - assertFalse(json.exists()); - // Should have copied file to root dir - assertTrue(new File(dest, "buildArtifact"+ action.getActionID() + ".json").exists()); - } - - @Test - public void shouldRemoveTempFolder() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - verify(runner).removeTempFolder(); - } } diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java index c6c41885..0456c292 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java @@ -15,20 +15,29 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; +import hudson.FilePath; +import hudson.model.Run; import hudson.model.TaskListener; +import com.mathworks.ci.BuildConsoleAnnotator; import com.mathworks.ci.MatlabExecutionException; import com.mathworks.ci.utilities.MatlabCommandRunner; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; @RunWith(MockitoJUnitRunner.Silent.class) public class RunMatlabCommandActionTest { - @Mock RunActionParameters params; + @Mock CommandActionParameters params; + @Mock BuildConsoleAnnotator annotator; @Mock MatlabCommandRunner runner; @Mock PrintStream out; @Mock TaskListener listener; + @Mock Run build; + + @Mock FilePath tempFolder; private boolean setup = false; private RunMatlabCommandAction action; @@ -38,17 +47,35 @@ public class RunMatlabCommandActionTest { public void init() { if (!setup) { setup = true; - action = new RunMatlabCommandAction(runner, params); + action = new RunMatlabCommandAction(runner, annotator, params); + + when(runner.getTempFolder()).thenReturn(tempFolder); + when(tempFolder.getRemote()).thenReturn("/path/less/traveled"); + + when(params.getTaskListener()).thenReturn(listener); + when(listener.getLogger()).thenReturn(out); + + when(params.getBuild()).thenReturn(build); } } + @Test + public void shouldUseCustomAnnotator() throws IOException, InterruptedException, MatlabExecutionException { + action.run(); + + verify(runner).redirectStdOut(annotator); + } + @Test public void runsGivenCommand() throws IOException, InterruptedException, MatlabExecutionException { when(params.getCommand()).thenReturn("Sit!"); + when(runner.getTempFolder()).thenReturn(tempFolder); + when(tempFolder.getRemote()).thenReturn("/path/less/traveled"); + action.run(); - verify(runner).runMatlabCommand("Sit!"); + verify(runner).runMatlabCommand("addpath('/path/less/traveled'); Sit!"); } @Test @@ -66,11 +93,4 @@ public void printsAndRethrowsMessage() throws IOException, InterruptedException, assertEquals(12, e.getExitCode()); }; } - - @Test - public void shouldRemoveTempFolder() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - verify(runner).removeTempFolder(); - } } diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java index 16d984fb..85de29e9 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java @@ -170,11 +170,4 @@ public void printsAndRethrowsMessage() throws IOException, InterruptedException, assertEquals(12, e.getExitCode()); }; } - - @Test - public void shouldRemoveTempFolder() throws IOException, InterruptedException, MatlabExecutionException { - action.run(); - - verify(runner).removeTempFolder(); - } } diff --git a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java index 3b15c754..3cc2e830 100644 --- a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java @@ -27,7 +27,7 @@ import com.mathworks.ci.MatlabExecutionException; import com.mathworks.ci.actions.MatlabActionFactory; import com.mathworks.ci.actions.RunMatlabCommandAction; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; @RunWith(MockitoJUnitRunner.class) public class RunMatlabCommandBuilderUnitTest { @@ -51,7 +51,7 @@ public class RunMatlabCommandBuilderUnitTest { @Before public void setup() throws IOException, InterruptedException { - doReturn(action).when(factory).createAction(any(RunActionParameters.class)); + doReturn(action).when(factory).createAction(any(CommandActionParameters.class)); } @Test @@ -60,10 +60,10 @@ public void shouldHandleNullCases() throws IOException, InterruptedException, Ma builder.perform(build, workspace, launcher, listener); - ArgumentCaptor captor = ArgumentCaptor.forClass(RunActionParameters.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); - RunActionParameters actual = captor.getValue(); + CommandActionParameters actual = captor.getValue(); assertEquals("", actual.getStartupOptions()); assertEquals(null, actual.getCommand()); @@ -78,10 +78,10 @@ public void shouldHandleMaximalCases() throws IOException, InterruptedException, builder.perform(build, workspace, launcher, listener); - ArgumentCaptor captor = ArgumentCaptor.forClass(RunActionParameters.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); - RunActionParameters actual = captor.getValue(); + CommandActionParameters actual = captor.getValue(); assertEquals("-nojvm -logfile mylog", actual.getStartupOptions()); assertEquals("SHAKE", actual.getCommand()); diff --git a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java index a753cd85..d8393374 100644 --- a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java @@ -14,9 +14,7 @@ import static org.junit.Assert.*; import org.mockito.Mock; -import org.mockito.InjectMocks; import org.mockito.ArgumentCaptor; -import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import static org.mockito.Mockito.*; diff --git a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java index 518b6c13..f4e5ed9b 100644 --- a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java @@ -22,7 +22,7 @@ import com.mathworks.ci.MatlabExecutionException; import com.mathworks.ci.actions.MatlabActionFactory; import com.mathworks.ci.actions.RunMatlabCommandAction; -import com.mathworks.ci.parameters.RunActionParameters; +import com.mathworks.ci.parameters.CommandActionParameters; @RunWith(MockitoJUnitRunner.class) public class MatlabCommandStepExecutionUnitTest { @@ -32,7 +32,7 @@ public class MatlabCommandStepExecutionUnitTest { @Before public void setup() throws IOException, InterruptedException { - when(factory.createAction(any(RunActionParameters.class))).thenReturn(action); + when(factory.createAction(any(CommandActionParameters.class))).thenReturn(action); } @Test @@ -44,10 +44,10 @@ public void shouldHandleNullCases() throws Exception, IOException, InterruptedEx ex.run(); - ArgumentCaptor captor = ArgumentCaptor.forClass(RunActionParameters.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); - RunActionParameters params = captor.getValue(); + CommandActionParameters params = captor.getValue(); assertEquals("", params.getStartupOptions()); assertEquals(null, params.getCommand()); @@ -63,10 +63,10 @@ public void shouldHandleMaximalCases() throws Exception, IOException, Interrupte ex.run(); - ArgumentCaptor captor = ArgumentCaptor.forClass(RunActionParameters.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); - RunActionParameters params = captor.getValue(); + CommandActionParameters params = captor.getValue(); assertEquals("-nojvm -logfile file", params.getStartupOptions()); assertEquals("mycommand", params.getCommand()); diff --git a/src/test/resources/buildArtifacts.t2/buildArtifact.json b/src/test/resources/buildArtifacts/t2/buildArtifact.json similarity index 100% rename from src/test/resources/buildArtifacts.t2/buildArtifact.json rename to src/test/resources/buildArtifacts/t2/buildArtifact.json From 8afb9e21f2a6c9b08d1d502532d8005d46839386 Mon Sep 17 00:00:00 2001 From: Kapil Gupta <111856426+mw-kapilg@users.noreply.github.com> Date: Thu, 5 Sep 2024 09:40:26 +0530 Subject: [PATCH 05/51] Add skip reason for skipped tasks in build results table (#356) * Add skipReason in build results table * add skip reason texts * add test and bump Maven task * remove .idea from gitignore in this branch * update as per review comments * update as per review * update function name * update build results table * update test * update skip link * update status to succeeded * update data constructor --- azure-pipelines.yml | 2 +- .../com/mathworks/ci/BuildArtifactAction.java | 22 ++++++++- .../com/mathworks/ci/BuildArtifactData.java | 9 ++++ .../+ciplugins/+jenkins/BuildReportPlugin.m | 45 ++++++++++++++----- .../ci/BuildArtifactAction/index.jelly | 40 ++++++++--------- .../ci/BuildArtifactAction/summary.jelly | 19 ++++---- .../mathworks/ci/MatlabBuilder/config.jelly | 2 +- .../mathworks/ci/BuildArtifactActionTest.java | 21 ++++++++- .../buildArtifacts/t1/buildArtifact.json | 1 + .../buildArtifacts/t2/buildArtifact.json | 1 + 10 files changed, 113 insertions(+), 49 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 358418b3..30ae949c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -19,7 +19,7 @@ trigger: - master steps: - - task: Maven@3 + - task: Maven@4 inputs: mavenPomFile: 'pom.xml' mavenOptions: '-Xmx3072m -Dmaven.javadoc.skip=true' diff --git a/src/main/java/com/mathworks/ci/BuildArtifactAction.java b/src/main/java/com/mathworks/ci/BuildArtifactAction.java index 2e2fd92c..cc50f9b7 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactAction.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactAction.java @@ -206,7 +206,7 @@ private void setCounts() throws InterruptedException, ParseException { private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) { // Iterates across all task attributes and updates String key = pair.getKey().toString(); - switch(key.toLowerCase()){ + switch(key){ case "duration": data.setTaskDuration(pair.getValue().toString()); break; @@ -222,6 +222,26 @@ private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) { case "skipped": data.setTaskSkipped((Boolean) pair.getValue()); break; + case "skipReason": + String skipReasonKey = pair.getValue().toString(); + String skipReason; + switch(skipReasonKey){ + case "UpToDate": + skipReason = "up-to-date"; + break; + case "UserSpecified": + case "UserRequested": + skipReason = "user requested"; + break; + case "DependencyFailed": + skipReason = "dependency failed"; + break; + default: + skipReason = skipReasonKey; + break; + } + data.setSkipReason(skipReason); + break; default : break; } diff --git a/src/main/java/com/mathworks/ci/BuildArtifactData.java b/src/main/java/com/mathworks/ci/BuildArtifactData.java index 4b2444ed..eac3bc19 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactData.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactData.java @@ -13,6 +13,7 @@ public class BuildArtifactData { private String taskDescription; private boolean taskSkipped; + private String skipReason; public BuildArtifactData() { } @@ -41,6 +42,14 @@ public void setTaskSkipped(boolean taskSkipped) { this.taskSkipped = taskSkipped; } + public String getSkipReason() { + return (this.skipReason == null) ? "" : this.skipReason; + } + + public void setSkipReason(String skipReason) { + this.skipReason = skipReason; + } + public boolean getTaskFailed() { return this.taskFailed; } diff --git a/src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m b/src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m index a9935e67..75190cd6 100644 --- a/src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m +++ b/src/main/resources/+ciplugins/+jenkins/BuildReportPlugin.m @@ -2,27 +2,48 @@ % Copyright 2024 The MathWorks, Inc. - methods (Access=protected) + properties + TaskDetails = {}; + end + methods (Access=protected) function runTaskGraph(plugin, pluginData) runTaskGraph@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); + [fID, msg] = fopen(fullfile(getenv("MW_MATLAB_TEMP_FOLDER"),"buildArtifact.json"), "w"); if fID == -1 warning("ciplugins:jenkins:BuildReportPlugin:UnableToOpenFile","Could not open a file for Jenkins build result table due to: %s", msg); else closeFile = onCleanup(@()fclose(fID)); - taskDetails = struct(); - for idx = 1:numel(pluginData.TaskResults) - taskDetails(idx).name = pluginData.TaskResults(idx).Name; - taskDetails(idx).description = pluginData.TaskGraph.Tasks(idx).Description; - taskDetails(idx).failed = pluginData.TaskResults(idx).Failed; - taskDetails(idx).skipped = pluginData.TaskResults(idx).Skipped; - taskDetails(idx).duration = string(pluginData.TaskResults(idx).Duration); - end - a = struct("taskDetails",taskDetails); - s = jsonencode(a,PrettyPrint=true); - fprintf(fID, "%s",s); + a = struct(); + a.taskDetails = plugin.TaskDetails; + s = jsonencode(a, PrettyPrint=true); + fprintf(fID, "%s", s); end end + + function runTask(plugin, pluginData) + runTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); + + taskDetail = getCommonTaskDetail(pluginData); + plugin.TaskDetails = [plugin.TaskDetails, taskDetail]; + end + + function skipTask(plugin, pluginData) + skipTask@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); + + taskDetail = getCommonTaskDetail(pluginData); + taskDetail.skipReason = pluginData.SkipReason; + plugin.TaskDetails = [plugin.TaskDetails, taskDetail]; + end end end + +function taskDetail = getCommonTaskDetail(pluginData) + taskDetail = struct(); + taskDetail.name = pluginData.TaskResults.Name; + taskDetail.description = pluginData.TaskGraph.Tasks.Description; + taskDetail.failed = pluginData.TaskResults.Failed; + taskDetail.skipped = pluginData.TaskResults.Skipped; + taskDetail.duration = string(pluginData.TaskResults.Duration); +end \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly index 2b6bdec2..abd685d0 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/index.jelly @@ -1,4 +1,3 @@ - @@ -23,20 +22,20 @@ (${h.getDiffString(it.failCount-prev.failCount)}) - , Skipped ${(it.skipCount)} + , ${(it.skipCount)} Skipped (${h.getDiffString(it.skipCount-prev.skipCount)}) -
+
-
+
-
+
- ${(it.failCount)} Failures + ${(it.failCount)} Failed (${h.getDiffString(it.totalCount-prev.totalCount)}) @@ -48,10 +47,10 @@ - + - + @@ -66,28 +65,25 @@ ${p.taskName} - diff --git a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly index eacd464e..f407202b 100644 --- a/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly +++ b/src/main/resources/com/mathworks/ci/BuildArtifactAction/summary.jelly @@ -9,18 +9,15 @@

MATLAB Build Results

-
Unable to generate a build artifact.
+
Unable to generate a build artifact.
-

- Tasks run: ${it.totalCount} -

-
- Failed: ${it.failCount} -
-
- Skipped: ${it.skipCount} -
-

+

Tasks run: ${it.totalCount}

+
+ Failed: ${it.failCount} +
+
+ Skipped: ${it.skipCount} +
\ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly b/src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly index 5a2cd6ae..25df9f60 100644 --- a/src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly +++ b/src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly @@ -1,7 +1,7 @@ - Using this build step is not recommended and will be removed in a feature release. Use “Run MATLAB Tests” or “Run MATLAB Command” instead. + Using this build step is not recommended and will be removed in a feature release. Use “Run MATLAB Tests” or “Run MATLAB Command” instead. diff --git a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java index e5dea1b7..d9aba437 100644 --- a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java @@ -100,7 +100,7 @@ public void verifyFailedCount() throws ExecutionException, InterruptedException, copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); List ba = ac.getBuildArtifact(); boolean expectedStatus = ba.get(0).getTaskFailed(); - Assert.assertEquals("The task is passed",false,expectedStatus); + Assert.assertEquals("The task succeeded",false,expectedStatus); } /** @@ -120,6 +120,24 @@ public void verifySkipCount() throws ExecutionException, InterruptedException, U Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped()); } + /** + * Verify if skip reason is returned from artifact file. + * + */ + + @Test + public void verifySkipReasonIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + FreeStyleBuild build = getFreestyleBuild(); + final String actionID = "abc123"; + final String targetFile = "buildArtifact"+ actionID + ".json"; + BuildArtifactAction ac = new BuildArtifactAction(build, actionID); + FilePath artifactRoot = new FilePath(build.getRootDir()); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + List ba = ac.getBuildArtifact(); + Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped()); + Assert.assertEquals("The skip reason for skipped task is inaccurate","user requested",ba.get(0).getSkipReason()); + } + /** * Verify if duration returned from artifact file. * @@ -219,6 +237,7 @@ public void verifyTotalFailedTaskCountIsAccurate() throws ExecutionException, In Assert.assertEquals("Total task count is not correct",3,ac.getTotalCount()); Assert.assertEquals("Total task failed count is not correct",1,ac.getFailCount()); } + /** * Verify if total skipped count returned from artifact file. * diff --git a/src/test/resources/buildArtifacts/t1/buildArtifact.json b/src/test/resources/buildArtifacts/t1/buildArtifact.json index f2f5d392..10675798 100644 --- a/src/test/resources/buildArtifacts/t1/buildArtifact.json +++ b/src/test/resources/buildArtifacts/t1/buildArtifact.json @@ -19,6 +19,7 @@ "description": "tests Dscription", "failed": false, "skipped": true, + "skipReason": "UserSpecified", "duration": "00:00:00" } ] diff --git a/src/test/resources/buildArtifacts/t2/buildArtifact.json b/src/test/resources/buildArtifacts/t2/buildArtifact.json index 5c9d061d..20333714 100644 --- a/src/test/resources/buildArtifacts/t2/buildArtifact.json +++ b/src/test/resources/buildArtifacts/t2/buildArtifact.json @@ -4,6 +4,7 @@ "description": "Test show", "failed": false, "skipped": true, + "skipReason": "UserSpecified", "duration": "00:02:53" } } \ No newline at end of file From aa45f72444010345e4f01b672aaa4297df7aa364 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 1 Oct 2024 14:22:31 +0530 Subject: [PATCH 06/51] Intial commit --- .../ci/UseMatlabVersionBuildWrapper.java | 5 +- .../ci/tools/InstallationFailedException.java | 12 ++ .../mathworks/ci/tools/MatlabInstallable.java | 48 +++++ .../mathworks/ci/tools/MatlabInstaller.java | 193 ++++++++++++++++++ .../ci/tools/MatlabInstaller/config.jelly | 9 + src/main/resources/config.properties | 2 + 6 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/mathworks/ci/tools/InstallationFailedException.java create mode 100644 src/main/java/com/mathworks/ci/tools/MatlabInstallable.java create mode 100644 src/main/java/com/mathworks/ci/tools/MatlabInstaller.java create mode 100644 src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index eb8f0399..7db197e7 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -194,11 +194,12 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } + // Add matlab-batch executable in path + context.env("PATH+matlab_batch", matlabExecutablePath.getParent().getParent().getRemote()); // Add "matlabroot" without bin as env variable which will be available across the build. context.env("matlabroot", getNodeSpecificMatlab(Computer.currentComputer(), listener)); // Add matlab bin to path to invoke MATLAB directly on command line. - context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote()); - // Specify which MATLAB was added to path. + context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());; listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath.getParent().getRemote()) + "\n"); } diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java new file mode 100644 index 00000000..863a2528 --- /dev/null +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -0,0 +1,12 @@ +package com.mathworks.ci.tools; + +import java.io.IOException; + +// Extend IOException so we can throw and stop the build if installation fails + +public class InstallationFailedException extends IOException { + InstallationFailedException(String message) { + super(message); + } +} + diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java new file mode 100644 index 00000000..ef931e6d --- /dev/null +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -0,0 +1,48 @@ +package com.mathworks.ci.tools; + + +import hudson.FilePath; +import hudson.tools.DownloadFromUrlInstaller.Installable; + +public class MatlabInstallable extends Installable { + public String getBatchURL() { + return this.batchURL; + } + + public String batchURL; + private String osName; + public MatlabInstallable(String osName) throws InstallationFailedException { + this.osName = osName; + switch (osName) { + case "win64" : + this.url = "https://www.mathworks.com/mpm/win64/mpm"; + this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe"; + break; + case "glnxa64" : + this.url = "https://www.mathworks.com/mpm/glnxa64/mpm"; + this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch"; + break; + case "maci64" : + this.url = "https://www.mathworks.com/mpm/maci64/mpm"; + this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch"; + break; + default : + throw new InstallationFailedException("Unsupported OS"); + } + } + + public FilePath getBatchInstallable(FilePath expectedPath) { + if(this.osName == "win64"){ + return new FilePath(expectedPath,"matlab-batch.exe"); + } + return new FilePath(expectedPath, "matlab-batch"); + } + + public FilePath getMpmInstallable(FilePath expectedPath) { + if(this.osName == "win64"){ + return new FilePath(expectedPath,"mpm.exe"); + } + return new FilePath(expectedPath, "mpm"); + } + +} diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java new file mode 100644 index 00000000..df936f6f --- /dev/null +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -0,0 +1,193 @@ +package com.mathworks.ci.tools; + +import com.mathworks.ci.MatlabInstallation; +import com.mathworks.ci.Message; +import com.sun.akuma.CLibrary.FILE; +import hudson.EnvVars; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.Launcher.ProcStarter; +import hudson.model.Node; +import hudson.model.TaskListener; +import hudson.tools.DownloadFromUrlInstaller; +import hudson.tools.ToolInstallation; +import hudson.tools.ToolInstallerDescriptor; +import hudson.util.ArgumentListBuilder; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Locale; +import jenkins.security.MasterToSlaveCallable; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; + +public class MatlabInstaller extends DownloadFromUrlInstaller { + private String version; + private String products; + + @DataBoundConstructor + public MatlabInstaller(String id) { + super(id); + } + + public String getVersion(){ + return this.version; + } + + @DataBoundSetter + public void setVersion(String version) { + this.version = version; + } + + public String getProducts() { return this.products; } + + @DataBoundSetter + public void setProducts(String products) { + this.products = products; + } + + public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { + FilePath expectedPath = preferredLocation(tool, node); + MatlabInstallable installable; + try { + installable = (MatlabInstallable) getInstallable(node); + } catch (InstallationFailedException e) { + throw new InstallationFailedException(e.getMessage()); + } + + if (installable == null) { + log.getLogger().println(Message.getValue("matlab.tools.auto.install.matlab.installable.error")); + return expectedPath; + } + + if (isUpToDate(expectedPath, installable)) { + return expectedPath; + } + + FilePath matlabVersionFile = new FilePath(expectedPath, "VersionInfo.xml"); + if(matlabVersionFile.exists()) { + // If MTALB found at given location then just pull matlab-bacth and mpm executables. + getFreshCopyOfExecutables(installable, expectedPath); + } else { + // Cleanup before initial installation if last install was incomplete for any reason + performCleanup(expectedPath); + getFreshCopyOfExecutables(installable, expectedPath); + + // Create installation process + EnvVars env = node.toComputer().getEnvironment(); + Launcher matlabInstaller = node.createLauncher(log); + ProcStarter installerProc = matlabInstaller.launch(); + + ArgumentListBuilder args = new ArgumentListBuilder(); + args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); // can use installable here + args.add("install"); + args.add("--release=" + this.getVersion()); + args.add("--destination="+ expectedPath.getRemote()); + args.add(getMatlabProducts()); + installerProc.pwd(expectedPath) + .cmds(args) + .envs(env).stdout(log); + try{ + int result = installerProc.join(); + } catch (Exception e) { + throw new InstallationFailedException(e.getMessage()); + } + } + return new FilePath(node.getChannel(), expectedPath.getRemote()); + } + + private void performCleanup(FilePath preferedLocation) throws IOException, InterruptedException { + preferedLocation.deleteContents(); + } + private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) throws IOException, InterruptedException { + FilePath mpmPath = installable.getMpmInstallable(expectedPath); + FilePath mbatchPath = installable.getBatchInstallable(expectedPath); + mpmPath.copyFrom(new URL(installable.url)); + mpmPath.chmod(0777); + mbatchPath.copyFrom(new URL(installable.batchURL)); + mbatchPath.chmod(0777); + } + + private String getNodeSpecificMPMExecutor(Node node) { + final String osName; + if (node.toComputer().isUnix()) { + osName = "/mpm"; + } else { + osName = "\\mpm.exe"; + } + return osName; + } + + private String getMatlabProducts(){ + if(!this.getProducts().isEmpty()){ + return "--products=MATLAB "+ this.getProducts().trim(); + } else { + return "--products=MATLAB"; + } + } + + private Installable getInstallable(Node node) throws IOException, InterruptedException { + // Get the GMATLAB release version that we want to install + String release = this.getVersion();//this.id; + if (release == null) { + return null; + } + + // Gather properties for the node to install on + String[] properties = node.getChannel().call(new GetSystemProperties("os.name", "os.arch", "os.version")); + + // Get the best matching install candidate for this node + return getInstallCandidate(properties[0]); + } + + public MatlabInstallable getInstallCandidate(String osName) throws InstallationFailedException { + String platform = getPlatform(osName); + + return new MatlabInstallable(platform); + } + + private String getPlatform(String os) throws InstallationFailedException { + String value = os.toLowerCase(Locale.ENGLISH); + if (value.contains("linux")) { + return "glnxa64"; + } + if (value.contains("os x")) { + return "maci64"; + } + if (value.contains("windows")) { + return "win64"; + } + throw new InstallationFailedException("Unsupported OS"); + } + + @Extension + public static final class DescriptorImpl extends ToolInstallerDescriptor { + public String getDisplayName() { + return Message.getValue("matlab.tools.auto.install.display.name"); + } + + @Override + public boolean isApplicable(Class toolType) { + return toolType == MatlabInstallation.class; + } + } + + private class GetSystemProperties extends MasterToSlaveCallable { + private static final long serialVersionUID = 1L; + + private final String[] properties; + + GetSystemProperties(String... properties) { + this.properties = properties; + } + + public String[] call() { + String[] values = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + values[i] = System.getProperty(properties[i]); + } + return values; + } + } +} \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly new file mode 100644 index 00000000..3bb8e4a1 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index e64fa092..59b2a525 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -33,4 +33,6 @@ Axis.matlab.key = MATLAB Axis.use.matlab.warning = This project specifies MATLAB versions using the added 'MATLAB' axis as well as the 'Use MATLAB version' option. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. Axis.no.installed.matlab.error = Because no MATLAB versions exist under Jenkins Global Tool Configuration, the plugin will run the default matrix configuration. Use.matlab.version.axis.warning = This project specifies MATLAB versions using the 'Use MATLAB version' option as well as the added 'MATLAB' axis. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. +matlab.tools.auto.install.display.name = Install Using MPM +matlab.tools.auto.install.matlab.installable.error = MATLAB installer for the specific node could not be found From 16cdd596b75cf672e10129d284730e1296bc45db Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 3 Oct 2024 17:04:14 +0530 Subject: [PATCH 07/51] Added unit tests and updated the install logic --- .../mathworks/ci/tools/MatlabInstallable.java | 13 +- .../mathworks/ci/tools/MatlabInstaller.java | 113 +++++++++--------- src/main/resources/config.properties | 7 ++ .../ci/tools/MatlabInstallableUnitTest.java | 45 +++++++ .../ci/tools/MatlabInstallerUnitTest.java | 72 +++++++++++ src/test/resources/testconfig.properties | 9 +- 6 files changed, 194 insertions(+), 65 deletions(-) create mode 100644 src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java create mode 100644 src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index ef931e6d..1886afd5 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -1,6 +1,7 @@ package com.mathworks.ci.tools; +import com.mathworks.ci.Message; import hudson.FilePath; import hudson.tools.DownloadFromUrlInstaller.Installable; @@ -15,16 +16,16 @@ public MatlabInstallable(String osName) throws InstallationFailedException { this.osName = osName; switch (osName) { case "win64" : - this.url = "https://www.mathworks.com/mpm/win64/mpm"; - this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe"; + this.url = Message.getValue("tools.matlab.mpm.installer.win"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.win"); break; case "glnxa64" : - this.url = "https://www.mathworks.com/mpm/glnxa64/mpm"; - this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch"; + this.url = Message.getValue("tools.matlab.mpm.installer.linux"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.linux"); break; case "maci64" : - this.url = "https://www.mathworks.com/mpm/maci64/mpm"; - this.batchURL = "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch"; + this.url = Message.getValue("tools.matlab.mpm.installer.mac"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.mac"); break; default : throw new InstallationFailedException("Unsupported OS"); diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index df936f6f..70a02a2e 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -2,7 +2,6 @@ import com.mathworks.ci.MatlabInstallation; import com.mathworks.ci.Message; -import com.sun.akuma.CLibrary.FILE; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -14,7 +13,6 @@ import hudson.tools.ToolInstallation; import hudson.tools.ToolInstallerDescriptor; import hudson.util.ArgumentListBuilder; -import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Locale; @@ -47,12 +45,13 @@ public void setProducts(String products) { this.products = products; } + @Override public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath expectedPath = preferredLocation(tool, node); MatlabInstallable installable; try { installable = (MatlabInstallable) getInstallable(node); - } catch (InstallationFailedException e) { + } catch (Exception e) { throw new InstallationFailedException(e.getMessage()); } @@ -61,93 +60,91 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen return expectedPath; } - if (isUpToDate(expectedPath, installable)) { - return expectedPath; - } + getFreshCopyOfExecutables(installable, expectedPath); - FilePath matlabVersionFile = new FilePath(expectedPath, "VersionInfo.xml"); - if(matlabVersionFile.exists()) { - // If MTALB found at given location then just pull matlab-bacth and mpm executables. - getFreshCopyOfExecutables(installable, expectedPath); - } else { - // Cleanup before initial installation if last install was incomplete for any reason - performCleanup(expectedPath); - getFreshCopyOfExecutables(installable, expectedPath); - - // Create installation process - EnvVars env = node.toComputer().getEnvironment(); - Launcher matlabInstaller = node.createLauncher(log); - ProcStarter installerProc = matlabInstaller.launch(); - - ArgumentListBuilder args = new ArgumentListBuilder(); - args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); // can use installable here - args.add("install"); - args.add("--release=" + this.getVersion()); - args.add("--destination="+ expectedPath.getRemote()); - args.add(getMatlabProducts()); - installerProc.pwd(expectedPath) - .cmds(args) - .envs(env).stdout(log); - try{ - int result = installerProc.join(); - } catch (Exception e) { - throw new InstallationFailedException(e.getMessage()); - } + int result = installUsingMpm(node,expectedPath,log); + if(result == 0) { + log.getLogger().println("MATLAB installation for version " + this.getVersion() +" using mpm is completed successfully !"); } - return new FilePath(node.getChannel(), expectedPath.getRemote()); + return expectedPath; } - private void performCleanup(FilePath preferedLocation) throws IOException, InterruptedException { - preferedLocation.deleteContents(); + private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) + throws IOException, InterruptedException { + + // Create installation process + EnvVars env = node.toComputer().getEnvironment(); + Launcher matlabInstaller = node.createLauncher(log); + ProcStarter installerProc = matlabInstaller.launch(); + + ArgumentListBuilder args = new ArgumentListBuilder(); + args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); // can use installable here + args.add("install"); + args.add("--release=" + this.getVersion()); + args.add("--destination="+ expectedPath.getRemote()); + addMatlabProductsToArgs(args); + installerProc.pwd(expectedPath) + .cmds(args) + .envs(env).stdout(log); + int result; + try { + result = installerProc.join(); + } catch (Exception e) { + throw new InstallationFailedException(e.getMessage()); + } + return result; } + private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) throws IOException, InterruptedException { FilePath mpmPath = installable.getMpmInstallable(expectedPath); FilePath mbatchPath = installable.getBatchInstallable(expectedPath); - mpmPath.copyFrom(new URL(installable.url)); + mpmPath.copyFrom(new URL(installable.url).openStream()); mpmPath.chmod(0777); - mbatchPath.copyFrom(new URL(installable.batchURL)); + mbatchPath.copyFrom(new URL(installable.batchURL).openStream()); mbatchPath.chmod(0777); } private String getNodeSpecificMPMExecutor(Node node) { - final String osName; - if (node.toComputer().isUnix()) { - osName = "/mpm"; - } else { - osName = "\\mpm.exe"; - } - return osName; + final String osName; + if(node.toComputer().isUnix()){ + osName = "/mpm"; + } else { + osName = "\\mpm.exe"; + } + return osName; } - private String getMatlabProducts(){ + private void addMatlabProductsToArgs(ArgumentListBuilder args) { + args.add("--products"); if(!this.getProducts().isEmpty()){ - return "--products=MATLAB "+ this.getProducts().trim(); + args.add("MATLAB"); + String[] productList = this.getProducts().split(" "); + for(String prod:productList){ + args.add(prod); + } } else { - return "--products=MATLAB"; + args.add("MATLAB"); } } - private Installable getInstallable(Node node) throws IOException, InterruptedException { - // Get the GMATLAB release version that we want to install - String release = this.getVersion();//this.id; + public Installable getInstallable(Node node) throws IOException, InterruptedException { + // Get appropriate installable version for MATLAB. + String release = this.getVersion(); if (release == null) { return null; } // Gather properties for the node to install on String[] properties = node.getChannel().call(new GetSystemProperties("os.name", "os.arch", "os.version")); - - // Get the best matching install candidate for this node return getInstallCandidate(properties[0]); } public MatlabInstallable getInstallCandidate(String osName) throws InstallationFailedException { - String platform = getPlatform(osName); - - return new MatlabInstallable(platform); + String platform = getPlatform(osName); + return new MatlabInstallable(platform); } - private String getPlatform(String os) throws InstallationFailedException { + public String getPlatform(String os) throws InstallationFailedException { String value = os.toLowerCase(Locale.ENGLISH); if (value.contains("linux")) { return "glnxa64"; diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 59b2a525..4c797bea 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -36,3 +36,10 @@ Use.matlab.version.axis.warning = This project specifies MATLAB versions using t matlab.tools.auto.install.display.name = Install Using MPM matlab.tools.auto.install.matlab.installable.error = MATLAB installer for the specific node could not be found +tools.matlab.mpm.installer.win = https://www.mathworks.com/mpm/win64/mpm +tools.matlab.batch.executable.win = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe +tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm +tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch +tools.matlab.mpm.installer.mac = https://www.mathworks.com/mpm/maci64/mpm +tools.matlab.batch.executable.mac = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch + diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java new file mode 100644 index 00000000..912dd0e0 --- /dev/null +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java @@ -0,0 +1,45 @@ +package unit.com.mathworks.ci.tools; + +import static org.junit.Assert.assertEquals; + +import com.mathworks.ci.TestMessage; +import com.mathworks.ci.tools.InstallationFailedException; +import com.mathworks.ci.tools.MatlabInstallable; +import hudson.FilePath; +import java.io.File; +import org.junit.Test; + +public class MatlabInstallableUnitTest { + @Test + public void testValidWin64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("win64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.win"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.win"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("C:/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch.exe").getRemote(), installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm.exe").getRemote(), installable.getMpmInstallable(expectedPath).getRemote()); + } + + @Test + public void testValidGlnxa64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("glnxa64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.linux"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.linux"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("/usr/local/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm").getRemote(), installable.getMpmInstallable(expectedPath).getRemote()); + } + + @Test + public void testValidMaci64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("maci64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.mac"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.mac"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("/Applications/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm").getRemote(), installable.getMpmInstallable(expectedPath).getRemote()); + } +} diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java new file mode 100644 index 00000000..6bbee31c --- /dev/null +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -0,0 +1,72 @@ +package unit.com.mathworks.ci.tools; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import com.mathworks.ci.tools.InstallationFailedException; + +import com.mathworks.ci.tools.MatlabInstaller; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Node; +import hudson.model.TaskListener; +import hudson.tools.ToolInstallation; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + +public class MatlabInstallerUnitTest { + + private MatlabInstaller installer; + @Mock + private Node mockNode; + @Mock + private TaskListener mockListener; + @Mock + private ToolInstallation mockTool; + @Mock + private FilePath mockFilePath; + @Mock + private Launcher mockLauncher; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + installer = spy(new MatlabInstaller("test-id")); + installer.setVersion("R2021a"); + installer.setProducts("MATLAB"); + } + + @Test + public void testGetVersion() { + assertEquals("R2021a", installer.getVersion()); + } + + @Test + public void testGetProducts() { + assertEquals("MATLAB", installer.getProducts()); + } + + @Test + public void testPerformInstallation() throws Exception { + doReturn(mockFilePath).when(installer).performInstallation(mockTool, mockNode, mockListener); + + FilePath result = installer.performInstallation(mockTool, mockNode, mockListener); + assertNotNull(result); + } + + @Test(expected = InstallationFailedException.class) + public void testUnsupportedOS() throws Exception { + installer.getPlatform("unsupportedOS"); + } + + @Test + public void testGetPlatform() throws InstallationFailedException { + assertEquals("glnxa64", installer.getPlatform("Linux")); + assertEquals("maci64", installer.getPlatform("Mac OS X")); + assertEquals("win64", installer.getPlatform("Windows 10")); + } +} diff --git a/src/test/resources/testconfig.properties b/src/test/resources/testconfig.properties index 9a075b9e..d01de454 100644 --- a/src/test/resources/testconfig.properties +++ b/src/test/resources/testconfig.properties @@ -10,4 +10,11 @@ Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model cov Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release. Buildwrapper.display.name = Add MATLAB to PATH Builder.matlab.script.builder.display.name = Run MATLAB Command -Builder.build.builder.display.name = Run MATLAB Build \ No newline at end of file +Builder.build.builder.display.name = Run MATLAB Build + +tools.matlab.mpm.installer.win = https://www.mathworks.com/mpm/win64/mpm +tools.matlab.batch.executable.win = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe +tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm +tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch +tools.matlab.mpm.installer.mac = https://www.mathworks.com/mpm/maci64/mpm +tools.matlab.batch.executable.mac = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch \ No newline at end of file From 3e1bc0450459c2dabc878579a963b745383b9b41 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 3 Oct 2024 17:23:47 +0530 Subject: [PATCH 08/51] Updated test and seperated system properties --- .../mathworks/ci/tools/MatlabInstaller.java | 41 +++++++------------ .../ci/utilities/GetSystemProperties.java | 22 ++++++++++ .../ci/tools/MatlabInstallerUnitTest.java | 14 ++++--- 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 70a02a2e..07ccdd2c 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -2,6 +2,7 @@ import com.mathworks.ci.MatlabInstallation; import com.mathworks.ci.Message; +import com.mathworks.ci.utilities.GetSystemProperties; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -145,17 +146,21 @@ public MatlabInstallable getInstallCandidate(String osName) throws InstallationF } public String getPlatform(String os) throws InstallationFailedException { - String value = os.toLowerCase(Locale.ENGLISH); - if (value.contains("linux")) { - return "glnxa64"; - } - if (value.contains("os x")) { - return "maci64"; + if (os == null) { + throw new InstallationFailedException("OS cannot be null"); } - if (value.contains("windows")) { - return "win64"; + + String value = os.toLowerCase(Locale.ENGLISH); + switch (value) { + case "linux": + return "glnxa64"; + case "os x": + return "maci64"; + case "windows": + return "win64"; + default: + throw new InstallationFailedException("Unsupported OS"); } - throw new InstallationFailedException("Unsupported OS"); } @Extension @@ -169,22 +174,4 @@ public boolean isApplicable(Class toolType) { return toolType == MatlabInstallation.class; } } - - private class GetSystemProperties extends MasterToSlaveCallable { - private static final long serialVersionUID = 1L; - - private final String[] properties; - - GetSystemProperties(String... properties) { - this.properties = properties; - } - - public String[] call() { - String[] values = new String[properties.length]; - for (int i = 0; i < properties.length; i++) { - values[i] = System.getProperty(properties[i]); - } - return values; - } - } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java new file mode 100644 index 00000000..480d9d47 --- /dev/null +++ b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java @@ -0,0 +1,22 @@ +package com.mathworks.ci.utilities; + + +import jenkins.security.MasterToSlaveCallable; + +public class GetSystemProperties extends MasterToSlaveCallable { + private static final long serialVersionUID = 1L; + + private final String[] properties; + + public GetSystemProperties(String... properties) { + this.properties = properties; + } + + public String[] call() { + String[] values = new String[properties.length]; + for (int i = 0; i < properties.length; i++) { + values[i] = System.getProperty(properties[i]); + } + return values; + } +} diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 6bbee31c..538cfa8c 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -2,10 +2,12 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import com.mathworks.ci.tools.InstallationFailedException; - import com.mathworks.ci.tools.MatlabInstaller; + import hudson.FilePath; import hudson.Launcher; import hudson.model.Node; @@ -14,8 +16,8 @@ import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; + + public class MatlabInstallerUnitTest { @@ -65,8 +67,8 @@ public void testUnsupportedOS() throws Exception { @Test public void testGetPlatform() throws InstallationFailedException { - assertEquals("glnxa64", installer.getPlatform("Linux")); - assertEquals("maci64", installer.getPlatform("Mac OS X")); - assertEquals("win64", installer.getPlatform("Windows 10")); + assertEquals("glnxa64", installer.getPlatform("linux")); + assertEquals("maci64", installer.getPlatform("os x")); + assertEquals("win64", installer.getPlatform("windows")); } } From f85001e7eb4473c5b4f8de9cbc1fdbd1f87d6509 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 3 Oct 2024 17:56:51 +0530 Subject: [PATCH 09/51] Updated the logic --- .../mathworks/ci/tools/MatlabInstaller.java | 27 +++++++++---------- .../ci/tools/MatlabInstallerUnitTest.java | 6 ++--- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 07ccdd2c..ecbd4867 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -3,6 +3,7 @@ import com.mathworks.ci.MatlabInstallation; import com.mathworks.ci.Message; import com.mathworks.ci.utilities.GetSystemProperties; + import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -14,10 +15,11 @@ import hudson.tools.ToolInstallation; import hudson.tools.ToolInstallerDescriptor; import hudson.util.ArgumentListBuilder; + import java.io.IOException; import java.net.URL; import java.util.Locale; -import jenkins.security.MasterToSlaveCallable; + import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -79,7 +81,7 @@ private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) ProcStarter installerProc = matlabInstaller.launch(); ArgumentListBuilder args = new ArgumentListBuilder(); - args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); // can use installable here + args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); args.add("install"); args.add("--release=" + this.getVersion()); args.add("--destination="+ expectedPath.getRemote()); @@ -146,20 +148,15 @@ public MatlabInstallable getInstallCandidate(String osName) throws InstallationF } public String getPlatform(String os) throws InstallationFailedException { - if (os == null) { - throw new InstallationFailedException("OS cannot be null"); - } - String value = os.toLowerCase(Locale.ENGLISH); - switch (value) { - case "linux": - return "glnxa64"; - case "os x": - return "maci64"; - case "windows": - return "win64"; - default: - throw new InstallationFailedException("Unsupported OS"); + if (value.contains("linux")) { + return "glnxa64"; + } else if (value.contains("os x")){ + return "maci64"; + } else if (value.contains("windows")){ + return "win64"; + } else { + throw new InstallationFailedException("Unsupported OS"); } } diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 538cfa8c..0d255426 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -67,8 +67,8 @@ public void testUnsupportedOS() throws Exception { @Test public void testGetPlatform() throws InstallationFailedException { - assertEquals("glnxa64", installer.getPlatform("linux")); - assertEquals("maci64", installer.getPlatform("os x")); - assertEquals("win64", installer.getPlatform("windows")); + assertEquals("glnxa64", installer.getPlatform("Linux")); + assertEquals("maci64", installer.getPlatform("Mac OS X")); + assertEquals("win64", installer.getPlatform("Windows 10")); } } From 5a663c24d3cd85715c3ac5f6020c61e0ccf7eb44 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 4 Oct 2024 15:00:31 +0530 Subject: [PATCH 10/51] Added tests and refactored code --- .../ci/tools/InstallationFailedException.java | 3 +- .../mathworks/ci/tools/MatlabInstallable.java | 26 +++++++-------- .../mathworks/ci/tools/MatlabInstaller.java | 24 ++++++++++---- .../ci/utilities/GetSystemProperties.java | 5 ++- src/main/resources/config.properties | 1 + .../ci/tools/MatlabInstallableUnitTest.java | 18 ++++++---- .../ci/tools/MatlabInstallerUnitTest.java | 3 -- .../GetSystemPropertiesUnitTest.java | 33 +++++++++++++++++++ 8 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java index 863a2528..9aa86cc8 100644 --- a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -8,5 +8,4 @@ public class InstallationFailedException extends IOException { InstallationFailedException(String message) { super(message); } -} - +} \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index 1886afd5..a01b9b20 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -1,6 +1,5 @@ package com.mathworks.ci.tools; - import com.mathworks.ci.Message; import hudson.FilePath; import hudson.tools.DownloadFromUrlInstaller.Installable; @@ -12,36 +11,37 @@ public String getBatchURL() { public String batchURL; private String osName; + public MatlabInstallable(String osName) throws InstallationFailedException { this.osName = osName; switch (osName) { - case "win64" : + case "win64": this.url = Message.getValue("tools.matlab.mpm.installer.win"); this.batchURL = Message.getValue("tools.matlab.batch.executable.win"); break; - case "glnxa64" : - this.url = Message.getValue("tools.matlab.mpm.installer.linux"); + case "glnxa64": + this.url = Message.getValue("tools.matlab.mpm.installer.linux"); this.batchURL = Message.getValue("tools.matlab.batch.executable.linux"); break; - case "maci64" : - this.url = Message.getValue("tools.matlab.mpm.installer.mac"); + case "maci64": + this.url = Message.getValue("tools.matlab.mpm.installer.mac"); this.batchURL = Message.getValue("tools.matlab.batch.executable.mac"); break; - default : + default: throw new InstallationFailedException("Unsupported OS"); } } - public FilePath getBatchInstallable(FilePath expectedPath) { - if(this.osName == "win64"){ - return new FilePath(expectedPath,"matlab-batch.exe"); + public FilePath getBatchInstallable(FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath(expectedPath, "matlab-batch.exe"); } return new FilePath(expectedPath, "matlab-batch"); } - public FilePath getMpmInstallable(FilePath expectedPath) { - if(this.osName == "win64"){ - return new FilePath(expectedPath,"mpm.exe"); + public FilePath getMpmInstallable(FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath(expectedPath, "mpm.exe"); } return new FilePath(expectedPath, "mpm"); } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index ecbd4867..961b2bdb 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -18,8 +18,10 @@ import java.io.IOException; import java.net.URL; +import java.nio.charset.Charset; import java.util.Locale; +import org.apache.commons.io.IOUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -67,7 +69,7 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen int result = installUsingMpm(node,expectedPath,log); if(result == 0) { - log.getLogger().println("MATLAB installation for version " + this.getVersion() +" using mpm is completed successfully !"); + log.getLogger().println("MATLAB installation for version " + this.getRelease() +" using mpm is completed successfully !"); } return expectedPath; } @@ -83,7 +85,7 @@ private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) ArgumentListBuilder args = new ArgumentListBuilder(); args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); args.add("install"); - args.add("--release=" + this.getVersion()); + args.add("--release=" + this.getRelease()); args.add("--destination="+ expectedPath.getRemote()); addMatlabProductsToArgs(args); installerProc.pwd(expectedPath) @@ -98,6 +100,16 @@ private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) return result; } + private String getRelease() throws IOException { + String trimmedRelease = this.getVersion().trim(); + if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { + String getReleaseVersion = Message.getValue("matlab.release.info.url") + trimmedRelease; + String releaseVersion = IOUtils.toString(new URL(getReleaseVersion), Charset.defaultCharset()); + return releaseVersion.trim(); + } + return trimmedRelease; + } + private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) throws IOException, InterruptedException { FilePath mpmPath = installable.getMpmInstallable(expectedPath); FilePath mbatchPath = installable.getBatchInstallable(expectedPath); @@ -107,7 +119,7 @@ private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath e mbatchPath.chmod(0777); } - private String getNodeSpecificMPMExecutor(Node node) { + private String getNodeSpecificMPMExecutor(Node node) { final String osName; if(node.toComputer().isUnix()){ osName = "/mpm"; @@ -115,9 +127,9 @@ private String getNodeSpecificMPMExecutor(Node node) { osName = "\\mpm.exe"; } return osName; - } + } - private void addMatlabProductsToArgs(ArgumentListBuilder args) { + private void addMatlabProductsToArgs(ArgumentListBuilder args) { args.add("--products"); if(!this.getProducts().isEmpty()){ args.add("MATLAB"); @@ -128,7 +140,7 @@ private void addMatlabProductsToArgs(ArgumentListBuilder args) { } else { args.add("MATLAB"); } - } + } public Installable getInstallable(Node node) throws IOException, InterruptedException { // Get appropriate installable version for MATLAB. diff --git a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java index 480d9d47..c906b65b 100644 --- a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java +++ b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java @@ -1,6 +1,5 @@ package com.mathworks.ci.utilities; - import jenkins.security.MasterToSlaveCallable; public class GetSystemProperties extends MasterToSlaveCallable { @@ -8,7 +7,7 @@ public class GetSystemProperties extends MasterToSlaveCallable Date: Fri, 4 Oct 2024 18:24:50 +0530 Subject: [PATCH 11/51] Fixed spotbug issue --- .../ci/tools/InstallationFailedException.java | 6 +- .../mathworks/ci/tools/MatlabInstallable.java | 73 ++-- .../mathworks/ci/tools/MatlabInstaller.java | 316 +++++++++--------- .../ci/tools/MatlabInstallableUnitTest.java | 86 ++--- .../ci/tools/MatlabInstallerUnitTest.java | 91 ++--- .../GetSystemPropertiesUnitTest.java | 46 +-- 6 files changed, 313 insertions(+), 305 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java index 9aa86cc8..ab986942 100644 --- a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -5,7 +5,7 @@ // Extend IOException so we can throw and stop the build if installation fails public class InstallationFailedException extends IOException { - InstallationFailedException(String message) { - super(message); - } + InstallationFailedException(String message) { + super(message); + } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index a01b9b20..7d69be41 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -5,45 +5,44 @@ import hudson.tools.DownloadFromUrlInstaller.Installable; public class MatlabInstallable extends Installable { - public String getBatchURL() { - return this.batchURL; - } + public String getBatchURL() { + return this.batchURL; + } - public String batchURL; - private String osName; + public String batchURL; + private String osName; - public MatlabInstallable(String osName) throws InstallationFailedException { - this.osName = osName; - switch (osName) { - case "win64": - this.url = Message.getValue("tools.matlab.mpm.installer.win"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.win"); - break; - case "glnxa64": - this.url = Message.getValue("tools.matlab.mpm.installer.linux"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.linux"); - break; - case "maci64": - this.url = Message.getValue("tools.matlab.mpm.installer.mac"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.mac"); - break; - default: - throw new InstallationFailedException("Unsupported OS"); - } - } + public MatlabInstallable(String osName) throws InstallationFailedException { + this.osName = osName; + switch (osName) { + case "win64": + this.url = Message.getValue("tools.matlab.mpm.installer.win"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.win"); + break; + case "glnxa64": + this.url = Message.getValue("tools.matlab.mpm.installer.linux"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.linux"); + break; + case "maci64": + this.url = Message.getValue("tools.matlab.mpm.installer.mac"); + this.batchURL = Message.getValue("tools.matlab.batch.executable.mac"); + break; + default: + throw new InstallationFailedException("Unsupported OS"); + } + } - public FilePath getBatchInstallable(FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath(expectedPath, "matlab-batch.exe"); - } - return new FilePath(expectedPath, "matlab-batch"); - } - - public FilePath getMpmInstallable(FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath(expectedPath, "mpm.exe"); - } - return new FilePath(expectedPath, "mpm"); - } + public FilePath getBatchInstallable(FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath(expectedPath, "matlab-batch.exe"); + } + return new FilePath(expectedPath, "matlab-batch"); + } + public FilePath getMpmInstallable(FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath(expectedPath, "mpm.exe"); + } + return new FilePath(expectedPath, "mpm"); + } } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 961b2bdb..025f3b20 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -4,6 +4,7 @@ import com.mathworks.ci.Message; import com.mathworks.ci.utilities.GetSystemProperties; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -26,161 +27,162 @@ import org.kohsuke.stapler.DataBoundSetter; public class MatlabInstaller extends DownloadFromUrlInstaller { - private String version; - private String products; - - @DataBoundConstructor - public MatlabInstaller(String id) { - super(id); - } - - public String getVersion(){ - return this.version; - } - - @DataBoundSetter - public void setVersion(String version) { - this.version = version; - } - - public String getProducts() { return this.products; } - - @DataBoundSetter - public void setProducts(String products) { - this.products = products; - } - - @Override - public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { - FilePath expectedPath = preferredLocation(tool, node); - MatlabInstallable installable; - try { - installable = (MatlabInstallable) getInstallable(node); - } catch (Exception e) { - throw new InstallationFailedException(e.getMessage()); - } - - if (installable == null) { - log.getLogger().println(Message.getValue("matlab.tools.auto.install.matlab.installable.error")); - return expectedPath; - } - - getFreshCopyOfExecutables(installable, expectedPath); - - int result = installUsingMpm(node,expectedPath,log); - if(result == 0) { - log.getLogger().println("MATLAB installation for version " + this.getRelease() +" using mpm is completed successfully !"); - } - return expectedPath; - } - - private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) - throws IOException, InterruptedException { - - // Create installation process - EnvVars env = node.toComputer().getEnvironment(); - Launcher matlabInstaller = node.createLauncher(log); - ProcStarter installerProc = matlabInstaller.launch(); - - ArgumentListBuilder args = new ArgumentListBuilder(); - args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); - args.add("install"); - args.add("--release=" + this.getRelease()); - args.add("--destination="+ expectedPath.getRemote()); - addMatlabProductsToArgs(args); - installerProc.pwd(expectedPath) - .cmds(args) - .envs(env).stdout(log); - int result; - try { - result = installerProc.join(); - } catch (Exception e) { - throw new InstallationFailedException(e.getMessage()); - } - return result; - } - - private String getRelease() throws IOException { - String trimmedRelease = this.getVersion().trim(); - if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { - String getReleaseVersion = Message.getValue("matlab.release.info.url") + trimmedRelease; - String releaseVersion = IOUtils.toString(new URL(getReleaseVersion), Charset.defaultCharset()); - return releaseVersion.trim(); - } - return trimmedRelease; - } - - private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) throws IOException, InterruptedException { - FilePath mpmPath = installable.getMpmInstallable(expectedPath); - FilePath mbatchPath = installable.getBatchInstallable(expectedPath); - mpmPath.copyFrom(new URL(installable.url).openStream()); - mpmPath.chmod(0777); - mbatchPath.copyFrom(new URL(installable.batchURL).openStream()); - mbatchPath.chmod(0777); - } - - private String getNodeSpecificMPMExecutor(Node node) { - final String osName; - if(node.toComputer().isUnix()){ - osName = "/mpm"; - } else { - osName = "\\mpm.exe"; - } - return osName; - } - - private void addMatlabProductsToArgs(ArgumentListBuilder args) { - args.add("--products"); - if(!this.getProducts().isEmpty()){ - args.add("MATLAB"); - String[] productList = this.getProducts().split(" "); - for(String prod:productList){ - args.add(prod); - } - } else { - args.add("MATLAB"); - } - } - - public Installable getInstallable(Node node) throws IOException, InterruptedException { - // Get appropriate installable version for MATLAB. - String release = this.getVersion(); - if (release == null) { - return null; - } - - // Gather properties for the node to install on - String[] properties = node.getChannel().call(new GetSystemProperties("os.name", "os.arch", "os.version")); - return getInstallCandidate(properties[0]); - } - - public MatlabInstallable getInstallCandidate(String osName) throws InstallationFailedException { - String platform = getPlatform(osName); - return new MatlabInstallable(platform); - } - - public String getPlatform(String os) throws InstallationFailedException { - String value = os.toLowerCase(Locale.ENGLISH); - if (value.contains("linux")) { - return "glnxa64"; - } else if (value.contains("os x")){ - return "maci64"; - } else if (value.contains("windows")){ - return "win64"; - } else { - throw new InstallationFailedException("Unsupported OS"); - } - } - - @Extension - public static final class DescriptorImpl extends ToolInstallerDescriptor { - public String getDisplayName() { - return Message.getValue("matlab.tools.auto.install.display.name"); - } - - @Override - public boolean isApplicable(Class toolType) { - return toolType == MatlabInstallation.class; - } - } + private String version; + private String products; + + @DataBoundConstructor + public MatlabInstaller(String id) { + super(id); + } + + public String getVersion() { + return this.version; + } + + @DataBoundSetter + public void setVersion(String version) { + this.version = version; + } + + public String getProducts() { + return this.products; + } + + @DataBoundSetter + public void setProducts(String products) { + this.products = products; + } + + @Override + public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) + throws IOException, InterruptedException { + FilePath expectedPath = preferredLocation(tool, node); + MatlabInstallable installable; + try { + installable = (MatlabInstallable) getInstallable(node); + } catch (Exception e) { + throw new InstallationFailedException(e.getMessage()); + } + + /*if (installable == null) { + log.getLogger().println(Message.getValue("matlab.tools.auto.install.matlab.installable.error")); + return expectedPath; + }*/ + + getFreshCopyOfExecutables(installable, expectedPath); + + int result = installUsingMpm(node, expectedPath, log); + if (result == 0) { + log.getLogger().println( + "MATLAB installation for version " + this.getRelease() + " using mpm is completed successfully !"); + } + return expectedPath; + } + + private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) + throws IOException, InterruptedException { + + // Create installation process + //EnvVars env = node.toComputer().getEnvironment(); + Launcher matlabInstaller = node.createLauncher(log); + ProcStarter installerProc = matlabInstaller.launch(); + + ArgumentListBuilder args = new ArgumentListBuilder(); + args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); + args.add("install"); + args.add("--release=" + this.getRelease()); + args.add("--destination=" + expectedPath.getRemote()); + addMatlabProductsToArgs(args); + installerProc.pwd(expectedPath).cmds(args).stdout(log); + int result; + try { + result = installerProc.join(); + } catch (Exception e) { + throw new InstallationFailedException(e.getMessage()); + } + return result; + } + + private String getRelease() throws IOException { + String trimmedRelease = this.getVersion().trim(); + if (trimmedRelease.equalsIgnoreCase("latest") + || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { + String getReleaseVersion = Message.getValue("matlab.release.info.url") + trimmedRelease; + String releaseVersion = IOUtils.toString(new URL(getReleaseVersion), Charset.defaultCharset()); + return releaseVersion.trim(); + } + return trimmedRelease; + } + + private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) + throws IOException, InterruptedException { + FilePath mpmPath = installable.getMpmInstallable(expectedPath); + FilePath mbatchPath = installable.getBatchInstallable(expectedPath); + mpmPath.copyFrom(new URL(installable.url).openStream()); + mpmPath.chmod(0777); + mbatchPath.copyFrom(new URL(installable.batchURL).openStream()); + mbatchPath.chmod(0777); + } + + @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, + justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") + private String getNodeSpecificMPMExecutor(Node node) { + if (!node.toComputer().isUnix()) { + return "\\mpm.exe"; + } + return "/mpm"; + } + + private void addMatlabProductsToArgs(ArgumentListBuilder args) { + args.add("--products"); + if (!this.getProducts().isEmpty()) { + args.add("MATLAB"); + String[] productList = this.getProducts().split(" "); + for (String prod : productList) { + args.add(prod); + } + } else { + args.add("MATLAB"); + } + } + + @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, + justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") + public Installable getInstallable(Node node) throws IOException, InterruptedException { + // Gather properties for the node to install on + String[] properties = node.getChannel().call(new GetSystemProperties("os.name", "os.arch", "os.version")); + return getInstallCandidate(properties[0]); + } + + public MatlabInstallable getInstallCandidate(String osName) throws InstallationFailedException { + String platform = getPlatform(osName); + return new MatlabInstallable(platform); + } + + public String getPlatform(String os) throws InstallationFailedException { + String value = os.toLowerCase(Locale.ENGLISH); + if (value.contains("linux")) { + return "glnxa64"; + } else if (value.contains("os x")) { + return "maci64"; + } else if (value.contains("windows")) { + return "win64"; + } else { + throw new InstallationFailedException("Unsupported OS"); + } + } + + @Extension + public static final class DescriptorImpl extends ToolInstallerDescriptor { + public String getDisplayName() { + return Message.getValue("matlab.tools.auto.install.display.name"); + } + + @Override + public boolean isApplicable(Class toolType) { + return toolType == MatlabInstallation.class; + } + } } \ No newline at end of file diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java index 1b7b6560..d09cf83c 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java @@ -1,51 +1,51 @@ -package unit.com.mathworks.ci.tools; +package com.mathworks.ci.tools; import static org.junit.Assert.assertEquals; -import com.mathworks.ci.TestMessage; -import com.mathworks.ci.tools.InstallationFailedException; -import com.mathworks.ci.tools.MatlabInstallable; -import hudson.FilePath; import java.io.File; + import org.junit.Test; +import hudson.FilePath; +import com.mathworks.ci.TestMessage; + public class MatlabInstallableUnitTest { - @Test - public void testValidWin64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("win64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.win"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.win"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("C:/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch.exe").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm.exe").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } - - @Test - public void testValidGlnxa64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("glnxa64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.linux"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.linux"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("/usr/local/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } - - @Test - public void testValidMaci64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("maci64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.mac"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.mac"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("/Applications/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } + @Test + public void testValidWin64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("win64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.win"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.win"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("C:/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch.exe").getRemote(), + installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm.exe").getRemote(), + installable.getMpmInstallable(expectedPath).getRemote()); + } + + @Test + public void testValidGlnxa64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("glnxa64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.linux"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.linux"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("/usr/local/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), + installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm").getRemote(), + installable.getMpmInstallable(expectedPath).getRemote()); + } + + @Test + public void testValidMaci64OS() throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable("maci64"); + assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.mac"), installable.url); + assertEquals(TestMessage.getValue("tools.matlab.batch.executable.mac"), installable.getBatchURL()); + + FilePath expectedPath = new FilePath(new File("/Applications/install")); + assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), + installable.getBatchInstallable(expectedPath).getRemote()); + assertEquals(new FilePath(expectedPath, "mpm").getRemote(), + installable.getMpmInstallable(expectedPath).getRemote()); + } } diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 289e8afe..6fcd9db1 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -1,4 +1,4 @@ -package unit.com.mathworks.ci.tools; +package com.mathworks.ci.tools; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -19,53 +19,58 @@ public class MatlabInstallerUnitTest { - private MatlabInstaller installer; - @Mock - private Node mockNode; - @Mock - private TaskListener mockListener; - @Mock - private ToolInstallation mockTool; - @Mock - private FilePath mockFilePath; - @Mock - private Launcher mockLauncher; + private MatlabInstaller installer; + + @Mock + private Node mockNode; + + @Mock + private TaskListener mockListener; + + @Mock + private ToolInstallation mockTool; + + @Mock + private FilePath mockFilePath; + + @Mock + private Launcher mockLauncher; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - installer = spy(new MatlabInstaller("test-id")); - installer.setVersion("R2021a"); - installer.setProducts("MATLAB"); - } + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + installer = spy(new MatlabInstaller("test-id")); + installer.setVersion("R2021a"); + installer.setProducts("MATLAB"); + } - @Test - public void testGetVersion() { - assertEquals("R2021a", installer.getVersion()); - } + @Test + public void testGetVersion() { + assertEquals("R2021a", installer.getVersion()); + } - @Test - public void testGetProducts() { - assertEquals("MATLAB", installer.getProducts()); - } + @Test + public void testGetProducts() { + assertEquals("MATLAB", installer.getProducts()); + } - @Test - public void testPerformInstallation() throws Exception { - doReturn(mockFilePath).when(installer).performInstallation(mockTool, mockNode, mockListener); + @Test + public void testPerformInstallation() throws Exception { + doReturn(mockFilePath).when(installer).performInstallation(mockTool, mockNode, mockListener); - FilePath result = installer.performInstallation(mockTool, mockNode, mockListener); - assertNotNull(result); - } + FilePath result = installer.performInstallation(mockTool, mockNode, mockListener); + assertNotNull(result); + } - @Test(expected = InstallationFailedException.class) - public void testUnsupportedOS() throws Exception { - installer.getPlatform("unsupportedOS"); - } + @Test(expected = InstallationFailedException.class) + public void testUnsupportedOS() throws Exception { + installer.getPlatform("unsupportedOS"); + } - @Test - public void testGetPlatform() throws InstallationFailedException { - assertEquals("glnxa64", installer.getPlatform("Linux")); - assertEquals("maci64", installer.getPlatform("Mac OS X")); - assertEquals("win64", installer.getPlatform("Windows 10")); - } + @Test + public void testGetPlatform() throws InstallationFailedException { + assertEquals("glnxa64", installer.getPlatform("Linux")); + assertEquals("maci64", installer.getPlatform("Mac OS X")); + assertEquals("win64", installer.getPlatform("Windows 10")); + } } diff --git a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java index 2c05cd41..c0e7f908 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java @@ -1,33 +1,35 @@ -package unit.com.mathworks.ci.utilities; +package com.mathworks.ci.utilities; import static org.junit.Assert.assertArrayEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; -import com.mathworks.ci.utilities.GetSystemProperties; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import com.mathworks.ci.utilities.GetSystemProperties; + public class GetSystemPropertiesUnitTest { - @Mock - private GetSystemProperties getSystemProperties; - - @Before - public void setUp() { - // Initialize with the properties - getSystemProperties = spy(new GetSystemProperties("os.name", "os.arch", "os.version")); - } - - @Test - public void testCall() { - doReturn(new String[] { "MockOS", "MockArch", "MockVersion" }).when(getSystemProperties).call(); - - // Call the method under test - String[] result = getSystemProperties.call(); - - // Define the expected result - String[] expected = { "MockOS", "MockArch", "MockVersion" }; - assertArrayEquals(expected, result); - } + + @Mock + private GetSystemProperties getSystemProperties; + + @Before + public void setUp() { + // Initialize with the properties + getSystemProperties = spy(new GetSystemProperties("os.name", "os.arch", "os.version")); + } + + @Test + public void testCall() { + doReturn(new String[] { "MockOS", "MockArch", "MockVersion" }).when(getSystemProperties).call(); + + // Call the method under test + String[] result = getSystemProperties.call(); + + // Define the expected result + String[] expected = { "MockOS", "MockArch", "MockVersion" }; + assertArrayEquals(expected, result); + } } From 64fd16d967856c7413595c4757ed54b3ec1e2edb Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 7 Oct 2024 11:55:59 +0530 Subject: [PATCH 12/51] Updated Mockito version --- pom.xml | 7 ++++++- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 6 ------ src/main/resources/config.properties | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index bd7c8387..57839d63 100644 --- a/pom.xml +++ b/pom.xml @@ -104,9 +104,14 @@ org.mockito mockito-core - 3.1.0 + 4.0.0 test + + org.objenesis + objenesis + 3.3 + diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 025f3b20..7bfa3b01 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -63,12 +63,6 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen } catch (Exception e) { throw new InstallationFailedException(e.getMessage()); } - - /*if (installable == null) { - log.getLogger().println(Message.getValue("matlab.tools.auto.install.matlab.installable.error")); - return expectedPath; - }*/ - getFreshCopyOfExecutables(installable, expectedPath); int result = installUsingMpm(node, expectedPath, log); diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 8da5bafb..4465bf22 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -34,7 +34,6 @@ Axis.use.matlab.warning = This project specifies MATLAB versions using the added Axis.no.installed.matlab.error = Because no MATLAB versions exist under Jenkins Global Tool Configuration, the plugin will run the default matrix configuration. Use.matlab.version.axis.warning = This project specifies MATLAB versions using the 'Use MATLAB version' option as well as the added 'MATLAB' axis. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. matlab.tools.auto.install.display.name = Install Using MPM -matlab.tools.auto.install.matlab.installable.error = MATLAB installer for the specific node could not be found tools.matlab.mpm.installer.win = https://www.mathworks.com/mpm/win64/mpm tools.matlab.batch.executable.win = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe From fbb631f8f81afa9a7d83ed9743261b8c1474cc22 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 7 Oct 2024 12:26:14 +0530 Subject: [PATCH 13/51] Updated buddy bytes version --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 57839d63..7863cacc 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,11 @@ org.objenesis objenesis 3.3 + + + net.bytebuddy + byte-buddy-maven-plugin + 1.15.3 From f57d86db575b05ef028c2e65109897bf4b847edf Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 7 Oct 2024 14:11:27 +0530 Subject: [PATCH 14/51] Updated azure pipeline for java version --- azure-pipelines.yml | 6 ++++++ pom.xml | 12 +----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 30ae949c..afd10b7a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -19,6 +19,12 @@ trigger: - master steps: + - task: JavaToolInstaller@0 + inputs: + versionSpec: '11' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' + - task: Maven@4 inputs: mavenPomFile: 'pom.xml' diff --git a/pom.xml b/pom.xml index 7863cacc..bd7c8387 100644 --- a/pom.xml +++ b/pom.xml @@ -104,19 +104,9 @@ org.mockito mockito-core - 4.0.0 + 3.1.0 test - - org.objenesis - objenesis - 3.3 - - - net.bytebuddy - byte-buddy-maven-plugin - 1.15.3 - From 8dd2c696db1af34bc7e0c1999b853dda66215623 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 7 Oct 2024 15:06:02 +0530 Subject: [PATCH 15/51] Added help icons for Version & products --- .../ci/tools/MatlabInstaller/help-products.html | 15 +++++++++++++++ .../ci/tools/MatlabInstaller/help-version.html | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html create mode 100644 src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html new file mode 100644 index 00000000..88dcda56 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html @@ -0,0 +1,15 @@ +
+

+ (Optional) Products to set up in addition to MATLAB, specified as a list of product names separated by spaces. + You can specify products to set up most MathWorks products and support packages. +

+

+ For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. + Specify products using the format shown in the input file, excluding the #product. prefix. +

+

+ Example: to set up Deep Learning Toolbox™ in addition to MATLAB, + specify products: Deep_Learning_Toolbox +

> + Note: MATLAB is selected by default if text box is blank or no products specified. +
\ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html new file mode 100644 index 00000000..ab9e7661 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html @@ -0,0 +1,14 @@ +
+

+ Enter the MATLAB version to be installed. For update versions, append the appropriate update number to the MATLAB version. +

+

+ Example: R2024a or R2024aU1 + Example: For latest MATLAB release just provide latest as version. +

+

+ Note: If the installation host is Linux, you may need to install some + dependencies + before installing MATLAB using MPM. +

+
\ No newline at end of file From 2062e3208d659d138bf933371d3f8a0ebebca489 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 10:53:18 +0530 Subject: [PATCH 16/51] Updated the help files --- .../mathworks/ci/tools/MatlabInstaller.java | 45 ++++++++++++------- .../tools/MatlabInstaller/help-products.html | 4 +- .../tools/MatlabInstaller/help-version.html | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 7bfa3b01..3260f2c0 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -5,7 +5,7 @@ import com.mathworks.ci.utilities.GetSystemProperties; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import hudson.EnvVars; + import hudson.Extension; import hudson.FilePath; import hudson.Launcher; @@ -19,10 +19,11 @@ import java.io.IOException; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Locale; import org.apache.commons.io.IOUtils; + import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -68,23 +69,21 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen int result = installUsingMpm(node, expectedPath, log); if (result == 0) { log.getLogger().println( - "MATLAB installation for version " + this.getRelease() + " using mpm is completed successfully !"); + "MATLAB installation for version " + this.getVersion() + " using mpm is completed successfully !"); } return expectedPath; } private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) - throws IOException, InterruptedException { + throws IOException { - // Create installation process - //EnvVars env = node.toComputer().getEnvironment(); Launcher matlabInstaller = node.createLauncher(log); ProcStarter installerProc = matlabInstaller.launch(); ArgumentListBuilder args = new ArgumentListBuilder(); args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); args.add("install"); - args.add("--release=" + this.getRelease()); + appendReleaseToArguments(args); args.add("--destination=" + expectedPath.getRemote()); addMatlabProductsToArgs(args); installerProc.pwd(expectedPath).cmds(args).stdout(log); @@ -97,16 +96,28 @@ private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) return result; } - private String getRelease() throws IOException { - String trimmedRelease = this.getVersion().trim(); - if (trimmedRelease.equalsIgnoreCase("latest") - || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { - String getReleaseVersion = Message.getValue("matlab.release.info.url") + trimmedRelease; - String releaseVersion = IOUtils.toString(new URL(getReleaseVersion), Charset.defaultCharset()); - return releaseVersion.trim(); - } - return trimmedRelease; - } + private void appendReleaseToArguments(ArgumentListBuilder args) { + try { + String trimmedRelease = this.getVersion().trim(); + String actualRelease = trimmedRelease; + + if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { + String releaseInfoUrl = Message.getValue("matlab.release.info.url") + trimmedRelease; + String releaseVersion = IOUtils.toString(new URL(releaseInfoUrl), StandardCharsets.UTF_8).trim(); + + if (releaseVersion.contains("prerelease")) { + actualRelease = releaseVersion.replace("prerelease", ""); + args.add("--release-status=Prerelease"); + } else { + actualRelease = releaseVersion; + } + } + args.add("--release=" + actualRelease); + } catch (IOException e) { + System.err.println("Failed to fetch release version: " + e.getMessage()); + + } + } private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) throws IOException, InterruptedException { diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html index 88dcda56..96d20cc0 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html @@ -4,12 +4,12 @@ You can specify products to set up most MathWorks products and support packages.

- For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. + For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. Specify products using the format shown in the input file, excluding the #product. prefix.

Example: to set up Deep Learning Toolbox™ in addition to MATLAB, specify products: Deep_Learning_Toolbox -

> +

Note: MATLAB is selected by default if text box is blank or no products specified. \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html index ab9e7661..4761468f 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html @@ -3,7 +3,7 @@ Enter the MATLAB version to be installed. For update versions, append the appropriate update number to the MATLAB version.

- Example: R2024a or R2024aU1 + Example: R2024a or R2024aU1
Example: For latest MATLAB release just provide latest as version.

From c1ef42b10a952eb23d8b5d2c3ef5ba7b717494f1 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 11:48:06 +0530 Subject: [PATCH 17/51] Updated Indentation --- .../ci/tools/InstallationFailedException.java | 7 +- .../mathworks/ci/tools/MatlabInstallable.java | 72 ++--- .../mathworks/ci/tools/MatlabInstaller.java | 298 +++++++++--------- .../ci/utilities/GetSystemProperties.java | 7 +- 4 files changed, 198 insertions(+), 186 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java index ab986942..3be8df22 100644 --- a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -5,7 +5,8 @@ // Extend IOException so we can throw and stop the build if installation fails public class InstallationFailedException extends IOException { - InstallationFailedException(String message) { - super(message); - } + + InstallationFailedException (String message) { + super (message); + } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index 7d69be41..64173dd2 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -5,44 +5,44 @@ import hudson.tools.DownloadFromUrlInstaller.Installable; public class MatlabInstallable extends Installable { - public String getBatchURL() { - return this.batchURL; - } - public String batchURL; - private String osName; + public String batchURL; + private String osName; + public MatlabInstallable (String osName) throws InstallationFailedException { + this.osName = osName; + switch (osName) { + case "win64": + this.url = Message.getValue ("tools.matlab.mpm.installer.win"); + this.batchURL = Message.getValue ("tools.matlab.batch.executable.win"); + break; + case "glnxa64": + this.url = Message.getValue ("tools.matlab.mpm.installer.linux"); + this.batchURL = Message.getValue ("tools.matlab.batch.executable.linux"); + break; + case "maci64": + this.url = Message.getValue ("tools.matlab.mpm.installer.mac"); + this.batchURL = Message.getValue ("tools.matlab.batch.executable.mac"); + break; + default: + throw new InstallationFailedException ("Unsupported OS"); + } + } - public MatlabInstallable(String osName) throws InstallationFailedException { - this.osName = osName; - switch (osName) { - case "win64": - this.url = Message.getValue("tools.matlab.mpm.installer.win"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.win"); - break; - case "glnxa64": - this.url = Message.getValue("tools.matlab.mpm.installer.linux"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.linux"); - break; - case "maci64": - this.url = Message.getValue("tools.matlab.mpm.installer.mac"); - this.batchURL = Message.getValue("tools.matlab.batch.executable.mac"); - break; - default: - throw new InstallationFailedException("Unsupported OS"); - } - } + public String getBatchURL () { + return this.batchURL; + } - public FilePath getBatchInstallable(FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath(expectedPath, "matlab-batch.exe"); - } - return new FilePath(expectedPath, "matlab-batch"); - } + public FilePath getBatchInstallable (FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath (expectedPath, "matlab-batch.exe"); + } + return new FilePath (expectedPath, "matlab-batch"); + } - public FilePath getMpmInstallable(FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath(expectedPath, "mpm.exe"); - } - return new FilePath(expectedPath, "mpm"); - } + public FilePath getMpmInstallable (FilePath expectedPath) { + if (this.osName == "win64") { + return new FilePath (expectedPath, "mpm.exe"); + } + return new FilePath (expectedPath, "mpm"); + } } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 3260f2c0..c77edd65 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -28,166 +28,176 @@ import org.kohsuke.stapler.DataBoundSetter; public class MatlabInstaller extends DownloadFromUrlInstaller { - private String version; - private String products; - - @DataBoundConstructor - public MatlabInstaller(String id) { - super(id); - } - - public String getVersion() { - return this.version; - } - - @DataBoundSetter - public void setVersion(String version) { - this.version = version; - } - - public String getProducts() { - return this.products; - } - - @DataBoundSetter - public void setProducts(String products) { - this.products = products; - } - - @Override - public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) - throws IOException, InterruptedException { - FilePath expectedPath = preferredLocation(tool, node); - MatlabInstallable installable; - try { - installable = (MatlabInstallable) getInstallable(node); - } catch (Exception e) { - throw new InstallationFailedException(e.getMessage()); - } - getFreshCopyOfExecutables(installable, expectedPath); - - int result = installUsingMpm(node, expectedPath, log); - if (result == 0) { - log.getLogger().println( - "MATLAB installation for version " + this.getVersion() + " using mpm is completed successfully !"); - } - return expectedPath; - } - - private int installUsingMpm(Node node, FilePath expectedPath, TaskListener log) - throws IOException { - - Launcher matlabInstaller = node.createLauncher(log); - ProcStarter installerProc = matlabInstaller.launch(); - - ArgumentListBuilder args = new ArgumentListBuilder(); - args.add(expectedPath.getRemote() + getNodeSpecificMPMExecutor(node)); - args.add("install"); - appendReleaseToArguments(args); - args.add("--destination=" + expectedPath.getRemote()); - addMatlabProductsToArgs(args); - installerProc.pwd(expectedPath).cmds(args).stdout(log); - int result; - try { - result = installerProc.join(); - } catch (Exception e) { - throw new InstallationFailedException(e.getMessage()); - } - return result; - } - - private void appendReleaseToArguments(ArgumentListBuilder args) { + + private String version; + private String products; + + @DataBoundConstructor + public MatlabInstaller (String id) { + super (id); + } + + public String getVersion () { + return this.version; + } + + @DataBoundSetter + public void setVersion (String version) { + this.version = version; + } + + public String getProducts () { + return this.products; + } + + @DataBoundSetter + public void setProducts (String products) { + this.products = products; + } + + @Override + public FilePath performInstallation (ToolInstallation tool, Node node, TaskListener log) + throws IOException, InterruptedException { + FilePath expectedPath = preferredLocation (tool, node); + MatlabInstallable installable; try { - String trimmedRelease = this.getVersion().trim(); + installable = (MatlabInstallable) getInstallable (node); + } catch (Exception e) { + throw new InstallationFailedException (e.getMessage ()); + } + getFreshCopyOfExecutables (installable, expectedPath); + + int result = installUsingMpm (node, expectedPath, log); + if (result == 0) { + log.getLogger ().println ( + "MATLAB installation for version " + this.getVersion () + + " using mpm is completed successfully !"); + } + return expectedPath; + } + + private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) + throws IOException { + + Launcher matlabInstaller = node.createLauncher (log); + ProcStarter installerProc = matlabInstaller.launch (); + + ArgumentListBuilder args = new ArgumentListBuilder (); + args.add (expectedPath.getRemote () + getNodeSpecificMPMExecutor (node)); + args.add ("install"); + appendReleaseToArguments (args); + args.add ("--destination=" + expectedPath.getRemote ()); + addMatlabProductsToArgs (args); + installerProc.pwd (expectedPath).cmds (args).stdout (log); + int result; + try { + result = installerProc.join (); + } catch (Exception e) { + throw new InstallationFailedException (e.getMessage ()); + } + return result; + } + + private void appendReleaseToArguments (ArgumentListBuilder args) { + try { + String trimmedRelease = this.getVersion ().trim (); String actualRelease = trimmedRelease; - if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase("latest-including-prerelease")) { - String releaseInfoUrl = Message.getValue("matlab.release.info.url") + trimmedRelease; - String releaseVersion = IOUtils.toString(new URL(releaseInfoUrl), StandardCharsets.UTF_8).trim(); + if (trimmedRelease.equalsIgnoreCase ("latest") || trimmedRelease.equalsIgnoreCase ( + "latest-including-prerelease")) { + String releaseInfoUrl = + Message.getValue ("matlab.release.info.url") + trimmedRelease; + String releaseVersion = IOUtils.toString (new URL (releaseInfoUrl), + StandardCharsets.UTF_8).trim (); - if (releaseVersion.contains("prerelease")) { - actualRelease = releaseVersion.replace("prerelease", ""); - args.add("--release-status=Prerelease"); + if (releaseVersion.contains ("prerelease")) { + actualRelease = releaseVersion.replace ("prerelease", ""); + args.add ("--release-status=Prerelease"); } else { actualRelease = releaseVersion; } } - args.add("--release=" + actualRelease); + args.add ("--release=" + actualRelease); } catch (IOException e) { - System.err.println("Failed to fetch release version: " + e.getMessage()); + System.err.println ("Failed to fetch release version: " + e.getMessage ()); } } - private void getFreshCopyOfExecutables(MatlabInstallable installable, FilePath expectedPath) - throws IOException, InterruptedException { - FilePath mpmPath = installable.getMpmInstallable(expectedPath); - FilePath mbatchPath = installable.getBatchInstallable(expectedPath); - mpmPath.copyFrom(new URL(installable.url).openStream()); - mpmPath.chmod(0777); - mbatchPath.copyFrom(new URL(installable.batchURL).openStream()); - mbatchPath.chmod(0777); - } + private void getFreshCopyOfExecutables (MatlabInstallable installable, FilePath expectedPath) + throws IOException, InterruptedException { + FilePath mpmPath = installable.getMpmInstallable (expectedPath); + FilePath mbatchPath = installable.getBatchInstallable (expectedPath); + mpmPath.copyFrom (new URL (installable.url).openStream ()); + mpmPath.chmod (0777); + mbatchPath.copyFrom (new URL (installable.batchURL).openStream ()); + mbatchPath.chmod (0777); + } @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, - justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " - + "https://github.com/spotbugs/spotbugs/issues/1843") - private String getNodeSpecificMPMExecutor(Node node) { - if (!node.toComputer().isUnix()) { + justification = + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") + private String getNodeSpecificMPMExecutor (Node node) { + if (!node.toComputer ().isUnix ()) { return "\\mpm.exe"; - } - return "/mpm"; - } - - private void addMatlabProductsToArgs(ArgumentListBuilder args) { - args.add("--products"); - if (!this.getProducts().isEmpty()) { - args.add("MATLAB"); - String[] productList = this.getProducts().split(" "); - for (String prod : productList) { - args.add(prod); - } - } else { - args.add("MATLAB"); - } - } + } + return "/mpm"; + } + + private void addMatlabProductsToArgs (ArgumentListBuilder args) { + args.add ("--products"); + if (!this.getProducts ().isEmpty ()) { + args.add ("MATLAB"); + String[] productList = this.getProducts ().split (" "); + for (String prod : productList) { + args.add (prod); + } + } else { + args.add ("MATLAB"); + } + } @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, - justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " - + "https://github.com/spotbugs/spotbugs/issues/1843") - public Installable getInstallable(Node node) throws IOException, InterruptedException { - // Gather properties for the node to install on - String[] properties = node.getChannel().call(new GetSystemProperties("os.name", "os.arch", "os.version")); - return getInstallCandidate(properties[0]); - } - - public MatlabInstallable getInstallCandidate(String osName) throws InstallationFailedException { - String platform = getPlatform(osName); - return new MatlabInstallable(platform); - } - - public String getPlatform(String os) throws InstallationFailedException { - String value = os.toLowerCase(Locale.ENGLISH); - if (value.contains("linux")) { - return "glnxa64"; - } else if (value.contains("os x")) { - return "maci64"; - } else if (value.contains("windows")) { - return "win64"; - } else { - throw new InstallationFailedException("Unsupported OS"); - } - } - - @Extension - public static final class DescriptorImpl extends ToolInstallerDescriptor { - public String getDisplayName() { - return Message.getValue("matlab.tools.auto.install.display.name"); - } - - @Override - public boolean isApplicable(Class toolType) { - return toolType == MatlabInstallation.class; - } - } + justification = + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") + public Installable getInstallable (Node node) throws IOException, InterruptedException { + // Gather properties for the node to install on + String[] properties = node.getChannel () + .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); + return getInstallCandidate (properties[0]); + } + + public MatlabInstallable getInstallCandidate (String osName) + throws InstallationFailedException { + String platform = getPlatform (osName); + return new MatlabInstallable (platform); + } + + public String getPlatform (String os) throws InstallationFailedException { + String value = os.toLowerCase (Locale.ENGLISH); + if (value.contains ("linux")) { + return "glnxa64"; + } else if (value.contains ("os x")) { + return "maci64"; + } else if (value.contains ("windows")) { + return "win64"; + } else { + throw new InstallationFailedException ("Unsupported OS"); + } + } + + @Extension + public static final class DescriptorImpl extends ToolInstallerDescriptor { + + public String getDisplayName () { + return Message.getValue ("matlab.tools.auto.install.display.name"); + } + + @Override + public boolean isApplicable (Class toolType) { + return toolType == MatlabInstallation.class; + } + } } \ No newline at end of file diff --git a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java index c906b65b..525337a3 100644 --- a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java +++ b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java @@ -3,18 +3,19 @@ import jenkins.security.MasterToSlaveCallable; public class GetSystemProperties extends MasterToSlaveCallable { + private static final long serialVersionUID = 1L; private final String[] properties; - public GetSystemProperties(String... properties) { + public GetSystemProperties (String... properties) { this.properties = properties; } - public String[] call() { + public String[] call () { String[] values = new String[properties.length]; for (int i = 0; i < properties.length; i++) { - values[i] = System.getProperty(properties[i]); + values[i] = System.getProperty (properties[i]); } return values; } From eaf7f4bf9d3b8c1ae1ac15916b29a6a0dbb9dd4b Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 11:51:17 +0530 Subject: [PATCH 18/51] Updated indentation --- .../ci/tools/MatlabInstallableUnitTest.java | 80 +++++++------ .../ci/tools/MatlabInstallerUnitTest.java | 110 +++++++++--------- .../GetSystemPropertiesUnitTest.java | 35 +++--- 3 files changed, 115 insertions(+), 110 deletions(-) diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java index d09cf83c..c04fd127 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java @@ -10,42 +10,46 @@ import com.mathworks.ci.TestMessage; public class MatlabInstallableUnitTest { - @Test - public void testValidWin64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("win64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.win"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.win"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("C:/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch.exe").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm.exe").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } - - @Test - public void testValidGlnxa64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("glnxa64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.linux"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.linux"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("/usr/local/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } - - @Test - public void testValidMaci64OS() throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable("maci64"); - assertEquals(TestMessage.getValue("tools.matlab.mpm.installer.mac"), installable.url); - assertEquals(TestMessage.getValue("tools.matlab.batch.executable.mac"), installable.getBatchURL()); - - FilePath expectedPath = new FilePath(new File("/Applications/install")); - assertEquals(new FilePath(expectedPath, "matlab-batch").getRemote(), - installable.getBatchInstallable(expectedPath).getRemote()); - assertEquals(new FilePath(expectedPath, "mpm").getRemote(), - installable.getMpmInstallable(expectedPath).getRemote()); - } + + @Test + public void testValidWin64OS () throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable ("win64"); + assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.win"), installable.url); + assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.win"), + installable.getBatchURL ()); + + FilePath expectedPath = new FilePath (new File ("C:/install")); + assertEquals (new FilePath (expectedPath, "matlab-batch.exe").getRemote (), + installable.getBatchInstallable (expectedPath).getRemote ()); + assertEquals (new FilePath (expectedPath, "mpm.exe").getRemote (), + installable.getMpmInstallable (expectedPath).getRemote ()); + } + + @Test + public void testValidGlnxa64OS () throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable ("glnxa64"); + assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.linux"), installable.url); + assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.linux"), + installable.getBatchURL ()); + + FilePath expectedPath = new FilePath (new File ("/usr/local/install")); + assertEquals (new FilePath (expectedPath, "matlab-batch").getRemote (), + installable.getBatchInstallable (expectedPath).getRemote ()); + assertEquals (new FilePath (expectedPath, "mpm").getRemote (), + installable.getMpmInstallable (expectedPath).getRemote ()); + } + + @Test + public void testValidMaci64OS () throws InstallationFailedException { + MatlabInstallable installable = new MatlabInstallable ("maci64"); + assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.mac"), installable.url); + assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.mac"), + installable.getBatchURL ()); + + FilePath expectedPath = new FilePath (new File ("/Applications/install")); + assertEquals (new FilePath (expectedPath, "matlab-batch").getRemote (), + installable.getBatchInstallable (expectedPath).getRemote ()); + assertEquals (new FilePath (expectedPath, "mpm").getRemote (), + installable.getMpmInstallable (expectedPath).getRemote ()); + } } diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 6fcd9db1..6946d3c3 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; + import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -19,58 +20,59 @@ public class MatlabInstallerUnitTest { - private MatlabInstaller installer; - - @Mock - private Node mockNode; - - @Mock - private TaskListener mockListener; - - @Mock - private ToolInstallation mockTool; - - @Mock - private FilePath mockFilePath; - - @Mock - private Launcher mockLauncher; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - installer = spy(new MatlabInstaller("test-id")); - installer.setVersion("R2021a"); - installer.setProducts("MATLAB"); - } - - @Test - public void testGetVersion() { - assertEquals("R2021a", installer.getVersion()); - } - - @Test - public void testGetProducts() { - assertEquals("MATLAB", installer.getProducts()); - } - - @Test - public void testPerformInstallation() throws Exception { - doReturn(mockFilePath).when(installer).performInstallation(mockTool, mockNode, mockListener); - - FilePath result = installer.performInstallation(mockTool, mockNode, mockListener); - assertNotNull(result); - } - - @Test(expected = InstallationFailedException.class) - public void testUnsupportedOS() throws Exception { - installer.getPlatform("unsupportedOS"); - } - - @Test - public void testGetPlatform() throws InstallationFailedException { - assertEquals("glnxa64", installer.getPlatform("Linux")); - assertEquals("maci64", installer.getPlatform("Mac OS X")); - assertEquals("win64", installer.getPlatform("Windows 10")); - } + private MatlabInstaller installer; + + @Mock + private Node mockNode; + + @Mock + private TaskListener mockListener; + + @Mock + private ToolInstallation mockTool; + + @Mock + private FilePath mockFilePath; + + @Mock + private Launcher mockLauncher; + + @Before + public void setUp () throws Exception { + MockitoAnnotations.initMocks (this); + installer = spy (new MatlabInstaller ("test-id")); + installer.setVersion ("R2021a"); + installer.setProducts ("MATLAB"); + } + + @Test + public void testGetVersion () { + assertEquals ("R2021a", installer.getVersion ()); + } + + @Test + public void testGetProducts () { + assertEquals ("MATLAB", installer.getProducts ()); + } + + @Test + public void testPerformInstallation () throws Exception { + doReturn (mockFilePath).when (installer) + .performInstallation (mockTool, mockNode, mockListener); + + FilePath result = installer.performInstallation (mockTool, mockNode, mockListener); + assertNotNull (result); + } + + @Test(expected = InstallationFailedException.class) + public void testUnsupportedOS () throws Exception { + installer.getPlatform ("unsupportedOS"); + } + + @Test + public void testGetPlatform () throws InstallationFailedException { + assertEquals ("glnxa64", installer.getPlatform ("Linux")); + assertEquals ("maci64", installer.getPlatform ("Mac OS X")); + assertEquals ("win64", installer.getPlatform ("Windows 10")); + } } diff --git a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java index c0e7f908..71b9e631 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java @@ -8,28 +8,27 @@ import org.junit.Test; import org.mockito.Mock; -import com.mathworks.ci.utilities.GetSystemProperties; - public class GetSystemPropertiesUnitTest { - @Mock - private GetSystemProperties getSystemProperties; + @Mock + private GetSystemProperties getSystemProperties; - @Before - public void setUp() { - // Initialize with the properties - getSystemProperties = spy(new GetSystemProperties("os.name", "os.arch", "os.version")); - } + @Before + public void setUp () { + // Initialize with the properties + getSystemProperties = spy (new GetSystemProperties ("os.name", "os.arch", "os.version")); + } - @Test - public void testCall() { - doReturn(new String[] { "MockOS", "MockArch", "MockVersion" }).when(getSystemProperties).call(); + @Test + public void testCall () { + doReturn (new String[]{"MockOS", "MockArch", "MockVersion"}).when (getSystemProperties) + .call (); - // Call the method under test - String[] result = getSystemProperties.call(); + // Call the method under test + String[] result = getSystemProperties.call (); - // Define the expected result - String[] expected = { "MockOS", "MockArch", "MockVersion" }; - assertArrayEquals(expected, result); - } + // Define the expected result + String[] expected = {"MockOS", "MockArch", "MockVersion"}; + assertArrayEquals (expected, result); + } } From fc66b886d5f10124f4345c95f8d0de700b9633c9 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 12:35:40 +0530 Subject: [PATCH 19/51] Added error for empty version --- .../com/mathworks/ci/tools/MatlabInstaller.java | 13 +++++++++++++ src/main/resources/config.properties | 11 ++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index c77edd65..034a3594 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -17,15 +17,19 @@ import hudson.tools.ToolInstallerDescriptor; import hudson.util.ArgumentListBuilder; +import hudson.util.FormValidation; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Locale; +import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; +import org.kohsuke.stapler.QueryParameter; +import org.kohsuke.stapler.verb.POST; public class MatlabInstaller extends DownloadFromUrlInstaller { @@ -199,5 +203,14 @@ public String getDisplayName () { public boolean isApplicable (Class toolType) { return toolType == MatlabInstallation.class; } + + @POST + public FormValidation doCheckVersion (@QueryParameter String value) { + Jenkins.get ().checkPermission (Jenkins.ADMINISTER); + if (value.isEmpty ()) { + return FormValidation.error (Message.getValue ("tools.matlab.empty.version.error")); + } + return FormValidation.ok (); + } } } \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 4465bf22..08f7574e 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -6,21 +6,17 @@ Builder.build.builder.display.name = Run MATLAB Build Builder.script.builder.display.name = Run MATLAB Command Buildwrapper.display.name = Use MATLAB version Builder.matlab.runner.target.file.name = runMatlabTests.m -Builder.matlab.cobertura.support.warning = To generate a Cobertura code coverage report, use MATLAB R2017b or a newer release. + Builder.invalid.matlab.root.warning = Unable to find MATLAB on this machine using the specified location. The specified root folder might contain MATLAB on a different build agent. Builder.matlab.root.empty.error = Full path to the MATLAB root folder is required. Builder.matlab.test.support.error = To run tests with the Jenkins plugin, use MATLAB R2013a or a newer release. -builder.matlab.automatictestoption.display.name = Automatic -builder.matlab.customcommandoption.display.name = Custom + Releaseinfo.matlab.version.not.found.error = Error finding MATLAB release for given MATLAB root. Verify MATLAB root path. matlab.not.found.error = Unable to launch MATLAB from the specified location. Verify the path to MATLAB root folder. matlab.not.found.error.for.node = Unable to launch MATLAB '%s' on the node '%s'. Verify global tool configuration for the specified node. matlab.execution.exception.prefix = Received a nonzero exit code %d while trying to run MATLAB. matlab.empty.command.error = Specify at least one script, function, or statement to execute. -Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model coverage report, use MATLAB R2018b or a newer release. -Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release. -Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh -Builder.matlab.runner.script.target.file.windows.name = run_matlab_command.bat + matlab.build.build.step.name = runMATLABBuild matlab.command.build.step.name = runMATLABCommand matlab.tests.build.step.name = runMATLABTests @@ -41,5 +37,6 @@ tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch tools.matlab.mpm.installer.mac = https://www.mathworks.com/mpm/maci64/mpm tools.matlab.batch.executable.mac = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch +tools.matlab.empty.version.error = MATLAB version is mandatory field. matlab.release.info.url = https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/ From 507bbd0644d3e38688ae4130fcb7d6d0f78f2106 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 16:43:43 +0530 Subject: [PATCH 20/51] Updated log for exeception --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 034a3594..674fd1a1 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -89,7 +89,7 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) ArgumentListBuilder args = new ArgumentListBuilder (); args.add (expectedPath.getRemote () + getNodeSpecificMPMExecutor (node)); args.add ("install"); - appendReleaseToArguments (args); + appendReleaseToArguments (args, log); args.add ("--destination=" + expectedPath.getRemote ()); addMatlabProductsToArgs (args); installerProc.pwd (expectedPath).cmds (args).stdout (log); @@ -97,12 +97,13 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) try { result = installerProc.join (); } catch (Exception e) { + log.getLogger ().println ("MATLAB installation failed" + e.getMessage ()); throw new InstallationFailedException (e.getMessage ()); } return result; } - private void appendReleaseToArguments (ArgumentListBuilder args) { + private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { try { String trimmedRelease = this.getVersion ().trim (); String actualRelease = trimmedRelease; @@ -123,8 +124,7 @@ private void appendReleaseToArguments (ArgumentListBuilder args) { } args.add ("--release=" + actualRelease); } catch (IOException e) { - System.err.println ("Failed to fetch release version: " + e.getMessage ()); - + log.getLogger().println("Failed to fetch release version: " + e.getMessage ()); } } From c9fc25bac6c3c9d1b01c656745843907e886bf15 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 8 Oct 2024 17:05:47 +0530 Subject: [PATCH 21/51] Added copyright --- .../mathworks/ci/tools/InstallationFailedException.java | 5 +++++ .../java/com/mathworks/ci/tools/MatlabInstallable.java | 5 +++++ src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 7 ++++++- .../com/mathworks/ci/utilities/GetSystemProperties.java | 5 +++++ .../com/mathworks/ci/tools/MatlabInstallableUnitTest.java | 5 +++++ .../com/mathworks/ci/tools/MatlabInstallerUnitTest.java | 5 +++++ .../ci/utilities/GetSystemPropertiesUnitTest.java | 5 +++++ 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java index 3be8df22..7ef594fd 100644 --- a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -1,5 +1,10 @@ package com.mathworks.ci.tools; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import java.io.IOException; // Extend IOException so we can throw and stop the build if installation fails diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index 64173dd2..57dd3a72 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -1,4 +1,9 @@ package com.mathworks.ci.tools; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import com.mathworks.ci.Message; import hudson.FilePath; diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 674fd1a1..592d0a64 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -1,4 +1,9 @@ package com.mathworks.ci.tools; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import com.mathworks.ci.MatlabInstallation; import com.mathworks.ci.Message; @@ -16,8 +21,8 @@ import hudson.tools.ToolInstallation; import hudson.tools.ToolInstallerDescriptor; import hudson.util.ArgumentListBuilder; - import hudson.util.FormValidation; + import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java index 525337a3..850d7c5c 100644 --- a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java +++ b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java @@ -1,4 +1,9 @@ package com.mathworks.ci.utilities; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import jenkins.security.MasterToSlaveCallable; diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java index c04fd127..3802e176 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java @@ -3,6 +3,11 @@ import static org.junit.Assert.assertEquals; import java.io.File; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import org.junit.Test; diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 6946d3c3..a2771f8a 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -1,4 +1,9 @@ package com.mathworks.ci.tools; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import static org.junit.Assert.*; import static org.mockito.Mockito.*; diff --git a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java index 71b9e631..39df9880 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java @@ -1,4 +1,9 @@ package com.mathworks.ci.utilities; +/** + * Copyright 2024, The MathWorks, Inc. + * + */ + import static org.junit.Assert.assertArrayEquals; import static org.mockito.Mockito.doReturn; From dcf47b6f003a61b31d8101f6a175b3318abe197c Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 10 Oct 2024 11:50:29 +0530 Subject: [PATCH 22/51] Addd batch executable build env for DSL --- src/main/java/com/mathworks/ci/MatlabInstallation.java | 1 + src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/mathworks/ci/MatlabInstallation.java b/src/main/java/com/mathworks/ci/MatlabInstallation.java index 298fcf6e..a5867f71 100644 --- a/src/main/java/com/mathworks/ci/MatlabInstallation.java +++ b/src/main/java/com/mathworks/ci/MatlabInstallation.java @@ -58,6 +58,7 @@ public MatlabInstallation forNode(@Nonnull Node node, TaskListener log) throws I @Override public void buildEnvVars(EnvVars env) { String pathToExecutable = getHome() + "/bin"; + env.put ("PATH+matlab_batch", getHome ()); env.put("PATH+matlabroot", pathToExecutable); } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 592d0a64..21cceadf 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -74,6 +74,7 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe } catch (Exception e) { throw new InstallationFailedException (e.getMessage ()); } + getFreshCopyOfExecutables (installable, expectedPath); int result = installUsingMpm (node, expectedPath, log); From 43cd307c0f022ea51126fc8bdf4136fdd56a49d3 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 10 Oct 2024 16:10:24 +0530 Subject: [PATCH 23/51] Support to maintain insalled matlab products --- .../mathworks/ci/tools/MatlabInstaller.java | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 21cceadf..68fb8b66 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -15,19 +15,28 @@ import hudson.FilePath; import hudson.Launcher; import hudson.Launcher.ProcStarter; + import hudson.model.Node; import hudson.model.TaskListener; import hudson.tools.DownloadFromUrlInstaller; import hudson.tools.ToolInstallation; import hudson.tools.ToolInstallerDescriptor; + import hudson.util.ArgumentListBuilder; import hudson.util.FormValidation; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; + import java.nio.charset.StandardCharsets; + +import java.util.Arrays; +import java.util.HashSet; import java.util.Locale; +import java.util.Set; import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; @@ -77,11 +86,23 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe getFreshCopyOfExecutables (installable, expectedPath); - int result = installUsingMpm (node, expectedPath, log); - if (result == 0) { - log.getLogger ().println ( - "MATLAB installation for version " + this.getVersion () - + " using mpm is completed successfully !"); + FilePath versionInfo = new FilePath (expectedPath,"VersionInfo.xml"); + FilePath installedProducts = new FilePath (expectedPath,"installed_matlab_product_list.txt"); + if (versionInfo.exists () && isSameProduct(installedProducts)) { + return expectedPath; + } else { + int result = installUsingMpm (node, expectedPath, log); + if (result == 0) { + log.getLogger ().println ( + "MATLAB installation for version " + this.getVersion () + + " using mpm is completed successfully !"); + String productList = this.getProducts (); + if(productList.isEmpty ()){ + installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name()); + } else { + installedProducts.write ("MATLAB "+ this.getProducts (), StandardCharsets.UTF_8.name()); + } + } } return expectedPath; } @@ -109,6 +130,34 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) return result; } + private boolean isSameProduct (FilePath installedProducts) + throws IOException, InterruptedException { + if (installedProducts.exists ()) { + Set productSet; + if (this.getProducts().isEmpty ()) { + // Add default product if no products are provided + productSet = new HashSet<>(Arrays.asList("MATLAB")); + } else { + productSet = new HashSet<>(Arrays.asList(this.getProducts().trim().split(" "))); + } + + try (BufferedReader reader = new BufferedReader ( + new InputStreamReader (installedProducts.read ()))) { + String line; + Set foundProducts = new HashSet<> (); + while ((line = reader.readLine()) != null) { + for (String product : productSet) { + if (line.trim().contains (product)) { + foundProducts.add (product); + } + } + } + return foundProducts.containsAll(productSet); + } + } + return false; + } + private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { try { String trimmedRelease = this.getVersion ().trim (); From 028510f7866681d16559ef613afc6d39db65a944 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 10 Oct 2024 16:57:59 +0530 Subject: [PATCH 24/51] Fixed spotbug --- .../mathworks/ci/tools/MatlabInstaller.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 68fb8b66..42af1dcf 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -96,12 +96,7 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe log.getLogger ().println ( "MATLAB installation for version " + this.getVersion () + " using mpm is completed successfully !"); - String productList = this.getProducts (); - if(productList.isEmpty ()){ - installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name()); - } else { - installedProducts.write ("MATLAB "+ this.getProducts (), StandardCharsets.UTF_8.name()); - } + updateProductList (installedProducts); } } return expectedPath; @@ -142,7 +137,7 @@ private boolean isSameProduct (FilePath installedProducts) } try (BufferedReader reader = new BufferedReader ( - new InputStreamReader (installedProducts.read ()))) { + new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) { String line; Set foundProducts = new HashSet<> (); while ((line = reader.readLine()) != null) { @@ -158,6 +153,31 @@ private boolean isSameProduct (FilePath installedProducts) return false; } + private void updateProductList (FilePath installedProducts) + throws IOException, InterruptedException { + String productList = this.getProducts (); + if (installedProducts.exists ()) { + try (BufferedReader reader = new BufferedReader ( + new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) { + String line; + Set productSet; + while ((line = reader.readLine ()) != null) { + productSet = new HashSet<> ( + Arrays.asList (line.trim () + " " + this.getProducts ().trim ())); + installedProducts.write (String.join (" ", productSet), + StandardCharsets.UTF_8.name ()); + } + } + } else { + if (productList.isEmpty ()) { + installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name ()); + } else { + installedProducts.write ("MATLAB " + this.getProducts (), + StandardCharsets.UTF_8.name ()); + } + } + } + private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { try { String trimmedRelease = this.getVersion ().trim (); From 328d9eba9d5082352db3ce282733312e2efb2705 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 10 Oct 2024 17:59:34 +0530 Subject: [PATCH 25/51] Updated product list logic --- .../mathworks/ci/tools/MatlabInstaller.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 42af1dcf..95bf8a4f 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -91,7 +91,7 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe if (versionInfo.exists () && isSameProduct(installedProducts)) { return expectedPath; } else { - int result = installUsingMpm (node, expectedPath, log); + int result = installUsingMpm (node, expectedPath, log, installedProducts); if (result == 0) { log.getLogger ().println ( "MATLAB installation for version " + this.getVersion () @@ -102,8 +102,8 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe return expectedPath; } - private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) - throws IOException { + private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log, FilePath installedProducts) + throws IOException, InterruptedException { Launcher matlabInstaller = node.createLauncher (log); ProcStarter installerProc = matlabInstaller.launch (); @@ -113,7 +113,7 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) args.add ("install"); appendReleaseToArguments (args, log); args.add ("--destination=" + expectedPath.getRemote ()); - addMatlabProductsToArgs (args); + addMatlabProductsToArgs (args, installedProducts); installerProc.pwd (expectedPath).cmds (args).stdout (log); int result; try { @@ -163,7 +163,7 @@ private void updateProductList (FilePath installedProducts) Set productSet; while ((line = reader.readLine ()) != null) { productSet = new HashSet<> ( - Arrays.asList (line.trim () + " " + this.getProducts ().trim ())); + Arrays.asList ((line.trim () + " " + this.getProducts ().trim()).split (" "))); installedProducts.write (String.join (" ", productSet), StandardCharsets.UTF_8.name ()); } @@ -224,16 +224,21 @@ private String getNodeSpecificMPMExecutor (Node node) { return "/mpm"; } - private void addMatlabProductsToArgs (ArgumentListBuilder args) { + private void addMatlabProductsToArgs (ArgumentListBuilder args, FilePath installedProducts) + throws IOException, InterruptedException { args.add ("--products"); if (!this.getProducts ().isEmpty ()) { - args.add ("MATLAB"); + if(!installedProducts.exists ()){ + args.add ("MATLAB"); + } String[] productList = this.getProducts ().split (" "); for (String prod : productList) { args.add (prod); } } else { - args.add ("MATLAB"); + if(!installedProducts.exists ()){ + args.add ("MATLAB"); + } } } From 0261e991053b93c3c006ba0e8f77eef0e55feb0a Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 16 Oct 2024 14:25:18 +0530 Subject: [PATCH 26/51] Updated as per review comments --- .../mathworks/ci/tools/MatlabInstallable.java | 8 ++- .../mathworks/ci/tools/MatlabInstaller.java | 60 ++++++++++--------- src/main/resources/config.properties | 6 +- .../ci/tools/MatlabInstallerUnitTest.java | 9 +-- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index 57dd3a72..d8732bab 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -25,8 +25,12 @@ public MatlabInstallable (String osName) throws InstallationFailedException { this.batchURL = Message.getValue ("tools.matlab.batch.executable.linux"); break; case "maci64": - this.url = Message.getValue ("tools.matlab.mpm.installer.mac"); - this.batchURL = Message.getValue ("tools.matlab.batch.executable.mac"); + this.url = Message.getValue ("tools.matlab.mpm.installer.maci64"); + this.batchURL = Message.getValue ("tools.matlab.batch.executable.maci64"); + break; + case "maca64": + this.url = Message.getValue ("tools.matlab.mpm.installer.maca64"); + this.batchURL = Message.getValue ("tools.matlab.batch.executable.maca64"); break; default: throw new InstallationFailedException ("Unsupported OS"); diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 95bf8a4f..ca59ef23 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -102,19 +102,19 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe return expectedPath; } - private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log, FilePath installedProducts) + private int installUsingMpm (Node node, FilePath destination, TaskListener log, FilePath installedProducts) throws IOException, InterruptedException { Launcher matlabInstaller = node.createLauncher (log); ProcStarter installerProc = matlabInstaller.launch (); ArgumentListBuilder args = new ArgumentListBuilder (); - args.add (expectedPath.getRemote () + getNodeSpecificMPMExecutor (node)); + args.add (destination.getRemote () + getNodeSpecificMPMExecutor (node)); args.add ("install"); appendReleaseToArguments (args, log); - args.add ("--destination=" + expectedPath.getRemote ()); + args.add ("--destination=" + destination.getRemote ()); addMatlabProductsToArgs (args, installedProducts); - installerProc.pwd (expectedPath).cmds (args).stdout (log); + installerProc.pwd (destination).cmds (args).stdout (log); int result; try { result = installerProc.join (); @@ -179,28 +179,29 @@ private void updateProductList (FilePath installedProducts) } private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { - try { - String trimmedRelease = this.getVersion ().trim (); - String actualRelease = trimmedRelease; - - if (trimmedRelease.equalsIgnoreCase ("latest") || trimmedRelease.equalsIgnoreCase ( - "latest-including-prerelease")) { - String releaseInfoUrl = - Message.getValue ("matlab.release.info.url") + trimmedRelease; - String releaseVersion = IOUtils.toString (new URL (releaseInfoUrl), + String trimmedRelease = this.getVersion ().trim (); + String actualRelease = trimmedRelease; + + if (trimmedRelease.equalsIgnoreCase ("latest") || trimmedRelease.equalsIgnoreCase ( + "latest-including-prerelease")) { + String releaseInfoUrl = + Message.getValue ("matlab.release.info.url") + trimmedRelease; + String releaseVersion = null; + try { + releaseVersion = IOUtils.toString (new URL (releaseInfoUrl), StandardCharsets.UTF_8).trim (); + } catch (IOException e) { + log.getLogger ().println ("Failed to fetch release version: " + e.getMessage ()); + } - if (releaseVersion.contains ("prerelease")) { - actualRelease = releaseVersion.replace ("prerelease", ""); - args.add ("--release-status=Prerelease"); - } else { - actualRelease = releaseVersion; - } + if (releaseVersion != null && releaseVersion.contains ("prerelease")) { + actualRelease = releaseVersion.replace ("prerelease", ""); + args.add ("--release-status=Prerelease"); + } else { + actualRelease = releaseVersion; } - args.add ("--release=" + actualRelease); - } catch (IOException e) { - log.getLogger().println("Failed to fetch release version: " + e.getMessage ()); } + args.add ("--release=" + actualRelease); } private void getFreshCopyOfExecutables (MatlabInstallable installable, FilePath expectedPath) @@ -250,21 +251,26 @@ public Installable getInstallable (Node node) throws IOException, InterruptedExc // Gather properties for the node to install on String[] properties = node.getChannel () .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); - return getInstallCandidate (properties[0]); + return getInstallCandidate (properties[0], properties[1]); } - public MatlabInstallable getInstallCandidate (String osName) + public MatlabInstallable getInstallCandidate (String osName, String architecture) throws InstallationFailedException { - String platform = getPlatform (osName); + String platform = getPlatform (osName, architecture); return new MatlabInstallable (platform); } - public String getPlatform (String os) throws InstallationFailedException { + public String getPlatform (String os, String architecture) throws InstallationFailedException { String value = os.toLowerCase (Locale.ENGLISH); if (value.contains ("linux")) { return "glnxa64"; } else if (value.contains ("os x")) { - return "maci64"; + if (architecture.equalsIgnoreCase ("aarch64") || architecture.equalsIgnoreCase ( + "arm64")) { + return "maca64"; + } else { + return "maci64"; + } } else if (value.contains ("windows")) { return "win64"; } else { diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 08f7574e..2ea13843 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -35,8 +35,10 @@ tools.matlab.mpm.installer.win = https://www.mathworks.com/mpm/win64/mpm tools.matlab.batch.executable.win = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch -tools.matlab.mpm.installer.mac = https://www.mathworks.com/mpm/maci64/mpm -tools.matlab.batch.executable.mac = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch +tools.matlab.mpm.installer.maci64 = https://www.mathworks.com/mpm/maci64/mpm +tools.matlab.batch.executable.maci64 = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch +tools.matlab.mpm.installer.maca64 = https://www.mathworks.com/mpm/maca64/mpm +tools.matlab.batch.executable.maca64 = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maca64/matlab-batch tools.matlab.empty.version.error = MATLAB version is mandatory field. matlab.release.info.url = https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/ diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index a2771f8a..509dbb57 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -71,13 +71,14 @@ public void testPerformInstallation () throws Exception { @Test(expected = InstallationFailedException.class) public void testUnsupportedOS () throws Exception { - installer.getPlatform ("unsupportedOS"); + installer.getPlatform ("unsupportedOS", "unsupportedArch"); } @Test public void testGetPlatform () throws InstallationFailedException { - assertEquals ("glnxa64", installer.getPlatform ("Linux")); - assertEquals ("maci64", installer.getPlatform ("Mac OS X")); - assertEquals ("win64", installer.getPlatform ("Windows 10")); + assertEquals ("glnxa64", installer.getPlatform ("Linux", "i686")); + assertEquals ("maci64", installer.getPlatform ("Mac OS X", "amd64")); + assertEquals ("maca64", installer.getPlatform ("Mac OS X", "arm64")); + assertEquals ("win64", installer.getPlatform ("Windows 10", "x86")); } } From c29ae44113ccd5e511e134df5fe95210c1646bea Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 17 Oct 2024 14:02:51 +0530 Subject: [PATCH 27/51] Updated as per review comments --- .../java/com/mathworks/ci/tools/MatlabInstaller.java | 1 - .../ci/utilities/GetSystemPropertiesUnitTest.java | 11 ++--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index ca59ef23..1fb72a14 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -196,7 +196,6 @@ private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener lo if (releaseVersion != null && releaseVersion.contains ("prerelease")) { actualRelease = releaseVersion.replace ("prerelease", ""); - args.add ("--release-status=Prerelease"); } else { actualRelease = releaseVersion; } diff --git a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java index 39df9880..b7d0f91e 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java @@ -20,20 +20,13 @@ public class GetSystemPropertiesUnitTest { @Before public void setUp () { - // Initialize with the properties - getSystemProperties = spy (new GetSystemProperties ("os.name", "os.arch", "os.version")); + getSystemProperties = new GetSystemProperties ("os.name","os.arch", "os.version"); } @Test public void testCall () { - doReturn (new String[]{"MockOS", "MockArch", "MockVersion"}).when (getSystemProperties) - .call (); - - // Call the method under test + String[] expected = {System.getProperty ("os.name"),System.getProperty ("os.arch"),System.getProperty ("os.version")}; String[] result = getSystemProperties.call (); - - // Define the expected result - String[] expected = {"MockOS", "MockArch", "MockVersion"}; assertArrayEquals (expected, result); } } From 9c08600457a1b76af87076ae2e3183b38ad0428d Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 23 Oct 2024 11:01:58 +0530 Subject: [PATCH 28/51] Revoked support for windows and other comments --- .../ci/UseMatlabVersionBuildWrapper.java | 27 ++++++++++++++++--- .../mathworks/ci/tools/MatlabInstaller.java | 20 +++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 7db197e7..041c9ef6 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -188,16 +188,19 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher // Set Environment variable setEnv(initialEnvironment); - FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), - getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher)); + String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); + FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } // Add matlab-batch executable in path - context.env("PATH+matlab_batch", matlabExecutablePath.getParent().getParent().getRemote()); + if(getNthParentFilePath(matlabExecutablePath, 3).exists () || getNthParentFilePath(matlabExecutablePath,3 ) != null){ + context.env("PATH+matlab_batch", matlabExecutablePath.getParent ().getParent ().getParent().getRemote ()); + } + // Add "matlabroot" without bin as env variable which will be available across the build. - context.env("matlabroot", getNodeSpecificMatlab(Computer.currentComputer(), listener)); + context.env("matlabroot", nodeSpecificMatlab); // Add matlab bin to path to invoke MATLAB directly on command line. context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());; listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath.getParent().getRemote()) + "\n"); @@ -206,4 +209,20 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher private String getNodeSpecificExecutable(Launcher launcher) { return (launcher.isUnix()) ? "/bin/matlab" : "\\bin\\matlab.exe"; } + + public static FilePath getNthParentFilePath (FilePath path, int levels) { + if (path == null || levels < 0) { + return null; + } + + FilePath currentPath = path; + for (int i = 0; i < levels; i++) { + if (currentPath == null) { + return null; + } + currentPath = currentPath.getParent (); + } + return currentPath; + } + } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 1fb72a14..dffd76a8 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -76,7 +76,8 @@ public void setProducts (String products) { @Override public FilePath performInstallation (ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { - FilePath expectedPath = preferredLocation (tool, node); + FilePath supportingExecutable = preferredLocation (tool, node); + FilePath expectedPath = new FilePath (supportingExecutable, this.getVersion ()); MatlabInstallable installable; try { installable = (MatlabInstallable) getInstallable (node); @@ -84,7 +85,8 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe throw new InstallationFailedException (e.getMessage ()); } - getFreshCopyOfExecutables (installable, expectedPath); + getFreshCopyOfExecutables (installable, supportingExecutable); + makeDir (expectedPath); FilePath versionInfo = new FilePath (expectedPath,"VersionInfo.xml"); FilePath installedProducts = new FilePath (expectedPath,"installed_matlab_product_list.txt"); @@ -109,7 +111,7 @@ private int installUsingMpm (Node node, FilePath destination, TaskListener log, ProcStarter installerProc = matlabInstaller.launch (); ArgumentListBuilder args = new ArgumentListBuilder (); - args.add (destination.getRemote () + getNodeSpecificMPMExecutor (node)); + args.add (destination.getParent ().getRemote () + getNodeSpecificMPMExecutor (node)); args.add ("install"); appendReleaseToArguments (args, log); args.add ("--destination=" + destination.getRemote ()); @@ -119,12 +121,19 @@ private int installUsingMpm (Node node, FilePath destination, TaskListener log, try { result = installerProc.join (); } catch (Exception e) { - log.getLogger ().println ("MATLAB installation failed" + e.getMessage ()); + log.getLogger ().println ("MATLAB installation failed " + e.getMessage ()); throw new InstallationFailedException (e.getMessage ()); } return result; } + private void makeDir(FilePath path) throws IOException, InterruptedException { + if(!path.exists ()){ + path.mkdirs (); + path.chmod (0777); + } + } + private boolean isSameProduct (FilePath installedProducts) throws IOException, InterruptedException { if (installedProducts.exists ()) { @@ -250,6 +259,9 @@ public Installable getInstallable (Node node) throws IOException, InterruptedExc // Gather properties for the node to install on String[] properties = node.getChannel () .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); + if(properties[0].contains ("win")) { + throw new InstallationFailedException ("Unsupported OS"); + } return getInstallCandidate (properties[0], properties[1]); } From 1a2acbcab000f46581901ea0369236dfad91b8bd Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 23 Oct 2024 16:05:51 +0530 Subject: [PATCH 29/51] Fixed test failures --- .../com/mathworks/ci/UseMatlabVersionBuildWrapper.java | 8 +++++++- .../com/mathworks/ci/RunMatlabBuildBuilderTest.java | 1 + .../com/mathworks/ci/RunMatlabBuildBuilderTester.java | 8 +------- .../com/mathworks/ci/RunMatlabCommandBuilderTester.java | 8 +------- .../com/mathworks/ci/RunMatlabTestsBuilderTester.java | 9 +-------- 5 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 041c9ef6..55b053a5 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -188,7 +188,13 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher // Set Environment variable setEnv(initialEnvironment); - String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); + String nodeSpecificMatlab = ""; + if(getNodeSpecificMatlab(Computer.currentComputer(), listener) != null) { + nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); + } else { + throw new IOException ("ERROR***"); + } + FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); if (!matlabExecutablePath.exists()) { diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java index 69b6ee44..4550b68d 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java @@ -62,6 +62,7 @@ public static void classSetup() throws URISyntaxException, IOException { url = classLoader.getResource("com/mathworks/ci/linux/bin/matlab.sh"); try { matlabExecutorAbsolutePath = new File(url.toURI()).getAbsolutePath(); + System.out.println ("THE EXECUTOR PATH IS" + matlabExecutorAbsolutePath); // Need to do this operation due to bug in maven Resource copy plugin [ // https://issues.apache.org/jira/browse/MRESOURCES-132 ] diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java index a52fb244..c6c0b3e1 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java @@ -93,13 +93,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { ProcStarter matlabLauncher; try { - matlabLauncher = launcher.launch().pwd(workspace).envs(this.env); - if (matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) { - ListenerLogDecorator outStream = new ListenerLogDecorator(listener); - matlabLauncher = matlabLauncher.cmds(testMatlabBuild()).stderr(outStream); - } else { - matlabLauncher = matlabLauncher.cmds(testMatlabBuild()).stdout(listener); - } + matlabLauncher = launcher.launch().pwd(workspace).envs(this.env).cmds(testMatlabBuild()).stdout(listener); } catch (Exception e) { listener.getLogger().println(e.getMessage()); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java index 8236c85d..4538e6b4 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java @@ -94,13 +94,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { ProcStarter matlabLauncher; try { - matlabLauncher = launcher.launch().pwd(workspace).envs(this.env); - if (matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) { - ListenerLogDecorator outStream = new ListenerLogDecorator(listener); - matlabLauncher = matlabLauncher.cmds(testMatlabCommand()).stderr(outStream); - } else { - matlabLauncher = matlabLauncher.cmds(testMatlabCommand()).stdout(listener); - } + matlabLauncher = launcher.launch().pwd(workspace).envs(this.env).cmds(testMatlabCommand()).stdout(listener); } catch (Exception e) { listener.getLogger().println(e.getMessage()); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java index cac180ba..a5ee3e86 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java @@ -179,14 +179,7 @@ public int execCommand(FilePath workspace, Launcher launcher, TaskListener liste } ProcStarter matlabLauncher; try { - matlabLauncher = launcher.launch().pwd(workspace).envs(this.env); - if (this.matlabroot != null && matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) { - ListenerLogDecorator outStream = new ListenerLogDecorator(listener); - matlabLauncher = matlabLauncher.cmds(testMatlabCommand()).stderr(outStream); - } else { - matlabLauncher = matlabLauncher.cmds(testMatlabCommand()).stdout(listener); - } - + matlabLauncher = launcher.launch().pwd(workspace).envs(this.env).cmds(testMatlabCommand()).stdout(listener); } catch (Exception e) { listener.getLogger().println(e.getMessage()); return 1; From 836dc3e8b680a6ad649e861402bc840f13838d48 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 24 Oct 2024 09:21:25 +0530 Subject: [PATCH 30/51] Removed Windows support --- .../ci/UseMatlabVersionBuildWrapper.java | 7 +------ .../mathworks/ci/tools/MatlabInstallable.java | 12 +----------- .../com/mathworks/ci/tools/MatlabInstaller.java | 5 ----- src/main/resources/config.properties | 2 -- .../ci/tools/MatlabInstallableUnitTest.java | 16 +++++++--------- .../ci/tools/MatlabInstallerUnitTest.java | 3 ++- 6 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 55b053a5..6ffabb3a 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -188,13 +188,8 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher // Set Environment variable setEnv(initialEnvironment); - String nodeSpecificMatlab = ""; - if(getNodeSpecificMatlab(Computer.currentComputer(), listener) != null) { - nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); - } else { - throw new IOException ("ERROR***"); - } + String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); if (!matlabExecutablePath.exists()) { diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java index d8732bab..a7efa4d1 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java @@ -15,11 +15,7 @@ public class MatlabInstallable extends Installable { private String osName; public MatlabInstallable (String osName) throws InstallationFailedException { this.osName = osName; - switch (osName) { - case "win64": - this.url = Message.getValue ("tools.matlab.mpm.installer.win"); - this.batchURL = Message.getValue ("tools.matlab.batch.executable.win"); - break; + switch (this.osName) { case "glnxa64": this.url = Message.getValue ("tools.matlab.mpm.installer.linux"); this.batchURL = Message.getValue ("tools.matlab.batch.executable.linux"); @@ -42,16 +38,10 @@ public String getBatchURL () { } public FilePath getBatchInstallable (FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath (expectedPath, "matlab-batch.exe"); - } return new FilePath (expectedPath, "matlab-batch"); } public FilePath getMpmInstallable (FilePath expectedPath) { - if (this.osName == "win64") { - return new FilePath (expectedPath, "mpm.exe"); - } return new FilePath (expectedPath, "mpm"); } } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index dffd76a8..e4119238 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -259,9 +259,6 @@ public Installable getInstallable (Node node) throws IOException, InterruptedExc // Gather properties for the node to install on String[] properties = node.getChannel () .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); - if(properties[0].contains ("win")) { - throw new InstallationFailedException ("Unsupported OS"); - } return getInstallCandidate (properties[0], properties[1]); } @@ -282,8 +279,6 @@ public String getPlatform (String os, String architecture) throws InstallationFa } else { return "maci64"; } - } else if (value.contains ("windows")) { - return "win64"; } else { throw new InstallationFailedException ("Unsupported OS"); } diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 2ea13843..deef2a91 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -31,8 +31,6 @@ Axis.no.installed.matlab.error = Because no MATLAB versions exist under Jenkins Use.matlab.version.axis.warning = This project specifies MATLAB versions using the 'Use MATLAB version' option as well as the added 'MATLAB' axis. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. matlab.tools.auto.install.display.name = Install Using MPM -tools.matlab.mpm.installer.win = https://www.mathworks.com/mpm/win64/mpm -tools.matlab.batch.executable.win = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/win64/matlab-batch.exe tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch tools.matlab.mpm.installer.maci64 = https://www.mathworks.com/mpm/maci64/mpm diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java index 3802e176..c764f3f3 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java @@ -8,26 +8,24 @@ * */ - +import org.junit.Rule; import org.junit.Test; import hudson.FilePath; import com.mathworks.ci.TestMessage; +import org.junit.rules.ExpectedException; public class MatlabInstallableUnitTest { + @Rule + public ExpectedException exceptionRule = ExpectedException.none (); + @Test public void testValidWin64OS () throws InstallationFailedException { + exceptionRule.expect(InstallationFailedException.class); + exceptionRule.expectMessage("Unsupported OS"); MatlabInstallable installable = new MatlabInstallable ("win64"); - assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.win"), installable.url); - assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.win"), - installable.getBatchURL ()); - FilePath expectedPath = new FilePath (new File ("C:/install")); - assertEquals (new FilePath (expectedPath, "matlab-batch.exe").getRemote (), - installable.getBatchInstallable (expectedPath).getRemote ()); - assertEquals (new FilePath (expectedPath, "mpm.exe").getRemote (), - installable.getMpmInstallable (expectedPath).getRemote ()); } @Test diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 509dbb57..5e1bf34e 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -8,6 +8,8 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import org.junit.Rule; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -79,6 +81,5 @@ public void testGetPlatform () throws InstallationFailedException { assertEquals ("glnxa64", installer.getPlatform ("Linux", "i686")); assertEquals ("maci64", installer.getPlatform ("Mac OS X", "amd64")); assertEquals ("maca64", installer.getPlatform ("Mac OS X", "arm64")); - assertEquals ("win64", installer.getPlatform ("Windows 10", "x86")); } } From c822a0f670ffcf681dfd7ca754a6ee8a79c02964 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 28 Oct 2024 13:20:57 +0530 Subject: [PATCH 31/51] Updated as per review comments --- .../mathworks/ci/tools/MatlabInstaller.java | 4 ++-- .../ci/tools/MatlabInstaller/config.jelly | 2 +- .../tools/MatlabInstaller/help-products.html | 10 ++++------ .../tools/MatlabInstaller/help-version.html | 20 +++++++++++++------ src/main/resources/config.properties | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index e4119238..8194bcc5 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -96,8 +96,8 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe int result = installUsingMpm (node, expectedPath, log, installedProducts); if (result == 0) { log.getLogger ().println ( - "MATLAB installation for version " + this.getVersion () - + " using mpm is completed successfully !"); + "MATLAB installation of version " + this.getVersion () + + " using mpm completed successfully!"); updateProductList (installedProducts); } } diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly index 3bb8e4a1..9e59b102 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html index 96d20cc0..6eee85b0 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html @@ -1,15 +1,13 @@

- (Optional) Products to set up in addition to MATLAB, specified as a list of product names separated by spaces. - You can specify products to set up most MathWorks products and support packages. + Insert a space-separated list of products to install. The plugin installs the specified products in addition to MATLAB.

For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. - Specify products using the format shown in the input file, excluding the #product. prefix. + Specify products using the format shown in the input file, excluding the #product. prefix. For example, to install Deep Learning Toolbox™ in addition to MATLAB, insert Deep_Learning_Toolbox in the Products box.

- Example: to set up Deep Learning Toolbox™ in addition to MATLAB, - specify products: Deep_Learning_Toolbox + Example: Simulink
+ Example: Simulink Deep_Learning_Toolbox

- Note: MATLAB is selected by default if text box is blank or no products specified.
\ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html index 4761468f..f5e80489 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html @@ -1,14 +1,22 @@

- Enter the MATLAB version to be installed. For update versions, append the appropriate update number to the MATLAB version. + Insert the MATLAB version to install. To install the latest release of MATLAB, insert latest in the Version box.

- Example: R2024a or R2024aU1
- Example: For latest MATLAB release just provide latest as version. +

    +
  • To install the latest update of a release, specify only the release name, for example, R2023b.
  • > +
  • To install a specific update release, specify the release name with an update number suffix, for example, R2023bU4.
  • > +
  • To install a release without updates, specify the release name with an update 0 or general release suffix, for example, R2023bU0 or R2023bGR.
  • > +
> +

> +

+ Example: R2024a
+ Example: latest
+ Example: R2023bU4

- Note: If the installation host is Linux, you may need to install some - dependencies - before installing MATLAB using MPM. + Note: The plugin does not install dependencies on a Linux platform. If you are using a Linux platform, + verify that the required software is available before installing products using MATLAB Package Manager. For more information, see + Get MATLAB Package Manager.

\ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index deef2a91..7da01e12 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -29,7 +29,7 @@ Axis.matlab.key = MATLAB Axis.use.matlab.warning = This project specifies MATLAB versions using the added 'MATLAB' axis as well as the 'Use MATLAB version' option. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. Axis.no.installed.matlab.error = Because no MATLAB versions exist under Jenkins Global Tool Configuration, the plugin will run the default matrix configuration. Use.matlab.version.axis.warning = This project specifies MATLAB versions using the 'Use MATLAB version' option as well as the added 'MATLAB' axis. The value specified by 'Use MATLAB version' takes precedence over the values specified by the 'MATLAB' axis. -matlab.tools.auto.install.display.name = Install Using MPM +matlab.tools.auto.install.display.name = Install Using MATLAB Package Manager tools.matlab.mpm.installer.linux = https://www.mathworks.com/mpm/glnxa64/mpm tools.matlab.batch.executable.linux = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/glnxa64/matlab-batch From 22b2351de3a7c539ce079a9165562bd513d81075 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 29 Oct 2024 12:00:04 +0530 Subject: [PATCH 32/51] Removed product hash --- .../mathworks/ci/tools/MatlabInstaller.java | 82 +++---------------- 1 file changed, 11 insertions(+), 71 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 8194bcc5..9ec69e47 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -49,6 +49,7 @@ public class MatlabInstaller extends DownloadFromUrlInstaller { private String version; private String products; + private static String DEFAULT_PRODUCT = "MATLAB"; @DataBoundConstructor public MatlabInstaller (String id) { @@ -88,23 +89,16 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe getFreshCopyOfExecutables (installable, supportingExecutable); makeDir (expectedPath); - FilePath versionInfo = new FilePath (expectedPath,"VersionInfo.xml"); - FilePath installedProducts = new FilePath (expectedPath,"installed_matlab_product_list.txt"); - if (versionInfo.exists () && isSameProduct(installedProducts)) { - return expectedPath; - } else { - int result = installUsingMpm (node, expectedPath, log, installedProducts); + int result = installUsingMpm (node, expectedPath, log); if (result == 0) { log.getLogger ().println ( "MATLAB installation of version " + this.getVersion () + " using mpm completed successfully!"); - updateProductList (installedProducts); } - } return expectedPath; } - private int installUsingMpm (Node node, FilePath destination, TaskListener log, FilePath installedProducts) + private int installUsingMpm (Node node, FilePath destination, TaskListener log) throws IOException, InterruptedException { Launcher matlabInstaller = node.createLauncher (log); @@ -115,7 +109,7 @@ private int installUsingMpm (Node node, FilePath destination, TaskListener log, args.add ("install"); appendReleaseToArguments (args, log); args.add ("--destination=" + destination.getRemote ()); - addMatlabProductsToArgs (args, installedProducts); + addMatlabProductsToArgs (args); installerProc.pwd (destination).cmds (args).stdout (log); int result; try { @@ -134,59 +128,6 @@ private void makeDir(FilePath path) throws IOException, InterruptedException { } } - private boolean isSameProduct (FilePath installedProducts) - throws IOException, InterruptedException { - if (installedProducts.exists ()) { - Set productSet; - if (this.getProducts().isEmpty ()) { - // Add default product if no products are provided - productSet = new HashSet<>(Arrays.asList("MATLAB")); - } else { - productSet = new HashSet<>(Arrays.asList(this.getProducts().trim().split(" "))); - } - - try (BufferedReader reader = new BufferedReader ( - new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) { - String line; - Set foundProducts = new HashSet<> (); - while ((line = reader.readLine()) != null) { - for (String product : productSet) { - if (line.trim().contains (product)) { - foundProducts.add (product); - } - } - } - return foundProducts.containsAll(productSet); - } - } - return false; - } - - private void updateProductList (FilePath installedProducts) - throws IOException, InterruptedException { - String productList = this.getProducts (); - if (installedProducts.exists ()) { - try (BufferedReader reader = new BufferedReader ( - new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) { - String line; - Set productSet; - while ((line = reader.readLine ()) != null) { - productSet = new HashSet<> ( - Arrays.asList ((line.trim () + " " + this.getProducts ().trim()).split (" "))); - installedProducts.write (String.join (" ", productSet), - StandardCharsets.UTF_8.name ()); - } - } - } else { - if (productList.isEmpty ()) { - installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name ()); - } else { - installedProducts.write ("MATLAB " + this.getProducts (), - StandardCharsets.UTF_8.name ()); - } - } - } - private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { String trimmedRelease = this.getVersion ().trim (); String actualRelease = trimmedRelease; @@ -233,21 +174,20 @@ private String getNodeSpecificMPMExecutor (Node node) { return "/mpm"; } - private void addMatlabProductsToArgs (ArgumentListBuilder args, FilePath installedProducts) + private void addMatlabProductsToArgs (ArgumentListBuilder args) throws IOException, InterruptedException { args.add ("--products"); - if (!this.getProducts ().isEmpty ()) { - if(!installedProducts.exists ()){ - args.add ("MATLAB"); + if (this.getProducts ().isEmpty ()) { + args.add (DEFAULT_PRODUCT); + + } else { + if (!this.getProducts ().contains (DEFAULT_PRODUCT)) { + args.add (DEFAULT_PRODUCT); } String[] productList = this.getProducts ().split (" "); for (String prod : productList) { args.add (prod); } - } else { - if(!installedProducts.exists ()){ - args.add ("MATLAB"); - } } } From 83f45478d7824e387be2f4663035ed0ea304ddd2 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 30 Oct 2024 12:41:22 +0530 Subject: [PATCH 33/51] Updated as per review comments --- .../java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java | 5 +++-- .../mathworks/ci/tools/MatlabInstaller/help-products.html | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 6ffabb3a..5da8c1ed 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -196,8 +196,9 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } // Add matlab-batch executable in path - if(getNthParentFilePath(matlabExecutablePath, 3).exists () || getNthParentFilePath(matlabExecutablePath,3 ) != null){ - context.env("PATH+matlab_batch", matlabExecutablePath.getParent ().getParent ().getParent().getRemote ()); + FilePath batchExecutable = getNthParentFilePath(matlabExecutablePath, 3); + if(batchExecutable != null && batchExecutable.exists ()){ + context.env("PATH+matlab_batch", batchExecutable.getRemote ()); } // Add "matlabroot" without bin as env variable which will be available across the build. diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html index 6eee85b0..39366b20 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html @@ -4,7 +4,7 @@

For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. - Specify products using the format shown in the input file, excluding the #product. prefix. For example, to install Deep Learning Toolbox™ in addition to MATLAB, insert Deep_Learning_Toolbox in the Products box. + Specify products using the format shown in the input file, excluding the #product. prefix. For example, to install Deep Learning Toolbox in addition to MATLAB, insert Deep_Learning_Toolbox in the Products box.

Example: Simulink
From 25b3608be537a7f1849675c06d313cc1427745e3 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 30 Oct 2024 18:29:48 +0530 Subject: [PATCH 34/51] Fixed path issue on Mac OS --- .../ci/UseMatlabVersionBuildWrapper.java | 2 +- .../mathworks/ci/tools/MatlabInstaller.java | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 5da8c1ed..7683f0b4 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -191,7 +191,7 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); - + listener.getLogger().println("**The path which is trying to uppend is **" + matlabExecutablePath.getRemote ()); if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 9ec69e47..d19085ba 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -78,10 +78,16 @@ public void setProducts (String products) { public FilePath performInstallation (ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath supportingExecutable = preferredLocation (tool, node); - FilePath expectedPath = new FilePath (supportingExecutable, this.getVersion ()); + String[] systemProperties = getSystemProperties(node); + FilePath expectedPath; + if(systemProperties[0].toLowerCase ().contains ("os x")) { + expectedPath = new FilePath (supportingExecutable, this.getVersion ()+".app"); + } else { + expectedPath = new FilePath (supportingExecutable, this.getVersion ()); + } MatlabInstallable installable; try { - installable = (MatlabInstallable) getInstallable (node); + installable = (MatlabInstallable) getInstallable (systemProperties); } catch (Exception e) { throw new InstallationFailedException (e.getMessage ()); } @@ -191,15 +197,9 @@ private void addMatlabProductsToArgs (ArgumentListBuilder args) } } - @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, - justification = - "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " - + "https://github.com/spotbugs/spotbugs/issues/1843") - public Installable getInstallable (Node node) throws IOException, InterruptedException { + public Installable getInstallable (String[] systemProperties) throws IOException { // Gather properties for the node to install on - String[] properties = node.getChannel () - .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); - return getInstallCandidate (properties[0], properties[1]); + return getInstallCandidate (systemProperties[0], systemProperties[1]); } public MatlabInstallable getInstallCandidate (String osName, String architecture) @@ -224,6 +224,16 @@ public String getPlatform (String os, String architecture) throws InstallationFa } } + @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, + justification = + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") + private String[] getSystemProperties(Node node) throws IOException, InterruptedException { + String[] properties = node.getChannel () + .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); + return properties; + } + @Extension public static final class DescriptorImpl extends ToolInstallerDescriptor { From 2e6f385b15dfaa110db560b642324a6349a2dc0c Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 4 Nov 2024 15:39:35 +0530 Subject: [PATCH 35/51] Updated as per Review comments --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 1 + .../com/mathworks/ci/tools/MatlabInstaller/help-products.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index d19085ba..08ad9b30 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -152,6 +152,7 @@ private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener lo if (releaseVersion != null && releaseVersion.contains ("prerelease")) { actualRelease = releaseVersion.replace ("prerelease", ""); + args.add ("--release-status=Prerelease"); } else { actualRelease = releaseVersion; } diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html index 39366b20..d15106e5 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-products.html @@ -3,7 +3,7 @@ Insert a space-separated list of products to install. The plugin installs the specified products in addition to MATLAB.

- For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. + For a list of supported products, open the input file for your preferred release from the mpm-input-files folder on GitHub. Specify products using the format shown in the input file, excluding the #product. prefix. For example, to install Deep Learning Toolbox in addition to MATLAB, insert Deep_Learning_Toolbox in the Products box.

From eb9332418f846dbda24b3c4d1b43c0700e98977f Mon Sep 17 00:00:00 2001 From: David Buzinski <103441853+davidbuzinski@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:15:08 -0500 Subject: [PATCH 36/51] Use ToolInstaller (#366) * changed to generic ToolInstaller and add prerelease logic * remove space between method names and parens * exception if mpm install fails * Updated mpm method as per reviw comment --------- Co-authored-by: Nikhil Bhoski --- .../mathworks/ci/tools/MatlabInstallable.java | 47 ---- .../mathworks/ci/tools/MatlabInstaller.java | 209 +++++++++--------- .../ci/tools/MatlabInstaller/config.jelly | 2 +- src/main/resources/config.properties | 2 +- .../ci/tools/MatlabInstallableUnitTest.java | 58 ----- .../ci/tools/MatlabInstallerUnitTest.java | 4 +- 6 files changed, 110 insertions(+), 212 deletions(-) delete mode 100644 src/main/java/com/mathworks/ci/tools/MatlabInstallable.java delete mode 100644 src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java b/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java deleted file mode 100644 index a7efa4d1..00000000 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstallable.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.mathworks.ci.tools; -/** - * Copyright 2024, The MathWorks, Inc. - * - */ - - -import com.mathworks.ci.Message; -import hudson.FilePath; -import hudson.tools.DownloadFromUrlInstaller.Installable; - -public class MatlabInstallable extends Installable { - - public String batchURL; - private String osName; - public MatlabInstallable (String osName) throws InstallationFailedException { - this.osName = osName; - switch (this.osName) { - case "glnxa64": - this.url = Message.getValue ("tools.matlab.mpm.installer.linux"); - this.batchURL = Message.getValue ("tools.matlab.batch.executable.linux"); - break; - case "maci64": - this.url = Message.getValue ("tools.matlab.mpm.installer.maci64"); - this.batchURL = Message.getValue ("tools.matlab.batch.executable.maci64"); - break; - case "maca64": - this.url = Message.getValue ("tools.matlab.mpm.installer.maca64"); - this.batchURL = Message.getValue ("tools.matlab.batch.executable.maca64"); - break; - default: - throw new InstallationFailedException ("Unsupported OS"); - } - } - - public String getBatchURL () { - return this.batchURL; - } - - public FilePath getBatchInstallable (FilePath expectedPath) { - return new FilePath (expectedPath, "matlab-batch"); - } - - public FilePath getMpmInstallable (FilePath expectedPath) { - return new FilePath (expectedPath, "mpm"); - } -} diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 08ad9b30..008572af 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -18,7 +18,7 @@ import hudson.model.Node; import hudson.model.TaskListener; -import hudson.tools.DownloadFromUrlInstaller; +import hudson.tools.ToolInstaller; import hudson.tools.ToolInstallation; import hudson.tools.ToolInstallerDescriptor; @@ -45,183 +45,186 @@ import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.verb.POST; -public class MatlabInstaller extends DownloadFromUrlInstaller { +public class MatlabInstaller extends ToolInstaller { - private String version; + private String release; private String products; private static String DEFAULT_PRODUCT = "MATLAB"; @DataBoundConstructor - public MatlabInstaller (String id) { - super (id); + public MatlabInstaller(String id) { + super(id); } - public String getVersion () { - return this.version; + public String getRelease() { + return this.release; } @DataBoundSetter - public void setVersion (String version) { - this.version = version; + public void setVersion(String release) { + this.release = release; } - public String getProducts () { + public String getProducts() { return this.products; } @DataBoundSetter - public void setProducts (String products) { + public void setProducts(String products) { this.products = products; } @Override - public FilePath performInstallation (ToolInstallation tool, Node node, TaskListener log) + public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { - FilePath supportingExecutable = preferredLocation (tool, node); + FilePath destination = preferredLocation(tool, node); String[] systemProperties = getSystemProperties(node); - FilePath expectedPath; - if(systemProperties[0].toLowerCase ().contains ("os x")) { - expectedPath = new FilePath (supportingExecutable, this.getVersion ()+".app"); + FilePath matlabRootPath; + if(systemProperties[0].toLowerCase().contains("os x")) { + matlabRootPath= new FilePath(destination, this.getRelease()+".app"); } else { - expectedPath = new FilePath (supportingExecutable, this.getVersion ()); + matlabRootPath = new FilePath(destination, this.getRelease()); } - MatlabInstallable installable; - try { - installable = (MatlabInstallable) getInstallable (systemProperties); - } catch (Exception e) { - throw new InstallationFailedException (e.getMessage ()); + String platform = getPlatform(systemProperties[0], systemProperties[1]); + getFreshCopyOfExecutables(platform, destination); + + makeDir(matlabRootPath); + int result = installUsingMpm(node, this.getRelease (), matlabRootPath, this.getProducts (), log); + if (result != 0) { + throw new InstallationFailedException("Unable to install MATLAB using mpm."); } - - getFreshCopyOfExecutables (installable, supportingExecutable); - makeDir (expectedPath); - - int result = installUsingMpm (node, expectedPath, log); - if (result == 0) { - log.getLogger ().println ( - "MATLAB installation of version " + this.getVersion () - + " using mpm completed successfully!"); - } - return expectedPath; + return matlabRootPath; } - private int installUsingMpm (Node node, FilePath destination, TaskListener log) + private int installUsingMpm(Node node, String release, FilePath destination, String products, TaskListener log) throws IOException, InterruptedException { - Launcher matlabInstaller = node.createLauncher (log); + Launcher matlabInstaller = node.createLauncher(log); ProcStarter installerProc = matlabInstaller.launch (); - ArgumentListBuilder args = new ArgumentListBuilder (); - args.add (destination.getParent ().getRemote () + getNodeSpecificMPMExecutor (node)); - args.add ("install"); - appendReleaseToArguments (args, log); - args.add ("--destination=" + destination.getRemote ()); - addMatlabProductsToArgs (args); - installerProc.pwd (destination).cmds (args).stdout (log); + ArgumentListBuilder args = new ArgumentListBuilder(); + args.add(destination.getParent().getRemote() + getNodeSpecificMPMExecutor(node)); + args.add("install"); + appendReleaseToArguments(release,args, log); + args.add("--destination=" + destination.getRemote()); + addMatlabProductsToArgs(args, products); + installerProc.pwd(destination).cmds(args).stdout(log); int result; try { - result = installerProc.join (); + result = installerProc.join(); } catch (Exception e) { - log.getLogger ().println ("MATLAB installation failed " + e.getMessage ()); - throw new InstallationFailedException (e.getMessage ()); + log.getLogger().println("MATLAB installation failed " + e.getMessage()); + throw new InstallationFailedException(e.getMessage ()); } return result; } + private void makeDir(FilePath path) throws IOException, InterruptedException { - if(!path.exists ()){ - path.mkdirs (); - path.chmod (0777); + if(!path.exists()){ + path.mkdirs(); + path.chmod(0777); } } - private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { - String trimmedRelease = this.getVersion ().trim (); + private void appendReleaseToArguments(String release, ArgumentListBuilder args, TaskListener log) { + String trimmedRelease = release.trim(); String actualRelease = trimmedRelease; - if (trimmedRelease.equalsIgnoreCase ("latest") || trimmedRelease.equalsIgnoreCase ( + if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase( "latest-including-prerelease")) { String releaseInfoUrl = - Message.getValue ("matlab.release.info.url") + trimmedRelease; + Message.getValue("matlab.release.info.url") + trimmedRelease; String releaseVersion = null; try { - releaseVersion = IOUtils.toString (new URL (releaseInfoUrl), - StandardCharsets.UTF_8).trim (); + releaseVersion = IOUtils.toString(new URL(releaseInfoUrl), + StandardCharsets.UTF_8).trim(); } catch (IOException e) { - log.getLogger ().println ("Failed to fetch release version: " + e.getMessage ()); + log.getLogger().println("Failed to fetch release version: " + e.getMessage()); } - if (releaseVersion != null && releaseVersion.contains ("prerelease")) { - actualRelease = releaseVersion.replace ("prerelease", ""); + if (releaseVersion != null && releaseVersion.contains("prerelease")) { + actualRelease = releaseVersion.replace("prerelease", ""); args.add ("--release-status=Prerelease"); } else { actualRelease = releaseVersion; } } - args.add ("--release=" + actualRelease); + args.add("--release=" + actualRelease); } - private void getFreshCopyOfExecutables (MatlabInstallable installable, FilePath expectedPath) + private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) throws IOException, InterruptedException { - FilePath mpmPath = installable.getMpmInstallable (expectedPath); - FilePath mbatchPath = installable.getBatchInstallable (expectedPath); - mpmPath.copyFrom (new URL (installable.url).openStream ()); - mpmPath.chmod (0777); - mbatchPath.copyFrom (new URL (installable.batchURL).openStream ()); - mbatchPath.chmod (0777); + FilePath matlabBatchPath = new FilePath(expectedPath, "matlab-batch"); + FilePath mpmPath = new FilePath(expectedPath, "mpm"); + + URL mpmUrl; + URL matlabBatchUrl; + + switch (platform) { + case "glnxa64": + mpmUrl = new URL(Message.getValue("tools.matlab.mpm.installer.linux")); + matlabBatchUrl = new URL(Message.getValue("tools.matlab.batch.executable.linux")); + break; + case "maci64": + mpmUrl = new URL(Message.getValue("tools.matlab.mpm.installer.maci64")); + matlabBatchUrl = new URL(Message.getValue("tools.matlab.batch.executable.maci64")); + break; + case "maca64": + mpmUrl = new URL(Message.getValue("tools.matlab.mpm.installer.maca64")); + matlabBatchUrl = new URL(Message.getValue("tools.matlab.batch.executable.maca64")); + break; + default: + throw new InstallationFailedException("Unsupported OS"); + } + + mpmPath.copyFrom(mpmUrl.openStream()); + mpmPath.chmod(0777); + matlabBatchPath.copyFrom(matlabBatchUrl.openStream()); + matlabBatchPath.chmod(0777); } @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + "https://github.com/spotbugs/spotbugs/issues/1843") - private String getNodeSpecificMPMExecutor (Node node) { - if (!node.toComputer ().isUnix ()) { + private String getNodeSpecificMPMExecutor(Node node) { + if (!node.toComputer().isUnix()) { return "\\mpm.exe"; } return "/mpm"; } - private void addMatlabProductsToArgs (ArgumentListBuilder args) + private void addMatlabProductsToArgs(ArgumentListBuilder args, String products) throws IOException, InterruptedException { - args.add ("--products"); - if (this.getProducts ().isEmpty ()) { - args.add (DEFAULT_PRODUCT); + args.add("--products"); + if (products.isEmpty()) { + args.add(DEFAULT_PRODUCT); } else { - if (!this.getProducts ().contains (DEFAULT_PRODUCT)) { - args.add (DEFAULT_PRODUCT); + if (!products.contains(DEFAULT_PRODUCT)) { + args.add(DEFAULT_PRODUCT); } - String[] productList = this.getProducts ().split (" "); + String[] productList = products.split(" "); for (String prod : productList) { - args.add (prod); + args.add(prod); } } } - public Installable getInstallable (String[] systemProperties) throws IOException { - // Gather properties for the node to install on - return getInstallCandidate (systemProperties[0], systemProperties[1]); - } - - public MatlabInstallable getInstallCandidate (String osName, String architecture) - throws InstallationFailedException { - String platform = getPlatform (osName, architecture); - return new MatlabInstallable (platform); - } - - public String getPlatform (String os, String architecture) throws InstallationFailedException { - String value = os.toLowerCase (Locale.ENGLISH); - if (value.contains ("linux")) { + public String getPlatform(String os, String architecture) throws InstallationFailedException { + String value = os.toLowerCase(Locale.ENGLISH); + if (value.contains("linux")) { return "glnxa64"; - } else if (value.contains ("os x")) { - if (architecture.equalsIgnoreCase ("aarch64") || architecture.equalsIgnoreCase ( + } else if (value.contains("os x")) { + if (architecture.equalsIgnoreCase("aarch64") || architecture.equalsIgnoreCase ( "arm64")) { return "maca64"; } else { return "maci64"; } } else { - throw new InstallationFailedException ("Unsupported OS"); + throw new InstallationFailedException("Unsupported OS"); } } @@ -230,30 +233,30 @@ public String getPlatform (String os, String architecture) throws InstallationFa "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + "https://github.com/spotbugs/spotbugs/issues/1843") private String[] getSystemProperties(Node node) throws IOException, InterruptedException { - String[] properties = node.getChannel () - .call (new GetSystemProperties ("os.name", "os.arch", "os.version")); + String[] properties = node.getChannel() + .call (new GetSystemProperties("os.name", "os.arch", "os.version")); return properties; } @Extension public static final class DescriptorImpl extends ToolInstallerDescriptor { - public String getDisplayName () { - return Message.getValue ("matlab.tools.auto.install.display.name"); + public String getDisplayName() { + return Message.getValue("matlab.tools.auto.install.display.name"); } @Override - public boolean isApplicable (Class toolType) { + public boolean isApplicable(Class toolType) { return toolType == MatlabInstallation.class; } @POST - public FormValidation doCheckVersion (@QueryParameter String value) { - Jenkins.get ().checkPermission (Jenkins.ADMINISTER); - if (value.isEmpty ()) { - return FormValidation.error (Message.getValue ("tools.matlab.empty.version.error")); + public FormValidation doCheckRelease(@QueryParameter String value) { + Jenkins.get().checkPermission(Jenkins.ADMINISTER); + if (value.isEmpty()) { + return FormValidation.error(Message.getValue("tools.matlab.empty.release.error")); } - return FormValidation.ok (); + return FormValidation.ok(); } } -} \ No newline at end of file +} diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly index 9e59b102..7b7891db 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/config.jelly @@ -1,6 +1,6 @@ - + diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 7da01e12..9498c373 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -37,6 +37,6 @@ tools.matlab.mpm.installer.maci64 = https://www.mathworks.com/mpm/maci64/mpm tools.matlab.batch.executable.maci64 = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maci64/matlab-batch tools.matlab.mpm.installer.maca64 = https://www.mathworks.com/mpm/maca64/mpm tools.matlab.batch.executable.maca64 = https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v1/maca64/matlab-batch -tools.matlab.empty.version.error = MATLAB version is mandatory field. +tools.matlab.empty.release.error = MATLAB release is mandatory field. matlab.release.info.url = https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/ diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java deleted file mode 100644 index c764f3f3..00000000 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallableUnitTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.mathworks.ci.tools; - -import static org.junit.Assert.assertEquals; - -import java.io.File; -/** - * Copyright 2024, The MathWorks, Inc. - * - */ - -import org.junit.Rule; -import org.junit.Test; - -import hudson.FilePath; -import com.mathworks.ci.TestMessage; -import org.junit.rules.ExpectedException; - -public class MatlabInstallableUnitTest { - - @Rule - public ExpectedException exceptionRule = ExpectedException.none (); - - @Test - public void testValidWin64OS () throws InstallationFailedException { - exceptionRule.expect(InstallationFailedException.class); - exceptionRule.expectMessage("Unsupported OS"); - MatlabInstallable installable = new MatlabInstallable ("win64"); - - } - - @Test - public void testValidGlnxa64OS () throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable ("glnxa64"); - assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.linux"), installable.url); - assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.linux"), - installable.getBatchURL ()); - - FilePath expectedPath = new FilePath (new File ("/usr/local/install")); - assertEquals (new FilePath (expectedPath, "matlab-batch").getRemote (), - installable.getBatchInstallable (expectedPath).getRemote ()); - assertEquals (new FilePath (expectedPath, "mpm").getRemote (), - installable.getMpmInstallable (expectedPath).getRemote ()); - } - - @Test - public void testValidMaci64OS () throws InstallationFailedException { - MatlabInstallable installable = new MatlabInstallable ("maci64"); - assertEquals (TestMessage.getValue ("tools.matlab.mpm.installer.mac"), installable.url); - assertEquals (TestMessage.getValue ("tools.matlab.batch.executable.mac"), - installable.getBatchURL ()); - - FilePath expectedPath = new FilePath (new File ("/Applications/install")); - assertEquals (new FilePath (expectedPath, "matlab-batch").getRemote (), - installable.getBatchInstallable (expectedPath).getRemote ()); - assertEquals (new FilePath (expectedPath, "mpm").getRemote (), - installable.getMpmInstallable (expectedPath).getRemote ()); - } -} diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index 5e1bf34e..ce734c9d 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -53,8 +53,8 @@ public void setUp () throws Exception { } @Test - public void testGetVersion () { - assertEquals ("R2021a", installer.getVersion ()); + public void testGetRelease () { + assertEquals ("R2021a", installer.getRelease ()); } @Test From 1614850deb4b7d919abcac6684f55d43790e2e15 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 11:54:34 +0530 Subject: [PATCH 37/51] Changed Version to release in setter --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 008572af..eeaec301 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -61,7 +61,7 @@ public String getRelease() { } @DataBoundSetter - public void setVersion(String release) { + public void setRelease(String release) { this.release = release; } From 94c46cc241a9753baa19468c88ef9942555b74a8 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 12:05:50 +0530 Subject: [PATCH 38/51] Updated Version to Release --- .../unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index ce734c9d..e5c1e823 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -48,8 +48,8 @@ public class MatlabInstallerUnitTest { public void setUp () throws Exception { MockitoAnnotations.initMocks (this); installer = spy (new MatlabInstaller ("test-id")); - installer.setVersion ("R2021a"); - installer.setProducts ("MATLAB"); + installer.setRelease("R2021a"); + installer.setProducts("MATLAB"); } @Test From f8e20d26b6f550a343b4366218b637ce158dbeec Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 13:03:41 +0530 Subject: [PATCH 39/51] Revereted the mpm failure mechanism --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index eeaec301..419e8da8 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -90,8 +90,12 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen makeDir(matlabRootPath); int result = installUsingMpm(node, this.getRelease (), matlabRootPath, this.getProducts (), log); - if (result != 0) { - throw new InstallationFailedException("Unable to install MATLAB using mpm."); + if (result == 0) { + if (result == 0) { + log.getLogger ().println ( + "MATLAB installation of version " + this.getRelease() + + " using mpm completed successfully!"); + } } return matlabRootPath; } From 0b7681a153a37faeb99dbc13ea4db1feff057d91 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 13:55:04 +0530 Subject: [PATCH 40/51] Fixed spotbug --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 419e8da8..5602a21b 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -91,11 +91,9 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen makeDir(matlabRootPath); int result = installUsingMpm(node, this.getRelease (), matlabRootPath, this.getProducts (), log); if (result == 0) { - if (result == 0) { log.getLogger ().println ( "MATLAB installation of version " + this.getRelease() + " using mpm completed successfully!"); - } } return matlabRootPath; } From 61bc2b1934a1e910a7f0a16f14b04a43c77ad066 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 14:19:45 +0530 Subject: [PATCH 41/51] Changed name of release help --- .../MatlabInstaller/{help-version.html => help-release.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/com/mathworks/ci/tools/MatlabInstaller/{help-version.html => help-release.html} (100%) diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html similarity index 100% rename from src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-version.html rename to src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html From e5ab50b78db65d084e12fd8300cf15f535012e7e Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 16:00:02 +0530 Subject: [PATCH 42/51] Fixed issue 369 --- .../java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java | 1 - src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 7683f0b4..5395ef51 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -191,7 +191,6 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); - listener.getLogger().println("**The path which is trying to uppend is **" + matlabExecutablePath.getRemote ()); if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 5602a21b..f2493897 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -57,7 +57,7 @@ public MatlabInstaller(String id) { } public String getRelease() { - return this.release; + return this.release.trim(); } @DataBoundSetter From 858677493a147c6ca0a5bbbcf4f276089e0b2574 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 7 Nov 2024 17:54:51 +0530 Subject: [PATCH 43/51] Fixed issue 370 --- .../ci/tools/MatlabInstaller/help-release.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html index f5e80489..3e4388fd 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html @@ -4,11 +4,11 @@

    -
  • To install the latest update of a release, specify only the release name, for example, R2023b.
  • > -
  • To install a specific update release, specify the release name with an update number suffix, for example, R2023bU4.
  • > -
  • To install a release without updates, specify the release name with an update 0 or general release suffix, for example, R2023bU0 or R2023bGR.
  • > -
> -

> +
  • To install the latest update of a release, specify only the release name, for example, R2023b.
  • +
  • To install a specific update release, specify the release name with an update number suffix, for example, R2023bU4.
  • +
  • To install a release without updates, specify the release name with an update 0 or general release suffix, for example, R2023bU0 or R2023bGR.
  • + +

    Example: R2024a
    Example: latest
    From 32432d6c3dfac0e1a2e25ce91b6ddf6cdd2b37a6 Mon Sep 17 00:00:00 2001 From: David Buzinski <103441853+davidbuzinski@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:10:53 -0500 Subject: [PATCH 44/51] remove unused imports and fix validation bug (#375) (#377) --- src/main/java/com/mathworks/ci/tools/MatlabInstaller.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index f2493897..6c31b78a 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -25,25 +25,19 @@ import hudson.util.ArgumentListBuilder; import hudson.util.FormValidation; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashSet; import java.util.Locale; -import java.util.Set; import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; -import org.kohsuke.stapler.verb.POST; public class MatlabInstaller extends ToolInstaller { @@ -252,7 +246,6 @@ public boolean isApplicable(Class toolType) { return toolType == MatlabInstallation.class; } - @POST public FormValidation doCheckRelease(@QueryParameter String value) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); if (value.isEmpty()) { From fbb611e71a4ac3cc1cd9b8bc89340ffa1975a52f Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 22 Nov 2024 14:10:19 +0530 Subject: [PATCH 45/51] Fixed issue378 --- src/main/java/com/mathworks/ci/MatlabInstallation.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mathworks/ci/MatlabInstallation.java b/src/main/java/com/mathworks/ci/MatlabInstallation.java index a5867f71..82930080 100644 --- a/src/main/java/com/mathworks/ci/MatlabInstallation.java +++ b/src/main/java/com/mathworks/ci/MatlabInstallation.java @@ -10,6 +10,7 @@ import hudson.CopyOnWrite; import hudson.EnvVars; import hudson.Extension; +import hudson.FilePath; import hudson.Util; import hudson.model.EnvironmentSpecific; import hudson.model.Node; @@ -18,7 +19,10 @@ import hudson.tools.ToolDescriptor; import hudson.tools.ToolInstallation; import hudson.tools.ToolProperty; +import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import javax.annotation.CheckForNull; @@ -57,8 +61,11 @@ public MatlabInstallation forNode(@Nonnull Node node, TaskListener log) throws I @Override public void buildEnvVars(EnvVars env) { + FilePath batchExecutablePath = new FilePath (Jenkins.get().getChannel(), getHome()); String pathToExecutable = getHome() + "/bin"; - env.put ("PATH+matlab_batch", getHome ()); + if( batchExecutablePath.getParent () != null ){ + env.put ("PATH+matlab_batch", batchExecutablePath.getParent().getRemote()); + } env.put("PATH+matlabroot", pathToExecutable); } From a2ac30e2de8faa2c776fc2128b832a6baa391c2d Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 22 Nov 2024 15:21:26 +0530 Subject: [PATCH 46/51] Fixed 371 379 --- .../com/mathworks/ci/MatlabInstallation.java | 19 +++++++++++++++---- .../mathworks/ci/tools/MatlabInstaller.java | 2 +- .../tools/MatlabInstaller/help-release.html | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mathworks/ci/MatlabInstallation.java b/src/main/java/com/mathworks/ci/MatlabInstallation.java index 82930080..006beb23 100644 --- a/src/main/java/com/mathworks/ci/MatlabInstallation.java +++ b/src/main/java/com/mathworks/ci/MatlabInstallation.java @@ -7,6 +7,7 @@ * */ +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.CopyOnWrite; import hudson.EnvVars; import hudson.Extension; @@ -15,6 +16,7 @@ import hudson.model.EnvironmentSpecific; import hudson.model.Node; import hudson.model.TaskListener; +import hudson.remoting.VirtualChannel; import hudson.slaves.NodeSpecific; import hudson.tools.ToolDescriptor; import hudson.tools.ToolInstallation; @@ -59,14 +61,23 @@ public MatlabInstallation forNode(@Nonnull Node node, TaskListener log) throws I return new MatlabInstallation(getName(), translateFor(node, log), getProperties().toList()); } + @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, + justification = + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") @Override public void buildEnvVars(EnvVars env) { - FilePath batchExecutablePath = new FilePath (Jenkins.get().getChannel(), getHome()); String pathToExecutable = getHome() + "/bin"; - if( batchExecutablePath.getParent () != null ){ - env.put ("PATH+matlab_batch", batchExecutablePath.getParent().getRemote()); - } env.put("PATH+matlabroot", pathToExecutable); + Jenkins jenkinsInstance = Jenkins.getInstanceOrNull(); + if(jenkinsInstance != null){ + if(jenkinsInstance.getChannel() != null){ + FilePath batchExecutablePath = new FilePath(jenkinsInstance.getChannel (), getHome()); + if( batchExecutablePath.getParent() != null ){ + env.put ("PATH+matlab_batch", batchExecutablePath.getParent().getRemote()); + } + } + } } public static MatlabInstallation[] getAll () { diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 6c31b78a..04869d31 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -149,7 +149,7 @@ private void appendReleaseToArguments(String release, ArgumentListBuilder args, args.add("--release=" + actualRelease); } - private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) + synchronized private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) throws IOException, InterruptedException { FilePath matlabBatchPath = new FilePath(expectedPath, "matlab-batch"); FilePath mpmPath = new FilePath(expectedPath, "mpm"); diff --git a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html index 3e4388fd..804233bf 100644 --- a/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html +++ b/src/main/resources/com/mathworks/ci/tools/MatlabInstaller/help-release.html @@ -1,6 +1,6 @@

    - Insert the MATLAB version to install. To install the latest release of MATLAB, insert latest in the Version box. + Insert the MATLAB version to install. To install the latest release of MATLAB, insert latest in the Release box.

      From aa291d8f69a87ecb52dc6792289d4ce12bb6a088 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 22 Nov 2024 17:12:17 +0530 Subject: [PATCH 47/51] Fixed 374 --- .../ci/UseMatlabVersionBuildWrapper.java | 2 +- src/main/java/com/mathworks/ci/Utilities.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 5395ef51..700b7a58 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -51,7 +51,7 @@ public String getMatlabRootFolder() { public String getMatlabInstallationHome(Computer cmp, TaskListener listener, EnvVars env) throws IOException, InterruptedException { return Utilities.getNodeSpecificHome(this.matlabInstallationName, - cmp.getNode(), listener, env); + cmp.getNode(), listener, env).getRemote (); } public String getMatlabInstallationName() { diff --git a/src/main/java/com/mathworks/ci/Utilities.java b/src/main/java/com/mathworks/ci/Utilities.java index 900e3565..103ef67d 100644 --- a/src/main/java/com/mathworks/ci/Utilities.java +++ b/src/main/java/com/mathworks/ci/Utilities.java @@ -41,20 +41,28 @@ public static void addMatlabToEnvPathFromAxis(Computer cmp, TaskListener listene return; } + FilePath matlabRoot = getNodeSpecificHome(name, + cmp.getNode(), listener, env); + + if(matlabRoot != null && matlabRoot.getParent().exists()){ + env.put("PATH+matlab_batch", matlabRoot.getParent().getRemote()); + } + String matlabExecutablePath = getNodeSpecificHome(name, - cmp.getNode(), listener, env) + ((Boolean.TRUE.equals(cmp.isUnix()))?"/bin" : "\\bin"); + cmp.getNode(), listener, env).getRemote () + ((Boolean.TRUE.equals(cmp.isUnix()))?"/bin" : "\\bin"); env.put("PATH+matlabroot", matlabExecutablePath); + // Specify which MATLAB was added to path. listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath) + "\n"); } - public static String getNodeSpecificHome(String instName,Node node, TaskListener listener, EnvVars env) + public static FilePath getNodeSpecificHome(String instName,Node node, TaskListener listener, EnvVars env) throws IOException, InterruptedException { MatlabInstallation inst = MatlabInstallation.getInstallation(instName); if (inst == null || node == null) { // Following will error out in BuildWrapper - return ""; + throw new MatlabNotFoundError("MATLAB installations could not be found"); } // get installation for node and environment. @@ -66,6 +74,6 @@ public static String getNodeSpecificHome(String instName,Node node, TaskListener throw new MatlabNotFoundError(String.format(Message.getValue("matlab.not.found.error.for.node"), instName, Objects .requireNonNull(node).getDisplayName())); } - return matlabExecutablePath.getRemote(); + return matlabExecutablePath; } } From 058cd766b9eec248fbf99f65e9501f00c65dd4fc Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 22 Nov 2024 18:06:55 +0530 Subject: [PATCH 48/51] Fixed 371 --- .../com/mathworks/ci/tools/MatlabInstaller.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 04869d31..fefda583 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -148,8 +148,7 @@ private void appendReleaseToArguments(String release, ArgumentListBuilder args, } args.add("--release=" + actualRelease); } - - synchronized private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) + private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) throws IOException, InterruptedException { FilePath matlabBatchPath = new FilePath(expectedPath, "matlab-batch"); FilePath mpmPath = new FilePath(expectedPath, "mpm"); @@ -174,10 +173,12 @@ synchronized private void getFreshCopyOfExecutables(String platform, FilePath ex throw new InstallationFailedException("Unsupported OS"); } - mpmPath.copyFrom(mpmUrl.openStream()); - mpmPath.chmod(0777); - matlabBatchPath.copyFrom(matlabBatchUrl.openStream()); - matlabBatchPath.chmod(0777); + synchronized(this){ + mpmPath.copyFrom(mpmUrl.openStream()); + mpmPath.chmod(0777); + matlabBatchPath.copyFrom(matlabBatchUrl.openStream()); + matlabBatchPath.chmod(0777); + } } @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, From a7cb7703f77ae1c60bb9e755569b9ead4d89635b Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 25 Nov 2024 18:11:02 +0530 Subject: [PATCH 49/51] Fixed concurrency issue --- .../mathworks/ci/tools/MatlabInstaller.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index fefda583..5ff2c8f9 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -173,11 +173,24 @@ private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) throw new InstallationFailedException("Unsupported OS"); } - synchronized(this){ - mpmPath.copyFrom(mpmUrl.openStream()); - mpmPath.chmod(0777); - matlabBatchPath.copyFrom(matlabBatchUrl.openStream()); - matlabBatchPath.chmod(0777); + //Handle the concurrency issues due to same name. + FilePath tempMatlabBatchPath = new FilePath(expectedPath, "temp-matlab-batch"); + FilePath tempMpmPath = new FilePath(expectedPath, "temp-mpm"); + try{ + tempMpmPath.copyFrom(mpmUrl.openStream()); + tempMpmPath.chmod(0777); + tempMatlabBatchPath.copyFrom(matlabBatchUrl.openStream()); + tempMatlabBatchPath.chmod(0777); + + tempMpmPath.renameTo(mpmPath); + tempMatlabBatchPath.renameTo(matlabBatchPath); + + } catch(IOException | InterruptedException e){ + e.printStackTrace(); + } finally { + // Clean up temporary files if they exist + tempMatlabBatchPath.delete(); + tempMpmPath.delete(); } } From e2ea2bb31d7c4222e7a18341e27557a6a6398743 Mon Sep 17 00:00:00 2001 From: David Buzinski <103441853+davidbuzinski@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:22:44 -0500 Subject: [PATCH 50/51] Bump minimum jenkins version and fix failing tests (#381) * bump min jenkins version and fix failing tests * fix url warning in pom * update email in pom.xml --- pom.xml | 62 ++++++---- .../ci/RunMatlabBuildBuilderTest.java | 106 ++++++++-------- .../mathworks/ci/RunMatlabBuildStepTest.java | 4 +- .../ci/RunMatlabCommandBuilderTest.java | 105 ++++++++-------- .../ci/RunMatlabCommandStepTest.java | 4 +- .../ci/RunMatlabTestsBuilderTest.java | 113 +++++++++--------- .../mathworks/ci/RunMatlabTestsStepTest.java | 4 +- .../ci/UseMatlabVersionBuildWrapperTest.java | 4 +- 8 files changed, 213 insertions(+), 189 deletions(-) diff --git a/pom.xml b/pom.xml index 12c1b9fb..4c7117bd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,61 +4,74 @@ org.jenkins-ci.plugins plugin - 3.57 + 4.75 + matlab 2.15.1-SNAPSHOT hpi + + MATLAB Plugin + https://github.com/jenkinsci/matlab-plugin + Jenkins plugin for MATLAB + mathworks_ci_team MathWorks - nbhoski@mathworks.com + continuous-integration@mathworks.com - - 2.164.3 - 8 - - MATLAB Plugin - Jenkins plugin for MATLAB - https://github.com/jenkinsci/matlab-plugin + MIT License https://opensource.org/licenses/MIT + repo.jenkins-ci.org https://repo.jenkins-ci.org/public/ + repo.jenkins-ci.org https://repo.jenkins-ci.org/public/ + scm:git:ssh://github.com/jenkinsci/matlab-plugin.git scm:git:ssh://git@github.com/jenkinsci/matlab-plugin.git - http://github.com/jenkinsci/matlab-plugin + https://github.com/jenkinsci/matlab-plugin HEAD + + + + 2.387 + ${jenkins.baseline}.3 + + High + + io.jenkins.tools.bom - bom-2.164.x - 4 - import + bom-${jenkins.baseline}.x + 2543.vfb_1a_5fb_9496d pom + import + @@ -100,16 +113,25 @@ workflow-job test - - - org.mockito - mockito-core - 3.1.0 - test - + + org.mockito + mockito-core + 3.1.0 + test + + + org.eclipse.jetty + jetty-util + 11.0.24 + test + + + org.jenkins-ci.tools + maven-hpi-plugin + diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java index 4550b68d..1a39f312 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java @@ -305,56 +305,62 @@ public void verifyDefaultMatlabNotPicked() throws Exception { jenkins.assertLogContains("MatlabNotFoundError", build); } - /* - * Test to verify if Matrix build fails when MATLAB is not available. - * + /* + * Test to verify if Matrix build fails when MATLAB is not available. + * * NOTE: This test assumes there is no MATLAB installed and is not on System Path. * - */ - @Test - public void verifyMatrixBuildFails() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2015b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - - scriptBuilder.setTasks(""); - matrixProject.getBuildersList().add(scriptBuilder); - Map vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1); - jenkins.assertLogContains("buildtool", build); - jenkins.assertBuildStatus(Result.FAILURE, build); - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); - } - - /* - * Test to verify if Matrix build passes (mock MATLAB). - */ - @Test - public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, - "-positive"); - - tester.setTasks(""); - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); - } + */ + @Test + public void verifyMatrixBuildFails() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2015b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + + scriptBuilder.setTasks(""); + matrixProject.getBuildersList().add(scriptBuilder); + + // Check for first matrix combination. + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); + + jenkins.assertLogContains("buildtool", build1); + jenkins.assertBuildStatus(Result.FAILURE, build1); + + // Check for second Matrix combination + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); + } + + /* + * Test to verify if Matrix build passes (mock MATLAB). + */ + @Test + public void verifyMatrixBuildPasses() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, + "-positive"); + + tester.setTasks(""); + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); + } } diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java index 8deb0ca0..88072661 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java @@ -51,7 +51,7 @@ public void verifyMATLABPathNotSet() throws Exception { public void verifyMATLABstartsInWorkspace() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition( - new CpsFlowDefinition("node('!master') { runMATLABBuild() }", true)); + new CpsFlowDefinition("node('!built-in') { runMATLABBuild() }", true)); FilePath workspace = s.getWorkspaceFor(project); String workspaceName = workspace.getName(); @@ -78,7 +78,7 @@ public void verifyMATLABstartsInWorkspace() throws Exception { public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( - "node('!master') { runMATLABBuild() }", true)); + "node('!built-in') { runMATLABBuild() }", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java index cf28cbed..c8635f29 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java @@ -7,9 +7,9 @@ * */ -import com.gargoylesoftware.htmlunit.WebAssert; -import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; -import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.htmlunit.WebAssert; +import org.htmlunit.html.HtmlCheckBoxInput; +import org.htmlunit.html.HtmlPage; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -306,65 +306,63 @@ public void verifyDefaultMatlabNotPicked() throws Exception { jenkins.assertLogContains("MatlabNotFoundError", build); } - /* - * Test to verify if Matrix build fails when MATLAB is not available. + /* + * Test to verify if Matrix build fails when MATLAB is not available. * * NOTE: This test assumes there is no MATLAB installed and is not on System Path. * - */ - @Test - public void verifyMatrixBuildFails() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2015b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - - scriptBuilder.setMatlabCommand("pwd"); - matrixProject.getBuildersList().add(scriptBuilder); - Map vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1); - jenkins.assertLogContains("run-matlab-command", build); - jenkins.assertBuildStatus(Result.FAILURE, build); - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); - } + */ + @Test + public void verifyMatrixBuildFails() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2015b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + + scriptBuilder.setMatlabCommand("pwd"); + matrixProject.getBuildersList().add(scriptBuilder); + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1); + jenkins.assertLogContains("run-matlab-command", build); + jenkins.assertBuildStatus(Result.FAILURE, build); + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); + } - /* - * Test to verify if Matrix build passes (mock MATLAB). - */ - @Test - public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, - "-positive"); - - tester.setMatlabCommand("pwd"); - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); + /* + * Test to verify if Matrix build passes (mock MATLAB). + */ + @Test + public void verifyMatrixBuildPasses() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, + "-positive"); + + tester.setMatlabCommand("pwd"); + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); } - /* + /* * Test to verify if command parses succesfully when multiple combinations of * characters are passed. (candidate for integ-tests once integrated) */ - - public void verifyMultispecialChar() throws Exception { final String actualCommand = "!\"\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; @@ -384,7 +382,6 @@ public void verifyMultispecialChar() throws Exception { /* * Test to verify error message when command is empty. */ - @Test public void verifyErrorMessageOnEmptyCommand() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java index 66c8e834..f4b37d2a 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -50,7 +50,7 @@ public void verifyMATLABPathNotSet() throws Exception { public void verifyMATLABstartsInWorkspace() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition( - new CpsFlowDefinition("node('!master') { runMATLABCommand(command: 'pwd')}", true)); + new CpsFlowDefinition("node('!built-in') { runMATLABCommand(command: 'pwd')}", true)); FilePath workspace = s.getWorkspaceFor(project); String workspaceName = workspace.getName(); @@ -81,7 +81,7 @@ public void verifyMATLABstartsInWorkspace() throws Exception { public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( - "node('!master') { runMATLABCommand(command: 'pwd')}", true)); + "node('!built-in') { runMATLABCommand(command: 'pwd')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java index 56fc1d51..86454f33 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTest.java @@ -12,7 +12,7 @@ import java.net.URL; import java.util.*; import java.util.concurrent.ExecutionException; -import com.gargoylesoftware.htmlunit.html.HtmlInput; +import org.htmlunit.html.HtmlInput; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -20,10 +20,10 @@ import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; -import com.gargoylesoftware.htmlunit.WebAssert; -import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlSelect; +import org.htmlunit.WebAssert; +import org.htmlunit.html.HtmlCheckBoxInput; +import org.htmlunit.html.HtmlPage; +import org.htmlunit.html.HtmlSelect; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.CoberturaArtifact; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.JunitArtifact; import com.mathworks.ci.freestyle.RunMatlabTestsBuilder.ModelCovArtifact; @@ -410,66 +410,65 @@ public void verifyDefaultMatlabNotPicked() throws Exception { jenkins.assertLogContains("MatlabNotFoundError", build); } - /* - * Test to verify if Matrix build fails when MATLAB is not available. + /* + * Test to verify if Matrix build fails when MATLAB is not available. * * NOTE: This test assumes there is no MATLAB installed and is not on System Path. * - */ - @Test - public void verifyMatrixBuildFails() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2015b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); + */ + @Test + public void verifyMatrixBuildFails() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2015b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); - matrixProject.getBuildersList().add(testBuilder); + matrixProject.getBuildersList().add(testBuilder); - // Check for first matrix combination. + // Check for first matrix combination. - Map vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); - jenkins.assertLogContains("run-matlab-command", build1); - jenkins.assertBuildStatus(Result.FAILURE, build1); + jenkins.assertLogContains("run-matlab-command", build1); + jenkins.assertBuildStatus(Result.FAILURE, build1); - // Check for second Matrix combination - - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); - } - - /* - * Test to verify if Matrix build passes (mock MATLAB). - */ - @Test - public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabTestsBuilderTester tester = new RunMatlabTestsBuilderTester(matlabExecutorAbsolutePath, "-positive"); - - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("Triggering", build); - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); - } - - /* + // Check for second Matrix combination + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); + } + + /* + * Test to verify if Matrix build passes (mock MATLAB). + */ + @Test + public void verifyMatrixBuildPasses() throws Exception { + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabTestsBuilderTester tester = new RunMatlabTestsBuilderTester(matlabExecutorAbsolutePath, "-positive"); + + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("Triggering", build); + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); + } + + /* * Test to verify if MATALB scratch file is not in workspace. */ @Test diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java index 0c49d86f..87166fd5 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -47,7 +47,7 @@ public void verifyMATLABPathNotSet() throws Exception { /* - * VErify when MATLAB PATH is set. + * Verify when MATLAB PATH is set. */ @Test @@ -66,7 +66,7 @@ public void verifyMATLABPathSet() throws Exception { public void verifyOnslave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( - "node('!master') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); + "node('!built-in') {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); diff --git a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java index 4c2a73d1..851bfb2b 100644 --- a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java +++ b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java @@ -20,8 +20,8 @@ import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; -import com.gargoylesoftware.htmlunit.WebAssert; -import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.htmlunit.WebAssert; +import org.htmlunit.html.HtmlPage; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.tasks.BuildWrapper; From 11259b8c04270ea5252200bc110767cb83f23e85 Mon Sep 17 00:00:00 2001 From: David Buzinski <103441853+davidbuzinski@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:00:35 -0500 Subject: [PATCH 51/51] run default java formatter (#382) --- .../com/mathworks/ci/BuildArtifactAction.java | 21 +- .../com/mathworks/ci/BuildArtifactData.java | 1 - .../mathworks/ci/BuildConsoleAnnotator.java | 5 +- .../com/mathworks/ci/BuildTargetNote.java | 8 +- .../com/mathworks/ci/FormValidationUtil.java | 3 +- .../mathworks/ci/ListenerLogDecorator.java | 6 +- .../ci/MatlabBuildWrapperContent.java | 5 +- .../mathworks/ci/MatlabBuilderConstants.java | 37 +- .../ci/MatlabExecutionException.java | 3 +- .../com/mathworks/ci/MatlabInstallation.java | 37 +- .../mathworks/ci/MatlabInstallationAxis.java | 10 +- .../com/mathworks/ci/MatlabItemListener.java | 20 +- .../com/mathworks/ci/MatlabNotFoundError.java | 5 +- .../com/mathworks/ci/MatlabReleaseInfo.java | 72 +-- .../ci/MatlabVersionNotFoundException.java | 7 +- .../mathworks/ci/MatrixPatternResolver.java | 11 +- src/main/java/com/mathworks/ci/Message.java | 14 +- .../ci/UseMatlabVersionBuildWrapper.java | 56 ++- src/main/java/com/mathworks/ci/Utilities.java | 22 +- .../mathworks/ci/actions/MatlabAction.java | 18 +- .../ci/actions/MatlabActionFactory.java | 6 +- .../ci/actions/RunMatlabBuildAction.java | 24 +- .../ci/actions/RunMatlabCommandAction.java | 20 +- .../ci/actions/RunMatlabTestsAction.java | 27 +- .../ci/freestyle/RunMatlabBuildBuilder.java | 19 +- .../ci/freestyle/RunMatlabCommandBuilder.java | 22 +- .../ci/freestyle/RunMatlabTestsBuilder.java | 171 +++---- .../ci/freestyle/options/BuildOptions.java | 5 +- .../ci/freestyle/options/SelectByFolder.java | 8 +- .../ci/freestyle/options/SourceFolder.java | 14 +- .../freestyle/options/SourceFolderPaths.java | 9 +- .../ci/freestyle/options/StartupOptions.java | 7 +- .../ci/freestyle/options/TestFolders.java | 5 +- .../ci/parameters/BuildActionParameters.java | 7 +- .../parameters/CommandActionParameters.java | 7 +- .../ci/parameters/MatlabActionParameters.java | 4 +- .../ci/parameters/TestActionParameters.java | 6 +- .../ci/pipeline/MatlabBuildStepExecution.java | 8 +- .../pipeline/MatlabCommandStepExecution.java | 13 +- .../pipeline/MatlabRunTestsStepExecution.java | 10 +- .../ci/pipeline/RunMatlabBuildStep.java | 9 +- .../ci/pipeline/RunMatlabCommandStep.java | 7 +- .../ci/pipeline/RunMatlabTestsStep.java | 32 +- .../ci/tools/InstallationFailedException.java | 7 +- .../mathworks/ci/tools/MatlabInstaller.java | 68 ++- .../ci/utilities/GetSystemProperties.java | 11 +- .../ci/utilities/MatlabCommandRunner.java | 49 +- .../mathworks/ci/BuildArtifactActionTest.java | 152 +++--- .../mathworks/ci/MatlabInstallationTest.java | 30 +- .../ci/RunMatlabBuildBuilderTest.java | 159 +++--- .../ci/RunMatlabBuildBuilderTester.java | 6 +- .../mathworks/ci/RunMatlabBuildStepTest.java | 16 +- .../ci/RunMatlabCommandBuilderTest.java | 168 ++++--- .../ci/RunMatlabCommandBuilderTester.java | 3 - .../ci/RunMatlabCommandStepTest.java | 22 +- .../RunMatlabTestBuilderPersistenceTest.java | 19 +- .../ci/RunMatlabTestsBuilderTest.java | 474 +++++++++--------- .../ci/RunMatlabTestsBuilderTester.java | 12 +- .../mathworks/ci/RunMatlabTestsStepTest.java | 115 +++-- .../integ/com/mathworks/ci/TestMessage.java | 2 +- .../ci/UseMatlabVersionBuildWrapperTest.java | 77 +-- .../ci/actions/MatlabActionTest.java | 38 +- .../ci/actions/RunMatlabBuildActionTest.java | 36 +- .../actions/RunMatlabCommandActionTest.java | 27 +- .../ci/actions/RunMatlabTestsActionTest.java | 72 +-- .../RunMatlabBuildBuilderUnitTest.java | 14 +- .../RunMatlabCommandBuilderUnitTest.java | 14 +- .../RunMatlabTestsBuilderUnitTest.java | 245 +++++---- .../MatlabBuildStepExecutionUnitTest.java | 18 +- .../MatlabCommandStepExecutionUnitTest.java | 26 +- .../MatlabRunTestsStepExecutionUnitTest.java | 20 +- .../ci/tools/MatlabInstallerUnitTest.java | 39 +- .../GetSystemPropertiesUnitTest.java | 16 +- .../ci/utilities/MatlabCommandRunnerTest.java | 148 +++--- .../utilities/MatlabCommandRunnerTester.java | 21 +- 75 files changed, 1514 insertions(+), 1411 deletions(-) diff --git a/src/main/java/com/mathworks/ci/BuildArtifactAction.java b/src/main/java/com/mathworks/ci/BuildArtifactAction.java index cc50f9b7..e5c5b0fb 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactAction.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactAction.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import hudson.FilePath; @@ -36,16 +35,16 @@ public BuildArtifactAction(Run build, String actionID) { this.actionID = actionID; // Setting the counts of task when Action is created. - try{ + try { setCounts(); } catch (ParseException e) { throw new RuntimeException(e); - } catch (InterruptedException e){ + } catch (InterruptedException e) { throw new RuntimeException(e); } } - public String getActionID(){ + public String getActionID() { return (this.actionID == null) ? "" : this.actionID; } @@ -64,13 +63,13 @@ public String getDisplayName() { @CheckForNull @Override public String getUrlName() { - return (this.actionID == null) ? "buildresults" : "buildresults" + this.actionID ; + return (this.actionID == null) ? "buildresults" : "buildresults" + this.actionID; } public List getBuildArtifact() throws ParseException, InterruptedException, IOException { List artifactData = new ArrayList(); FilePath fl; - if(this.actionID == null){ + if (this.actionID == null) { fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + MatlabBuilderConstants.BUILD_ARTIFACT + ".json")); } else { @@ -147,7 +146,7 @@ public void setOwner(Run owner) { private void setCounts() throws InterruptedException, ParseException { List artifactData = new ArrayList(); FilePath fl; - if(this.actionID == null){ + if (this.actionID == null) { fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + MatlabBuilderConstants.BUILD_ARTIFACT + ".json")); } else { @@ -206,11 +205,11 @@ private void setCounts() throws InterruptedException, ParseException { private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) { // Iterates across all task attributes and updates String key = pair.getKey().toString(); - switch(key){ + switch (key) { case "duration": data.setTaskDuration(pair.getValue().toString()); break; - case "name" : + case "name": data.setTaskName(pair.getValue().toString()); break; case "description": @@ -225,7 +224,7 @@ private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) { case "skipReason": String skipReasonKey = pair.getValue().toString(); String skipReason; - switch(skipReasonKey){ + switch (skipReasonKey) { case "UpToDate": skipReason = "up-to-date"; break; @@ -242,7 +241,7 @@ private void iterateAllTaskAttributes(Entry pair, BuildArtifactData data) { } data.setSkipReason(skipReason); break; - default : + default: break; } } diff --git a/src/main/java/com/mathworks/ci/BuildArtifactData.java b/src/main/java/com/mathworks/ci/BuildArtifactData.java index eac3bc19..0ecd6926 100644 --- a/src/main/java/com/mathworks/ci/BuildArtifactData.java +++ b/src/main/java/com/mathworks/ci/BuildArtifactData.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ public class BuildArtifactData { diff --git a/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java b/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java index 8197b6d8..53a3fda2 100644 --- a/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java +++ b/src/main/java/com/mathworks/ci/BuildConsoleAnnotator.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import com.google.common.base.Charsets; @@ -39,7 +38,7 @@ private static byte[][] createBuildNotes() { ByteArrayOutputStream targetNote = new ByteArrayOutputStream(); new BuildTargetNote().encodeTo(targetNote); ByteArrayOutputStream outcomeNote = new ByteArrayOutputStream(); - return new byte[][]{targetNote.toByteArray(), outcomeNote.toByteArray()}; + return new byte[][] { targetNote.toByteArray(), outcomeNote.toByteArray() }; } catch (IOException e) { throw new RuntimeException(e); } @@ -71,7 +70,7 @@ private static class ConsoleLogFilterImpl extends ConsoleLogFilter implements Se private static final long serialVersionUID = 1; private byte[][] buildNotes = createBuildNotes(); - //Taking care of old MATLAB build actions. + // Taking care of old MATLAB build actions. private Object readResolve() { if (buildNotes == null) { buildNotes = createBuildNotes(); diff --git a/src/main/java/com/mathworks/ci/BuildTargetNote.java b/src/main/java/com/mathworks/ci/BuildTargetNote.java index b047105c..cf3062c9 100644 --- a/src/main/java/com/mathworks/ci/BuildTargetNote.java +++ b/src/main/java/com/mathworks/ci/BuildTargetNote.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import com.google.common.annotations.VisibleForTesting; @@ -14,7 +13,6 @@ import hudson.console.ConsoleNote; import java.util.regex.Pattern; - public class BuildTargetNote extends ConsoleNote { @VisibleForTesting @SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Visible for testing") @@ -26,10 +24,10 @@ public BuildTargetNote() { @Override public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) { MarkupText.SubText t = text.findToken(Pattern.compile("MATLAB-Build-")); - String taskName = text.subText(13, text.length()-2).getText(); - taskName = taskName.replace("]","").trim(); + String taskName = text.subText(13, text.length() - 2).getText(); + taskName = taskName.replace("]", "").trim(); if (t != null) - t.addMarkup(0, t.length()-1, "", ""); + t.addMarkup(0, t.length() - 1, "", ""); return null; } diff --git a/src/main/java/com/mathworks/ci/FormValidationUtil.java b/src/main/java/com/mathworks/ci/FormValidationUtil.java index 8ccba320..05f2c8c2 100644 --- a/src/main/java/com/mathworks/ci/FormValidationUtil.java +++ b/src/main/java/com/mathworks/ci/FormValidationUtil.java @@ -1,10 +1,9 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2019-2024 The MathWorks, Inc. * * This is Utility class which provides commonly used methods for form validations across builders - * */ import java.util.List; diff --git a/src/main/java/com/mathworks/ci/ListenerLogDecorator.java b/src/main/java/com/mathworks/ci/ListenerLogDecorator.java index 454f843e..9ea6af29 100644 --- a/src/main/java/com/mathworks/ci/ListenerLogDecorator.java +++ b/src/main/java/com/mathworks/ci/ListenerLogDecorator.java @@ -1,8 +1,8 @@ package com.mathworks.ci; -/* -* Copyright 2018 The MathWorks, Inc. -*/ +/** + * Copyright 2018-2024 The MathWorks, Inc. + */ import java.io.IOException; import java.io.OutputStream; diff --git a/src/main/java/com/mathworks/ci/MatlabBuildWrapperContent.java b/src/main/java/com/mathworks/ci/MatlabBuildWrapperContent.java index 193a84ab..9ccc7570 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuildWrapperContent.java +++ b/src/main/java/com/mathworks/ci/MatlabBuildWrapperContent.java @@ -1,10 +1,9 @@ package com.mathworks.ci; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Class to parse Stapler request for Use MATLAB Version build wrapper. - * */ import org.kohsuke.stapler.DataBoundConstructor; @@ -15,7 +14,7 @@ public class MatlabBuildWrapperContent { private final String matlabRootFolder; @DataBoundConstructor - public MatlabBuildWrapperContent(String matlabInstallationName, String matlabRootFolder){ + public MatlabBuildWrapperContent(String matlabInstallationName, String matlabRootFolder) { this.matlabInstallationName = matlabInstallationName; this.matlabRootFolder = matlabRootFolder; } diff --git a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java index 62b9c130..27a8b593 100644 --- a/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java +++ b/src/main/java/com/mathworks/ci/MatlabBuilderConstants.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /* - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2019-2024 The MathWorks, Inc. */ public class MatlabBuilderConstants { @@ -11,27 +11,28 @@ public class MatlabBuilderConstants { public static final double BASE_MATLAB_VERSION_COBERTURA_SUPPORT = 9.3; public static final double BASE_MATLAB_VERSION_MODELCOVERAGE_SUPPORT = 9.5; public static final double BASE_MATLAB_VERSION_EXPORTSTMRESULTS_SUPPORT = 9.6; - + public static final String MATLAB_RUNNER_TARGET_FILE = "Builder.matlab.runner.target.file.name"; public static final String MATLAB_TESTS_RUNNER_TARGET_FILE = "runMatlabTests.m"; public static final String MATLAB_RUNNER_RESOURCE = "com/mathworks/ci/MatlabBuilder/runMatlabTests.m"; public static final String AUTOMATIC_OPTION = "RunTestsAutomaticallyOption"; - - // Input parameter names (Passed to runMatlabTests.m as name-value pair arguments) + + // Input parameter names (Passed to runMatlabTests.m as name-value pair + // arguments) public static final String PDF_REPORT = "'PDFReport'"; public static final String TAP_RESULTS = "'TAPResults'"; public static final String JUNIT_RESULTS = "'JUnitResults'"; public static final String STM_RESULTS = "'SimulinkTestResults'"; public static final String COBERTURA_CODE_COVERAGE = "'CoberturaCodeCoverage'"; public static final String COBERTURA_MODEL_COVERAGE = "'CoberturaModelCoverage'"; - - //Matlab Script generator package + + // Matlab Script generator package public static final String MATLAB_SCRIPT_GENERATOR = "matlab-script-generator.zip"; - - //Test runner file prefix + + // Test runner file prefix public static final String MATLAB_TEST_RUNNER_FILE_PREFIX = "runner_"; - - //Temporary MATLAB folder name in workspace + + // Temporary MATLAB folder name in workspace public static final String TEMP_MATLAB_FOLDER_NAME = ".matlab"; // MATLAB default function/plugin paths @@ -39,15 +40,15 @@ public class MatlabBuilderConstants { public static final String BUILD_REPORT_PLUGIN = "+ciplugins/+jenkins/BuildReportPlugin.m"; public static final String TASK_RUN_PROGRESS_PLUGIN = "+ciplugins/+jenkins/TaskRunProgressPlugin.m"; public static final String BUILD_ARTIFACT = "buildArtifact"; - + public static final String NEW_LINE = System.getProperty("line.separator"); - //MATLAB Runner Script + // MATLAB Runner Script public static final String TEST_RUNNER_SCRIPT = String.join(NEW_LINE, - "addpath('${TEMP_FOLDER}');", - "testScript = genscript(${PARAMS});", - "disp('Running MATLAB script with content:');", - "disp(testScript.Contents);", - "fprintf('___________________________________\\n\\n');", - "run(testScript);"); + "addpath('${TEMP_FOLDER}');", + "testScript = genscript(${PARAMS});", + "disp('Running MATLAB script with content:');", + "disp(testScript.Contents);", + "fprintf('___________________________________\\n\\n');", + "run(testScript);"); } diff --git a/src/main/java/com/mathworks/ci/MatlabExecutionException.java b/src/main/java/com/mathworks/ci/MatlabExecutionException.java index ca7754bc..a0a0aa3b 100644 --- a/src/main/java/com/mathworks/ci/MatlabExecutionException.java +++ b/src/main/java/com/mathworks/ci/MatlabExecutionException.java @@ -1,8 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2021 The MathWorks, Inc. - * + * Copyright 2021-2024 The MathWorks, Inc. */ import java.lang.Exception; diff --git a/src/main/java/com/mathworks/ci/MatlabInstallation.java b/src/main/java/com/mathworks/ci/MatlabInstallation.java index 006beb23..5cace624 100644 --- a/src/main/java/com/mathworks/ci/MatlabInstallation.java +++ b/src/main/java/com/mathworks/ci/MatlabInstallation.java @@ -1,10 +1,9 @@ package com.mathworks.ci; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Describable class for adding MATLAB installations in Jenkins Global Tool configuration. - * */ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -36,7 +35,8 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.StaplerRequest; -public class MatlabInstallation extends ToolInstallation implements EnvironmentSpecific, NodeSpecific { +public class MatlabInstallation extends ToolInstallation + implements EnvironmentSpecific, NodeSpecific { private static final long serialVersionUID = 1L; @DataBoundConstructor @@ -45,14 +45,15 @@ public MatlabInstallation(String name, @CheckForNull String home, List { @CopyOnWrite private volatile MatlabInstallation[] installations = new MatlabInstallation[0]; diff --git a/src/main/java/com/mathworks/ci/MatlabInstallationAxis.java b/src/main/java/com/mathworks/ci/MatlabInstallationAxis.java index 67c33098..d19fbff7 100644 --- a/src/main/java/com/mathworks/ci/MatlabInstallationAxis.java +++ b/src/main/java/com/mathworks/ci/MatlabInstallationAxis.java @@ -1,11 +1,10 @@ package com.mathworks.ci; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Describable class for MATLAB Axis that provides a list of configured MATLAB installation for * generating matrix configurations. - * */ import hudson.Extension; @@ -34,7 +33,7 @@ static private List evaluateValues(List values) { } @Extension - public static class DescriptorImpl extends AxisDescriptor{ + public static class DescriptorImpl extends AxisDescriptor { @Override public String getDisplayName() { @@ -47,10 +46,11 @@ public boolean isInstantiable() { } public boolean checkUseMatlabVersion(Object it) { - return MatlabItemListener.getMatlabBuildWrapperCheckForPrj(((MatrixProject) it).getFullName()) && !isMatlabInstallationEmpty(); + return MatlabItemListener.getMatlabBuildWrapperCheckForPrj(((MatrixProject) it).getFullName()) + && !isMatlabInstallationEmpty(); } - public MatlabInstallation[] getInstallations () { + public MatlabInstallation[] getInstallations() { return MatlabInstallation.getAll(); } diff --git a/src/main/java/com/mathworks/ci/MatlabItemListener.java b/src/main/java/com/mathworks/ci/MatlabItemListener.java index 442d8e15..ea2d3bb5 100644 --- a/src/main/java/com/mathworks/ci/MatlabItemListener.java +++ b/src/main/java/com/mathworks/ci/MatlabItemListener.java @@ -1,11 +1,10 @@ package com.mathworks.ci; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Item listener class to provide functionality to check UI element states for a * Multi-configuration project. - * */ import hudson.Extension; @@ -27,28 +26,27 @@ public final class MatlabItemListener extends ItemListener { private static final Map prjCheckMatlabBuildWrapper = new HashMap<>(); @Override - public void onLoaded(){ + public void onLoaded() { checkItems(Jenkins.get().getItems()); } @Override public void onUpdated(Item item) { - if(!(item instanceof MatrixProject)){ + if (!(item instanceof MatrixProject)) { return; } checkSingleItem(item); } - private void checkItems(List items) { - for(TopLevelItem item : items){ - if(item instanceof MatrixProject){ + for (TopLevelItem item : items) { + if (item instanceof MatrixProject) { check((MatrixProject) item); } } } - private void checkSingleItem(Item item){ + private void checkSingleItem(Item item) { check((MatrixProject) item); } @@ -60,7 +58,7 @@ private void check(MatrixProject prj) { private void checkForAxis(MatrixProject prj) { boolean checkForAxis = false; Collection configurations = prj.getActiveConfigurations(); - for(MatrixConfiguration conf : configurations){ + for (MatrixConfiguration conf : configurations) { String matlabAxisValue = conf.getCombination().get(Message.getValue("Axis.matlab.key")); if (matlabAxisValue != null) { checkForAxis = true; @@ -72,8 +70,8 @@ private void checkForAxis(MatrixProject prj) { private void checkForBuildWrapper(MatrixProject prj) { boolean checkForBuildWrapper = false; - for(Object bWrapper : prj.getBuildWrappersList().toArray()) { - if(bWrapper instanceof UseMatlabVersionBuildWrapper){ + for (Object bWrapper : prj.getBuildWrappersList().toArray()) { + if (bWrapper instanceof UseMatlabVersionBuildWrapper) { checkForBuildWrapper = ((UseMatlabVersionBuildWrapper) bWrapper).getMatlabInstallationName() != null; break; } diff --git a/src/main/java/com/mathworks/ci/MatlabNotFoundError.java b/src/main/java/com/mathworks/ci/MatlabNotFoundError.java index a495f918..f69221bb 100644 --- a/src/main/java/com/mathworks/ci/MatlabNotFoundError.java +++ b/src/main/java/com/mathworks/ci/MatlabNotFoundError.java @@ -1,15 +1,14 @@ package com.mathworks.ci; /** - * Copyright 2020 The MathWorks, Inc. - * + * Copyright 2020-2024 The MathWorks, Inc. */ public class MatlabNotFoundError extends Error { private static final long serialVersionUID = 7918595075502022644L; - MatlabNotFoundError(String errorMessage){ + MatlabNotFoundError(String errorMessage) { super(errorMessage); } diff --git a/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java b/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java index 641a9958..0636ce66 100644 --- a/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java +++ b/src/main/java/com/mathworks/ci/MatlabReleaseInfo.java @@ -1,8 +1,10 @@ package com.mathworks.ci; /* - * Copyright 2019 The MathWorks, Inc. This Class provides MATLAB release information in the form of - * Version numbers. Class constructor requires MATLAB root as input parameter + * Copyright 2019-2024 The MathWorks, Inc. + * + * This Class provides MATLAB release information in the form of Version numbers. Class constructor + * requires MATLAB root as input parameter. */ import java.io.InputStream; @@ -36,9 +38,9 @@ public class MatlabReleaseInfo { private static final String VERSION_TAG = "version"; private static final String DESCRIPTION_TAG = "description"; private static final String DATE_TAG = "date"; - + private Map versionInfoCache = new HashMap(); - + public MatlabReleaseInfo(FilePath matlabRoot) { this.matlabRoot = matlabRoot; } @@ -71,19 +73,20 @@ public boolean verLessThan(double version) throws MatlabVersionNotFoundException return false; } } - - @SuppressFBWarnings(value = {"REC_CATCH_EXCEPTION", "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}, - justification = "REC_CATCH_EXCEPTION: Irrespective of exception type, intention is to handle it in same way." + + + @SuppressFBWarnings(value = { "REC_CATCH_EXCEPTION", + "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" }, justification = "REC_CATCH_EXCEPTION: Irrespective of exception type, intention is to handle it in same way." + + " Also, there is no intention to propagate any runtime exception up in the hierarchy." + "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE: This is a false positive reported by spotbugs for JDK 11 for try-with-resources block.") private Map getVersionInfoFromFile() throws MatlabVersionNotFoundException { if (MapUtils.isEmpty(versionInfoCache)) { try { FilePath versionFile = new FilePath(this.matlabRoot, VERSION_INFO_FILE); - if(versionFile.exists()) { + if (versionFile.exists()) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); String FEATURE = null; - try{ + try { FEATURE = "http://apache.org/xml/features/disallow-doctype-decl"; dbFactory.setFeature(FEATURE, true); dbFactory.setXIncludeAware(false); @@ -93,7 +96,7 @@ private Map getVersionInfoFromFile() throws MatlabVersionNotFoun } DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(versionFile.read()); - + doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName(VERSION_INFO_ROOT_TAG); @@ -113,35 +116,34 @@ private Map getVersionInfoFromFile() throws MatlabVersionNotFoun eElement.getElementsByTagName(DATE_TAG).item(0).getTextContent()); } } - } - else if(!this.matlabRoot.exists()){ + } else if (!this.matlabRoot.exists()) { throw new NotDirectoryException("Invalid matlabroot path"); - }else { - // Get the version information from Contents.m file when VersionInfo.xml is not - // present. - FilePath contentFile = new FilePath(this.matlabRoot, CONTENTS_FILE); - String actualVersion = null; - try (InputStream in = contentFile.read(); - BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { - - // Skip first line and capture the second line. - br.readLine(); - String versionLine = br.readLine(); - - Pattern p = Pattern.compile(VERSION_PATTERN); - Matcher m = p.matcher(versionLine); - if (m.find()) { - actualVersion = m.group(); - } - } - // Update the versionInfoCache with actual version extracted from Contents.m - versionInfoCache.put(VERSION_TAG, actualVersion); - } + } else { + // Get the version information from Contents.m file when VersionInfo.xml is not + // present. + FilePath contentFile = new FilePath(this.matlabRoot, CONTENTS_FILE); + String actualVersion = null; + try (InputStream in = contentFile.read(); + BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { + + // Skip first line and capture the second line. + br.readLine(); + String versionLine = br.readLine(); + + Pattern p = Pattern.compile(VERSION_PATTERN); + Matcher m = p.matcher(versionLine); + if (m.find()) { + actualVersion = m.group(); + } + } + // Update the versionInfoCache with actual version extracted from Contents.m + versionInfoCache.put(VERSION_TAG, actualVersion); + } } catch (Exception e) { throw new MatlabVersionNotFoundException( Message.getValue("Releaseinfo.matlab.version.not.found.error"), e); - } + } } return versionInfoCache; } - } \ No newline at end of file +} diff --git a/src/main/java/com/mathworks/ci/MatlabVersionNotFoundException.java b/src/main/java/com/mathworks/ci/MatlabVersionNotFoundException.java index 74232867..fe790f69 100644 --- a/src/main/java/com/mathworks/ci/MatlabVersionNotFoundException.java +++ b/src/main/java/com/mathworks/ci/MatlabVersionNotFoundException.java @@ -1,9 +1,10 @@ package com.mathworks.ci; /* - * Copyright 2018 The MathWorks, Inc. This Exception class provides a business exception for all - * Classes/methods which tries to get version information of MATLAB. - * + * Copyright 2018-2024 The MathWorks, Inc. + * + * This Exception class provides a business exception for all Classes/methods which tries to get + * version information of MATLAB. */ public class MatlabVersionNotFoundException extends Exception { diff --git a/src/main/java/com/mathworks/ci/MatrixPatternResolver.java b/src/main/java/com/mathworks/ci/MatrixPatternResolver.java index 77611061..71dfde68 100644 --- a/src/main/java/com/mathworks/ci/MatrixPatternResolver.java +++ b/src/main/java/com/mathworks/ci/MatrixPatternResolver.java @@ -1,9 +1,10 @@ package com.mathworks.ci; /* - * Copyright 2019 The MathWorks, Inc. + * Copyright 2019-2024 The MathWorks, Inc. * - * This is Matrix pattern resolver class which is a utility for identifying variables. Either $xyz, ${xyz} or ${a.b} but not $a.b, while ignoring "$$" + * This is Matrix pattern resolver class which is a utility for identifying variables. Either $xyz, + * ${xyz} or ${a.b} but not $a.b, while ignoring "$$" */ import java.util.regex.Matcher; @@ -12,15 +13,15 @@ public class MatrixPatternResolver { private String inputString; private static Pattern VARIBLE = Pattern.compile("\\$([A-Za-z0-9_]+|\\{[A-Za-z0-9_.]+\\}|\\$)"); - + public MatrixPatternResolver(String inputString) { this.inputString = inputString; } - + public String getInputString() { return this.inputString; } - + public boolean hasVariablePattern() { Matcher m = VARIBLE.matcher(getInputString()); return m.find(0); diff --git a/src/main/java/com/mathworks/ci/Message.java b/src/main/java/com/mathworks/ci/Message.java index 52e4c3e5..3159fe4f 100644 --- a/src/main/java/com/mathworks/ci/Message.java +++ b/src/main/java/com/mathworks/ci/Message.java @@ -1,10 +1,9 @@ package com.mathworks.ci; -/* Copyright 2018 The MathWorks, Inc. +/* Copyright 2018-2024 The MathWorks, Inc. * * This Class is wrapper to access the static configuration values across project. Acts as * Utility class to access key & value pairs from config.properties - * */ import java.util.ResourceBundle; @@ -14,22 +13,17 @@ public class Message { private static String MATLAB_BUILDER_DISPLAY_NAME = "Builder.display.name"; private static String CONFIG_FILE = "config"; - private static ResourceBundle rb = ResourceBundle.getBundle(CONFIG_FILE); - + private static ResourceBundle rb = ResourceBundle.getBundle(CONFIG_FILE); - public static String getBuilderDisplayName(){ + public static String getBuilderDisplayName() { return rb.getString(MATLAB_BUILDER_DISPLAY_NAME); - } - public static String getValue(String key){ + public static String getValue(String key) { return rb.getString(key); } - - - } diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index 700b7a58..12178b3c 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -1,11 +1,10 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2019-2024 The MathWorks, Inc. * * This class is BuildWrapper which accepts the "matlabroot" from user and updates the PATH varible with it. * which could be later used across build. - * */ import hudson.model.Item; @@ -42,7 +41,8 @@ public class UseMatlabVersionBuildWrapper extends SimpleBuildWrapper { private String matlabInstallationName; @DataBoundConstructor - public UseMatlabVersionBuildWrapper() {} + public UseMatlabVersionBuildWrapper() { + } public String getMatlabRootFolder() { return this.matlabRootFolder; @@ -51,22 +51,23 @@ public String getMatlabRootFolder() { public String getMatlabInstallationHome(Computer cmp, TaskListener listener, EnvVars env) throws IOException, InterruptedException { return Utilities.getNodeSpecificHome(this.matlabInstallationName, - cmp.getNode(), listener, env).getRemote (); + cmp.getNode(), listener, env).getRemote(); } public String getMatlabInstallationName() { - /* For backward compatibility assign installation name to custom + /* + * For backward compatibility assign installation name to custom * if matlabRootFolder is not null. - * */ - if(this.matlabRootFolder!=null && !this.matlabRootFolder.isEmpty()){ + */ + if (this.matlabRootFolder != null && !this.matlabRootFolder.isEmpty()) { this.matlabInstallationName = Message.getValue("matlab.custom.location"); } return matlabInstallationName; } @DataBoundSetter - public void setMatlabBuildWrapperContent(MatlabBuildWrapperContent matlabBuildWrapperContent){ - if (matlabBuildWrapperContent != null){ + public void setMatlabBuildWrapperContent(MatlabBuildWrapperContent matlabBuildWrapperContent) { + if (matlabBuildWrapperContent != null) { this.matlabInstallationName = matlabBuildWrapperContent.getMatlabInstallationName(); this.matlabRootFolder = matlabBuildWrapperContent.getMatlabRootFolder(); } @@ -76,7 +77,7 @@ private String getNodeSpecificMatlab(Computer cmp, TaskListener listener) throws IOException, InterruptedException { String matlabroot = getMatlabRootFolder(); // If matlabroot is null use matlab installation path - if (matlabroot == null || matlabroot.isEmpty()){ + if (matlabroot == null || matlabroot.isEmpty()) { matlabroot = getMatlabInstallationHome(cmp, listener, this.env); } @@ -136,22 +137,24 @@ public String getMatlabAxisWarning() { } /* - * Below methods with 'doCheck' prefix gets called by jenkins when this builder is loaded. - * these methods are used to perform basic validation on UI elements associated with this + * Below methods with 'doCheck' prefix gets called by jenkins when this builder + * is loaded. + * these methods are used to perform basic validation on UI elements associated + * with this * descriptor class. */ @POST - public FormValidation doCheckMatlabRootFolder(@QueryParameter String matlabRootFolder, @AncestorInPath Item item) { + public FormValidation doCheckMatlabRootFolder(@QueryParameter String matlabRootFolder, + @AncestorInPath Item item) { if (item == null) { return FormValidation.ok(); } item.checkPermission(Item.CONFIGURE); - List> listOfCheckMethods = - new ArrayList>(); + List> listOfCheckMethods = new ArrayList>(); listOfCheckMethods.add(chkMatlabEmpty); listOfCheckMethods.add(chkMatlabSupportsRunTests); - return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,matlabRootFolder); + return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods, matlabRootFolder); } Function chkMatlabEmpty = (String matlabRootFolder) -> { @@ -188,30 +191,33 @@ public void setUp(Context context, Run build, FilePath workspace, Launcher // Set Environment variable setEnv(initialEnvironment); - - String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + getNodeSpecificExecutable(launcher); + String nodeSpecificMatlab = getNodeSpecificMatlab(Computer.currentComputer(), listener) + + getNodeSpecificExecutable(launcher); FilePath matlabExecutablePath = new FilePath(launcher.getChannel(), nodeSpecificMatlab); if (!matlabExecutablePath.exists()) { throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error")); } // Add matlab-batch executable in path FilePath batchExecutable = getNthParentFilePath(matlabExecutablePath, 3); - if(batchExecutable != null && batchExecutable.exists ()){ - context.env("PATH+matlab_batch", batchExecutable.getRemote ()); + if (batchExecutable != null && batchExecutable.exists()) { + context.env("PATH+matlab_batch", batchExecutable.getRemote()); } - // Add "matlabroot" without bin as env variable which will be available across the build. + // Add "matlabroot" without bin as env variable which will be available across + // the build. context.env("matlabroot", nodeSpecificMatlab); // Add matlab bin to path to invoke MATLAB directly on command line. - context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());; - listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath.getParent().getRemote()) + "\n"); + context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote()); + ; + listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), + matlabExecutablePath.getParent().getRemote()) + "\n"); } private String getNodeSpecificExecutable(Launcher launcher) { return (launcher.isUnix()) ? "/bin/matlab" : "\\bin\\matlab.exe"; } - public static FilePath getNthParentFilePath (FilePath path, int levels) { + public static FilePath getNthParentFilePath(FilePath path, int levels) { if (path == null || levels < 0) { return null; } @@ -221,7 +227,7 @@ public static FilePath getNthParentFilePath (FilePath path, int levels) { if (currentPath == null) { return null; } - currentPath = currentPath.getParent (); + currentPath = currentPath.getParent(); } return currentPath; } diff --git a/src/main/java/com/mathworks/ci/Utilities.java b/src/main/java/com/mathworks/ci/Utilities.java index 103ef67d..999649f0 100644 --- a/src/main/java/com/mathworks/ci/Utilities.java +++ b/src/main/java/com/mathworks/ci/Utilities.java @@ -4,7 +4,6 @@ * Copyright 2020-2024 The MathWorks, Inc. * * Utility class for common methods. - * */ import hudson.EnvVars; @@ -21,7 +20,7 @@ public class Utilities { - public static String getCellArrayFromList(List listOfStr){ + public static String getCellArrayFromList(List listOfStr) { // Ignore empty string values in the list Predicate isEmpty = String::isEmpty; Predicate isNotEmpty = isEmpty.negate(); @@ -37,27 +36,27 @@ public static void addMatlabToEnvPathFromAxis(Computer cmp, TaskListener listene String name = env.get(Message.getValue("Axis.matlab.key")); // If no MATLAB axis is set or if 'Use MATLAB version' is selected, return - if (name == null || name.isEmpty() || env.get("matlabroot") != null){ + if (name == null || name.isEmpty() || env.get("matlabroot") != null) { return; } FilePath matlabRoot = getNodeSpecificHome(name, - cmp.getNode(), listener, env); + cmp.getNode(), listener, env); - if(matlabRoot != null && matlabRoot.getParent().exists()){ + if (matlabRoot != null && matlabRoot.getParent().exists()) { env.put("PATH+matlab_batch", matlabRoot.getParent().getRemote()); } String matlabExecutablePath = getNodeSpecificHome(name, - cmp.getNode(), listener, env).getRemote () + ((Boolean.TRUE.equals(cmp.isUnix()))?"/bin" : "\\bin"); + cmp.getNode(), listener, env).getRemote() + ((Boolean.TRUE.equals(cmp.isUnix())) ? "/bin" : "\\bin"); env.put("PATH+matlabroot", matlabExecutablePath); - // Specify which MATLAB was added to path. - listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath) + "\n"); + listener.getLogger().println( + "\n" + String.format(Message.getValue("matlab.added.to.path.from"), matlabExecutablePath) + "\n"); } - public static FilePath getNodeSpecificHome(String instName,Node node, TaskListener listener, EnvVars env) + public static FilePath getNodeSpecificHome(String instName, Node node, TaskListener listener, EnvVars env) throws IOException, InterruptedException { MatlabInstallation inst = MatlabInstallation.getInstallation(instName); if (inst == null || node == null) { @@ -71,8 +70,9 @@ public static FilePath getNodeSpecificHome(String instName,Node node, TaskListen FilePath matlabExecutablePath = node.createPath(inst.getHome()); // If no MATLAB version is configured for current node, throw error. if (matlabExecutablePath == null || !matlabExecutablePath.exists()) { - throw new MatlabNotFoundError(String.format(Message.getValue("matlab.not.found.error.for.node"), instName, Objects - .requireNonNull(node).getDisplayName())); + throw new MatlabNotFoundError( + String.format(Message.getValue("matlab.not.found.error.for.node"), instName, Objects + .requireNonNull(node).getDisplayName())); } return matlabExecutablePath; } diff --git a/src/main/java/com/mathworks/ci/actions/MatlabAction.java b/src/main/java/com/mathworks/ci/actions/MatlabAction.java index df93b8d0..879817ae 100644 --- a/src/main/java/com/mathworks/ci/actions/MatlabAction.java +++ b/src/main/java/com/mathworks/ci/actions/MatlabAction.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import com.mathworks.ci.BuildArtifactAction; @@ -21,7 +20,7 @@ public class MatlabAction { BuildConsoleAnnotator annotator; String actionID; - public String getActionID(){ + public String getActionID() { return (this.actionID == null) ? "" : this.actionID; } @@ -38,8 +37,10 @@ public MatlabAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator) public void copyBuildPluginsToTemp() throws IOException, InterruptedException { // Copy plugins and override default plugins function runner.copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); - runner.copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); - runner.copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, + MatlabBuilderConstants.BUILD_REPORT_PLUGIN); + runner.copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, + MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); } public void setBuildEnvVars() throws IOException, InterruptedException { @@ -47,7 +48,7 @@ public void setBuildEnvVars() throws IOException, InterruptedException { runner.addEnvironmentVariable( "MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE", "ciplugins.jenkins.getDefaultPlugins"); - runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID()); + runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID", this.getActionID()); runner.addEnvironmentVariable( "MW_MATLAB_TEMP_FOLDER", runner.getTempFolder().toString()); @@ -55,7 +56,7 @@ public void setBuildEnvVars() throws IOException, InterruptedException { public void teardownAction(Run build) { // Handle build result - if(this.annotator != null) { + if (this.annotator != null) { moveJsonArtifactToBuildRoot(build, MatlabBuilderConstants.BUILD_ARTIFACT); } @@ -66,15 +67,14 @@ public void teardownAction(Run build) { } } - private void moveJsonArtifactToBuildRoot(Run build, String artifactBaseName) { + private void moveJsonArtifactToBuildRoot(Run build, String artifactBaseName) { try { FilePath file = new FilePath(this.runner.getTempFolder(), artifactBaseName + ".json"); if (file.exists()) { FilePath rootLocation = new FilePath( new File( build.getRootDir().getAbsolutePath(), - artifactBaseName + this.getActionID() + ".json") - ); + artifactBaseName + this.getActionID() + ".json")); file.copyTo(rootLocation); file.delete(); build.addAction(new BuildArtifactAction(build, this.getActionID())); diff --git a/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java b/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java index d5892789..f020b7dd 100644 --- a/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java +++ b/src/main/java/com/mathworks/ci/actions/MatlabActionFactory.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.Serializable; @@ -10,7 +9,8 @@ import com.mathworks.ci.parameters.*; public class MatlabActionFactory implements Serializable { - public RunMatlabCommandAction createAction(CommandActionParameters params) throws IOException, InterruptedException { + public RunMatlabCommandAction createAction(CommandActionParameters params) + throws IOException, InterruptedException { return new RunMatlabCommandAction(params); } @@ -18,7 +18,7 @@ public RunMatlabBuildAction createAction(BuildActionParameters params) throws IO return new RunMatlabBuildAction(params); } - public RunMatlabTestsAction createAction(TestActionParameters params) throws IOException, InterruptedException { + public RunMatlabTestsAction createAction(TestActionParameters params) throws IOException, InterruptedException { return new RunMatlabTestsAction(params); } } diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java index c4e48ef6..9083e39d 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -17,16 +16,17 @@ public class RunMatlabBuildAction extends MatlabAction { private BuildActionParameters params; - public RunMatlabBuildAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, BuildActionParameters params) { + public RunMatlabBuildAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, + BuildActionParameters params) { super(runner, annotator); this.params = params; } public RunMatlabBuildAction(BuildActionParameters params) throws IOException, InterruptedException { - this(new MatlabCommandRunner(params), + this(new MatlabCommandRunner(params), new BuildConsoleAnnotator( - params.getTaskListener().getLogger(), - params.getBuild().getCharset()), + params.getTaskListener().getLogger(), + params.getBuild().getCharset()), params); } @@ -39,10 +39,10 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep // Prepare the build tool command // TODO: Devise better solution then prepending the command - // here. - String command = "addpath('" - + runner.getTempFolder().getRemote() - + "'); buildtool"; + // here. + String command = "addpath('" + + runner.getTempFolder().getRemote() + + "'); buildtool"; if (params.getTasks() != null) { command += " " + params.getTasks(); @@ -56,8 +56,8 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep runner.runMatlabCommand(command); } catch (Exception e) { this.params.getTaskListener().getLogger() - .println(e.getMessage()); - throw(e); + .println(e.getMessage()); + throw (e); } finally { annotator.forceEol(); @@ -65,4 +65,4 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep super.teardownAction(build); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java index 72e942f8..3a59669a 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -17,16 +16,17 @@ public class RunMatlabCommandAction extends MatlabAction { private CommandActionParameters params; - public RunMatlabCommandAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, CommandActionParameters params) { + public RunMatlabCommandAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, + CommandActionParameters params) { super(runner, annotator); this.params = params; } public RunMatlabCommandAction(CommandActionParameters params) throws IOException, InterruptedException { - this(new MatlabCommandRunner(params), + this(new MatlabCommandRunner(params), new BuildConsoleAnnotator( - params.getTaskListener().getLogger(), - params.getBuild().getCharset()), + params.getTaskListener().getLogger(), + params.getBuild().getCharset()), params); } @@ -38,16 +38,16 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep runner.redirectStdOut(annotator); // Prepare MATLAB command - String command = "addpath('" - + runner.getTempFolder().getRemote() - + "'); " + this.params.getCommand(); + String command = "addpath('" + + runner.getTempFolder().getRemote() + + "'); " + this.params.getCommand(); try { runner.runMatlabCommand(command); } catch (Exception e) { this.params.getTaskListener().getLogger() - .println(e.getMessage()); - throw(e); + .println(e.getMessage()); + throw (e); } finally { annotator.forceEol(); diff --git a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java index 0156bbb4..6482fdfe 100644 --- a/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java +++ b/src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -41,19 +40,19 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep String command = MatlabBuilderConstants.TEST_RUNNER_SCRIPT; command = command.replace("${TEMP_FOLDER}", runner.getTempFolder().getRemote()); command = command.replace("${PARAMS}", getParameterString()); - + // Run the command try { runner.runMatlabCommand(command); } catch (Exception e) { this.params.getTaskListener() - .getLogger() - .println(e.getMessage()); - throw(e); + .getLogger() + .println(e.getMessage()); + throw (e); } finally { Run build = this.params.getBuild(); super.teardownAction(build); - } + } } private String singleQuotify(String in) { @@ -72,15 +71,15 @@ private String getParameterString() { String sourceFolders = null; if (this.params.getSourceFolder() != null) { sourceFolders = this.params.getSourceFolder().size() == 0 - ? null - : Utilities.getCellArrayFromList(this.params.getSourceFolder()); + ? null + : Utilities.getCellArrayFromList(this.params.getSourceFolder()); } String selectFolders = null; if (this.params.getSelectByFolder() != null) { selectFolders = this.params.getSelectByFolder().size() == 0 - ? null - : Utilities.getCellArrayFromList(this.params.getSelectByFolder()); + ? null + : Utilities.getCellArrayFromList(this.params.getSelectByFolder()); } // All string-based fields @@ -99,7 +98,7 @@ private String getParameterString() { "'SourceFolder'", "'SelectByFolder'" }; - final String[] values = { + final String[] values = { this.params.getTestResultsPDF(), this.params.getTestResultsTAP(), this.params.getTestResultsJUnit(), @@ -119,12 +118,12 @@ private String getParameterString() { if (values[i] != null && !values[i].equals("false")) { inputArgsList.add(names[i]); String arg = values[i].equals("true") || values[i].startsWith("{") - ? values[i] - : singleQuotify(values[i]); + ? values[i] + : singleQuotify(values[i]); inputArgsList.add(arg); } } - + return String.join(",", inputArgsList); } } diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabBuildBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabBuildBuilder.java index 89465b89..9b74f813 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabBuildBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabBuildBuilder.java @@ -2,7 +2,6 @@ /** * Copyright 2022-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -78,8 +77,8 @@ public StartupOptions getStartupOptions() { public String getStartupOptionsAsString() { return this.startupOptions == null - ? "" - : this.startupOptions.getOptions(); + ? "" + : this.startupOptions.getOptions(); } public BuildOptions getBuildOptions() { @@ -88,10 +87,10 @@ public BuildOptions getBuildOptions() { public String getBuildOptionsAsString() { return this.buildOptions == null - ? null - : this.buildOptions.getOptions(); + ? null + : this.buildOptions.getOptions(); } - + @Extension public static class RunMatlabBuildDescriptor extends BuildStepDescriptor { @@ -113,11 +112,13 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc } /* - * This is to identify which project type in jenkins this should be applicable.(non-Javadoc) + * This is to identify which project type in jenkins this should be + * applicable.(non-Javadoc) * * @see hudson.tasks.BuildStepDescriptor#isApplicable(java.lang.Class) * - * if it returns true then this build step will be applicable for all project type. + * if it returns true then this build step will be applicable for all project + * type. */ @Override public boolean isApplicable( @@ -149,7 +150,7 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, } // Added for backwards compatibility: - // Called when object is loaded from persistent data. + // Called when object is loaded from persistent data. protected Object readResolve() { if (factory == null) { factory = new MatlabActionFactory(); diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java index c97cb6f3..3a0c6346 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java @@ -4,7 +4,6 @@ * Copyright 2019-2024 The MathWorks, Inc. * * Script builder used to run custom MATLAB commands or scripts. - * */ import hudson.util.FormValidation; @@ -78,16 +77,17 @@ public StartupOptions getStartupOptions() { public String getStartupOptionsAsString() { return this.startupOptions == null - ? "" - : this.startupOptions.getOptions(); + ? "" + : this.startupOptions.getOptions(); } - + @Extension public static class RunMatlabCommandDescriptor extends BuildStepDescriptor { @Initializer(before = InitMilestone.PLUGINS_STARTED) public static void addAliases() { - Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.RunMatlabCommandBuilder", RunMatlabCommandBuilder.class); + Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.RunMatlabCommandBuilder", + RunMatlabCommandBuilder.class); } // Overridden Method used to show the text under build dropdown @@ -103,11 +103,13 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc } /* - * This is to identify which project type in jenkins this should be applicable.(non-Javadoc) + * This is to identify which project type in jenkins this should be + * applicable.(non-Javadoc) * * @see hudson.tasks.BuildStepDescriptor#isApplicable(java.lang.Class) * - * if it returns true then this build step will be applicable for all project type. + * if it returns true then this build step will be applicable for all project + * type. */ @Override public boolean isApplicable( @@ -134,8 +136,8 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, final EnvVars env = build.getEnvironment(listener); CommandActionParameters params = new CommandActionParameters( - build, workspace, env, - launcher, listener, + build, workspace, env, + launcher, listener, getStartupOptionsAsString(), getMatlabCommand()); RunMatlabCommandAction action = factory.createAction(params); @@ -148,7 +150,7 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, } // Added for backwards compatibility: - // Called when object is loaded from persistent data. + // Called when object is loaded from persistent data. protected Object readResolve() { if (factory == null) { factory = new MatlabActionFactory(); diff --git a/src/main/java/com/mathworks/ci/freestyle/RunMatlabTestsBuilder.java b/src/main/java/com/mathworks/ci/freestyle/RunMatlabTestsBuilder.java index 4868d83a..5b4096e3 100644 --- a/src/main/java/com/mathworks/ci/freestyle/RunMatlabTestsBuilder.java +++ b/src/main/java/com/mathworks/ci/freestyle/RunMatlabTestsBuilder.java @@ -5,7 +5,6 @@ * * MATLAB test run builder used to run all MATLAB & Simulink tests automatically and generate * selected test artifacts. - * */ import java.io.IOException; @@ -44,7 +43,6 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep { - // Make all old values transient which protects them writing back on disk. private transient int buildResult; private transient boolean tapChkBx; @@ -53,14 +51,14 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep { private transient boolean stmResultsChkBx; private transient boolean modelCoverageChkBx; private transient boolean pdfReportChkBx; - + private Artifact tapArtifact = new NullArtifact(); private Artifact junitArtifact = new NullArtifact(); private Artifact coberturaArtifact = new NullArtifact(); private Artifact stmResultsArtifact = new NullArtifact(); private Artifact modelCoverageArtifact = new NullArtifact(); private Artifact pdfReportArtifact = new NullArtifact(); - + private SourceFolder sourceFolder; private SelectByFolder selectByFolder; private SelectByTag selectByTag; @@ -80,57 +78,57 @@ public RunMatlabTestsBuilder(MatlabActionFactory factory) { public RunMatlabTestsBuilder() { this(new MatlabActionFactory()); } - + // Getter and Setters to access local members @DataBoundSetter public void setTapArtifact(TapArtifact tapArtifact) { this.tapArtifact = tapArtifact; - } - + } + @DataBoundSetter public void setJunitArtifact(JunitArtifact junitArtifact) { this.junitArtifact = junitArtifact; } - + @DataBoundSetter public void setCoberturaArtifact(CoberturaArtifact coberturaArtifact) { this.coberturaArtifact = coberturaArtifact; } - + @DataBoundSetter public void setStmResultsArtifact(StmResultsArtifact stmResultsArtifact) { this.stmResultsArtifact = stmResultsArtifact; } - + @DataBoundSetter public void setModelCoverageArtifact(ModelCovArtifact modelCoverageArtifact) { this.modelCoverageArtifact = modelCoverageArtifact; - } + } @DataBoundSetter public void setPdfReportArtifact(PdfArtifact pdfReportArtifact) { this.pdfReportArtifact = pdfReportArtifact; } - + @DataBoundSetter public void setSelectByTag(SelectByTag selectByTag) { this.selectByTag = selectByTag; } - + @DataBoundSetter public void setSourceFolder(SourceFolder sourceFolder) { this.sourceFolder = sourceFolder; } - + @DataBoundSetter public void setSelectByFolder(SelectByFolder selectByFolder) { - this.selectByFolder = selectByFolder; + this.selectByFolder = selectByFolder; } - + @DataBoundSetter public void setStartupOptions(StartupOptions startupOptions) { - this.startupOptions = startupOptions; + this.startupOptions = startupOptions; } @DataBoundSetter @@ -155,59 +153,60 @@ public void setStrict(boolean strict) { public String getTapReportFilePath() { return this.getTapArtifact().getFilePath(); - } - + } + public Artifact getTapArtifact() { return this.tapArtifact; } - + public Artifact getJunitArtifact() { return this.junitArtifact; } - + public String getJunitReportFilePath() { return this.getJunitArtifact().getFilePath(); } - + public Artifact getCoberturaArtifact() { return this.coberturaArtifact; } - + public String getCoberturaReportFilePath() { return this.getCoberturaArtifact().getFilePath(); } - + public Artifact getStmResultsArtifact() { return this.stmResultsArtifact; - } - + } + public String getStmResultsFilePath() { return this.getStmResultsArtifact().getFilePath(); } - + public Artifact getModelCoverageArtifact() { return this.modelCoverageArtifact; } - + public String getModelCoverageFilePath() { return this.getModelCoverageArtifact().getFilePath(); } - + public Artifact getPdfReportArtifact() { return this.pdfReportArtifact; } - + public String getPdfReportFilePath() { return this.getPdfReportArtifact().getFilePath(); } + public SelectByTag getSelectByTag() { - return this.selectByTag; + return this.selectByTag; } public String getSelectByTagAsString() { return this.selectByTag == null - ? null - : selectByTag.getTestTag(); + ? null + : selectByTag.getTestTag(); }; public SourceFolder getSourceFolder() { @@ -216,25 +215,25 @@ public SourceFolder getSourceFolder() { public List getSourceFolderPaths() { return this.sourceFolder == null - ? null - : this.sourceFolder.getSourceFolderStringPaths(); + ? null + : this.sourceFolder.getSourceFolderStringPaths(); } - + public SelectByFolder getSelectByFolder() { - return this.selectByFolder; + return this.selectByFolder; } public List getSelectByFolderPaths() { return this.selectByFolder == null - ? null - : this.selectByFolder.getTestFolderStringPaths(); + ? null + : this.selectByFolder.getTestFolderStringPaths(); } - private Artifact getArtifactObject(boolean isChecked, Artifact returnVal) { + private Artifact getArtifactObject(boolean isChecked, Artifact returnVal) { // If previously checked assign valid artifact object else NullArtifact. return (isChecked) ? returnVal : new NullArtifact(); } - + // Verbosity level public String getLoggingLevel() { @@ -259,40 +258,38 @@ public StartupOptions getStartupOptions() { public String getStartupOptionsAsString() { return this.startupOptions == null - ? "" - : this.startupOptions.getOptions(); + ? "" + : this.startupOptions.getOptions(); } - + // To retain Backward compatibility protected Object readResolve() { /* - * Assign appropriate artifact objects if it was selected in release 2.0.0 or earlier. - * If using a later plugin release, check if artifact objects were previously serialized. - * */ - this.pdfReportArtifact = Optional.ofNullable(this.pdfReportArtifact).orElseGet(() -> - this.getArtifactObject(pdfReportChkBx, new PdfArtifact("matlabTestArtifacts/testreport.pdf")) - ); + * Assign appropriate artifact objects if it was selected in release 2.0.0 or + * earlier. + * If using a later plugin release, check if artifact objects were previously + * serialized. + */ + this.pdfReportArtifact = Optional.ofNullable(this.pdfReportArtifact).orElseGet( + () -> this.getArtifactObject(pdfReportChkBx, new PdfArtifact("matlabTestArtifacts/testreport.pdf"))); - this.tapArtifact = Optional.ofNullable(this.tapArtifact).orElseGet(() -> - this.getArtifactObject(tapChkBx, new TapArtifact("matlabTestArtifacts/taptestresults.tap")) - ); + this.tapArtifact = Optional.ofNullable(this.tapArtifact).orElseGet( + () -> this.getArtifactObject(tapChkBx, new TapArtifact("matlabTestArtifacts/taptestresults.tap"))); - this.junitArtifact = Optional.ofNullable(this.junitArtifact).orElseGet(() -> - this.getArtifactObject(junitChkBx, new JunitArtifact("matlabTestArtifacts/junittestresults.xml")) - ); + this.junitArtifact = Optional.ofNullable(this.junitArtifact).orElseGet(() -> this.getArtifactObject(junitChkBx, + new JunitArtifact("matlabTestArtifacts/junittestresults.xml"))); - this.coberturaArtifact = Optional.ofNullable(this.coberturaArtifact).orElseGet(() -> - this.getArtifactObject(coberturaChkBx, new CoberturaArtifact("matlabTestArtifacts/cobertura.xml")) - ); + this.coberturaArtifact = Optional.ofNullable(this.coberturaArtifact).orElseGet(() -> this + .getArtifactObject(coberturaChkBx, new CoberturaArtifact("matlabTestArtifacts/cobertura.xml"))); - this.stmResultsArtifact = Optional.ofNullable(this.stmResultsArtifact).orElseGet(() -> - this.getArtifactObject(stmResultsChkBx, new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx")) - ); + this.stmResultsArtifact = Optional.ofNullable(this.stmResultsArtifact) + .orElseGet(() -> this.getArtifactObject(stmResultsChkBx, + new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx"))); - this.modelCoverageArtifact = Optional.ofNullable(this.modelCoverageArtifact).orElseGet(() -> - this.getArtifactObject(modelCoverageChkBx, new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml")) - ); + this.modelCoverageArtifact = Optional.ofNullable(this.modelCoverageArtifact) + .orElseGet(() -> this.getArtifactObject(modelCoverageChkBx, + new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml"))); if (factory == null) { factory = new MatlabActionFactory(); @@ -300,9 +297,7 @@ protected Object readResolve() { return this; } - - - + @Extension public static class RunMatlabTestsDescriptor extends BuildStepDescriptor { @@ -313,22 +308,22 @@ public static void addAliases() { Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.TestFolders", TestFolders.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$PdfArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$PdfArtifact", RunMatlabTestsBuilder.PdfArtifact.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$JunitArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$JunitArtifact", RunMatlabTestsBuilder.JunitArtifact.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$TapArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$TapArtifact", RunMatlabTestsBuilder.TapArtifact.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$CoberturaArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$CoberturaArtifact", RunMatlabTestsBuilder.CoberturaArtifact.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$StmResultsArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$StmResultsArtifact", RunMatlabTestsBuilder.StmResultsArtifact.class); Items.XSTREAM2.addCompatibilityAlias( - "com.mathworks.ci.RunMatlabTestsBuilder$ModelCovArtifact", + "com.mathworks.ci.RunMatlabTestsBuilder$ModelCovArtifact", RunMatlabTestsBuilder.ModelCovArtifact.class); } @@ -343,7 +338,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc save(); return super.configure(req, formData); } - + // Verbosity lists public ListBoxModel doFillLoggingLevelItems() { ListBoxModel items = new ListBoxModel(); @@ -370,11 +365,13 @@ public ListBoxModel doFillOutputDetailItems() { } /* - * This is to identify which project type in jenkins this should be applicable.(non-Javadoc) + * This is to identify which project type in jenkins this should be + * applicable.(non-Javadoc) * * @see hudson.tasks.BuildStepDescriptor#isApplicable(java.lang.Class) * - * if it returns true then this build step will be applicable for all project type. + * if it returns true then this build step will be applicable for all project + * type. */ @Override public boolean isApplicable( @@ -415,14 +412,19 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, build.setResult(Result.FAILURE); } } - + /* - * Classes for each optional block in jelly file.This is restriction from Stapler architecture - * when we use as it creates a object for each block in JSON. This could be - * simplified by using inline=true attribute of however it has some abrupt UI - * scrolling issue on click and also some esthetic issue like broken gray side bar appears.Some + * Classes for each optional block in jelly file.This is restriction from + * Stapler architecture + * when we use as it creates a object for each block in JSON. + * This could be + * simplified by using inline=true attribute of however it has + * some abrupt UI + * scrolling issue on click and also some esthetic issue like broken gray side + * bar appears.Some * discussion about this on Jenkins forum - * https://groups.google.com/forum/#!searchin/jenkinsci-dev/OptionalBlock$20action$20class% + * https://groups.google.com/forum/#!searchin/jenkinsci-dev/ + * OptionalBlock$20action$20class% * 7Csort:date/jenkinsci-dev/AFYHSG3NUEI/UsVJIKoE4B8J * */ @@ -557,7 +559,6 @@ public String getFilePath() { } } - public interface Artifact { public void addFilePathArgTo(Map inputArgs); @@ -565,7 +566,7 @@ public interface Artifact { public boolean getSelected(); } - + public static final class SelectByTag extends AbstractDescribableImpl { private String testTag; private static final String SELECT_BY_TAG = "SelectByTag"; diff --git a/src/main/java/com/mathworks/ci/freestyle/options/BuildOptions.java b/src/main/java/com/mathworks/ci/freestyle/options/BuildOptions.java index e68eb968..efac5049 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/BuildOptions.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/BuildOptions.java @@ -5,7 +5,6 @@ * Copyright 2024 The MathWorks, Inc. * * Describable class for Build Options. - * */ import hudson.Extension; @@ -27,5 +26,7 @@ public String getOptions() { return this.options; } - @Extension public static class DescriptorImpl extends Descriptor {} + @Extension + public static class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java b/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java index 9482ec7b..64970ced 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/SelectByFolder.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.util.List; @@ -30,8 +29,7 @@ public List getTestFolderPaths() { public List getTestFolderStringPaths() { return this.testFolderPaths.stream().map( - p -> p.getTestFolders() - ).collect(Collectors.toList()); + p -> p.getTestFolders()).collect(Collectors.toList()); } public void addSourceToInputArgs(List inputArgsList, String cellArraySourceVal) { @@ -39,5 +37,7 @@ public void addSourceToInputArgs(List inputArgsList, String cellArraySou inputArgsList.add("'" + SELECT_BY_FOLDER + "'" + "," + cellArraySourceVal); } - @Extension public static class DescriptorImpl extends Descriptor {} + @Extension + public static class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java index 2f5e4941..984d60b1 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolder.java @@ -1,10 +1,9 @@ package com.mathworks.ci.freestyle.options; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Describable class for Source Folder Option in RunMATLABTest Build step. - * */ import hudson.Extension; @@ -31,16 +30,17 @@ public List getSourceFolderPaths() { public List getSourceFolderStringPaths() { return this.sourceFolderPaths.stream().map( - (SourceFolderPaths p) -> p.getSrcFolderPath() - ) - .collect(Collectors.toList()); + (SourceFolderPaths p) -> p.getSrcFolderPath()) + .collect(Collectors.toList()); } - public void addSourceToInputArgs(List inputArgsList, String cellArraySourceVal) { + public void addSourceToInputArgs(List inputArgsList, String cellArraySourceVal) { // Concatenate all source folders to MATLAB cell array string. inputArgsList.add("'" + SOURCE_FOLDER + "'" + "," + cellArraySourceVal); } - @Extension public static class DescriptorImpl extends Descriptor {} + @Extension + public static class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolderPaths.java b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolderPaths.java index e8728cb9..8d9bfc33 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/SourceFolderPaths.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/SourceFolderPaths.java @@ -1,11 +1,10 @@ package com.mathworks.ci.freestyle.options; /** - * Copyright 2020 The MathWorks, Inc. + * Copyright 2020-2024 The MathWorks, Inc. * * Describable class for Repeatable Source Folder text boxes in Source Folder option * in RunMATLABTest Build step. - * */ import hudson.Extension; @@ -18,7 +17,7 @@ public class SourceFolderPaths extends AbstractDescribableImpl {} + @Extension + public static final class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/freestyle/options/StartupOptions.java b/src/main/java/com/mathworks/ci/freestyle/options/StartupOptions.java index 631e151b..4febd63e 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/StartupOptions.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/StartupOptions.java @@ -1,10 +1,9 @@ package com.mathworks.ci.freestyle.options; /** - * Copyright 2023 The MathWorks, Inc. + * Copyright 2023-2024 The MathWorks, Inc. * * Describable class for Startup Options. - * */ import hudson.Extension; @@ -26,5 +25,7 @@ public String getOptions() { return this.options; } - @Extension public static class DescriptorImpl extends Descriptor {} + @Extension + public static class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java b/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java index b47a3da1..4ddc5be8 100644 --- a/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java +++ b/src/main/java/com/mathworks/ci/freestyle/options/TestFolders.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import org.kohsuke.stapler.DataBoundConstructor; @@ -24,5 +23,7 @@ public String getTestFolders() { return this.testFolders; } - @Extension public static final class DescriptorImpl extends Descriptor {} + @Extension + public static final class DescriptorImpl extends Descriptor { + } } diff --git a/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java b/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java index 797e9cf3..437755c1 100644 --- a/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/BuildActionParameters.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -17,13 +16,15 @@ public class BuildActionParameters extends MatlabActionParameters { private String tasks; private String buildOptions; - public BuildActionParameters(StepContext context, String startupOpts, String tasks, String buildOpts) throws IOException, InterruptedException { + public BuildActionParameters(StepContext context, String startupOpts, String tasks, String buildOpts) + throws IOException, InterruptedException { super(context, startupOpts); this.tasks = tasks; this.buildOptions = buildOpts; } - public BuildActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts, String tasks, String buildOptions) { + public BuildActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, + TaskListener listener, String startupOpts, String tasks, String buildOptions) { super(build, workspace, env, launcher, listener, startupOpts); this.tasks = tasks; this.buildOptions = buildOptions; diff --git a/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java b/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java index ec3027a4..d8247a72 100644 --- a/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/CommandActionParameters.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -16,12 +15,14 @@ public class CommandActionParameters extends MatlabActionParameters { private String command; - public CommandActionParameters(StepContext context, String startupOpts, String command) throws IOException, InterruptedException { + public CommandActionParameters(StepContext context, String startupOpts, String command) + throws IOException, InterruptedException { super(context, startupOpts); this.command = command; } - public CommandActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts, String command) { + public CommandActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, + TaskListener listener, String startupOpts, String command) { super(build, workspace, env, launcher, listener, startupOpts); this.command = command; } diff --git a/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java b/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java index 9559e801..e62de827 100644 --- a/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -31,7 +30,8 @@ public MatlabActionParameters(StepContext context, String startupOpts) throws IO this.startupOptions = startupOpts; } - public MatlabActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts) { + public MatlabActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, + String startupOpts) { this.build = build; this.workspace = workspace; this.env = env; diff --git a/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java b/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java index 97343b77..4b041b21 100644 --- a/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java +++ b/src/main/java/com/mathworks/ci/parameters/TestActionParameters.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import java.util.List; @@ -30,7 +29,7 @@ public class TestActionParameters extends MatlabActionParameters { private List sourceFolder = new ArrayList<>(); private List selectByFolder = new ArrayList<>(); - public TestActionParameters(StepContext context, String startupOpts, + public TestActionParameters(StepContext context, String startupOpts, String testResultsPDF, String testResultsTAP, String testResultsJUnit, String codeCoverageCobertura, String testResultsSimulinkTest, String modelCoverageCobertura, String selectByTag, String loggingLevel, String outputDetail, @@ -53,7 +52,8 @@ public TestActionParameters(StepContext context, String startupOpts, this.selectByFolder = selectByFolder; } - public TestActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, TaskListener listener, String startupOpts, + public TestActionParameters(Run build, FilePath workspace, EnvVars env, Launcher launcher, + TaskListener listener, String startupOpts, String testResultsPDF, String testResultsTAP, String testResultsJUnit, String codeCoverageCobertura, String testResultsSimulinkTest, String modelCoverageCobertura, String selectByTag, String loggingLevel, String outputDetail, diff --git a/src/main/java/com/mathworks/ci/pipeline/MatlabBuildStepExecution.java b/src/main/java/com/mathworks/ci/pipeline/MatlabBuildStepExecution.java index a8ab3f64..20616dc2 100644 --- a/src/main/java/com/mathworks/ci/pipeline/MatlabBuildStepExecution.java +++ b/src/main/java/com/mathworks/ci/pipeline/MatlabBuildStepExecution.java @@ -2,7 +2,6 @@ /** * Copyright 2022-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -16,19 +15,20 @@ import com.mathworks.ci.parameters.BuildActionParameters; public class MatlabBuildStepExecution extends SynchronousNonBlockingStepExecution { - + private static final long serialVersionUID = 4771831219402275744L; private MatlabActionFactory factory; private RunMatlabBuildStep step; - public MatlabBuildStepExecution(MatlabActionFactory factory, StepContext ctx, RunMatlabBuildStep step) throws IOException, InterruptedException { + public MatlabBuildStepExecution(MatlabActionFactory factory, StepContext ctx, RunMatlabBuildStep step) + throws IOException, InterruptedException { super(ctx); this.factory = factory; this.step = step; } - + public MatlabBuildStepExecution(StepContext ctx, RunMatlabBuildStep step) throws IOException, InterruptedException { this(new MatlabActionFactory(), ctx, step); } diff --git a/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java b/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java index 2efaad92..8ba26e63 100644 --- a/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java +++ b/src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java @@ -2,7 +2,6 @@ /** * Copyright 2023-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -15,20 +14,22 @@ import com.mathworks.ci.actions.RunMatlabCommandAction; public class MatlabCommandStepExecution extends SynchronousNonBlockingStepExecution { - + private static final long serialVersionUID = 1957239693658914450L; - + private MatlabActionFactory factory; private RunMatlabCommandStep step; - public MatlabCommandStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabCommandStep step) throws IOException, InterruptedException { + public MatlabCommandStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabCommandStep step) + throws IOException, InterruptedException { super(context); this.factory = factory; this.step = step; } - public MatlabCommandStepExecution(StepContext context, RunMatlabCommandStep step) throws IOException, InterruptedException { + public MatlabCommandStepExecution(StepContext context, RunMatlabCommandStep step) + throws IOException, InterruptedException { this(new MatlabActionFactory(), context, step); } @@ -38,7 +39,7 @@ public Void run() throws Exception { getContext(), step.getStartupOptions(), step.getCommand()); - RunMatlabCommandAction action = factory.createAction(params); + RunMatlabCommandAction action = factory.createAction(params); try { action.run(); diff --git a/src/main/java/com/mathworks/ci/pipeline/MatlabRunTestsStepExecution.java b/src/main/java/com/mathworks/ci/pipeline/MatlabRunTestsStepExecution.java index 2f604fd1..4bc20e84 100644 --- a/src/main/java/com/mathworks/ci/pipeline/MatlabRunTestsStepExecution.java +++ b/src/main/java/com/mathworks/ci/pipeline/MatlabRunTestsStepExecution.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -19,22 +18,23 @@ public class MatlabRunTestsStepExecution extends SynchronousNonBlockingStepExecution { private static final long serialVersionUID = 6704588180717665100L; - + private MatlabActionFactory factory; private RunMatlabTestsStep step; - public MatlabRunTestsStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabTestsStep step) throws IOException, InterruptedException { + public MatlabRunTestsStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabTestsStep step) + throws IOException, InterruptedException { super(context); this.factory = factory; this.step = step; } - public MatlabRunTestsStepExecution(StepContext context, RunMatlabTestsStep step) throws IOException, InterruptedException { + public MatlabRunTestsStepExecution(StepContext context, RunMatlabTestsStep step) + throws IOException, InterruptedException { this(new MatlabActionFactory(), context, step); } - @Override public Void run() throws Exception { TestActionParameters params = new TestActionParameters( diff --git a/src/main/java/com/mathworks/ci/pipeline/RunMatlabBuildStep.java b/src/main/java/com/mathworks/ci/pipeline/RunMatlabBuildStep.java index a978fbe8..7608a356 100644 --- a/src/main/java/com/mathworks/ci/pipeline/RunMatlabBuildStep.java +++ b/src/main/java/com/mathworks/ci/pipeline/RunMatlabBuildStep.java @@ -2,7 +2,6 @@ /** * Copyright 2022-2024 The MathWorks, Inc. - * */ import java.io.Serializable; @@ -34,7 +33,7 @@ public class RunMatlabBuildStep extends Step implements Serializable { @DataBoundConstructor public RunMatlabBuildStep() { - + } public String getTasks() { @@ -60,7 +59,7 @@ public void setStartupOptions(String startupOptions) { } @DataBoundSetter - public void setBuildOptions (String buildOptions) { + public void setBuildOptions(String buildOptions) { this.buildOptions = buildOptions; } @@ -82,12 +81,10 @@ public Set> getRequiredContext() { public String getFunctionName() { return Message.getValue("matlab.build.build.step.name"); } - + @Override public String getDisplayName() { return Message.getValue("matlab.build.step.display.name"); } } } - - diff --git a/src/main/java/com/mathworks/ci/pipeline/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/pipeline/RunMatlabCommandStep.java index 470bba23..45469d13 100644 --- a/src/main/java/com/mathworks/ci/pipeline/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/pipeline/RunMatlabCommandStep.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.io.Serializable; @@ -25,7 +24,7 @@ import com.mathworks.ci.Message; public class RunMatlabCommandStep extends Step implements Serializable { - + private static final long serialVersionUID = 1L; private String command; @@ -67,12 +66,10 @@ public Set> getRequiredContext() { public String getFunctionName() { return Message.getValue("matlab.command.build.step.name"); } - + @Override public String getDisplayName() { return Message.getValue("matlab.command.step.display.name"); } } } - - diff --git a/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java index 62375800..960c976a 100644 --- a/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.io.Serializable; @@ -28,7 +27,7 @@ public class RunMatlabTestsStep extends Step implements Serializable { private static final long serialVersionUID = 1L; - + private String testResultsPDF; private String testResultsTAP; private String testResultsJUnit; @@ -47,9 +46,9 @@ public class RunMatlabTestsStep extends Step implements Serializable { @DataBoundConstructor public RunMatlabTestsStep() { - + } - + public String getTestResultsTAP() { return testResultsTAP; } @@ -58,7 +57,7 @@ public String getTestResultsTAP() { public void setTestResultsTAP(String testResultsTAP) { this.testResultsTAP = testResultsTAP; } - + public String getTestResultsPDF() { return testResultsPDF; } @@ -98,7 +97,6 @@ public void setTestResultsSimulinkTest(String testResultsSimulinkTest) { public String getModelCoverageCobertura() { return modelCoverageCobertura; } - @DataBoundSetter public void setModelCoverageCobertura(String modelCoverageCobertura) { @@ -113,29 +111,29 @@ public List getSourceFolder() { public void setSourceFolder(List sourceFolder) { this.sourceFolder = sourceFolder; } - + public String getSelectByTag() { return this.selectByTag; } - + @DataBoundSetter public void setSelectByTag(String selectByTag) { this.selectByTag = selectByTag; } - + public List getSelectByFolder() { return this.selectByFolder; } - + @DataBoundSetter public void setSelectByFolder(List selectByFolder) { this.selectByFolder = selectByFolder; } - + public String getLoggingLevel() { return loggingLevel; } - + @DataBoundSetter public void setLoggingLevel(String loggingLevel) { this.loggingLevel = loggingLevel; @@ -144,7 +142,7 @@ public void setLoggingLevel(String loggingLevel) { public String getOutputDetail() { return outputDetail; } - + @DataBoundSetter public void setOutputDetail(String outputDetail) { this.outputDetail = outputDetail; @@ -153,7 +151,7 @@ public void setOutputDetail(String outputDetail) { public boolean getUseParallel() { return useParallel; } - + @DataBoundSetter public void setUseParallel(boolean useParallel) { this.useParallel = useParallel; @@ -162,7 +160,7 @@ public void setUseParallel(boolean useParallel) { public boolean getStrict() { return strict; } - + @DataBoundSetter public void setStrict(boolean strict) { this.strict = strict; @@ -171,7 +169,7 @@ public void setStrict(boolean strict) { public String getStartupOptions() { return Util.fixNull(startupOptions); } - + @DataBoundSetter public void setStartupOptions(String startupOptions) { this.startupOptions = startupOptions; @@ -195,7 +193,7 @@ public Set> getRequiredContext() { public String getFunctionName() { return Message.getValue("matlab.tests.build.step.name"); } - + @Override public String getDisplayName() { return Message.getValue("matlab.tests.step.display.name"); diff --git a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java index 7ef594fd..0e87c3c0 100644 --- a/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java +++ b/src/main/java/com/mathworks/ci/tools/InstallationFailedException.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks, Inc. - * */ import java.io.IOException; @@ -11,7 +10,7 @@ public class InstallationFailedException extends IOException { - InstallationFailedException (String message) { - super (message); + InstallationFailedException(String message) { + super(message); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java index 5ff2c8f9..0a9e8bee 100644 --- a/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java +++ b/src/main/java/com/mathworks/ci/tools/MatlabInstaller.java @@ -1,10 +1,9 @@ package com.mathworks.ci.tools; + /** * Copyright 2024, The MathWorks, Inc. - * */ - import com.mathworks.ci.MatlabInstallation; import com.mathworks.ci.Message; import com.mathworks.ci.utilities.GetSystemProperties; @@ -70,38 +69,38 @@ public void setProducts(String products) { @Override public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) - throws IOException, InterruptedException { + throws IOException, InterruptedException { FilePath destination = preferredLocation(tool, node); String[] systemProperties = getSystemProperties(node); FilePath matlabRootPath; - if(systemProperties[0].toLowerCase().contains("os x")) { - matlabRootPath= new FilePath(destination, this.getRelease()+".app"); + if (systemProperties[0].toLowerCase().contains("os x")) { + matlabRootPath = new FilePath(destination, this.getRelease() + ".app"); } else { matlabRootPath = new FilePath(destination, this.getRelease()); } String platform = getPlatform(systemProperties[0], systemProperties[1]); getFreshCopyOfExecutables(platform, destination); - + makeDir(matlabRootPath); - int result = installUsingMpm(node, this.getRelease (), matlabRootPath, this.getProducts (), log); + int result = installUsingMpm(node, this.getRelease(), matlabRootPath, this.getProducts(), log); if (result == 0) { - log.getLogger ().println ( + log.getLogger().println( "MATLAB installation of version " + this.getRelease() - + " using mpm completed successfully!"); + + " using mpm completed successfully!"); } return matlabRootPath; } private int installUsingMpm(Node node, String release, FilePath destination, String products, TaskListener log) - throws IOException, InterruptedException { + throws IOException, InterruptedException { Launcher matlabInstaller = node.createLauncher(log); - ProcStarter installerProc = matlabInstaller.launch (); + ProcStarter installerProc = matlabInstaller.launch(); ArgumentListBuilder args = new ArgumentListBuilder(); args.add(destination.getParent().getRemote() + getNodeSpecificMPMExecutor(node)); args.add("install"); - appendReleaseToArguments(release,args, log); + appendReleaseToArguments(release, args, log); args.add("--destination=" + destination.getRemote()); addMatlabProductsToArgs(args, products); installerProc.pwd(destination).cmds(args).stdout(log); @@ -110,14 +109,13 @@ private int installUsingMpm(Node node, String release, FilePath destination, Str result = installerProc.join(); } catch (Exception e) { log.getLogger().println("MATLAB installation failed " + e.getMessage()); - throw new InstallationFailedException(e.getMessage ()); + throw new InstallationFailedException(e.getMessage()); } return result; } - private void makeDir(FilePath path) throws IOException, InterruptedException { - if(!path.exists()){ + if (!path.exists()) { path.mkdirs(); path.chmod(0777); } @@ -128,28 +126,28 @@ private void appendReleaseToArguments(String release, ArgumentListBuilder args, String actualRelease = trimmedRelease; if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase( - "latest-including-prerelease")) { - String releaseInfoUrl = - Message.getValue("matlab.release.info.url") + trimmedRelease; + "latest-including-prerelease")) { + String releaseInfoUrl = Message.getValue("matlab.release.info.url") + trimmedRelease; String releaseVersion = null; try { releaseVersion = IOUtils.toString(new URL(releaseInfoUrl), - StandardCharsets.UTF_8).trim(); + StandardCharsets.UTF_8).trim(); } catch (IOException e) { log.getLogger().println("Failed to fetch release version: " + e.getMessage()); } if (releaseVersion != null && releaseVersion.contains("prerelease")) { actualRelease = releaseVersion.replace("prerelease", ""); - args.add ("--release-status=Prerelease"); + args.add("--release-status=Prerelease"); } else { actualRelease = releaseVersion; } } args.add("--release=" + actualRelease); } + private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) - throws IOException, InterruptedException { + throws IOException, InterruptedException { FilePath matlabBatchPath = new FilePath(expectedPath, "matlab-batch"); FilePath mpmPath = new FilePath(expectedPath, "mpm"); @@ -173,10 +171,10 @@ private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) throw new InstallationFailedException("Unsupported OS"); } - //Handle the concurrency issues due to same name. + // Handle the concurrency issues due to same name. FilePath tempMatlabBatchPath = new FilePath(expectedPath, "temp-matlab-batch"); FilePath tempMpmPath = new FilePath(expectedPath, "temp-mpm"); - try{ + try { tempMpmPath.copyFrom(mpmUrl.openStream()); tempMpmPath.chmod(0777); tempMatlabBatchPath.copyFrom(matlabBatchUrl.openStream()); @@ -185,7 +183,7 @@ private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) tempMpmPath.renameTo(mpmPath); tempMatlabBatchPath.renameTo(matlabBatchPath); - } catch(IOException | InterruptedException e){ + } catch (IOException | InterruptedException e) { e.printStackTrace(); } finally { // Clean up temporary files if they exist @@ -194,10 +192,9 @@ private void getFreshCopyOfExecutables(String platform, FilePath expectedPath) } } - @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, - justification = - "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " - + "https://github.com/spotbugs/spotbugs/issues/1843") + @SuppressFBWarnings(value = { + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" }, justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") private String getNodeSpecificMPMExecutor(Node node) { if (!node.toComputer().isUnix()) { return "\\mpm.exe"; @@ -206,7 +203,7 @@ private String getNodeSpecificMPMExecutor(Node node) { } private void addMatlabProductsToArgs(ArgumentListBuilder args, String products) - throws IOException, InterruptedException { + throws IOException, InterruptedException { args.add("--products"); if (products.isEmpty()) { args.add(DEFAULT_PRODUCT); @@ -227,8 +224,8 @@ public String getPlatform(String os, String architecture) throws InstallationFai if (value.contains("linux")) { return "glnxa64"; } else if (value.contains("os x")) { - if (architecture.equalsIgnoreCase("aarch64") || architecture.equalsIgnoreCase ( - "arm64")) { + if (architecture.equalsIgnoreCase("aarch64") || architecture.equalsIgnoreCase( + "arm64")) { return "maca64"; } else { return "maci64"; @@ -238,13 +235,12 @@ public String getPlatform(String os, String architecture) throws InstallationFai } } - @SuppressFBWarnings(value = {"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, - justification = - "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " - + "https://github.com/spotbugs/spotbugs/issues/1843") + @SuppressFBWarnings(value = { + "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" }, justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions " + + "https://github.com/spotbugs/spotbugs/issues/1843") private String[] getSystemProperties(Node node) throws IOException, InterruptedException { String[] properties = node.getChannel() - .call (new GetSystemProperties("os.name", "os.arch", "os.version")); + .call(new GetSystemProperties("os.name", "os.arch", "os.version")); return properties; } diff --git a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java index 850d7c5c..117453d7 100644 --- a/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java +++ b/src/main/java/com/mathworks/ci/utilities/GetSystemProperties.java @@ -1,10 +1,9 @@ package com.mathworks.ci.utilities; + /** * Copyright 2024, The MathWorks, Inc. - * */ - import jenkins.security.MasterToSlaveCallable; public class GetSystemProperties extends MasterToSlaveCallable { @@ -13,15 +12,15 @@ public class GetSystemProperties extends MasterToSlaveCallable additionalEnvVars; + private Map additionalEnvVars; public MatlabCommandRunner(MatlabActionParameters params) throws IOException, InterruptedException { this.params = params; - this.additionalEnvVars = new HashMap(); + this.additionalEnvVars = new HashMap(); FilePath workspace = params.getWorkspace(); @@ -50,14 +49,14 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In this.tempFolder = tmpRoot.createTempDir("matlab", null); } - /** + /** * Spawns a process to run the specified command. * * @param command The command to run */ public void runMatlabCommand(String command) throws IOException, InterruptedException, MatlabExecutionException { this.params.getTaskListener().getLogger() - .println("\n#################### Starting command output ####################"); + .println("\n#################### Starting command output ####################"); // Prepare the executable FilePath exePath = prepareRunnerExecutable(); @@ -65,9 +64,9 @@ public void runMatlabCommand(String command) throws IOException, InterruptedExce // Create the script file FilePath scriptFile = createFileWithContent(command); String cmd = "setenv('MW_ORIG_WORKING_FOLDER', cd('" - + this.tempFolder.getRemote() - + "'));" - + scriptFile.getBaseName(); + + this.tempFolder.getRemote() + + "'));" + + scriptFile.getBaseName(); // Create command ArgumentListBuilder args = new ArgumentListBuilder(); @@ -78,13 +77,13 @@ public void runMatlabCommand(String command) throws IOException, InterruptedExce // Add custom environment vars EnvVars env = getEnvVars(); Utilities.addMatlabToEnvPathFromAxis( - Computer.currentComputer(), - this.params.getTaskListener(), + Computer.currentComputer(), + this.params.getTaskListener(), env); ProcStarter proc = this.params.getLauncher().launch() - .envs(env) - .cmds(args); + .envs(env) + .cmds(args); if (this.stdOut == null) { proc.stdout(this.params.getTaskListener()); } else { @@ -111,7 +110,7 @@ public void redirectStdOut(OutputStream out) { /** * Adds an environment variable. * - * @param key the environment variable name + * @param key the environment variable name * @param value the environment variable value */ public void addEnvironmentVariable(String key, String value) { @@ -120,7 +119,7 @@ public void addEnvironmentVariable(String key, String value) { public EnvVars getEnvVars() { EnvVars env = new EnvVars(this.params.getEnvVars()); - env.putAll(additionalEnvVars); + env.putAll(additionalEnvVars); return env; } @@ -131,7 +130,8 @@ public EnvVars getEnvVars() { * @param targetFile the name of the file to create in the temp folder. * @return the FilePath to the new location in the temp folder. */ - public FilePath copyFileToTempFolder(String sourceFile, String targetFile) throws IOException, InterruptedException { + public FilePath copyFileToTempFolder(String sourceFile, String targetFile) + throws IOException, InterruptedException { final ClassLoader classLoader = getClass().getClassLoader(); FilePath targetFilePath = new FilePath(this.tempFolder, targetFile); InputStream in = classLoader.getResourceAsStream(sourceFile); @@ -154,7 +154,8 @@ public void removeTempFolder() throws IOException, InterruptedException { /** * Creates a file with the specified content in the temporary folder. * - * Additionally, the file content will be prefixed with a statement returning to the MATLAB starting folder. + * Additionally, the file content will be prefixed with a statement returning to + * the MATLAB starting folder. * * @param content string that represents the content of the file. * @return the FilePath to the script file that is created. @@ -165,10 +166,10 @@ protected FilePath createFileWithContent(String content) throws IOException, Int String expandedContent = getEnvVars().expand(content); String finalContent = "cd(getenv('MW_ORIG_WORKING_FOLDER'));\n" - + expandedContent; + + expandedContent; this.params.getTaskListener().getLogger() - .println("Generating MATLAB script with content:\n" + expandedContent + "\n\n"); + .println("Generating MATLAB script with content:\n" + expandedContent + "\n\n"); scriptFile.write(finalContent, "UTF-8"); @@ -192,17 +193,17 @@ protected FilePath prepareRunnerExecutable() throws IOException, InterruptedExce args.add("-m"); launcher.launch() - .cmds(args) - .masks(true, true, true) - .stdout(kernelStream) - .join(); + .cmds(args) + .masks(true, true, true) + .stdout(kernelStream) + .join(); String runnerSource; String kernelArch = kernelStream.toString("UTF-8"); if (kernelArch.contains("Linux")) { runnerSource = "glnxa64/run-matlab-command"; } else if (kernelArch.contains("arm64")) { - runnerSource = "maca64/run-matlab-command"; + runnerSource = "maca64/run-matlab-command"; } else { runnerSource = "maci64/run-matlab-command"; } @@ -211,7 +212,7 @@ protected FilePath prepareRunnerExecutable() throws IOException, InterruptedExce copyFileToTempFolder(runnerSource, dest); return new FilePath(this.tempFolder, dest); - } + } // Windows String dest = "run-matlab-command.exe"; diff --git a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java index d9aba437..62bc5b9f 100644 --- a/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java +++ b/src/test/java/integ/com/mathworks/ci/BuildArtifactActionTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024 The MathWorks, Inc. - * */ import hudson.FilePath; @@ -33,13 +32,12 @@ public class BuildArtifactActionTest { private static String VERSION_INFO_XML_FILE = "VersionInfo.xml"; - public BuildArtifactActionTest(){ + public BuildArtifactActionTest() { } @Rule public JenkinsRule jenkins = new JenkinsRule(); - @Before public void testSetup() throws IOException { this.project = jenkins.createFreeStyleProject(); @@ -68,211 +66,222 @@ private URL getResource(String resource) { } /** - * Verify if total BuildArtifacts returned from artifact file. - *5 + * Verify if total BuildArtifacts returned from artifact file. + * 5 */ @Test - public void verifyBuildArtifactsReturned() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyBuildArtifactsReturned() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); int expectedSize = ba.size(); - Assert.assertEquals("Incorrect build artifact",3,expectedSize); + Assert.assertEquals("Incorrect build artifact", 3, expectedSize); } /** - * Verify if total Failed count returned from artifact file. + * Verify if total Failed count returned from artifact file. * */ @Test - public void verifyFailedCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyFailedCount() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); boolean expectedStatus = ba.get(0).getTaskFailed(); - Assert.assertEquals("The task succeeded",false,expectedStatus); + Assert.assertEquals("The task succeeded", false, expectedStatus); } /** - * Verify if total skipped count returned from artifact file. + * Verify if total skipped count returned from artifact file. * */ @Test - public void verifySkipCount() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifySkipCount() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); - Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped()); + Assert.assertEquals("The task is not skipped", true, ba.get(0).getTaskSkipped()); } /** - * Verify if skip reason is returned from artifact file. + * Verify if skip reason is returned from artifact file. * */ @Test - public void verifySkipReasonIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifySkipReasonIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); - Assert.assertEquals("The task is not skipped",true,ba.get(0).getTaskSkipped()); - Assert.assertEquals("The skip reason for skipped task is inaccurate","user requested",ba.get(0).getSkipReason()); + Assert.assertEquals("The task is not skipped", true, ba.get(0).getTaskSkipped()); + Assert.assertEquals("The skip reason for skipped task is inaccurate", "user requested", + ba.get(0).getSkipReason()); } /** - * Verify if duration returned from artifact file. + * Verify if duration returned from artifact file. * */ @Test - public void verifyDurationIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyDurationIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); - Assert.assertEquals("The task duration is not matching","00:02:53",ba.get(0).getTaskDuration()); + Assert.assertEquals("The task duration is not matching", "00:02:53", ba.get(0).getTaskDuration()); } /** - * Verify if Task description returned from artifact file. + * Verify if Task description returned from artifact file. * */ @Test - public void verifyTaskDescriptionIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTaskDescriptionIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); - Assert.assertEquals("The task description is not matching","Test show",ba.get(0).getTaskDescription()); + Assert.assertEquals("The task description is not matching", "Test show", ba.get(0).getTaskDescription()); } /** - * Verify if Task name returned from artifact file. + * Verify if Task name returned from artifact file. * */ @Test - public void verifyTaskNameIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTaskNameIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; + final String targetFile = "buildArtifact" + actionID + ".json"; BuildArtifactAction ac = new BuildArtifactAction(build, actionID); FilePath artifactRoot = new FilePath(build.getRootDir()); - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); List ba = ac.getBuildArtifact(); - Assert.assertEquals("The task name is not matching","show",ba.get(0).getTaskName()); + Assert.assertEquals("The task name is not matching", "show", ba.get(0).getTaskName()); } /** - * Verify if total count returned from artifact file. + * Verify if total count returned from artifact file. * */ @Test - public void verifyTotalTaskCountIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTotalTaskCountIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json",targetFile,artifactRoot); + final String targetFile = "buildArtifact" + actionID + ".json"; + copyFileInWorkspace("buildArtifacts/t2/buildArtifact.json", targetFile, artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); - Assert.assertEquals("Total task count is not correct",1,ac.getTotalCount()); + Assert.assertEquals("Total task count is not correct", 1, ac.getTotalCount()); } /** - * Verify if total count returned from artifact file. + * Verify if total count returned from artifact file. * */ @Test - public void verifyTotalTaskCountIsAccurate2() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTotalTaskCountIsAccurate2() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + final String targetFile = "buildArtifact" + actionID + ".json"; + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); - Assert.assertEquals("Total task count is not correct",3,ac.getTotalCount()); + Assert.assertEquals("Total task count is not correct", 3, ac.getTotalCount()); } /** - * Verify if total failed count returned from artifact file. + * Verify if total failed count returned from artifact file. * */ @Test - public void verifyTotalFailedTaskCountIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTotalFailedTaskCountIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + final String targetFile = "buildArtifact" + actionID + ".json"; + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); - Assert.assertEquals("Total task count is not correct",3,ac.getTotalCount()); - Assert.assertEquals("Total task failed count is not correct",1,ac.getFailCount()); + Assert.assertEquals("Total task count is not correct", 3, ac.getTotalCount()); + Assert.assertEquals("Total task failed count is not correct", 1, ac.getFailCount()); } - + /** - * Verify if total skipped count returned from artifact file. + * Verify if total skipped count returned from artifact file. * */ @Test - public void verifyTotalSkipTaskCountIsAccurate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyTotalSkipTaskCountIsAccurate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + final String targetFile = "buildArtifact" + actionID + ".json"; + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); - Assert.assertEquals("Total task count is not correct",3,ac.getTotalCount()); - Assert.assertEquals("Total task skip count is not correct",1,ac.getSkipCount()); + Assert.assertEquals("Total task count is not correct", 3, ac.getTotalCount()); + Assert.assertEquals("Total task skip count is not correct", 1, ac.getSkipCount()); } /** - * Verify if ActionID is set correctly. + * Verify if ActionID is set correctly. * */ @Test - public void verifyActionIDisAppropriate() throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { + public void verifyActionIDisAppropriate() + throws ExecutionException, InterruptedException, URISyntaxException, IOException, ParseException { FreeStyleBuild build = getFreestyleBuild(); FilePath artifactRoot = new FilePath(build.getRootDir()); final String actionID = "abc123"; - final String targetFile = "buildArtifact"+ actionID + ".json"; - copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json",targetFile,artifactRoot); + final String targetFile = "buildArtifact" + actionID + ".json"; + copyFileInWorkspace("buildArtifacts/t1/buildArtifact.json", targetFile, artifactRoot); BuildArtifactAction ac = new BuildArtifactAction(build, actionID); - Assert.assertEquals("Incorrect ActionID",actionID,ac.getActionID()); + Assert.assertEquals("Incorrect ActionID", actionID, ac.getActionID()); } - - private void copyFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) throws IOException, InterruptedException { final ClassLoader classLoader = getClass().getClassLoader(); @@ -284,7 +293,8 @@ private void copyFileInWorkspace(String sourceFile, String targetFile, FilePath } private FreeStyleBuild getFreestyleBuild() throws ExecutionException, InterruptedException, URISyntaxException { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(this.scriptBuilder); diff --git a/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java b/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java index 4012c61f..288683e2 100644 --- a/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java +++ b/src/test/java/integ/com/mathworks/ci/MatlabInstallationTest.java @@ -1,8 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2020-2021 The MathWorks, Inc. - * + * Copyright 2020-2024 The MathWorks, Inc. */ import hudson.matrix.AxisList; @@ -85,17 +84,18 @@ private MatlabInstallation setMatlabInstallation(String name, String home) { newInst.add(newMatlabInstallation); MatlabInstallation[] setInst = new MatlabInstallation[newInst.size()]; matlabInstDescriptor.setInstallations(newInst.toArray(setInst)); - return newMatlabInstallation; + return newMatlabInstallation; } - private MatlabInstallation[] getMatlabInstallation(){ + private MatlabInstallation[] getMatlabInstallation() { // static method to return all installations return MatlabInstallation.getAll(); } /* - * Test to verify global tool configuration for MATLAB by doing a configuration round trip. - * */ + * Test to verify global tool configuration for MATLAB by doing a configuration + * round trip. + */ @Test public void verifyRoundTripInstallation() throws Exception { MatlabInstallation matlabInst = setMatlabInstallation("R2019b", "C:\\FakePath\\MATLAB\\R2019b"); @@ -112,7 +112,7 @@ public void verifyRoundTripInstallation() throws Exception { /* * Test to verify usage of MATLAB tool installation in pipeline project. - * */ + */ @Test public void verifyInstallationInPipeline() throws Exception { URL url = MatlabInstallationTest.class.getClassLoader().getResource("versioninfo/R2018b"); @@ -120,19 +120,20 @@ public void verifyInstallationInPipeline() throws Exception { jenkins.configRoundtrip(); WorkflowJob project = jenkins.createProject(WorkflowJob.class); project.setDefinition(new CpsFlowDefinition("node { \n" - + " def matlabroot \n" - + " matlabroot = tool 'R2018b' \n" - + " withEnv([\"PATH+MATLAB=$matlabroot/bin\"]) { \n" - + " echo env.PATH \n" - + " runMATLABTests(testResultsPDF:'myresult/result.pdf')}}", true)); + + " def matlabroot \n" + + " matlabroot = tool 'R2018b' \n" + + " withEnv([\"PATH+MATLAB=$matlabroot/bin\"]) { \n" + + " echo env.PATH \n" + + " runMATLABTests(testResultsPDF:'myresult/result.pdf')}}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("versioninfo", build); jenkins.assertLogContains("2018b", build); jenkins.assertLogContains("bin", build); } + /* * Test to verify usage of MATLAB tool installation in freestyle project. - * */ + */ @Test public void verifyInstallationInFreeStyle() throws Exception { URL url = MatlabInstallationTest.class.getClassLoader().getResource("versioninfo" + FileSeperator + "R2018a"); @@ -185,7 +186,8 @@ public void verifyInstallationInMatrixBuild() throws Exception { /* * @Integ Test * Paths should point to MATLAB executable - * Test to verify correct MATLAB installation is added to PATH environment variable + * Test to verify correct MATLAB installation is added to PATH environment + * variable */ public void verifyInstallationPathVarInMatrixBuild() throws Exception { diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java index 1a39f312..9810988c 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTest.java @@ -50,9 +50,9 @@ public class RunMatlabBuildBuilderTest { @Rule public JenkinsRule jenkins = new JenkinsRule(); - + @Rule - public Timeout globalTimeout = Timeout.seconds(500); + public Timeout globalTimeout = Timeout.seconds(500); @BeforeClass public static void classSetup() throws URISyntaxException, IOException { @@ -62,7 +62,7 @@ public static void classSetup() throws URISyntaxException, IOException { url = classLoader.getResource("com/mathworks/ci/linux/bin/matlab.sh"); try { matlabExecutorAbsolutePath = new File(url.toURI()).getAbsolutePath(); - System.out.println ("THE EXECUTOR PATH IS" + matlabExecutorAbsolutePath); + System.out.println("THE EXECUTOR PATH IS" + matlabExecutorAbsolutePath); // Need to do this operation due to bug in maven Resource copy plugin [ // https://issues.apache.org/jira/browse/MRESOURCES-132 ] @@ -125,13 +125,13 @@ public void verifyBuildStepWithRunMatlab() throws Exception { Assert.assertTrue("Build step does not contain Run MATLAB Build option", found); } - /* * Test to verify MATLAB is launched using the default MATLAB runner script. */ @Test public void verifyMATLABlaunchedWithDefaultArguments() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(this.scriptBuilder); @@ -144,7 +144,8 @@ public void verifyMATLABlaunchedWithDefaultArguments() throws Exception { */ @Test public void verifyMATLABlaunchedfromWorkspace() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(this.scriptBuilder); @@ -154,11 +155,13 @@ public void verifyMATLABlaunchedfromWorkspace() throws Exception { } /* - * Test to verify job fails when invalid MATLAB path is provided and Exception is thrown + * Test to verify job fails when invalid MATLAB path is provided and Exception + * is thrown */ @Test public void verifyBuilderFailsForInvalidMATLABPath() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), "/fake/matlabroot/that/does/not/exist")); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), "/fake/matlabroot/that/does/not/exist")); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(this.scriptBuilder); @@ -171,10 +174,11 @@ public void verifyBuilderFailsForInvalidMATLABPath() throws Exception { */ @Test public void verifyBuildFailureWhenMatlabBuildFails() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabBuildBuilderTester tester = - new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, "-positiveFail"); + RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, + "-positiveFail"); scriptBuilder.setTasks(""); project.getBuildersList().add(tester); FreeStyleBuild build = project.scheduleBuild2(0).get(); @@ -186,10 +190,10 @@ public void verifyBuildFailureWhenMatlabBuildFails() throws Exception { */ @Test public void verifyBuildPassesWhenMatlabBuildPasses() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabBuildBuilderTester tester = - new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, "-positive"); + RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, "-positive"); scriptBuilder.setTasks(""); project.getBuildersList().add(tester); FreeStyleBuild build = project.scheduleBuild2(0).get(); @@ -202,7 +206,8 @@ public void verifyBuildPassesWhenMatlabBuildPasses() throws Exception { */ @Test public void verifyBuildPicksTheCorrectBuildBatch() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks("compile"); project.getBuildersList().add(this.scriptBuilder); @@ -217,7 +222,8 @@ public void verifyBuildPicksTheCorrectBuildBatch() throws Exception { */ @Test public void verifyBuildPicksTheCorrectStartupOptions() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); scriptBuilder.setStartupOptions(new StartupOptions("-nojvm -uniqueoption")); @@ -232,7 +238,8 @@ public void verifyBuildPicksTheCorrectStartupOptions() throws Exception { */ @Test public void verifyBuildPicksTheCorrectBuildOptions() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); scriptBuilder.setBuildOptions(new BuildOptions("-continueOnFailure -skip compile")); @@ -243,11 +250,13 @@ public void verifyBuildPicksTheCorrectBuildOptions() throws Exception { } /* - * Test to verify if MATLAB scratch file is not generated in workspace for this builder. + * Test to verify if MATLAB scratch file is not generated in workspace for this + * builder. */ @Test public void verifyMATLABscratchFileNotGenerated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(this.scriptBuilder); @@ -255,9 +264,10 @@ public void verifyMATLABscratchFileNotGenerated() throws Exception { File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m"); Assert.assertFalse(matlabRunner.exists()); } - + /* - * Test to verify build supports resolving environment variable (For matrix builds). + * Test to verify build supports resolving environment variable (For matrix + * builds). */ @Test public void verifyBuildSupportsEnvVar() throws Exception { @@ -266,7 +276,8 @@ public void verifyBuildSupportsEnvVar() throws Exception { var.put("TASKS", "compile"); var.put("BUILD_OPTIONS", "-continueOnFailure -skip test"); jenkins.jenkins.getGlobalNodeProperties().add(prop); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks("$TASKS"); scriptBuilder.setBuildOptions(new BuildOptions("$BUILD_OPTIONS")); @@ -275,70 +286,75 @@ public void verifyBuildSupportsEnvVar() throws Exception { jenkins.assertLogContains("compile", build); jenkins.assertLogContains("-continueOnFailure -skip test", build); } - + /* * Test to verify if appropriate MATLAB runner file is copied in workspace. * - * NOTE: This test assumes there is no MATLAB installed and is not on System Path. + * NOTE: This test assumes there is no MATLAB installed and is not on System + * Path. * */ @Test public void verifyMATLABrunnerFileGenerated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(scriptBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("run-matlab-command", build); } - + /* * Verify default MATLAB is not picked if invalid MATLAB path is provided */ @Test public void verifyDefaultMatlabNotPicked() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2020b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2020b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setTasks(""); project.getBuildersList().add(scriptBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("MatlabNotFoundError", build); } - + /* * Test to verify if Matrix build fails when MATLAB is not available. * - * NOTE: This test assumes there is no MATLAB installed and is not on System Path. + * NOTE: This test assumes there is no MATLAB installed and is not on System + * Path. * */ @Test public void verifyMatrixBuildFails() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2015b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - - scriptBuilder.setTasks(""); - matrixProject.getBuildersList().add(scriptBuilder); - - // Check for first matrix combination. - Map vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); - - jenkins.assertLogContains("buildtool", build1); - jenkins.assertBuildStatus(Result.FAILURE, build1); - - // Check for second Matrix combination - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2015b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + + scriptBuilder.setTasks(""); + matrixProject.getBuildersList().add(scriptBuilder); + + // Check for first matrix combination. + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); + + jenkins.assertLogContains("buildtool", build1); + jenkins.assertBuildStatus(Result.FAILURE, build1); + + // Check for second Matrix combination + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); } /* @@ -346,21 +362,22 @@ public void verifyMatrixBuildFails() throws Exception { */ @Test public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, - "-positive"); - - tester.setTasks(""); - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabBuildBuilderTester tester = new RunMatlabBuildBuilderTester(matlabExecutorAbsolutePath, + "-positive"); + + tester.setTasks(""); + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); } } diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java index c6c0b3e1..158daacc 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildBuilderTester.java @@ -1,8 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2022 The MathWorks, Inc. - * + * Copyright 2022-2024 The MathWorks, Inc. */ import java.io.IOException; @@ -38,14 +37,12 @@ public RunMatlabBuildBuilderTester(String matlabExecutorPath, String customTestP this.matlabExecutorPath = matlabExecutorPath; } - // Getter and Setters to access local members private void setEnv(EnvVars env) { this.env = env; } - @Extension public static class Desriptor extends BuildStepDescriptor { @Override @@ -110,4 +107,3 @@ private List testMatlabBuild() { return matlabDefaultArgs; } } - diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java index 88072661..fa141756 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabBuildStepTest.java @@ -32,7 +32,6 @@ public void testSetup() throws IOException { this.project = j.createProject(WorkflowJob.class); } - /* * Verify when MATLAB is not on system path. */ @@ -65,10 +64,10 @@ public void verifyMATLABstartsInWorkspace() throws Exception { */ // @Test // public void verifyMATLABPathSet() throws Exception { - // project.setDefinition( - // new CpsFlowDefinition("node { runMATLABBuild() }", true)); - // WorkflowRun build = project.scheduleBuild2(0).get(); - // j.assertLogContains("tester_started", build); + // project.setDefinition( + // new CpsFlowDefinition("node { runMATLABBuild() }", true)); + // WorkflowRun build = project.scheduleBuild2(0).get(); + // j.assertLogContains("tester_started", build); // } /* @@ -128,7 +127,8 @@ public void verifyStartupOptionsSameAsScript() throws Exception { @Test public void verifyBuildOptionsSameAsScript() throws Exception { project.setDefinition( - new CpsFlowDefinition("node { runMATLABBuild(buildOptions: '-continueOnFailure -skip compile') }", true)); + new CpsFlowDefinition("node { runMATLABBuild(buildOptions: '-continueOnFailure -skip compile') }", + true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("-continueOnFailure -skip compile", build); @@ -150,8 +150,8 @@ public void verifyMatrixBuild() throws Exception { } /* - * Test for verifying Run Matlab Build raises exception for non-zero exit code. - * */ + * Test for verifying Run Matlab Build raises exception for non-zero exit code. + */ @Test public void verifyExceptionForNonZeroExitCode() throws Exception { // exitMatlab is a mock build for run_matlab_build script to exit with 1. diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java index c8635f29..8b7bbc56 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTest.java @@ -54,9 +54,9 @@ public class RunMatlabCommandBuilderTest { @Rule public JenkinsRule jenkins = new JenkinsRule(); - + @Rule - public Timeout globalTimeout = Timeout.seconds(500); + public Timeout globalTimeout = Timeout.seconds(500); @BeforeClass public static void classSetup() throws URISyntaxException, IOException { @@ -130,7 +130,6 @@ public void verifyBuildStepWithRunMatlab() throws Exception { Assert.assertTrue("Build step does not contain Run MATLAB Command option", found); } - /* * Test To verify MATLAB is launched using the default matlab runner binary. * @@ -138,7 +137,8 @@ public void verifyBuildStepWithRunMatlab() throws Exception { @Test public void verifyMATLABlaunchedWithDefaultArguments() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(this.scriptBuilder); @@ -153,7 +153,8 @@ public void verifyMATLABlaunchedWithDefaultArguments() throws Exception { @Test public void verifyMATLABlaunchedfromWorkspace() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(this.scriptBuilder); @@ -163,12 +164,14 @@ public void verifyMATLABlaunchedfromWorkspace() throws Exception { } /* - * Test to verify if job fails when invalid MATLAB path is provided and Exception is thrown + * Test to verify if job fails when invalid MATLAB path is provided and + * Exception is thrown */ @Test public void verifyBuilderFailsForInvalidMATLABPath() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), "/fake/matlabroot/that/does/not/exist")); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), "/fake/matlabroot/that/does/not/exist")); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(this.scriptBuilder); @@ -182,10 +185,11 @@ public void verifyBuilderFailsForInvalidMATLABPath() throws Exception { @Test public void verifyBuildFailureWhenMatlabCommandFails() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabCommandBuilderTester tester = - new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, "-positiveFail"); + RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, + "-positiveFail"); tester.setMatlabCommand("pp"); project.getBuildersList().add(tester); FreeStyleBuild build = project.scheduleBuild2(0).get(); @@ -198,10 +202,11 @@ public void verifyBuildFailureWhenMatlabCommandFails() throws Exception { @Test public void verifyBuildPassesWhenMatlabCommandPasses() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabCommandBuilderTester tester = - new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, "-positive"); + RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, + "-positive"); tester.setMatlabCommand("pwd"); project.getBuildersList().add(tester); FreeStyleBuild build = project.scheduleBuild2(0).get(); @@ -216,7 +221,8 @@ public void verifyBuildPassesWhenMatlabCommandPasses() throws Exception { @Test public void verifyBuildPicksTheCorretCommandBatch() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(this.scriptBuilder); @@ -233,7 +239,8 @@ public void verifyBuildPicksTheCorretCommandBatch() throws Exception { @Test public void verifyBuildPicksTheCorrectStartupOptions() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); scriptBuilder.setStartupOptions(new StartupOptions("-nojvm -uniqueoption")); @@ -246,11 +253,13 @@ public void verifyBuildPicksTheCorrectStartupOptions() throws Exception { } /* - * Test to verify if MATALB scratch file is not generated in workspace for this builder. + * Test to verify if MATALB scratch file is not generated in workspace for this + * builder. */ @Test public void verifyMATLABscratchFileNotGenerated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(this.scriptBuilder); @@ -258,9 +267,10 @@ public void verifyMATLABscratchFileNotGenerated() throws Exception { File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m"); Assert.assertFalse(matlabRunner.exists()); } - + /* - * Test to verify command supports resolving environment variable (For MATRIX builds). + * Test to verify command supports resolving environment variable (For MATRIX + * builds). * */ @Test @@ -269,71 +279,77 @@ public void verifyCommandSupportsEnvVar() throws Exception { EnvVars var = prop.getEnvVars(); var.put("PWDCMD", "pwd"); jenkins.jenkins.getGlobalNodeProperties().add(prop); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("$PWDCMD"); project.getBuildersList().add(scriptBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("pwd", build); } - + /* * Test to verify if appropriate MATALB runner file is copied in workspace. * - * NOTE: This test assumes there is no MATLAB installed and is not on System Path. + * NOTE: This test assumes there is no MATLAB installed and is not on System + * Path. * */ @Test public void verifyMATLABrunnerFileGenerated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(scriptBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("run-matlab-command", build); } - + /* * Verify default MATLAB is not picked if invalid MATLAB path is provided */ @Test public void verifyDefaultMatlabNotPicked() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2020b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2020b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("pwd"); project.getBuildersList().add(scriptBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("MatlabNotFoundError", build); } - + /* * Test to verify if Matrix build fails when MATLAB is not available. * - * NOTE: This test assumes there is no MATLAB installed and is not on System Path. + * NOTE: This test assumes there is no MATLAB installed and is not on System + * Path. * */ @Test public void verifyMatrixBuildFails() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2015b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - - scriptBuilder.setMatlabCommand("pwd"); - matrixProject.getBuildersList().add(scriptBuilder); - Map vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1); - jenkins.assertLogContains("run-matlab-command", build); - jenkins.assertBuildStatus(Result.FAILURE, build); - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2015b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + + scriptBuilder.setMatlabCommand("pwd"); + matrixProject.getBuildersList().add(scriptBuilder); + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1); + jenkins.assertLogContains("run-matlab-command", build); + jenkins.assertBuildStatus(Result.FAILURE, build); + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); } /* @@ -341,34 +357,34 @@ public void verifyMatrixBuildFails() throws Exception { */ @Test public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, - "-positive"); - - tester.setMatlabCommand("pwd"); - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); - } - + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabCommandBuilderTester tester = new RunMatlabCommandBuilderTester(matlabExecutorAbsolutePath, + "-positive"); + + tester.setMatlabCommand("pwd"); + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); + } + /* - * Test to verify if command parses succesfully when multiple combinations of + * Test to verify if command parses succesfully when multiple combinations of * characters are passed. (candidate for integ-tests once integrated) */ public void verifyMultispecialChar() throws Exception { - final String actualCommand = - "!\"\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - final String expectedCommand = - "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + final String actualCommand = "!\"\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + final String expectedCommand = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); scriptBuilder.setMatlabCommand("disp(" + actualCommand + ")"); @@ -384,12 +400,13 @@ public void verifyMultispecialChar() throws Exception { */ @Test public void verifyErrorMessageOnEmptyCommand() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); project.getBuildersList().add(this.scriptBuilder); HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertTextPresent(page,"Specify at least one script, function, or statement to execute."); + WebAssert.assertTextPresent(page, "Specify at least one script, function, or statement to execute."); } /* @@ -398,13 +415,14 @@ public void verifyErrorMessageOnEmptyCommand() throws Exception { @Test public void verifyWhenCommandNonEmpty() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a"))); project.getBuildWrappersList().add(this.buildWrapper); this.scriptBuilder.setMatlabCommand("NONEMPTY"); project.getBuildersList().add(this.scriptBuilder); HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertTextNotPresent(page,"Specify at least one script, function, or statement to execute."); + WebAssert.assertTextNotPresent(page, "Specify at least one script, function, or statement to execute."); } } diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java index 4538e6b4..f67fa0ec 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandBuilderTester.java @@ -39,14 +39,12 @@ public RunMatlabCommandBuilderTester(String matlabExecutorPath, String customTes this.matlabExecutorPath = matlabExecutorPath; } - // Getter and Setters to access local members private void setEnv(EnvVars env) { this.env = env; } - @Extension public static class Desriptor extends BuildStepDescriptor { @Override @@ -111,4 +109,3 @@ private List testMatlabCommand() { return matlabDefaultArgs; } } - diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java index f4b37d2a..47181cea 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -1,7 +1,7 @@ package com.mathworks.ci.pipeline; + /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -66,10 +66,10 @@ public void verifyMATLABstartsInWorkspace() throws Exception { // @Test // public void verifyMATLABPathSet() throws Exception { - // project.setDefinition( - // new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd')}", true)); - // WorkflowRun build = project.scheduleBuild2(0).get(); - // j.assertLogContains("tester_started", build); + // project.setDefinition( + // new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd')}", true)); + // WorkflowRun build = project.scheduleBuild2(0).get(); + // j.assertLogContains("tester_started", build); // } /* @@ -112,7 +112,8 @@ public void verifyCommandSameAsScript() throws Exception { @Test public void verifyStartupOptionsSameAsScript() throws Exception { project.setDefinition( - new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd', startupOptions: '-nojvm -uniqueoption')}", true)); + new CpsFlowDefinition( + "node { runMATLABCommand(command: 'pwd', startupOptions: '-nojvm -uniqueoption')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("-nojvm -uniqueoption", build); @@ -136,13 +137,16 @@ public void verifyMatrixBuild() throws Exception { } /* - * Test for verifying Run Matlab Command raises exception for non-zero exit code. - * */ + * Test for verifying Run Matlab Command raises exception for non-zero exit + * code. + */ @Test public void verifyExceptionForNonZeroExitCode() throws Exception { // exitMatlab is a mock command for run_matlab_command script to exit with 1. project.setDefinition( - new CpsFlowDefinition("node { try {runMATLABCommand(command: 'exitMatlab')}catch(exc){echo exc.getMessage()}}", true)); + new CpsFlowDefinition( + "node { try {runMATLABCommand(command: 'exitMatlab')}catch(exc){echo exc.getMessage()}}", + true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java index 4ed50ce3..bb0eb6ef 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestBuilderPersistenceTest.java @@ -4,7 +4,6 @@ * Copyright 2020-2024 The MathWorks, Inc. * * Test class for RunMatlabTestsBuilder Persistence - * */ import hudson.model.FreeStyleProject; @@ -42,8 +41,8 @@ private boolean areSourcePathsEqual(List listA, List vals = new HashMap(); - vals.put("VERSION", "R2018a"); - Combination c1 = new Combination(vals); - MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); + Map vals = new HashMap(); + vals.put("VERSION", "R2018a"); + Combination c1 = new Combination(vals); + MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1); - jenkins.assertLogContains("run-matlab-command", build1); - jenkins.assertBuildStatus(Result.FAILURE, build1); + jenkins.assertLogContains("run-matlab-command", build1); + jenkins.assertBuildStatus(Result.FAILURE, build1); - // Check for second Matrix combination - vals.put("VERSION", "R2015b"); - Combination c2 = new Combination(vals); - MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); + // Check for second Matrix combination + vals.put("VERSION", "R2015b"); + Combination c2 = new Combination(vals); + MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2); - jenkins.assertLogContains("MatlabNotFoundError", build2); - jenkins.assertBuildStatus(Result.FAILURE, build2); + jenkins.assertLogContains("MatlabNotFoundError", build2); + jenkins.assertBuildStatus(Result.FAILURE, build2); } /* @@ -451,123 +463,129 @@ public void verifyMatrixBuildFails() throws Exception { */ @Test public void verifyMatrixBuildPasses() throws Exception { - MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); - Axis axes = new Axis("VERSION", "R2018a", "R2018b"); - matrixProject.setAxes(new AxisList(axes)); - String matlabRoot = getMatlabroot("R2018b"); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); - matrixProject.getBuildWrappersList().add(this.buildWrapper); - RunMatlabTestsBuilderTester tester = new RunMatlabTestsBuilderTester(matlabExecutorAbsolutePath, "-positive"); - - matrixProject.getBuildersList().add(tester); - MatrixBuild build = matrixProject.scheduleBuild2(0).get(); - - jenkins.assertLogContains("Triggering", build); - jenkins.assertLogContains("R2018a completed", build); - jenkins.assertLogContains("R2018b completed", build); - jenkins.assertBuildStatus(Result.SUCCESS, build); - } - - /* + MatrixProject matrixProject = jenkins.createProject(MatrixProject.class); + Axis axes = new Axis("VERSION", "R2018a", "R2018b"); + matrixProject.setAxes(new AxisList(axes)); + String matlabRoot = getMatlabroot("R2018b"); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), matlabRoot.replace("R2018b", "$VERSION"))); + matrixProject.getBuildWrappersList().add(this.buildWrapper); + RunMatlabTestsBuilderTester tester = new RunMatlabTestsBuilderTester(matlabExecutorAbsolutePath, "-positive"); + + matrixProject.getBuildersList().add(tester); + MatrixBuild build = matrixProject.scheduleBuild2(0).get(); + + jenkins.assertLogContains("Triggering", build); + jenkins.assertLogContains("R2018a completed", build); + jenkins.assertLogContains("R2018b completed", build); + jenkins.assertBuildStatus(Result.SUCCESS, build); + } + + /* * Test to verify if MATALB scratch file is not in workspace. */ @Test public void verifyMATLABscratchFileGenerated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); project.getBuildWrappersList().add(this.buildWrapper); project.getBuildersList().add(testBuilder); FreeStyleBuild build = project.scheduleBuild2(0).get(); File matlabRunner = new File(build.getWorkspace() + File.separator + "runnerScript.m"); Assert.assertFalse(matlabRunner.exists()); } - + /* * Test to verify Use Parallel check box present. */ - @Test - public void verifyUseParallelPresent() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.useParallel\"]"); - } - - /* - * Test to verify Strict check box present. - */ - - @Test - public void verifyStrictPresent() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.strict\"]"); - } - - /* - * Test to verify Logging Level is present. - */ - - @Test - public void verifyLoggingLevelPresent() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertElementPresentByXPath(page, "//select[@name=\"_.loggingLevel\"]"); - } - - /* - * Test to verify Output Detail is present. - */ - - @Test - public void verifyOutputDetailPresent() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - WebAssert.assertElementPresentByXPath(page, "//select[@name=\"_.outputDetail\"]"); - } - - /* - * Test to verify Logging Level set to default - */ - - @Test - public void verifyLoggingLevelSetToDefault() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - HtmlSelect loggingLevel = page.getElementByName("_.loggingLevel"); - assertEquals("default", loggingLevel.getAttribute("value")); - } - - /* - * Test to verify Output Detail set to default - */ - - @Test - public void verifyOutputDetailSetToDefault() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); - project.getBuildWrappersList().add(this.buildWrapper); - project.getBuildersList().add(this.testBuilder); - HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); - HtmlSelect outputDetail = page.getElementByName("_.outputDetail"); - assertEquals("default", outputDetail.getAttribute("value")); - } - - + @Test + public void verifyUseParallelPresent() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.useParallel\"]"); + } + + /* + * Test to verify Strict check box present. + */ + + @Test + public void verifyStrictPresent() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + WebAssert.assertElementPresentByXPath(page, "//input[@name=\"_.strict\"]"); + } + + /* + * Test to verify Logging Level is present. + */ + + @Test + public void verifyLoggingLevelPresent() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + WebAssert.assertElementPresentByXPath(page, "//select[@name=\"_.loggingLevel\"]"); + } + + /* + * Test to verify Output Detail is present. + */ + + @Test + public void verifyOutputDetailPresent() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + WebAssert.assertElementPresentByXPath(page, "//select[@name=\"_.outputDetail\"]"); + } + + /* + * Test to verify Logging Level set to default + */ + + @Test + public void verifyLoggingLevelSetToDefault() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + HtmlSelect loggingLevel = page.getElementByName("_.loggingLevel"); + assertEquals("default", loggingLevel.getAttribute("value")); + } + + /* + * Test to verify Output Detail set to default + */ + + @Test + public void verifyOutputDetailSetToDefault() throws Exception { + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + project.getBuildWrappersList().add(this.buildWrapper); + project.getBuildersList().add(this.testBuilder); + HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); + HtmlSelect outputDetail = page.getElementByName("_.outputDetail"); + assertEquals("default", outputDetail.getAttribute("value")); + } + /* * @Integ - * Test To verify if Logging level is set correctly + * Test To verify if Logging level is set correctly * */ - public void verifyLoggingLevelSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); @@ -591,13 +609,13 @@ public void verifyLoggingLevelSet() throws Exception { } }); } - - /*@Integ - * Test To verify if Output Detail is set correctly + + /* + * @Integ + * Test To verify if Output Detail is set correctly * */ - public void verifyOutputDetailSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); @@ -623,12 +641,12 @@ public void verifyOutputDetailSet() throws Exception { }); } - /*@Integ + /* + * @Integ * Test To verify when Strict option set * */ - public void verifyStrictSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); @@ -641,12 +659,12 @@ public void verifyStrictSet() throws Exception { } - /*@Integ + /* + * @Integ * Test To verify when Strict option not set * */ - public void verifyStrictNotSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); @@ -658,13 +676,13 @@ public void verifyStrictNotSet() throws Exception { jenkins.assertLogNotContains("FailOnWarningsPlugin", build); } - - /*@Integ - * Test To verify when Run in Parallel option is set + + /* + * @Integ + * Test To verify when Run in Parallel option is set * */ - public void verifyRunParallelSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); @@ -675,13 +693,13 @@ public void verifyRunParallelSet() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("runInParallel", build); } - - /*@Integ - * Test To verify when Run in Parallel option is set + + /* + * @Integ + * Test To verify when Run in Parallel option is set * */ - public void verifyRunParallelNotSet() throws Exception { this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java index a5ee3e86..0c38793b 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsBuilderTester.java @@ -1,9 +1,9 @@ package com.mathworks.ci; + /** * Copyright 2019-2024 The MathWorks, Inc. * * Tester builder for RunMatlabTestsBuilder. - * */ import java.io.IOException; @@ -43,8 +43,6 @@ public class RunMatlabTestsBuilderTester extends RunMatlabTestsBuilder { private String matlabExecutorPath; private String matlabVerName; - - public RunMatlabTestsBuilderTester(String matlabExecutorPath, String customTestPointArgument) { super(); this.commandParameter = customTestPointArgument; @@ -58,7 +56,6 @@ public RunMatlabTestsBuilderTester(String customTestPointArgument) { // Getter and Setters to access local members - @DataBoundSetter public void setTapChkBx(TapArtifact tapArtifact) { this.tapArtifact = tapArtifact; @@ -139,11 +136,13 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc } /* - * This is to identify which project type in jenkins this should be applicable.(non-Javadoc) + * This is to identify which project type in jenkins this should be + * applicable.(non-Javadoc) * * @see hudson.tasks.BuildStepDescriptor#isApplicable(java.lang.Class) * - * if it returns true then this build step will be applicable for all project type. + * if it returns true then this build step will be applicable for all project + * type. */ @Override public boolean isApplicable( @@ -194,5 +193,4 @@ private List testMatlabCommand() { return matlabDefaultArgs; } - } diff --git a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java index 87166fd5..be30c713 100644 --- a/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/integ/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -2,7 +2,6 @@ /** * Copyright 2020-2024 The MathWorks, Inc. - * */ import java.io.IOException; @@ -33,7 +32,6 @@ public void testSetup() throws IOException { this.project = j.createProject(WorkflowJob.class); } - /* * Verify when MATLAB Path is not set */ @@ -45,7 +43,6 @@ public void verifyMATLABPathNotSet() throws Exception { j.assertLogContains("system path", build); } - /* * Verify when MATLAB PATH is set. */ @@ -77,7 +74,6 @@ public void verifyOnslave() throws Exception { * Verify artifact path is correct. Need to move this to integration test. */ - public void verifyArtifactPath() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); @@ -93,24 +89,26 @@ public void verifyArtifactPath() throws Exception { @Test public void verifyStartupOptionsSameAsScript() throws Exception { project.setDefinition( - new CpsFlowDefinition("node {runMATLABTests(testResultsPDF:'myresult/result.pdf', startupOptions: '-nojvm -uniqueoption')}", true)); + new CpsFlowDefinition( + "node {runMATLABTests(testResultsPDF:'myresult/result.pdf', startupOptions: '-nojvm -uniqueoption')}", + true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("-nojvm -uniqueoption", build); } - + /* - * Verify default command options for test run. - */ - - @Test - public void verifyCmdOptions() throws Exception { - project.setDefinition(new CpsFlowDefinition( - "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); - WorkflowRun build = project.scheduleBuild2(0).get(); - j.assertLogContains("setenv('MW_ORIG_WORKING_FOLDER',", build); - j.assertLogContains("run-matlab-command", build); - } + * Verify default command options for test run. + */ + + @Test + public void verifyCmdOptions() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("setenv('MW_ORIG_WORKING_FOLDER',", build); + j.assertLogContains("run-matlab-command", build); + } /* * Verify Artifact is not sent as parameter. @@ -128,9 +126,9 @@ public void verifyArtifactParameters() throws Exception { j.assertLogNotContains("SimulinkTestResults", build); j.assertLogNotContains("CoberturaModelCoverage", build); } - + /* - * Verify runMatlabTests runs with empty parameters when nothing no artifact selected + * Verify runMatlabTests runs with empty parameters when nothing no artifact selected */ @Test @@ -155,34 +153,37 @@ public void verifyExceptionForNonZeroExitCode() throws Exception { j.assertBuildStatus(Result.FAILURE, build); j.assertLogContains(String.format(Message.getValue("matlab.execution.exception.prefix"), 1), build); } - - /*@Integ Test - * Verify default command options for test Filter using selectByFolder option + + /* + * @Integ Test + * Verify default command options for test Filter using selectByFolder option */ - public void verifyTestSelectByFolder () throws Exception { + public void verifyTestSelectByFolder() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(selectByFolder:['mytest1','mytest2'])}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("mytest1", build); j.assertLogContains("mytest2", build); } - - /*@Integ Test - * Verify default command options for test Filter using selectByTag option + + /* + * @Integ Test + * Verify default command options for test Filter using selectByTag option */ - public void verifyTestSelectByTag () throws Exception { + public void verifyTestSelectByTag() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(selectByTag: 'myTestTag')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("myTestTag", build); } - - /*@Integ + + /* + * @Integ * Verify outputDetail set */ - + public void verifyOutputDetailSet() { Map outputDetail = new HashMap(); outputDetail.put("none", "'OutputDetail', 0"); @@ -204,12 +205,12 @@ public void verifyOutputDetailSet() { } }); } - - /*@Integ - * Verify loggingLevel set + + /* + * @Integ + * Verify loggingLevel set */ - - + public void verifyLoggingLevelSet() { Map outputDetail = new HashMap(); outputDetail.put("none", "'LoggingLevel', 0"); @@ -232,45 +233,49 @@ public void verifyLoggingLevelSet() { } }); } - - /*@Integ - * Verify when useParallel Set + + /* + * @Integ + * Verify when useParallel Set */ - - public void verifyUseParallelSet () throws Exception { + + public void verifyUseParallelSet() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(useParallel: true)}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("runInParallel", build); } - - /*@Integ - * Verify when useParallel Not Set + + /* + * @Integ + * Verify when useParallel Not Set */ - - public void verifyUseParallelNotSet () throws Exception { + + public void verifyUseParallelNotSet() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(useParallel: false)}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogNotContains("runInParallel", build); } - - /*@Integ - * Verify when strict Set + + /* + * @Integ + * Verify when strict Set */ - - public void verifyStrictSet () throws Exception { + + public void verifyStrictSet() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(strict: true)}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("FailOnWarningsPlugin", build); } - - /*@Integ - * Verify when strict is not Set + + /* + * @Integ + * Verify when strict is not Set */ - - public void verifyStrictNotSet () throws Exception { + + public void verifyStrictNotSet() throws Exception { project.setDefinition(new CpsFlowDefinition( "node {runMATLABTests(strict: false)}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); diff --git a/src/test/java/integ/com/mathworks/ci/TestMessage.java b/src/test/java/integ/com/mathworks/ci/TestMessage.java index 60846be0..061bb5e1 100644 --- a/src/test/java/integ/com/mathworks/ci/TestMessage.java +++ b/src/test/java/integ/com/mathworks/ci/TestMessage.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /* - * Copyright 2018 The MathWorks, Inc. + * Copyright 2018-2024 The MathWorks, Inc. * * This Class is wrapper to access the static configuration values used across test classes. Acts as * Utility class to access key & value pairs from testconfig.properties diff --git a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java index 851bfb2b..bddad7c7 100644 --- a/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java +++ b/src/test/java/integ/com/mathworks/ci/UseMatlabVersionBuildWrapperTest.java @@ -1,10 +1,9 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2019-2024 The MathWorks, Inc. * * Test class for AddMatlabToPathBuildWrapper - * */ import java.io.File; @@ -27,26 +26,24 @@ import hudson.tasks.BuildWrapper; public class UseMatlabVersionBuildWrapperTest { - + private FreeStyleProject project; private UseMatlabVersionBuildWrapper buildWrapper; private static String FileSeperator; private static String VERSION_INFO_XML_FILE = "VersionInfo.xml"; - + @BeforeClass public static void classSetup() { if (!System.getProperty("os.name").startsWith("Win")) { FileSeperator = "/"; - }else { + } else { FileSeperator = "\\"; } } - - @Rule public JenkinsRule jenkins = new JenkinsRule(); - + @Before public void testSetup() throws IOException { this.project = jenkins.createFreeStyleProject(); @@ -57,29 +54,32 @@ public void testSetup() throws IOException { public void testTearDown() { this.project = null; } - - //Private Method to get the valid MATLAB roots + + // Private Method to get the valid MATLAB roots private String getMatlabroot(String version) throws URISyntaxException { String defaultVersionInfo = "versioninfo/R2017a/" + VERSION_INFO_XML_FILE; - String userVersionInfo = "versioninfo/"+version+"/" + VERSION_INFO_XML_FILE; - URL matlabRootURL = Optional.ofNullable(getResource(userVersionInfo)).orElseGet(() -> getResource(defaultVersionInfo)); + String userVersionInfo = "versioninfo/" + version + "/" + VERSION_INFO_XML_FILE; + URL matlabRootURL = Optional.ofNullable(getResource(userVersionInfo)) + .orElseGet(() -> getResource(defaultVersionInfo)); File matlabRoot = new File(matlabRootURL.toURI()); - return matlabRoot.getAbsolutePath().replace(FileSeperator + VERSION_INFO_XML_FILE,"").replace("R2017a",version); + return matlabRoot.getAbsolutePath().replace(FileSeperator + VERSION_INFO_XML_FILE, "").replace("R2017a", + version); } - + private URL getResource(String resource) { - return UseMatlabVersionBuildWrapperTest.class.getClassLoader().getResource(resource); + return UseMatlabVersionBuildWrapperTest.class.getClassLoader().getResource(resource); } - + /* * Test Case to verify if job contains MATLAB build environment section. */ @Test public void verifyBuildEnvForMatlab() throws Exception { boolean found = false; - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), "")); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), "")); project.getBuildWrappersList().add(this.buildWrapper); - List bw = project.getBuildWrappersList(); + List bw = project.getBuildWrappersList(); for (BuildWrapper b : bw) { if (b.getDescriptor().getDisplayName() .equalsIgnoreCase(Message.getValue("Buildwrapper.display.name"))) { @@ -88,37 +88,40 @@ public void verifyBuildEnvForMatlab() throws Exception { } Assert.assertTrue("Build does not have MATLAB build environment", found); } - + /* * Verify if given MATLAB root is added in the PATH. * Should be added to integration test. */ - + public void verifyPATHupdated() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/R2019a"))); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/R2019a"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("",""); + RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("", ""); project.getBuildersList().add(buildTester); FreeStyleBuild build = project.scheduleBuild2(0).get(); - Assert.assertTrue("Build does not have MATLAB build environment", this.buildWrapper.getMatlabRootFolder().equalsIgnoreCase(buildTester.getMatlabRoot())); + Assert.assertTrue("Build does not have MATLAB build environment", + this.buildWrapper.getMatlabRootFolder().equalsIgnoreCase(buildTester.getMatlabRoot())); } - + /* * Verify if invalid MATLAB path throes error on console. */ @Test public void verifyInvalidPATHError() throws Exception { - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/R2019a"))); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/R2019a"))); project.getBuildWrappersList().add(this.buildWrapper); - RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("",""); + RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("", ""); project.getBuildersList().add(buildTester); project.scheduleBuild2(0).get(); FreeStyleBuild build = project.scheduleBuild2(0).get(); jenkins.assertLogContains("MatlabNotFoundError", build); } - + /* - * Test To verify if UI throws an error when MATLAB root is empty. + * Test To verify if UI throws an error when MATLAB root is empty. * */ @@ -128,7 +131,7 @@ public void verifyEmptyMatlabRootError() throws Exception { HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); WebAssert.assertTextPresent(page, TestMessage.getValue("Builder.matlab.root.empty.error")); } - + /* * Test To verify UI does throw error when in-valid MATLAB root entered * @@ -137,12 +140,12 @@ public void verifyEmptyMatlabRootError() throws Exception { @Test public void verifyInvalidMatlabRootDisplaysWarnning() throws Exception { project.getBuildWrappersList().add(this.buildWrapper); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("/fake/MATLAB/path"))); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), getMatlabroot("/fake/MATLAB/path"))); HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); WebAssert.assertTextPresent(page, TestMessage.getValue("Builder.invalid.matlab.root.warning")); } - - + /* * Test To verify UI does not throw error when matrix variables are use * @@ -151,11 +154,12 @@ public void verifyInvalidMatlabRootDisplaysWarnning() throws Exception { @Test public void verifyMatriVariableNoErrorOrWarnning() throws Exception { project.getBuildWrappersList().add(this.buildWrapper); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/$VERSION"))); + this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent( + Message.getValue("matlab.custom.location"), getMatlabroot("/test/MATLAB/$VERSION"))); HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); WebAssert.assertTextNotPresent(page, TestMessage.getValue("Builder.invalid.matlab.root.warning")); } - + /* * Test To verify UI does not throw warning when valid Matlab root is entered. * @@ -164,11 +168,10 @@ public void verifyMatriVariableNoErrorOrWarnning() throws Exception { @Test public void verifyValidMatlabNoWarning() throws Exception { project.getBuildWrappersList().add(this.buildWrapper); - this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); + this.buildWrapper.setMatlabBuildWrapperContent( + new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2018b"))); HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure"); WebAssert.assertTextNotPresent(page, TestMessage.getValue("Builder.invalid.matlab.root.warning")); } - - } diff --git a/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java index 44dadae0..795475d4 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/MatlabActionTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.File; @@ -36,14 +35,21 @@ @RunWith(MockitoJUnitRunner.Silent.class) public class MatlabActionTest { - @Mock CommandActionParameters params; - @Mock BuildConsoleAnnotator annotator; - @Mock MatlabCommandRunner runner; - @Mock PrintStream out; - @Mock TaskListener listener; - @Mock Run build; - - @Mock FilePath tempFolder; + @Mock + CommandActionParameters params; + @Mock + BuildConsoleAnnotator annotator; + @Mock + MatlabCommandRunner runner; + @Mock + PrintStream out; + @Mock + TaskListener listener; + @Mock + Run build; + + @Mock + FilePath tempFolder; private boolean setup = false; private RunMatlabCommandAction action; @@ -74,13 +80,16 @@ public void shouldCopyPluginsToTempDirectory() throws IOException, InterruptedEx inOrder.verify(runner) .copyFileToTempFolder(MatlabBuilderConstants.DEFAULT_PLUGIN, MatlabBuilderConstants.DEFAULT_PLUGIN); inOrder.verify(runner) - .copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, MatlabBuilderConstants.BUILD_REPORT_PLUGIN); + .copyFileToTempFolder(MatlabBuilderConstants.BUILD_REPORT_PLUGIN, + MatlabBuilderConstants.BUILD_REPORT_PLUGIN); inOrder.verify(runner) - .copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); + .copyFileToTempFolder(MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN, + MatlabBuilderConstants.TASK_RUN_PROGRESS_PLUGIN); } @Test - public void shouldOverrideDefaultBuildtoolPlugin() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldOverrideDefaultBuildtoolPlugin() + throws IOException, InterruptedException, MatlabExecutionException { action.run(); verify(runner).addEnvironmentVariable( @@ -89,7 +98,8 @@ public void shouldOverrideDefaultBuildtoolPlugin() throws IOException, Interrupt } @Test - public void shouldCopyBuildResultsToRootAndAddAction() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldCopyBuildResultsToRootAndAddAction() + throws IOException, InterruptedException, MatlabExecutionException { File tmp = Files.createTempDirectory("temp").toFile(); tmp.deleteOnExit(); @@ -107,7 +117,7 @@ public void shouldCopyBuildResultsToRootAndAddAction() throws IOException, Inter // Should have deleted original file assertFalse(json.exists()); // Should have copied file to root dir - assertTrue(new File(dest, "buildArtifact"+ action.getActionID() + ".json").exists()); + assertTrue(new File(dest, "buildArtifact" + action.getActionID() + ".json").exists()); } @Test diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java index bfd66117..d4ce810e 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabBuildActionTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -30,14 +29,21 @@ @RunWith(MockitoJUnitRunner.class) public class RunMatlabBuildActionTest { - @Mock BuildActionParameters params; - @Mock BuildConsoleAnnotator annotator; - @Mock MatlabCommandRunner runner; - @Mock TaskListener listener; - @Mock PrintStream out; - @Mock Run build; - - @Mock FilePath tempFolder; + @Mock + BuildActionParameters params; + @Mock + BuildConsoleAnnotator annotator; + @Mock + MatlabCommandRunner runner; + @Mock + TaskListener listener; + @Mock + PrintStream out; + @Mock + Run build; + + @Mock + FilePath tempFolder; private boolean setup = false; private RunMatlabBuildAction action; @@ -74,17 +80,18 @@ public void shouldRunCorrectCommand() throws IOException, InterruptedException, } @Test - public void shouldRunCommandWithTasksAndBuildOptions() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldRunCommandWithTasksAndBuildOptions() + throws IOException, InterruptedException, MatlabExecutionException { doReturn("dishes groceries").when(params).getTasks(); doReturn("-continueOnFailure -skip dishes").when(params) - .getBuildOptions(); + .getBuildOptions(); action.run(); verify(runner).runMatlabCommand( "addpath('/path/less/traveled'); " - + "buildtool dishes groceries " - + "-continueOnFailure -skip dishes"); + + "buildtool dishes groceries " + + "-continueOnFailure -skip dishes"); } @Test @@ -96,6 +103,7 @@ public void shouldPrintAndRethrowMessage() throws IOException, InterruptedExcept } catch (MatlabExecutionException e) { verify(out).println(e.getMessage()); assertEquals(12, e.getExitCode()); - }; + } + ; } } diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java index 0456c292..5f4cee96 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabCommandActionTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -30,14 +29,21 @@ @RunWith(MockitoJUnitRunner.Silent.class) public class RunMatlabCommandActionTest { - @Mock CommandActionParameters params; - @Mock BuildConsoleAnnotator annotator; - @Mock MatlabCommandRunner runner; - @Mock PrintStream out; - @Mock TaskListener listener; - @Mock Run build; - - @Mock FilePath tempFolder; + @Mock + CommandActionParameters params; + @Mock + BuildConsoleAnnotator annotator; + @Mock + MatlabCommandRunner runner; + @Mock + PrintStream out; + @Mock + TaskListener listener; + @Mock + Run build; + + @Mock + FilePath tempFolder; private boolean setup = false; private RunMatlabCommandAction action; @@ -91,6 +97,7 @@ public void printsAndRethrowsMessage() throws IOException, InterruptedException, } catch (MatlabExecutionException e) { verify(out).println(e.getMessage()); assertEquals(12, e.getExitCode()); - }; + } + ; } } diff --git a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java index 85de29e9..6519c08b 100644 --- a/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java +++ b/src/test/java/unit/com/mathworks/ci/actions/RunMatlabTestsActionTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -31,11 +30,16 @@ @RunWith(MockitoJUnitRunner.class) public class RunMatlabTestsActionTest { - @Mock TestActionParameters params; - @Mock MatlabCommandRunner runner; - @Mock PrintStream out; - @Mock TaskListener listener; - @Mock FilePath tempFolder; + @Mock + TestActionParameters params; + @Mock + MatlabCommandRunner runner; + @Mock + PrintStream out; + @Mock + TaskListener listener; + @Mock + FilePath tempFolder; private boolean setup = false; private RunMatlabTestsAction action; @@ -50,7 +54,7 @@ public void init() throws IOException, InterruptedException { when(runner.getTempFolder()).thenReturn(tempFolder); when(tempFolder.getRemote()).thenReturn("/gravel/path"); when(runner.copyFileToTempFolder(anyString(), anyString())) - .thenReturn(tempFolder); + .thenReturn(tempFolder); } } @@ -75,7 +79,8 @@ public void shouldAddTempFolderToPath() throws IOException, InterruptedException } @Test - public void shouldReplaceParamsCorrectlyWhenAllNull() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldReplaceParamsCorrectlyWhenAllNull() + throws IOException, InterruptedException, MatlabExecutionException { // Keep parameters as null action.run(); @@ -86,7 +91,8 @@ public void shouldReplaceParamsCorrectlyWhenAllNull() throws IOException, Interr } @Test - public void shouldReplaceParamsCorrectlyWithFewNull() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldReplaceParamsCorrectlyWithFewNull() + throws IOException, InterruptedException, MatlabExecutionException { // Set some params doReturn("results.xml").when(params).getTestResultsJUnit(); doReturn("cov.xml").when(params).getCodeCoverageCobertura(); @@ -104,17 +110,17 @@ public void shouldReplaceParamsCorrectlyWithFewNull() throws IOException, Interr ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); verify(runner).runMatlabCommand(captor.capture()); assertThat(captor.getValue(), containsString( - "genscript('Test','JUnitTestResults','results.xml'," - + "'CoberturaCodeCoverage','cov.xml'," - + "'Strict',true," - + "'LoggingLevel','Default'," - + "'OutputDetail','Concise'," - + "'SourceFolder',{'src','toolbox'})" - )); + "genscript('Test','JUnitTestResults','results.xml'," + + "'CoberturaCodeCoverage','cov.xml'," + + "'Strict',true," + + "'LoggingLevel','Default'," + + "'OutputDetail','Concise'," + + "'SourceFolder',{'src','toolbox'})")); } @Test - public void shouldReplaceParamsCorrectlyWithNoneNull() throws IOException, InterruptedException, MatlabExecutionException { + public void shouldReplaceParamsCorrectlyWithNoneNull() + throws IOException, InterruptedException, MatlabExecutionException { // Set all params doReturn("results.pdf").when(params).getTestResultsPDF(); doReturn("results.tap").when(params).getTestResultsTAP(); @@ -139,21 +145,20 @@ public void shouldReplaceParamsCorrectlyWithNoneNull() throws IOException, Inter ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); verify(runner).runMatlabCommand(captor.capture()); assertThat(captor.getValue(), containsString( - "genscript('Test'," - + "'PDFTestReport','results.pdf'," - + "'TAPTestResults','results.tap'," - + "'JUnitTestResults','results.xml'," - + "'CoberturaCodeCoverage','cov.xml'," - + "'SimulinkTestResults','results.sltest'," - + "'CoberturaModelCoverage','cov.model'," - + "'SelectByTag','MyTag'," - + "'UseParallel',true," - + "'Strict',true," - + "'LoggingLevel','Default'," - + "'OutputDetail','Concise'," - + "'SourceFolder',{'src','toolbox'}," - + "'SelectByFolder',{'src','toolbox'})" - )); + "genscript('Test'," + + "'PDFTestReport','results.pdf'," + + "'TAPTestResults','results.tap'," + + "'JUnitTestResults','results.xml'," + + "'CoberturaCodeCoverage','cov.xml'," + + "'SimulinkTestResults','results.sltest'," + + "'CoberturaModelCoverage','cov.model'," + + "'SelectByTag','MyTag'," + + "'UseParallel',true," + + "'Strict',true," + + "'LoggingLevel','Default'," + + "'OutputDetail','Concise'," + + "'SourceFolder',{'src','toolbox'}," + + "'SelectByFolder',{'src','toolbox'})")); } @Test @@ -168,6 +173,7 @@ public void printsAndRethrowsMessage() throws IOException, InterruptedException, } catch (MatlabExecutionException e) { verify(out).println(e.getMessage()); assertEquals(12, e.getExitCode()); - }; + } + ; } } diff --git a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabBuildBuilderUnitTest.java b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabBuildBuilderUnitTest.java index 02e38116..e4ca91f0 100644 --- a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabBuildBuilderUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabBuildBuilderUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -48,7 +47,7 @@ public class RunMatlabBuildBuilderUnitTest { TaskListener listener; @Mock - FilePath workspace; + FilePath workspace; @Before public void setup() throws IOException, InterruptedException { @@ -60,12 +59,12 @@ public void shouldHandleNullCases() throws IOException, InterruptedException, Ma RunMatlabBuildBuilder builder = new RunMatlabBuildBuilder(factory); builder.perform(build, workspace, launcher, listener); - + ArgumentCaptor captor = ArgumentCaptor.forClass(BuildActionParameters.class); verify(factory).createAction(captor.capture()); BuildActionParameters actual = captor.getValue(); - + assertEquals("", actual.getStartupOptions()); assertEquals(null, actual.getTasks()); assertEquals(null, actual.getBuildOptions()); @@ -80,12 +79,12 @@ public void shouldHandleMaximalCases() throws IOException, InterruptedException, builder.setStartupOptions(new StartupOptions("-nojvm -logfile mylog")); builder.perform(build, workspace, launcher, listener); - + ArgumentCaptor captor = ArgumentCaptor.forClass(BuildActionParameters.class); verify(factory).createAction(captor.capture()); BuildActionParameters actual = captor.getValue(); - + assertEquals("-nojvm -logfile mylog", actual.getStartupOptions()); assertEquals("laundry sweeping", actual.getTasks()); assertEquals("-continueOnFailure -skip laundry", actual.getBuildOptions()); @@ -95,7 +94,7 @@ public void shouldHandleMaximalCases() throws IOException, InterruptedException, @Test public void shouldMarkFailureWhenActionFails() throws IOException, InterruptedException, MatlabExecutionException { RunMatlabBuildBuilder builder = new RunMatlabBuildBuilder(factory); - + doThrow(new MatlabExecutionException(12)).when(action).run(); builder.perform(build, workspace, launcher, listener); @@ -103,4 +102,3 @@ public void shouldMarkFailureWhenActionFails() throws IOException, InterruptedEx verify(build).setResult(Result.FAILURE); } } - diff --git a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java index 3cc2e830..b93fdacd 100644 --- a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabCommandBuilderUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -47,7 +46,7 @@ public class RunMatlabCommandBuilderUnitTest { TaskListener listener; @Mock - FilePath workspace; + FilePath workspace; @Before public void setup() throws IOException, InterruptedException { @@ -59,12 +58,12 @@ public void shouldHandleNullCases() throws IOException, InterruptedException, Ma RunMatlabCommandBuilder builder = new RunMatlabCommandBuilder(factory); builder.perform(build, workspace, launcher, listener); - + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); CommandActionParameters actual = captor.getValue(); - + assertEquals("", actual.getStartupOptions()); assertEquals(null, actual.getCommand()); verify(action).run(); @@ -77,12 +76,12 @@ public void shouldHandleMaximalCases() throws IOException, InterruptedException, builder.setStartupOptions(new StartupOptions("-nojvm -logfile mylog")); builder.perform(build, workspace, launcher, listener); - + ArgumentCaptor captor = ArgumentCaptor.forClass(CommandActionParameters.class); verify(factory).createAction(captor.capture()); CommandActionParameters actual = captor.getValue(); - + assertEquals("-nojvm -logfile mylog", actual.getStartupOptions()); assertEquals("SHAKE", actual.getCommand()); verify(action).run(); @@ -91,7 +90,7 @@ public void shouldHandleMaximalCases() throws IOException, InterruptedException, @Test public void shouldMarkFailureWhenActionFails() throws IOException, InterruptedException, MatlabExecutionException { RunMatlabCommandBuilder builder = new RunMatlabCommandBuilder(factory); - + doThrow(new MatlabExecutionException(12)).when(action).run(); builder.perform(build, workspace, launcher, listener); @@ -99,4 +98,3 @@ public void shouldMarkFailureWhenActionFails() throws IOException, InterruptedEx verify(build).setResult(Result.FAILURE); } } - diff --git a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java index d8393374..b492607e 100644 --- a/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/freestyle/RunMatlabTestsBuilderUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -32,126 +31,126 @@ @RunWith(MockitoJUnitRunner.class) public class RunMatlabTestsBuilderUnitTest { - @Mock - MatlabActionFactory factory; - - @Mock - RunMatlabTestsAction action; - - @Mock - Run build; - - @Mock - Launcher launcher; - - @Mock - TaskListener listener; - - @Mock - FilePath workspace; - - @Before - public void setup() throws IOException, InterruptedException { - doReturn(action).when(factory).createAction(any(TestActionParameters.class)); - } - - @Test - public void shouldHandleNullCases() throws IOException, InterruptedException, MatlabExecutionException { - RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); - - builder.perform(build, workspace, launcher, listener); - - ArgumentCaptor captor = ArgumentCaptor.forClass(TestActionParameters.class); - verify(factory).createAction(captor.capture()); - - TestActionParameters actual = captor.getValue(); - - assertEquals("", actual.getStartupOptions()); - assertEquals(null, actual.getTestResultsPDF()); - assertEquals(null, actual.getTestResultsTAP()); - assertEquals(null, actual.getTestResultsJUnit()); - assertEquals(null, actual.getCodeCoverageCobertura()); - assertEquals(null, actual.getTestResultsSimulinkTest()); - assertEquals(null, actual.getModelCoverageCobertura()); - assertEquals(null, actual.getSelectByTag()); - assertEquals(null, actual.getLoggingLevel()); - assertEquals(null, actual.getOutputDetail()); - assertEquals("false", actual.getUseParallel()); - assertEquals("false", actual.getStrict()); - assertEquals(null, actual.getSourceFolder()); - assertEquals(null, actual.getSelectByFolder()); - verify(action).run(); - } - - @Test - public void shouldHandleMaximalCases() throws IOException, InterruptedException, MatlabExecutionException { - RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); - - ArrayList source = new ArrayList(); - source.add(new SourceFolderPaths("toolbox")); - source.add(new SourceFolderPaths("src")); - - ArrayList select = new ArrayList(); - select.add(new TestFolders("toolbox")); - select.add(new TestFolders("src")); - - builder.setStartupOptions(new StartupOptions("-nojvm -logfile mylog")); - builder.setPdfReportArtifact( - new RunMatlabTestsBuilder.PdfArtifact("pdf.pdf")); - builder.setTapArtifact( - new RunMatlabTestsBuilder.TapArtifact("tap.tap")); - builder.setJunitArtifact( - new RunMatlabTestsBuilder.JunitArtifact("results.xml")); - builder.setCoberturaArtifact( - new RunMatlabTestsBuilder.CoberturaArtifact("cov.xml")); - builder.setStmResultsArtifact( - new RunMatlabTestsBuilder.StmResultsArtifact("res.sltest")); - builder.setModelCoverageArtifact( - new RunMatlabTestsBuilder.ModelCovArtifact("cov.model")); - builder.setSelectByTag( - new RunMatlabTestsBuilder.SelectByTag("MyTag")); - builder.setSourceFolder( - new SourceFolder(source)); - builder.setSelectByFolder( - new SelectByFolder(select)); - builder.setLoggingLevel("Concise"); - builder.setOutputDetail("Concise"); - builder.setUseParallel(true); - builder.setStrict(true); - - builder.perform(build, workspace, launcher, listener); - - ArgumentCaptor captor = ArgumentCaptor.forClass(TestActionParameters.class); - verify(factory).createAction(captor.capture()); - - TestActionParameters actual = captor.getValue(); - - assertEquals("-nojvm -logfile mylog", actual.getStartupOptions()); - assertEquals("pdf.pdf", actual.getTestResultsPDF()); - assertEquals("tap.tap", actual.getTestResultsTAP()); - assertEquals("results.xml", actual.getTestResultsJUnit()); - assertEquals("cov.xml", actual.getCodeCoverageCobertura()); - assertEquals("res.sltest", actual.getTestResultsSimulinkTest()); - assertEquals("cov.model", actual.getModelCoverageCobertura()); - assertEquals("MyTag", actual.getSelectByTag()); - assertEquals("Concise", actual.getLoggingLevel()); - assertEquals("Concise", actual.getOutputDetail()); - assertEquals("true", actual.getUseParallel()); - assertEquals("true", actual.getStrict()); - assertEquals(2, actual.getSourceFolder().size()); - assertEquals(2, actual.getSelectByFolder().size()); - verify(action).run(); - } - - @Test - public void shouldMarkFailureWhenActionFails() throws IOException, InterruptedException, MatlabExecutionException { - RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); - - doThrow(new MatlabExecutionException(12)).when(action).run(); - - builder.perform(build, workspace, launcher, listener); - - verify(build).setResult(Result.FAILURE); - } + @Mock + MatlabActionFactory factory; + + @Mock + RunMatlabTestsAction action; + + @Mock + Run build; + + @Mock + Launcher launcher; + + @Mock + TaskListener listener; + + @Mock + FilePath workspace; + + @Before + public void setup() throws IOException, InterruptedException { + doReturn(action).when(factory).createAction(any(TestActionParameters.class)); + } + + @Test + public void shouldHandleNullCases() throws IOException, InterruptedException, MatlabExecutionException { + RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); + + builder.perform(build, workspace, launcher, listener); + + ArgumentCaptor captor = ArgumentCaptor.forClass(TestActionParameters.class); + verify(factory).createAction(captor.capture()); + + TestActionParameters actual = captor.getValue(); + + assertEquals("", actual.getStartupOptions()); + assertEquals(null, actual.getTestResultsPDF()); + assertEquals(null, actual.getTestResultsTAP()); + assertEquals(null, actual.getTestResultsJUnit()); + assertEquals(null, actual.getCodeCoverageCobertura()); + assertEquals(null, actual.getTestResultsSimulinkTest()); + assertEquals(null, actual.getModelCoverageCobertura()); + assertEquals(null, actual.getSelectByTag()); + assertEquals(null, actual.getLoggingLevel()); + assertEquals(null, actual.getOutputDetail()); + assertEquals("false", actual.getUseParallel()); + assertEquals("false", actual.getStrict()); + assertEquals(null, actual.getSourceFolder()); + assertEquals(null, actual.getSelectByFolder()); + verify(action).run(); + } + + @Test + public void shouldHandleMaximalCases() throws IOException, InterruptedException, MatlabExecutionException { + RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); + + ArrayList source = new ArrayList(); + source.add(new SourceFolderPaths("toolbox")); + source.add(new SourceFolderPaths("src")); + + ArrayList select = new ArrayList(); + select.add(new TestFolders("toolbox")); + select.add(new TestFolders("src")); + + builder.setStartupOptions(new StartupOptions("-nojvm -logfile mylog")); + builder.setPdfReportArtifact( + new RunMatlabTestsBuilder.PdfArtifact("pdf.pdf")); + builder.setTapArtifact( + new RunMatlabTestsBuilder.TapArtifact("tap.tap")); + builder.setJunitArtifact( + new RunMatlabTestsBuilder.JunitArtifact("results.xml")); + builder.setCoberturaArtifact( + new RunMatlabTestsBuilder.CoberturaArtifact("cov.xml")); + builder.setStmResultsArtifact( + new RunMatlabTestsBuilder.StmResultsArtifact("res.sltest")); + builder.setModelCoverageArtifact( + new RunMatlabTestsBuilder.ModelCovArtifact("cov.model")); + builder.setSelectByTag( + new RunMatlabTestsBuilder.SelectByTag("MyTag")); + builder.setSourceFolder( + new SourceFolder(source)); + builder.setSelectByFolder( + new SelectByFolder(select)); + builder.setLoggingLevel("Concise"); + builder.setOutputDetail("Concise"); + builder.setUseParallel(true); + builder.setStrict(true); + + builder.perform(build, workspace, launcher, listener); + + ArgumentCaptor captor = ArgumentCaptor.forClass(TestActionParameters.class); + verify(factory).createAction(captor.capture()); + + TestActionParameters actual = captor.getValue(); + + assertEquals("-nojvm -logfile mylog", actual.getStartupOptions()); + assertEquals("pdf.pdf", actual.getTestResultsPDF()); + assertEquals("tap.tap", actual.getTestResultsTAP()); + assertEquals("results.xml", actual.getTestResultsJUnit()); + assertEquals("cov.xml", actual.getCodeCoverageCobertura()); + assertEquals("res.sltest", actual.getTestResultsSimulinkTest()); + assertEquals("cov.model", actual.getModelCoverageCobertura()); + assertEquals("MyTag", actual.getSelectByTag()); + assertEquals("Concise", actual.getLoggingLevel()); + assertEquals("Concise", actual.getOutputDetail()); + assertEquals("true", actual.getUseParallel()); + assertEquals("true", actual.getStrict()); + assertEquals(2, actual.getSourceFolder().size()); + assertEquals(2, actual.getSelectByFolder().size()); + verify(action).run(); + } + + @Test + public void shouldMarkFailureWhenActionFails() + throws IOException, InterruptedException, MatlabExecutionException { + RunMatlabTestsBuilder builder = new RunMatlabTestsBuilder(factory); + + doThrow(new MatlabExecutionException(12)).when(action).run(); + + builder.perform(build, workspace, launcher, listener); + + verify(build).setResult(Result.FAILURE); + } } - diff --git a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabBuildStepExecutionUnitTest.java b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabBuildStepExecutionUnitTest.java index 5699646d..2729138a 100644 --- a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabBuildStepExecutionUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabBuildStepExecutionUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -26,10 +25,13 @@ @RunWith(MockitoJUnitRunner.class) public class MatlabBuildStepExecutionUnitTest { - @Mock StepContext context; - @Mock MatlabActionFactory factory; - @Mock RunMatlabBuildAction action; - + @Mock + StepContext context; + @Mock + MatlabActionFactory factory; + @Mock + RunMatlabBuildAction action; + @Before public void setup() throws IOException, InterruptedException { when(factory.createAction(any(BuildActionParameters.class))).thenReturn(action); @@ -54,7 +56,8 @@ public void shouldHandleNullCases() throws Exception, IOException, InterruptedEx } @Test - public void shouldHandleMaximalCases() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleMaximalCases() + throws Exception, IOException, InterruptedException, MatlabExecutionException { RunMatlabBuildStep step = new RunMatlabBuildStep(); step.setStartupOptions("-nojvm -logfile file"); step.setTasks("vacuum bills"); @@ -77,7 +80,8 @@ public void shouldHandleMaximalCases() throws Exception, IOException, Interrupte } @Test - public void shouldHandleActionThrowing() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleActionThrowing() + throws Exception, IOException, InterruptedException, MatlabExecutionException { MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, new RunMatlabBuildStep()); doThrow(new MatlabExecutionException(12)).when(action).run(); diff --git a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java index f4e5ed9b..50c54dfb 100644 --- a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -26,10 +25,13 @@ @RunWith(MockitoJUnitRunner.class) public class MatlabCommandStepExecutionUnitTest { - @Mock StepContext context; - @Mock MatlabActionFactory factory; - @Mock RunMatlabCommandAction action; - + @Mock + StepContext context; + @Mock + MatlabActionFactory factory; + @Mock + RunMatlabCommandAction action; + @Before public void setup() throws IOException, InterruptedException { when(factory.createAction(any(CommandActionParameters.class))).thenReturn(action); @@ -38,8 +40,8 @@ public void setup() throws IOException, InterruptedException { @Test public void shouldHandleNullCases() throws Exception, IOException, InterruptedException, MatlabExecutionException { MatlabCommandStepExecution ex = new MatlabCommandStepExecution( - factory, - context, + factory, + context, new RunMatlabCommandStep(null)); ex.run(); @@ -55,7 +57,8 @@ public void shouldHandleNullCases() throws Exception, IOException, InterruptedEx } @Test - public void shouldHandleMaximalCases() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleMaximalCases() + throws Exception, IOException, InterruptedException, MatlabExecutionException { RunMatlabCommandStep step = new RunMatlabCommandStep("mycommand"); step.setStartupOptions("-nojvm -logfile file"); @@ -74,10 +77,11 @@ public void shouldHandleMaximalCases() throws Exception, IOException, Interrupte } @Test - public void shouldHandleActionThrowing() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleActionThrowing() + throws Exception, IOException, InterruptedException, MatlabExecutionException { MatlabCommandStepExecution ex = new MatlabCommandStepExecution( - factory, - context, + factory, + context, new RunMatlabCommandStep(null)); doThrow(new MatlabExecutionException(12)).when(action).run(); diff --git a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabRunTestsStepExecutionUnitTest.java b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabRunTestsStepExecutionUnitTest.java index fe9d18fd..54e82a71 100644 --- a/src/test/java/unit/com/mathworks/ci/pipeline/MatlabRunTestsStepExecutionUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/pipeline/MatlabRunTestsStepExecutionUnitTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -27,10 +26,13 @@ @RunWith(MockitoJUnitRunner.class) public class MatlabRunTestsStepExecutionUnitTest { - @Mock StepContext context; - @Mock MatlabActionFactory factory; - @Mock RunMatlabTestsAction action; - + @Mock + StepContext context; + @Mock + MatlabActionFactory factory; + @Mock + RunMatlabTestsAction action; + @Before public void setup() throws IOException, InterruptedException { when(factory.createAction(any(TestActionParameters.class))).thenReturn(action); @@ -66,7 +68,8 @@ public void shouldHandleNullCase() throws Exception, IOException, InterruptedExc } @Test - public void shouldHandleMaximalCase() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleMaximalCase() + throws Exception, IOException, InterruptedException, MatlabExecutionException { RunMatlabTestsStep step = new RunMatlabTestsStep(); step.setStartupOptions("-nojvm -logfile file"); step.setTestResultsPDF("res.pdf"); @@ -89,7 +92,7 @@ public void shouldHandleMaximalCase() throws Exception, IOException, Interrupted step.setSelectByFolder(folders); MatlabRunTestsStepExecution ex = new MatlabRunTestsStepExecution(factory, context, step); - + ex.run(); ArgumentCaptor captor = ArgumentCaptor.forClass(TestActionParameters.class); @@ -115,7 +118,8 @@ public void shouldHandleMaximalCase() throws Exception, IOException, Interrupted } @Test - public void shouldHandleActionThrowing() throws Exception, IOException, InterruptedException, MatlabExecutionException { + public void shouldHandleActionThrowing() + throws Exception, IOException, InterruptedException, MatlabExecutionException { MatlabRunTestsStepExecution ex = new MatlabRunTestsStepExecution(factory, context, new RunMatlabTestsStep()); doThrow(new MatlabExecutionException(12)).when(action).run(); diff --git a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java index e5c1e823..8900cd0e 100644 --- a/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/tools/MatlabInstallerUnitTest.java @@ -1,10 +1,9 @@ package com.mathworks.ci.tools; + /** * Copyright 2024, The MathWorks, Inc. - * */ - import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -45,41 +44,41 @@ public class MatlabInstallerUnitTest { private Launcher mockLauncher; @Before - public void setUp () throws Exception { - MockitoAnnotations.initMocks (this); - installer = spy (new MatlabInstaller ("test-id")); + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + installer = spy(new MatlabInstaller("test-id")); installer.setRelease("R2021a"); installer.setProducts("MATLAB"); } @Test - public void testGetRelease () { - assertEquals ("R2021a", installer.getRelease ()); + public void testGetRelease() { + assertEquals("R2021a", installer.getRelease()); } @Test - public void testGetProducts () { - assertEquals ("MATLAB", installer.getProducts ()); + public void testGetProducts() { + assertEquals("MATLAB", installer.getProducts()); } @Test - public void testPerformInstallation () throws Exception { - doReturn (mockFilePath).when (installer) - .performInstallation (mockTool, mockNode, mockListener); + public void testPerformInstallation() throws Exception { + doReturn(mockFilePath).when(installer) + .performInstallation(mockTool, mockNode, mockListener); - FilePath result = installer.performInstallation (mockTool, mockNode, mockListener); - assertNotNull (result); + FilePath result = installer.performInstallation(mockTool, mockNode, mockListener); + assertNotNull(result); } @Test(expected = InstallationFailedException.class) - public void testUnsupportedOS () throws Exception { - installer.getPlatform ("unsupportedOS", "unsupportedArch"); + public void testUnsupportedOS() throws Exception { + installer.getPlatform("unsupportedOS", "unsupportedArch"); } @Test - public void testGetPlatform () throws InstallationFailedException { - assertEquals ("glnxa64", installer.getPlatform ("Linux", "i686")); - assertEquals ("maci64", installer.getPlatform ("Mac OS X", "amd64")); - assertEquals ("maca64", installer.getPlatform ("Mac OS X", "arm64")); + public void testGetPlatform() throws InstallationFailedException { + assertEquals("glnxa64", installer.getPlatform("Linux", "i686")); + assertEquals("maci64", installer.getPlatform("Mac OS X", "amd64")); + assertEquals("maca64", installer.getPlatform("Mac OS X", "arm64")); } } diff --git a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java index b7d0f91e..3edc63df 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/GetSystemPropertiesUnitTest.java @@ -1,10 +1,9 @@ package com.mathworks.ci.utilities; + /** * Copyright 2024, The MathWorks, Inc. - * */ - import static org.junit.Assert.assertArrayEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -19,14 +18,15 @@ public class GetSystemPropertiesUnitTest { private GetSystemProperties getSystemProperties; @Before - public void setUp () { - getSystemProperties = new GetSystemProperties ("os.name","os.arch", "os.version"); + public void setUp() { + getSystemProperties = new GetSystemProperties("os.name", "os.arch", "os.version"); } @Test - public void testCall () { - String[] expected = {System.getProperty ("os.name"),System.getProperty ("os.arch"),System.getProperty ("os.version")}; - String[] result = getSystemProperties.call (); - assertArrayEquals (expected, result); + public void testCall() { + String[] expected = { System.getProperty("os.name"), System.getProperty("os.arch"), + System.getProperty("os.version") }; + String[] result = getSystemProperties.call(); + assertArrayEquals(expected, result); } } diff --git a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java index 4c0087b2..48403d5e 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.File; @@ -40,13 +39,18 @@ @RunWith(MockitoJUnitRunner.class) public class MatlabCommandRunnerTest { - - @Mock private Launcher launcher; - @Mock private ProcStarter procStarter; + + @Mock + private Launcher launcher; + @Mock + private ProcStarter procStarter; private EnvVars env; - @Mock private TaskListener listener; - @Mock private PrintStream logger; - @Mock private MatlabActionParameters params; + @Mock + private TaskListener listener; + @Mock + private PrintStream logger; + @Mock + private MatlabActionParameters params; @Rule public TemporaryFolder tempDir = new TemporaryFolder(); @@ -55,25 +59,25 @@ public class MatlabCommandRunnerTest { @Before public void initialize() throws IOException, InterruptedException { - env = new EnvVars(); - - doReturn(new FilePath(tempDir.getRoot())).when(params).getWorkspace(); - when(params.getLauncher()).thenReturn(launcher); - when(params.getEnvVars()).thenReturn(env); - when(params.getTaskListener()).thenReturn(listener); - when(params.getStartupOptions()).thenReturn(""); - - when(listener.getLogger()).thenReturn(logger); - - doReturn(false).when(launcher).isUnix(); - when(launcher.launch()).thenReturn(procStarter); - when(procStarter.cmds(any(ArgumentListBuilder.class))).thenReturn(procStarter); - when(procStarter.masks(anyBoolean(), anyBoolean(), anyBoolean())) - .thenReturn(procStarter); - when(procStarter.envs(any(EnvVars.class))).thenReturn(procStarter); - doReturn(procStarter).when(procStarter) - .stdout(any(OutputStream.class)); - when(procStarter.join()).thenReturn(0); + env = new EnvVars(); + + doReturn(new FilePath(tempDir.getRoot())).when(params).getWorkspace(); + when(params.getLauncher()).thenReturn(launcher); + when(params.getEnvVars()).thenReturn(env); + when(params.getTaskListener()).thenReturn(listener); + when(params.getStartupOptions()).thenReturn(""); + + when(listener.getLogger()).thenReturn(logger); + + doReturn(false).when(launcher).isUnix(); + when(launcher.launch()).thenReturn(procStarter); + when(procStarter.cmds(any(ArgumentListBuilder.class))).thenReturn(procStarter); + when(procStarter.masks(anyBoolean(), anyBoolean(), anyBoolean())) + .thenReturn(procStarter); + when(procStarter.envs(any(EnvVars.class))).thenReturn(procStarter); + doReturn(procStarter).when(procStarter) + .stdout(any(OutputStream.class)); + when(procStarter.join()).thenReturn(0); } @Test @@ -88,13 +92,13 @@ public void constructorUsesParamsForTempFolder() throws IOException, Interrupted verify(params, times(1)).getWorkspace(); } - @Test + @Test public void correctTempFolderLocation() throws IOException, InterruptedException { runner = new MatlabCommandRunner(params); FilePath tmp = runner.getTempFolder(); FilePath expected = WorkspaceList.tempDir(new FilePath(tempDir.getRoot())); - + Assert.assertTrue(tmp.exists()); Assert.assertThat( tmp.getRemote(), @@ -127,9 +131,9 @@ public void prepareRunnerExecutableMaci() throws IOException, InterruptedExcepti Assert.assertTrue(f.exists()); Assert.assertEquals( - runner.getTempFolder().getRemote() - + File.separator - + "run-matlab-command", + runner.getTempFolder().getRemote() + + File.separator + + "run-matlab-command", f.getRemote()); } @@ -137,26 +141,26 @@ public void prepareRunnerExecutableMaci() throws IOException, InterruptedExcepti public void prepareRunnerExecutableMaca() throws IOException, InterruptedException { runner = new MatlabCommandRunner(params); - doReturn(true).when(launcher).isUnix(); + doReturn(true).when(launcher).isUnix(); when(procStarter.stdout(any(OutputStream.class))).thenAnswer( - new Answer() { - public Object answer(InvocationOnMock invocation) throws IOException { - Object[] args = invocation.getArguments(); - OutputStream s = (OutputStream)args[0]; + new Answer() { + public Object answer(InvocationOnMock invocation) throws IOException { + Object[] args = invocation.getArguments(); + OutputStream s = (OutputStream) args[0]; - String tag = "arm64"; - s.write(tag.getBytes()); - return procStarter; - } - }); + String tag = "arm64"; + s.write(tag.getBytes()); + return procStarter; + } + }); FilePath f = runner.prepareRunnerExecutable(); Assert.assertTrue(f.exists()); Assert.assertEquals( - runner.getTempFolder().getRemote() - + File.separator - + "run-matlab-command", + runner.getTempFolder().getRemote() + + File.separator + + "run-matlab-command", f.getRemote()); } @@ -164,26 +168,26 @@ public Object answer(InvocationOnMock invocation) throws IOException { public void prepareRunnerExecutableLinux() throws IOException, InterruptedException { runner = new MatlabCommandRunner(params); - doReturn(true).when(launcher).isUnix(); + doReturn(true).when(launcher).isUnix(); when(procStarter.stdout(any(OutputStream.class))).thenAnswer( - new Answer() { - public Object answer(InvocationOnMock invocation) throws IOException { - Object[] args = invocation.getArguments(); - OutputStream s = (OutputStream)args[0]; + new Answer() { + public Object answer(InvocationOnMock invocation) throws IOException { + Object[] args = invocation.getArguments(); + OutputStream s = (OutputStream) args[0]; - String tag = "Linux"; - s.write(tag.getBytes()); - return procStarter; - } - }); + String tag = "Linux"; + s.write(tag.getBytes()); + return procStarter; + } + }); FilePath f = runner.prepareRunnerExecutable(); Assert.assertTrue(f.exists()); Assert.assertEquals( - runner.getTempFolder().getRemote() - + File.separator - + "run-matlab-command", + runner.getTempFolder().getRemote() + + File.separator + + "run-matlab-command", f.getRemote()); } @@ -196,8 +200,8 @@ public void prepareRunnerExecutableWindows() throws IOException, InterruptedExce Assert.assertTrue(f.exists()); Assert.assertEquals( runner.getTempFolder().getRemote() - + File.separator - + "run-matlab-command.exe", + + File.separator + + "run-matlab-command.exe", f.getRemote()); } @@ -209,7 +213,7 @@ public void createFileWithContentWorks() throws IOException, InterruptedExceptio FilePath f = runner.createFileWithContent(content); String expected = "cd(getenv('MW_ORIG_WORKING_FOLDER'));\n" - + content; + + content; Assert.assertTrue(f.exists()); Assert.assertThat(f.getRemote(), @@ -220,11 +224,11 @@ public void createFileWithContentWorks() throws IOException, InterruptedExceptio @Test public void copyFileFromResourcePathWorks() throws IOException, InterruptedException { runner = new MatlabCommandRunner(params); - + FilePath f = runner.copyFileToTempFolder("testcontent.txt", "target.txt"); Assert.assertTrue(f.exists()); - Assert.assertThat(f.readToString(), startsWith("This has text!")); + Assert.assertThat(f.readToString(), startsWith("This has text!")); } @Test @@ -235,11 +239,11 @@ public void runWorksInBasicCase() throws IOException, InterruptedException, Matl runner.runMatlabCommand(myCommand); String exe = runner.getTempFolder().getRemote() - + File.separator - + "run-matlab-command.exe"; + + File.separator + + "run-matlab-command.exe"; String cmd = "setenv('MW_ORIG_WORKING_FOLDER', cd('" - + runner.getTempFolder().getRemote() - + "'));script_"; + + runner.getTempFolder().getRemote() + + "'));script_"; ArgumentCaptor captor = ArgumentCaptor.forClass(ArgumentListBuilder.class); verify(procStarter).cmds(captor.capture()); @@ -253,7 +257,7 @@ public void runWorksInBasicCase() throws IOException, InterruptedException, Matl @Test public void runUsesWorkspaceLocationAsWD() throws IOException, InterruptedException, MatlabExecutionException { runner = new MatlabCommandRunner(params); - + runner.runMatlabCommand("COMMAND"); verify(procStarter).pwd(new FilePath(tempDir.getRoot())); @@ -266,7 +270,7 @@ public void runWorksWithAddedEnvVars() throws IOException, InterruptedException, String myCommand = "OBEY"; runner.addEnvironmentVariable("MYVAR", "MYVALUE"); runner.runMatlabCommand(myCommand); - + ArgumentCaptor captor = ArgumentCaptor.forClass(EnvVars.class); verify(procStarter).envs(captor.capture()); @@ -285,16 +289,16 @@ public void runShouldExpandAddedEnvVars() throws IOException, InterruptedExcepti Assert.assertThat(f.readToString(), containsString(myCommand)); } - @Test + @Test public void runWorksWithStartupOptions() throws IOException, InterruptedException, MatlabExecutionException { runner = new MatlabCommandRunner(params); doReturn("-nojvm -logfile mylog.log") - .when(params).getStartupOptions(); + .when(params).getStartupOptions(); String myCommand = "OBEY"; runner.runMatlabCommand(myCommand); - + ArgumentCaptor captor = ArgumentCaptor.forClass(ArgumentListBuilder.class); verify(procStarter).cmds(captor.capture()); @@ -305,7 +309,7 @@ public void runWorksWithStartupOptions() throws IOException, InterruptedExceptio Assert.assertEquals("mylog.log", cmds.get(4)); } - @Test + @Test public void runWorksWithRedirectedOutput() throws IOException, InterruptedException, MatlabExecutionException { OutputStream out = mock(OutputStream.class); diff --git a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTester.java b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTester.java index d8502b8e..799e81ea 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTester.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTester.java @@ -2,7 +2,6 @@ /** * Copyright 2024, The MathWorks Inc. - * */ import java.io.IOException; @@ -10,17 +9,17 @@ import com.mathworks.ci.parameters.MatlabActionParameters; public class MatlabCommandRunnerTester extends MatlabCommandRunner { - public MatlabCommandRunnerTester(MatlabActionParameters params) throws IOException, InterruptedException { - super(params); - } + public MatlabCommandRunnerTester(MatlabActionParameters params) throws IOException, InterruptedException { + super(params); + } - @Override - public FilePath prepareRunnerExecutable() throws IOException, InterruptedException { - return super.prepareRunnerExecutable(); - } + @Override + public FilePath prepareRunnerExecutable() throws IOException, InterruptedException { + return super.prepareRunnerExecutable(); + } - @Override - public FilePath createFileWithContent(String content) throws IOException, InterruptedException { + @Override + public FilePath createFileWithContent(String content) throws IOException, InterruptedException { return super.createFileWithContent(content); - } + } }
    Task NameTask Status DescriptionDuration (HH:MM:SS)Duration (HH:mm:ss)
    + - - FAILED - - - FAILED - + + Failed + - PASSED + Succeeded - - SKIPPED - - - SKIPPED - + + Skipped + + (${p.skipReason}) + +