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

Commit d166cd8

Browse files
committed
Rearrange pipeline step parameter creation order to avoid serialization issues
1 parent cda9e05 commit d166cd8

14 files changed

+161
-261
lines changed

src/main/java/com/mathworks/ci/parameters/MatlabActionParameters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*
1515
*/
1616

17-
public class MatlabActionParameters implements Serializable {
18-
private transient Run build;
17+
public class MatlabActionParameters {
18+
private Run build;
1919
private FilePath workspace;
2020
private EnvVars env;
21-
private transient Launcher launcher;
22-
private transient TaskListener listener;
21+
private Launcher launcher;
22+
private TaskListener listener;
2323

2424
private String startupOptions;
2525

src/main/java/com/mathworks/ci/pipeline/MatlabBuildStepExecution.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ public class MatlabBuildStepExecution extends SynchronousNonBlockingStepExecutio
1919

2020
private static final long serialVersionUID = 4771831219402275744L;
2121

22-
private BuildActionParameters params;
2322
private MatlabActionFactory factory;
24-
public MatlabBuildStepExecution(MatlabActionFactory factory, StepContext context, String tasks, String startupOptions, String buildOptions) throws IOException, InterruptedException {
25-
super(context);
23+
private RunMatlabBuildStep step;
24+
25+
public MatlabBuildStepExecution(MatlabActionFactory factory, StepContext ctx, RunMatlabBuildStep step) throws IOException, InterruptedException {
26+
super(ctx);
2627

27-
this.params = new BuildActionParameters(context, startupOptions, tasks, buildOptions);
2828
this.factory = factory;
29+
this.step = step;
2930
}
3031

31-
public MatlabBuildStepExecution(StepContext context, String tasks, String startupOptions, String buildOptions) throws IOException, InterruptedException {
32-
this(new MatlabActionFactory(), context, tasks, startupOptions, buildOptions);
33-
}
34-
35-
public BuildActionParameters getParameters() {
36-
return this.params;
32+
public MatlabBuildStepExecution(StepContext ctx, RunMatlabBuildStep step) throws IOException, InterruptedException {
33+
this(new MatlabActionFactory(), ctx, step);
3734
}
3835

3936
@Override
4037
public Void run() throws Exception {
38+
BuildActionParameters params = new BuildActionParameters(
39+
getContext(),
40+
step.getStartupOptions(),
41+
step.getTasks(),
42+
step.getBuildOptions());
43+
4144
RunMatlabBuildAction action = factory.createAction(params);
4245
try {
4346
action.run();

src/main/java/com/mathworks/ci/pipeline/MatlabCommandStepExecution.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,26 @@ public class MatlabCommandStepExecution extends SynchronousNonBlockingStepExecut
1818

1919
private static final long serialVersionUID = 1957239693658914450L;
2020

21-
private String command;
22-
private String startupOptions;
23-
24-
private RunActionParameters params;
25-
2621
private MatlabActionFactory factory;
22+
private RunMatlabCommandStep step;
2723

28-
public MatlabCommandStepExecution(MatlabActionFactory factory, StepContext context, String command, String startupOptions) throws IOException, InterruptedException {
24+
public MatlabCommandStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabCommandStep step) throws IOException, InterruptedException {
2925
super(context);
3026

31-
this.params = new RunActionParameters(context, startupOptions, command);
3227
this.factory = factory;
28+
this.step = step;
3329
}
3430

35-
public MatlabCommandStepExecution(StepContext context, String command, String startupOptions) throws IOException, InterruptedException {
36-
this(new MatlabActionFactory(), context, command, startupOptions);
37-
}
38-
39-
public RunActionParameters getParameters() {
40-
return this.params;
31+
public MatlabCommandStepExecution(StepContext context, RunMatlabCommandStep step) throws IOException, InterruptedException {
32+
this(new MatlabActionFactory(), context, step);
4133
}
4234

4335
@Override
4436
public Void run() throws Exception {
37+
RunActionParameters params = new RunActionParameters(
38+
getContext(),
39+
step.getStartupOptions(),
40+
step.getCommand());
4541
RunMatlabCommandAction action = factory.createAction(params);
4642

4743
try {

src/main/java/com/mathworks/ci/pipeline/MatlabRunTestsStepExecution.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,39 @@ public class MatlabRunTestsStepExecution extends SynchronousNonBlockingStepExecu
2020

2121
private static final long serialVersionUID = 6704588180717665100L;
2222

23-
private TestActionParameters params;
2423
private MatlabActionFactory factory;
24+
private RunMatlabTestsStep step;
2525

26-
public MatlabRunTestsStepExecution(MatlabActionFactory factory, StepContext context, TestActionParameters params) throws IOException, InterruptedException {
26+
public MatlabRunTestsStepExecution(MatlabActionFactory factory, StepContext context, RunMatlabTestsStep step) throws IOException, InterruptedException {
2727
super(context);
2828

29-
this.params = params;
3029
this.factory = factory;
30+
this.step = step;
3131
}
3232

33-
public MatlabRunTestsStepExecution(StepContext context, TestActionParameters params) throws IOException, InterruptedException {
34-
this(new MatlabActionFactory(), context, params);
33+
public MatlabRunTestsStepExecution(StepContext context, RunMatlabTestsStep step) throws IOException, InterruptedException {
34+
this(new MatlabActionFactory(), context, step);
3535
}
3636

37-
public TestActionParameters getParameters() {
38-
return this.params;
39-
}
4037

4138
@Override
4239
public Void run() throws Exception {
40+
TestActionParameters params = new TestActionParameters(
41+
getContext(),
42+
step.getStartupOptions(),
43+
step.getTestResultsPDF(),
44+
step.getTestResultsTAP(),
45+
step.getTestResultsJUnit(),
46+
step.getCodeCoverageCobertura(),
47+
step.getTestResultsSimulinkTest(),
48+
step.getModelCoverageCobertura(),
49+
step.getSelectByTag(),
50+
step.getLoggingLevel(),
51+
step.getOutputDetail(),
52+
step.getUseParallel(),
53+
step.getStrict(),
54+
step.getSourceFolder(),
55+
step.getSelectByFolder());
4356
RunMatlabTestsAction action = factory.createAction(params);
4457
try {
4558
action.run();

src/main/java/com/mathworks/ci/pipeline/RunMatlabBuildStep.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
import java.io.Serializable;
89
import java.util.Set;
910
import org.jenkinsci.plugins.workflow.steps.Step;
1011
import org.jenkinsci.plugins.workflow.steps.StepContext;
@@ -23,7 +24,9 @@
2324

2425
import com.mathworks.ci.Message;
2526

26-
public class RunMatlabBuildStep extends Step {
27+
public class RunMatlabBuildStep extends Step implements Serializable {
28+
29+
private static final long serialVersionUID = 1L;
2730

2831
private String tasks;
2932
private String startupOptions;
@@ -63,7 +66,7 @@ public void setBuildOptions (String buildOptions) {
6366

6467
@Override
6568
public StepExecution start(StepContext context) throws Exception {
66-
return new MatlabBuildStepExecution(context, getTasks(), getStartupOptions(), getBuildOptions());
69+
return new MatlabBuildStepExecution(context, this);
6770
}
6871

6972
@Extension

src/main/java/com/mathworks/ci/pipeline/RunMatlabCommandStep.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.mathworks.ci.pipeline;
22

33
/**
4-
* Copyright 2020-2023 The MathWorks, Inc.
4+
* Copyright 2020-2024 The MathWorks, Inc.
55
*
66
*/
77

8+
import java.io.Serializable;
89
import java.util.Set;
910
import org.jenkinsci.plugins.workflow.steps.Step;
1011
import org.jenkinsci.plugins.workflow.steps.StepContext;
@@ -23,8 +24,10 @@
2324

2425
import com.mathworks.ci.Message;
2526

26-
public class RunMatlabCommandStep extends Step {
27+
public class RunMatlabCommandStep extends Step implements Serializable {
2728

29+
private static final long serialVersionUID = 1L;
30+
2831
private String command;
2932
private String startupOptions = "";
3033

@@ -33,7 +36,6 @@ public RunMatlabCommandStep(String command) {
3336
this.command = command;
3437
}
3538

36-
3739
public String getCommand() {
3840
return this.command;
3941
}
@@ -49,7 +51,7 @@ public String getStartupOptions() {
4951

5052
@Override
5153
public StepExecution start(StepContext context) throws Exception {
52-
return new MatlabCommandStepExecution(context, getCommand(), getStartupOptions());
54+
return new MatlabCommandStepExecution(context, this);
5355
}
5456

5557
@Extension

src/main/java/com/mathworks/ci/pipeline/RunMatlabTestsStep.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
import java.io.Serializable;
78
import java.util.ArrayList;
89
import java.util.HashMap;
910
import java.util.List;
@@ -27,7 +28,9 @@
2728
import com.mathworks.ci.Message;
2829
import com.mathworks.ci.parameters.TestActionParameters;
2930

30-
public class RunMatlabTestsStep extends Step {
31+
public class RunMatlabTestsStep extends Step implements Serializable {
32+
33+
private static final long serialVersionUID = 1L;
3134

3235
private String testResultsPDF;
3336
private String testResultsTAP;
@@ -179,23 +182,7 @@ public void setStartupOptions(String startupOptions) {
179182

180183
@Override
181184
public StepExecution start(StepContext context) throws Exception {
182-
TestActionParameters params = new TestActionParameters(
183-
context,
184-
this.getStartupOptions(),
185-
this.getTestResultsPDF(),
186-
this.getTestResultsTAP(),
187-
this.getTestResultsJUnit(),
188-
this.getCodeCoverageCobertura(),
189-
this.getTestResultsSimulinkTest(),
190-
this.getModelCoverageCobertura(),
191-
this.getSelectByTag(),
192-
this.getLoggingLevel(),
193-
this.getOutputDetail(),
194-
this.getUseParallel(),
195-
this.getStrict(),
196-
this.getSourceFolder(),
197-
this.getSelectByFolder());
198-
return new MatlabRunTestsStepExecution(context, params);
185+
return new MatlabRunTestsStepExecution(context, this);
199186
}
200187

201188
@Extension

src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In
4848
new Thread(() -> {
4949
try {
5050
tempFolder.deleteRecursive();
51-
} catch(Exception e) {}
51+
} catch(Exception e) {
52+
System.err.println(e.toString());
53+
}
5254
}));
5355
}
5456

src/test/java/unit/com/mathworks/ci/pipeline/MatlabBuildStepExecutionUnitTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void setup() throws IOException, InterruptedException {
3737

3838
@Test
3939
public void shouldHandleNullCases() throws Exception, IOException, InterruptedException, MatlabExecutionException {
40-
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, null, null, null);
40+
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, new RunMatlabBuildStep());
4141

4242
ArgumentCaptor<BuildActionParameters> captor = ArgumentCaptor.forClass(BuildActionParameters.class);
4343

@@ -46,16 +46,21 @@ public void shouldHandleNullCases() throws Exception, IOException, InterruptedEx
4646
verify(factory).createAction(captor.capture());
4747

4848
BuildActionParameters params = captor.getValue();
49-
assertEquals(null, params.getStartupOptions());
50-
assertEquals(null, params.getTasks());
51-
assertEquals(null, params.getBuildOptions());
49+
assertEquals("", params.getStartupOptions());
50+
assertEquals("", params.getTasks());
51+
assertEquals("", params.getBuildOptions());
5252

5353
verify(action).run();
5454
}
5555

5656
@Test
5757
public void shouldHandleMaximalCases() throws Exception, IOException, InterruptedException, MatlabExecutionException {
58-
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, "mytask", "-nojvm -nodisplay", "-continueOnFailure");
58+
RunMatlabBuildStep step = new RunMatlabBuildStep();
59+
step.setStartupOptions("-nojvm -logfile file");
60+
step.setTasks("vacuum bills");
61+
step.setBuildOptions("-continueOnFailure");
62+
63+
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, step);
5964

6065
ex.run();
6166

@@ -64,16 +69,16 @@ public void shouldHandleMaximalCases() throws Exception, IOException, Interrupte
6469
verify(factory).createAction(captor.capture());
6570

6671
BuildActionParameters params = captor.getValue();
67-
assertEquals("-nojvm -nodisplay", params.getStartupOptions());
68-
assertEquals("mytask", params.getTasks());
72+
assertEquals("-nojvm -logfile file", params.getStartupOptions());
73+
assertEquals("vacuum bills", params.getTasks());
6974
assertEquals("-continueOnFailure", params.getBuildOptions());
7075

7176
verify(action).run();
7277
}
7378

7479
@Test
7580
public void shouldHandleActionThrowing() throws Exception, IOException, InterruptedException, MatlabExecutionException {
76-
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, null, null, null);
81+
MatlabBuildStepExecution ex = new MatlabBuildStepExecution(factory, context, new RunMatlabBuildStep());
7782

7883
doThrow(new MatlabExecutionException(12)).when(action).run();
7984

src/test/java/unit/com/mathworks/ci/pipeline/MatlabCommandStepExecutionUnitTest.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,48 @@ public void setup() throws IOException, InterruptedException {
3737

3838
@Test
3939
public void shouldHandleNullCases() throws Exception, IOException, InterruptedException, MatlabExecutionException {
40-
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(factory, context, null, null);
41-
42-
ArgumentCaptor<RunActionParameters> captor = ArgumentCaptor.forClass(RunActionParameters.class);
40+
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(
41+
factory,
42+
context,
43+
new RunMatlabCommandStep(null));
4344

4445
ex.run();
4546

47+
ArgumentCaptor<RunActionParameters> captor = ArgumentCaptor.forClass(RunActionParameters.class);
4648
verify(factory).createAction(captor.capture());
4749

4850
RunActionParameters params = captor.getValue();
49-
assertEquals(null, params.getStartupOptions());
51+
assertEquals("", params.getStartupOptions());
5052
assertEquals(null, params.getCommand());
5153

5254
verify(action).run();
5355
}
5456

5557
@Test
5658
public void shouldHandleMaximalCases() throws Exception, IOException, InterruptedException, MatlabExecutionException {
57-
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(factory, context, "mycommand", "-nojvm -nodisplay");
59+
RunMatlabCommandStep step = new RunMatlabCommandStep("mycommand");
60+
step.setStartupOptions("-nojvm -logfile file");
61+
62+
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(factory, context, step);
5863

5964
ex.run();
6065

6166
ArgumentCaptor<RunActionParameters> captor = ArgumentCaptor.forClass(RunActionParameters.class);
62-
6367
verify(factory).createAction(captor.capture());
6468

6569
RunActionParameters params = captor.getValue();
66-
assertEquals("-nojvm -nodisplay", params.getStartupOptions());
70+
assertEquals("-nojvm -logfile file", params.getStartupOptions());
6771
assertEquals("mycommand", params.getCommand());
6872

6973
verify(action).run();
7074
}
7175

7276
@Test
7377
public void shouldHandleActionThrowing() throws Exception, IOException, InterruptedException, MatlabExecutionException {
74-
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(factory, context, null, null);
78+
MatlabCommandStepExecution ex = new MatlabCommandStepExecution(
79+
factory,
80+
context,
81+
new RunMatlabCommandStep(null));
7582

7683
doThrow(new MatlabExecutionException(12)).when(action).run();
7784

0 commit comments

Comments
 (0)