|
24 | 24 |
|
25 | 25 | package org.jenkinsci.plugins.workflow.libs;
|
26 | 26 |
|
| 27 | +import edu.umd.cs.findbugs.annotations.NonNull; |
27 | 28 | import hudson.AbortException;
|
| 29 | +import hudson.ExtensionList; |
28 | 30 | import hudson.FilePath;
|
29 | 31 | import hudson.model.Item;
|
30 | 32 | import hudson.model.Result;
|
|
48 | 50 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
|
49 | 51 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
50 | 52 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
| 53 | + |
| 54 | +import static hudson.ExtensionList.lookupSingleton; |
| 55 | +import static org.hamcrest.Matchers.contains; |
| 56 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 57 | +import static org.hamcrest.Matchers.instanceOf; |
| 58 | +import static org.hamcrest.Matchers.not; |
51 | 59 | import static org.junit.Assert.*;
|
52 | 60 | import org.junit.ClassRule;
|
53 | 61 | import org.junit.Rule;
|
@@ -211,6 +219,42 @@ private WorkflowRun prepareRetryTests(SCMSource scmSource) throws Exception{
|
211 | 219 | r.jenkins.setScmCheckoutRetryCount(1);
|
212 | 220 |
|
213 | 221 | return r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
|
| 222 | + } |
| 223 | + |
| 224 | + @Test |
| 225 | + public void modernAndLegacyImpls() { |
| 226 | + SCMSourceRetriever.DescriptorImpl modern = lookupSingleton(SCMSourceRetriever.DescriptorImpl.class); |
| 227 | + |
| 228 | + containsInAnyOrder(modern.getSCMDescriptors(), contains(instanceOf(FakeModernSCM.DescriptorImpl.class))); |
| 229 | + containsInAnyOrder(modern.getSCMDescriptors(), contains(instanceOf(FakeAlsoModernSCM.DescriptorImpl.class))); |
| 230 | + containsInAnyOrder(modern.getSCMDescriptors(), not(contains(instanceOf(BasicSCMSource.DescriptorImpl.class)))); |
| 231 | + } |
| 232 | + // Implementation of latest and greatest API |
| 233 | + public static final class FakeModernSCM extends SCMSource { |
| 234 | + @Override protected void retrieve(SCMSourceCriteria c, @NonNull SCMHeadObserver o, SCMHeadEvent<?> e, @NonNull TaskListener l) {} |
| 235 | + @Override public @NonNull SCM build(@NonNull SCMHead head, SCMRevision revision) { return null; } |
| 236 | + @TestExtension("modernAndLegacyImpls") public static final class DescriptorImpl extends SCMSourceDescriptor {} |
214 | 237 |
|
| 238 | + @Override |
| 239 | + protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener listener, Item context) throws IOException, InterruptedException { |
| 240 | + return super.retrieve(thingName, listener, context); |
| 241 | + } |
| 242 | + } |
| 243 | + // Implementation of second latest and second greatest API |
| 244 | + public static final class FakeAlsoModernSCM extends SCMSource { |
| 245 | + @Override protected void retrieve(SCMSourceCriteria c, @NonNull SCMHeadObserver o, SCMHeadEvent<?> e, @NonNull TaskListener l) {} |
| 246 | + @Override public @NonNull SCM build(@NonNull SCMHead head, SCMRevision revision) { return null; } |
| 247 | + @TestExtension("modernAndLegacyImpls") public static final class DescriptorImpl extends SCMSourceDescriptor {} |
| 248 | + |
| 249 | + @Override |
| 250 | + protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener listener) throws IOException, InterruptedException { |
| 251 | + return super.retrieve(thingName, listener); |
| 252 | + } |
| 253 | + } |
| 254 | + // No modern stuff |
| 255 | + public static class BasicSCMSource extends SCMSource { |
| 256 | + @Override protected void retrieve(SCMSourceCriteria c, @NonNull SCMHeadObserver o, SCMHeadEvent<?> e, @NonNull TaskListener l) {} |
| 257 | + @Override public @NonNull SCM build(@NonNull SCMHead head, SCMRevision revision) { return null; } |
| 258 | + @TestExtension("modernAndLegacyImpls") public static final class DescriptorImpl extends SCMSourceDescriptor {} |
215 | 259 | }
|
216 | 260 | }
|
0 commit comments