Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
779 additions
and 47 deletions.
- +45 −1 src/main/java/jenkins/scm/api/SCMHeadObserver.java
- +53 −0 src/main/java/jenkins/scm/api/trait/SCMHeadAuthority.java
- +87 −0 src/main/java/jenkins/scm/api/trait/SCMHeadAuthorityDescriptor.java
- +23 −0 src/main/java/jenkins/scm/api/trait/SCMHeadFilter.java
- +34 −0 src/main/java/jenkins/scm/api/trait/SCMHeadPrefilter.java
- +70 −13 src/main/java/jenkins/scm/api/trait/SCMSourceRequest.java
- +51 −14 src/main/java/jenkins/scm/api/trait/SCMSourceRequestBuilder.java
- +2 −2 src/main/java/jenkins/scm/api/trait/SCMSourceTrait.java
- +2 −2 src/main/java/jenkins/scm/api/trait/SCMSourceTraitDescriptor.java
- +103 −0 src/main/java/jenkins/scm/impl/trait/WildcardNameFilterTrait.java
- +24 −0 src/main/resources/jenkins/scm/impl/trait/Messages.properties
- +32 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/config.jelly
- +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/help-excludes.html
- +4 −0 src/main/resources/jenkins/scm/impl/trait/WIldcardNameFilterTrait/help-includes.html
- +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverBranches.java
- +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverChangeRequests.java
- +26 −2 src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverTags.java
- +3 −3 src/test/java/jenkins/scm/impl/mock/MockSCMSource.java
- +27 −2 src/test/java/jenkins/scm/impl/mock/MockSCMSourceRequest.java
- +34 −4 src/test/java/jenkins/scm/impl/mock/MockSCMSourceRequestBuilder.java
- +103 −0 src/test/java/jenkins/scm/impl/trait/WildcardNameFilterTraitTest.java
@@ -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); | ||
} | ||
} |
@@ -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.