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

Commit 3480719

Browse files
authored
Merge pull request #353 from mathworks/gecko_2221893
Added check for command textbox
2 parents 0248136 + b88d782 commit 3480719

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/main/java/com/mathworks/ci/freestyle/RunMatlabCommandBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
*
88
*/
99

10+
import hudson.util.FormValidation;
1011
import java.io.IOException;
1112
import javax.annotation.Nonnull;
13+
import jenkins.model.Jenkins;
1214
import org.kohsuke.stapler.DataBoundConstructor;
1315
import org.kohsuke.stapler.DataBoundSetter;
16+
import org.kohsuke.stapler.QueryParameter;
1417
import org.kohsuke.stapler.StaplerRequest;
1518
import hudson.EnvVars;
1619
import hudson.Extension;
@@ -33,6 +36,7 @@
3336
import com.mathworks.ci.actions.MatlabActionFactory;
3437
import com.mathworks.ci.actions.RunMatlabCommandAction;
3538
import com.mathworks.ci.freestyle.options.StartupOptions;
39+
import org.kohsuke.stapler.verb.POST;
3640

3741
public class RunMatlabCommandBuilder extends Builder implements SimpleBuildStep {
3842
// Deprecated
@@ -110,6 +114,15 @@ public boolean isApplicable(
110114
@SuppressWarnings("rawtypes") Class<? extends AbstractProject> jobtype) {
111115
return true;
112116
}
117+
118+
@POST
119+
public FormValidation doCheckMatlabCommand(@QueryParameter String value) {
120+
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
121+
if (value.isEmpty()) {
122+
return FormValidation.error(Message.getValue("matlab.empty.command.error"));
123+
}
124+
return FormValidation.ok();
125+
}
113126
}
114127

115128
@Override

src/main/resources/com/mathworks/ci/freestyle/RunMatlabCommandBuilder/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

44
<f:entry title="Command" field="matlabCommand">
5-
<f:textbox/>
5+
<f:textbox checkMethod="post"/>
66
</f:entry>
77

88
<f:optionalProperty field="startupOptions" title="Startup options" />

src/main/resources/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Releaseinfo.matlab.version.not.found.error = Error finding MATLAB release for gi
1616
matlab.not.found.error = Unable to launch MATLAB from the specified location. Verify the path to MATLAB root folder.
1717
matlab.not.found.error.for.node = Unable to launch MATLAB '%s' on the node '%s'. Verify global tool configuration for the specified node.
1818
matlab.execution.exception.prefix = Received a nonzero exit code %d while trying to run MATLAB.
19+
matlab.empty.command.error = Specify at least one script, function, or statement to execute.
1920
Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model coverage report, use MATLAB R2018b or a newer release.
2021
Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release.
2122
Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*
88
*/
99

10+
import com.gargoylesoftware.htmlunit.WebAssert;
11+
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
12+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
1013
import java.io.File;
1114
import java.io.IOException;
1215
import java.net.URISyntaxException;
@@ -377,4 +380,34 @@ public void verifyMultispecialChar() throws Exception {
377380
jenkins.assertLogContains("Generating MATLAB script with content", build);
378381
jenkins.assertLogContains(expectedCommand, build);
379382
}
383+
384+
/*
385+
* Test to verify error message when command is empty.
386+
*/
387+
388+
@Test
389+
public void verifyErrorMessageOnEmptyCommand() throws Exception {
390+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a")));
391+
project.getBuildWrappersList().add(this.buildWrapper);
392+
project.getBuildersList().add(this.scriptBuilder);
393+
HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure");
394+
395+
WebAssert.assertTextPresent(page,"Specify at least one script, function, or statement to execute.");
396+
}
397+
398+
/*
399+
* Test to verify no error message when command is provided.
400+
*/
401+
402+
@Test
403+
public void verifyWhenCommandNonEmpty() throws Exception {
404+
this.buildWrapper.setMatlabBuildWrapperContent(new MatlabBuildWrapperContent(Message.getValue("matlab.custom.location"), getMatlabroot("R2017a")));
405+
project.getBuildWrappersList().add(this.buildWrapper);
406+
this.scriptBuilder.setMatlabCommand("NONEMPTY");
407+
project.getBuildersList().add(this.scriptBuilder);
408+
HtmlPage page = jenkins.createWebClient().goTo("job/test0/configure");
409+
410+
WebAssert.assertTextNotPresent(page,"Specify at least one script, function, or statement to execute.");
411+
}
412+
380413
}

0 commit comments

Comments
 (0)