Skip to content

Commit

Permalink
Add support for Build Options (#32)
Browse files Browse the repository at this point in the history
* add build options

* modify help text for build options
  • Loading branch information
tsharmaMW committed Mar 4, 2024
1 parent 6cd6858 commit 1191cd9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ private String getTaskName(){
return tasks == null ? "" : tasks;
}

private String getBuildOptions(){
final String buildOptions = getUserInputs().get(MatlabConstants.BUILD_OPTIONS);
return buildOptions == null ? "" : buildOptions;
}

@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
Expand All @@ -35,7 +40,14 @@ public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {

ProgramCommandLine value;
try {
value = this.runner.createCommand(getContext(), "buildtool " + getTaskName());
String cmd = "buildtool";
if (!getTaskName().isEmpty()){
cmd += " " + getTaskName();
}
if (!getBuildOptions().isEmpty()){
cmd += " " + getBuildOptions();
}
value = this.runner.createCommand(getContext(), cmd);
} catch (Exception e) {
throw new RunBuildException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public void testTearDown() throws IOException {
}

@Test(description="Validate default command")
public void verifyDefaultCommandWithNoTasks() throws RunBuildException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
public void verifyDefaultCommandWithNoTasksAndNoBuildOptions() throws RunBuildException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
Map<String, String> envMap = new HashMap<>();
envMap.put("matlabTasks", null);
envMap.put("BuildOptions", null);

doReturn(envMap).when(service).getUserInputs();

Expand All @@ -72,13 +73,14 @@ public void verifyDefaultCommandWithNoTasks() throws RunBuildException, NoSuchMe
ArgumentCaptor<String> matlabCommand = ArgumentCaptor.forClass(String.class);
Mockito.verify(runner).createCommand(isNull(), matlabCommand.capture());

assertEquals("buildtool ", matlabCommand.getValue());
assertEquals("buildtool", matlabCommand.getValue());
}

@Test(description="Validate specific tasks")
public void verifyDefaultCommandWithTasks() throws RunBuildException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
public void verifyDefaultCommandWithTasksAndBuildOptions() throws RunBuildException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
Map<String, String> envMap = new HashMap<>();
envMap.put("matlabTasks", "mex test");
envMap.put("BuildOptions","-continueOnFailure -skip test");

doReturn(envMap).when(service).getUserInputs();

Expand All @@ -87,6 +89,6 @@ public void verifyDefaultCommandWithTasks() throws RunBuildException, NoSuchMeth
ArgumentCaptor<String> matlabCommand = ArgumentCaptor.forClass(String.class);
Mockito.verify(runner, Mockito.times(2)).createCommand(isNull(), matlabCommand.capture());

assertEquals("buildtool mex test", matlabCommand.getValue());
assertEquals("buildtool mex test -continueOnFailure -skip test", matlabCommand.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface MatlabConstants {
String BUILD_RUNNER_TYPE = "matlabBuildRunner";
String MATLAB_PATH = "MatlabPathKey"; // What's the difference between this and root?
String STARTUP_OPTIONS = "StartupOptions";
String BUILD_OPTIONS = "BuildOptions";
String COMMAND_RUNNER_TYPE = "matlabCommandRunner";
String COMMAND_RUNNER_NAME = "Run MATLAB Command";
String BUILD_RUNNER_NAME = "Run MATLAB Build";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<c:set var="matlabTasks" value="<%=MatlabConstants.MATLAB_TASKS%>"/>
<c:set var="matlabRoot" value="<%=MatlabConstants.MATLAB_PATH%>"/>
<c:set var="startupOptions" value="<%=MatlabConstants.STARTUP_OPTIONS%>"/>
<c:set var="buildOptions" value="<%=MatlabConstants.BUILD_OPTIONS%>"/>

<l:settingsGroup title="Specify MATLAB Executable">
<tr>
Expand Down Expand Up @@ -53,4 +54,19 @@
</div>
</td>
</tr>

<tr>
<th >
<label for="${buildOptions}">Build Options: </label>
<a id="" class="helpIcon actionIconWrapper" onclick="BS.Util.showHelp(event, 'https://github.com/mathworks/matlab-teamcity-plugin/blob/main/CONFIGDOC.md#run-matlab-build', {width: 0, height: 0}); return false" style="" href="https://github.com/mathworks/matlab-teamcity-plugin/blob/main/CONFIGDOC.md#run-matlab-build" title="View help" showdiscardchangesmessage="false"><span class="actionIconWrapper"><span class="svg-icon actionIcon actionIconHelp"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M7.27 12h1.51v-1.45H7.27zm2.65-7.42A3.36 3.36 0 0 0 7.9 4a2.82 2.82 0 0 0-1.55.41 2.49 2.49 0 0 0-1.07 2.17h1.55a1.55 1.55 0 0 1 .26-.86.93.93 0 0 1 .91-.41 1 1 0 0 1 .87.33 1.26 1.26 0 0 1 .24.75 1.17 1.17 0 0 1-.24.61 1.34 1.34 0 0 1-.32.31l-.39.31a2.19 2.19 0 0 0-.71.8 4.39 4.39 0 0 0-.18 1.25h1.46a2.22 2.22 0 0 1 .07-.63 1.18 1.18 0 0 1 .41-.57l.38-.29a3.66 3.66 0 0 0 .78-.74 1.93 1.93 0 0 0 .35-1.18 2 2 0 0 0-.8-1.68zm3-1.53A7 7 0 1 0 13 13a7 7 0 0 0 0-9.95zM12 12a5.6 5.6 0 0 1-8 0 5.61 5.61 0 0 1 0-8 5.6 5.6 0 0 1 8 0 5.61 5.61 0 0 1 0 8z"></path></svg></span></span></a>
</th>
<td>
<div class="posRel">
<props:textProperty name="${buildOptions}" size="56" />
<span class="error" id="error_${buildOptions}"></span>
<span class="smallNote">Specify MATLAB build options.</span>
</div>
</td>
</tr>

</l:settingsGroup>

0 comments on commit 1191cd9

Please sign in to comment.