├── .cloudbees.md ├── .jenkins └── artifacts.lst ├── src ├── main │ ├── resources │ │ ├── jenkins │ │ │ └── scm │ │ │ │ ├── api │ │ │ │ ├── form │ │ │ │ │ ├── taglib │ │ │ │ │ └── traits │ │ │ │ │ │ ├── traits.css │ │ │ │ │ │ └── traits.js │ │ │ │ ├── SCMNavigator │ │ │ │ │ └── newInstanceDetail.jelly │ │ │ │ ├── Messages.properties │ │ │ │ └── SCMSource │ │ │ │ │ └── config.jelly │ │ │ │ └── impl │ │ │ │ ├── SingleSCMSource │ │ │ │ ├── help-name.html │ │ │ │ ├── config-detail.properties │ │ │ │ └── config-detail.jelly │ │ │ │ ├── SingleSCMNavigator │ │ │ │ ├── config.properties │ │ │ │ └── config.jelly │ │ │ │ ├── trait │ │ │ │ ├── WildcardSCMSourceFilterTrait │ │ │ │ │ ├── help-excludes.html │ │ │ │ │ ├── help-includes.html │ │ │ │ │ └── config.jelly │ │ │ │ ├── RegexSCMHeadFilterTrait │ │ │ │ │ ├── config.jelly │ │ │ │ │ └── help-regex.html │ │ │ │ ├── RegexSCMSourceFilterTrait │ │ │ │ │ ├── config.jelly │ │ │ │ │ └── help-regex.html │ │ │ │ ├── Messages.properties │ │ │ │ └── WildcardSCMHeadFilterTrait │ │ │ │ │ ├── help-excludes.html │ │ │ │ │ ├── help-includes.html │ │ │ │ │ └── config.jelly │ │ │ │ └── Messages.properties │ │ └── index.jelly │ ├── webapp │ │ └── test-avatar.png │ └── java │ │ └── jenkins │ │ └── scm │ │ ├── api │ │ ├── SCMDetailGroup.java │ │ ├── package-info.java │ │ ├── actions │ │ │ ├── package-info.java │ │ │ └── ChangeRequestAction.java │ │ ├── trait │ │ │ ├── package-info.java │ │ │ ├── SCMHeadPrefilter.java │ │ │ ├── SCMSourcePrefilter.java │ │ │ ├── SCMSourceFilter.java │ │ │ ├── SCMHeadFilter.java │ │ │ └── SCMTraitDescriptor.java │ │ ├── mixin │ │ │ ├── package-info.java │ │ │ ├── ChangeRequestSCMHead.java │ │ │ ├── ChangeRequestCheckoutStrategy.java │ │ │ ├── TagSCMHead.java │ │ │ └── ChangeRequestSCMHead2.java │ │ ├── SCMNavigatorOwner.java │ │ ├── SCMEventListener.java │ │ ├── metadata │ │ │ └── package-info.java │ │ ├── SCMProbe.java │ │ └── SCMRevision.java │ │ └── impl │ │ ├── package-info.java │ │ ├── avatars │ │ ├── AvatarImage.java │ │ └── AvatarImageSource.java │ │ ├── trait │ │ ├── Selection.java │ │ └── Discovery.java │ │ ├── NoOpProjectObserver.java │ │ ├── NullSCMSource.java │ │ ├── TagSCMHeadCategory.java │ │ ├── ChangeRequestSCMHeadCategory.java │ │ ├── SingleSCMNavigator.java │ │ ├── UncategorizedSCMHeadCategory.java │ │ └── SCMTriggerListener.java └── test │ ├── java │ └── jenkins │ │ └── scm │ │ ├── impl │ │ ├── mock │ │ │ ├── MockSCMControllerTest.java │ │ │ ├── MockSCMSourceSaveListener.java │ │ │ ├── MockSCMRepositoryBrowser.java │ │ │ ├── MockSCMNavigatorSaveListener.java │ │ │ ├── MockSCMHead.java │ │ │ ├── MockSCMNavigatorRequest.java │ │ │ ├── MockRepositoryFlags.java │ │ │ ├── MockTagSCMHead.java │ │ │ ├── MockSCMNavigatorContext.java │ │ │ ├── MockChangeRequestFlags.java │ │ │ ├── MockSCMFileSystem.java │ │ │ ├── MockFailure.java │ │ │ ├── MockSCMBuilder.java │ │ │ ├── MockSCMRevision.java │ │ │ ├── MockSCMChangeLogEntry.java │ │ │ ├── MockSCMChangeLogSet.java │ │ │ ├── MockSCMLink.java │ │ │ ├── MockAvatarMetadataAction.java │ │ │ ├── MockSCMFile.java │ │ │ ├── MockSCMNavigatorEvent.java │ │ │ ├── MockSCMSourceBuilder.java │ │ │ ├── MockChangeRequestSCMRevision.java │ │ │ ├── MockSCMSourceRequest.java │ │ │ ├── MockSCMDiscoverBranches.java │ │ │ ├── MockSCMDiscoverTags.java │ │ │ ├── MockSCMSourceEvent.java │ │ │ ├── MockChangeRequestSCMHead.java │ │ │ ├── MockSCMSourceContext.java │ │ │ ├── AbstractSampleDVCSRepoRule.java │ │ │ └── AbstractSampleRepoRule.java │ │ ├── UncategorizedSCMSourceCategoryTest.java │ │ ├── NoOpProjectObserverTest.java │ │ ├── ChangeRequestSCMHeadCategoryTest.java │ │ ├── TagSCMHeadCategoryTest.java │ │ ├── trait │ │ │ └── RegexSCMHeadFilterTraitTest.java │ │ ├── UncategorizedSCMHeadCategoryTest.java │ │ └── NullSCMSourceTest.java │ │ └── api │ │ └── SCMNameTest.java │ └── resources │ └── jenkins │ └── scm │ └── impl │ ├── SingleSCMSourceTest │ └── SCMSourceBuilder │ │ └── config.jelly │ └── mock │ ├── MockSCMDiscoverChangeRequests │ └── config.jelly │ ├── MockSCMNavigator │ └── config.jelly │ ├── MockSCMSource │ └── config-detail.jelly │ └── MockSCM │ └── config.jelly ├── .github ├── CODEOWNERS ├── workflows │ ├── auto-merge-safe-deps.yml │ ├── close-bom-if-passing.yml │ ├── cd.yaml │ └── jenkins-security-scan.yml └── dependabot.yml ├── .mvn ├── maven.config └── extensions.xml ├── Jenkinsfile ├── .gitignore └── README.md /.cloudbees.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.jenkins/artifacts.lst: -------------------------------------------------------------------------------- 1 | **/target/*.hpi 2 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/form/taglib: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jenkinsci/scm-api-plugin-developers 2 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -Dchangelist.format=%d.v%s 4 | -------------------------------------------------------------------------------- /src/main/webapp/test-avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scm-api-plugin/HEAD/src/main/webapp/test-avatar.png -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | buildPlugin( 2 | useContainerAgent: true, 3 | configurations: [ 4 | [platform: 'linux', jdk: 25], 5 | [platform: 'windows', jdk: 21], 6 | ]) 7 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/SingleSCMSource/help-name.html: -------------------------------------------------------------------------------- 1 |
jenkins *-plugin
27 | * as a wildcard; for example: jenkins *-plugin
27 | release alpha-* beta-** as a wildcard; for example: master release*master branch of a special clone.
28 |
--------------------------------------------------------------------------------
/src/main/resources/jenkins/scm/impl/trait/WildcardSCMHeadFilterTrait/config.jelly:
--------------------------------------------------------------------------------
1 |
24 |
25 |
30 | * This defines a source for avatar to be ached and implementation to fetch it
31 | */
32 | public interface AvatarImageSource {
33 | /**
34 | *
35 | * Fetch image from source
36 | *
37 | * @return image as AvatarImage object
38 | */
39 | AvatarImage fetch();
40 |
41 | /**
42 | * Get unique hash key for this item to be used for caching
43 | */
44 | String getId();
45 |
46 | /**
47 | * Make sure we can fetch
48 | *
49 | * @return true if can fetch
50 | */
51 | boolean canFetch();
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/jenkins/scm/impl/trait/Selection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2017, CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.impl.trait;
26 |
27 | import java.lang.annotation.Documented;
28 | import java.lang.annotation.ElementType;
29 | import java.lang.annotation.Inherited;
30 | import java.lang.annotation.Retention;
31 | import java.lang.annotation.RetentionPolicy;
32 | import java.lang.annotation.Target;
33 | import jenkins.scm.api.trait.SCMTraitDescriptor;
34 |
35 | /**
36 | * Annotation to apply to {@link SCMTraitDescriptor} types that are pure filters. These traits will restrict the
37 | * effective discovery
38 | *
39 | * @since 2.2.0
40 | */
41 | @Target(ElementType.TYPE)
42 | @Retention(RetentionPolicy.RUNTIME)
43 | @Documented
44 | @Inherited
45 | public @interface Selection {
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/jenkins/scm/impl/mock/MockChangeRequestFlags.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2017 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.impl.mock;
26 |
27 | import java.util.Set;
28 |
29 | /**
30 | * Feature flags for different types of change request.
31 | */
32 | public enum MockChangeRequestFlags {
33 | FORK {
34 | @Override
35 | public boolean isApplicable(Set
43 | * In the event that the merge operation cannot be completed then the checkout operation will fail.
44 | *
46 | * It is assumed that the algorithm for merging is deterministic given the revision of the change request and
47 | * the revision of the {@link ChangeRequestSCMHead#getTarget()}
48 | *
44 | * For example, if a consumer creates a job for every {@link SCMHead} it may not be a good idea to trigger
45 | * builds of old tags (especially if the build were to result in a deployment to production). However when newly
46 | * created tags are discovered on subsequent searches (or when reported by the events subsystem), it may be
47 | * the intent of the user to have that tag result in a build (eg allowing the creation of a tag to trigger
48 | * a release)
49 | *
50 | * NOTE: Implementers are strongly recommended to use the time that the tag
51 | * was created as the timestamp. Where this is not possible, then implementers should use the maximum last modified
52 | * timestamp of the contents of the tag.
53 | *
54 | * @return the timestamp, directly comparable to {@link System#currentTimeMillis()}.
55 | */
56 | long getTimestamp();
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/jenkins/scm/api/metadata/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | */
25 |
26 | /**
27 | * The {@linkplain hudson.model.InvisibleAction metadata} classes that can be used to report metadata about
28 | * {@linkplain jenkins.scm.api.SCMNavigator navigator}, {@linkplain jenkins.scm.api.SCMSource source},
29 | * {@linkplain jenkins.scm.api.SCMHead head} and {@linkplain jenkins.scm.api.SCMRevision revisions} objects via the
30 | * {@link jenkins.scm.api.SCMNavigator#fetchActions(jenkins.scm.api.SCMNavigatorOwner, jenkins.scm.api.SCMNavigatorEvent, hudson.model.TaskListener) SCMNavigator.fetchActions(...)},
31 | * {@link jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMSourceEvent, hudson.model.TaskListener) SCMSource.fetchActions(...)},
32 | * {@link jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMHead, jenkins.scm.api.SCMHeadEvent, hudson.model.TaskListener) SCMSource.fetchActions(SCMHead, ...)}
33 | * and
34 | * {@link jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMRevision, jenkins.scm.api.SCMHeadEvent, hudson.model.TaskListener) SCMSource.fetchActions(SCMRevision, ...)}
35 | * methods respectively.
36 | *
37 | * @see hudson.model.InvisibleAction
38 | * @see jenkins.scm.api.SCMNavigator#fetchActions(jenkins.scm.api.SCMNavigatorOwner, jenkins.scm.api.SCMNavigatorEvent, hudson.model.TaskListener)
39 | * @see jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMSourceEvent, hudson.model.TaskListener)
40 | * @see jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMHead, jenkins.scm.api.SCMHeadEvent, hudson.model.TaskListener)
41 | * @see jenkins.scm.api.SCMSource#fetchActions(jenkins.scm.api.SCMRevision, jenkins.scm.api.SCMHeadEvent, hudson.model.TaskListener)
42 | * @since 2.0
43 | */
44 | package jenkins.scm.api.metadata;
45 |
--------------------------------------------------------------------------------
/src/main/java/jenkins/scm/impl/TagSCMHeadCategory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | */
25 |
26 | package jenkins.scm.impl;
27 |
28 | import edu.umd.cs.findbugs.annotations.NonNull;
29 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
30 | import jenkins.scm.api.SCMHead;
31 | import jenkins.scm.api.SCMHeadCategory;
32 | import jenkins.scm.api.SCMSource;
33 | import jenkins.scm.api.mixin.TagSCMHead;
34 | import org.jvnet.localizer.Localizable;
35 |
36 | /**
37 | * Standard category for {@link SCMHead} instances that implement {@link TagSCMHead}.
38 | *
39 | * @since 2.0
40 | */
41 | public final class TagSCMHeadCategory extends SCMHeadCategory {
42 | /**
43 | * The {@link TagSCMHeadCategory} singleton with the default naming.
44 | */
45 | public static final TagSCMHeadCategory DEFAULT = new TagSCMHeadCategory();
46 |
47 | /**
48 | * Constructs a {@link TagSCMHeadCategory} using the default naming.
49 | */
50 | private TagSCMHeadCategory() {
51 | super("tags", Messages._TagSCMHeadCategory_DisplayName());
52 | }
53 |
54 | /**
55 | * Constructs a {@link TagSCMHeadCategory} with customized naming. Use this constructor when the generic
56 | * naming is not appropriate terminology for the specific {@link SCMSource}'s naming of change requests.
57 | *
58 | * @param displayName the display name for change requests.
59 | */
60 | @SuppressFBWarnings("NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION")
61 | public TagSCMHeadCategory(@NonNull Localizable displayName) {
62 | super("tags", displayName);
63 | }
64 |
65 | /**
66 | * {@inheritDoc}
67 | */
68 | @Override
69 | public boolean isMatch(@NonNull SCMHead instance) {
70 | return instance instanceof TagSCMHead;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverBranches.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2017, CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.impl.mock;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import hudson.Extension;
29 | import jenkins.scm.api.SCMHeadCategory;
30 | import jenkins.scm.api.trait.SCMBuilder;
31 | import jenkins.scm.api.trait.SCMSourceContext;
32 | import jenkins.scm.api.trait.SCMSourceTrait;
33 | import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
34 | import org.jenkinsci.Symbol;
35 | import org.kohsuke.stapler.DataBoundConstructor;
36 |
37 | public class MockSCMDiscoverBranches extends SCMSourceTrait {
38 |
39 | @DataBoundConstructor
40 | public MockSCMDiscoverBranches() {
41 | }
42 |
43 | @Override
44 | protected void decorateContext(SCMSourceContext, ?> context) {
45 | ((MockSCMSourceContext) context).withBranches(true);
46 | }
47 |
48 | @Override
49 | public boolean includeCategory(@NonNull SCMHeadCategory category) {
50 | return category.isUncategorized();
51 | }
52 |
53 | @Symbol("discoverBranches")
54 | @Extension
55 | public static final class DescriptorImpl extends SCMSourceTraitDescriptor {
56 |
57 | @NonNull
58 | @Override
59 | public String getDisplayName() {
60 | return "Discover branches";
61 | }
62 |
63 | @Override
64 | public boolean isApplicableToContext(@NonNull Class extends SCMSourceContext> contextClass) {
65 | return MockSCMSourceContext.class.isAssignableFrom(contextClass);
66 | }
67 |
68 | @Override
69 | public boolean isApplicableToBuilder(@NonNull Class extends SCMBuilder> builderClass) {
70 | return MockSCMBuilder.class.isAssignableFrom(builderClass);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/jenkins/scm/impl/mock/MockSCMDiscoverTags.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2017, CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.impl.mock;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import hudson.Extension;
29 | import jenkins.scm.api.SCMHeadCategory;
30 | import jenkins.scm.api.trait.SCMBuilder;
31 | import jenkins.scm.api.trait.SCMSourceContext;
32 | import jenkins.scm.api.trait.SCMSourceTrait;
33 | import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
34 | import jenkins.scm.impl.TagSCMHeadCategory;
35 | import org.jenkinsci.Symbol;
36 | import org.kohsuke.stapler.DataBoundConstructor;
37 |
38 | public class MockSCMDiscoverTags extends SCMSourceTrait {
39 |
40 | @DataBoundConstructor
41 | public MockSCMDiscoverTags() {
42 | }
43 |
44 | @Override
45 | protected void decorateContext(SCMSourceContext, ?> context) {
46 | ((MockSCMSourceContext) context).withTags(true);
47 | }
48 |
49 | @Override
50 | public boolean includeCategory(@NonNull SCMHeadCategory category) {
51 | return category instanceof TagSCMHeadCategory;
52 | }
53 |
54 | @Symbol("discoverTags")
55 | @Extension
56 | public static final class DescriptorImpl extends SCMSourceTraitDescriptor {
57 |
58 | @NonNull
59 | @Override
60 | public String getDisplayName() {
61 | return "Discover tags";
62 | }
63 |
64 | @Override
65 | public boolean isApplicableToContext(@NonNull Class extends SCMSourceContext> contextClass) {
66 | return MockSCMSourceContext.class.isAssignableFrom(contextClass);
67 | }
68 |
69 | @Override
70 | public boolean isApplicableToBuilder(@NonNull Class extends SCMBuilder> builderClass) {
71 | return MockSCMBuilder.class.isAssignableFrom(builderClass);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/test/java/jenkins/scm/impl/mock/MockSCMSourceEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | */
25 |
26 | package jenkins.scm.impl.mock;
27 |
28 | import edu.umd.cs.findbugs.annotations.CheckForNull;
29 | import edu.umd.cs.findbugs.annotations.NonNull;
30 | import jenkins.scm.api.SCMNavigator;
31 | import jenkins.scm.api.SCMSource;
32 | import jenkins.scm.api.SCMSourceEvent;
33 |
34 | public class MockSCMSourceEvent extends SCMSourceEvent {@inheritDoc}
70 | */
71 | @Override
72 | public String toString() {
73 | return super.toString();
74 | }
75 |
76 | /**
77 | * Returns {@code true} if and only if this revision is deterministic, in other words that repeated checkouts of
78 | * this revision will result in the exact same files being checked out. Most modern SCM systems have a deterministic
79 | * revision, however some of the older ones do not have a deterministic revision for all types of head.
80 | *
81 | * @return {@code true} if and only if this revision is deterministic.
82 | */
83 | @Exported
84 | public boolean isDeterministic() {
85 | return true;
86 | }
87 |
88 | /**
89 | * Returns the {@link SCMHead} that this {@link SCMRevision} belongs to.
90 | *
91 | * @return the {@link SCMHead} that this {@link SCMRevision} belongs to.
92 | */
93 | @Exported
94 | @NonNull
95 | public final SCMHead getHead() {
96 | return head;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/jenkins/scm/api/trait/SCMTraitDescriptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2017 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.api.trait;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import hudson.model.Descriptor;
29 | import hudson.scm.SCM;
30 | import hudson.scm.SCMDescriptor;
31 |
32 | /**
33 | * Abstract base class for {@link Descriptor} of {@link SCMTrait} implementations.
34 | *
35 | * @since 2.2.0
36 | */
37 | public abstract class SCMTraitDescriptor For example: the Accurev source control system uses the term "streams" to refer to the same thing that
56 | * Git would call "branches", it would confuse Accurev users if we called their "streams" as "branches" so an
57 | * Accurev specific provider would use this constructor to generate a singleton with the "streams" name.
58 | * If there is a Git and Accurev source in the same context then
59 | * {@link SCMHeadCategory#collectAndSimplify(Iterable)} will contain an {@link UncategorizedSCMHeadCategory} under
60 | * the {@code default} key that has a {@link #getDisplayName()} of {@code Branches / Streams}
61 | *
62 | * @param displayName the display name for the uncategorized {@link SCMHead}s when the source control system uses a
63 | * different terminology from "branches".
64 | */
65 | @SuppressFBWarnings("NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION")
66 | public UncategorizedSCMHeadCategory(@NonNull Localizable displayName) {
67 | super(displayName);
68 | }
69 |
70 | /**
71 | * {@inheritDoc}
72 | */
73 | @Override
74 | public boolean isMatch(@NonNull SCMHead instance) {
75 | return true;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/test/java/jenkins/scm/impl/mock/AbstractSampleDVCSRepoRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2015 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package jenkins.scm.impl.mock;
26 |
27 | import java.io.File;
28 | import java.io.IOException;
29 | import java.io.UnsupportedEncodingException;
30 | import java.net.URLEncoder;
31 | import java.nio.charset.StandardCharsets;
32 | import java.util.ArrayList;
33 | import java.util.Arrays;
34 | import java.util.List;
35 | import org.apache.commons.io.FileUtils;
36 | import static jenkins.scm.impl.mock.AbstractSampleRepoRule.run;
37 |
38 | /**
39 | * Rule tailored to a DVCS which may be initialized and cloned from a local directory.
40 | *
41 | * @since 2.0.8
42 | */
43 | public abstract class AbstractSampleDVCSRepoRule extends AbstractSampleRepoRule {
44 |
45 | /**
46 | * The origin clone.
47 | */
48 | protected File sampleRepo;
49 |
50 | @Override
51 | protected void before() throws Throwable {
52 | super.before();
53 | sampleRepo = tmp.newFolder();
54 | }
55 |
56 | /**
57 | * Write a file to {@link #sampleRepo}.
58 | * @param rel relative path ({@code /}-separated)
59 | * @param text text to write
60 | */
61 | public final void write(String rel, String text) throws IOException {
62 | FileUtils.write(new File(sampleRepo, rel), text, StandardCharsets.UTF_8);
63 | }
64 |
65 | /**
66 | * @return path of {@link #sampleRepo}
67 | */
68 | @Override
69 | public final String toString() {
70 | return sampleRepo.getAbsolutePath();
71 | }
72 |
73 | /**
74 | * Initialize a repository in an empty directory.
75 | */
76 | public abstract void init() throws Exception;
77 |
78 | /**
79 | * Run the specified tool inside {@link #sampleRepo}.
80 | * @param tool a tool like {@code git}
81 | * @param cmds its arguments
82 | */
83 | protected final void run(String tool, String... cmds) throws Exception {
84 | List