forked from Praqma/pretested-integration-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractSCMBridge.java
More file actions
237 lines (209 loc) · 8.64 KB
/
AbstractSCMBridge.java
File metadata and controls
237 lines (209 loc) · 8.64 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package org.jenkinsci.plugins.pretestedintegration;
import hudson.DescriptorExtensionList;
import hudson.EnvVars;
import hudson.ExtensionPoint;
import hudson.Launcher;
import hudson.model.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.pretestedintegration.exceptions.*;
/**
* Abstract class representing an SCM bridge.
*/
public abstract class AbstractSCMBridge implements Describable<AbstractSCMBridge>, ExtensionPoint {
/**
* Information about the result of the integration (Unknown, Conflict, Build, Push).
*/
protected abstract String getIntegrationBranch();
/**
* The integration strategy.
* This is the strategy applied to merge pretested commits into the integration integrationBranch.
*/
public final IntegrationStrategy integrationStrategy;
final static String LOG_PREFIX = "[PREINT] ";
/**
* Constructor for the SCM bridge.
*
* @param integrationStrategy The integration strategy to apply when merging commits.
*/
public AbstractSCMBridge(IntegrationStrategy integrationStrategy) {
this.integrationStrategy = integrationStrategy;
}
/**
* Pushes changes to the integration integrationBranch.
*
* @param build The Build
* @param listener The BuildListener
* @throws PushFailedException
*/
public void pushToIntegrationBranch(AbstractBuild<?, ?> build, BuildListener listener) throws PushFailedException {
}
/**
* Deletes the integrated integrationBranch.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @throws BranchDeletionFailedException
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
*/
public void deleteIntegratedBranch(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws BranchDeletionFailedException, NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException {
}
/**
* Make sure the SCM is checked out on the given integrationBranch.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @param branch The integrationBranch to check out
* @throws EstablishingWorkspaceFailedException
*/
public abstract void ensureBranch(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String branch) throws EstablishingWorkspaceFailedException;
/**
* Called after the build has run. If the build was successful, the
* changes should be committed, otherwise the workspace is reset.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @throws IOException A repository could not be reached.
*/
public abstract void handlePostBuild(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException;
/**
* Determines if we should prepare a workspace for integration. If not we
* throw a NothingToDoException
*
* @param build The Build
* @param listener The BuildListener
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
*/
public void isApplicable(AbstractBuild<?, ?> build, BuildListener listener) throws NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException { }
/**
* Integrates the commit into the integration integrationBranch.
* Uses the selected IntegrationStrategy.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @throws NothingToDoException
* @throws IntegrationFailedException
* @throws UnsupportedConfigurationException
*/
protected void mergeChanges(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws NothingToDoException, IntegrationFailedException, UnsupportedConfigurationException, IntegrationAllowedNoCommitException {
integrationStrategy.integrate(build, launcher, listener, this);
}
/**
* Called after the SCM plugin has updated the workspace with remote changes.
* Afterwards, the workspace must be ready to perform builds and tests.
* The integration integrationBranch must be checked out, and the given commit must be merged in.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @throws IntegrationFailedException
* @throws EstablishingWorkspaceFailedException
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
*/
public void prepareWorkspace(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws EstablishingWorkspaceFailedException, NothingToDoException, IntegrationFailedException, UnsupportedConfigurationException, IntegrationAllowedNoCommitException {
mergeChanges(build, launcher, listener);
}
/**
* Updates the description of the Jenkins build.
*
* @param build The Build
* @param launcher The Launcher
* @param listener The BuildListener
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
*/
public void updateBuildDescription(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException {
}
/**
* Updates the description of the Jenkins build.
*
* @param run The Build
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
*/
public void updateBuildDescription(Run<?, ?> run) throws NothingToDoException, UnsupportedConfigurationException, IOException {
}
/**
*
* @param tBranch the branch that triggered this build
* @return a build description
* @throws NothingToDoException
* @throws UnsupportedConfigurationException
* @throws IOException
* @throws InterruptedException
*/
public String createBuildDescription(String tBranch) throws NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException{
return "";
}
/**
* Validates the configuration of the Jenkins Job.
* Throws an exception when the configuration is invalid.
*
* @param project The Project
* @throws UnsupportedConfigurationException
*/
public void validateConfiguration(AbstractProject<?, ?> project) throws UnsupportedConfigurationException {
}
/**
* @return all the SCM Bridge Descriptors
*/
public static DescriptorExtensionList<AbstractSCMBridge, SCMBridgeDescriptor<AbstractSCMBridge>> all() {
return Jenkins.getInstance().<AbstractSCMBridge, SCMBridgeDescriptor<AbstractSCMBridge>>getDescriptorList(AbstractSCMBridge.class);
}
/**
* @return all the Integration Strategy Descriptors
*/
public static List<IntegrationStrategyDescriptor<?>> getBehaviours() {
List<IntegrationStrategyDescriptor<?>> behaviours = new ArrayList<>();
for (IntegrationStrategyDescriptor<?> behaviour : IntegrationStrategy.all()) {
behaviours.add(behaviour);
}
return behaviours;
}
/**
* {@inheritDoc}
*/
@Override
public Descriptor<AbstractSCMBridge> getDescriptor() {
return (SCMBridgeDescriptor<?>) Jenkins.getInstance().getDescriptorOrDie(getClass());
}
/**
* @return all the SCM Bridge Descriptors
*/
public static List<SCMBridgeDescriptor<?>> getDescriptors() {
List<SCMBridgeDescriptor<?>> descriptors = new ArrayList<>();
for (SCMBridgeDescriptor<?> descriptor : all()) {
descriptors.add(descriptor);
}
return descriptors;
}
/**
* @param environment environment
* @return The Integration Branch name as variable expanded if possible - otherwise return integrationBranch
*/
public String getExpandedIntegrationBranch(EnvVars environment) {
return environment.expand(getIntegrationBranch());
}
/**
* @param environment The environment to expand the integrationBranch in
* @return The Integration Branch name, expanded using given EnvVars.
*/
/***
* @return The required result
*/
public Result getRequiredResult() {
return Result.SUCCESS;
}
void setIntegrationFailedStatusUnstable(boolean integrationFailedStatusUnstable) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}