Skip to content
Permalink
Browse files

[JENKINS-43507] Check-pointing work in progress

  • Loading branch information...
stephenc committed Apr 28, 2017
1 parent af5b256 commit 93b3c886740dc66a5627c56300bae69684f4b7ae
Showing with 1,889 additions and 123 deletions.
  1. +8 −3 src/main/java/jenkins/scm/api/SCMSourceObserver.java
  2. +22 −13 src/main/java/jenkins/scm/api/{ → trait}/SCMBuilder.java
  3. +1 −1 src/main/java/jenkins/scm/api/trait/SCMHeadAuthorityDescriptor.java
  4. +154 −0 src/main/java/jenkins/scm/api/trait/SCMNavigatorContext.java
  5. +280 −0 src/main/java/jenkins/scm/api/trait/SCMNavigatorRequest.java
  6. +176 −0 src/main/java/jenkins/scm/api/trait/SCMNavigatorTrait.java
  7. +110 −0 src/main/java/jenkins/scm/api/trait/SCMNavigatorTraitDescriptor.java
  8. +76 −0 src/main/java/jenkins/scm/api/trait/SCMSourceBuilder.java
  9. +57 −0 src/main/java/jenkins/scm/api/trait/SCMSourceDecorator.java
  10. +36 −0 src/main/java/jenkins/scm/api/trait/SCMSourceFilter.java
  11. +35 −0 src/main/java/jenkins/scm/api/trait/SCMSourcePrefilter.java
  12. +46 −9 src/main/java/jenkins/scm/api/trait/SCMSourceTrait.java
  13. +47 −7 src/main/java/jenkins/scm/api/trait/SCMSourceTraitDescriptor.java
  14. +20 −0 src/main/java/jenkins/scm/api/trait/SCMTrait.java
  15. +70 −0 src/main/java/jenkins/scm/api/trait/SCMTraitDescriptor.java
  16. +94 −0 src/main/java/jenkins/scm/impl/trait/RegexSCMSourceFilterTrait.java
  17. +3 −3 ...main/java/jenkins/scm/impl/trait/{WildcardNameFilterTrait.java → WildcardSCMHeadFilterTrait.java}
  18. +110 −0 src/main/java/jenkins/scm/impl/trait/WildcardSCMSourceFilterTrait.java
  19. +3 −1 src/main/resources/jenkins/scm/impl/trait/Messages.properties
  20. +29 −0 src/main/resources/jenkins/scm/impl/trait/RegexSCMSourceFilterTrait/config.jelly
  21. 0 ...pl/trait/{WIldcardNameFilterTrait/help-includes.html → RegexSCMSourceFilterTrait/help-regex.html}
  22. 0 ...ources/jenkins/scm/impl/trait/{WIldcardNameFilterTrait → WIldcardSCMHeadFilterTrait}/config.jelly
  23. 0 .../jenkins/scm/impl/trait/{WIldcardNameFilterTrait → WIldcardSCMHeadFilterTrait}/help-excludes.html
  24. +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardSCMHeadFilterTrait/help-includes.html
  25. +32 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardSCMSourceFilterTrait/config.jelly
  26. +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardSCMSourceFilterTrait/help-excludes.html
  27. +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardSCMSourceFilterTrait/help-includes.html
  28. +28 −3 src/test/java/jenkins/scm/impl/mock/MockSCMBuilder.java
  29. +5 −5 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverBranches.java
  30. +5 −5 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverChangeRequests.java
  31. +5 −5 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverTags.java
  32. +44 −47 src/test/java/jenkins/scm/impl/mock/MockSCMNavigator.java
  33. +37 −0 src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorContext.java
  34. +36 −0 src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorRequest.java
  35. +1 −17 src/test/java/jenkins/scm/impl/mock/MockSCMSource.java
  36. +58 −0 src/test/java/jenkins/scm/impl/mock/MockSCMSourceBuilder.java
  37. +103 −0 src/test/java/jenkins/scm/impl/trait/RegexSCMSourceFilterTraitTest.java
  38. +4 −4 ...a/jenkins/scm/impl/trait/{WildcardNameFilterTraitTest.java → WildcardSCMHeadFilterTraitTest.java}
  39. +142 −0 src/test/java/jenkins/scm/impl/trait/WildcardSCMSourceFilterTraitTest.java
@@ -81,9 +81,12 @@
* {@link Item#getName}
* @return a secondary callback to customize the project, on which you must call {@link ProjectObserver#complete}
* @throws IllegalArgumentException if this {@code projectName} has already been encountered
* @throws IOException if observing this {@code projectName} could not be completed due to an {@link IOException}.
* @throws InterruptedException if observing this {@code projectName} was interrupted.
*/
@NonNull
public abstract ProjectObserver observe(@NonNull String projectName) throws IllegalArgumentException;
public abstract ProjectObserver observe(@NonNull String projectName) throws IllegalArgumentException, IOException,
InterruptedException;

/**
* Adds extra metadata about the overall organization.
@@ -212,7 +215,8 @@ public TaskListener getListener() {
*/
@Override
@NonNull
public ProjectObserver observe(@NonNull String projectName) throws IllegalArgumentException {
public ProjectObserver observe(@NonNull String projectName)
throws IllegalArgumentException, IOException, InterruptedException {
return delegate.observe(projectName);
}

@@ -280,7 +284,8 @@ public Filter(O delegate, String... projectNames) {
*/
@NonNull
@Override
public ProjectObserver observe(@NonNull String projectName) throws IllegalArgumentException {
public ProjectObserver observe(@NonNull String projectName)
throws IllegalArgumentException, IOException, InterruptedException {
if (remaining.remove(projectName)) {
return super.observe(projectName);
} else {
@@ -1,39 +1,52 @@
package jenkins.scm.api;
package jenkins.scm.api.trait;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import java.util.Arrays;
import java.util.Collection;
import jenkins.model.Jenkins;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;

public abstract class SCMBuilder<B extends SCMBuilder<B,S>,S extends SCM> {

private final Class<S> clazz;
private final SCMHead head;
private final SCMRevision revision;
private SCMHead head;
private SCMRevision revision;

public SCMBuilder(Class<S> clazz, @NonNull SCMHead head, @CheckForNull SCMRevision revision) {
this.clazz = clazz;
this.head = head;
this.revision = revision;
}

public SCMHead getHead() {
public Class<S> scmClass() {
return clazz;
}

public SCMHead head() {
return head;
}

public SCMRevision getRevision() {
public B withHead(@NonNull SCMHead head) {
this.head = head;
return (B) this;
}

public SCMRevision revision() {
return revision;
}

public B withRevision(@CheckForNull SCMRevision revision) {
this.revision = revision;
return (B) this;
}

public abstract S build();

@SuppressWarnings("unchecked")
public B withTrait(@NonNull SCMSourceTrait trait) {
trait.applyToBuilder((B)this);
trait.applyToBuilder(this);
return (B) this;
}

@@ -48,8 +61,4 @@ public B withTraits(@NonNull Collection<SCMSourceTrait> traits) {
}
return (B) this;
}

public SCMDescriptor<S> getSCMDescriptor() {
return (SCMDescriptor<S>)Jenkins.getActiveInstance().getDescriptorOrDie(clazz);
}
}
@@ -51,7 +51,7 @@ protected SCMHeadAuthorityDescriptor() {
// this 'headClass' is the closest approximation of T of SCMHeadAuthority<T>.
requestClass = Types.erasure(pt.getActualTypeArguments()[0]);
headClass = Types.erasure(pt.getActualTypeArguments()[1]);
if (!SCMSource.class.isAssignableFrom(requestClass)) {
if (!SCMSourceRequest.class.isAssignableFrom(requestClass)) {
throw new AssertionError(
"Failed to correctly detect SCMSourceRequest specialization. Use the constructor that takes "
+ "the "
@@ -0,0 +1,154 @@
/*
* The MIT License
*
* Copyright (c) 2017 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package jenkins.scm.api.trait;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.SCMSourceEvent;
import jenkins.scm.api.SCMSourceObserver;

/**
* Represents the context within which a {@link SCMNavigator} is processing requests. In general this is used as a
* builder for {@link SCMNavigatorRequest} instances through
* {@link SCMNavigatorContext#newRequest(SCMNavigator, SCMSourceObserver)} but there are some cases (such as
* {@link SCMSourceEvent} processing) where only the context is required and as such this
* type will be instantiated to obtain the context but no {@link SCMNavigatorRequest} will be created.
*
* @param <C> the type of {@link SCMNavigatorContext}
* @param <R> the type of {@link SCMNavigatorRequest} produced by this context.
* @since 2.2.0
*/
public abstract class SCMNavigatorContext<C extends SCMNavigatorContext<C, R>, R extends SCMNavigatorRequest> {
@NonNull
private final List<SCMSourcePrefilter> prefilters = new ArrayList<SCMSourcePrefilter>();
@NonNull
private final List<SCMSourceFilter> filters = new ArrayList<SCMSourceFilter>();
@NonNull
private final List<SCMSourceTrait> traits = new ArrayList<SCMSourceTrait>();
@NonNull
private final List<SCMSourceDecorator<?,?>> decorators = new ArrayList<SCMSourceDecorator<?, ?>>();

public SCMNavigatorContext() { }

@SuppressWarnings("unchecked")
public C withFilter(@CheckForNull SCMSourceFilter filter) {
if (filter != null) {
this.filters.add(filter);
}
return (C) this;
}

@SuppressWarnings("unchecked")
public C withPrefilter(@CheckForNull SCMSourcePrefilter prefilter) {
if (prefilter != null) {
this.prefilters.add(prefilter);
}
return (C) this;
}

@SuppressWarnings("unchecked")
public C withPrefilters(@CheckForNull Collection<SCMSourcePrefilter> prefilters) {
if (prefilters != null) {
this.prefilters.addAll(prefilters);
}
return (C) this;
}

@SuppressWarnings("unchecked")
public C withTrait(@NonNull SCMNavigatorTrait trait) {
trait.applyToContext(this);
return (C) this;
}

@SuppressWarnings("unchecked")
public C withTrait(@NonNull SCMSourceTrait trait) {
traits.add(trait);
return (C) this;
}

public C withTraits(@NonNull SCMTrait<? extends SCMTrait<?>>... traits) {
return withTraits(Arrays.asList(traits));
}

@SuppressWarnings("unchecked")
public C withTraits(@NonNull Collection<? extends SCMTrait<?>> traits) {
for (SCMTrait<?> trait : traits) {
if (trait instanceof SCMNavigatorTrait) {
withTrait((SCMNavigatorTrait) trait);
} else if (trait instanceof SCMSourceTrait) {
withTrait((SCMSourceTrait) trait);
} else {
throw new IllegalArgumentException("Unsupported trait: " + trait.getClass().getName());
}
}
return (C) this;
}

@SuppressWarnings("unchecked")
public C withDecorator(@NonNull SCMSourceDecorator<?,?> decorator) {
decorators.add(decorator);
return (C) this;
}

@SuppressWarnings("unchecked")
public C withDecorators(@NonNull SCMSourceDecorator<?,?>... decorator) {
return withDecorators(Arrays.asList(decorator));
}

@SuppressWarnings("unchecked")
public C withDecorators(@NonNull Collection<? extends SCMSourceDecorator<?,?>> decorators) {
this.decorators.addAll(decorators);
return (C) this;
}

@NonNull
public List<SCMSourceTrait> traits() {
return new ArrayList<SCMSourceTrait>(traits);
}

@NonNull
public List<SCMSourceDecorator<?,?>> decorators() {
return new ArrayList<SCMSourceDecorator<?,?>>(decorators);
}

@NonNull
public List<SCMSourceFilter> filters() {
return Collections.unmodifiableList(filters);
}

@NonNull
public List<SCMSourcePrefilter> prefilters() {
return Collections.unmodifiableList(prefilters);
}

public abstract R newRequest(@NonNull SCMNavigator navigator, @NonNull SCMSourceObserver observer);
}
Oops, something went wrong.

0 comments on commit 93b3c88

Please sign in to comment.
You can’t perform that action at this time.