forked from mathworks/jenkins-matlab-plugin
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathRunMatlabBuildBuilder.java
More file actions
175 lines (145 loc) · 5.17 KB
/
Copy pathRunMatlabBuildBuilder.java
File metadata and controls
175 lines (145 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.mathworks.ci.freestyle;
/**
* Copyright 2022-26 The MathWorks, Inc.
*/
import java.io.IOException;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.init.Initializer;
import hudson.init.InitMilestone;
import hudson.model.Items;
import hudson.model.AbstractProject;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import com.mathworks.ci.Message;
import com.mathworks.ci.actions.MatlabActionFactory;
import com.mathworks.ci.actions.RunMatlabBuildAction;
import com.mathworks.ci.parameters.BuildActionParameters;
import com.mathworks.ci.freestyle.options.*;
public class RunMatlabBuildBuilder extends Builder implements SimpleBuildStep {
// Deprecated
private transient int buildResult;
// In use
private String tasks;
private StartupOptions startupOptions;
private BuildOptions buildOptions;
private Boolean generateSummary;
private MatlabActionFactory factory;
public RunMatlabBuildBuilder(MatlabActionFactory factory) {
this.factory = factory;
}
@DataBoundConstructor
public RunMatlabBuildBuilder() {
this(new MatlabActionFactory());
}
// Getter and Setters to access local members
@DataBoundSetter
public void setTasks(String tasks) {
this.tasks = tasks;
}
@DataBoundSetter
public void setStartupOptions(StartupOptions startupOptions) {
this.startupOptions = startupOptions;
}
@DataBoundSetter
public void setBuildOptions(BuildOptions buildOptions) {
this.buildOptions = buildOptions;
}
@DataBoundSetter
public void setGenerateSummary(Boolean generateSummary) {
this.generateSummary = generateSummary;
}
public String getTasks() {
return this.tasks;
}
public StartupOptions getStartupOptions() {
return this.startupOptions;
}
public String getStartupOptionsAsString() {
return this.startupOptions == null
? ""
: this.startupOptions.getOptions();
}
public BuildOptions getBuildOptions() {
return this.buildOptions;
}
public String getBuildOptionsAsString() {
return this.buildOptions == null
? null
: this.buildOptions.getOptions();
}
public boolean getGenerateSummary() {
return this.generateSummary == null || this.generateSummary;
}
@Extension
public static class RunMatlabBuildDescriptor extends BuildStepDescriptor<Builder> {
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void addAliases() {
Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.RunMatlabBuildBuilder", RunMatlabBuildBuilder.class);
}
// Overridden Method used to show the text under build dropdown
@Override
public String getDisplayName() {
return Message.getValue("Builder.build.builder.display.name");
}
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
save();
return super.configure(req, formData);
}
/*
* 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.
*/
@Override
public boolean isApplicable(
@SuppressWarnings("rawtypes") Class<? extends AbstractProject> jobtype) {
return true;
}
}
@Override
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
@Nonnull Launcher launcher, @Nonnull TaskListener listener)
throws InterruptedException, IOException {
// Get the environment variable specific to the this build
final EnvVars env = build.getEnvironment(listener);
BuildActionParameters params = new BuildActionParameters(
build, workspace, env, launcher, listener,
this.getStartupOptionsAsString(),
this.getTasks(),
this.getBuildOptionsAsString(),
this.getGenerateSummary());
RunMatlabBuildAction action = factory.createAction(params);
try {
action.run();
} catch (Exception e) {
build.setResult(Result.FAILURE);
}
}
// Added for backwards compatibility:
// Called when object is loaded from persistent data.
protected Object readResolve() {
this.generateSummary = Optional.ofNullable(this.generateSummary).orElse(true);
if (factory == null) {
factory = new MatlabActionFactory();
}
return this;
}
}