Skip to content
Permalink
Browse files

[JENKINS-43507] This stuff is seeming reasonably solid

  • Loading branch information...
stephenc committed Apr 25, 2017
1 parent fd479ad commit a1fa90b418fe71ed57fed32cb814b809d5541d89
Showing with 779 additions and 47 deletions.
  1. +45 −1 src/main/java/jenkins/scm/api/SCMHeadObserver.java
  2. +53 −0 src/main/java/jenkins/scm/api/trait/SCMHeadAuthority.java
  3. +87 −0 src/main/java/jenkins/scm/api/trait/SCMHeadAuthorityDescriptor.java
  4. +23 −0 src/main/java/jenkins/scm/api/trait/SCMHeadFilter.java
  5. +34 −0 src/main/java/jenkins/scm/api/trait/SCMHeadPrefilter.java
  6. +70 −13 src/main/java/jenkins/scm/api/trait/SCMSourceRequest.java
  7. +51 −14 src/main/java/jenkins/scm/api/trait/SCMSourceRequestBuilder.java
  8. +2 −2 src/main/java/jenkins/scm/api/trait/SCMSourceTrait.java
  9. +2 −2 src/main/java/jenkins/scm/api/trait/SCMSourceTraitDescriptor.java
  10. +103 −0 src/main/java/jenkins/scm/impl/trait/WildcardNameFilterTrait.java
  11. +24 −0 src/main/resources/jenkins/scm/impl/trait/Messages.properties
  12. +32 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/config.jelly
  13. +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/help-excludes.html
  14. +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/help-includes.html
  15. +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverBranches.java
  16. +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverChangeRequests.java
  17. +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverTags.java
  18. +3 −3 src/test/java/jenkins/scm/impl/mock/MockSCMSource.java
  19. +27 −2 src/test/java/jenkins/scm/impl/mock/MockSCMSourceRequest.java
  20. +34 −4 src/test/java/jenkins/scm/impl/mock/MockSCMSourceRequestBuilder.java
  21. +103 −0 src/test/java/jenkins/scm/impl/trait/WildcardNameFilterTraitTest.java
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2011-2013, CloudBees, Inc., Stephen Connolly.
* Copyright (c) 2011-2017, CloudBees, Inc., Stephen Connolly.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -158,6 +158,17 @@ public static Any any() {
return new Any();
}

/**
* Creates an observer that selects the first revision it finds. Also useful for quick checks of non-empty.
*
* @return an observer that selects the first revision of a any head.
* @since 2.2.0
*/
@NonNull
public static None none() {
return None.INSTANCE;
}

/**
* An observer that wraps multiple observers and keeps observing as long as one of the wrapped observers wants to.
*/
@@ -545,6 +556,39 @@ public boolean isObserving() {

}

/**
* An observer that is already finished.
*
* @since 2.2.0
*/
public static final class None extends SCMHeadObserver {
/**
* Singleton.
*/
public static final None INSTANCE = new None();

/**
* Constructor.
*/
private None() {
}

/**
* {@inheritDoc}
*/
@Override
public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
}

/**
* {@inheritDoc}
*/
@Override
public boolean isObserving() {
return false;
}
}

/**
* Base class for an {@link SCMHeadObserver} that wraps another {@link SCMHeadObserver} while allowing access to the
* original observer via {@link #unwrap()}.
@@ -0,0 +1,53 @@
/*
* 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.NonNull;
import hudson.model.AbstractDescribableImpl;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.mixin.SCMHeadMixin;

public abstract class SCMHeadAuthority<S extends SCMSourceRequest, H extends SCMHeadMixin>
extends AbstractDescribableImpl<SCMHeadAuthority<?, ?>> {

public final boolean isApplicableTo(@NonNull SCMHead head) {
return getDescriptor().isApplicableToHead(head);
}

public final boolean isApplicableTo(@NonNull SCMSourceRequest request) {
return getDescriptor().isApplicableToRequest(request);
}

@SuppressWarnings("unchecked")
public final boolean isTrusted(@NonNull SCMSourceRequest request, @NonNull SCMHead head) {
return isApplicableTo(request) && isApplicableTo(head) && checkTrusted((S) request, (H) head);
}

protected abstract boolean checkTrusted(@NonNull S request, @NonNull H head);

@Override
public SCMHeadAuthorityDescriptor getDescriptor() {
return (SCMHeadAuthorityDescriptor) super.getDescriptor();
}
}
@@ -0,0 +1,87 @@
/*
* 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 hudson.model.Descriptor;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.mixin.SCMHeadMixin;
import org.jvnet.tiger_types.Types;

public abstract class SCMHeadAuthorityDescriptor extends Descriptor<SCMHeadAuthority<?, ?>> {

private final Class<? extends SCMSourceRequest> requestClass;
private final Class<? extends SCMHeadMixin> headClass;

protected SCMHeadAuthorityDescriptor(Class<? extends SCMHeadAuthority<?, ?>> clazz,
Class<? extends SCMSourceRequest> requestClass,
Class<? extends SCMHeadMixin> headClass) {
super(clazz);
this.requestClass = requestClass;
this.headClass = headClass;
}

protected SCMHeadAuthorityDescriptor() {
Type bt = Types.getBaseClass(clazz, SCMHeadAuthority.class);
if (bt instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) bt;
// 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)) {
throw new AssertionError(
"Failed to correctly detect SCMSourceRequest specialization. Use the constructor that takes "
+ "the "
+ "Class objects explicitly");
}
if (!SCMHeadMixin.class.isAssignableFrom(headClass)) {
throw new AssertionError(
"Failed to correctly detect SCMHead specialization. Use the constructor that takes the Class "
+ "objects explicitly");
}
} else {
throw new AssertionError(
"Failed to correctly detect specialization. Use the constructor that takes the Class objects "
+ "explicitly");
}
}

public boolean isApplicableToHead(SCMHead head) {
return isApplicableToHead(head.getClass());
}

public boolean isApplicableToHead(Class<? extends SCMHead> headClass) {
return this.headClass.isAssignableFrom(headClass);
}

public boolean isApplicableToRequest(SCMSourceRequest request) {
return requestClass.isInstance(request);
}

public boolean isApplicableToRequest(Class<? extends SCMSourceRequest> requestClass) {
return this.requestClass.isAssignableFrom(requestClass);
}
}
@@ -1,3 +1,26 @@
/*
* 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.NonNull;
@@ -0,0 +1,34 @@
/*
* 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.NonNull;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;

public abstract class SCMHeadPrefilter {

public abstract boolean isExcluded(@NonNull SCMSource source, @NonNull SCMHead head);

}
Oops, something went wrong.

0 comments on commit a1fa90b

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