├── .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 |
2 | The name of the SCM head/trunk/branch/tag that this source provides. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | This plugin provides a new enhanced API for interacting with SCM systems. 4 |
5 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge-safe-deps.yml: -------------------------------------------------------------------------------- 1 | name: Automatically approve and merge safe dependency updates 2 | on: 3 | - pull_request_target 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | jobs: 8 | auto-merge-safe-deps: 9 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/auto-merge-safe-deps.yml@v1 10 | -------------------------------------------------------------------------------- /.github/workflows/close-bom-if-passing.yml: -------------------------------------------------------------------------------- 1 | name: Close BOM update PR if passing 2 | on: 3 | check_run: 4 | types: 5 | - completed 6 | permissions: 7 | contents: read 8 | pull-requests: write 9 | jobs: 10 | close-bom-if-passing: 11 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/close-bom-if-passing.yml@v1 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven build files 2 | target/ 3 | 4 | # Jenkins plugin development 5 | work/ 6 | 7 | # IntelliJ project files 8 | *.iml 9 | *.ipr 10 | *.iws 11 | .idea/ 12 | 13 | # Eclipse project files 14 | .settings/ 15 | .classpath 16 | .project 17 | .metadata 18 | .loadpath 19 | 20 | # NetBeans project files 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | nbactions.xml 27 | nb-configuration.xml 28 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.13 6 | 7 | 8 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | # Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins 2 | 3 | name: cd 4 | on: 5 | workflow_dispatch: 6 | check_run: 7 | types: 8 | - completed 9 | 10 | jobs: 11 | maven-cd: 12 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1 13 | secrets: 14 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 15 | MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }} 16 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/SCMDetailGroup.java: -------------------------------------------------------------------------------- 1 | package jenkins.scm.api; 2 | 3 | import hudson.Extension; 4 | import hudson.ExtensionList; 5 | import jenkins.model.details.DetailGroup; 6 | 7 | /** 8 | * A {@link DetailGroup} implementation that provides SCM-related details. 9 | */ 10 | @Extension(ordinal = -1) 11 | public class SCMDetailGroup extends DetailGroup { 12 | 13 | public static SCMDetailGroup get() { 14 | return ExtensionList.lookupSingleton(SCMDetailGroup.class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jenkins SCM API Plugin 2 | 3 | This plugin provides a new enhanced API for interacting with SCM systems. 4 | 5 | If you are writing a plugin that implements this API, please see [the implementation guide](docs/implementation.adoc) 6 | 7 | If you are writing a plugin that consumes this API, please see [the consumer guide](docs/consumer.adoc) 8 | 9 | # Build 10 | 11 | To build the plugin locally: 12 | 13 | mvn clean verify 14 | 15 | # Test local instance 16 | 17 | To test in a local Jenkins instance 18 | 19 | mvn hpi:run 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: maven 9 | directory: / 10 | schedule: 11 | interval: weekly 12 | - package-ecosystem: github-actions 13 | directory: / 14 | schedule: 15 | interval: weekly 16 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMControllerTest.java: -------------------------------------------------------------------------------- 1 | package jenkins.scm.impl.mock; 2 | 3 | import org.junit.Test; 4 | 5 | import java.security.MessageDigest; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | 9 | public class MockSCMControllerTest { 10 | 11 | @Test 12 | public void toHexBinary() throws Exception { 13 | final MessageDigest msg = MessageDigest.getInstance("SHA-1"); 14 | msg.update("blah".getBytes()); 15 | assertEquals("5bf1fd927dfb8679496a2e6cf00cbe50c1c87145", MockSCMController.toHexBinary(msg.digest())); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | name: Jenkins Security Scan 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [ opened, synchronize, reopened ] 9 | workflow_dispatch: 10 | 11 | permissions: 12 | security-events: write 13 | contents: read 14 | actions: read 15 | 16 | jobs: 17 | security-scan: 18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 19 | with: 20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 22 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/form/traits/traits.css: -------------------------------------------------------------------------------- 1 | DIV.repeated-chunk.trait-section { 2 | display: block; 3 | text-align: center; 4 | margin: 0; 5 | padding: 0.1em; 6 | border: 0 !important; 7 | 8 | &::after { 9 | display: none; 10 | } 11 | } 12 | 13 | DIV.repeated-chunk.trait-section.trait-section-empty { 14 | display: none; 15 | } 16 | 17 | SPAN.trait-section-header { 18 | position: relative; 19 | overflow: hidden; 20 | font-style: italic; 21 | } 22 | 23 | SPAN.trait-section-header SPAN { 24 | display: inline-block; 25 | vertical-align: baseline; 26 | zoom: 1; 27 | *display: inline; 28 | *vertical-align: auto; 29 | position: relative; 30 | padding: 0 1em; 31 | } 32 | 33 | SPAN.trait-section-header SPAN:before, SPAN.trait-section-header SPAN:after { 34 | content: ''; 35 | display: block; 36 | width: 10em; 37 | position: absolute; 38 | top: 0.5em; 39 | border-top: 1px dotted rgba(0, 0, 0, 0.5); 40 | } 41 | 42 | SPAN.trait-section-header SPAN:before { 43 | right: 100%; 44 | } 45 | 46 | SPAN.trait-section-header SPAN:after { 47 | left: 100%; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/SCMNavigator/newInstanceDetail.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/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 public API contract of the SCM API plugin. 28 | */ 29 | package jenkins.scm.api; 30 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/SingleSCMNavigator/config.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright 2016 CloudBees, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | blurb=\ 24 | Allows a single, fixed SCM repository to be configured. \ 25 | Not normally used, as it does not allow repositories to be detected automatically. 26 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/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 common implementations of classes in the public API. 28 | * 29 | * @see jenkins.scm.api 30 | */ 31 | package jenkins.scm.impl; 32 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMSourceSaveListener.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 | 26 | package jenkins.scm.impl.mock; 27 | 28 | public abstract class MockSCMSourceSaveListener { 29 | public abstract void afterSave(MockSCMSource source); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # 4 | # Copyright (c) 2011-2013, CloudBees, Inc., Stephen Connolly. 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 | SCMNavigator.Description=A collection of SCM repositories 26 | 27 | SCMCategory.Join={0} / {1} 28 | SCMHeadCategory.DisplayName=Branches 29 | SCMSourceCategory.DisplayName=Repositories 30 | -------------------------------------------------------------------------------- /src/test/resources/jenkins/scm/impl/SingleSCMSourceTest/SCMSourceBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMRepositoryBrowser.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 hudson.scm.RepositoryBrowser; 29 | 30 | public abstract class MockSCMRepositoryBrowser extends RepositoryBrowser { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/actions/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 | * Do not use. 28 | * 29 | * @deprecated Do not use any of these classes they were added in error, retained for binary compatibility only 30 | */ 31 | package jenkins.scm.api.actions; 32 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMSourceFilterTrait/help-excludes.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | Space-separated list of project name patterns to ignore even if matched by the includes list. 26 | For example: jenkins *-plugin 27 |
28 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMSourceFilterTrait/help-includes.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | Space-separated list of project name patterns to consider. 26 | You may use * as a wildcard; for example: jenkins *-plugin 27 |
28 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/form/traits/traits.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | var traitSectionRule = function (e) { 3 | var p = e.previousSibling; 4 | var n = e.nextSibling; 5 | var empty = (!n || n.classList.contains("trait-section") || n.classList.contains("repeatable-insertion-point")); 6 | // find any previous entries 7 | while (p && p.classList.contains("trait-section")) { 8 | p = p.previousSibling; 9 | } 10 | if (!empty) { 11 | // skip our entries 12 | while (n && !n.classList.contains("trait-section") && !n.classList.contains("repeatable-insertion-point")) { 13 | n = n.nextSibling; 14 | } 15 | } 16 | // find next section entries 17 | while (n && n.classList.contains("trait-section") && !n.classList.contains("repeatable-insertion-point")) { 18 | n = n.nextSibling; 19 | } 20 | if ((!p && n.classList.contains("repeatable-insertion-point")) || empty) { 21 | e.classList.add("trait-section-empty"); 22 | } else { 23 | e.classList.remove("trait-section-empty"); 24 | } 25 | }; 26 | Behaviour.specify("DIV.trait-container", 'traits', -50, function (e) { 27 | if (isInsideRemovable(e)) { 28 | return; 29 | } 30 | layoutUpdateCallback.add(function () { 31 | e.querySelectorAll(".trait-section").forEach(traitSectionRule); 32 | }) 33 | }); 34 | })(); 35 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/RegexSCMHeadFilterTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/RegexSCMSourceFilterTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/trait/package-info.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 | 26 | /** 27 | * An API/SPI to allow the sharing of common traits between different {@link jenkins.scm.api.SCMSource} and 28 | * {@link jenkins.scm.api.SCMNavigator} implementations. 29 | * 30 | * @since 2.2.0 31 | */ 32 | package jenkins.scm.api.trait; 33 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorSaveListener.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 | 26 | package jenkins.scm.impl.mock; 27 | 28 | import jenkins.scm.api.SCMNavigatorOwner; 29 | 30 | public abstract class MockSCMNavigatorSaveListener { 31 | public abstract void afterSave(MockSCMNavigator navigator, SCMNavigatorOwner owner); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/RegexSCMSourceFilterTrait/help-regex.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | A Java regular expression to 26 | restrict the project names. Project names that do not match the supplied regular expression will be ignored. 27 |
28 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMHead.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.NonNull; 29 | import jenkins.scm.api.SCMHead; 30 | 31 | public class MockSCMHead extends SCMHead { 32 | 33 | public MockSCMHead(@NonNull String name) { 34 | super(name); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/Messages.properties: -------------------------------------------------------------------------------- 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 | WildcardSCMHeadFilterTrait.DisplayName=Filter by name (with wildcards) 25 | WildcardSCMSourceFilterTrait.DisplayName=Filter by name (with wildcards) 26 | RegexSCMHeadFilterTrait.DisplayName=Filter by name (with regular expression) 27 | RegexSCMSourceFilterTrait.DisplayName=Filter by name (with regular expression) 28 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMHeadFilterTrait/help-excludes.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | Space-separated list of name patterns to ignore even if matched by the includes list. 26 | For example: release alpha-* beta-*
27 | NOTE: this filter will be applied to all branch like things, including change requests 28 |
29 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMHeadFilterTrait/help-includes.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | Space-separated list of name patterns to consider. 26 | You may use * as a wildcard; for example: master release*
27 | NOTE: this filter will be applied to all branch like things, including change requests 28 |
29 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/Messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # The MIT License 3 | # 4 | # Copyright (c) 2011-2013, CloudBees, Inc., Stephen Connolly. 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 | SingleSCMSource.DisplayName=Single repository & branch 25 | SingleSCMNavigator.DisplayName=Single repository 26 | ChangeRequestSCMHeadCategory.DisplayName=Change requests 27 | TagSCMHeadCategory.DisplayName=Tags 28 | UncategorizedSCMHeadCategory.DisplayName=Branches 29 | UncategorizedSCMSourceCategory.DisplayName=Repositories 30 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/SingleSCMSource/config-detail.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright 2016 CloudBees, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | blurb=\ 24 | Allows a single, fixed branch of some repository to be configured. \ 25 | Not normally used, as it does not allow branches to be detected automatically. \ 26 | Might be used, for example, if you want to build all branches of one repository, \ 27 | and the master branch of a special clone. 28 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMHeadFilterTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/WildcardSCMSourceFilterTrait/config.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/test/resources/jenkins/scm/impl/mock/MockSCMDiscoverChangeRequests/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/trait/RegexSCMHeadFilterTrait/help-regex.html: -------------------------------------------------------------------------------- 1 | 24 |
25 | A Java regular expression to 26 | restrict the names. Names that do not match the supplied regular expression will be ignored.
27 | NOTE: this filter will be applied to all branch like things, including change requests 28 |
29 | -------------------------------------------------------------------------------- /src/test/resources/jenkins/scm/impl/mock/MockSCMNavigator/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/SingleSCMNavigator/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/jenkins/scm/impl/mock/MockSCMSource/config-detail.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/api/SCMSource/config.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorRequest.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 jenkins.scm.api.SCMNavigator; 28 | import jenkins.scm.api.SCMSourceObserver; 29 | import jenkins.scm.api.trait.SCMNavigatorContext; 30 | import jenkins.scm.api.trait.SCMNavigatorRequest; 31 | 32 | public class MockSCMNavigatorRequest extends SCMNavigatorRequest { 33 | MockSCMNavigatorRequest(SCMNavigator navigator, SCMNavigatorContext context, SCMSourceObserver observer) { 34 | super(navigator, context, observer); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/mixin/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 jenkins.scm.api.mixin.SCMHeadMixin mix-in} interfaces used by {@link jenkins.scm.api.SCMHead SCMHead} 28 | * implementations to advertise that a specific head is not just a regular branch but is actually a special type of 29 | * branch such as a {@linkplain jenkins.scm.api.mixin.ChangeRequestSCMHead change request} / 30 | * {@linkplain jenkins.scm.api.mixin.TagSCMHead tag} / etc. 31 | * 32 | * @see jenkins.scm.api.SCMHead 33 | * @since 2.0 34 | */ 35 | package jenkins.scm.api.mixin; 36 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockRepositoryFlags.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 | 26 | package jenkins.scm.impl.mock; 27 | 28 | /** 29 | * Feature flags for different types of repository. 30 | */ 31 | public enum MockRepositoryFlags { 32 | /** 33 | * Enables marking change requests as {@link MockChangeRequestFlags#FORK}. 34 | */ 35 | FORKABLE, 36 | /** 37 | * The repository has the concept of trust for change requests and will report change requests marked {@link 38 | * MockChangeRequestFlags#UNTRUSTED} as untrusted. 39 | */ 40 | TRUST_AWARE 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockTagSCMHead.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.NonNull; 29 | import jenkins.scm.api.mixin.TagSCMHead; 30 | 31 | public class MockTagSCMHead extends MockSCMHead implements TagSCMHead { 32 | 33 | private final long timestamp; 34 | 35 | public MockTagSCMHead(@NonNull String name, long timestamp) { 36 | super(name); 37 | this.timestamp = timestamp; 38 | } 39 | 40 | @Override 41 | public long getTimestamp() { 42 | return timestamp; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/SCMNavigatorOwner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011-2016, CloudBees, Inc., Stephen Connolly. 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 | package jenkins.scm.api; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import hudson.model.Item; 28 | import java.util.List; 29 | 30 | /** 31 | * An {@link Item} that owns {@link SCMNavigator} instances. 32 | * 33 | * @since 2.0 34 | */ 35 | public interface SCMNavigatorOwner extends SCMSourceOwner { 36 | /** 37 | * Returns the {@link SCMNavigator} instances that this item is consuming. 38 | * 39 | * @return the {@link SCMNavigator} instances that this item is consuming. 40 | */ 41 | @NonNull 42 | List getSCMNavigators(); 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorContext.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 jenkins.scm.api.SCMNavigator; 29 | import jenkins.scm.api.SCMSourceObserver; 30 | import jenkins.scm.api.trait.SCMNavigatorContext; 31 | 32 | public class MockSCMNavigatorContext extends SCMNavigatorContext { 33 | @NonNull 34 | @Override 35 | public MockSCMNavigatorRequest newRequest(@NonNull SCMNavigator source, @NonNull SCMSourceObserver observer) { 36 | return new MockSCMNavigatorRequest(source, this, observer); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/jenkins/scm/impl/mock/MockSCM/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/avatars/AvatarImage.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 | package jenkins.scm.impl.avatars; 25 | 26 | import java.awt.image.BufferedImage; 27 | 28 | /** 29 | * Holds Image and lastModified date 30 | */ 31 | public class AvatarImage { 32 | /** 33 | * Avatar Image 34 | */ 35 | public final BufferedImage image; 36 | /** 37 | * Last Modified Timestamp 38 | */ 39 | public final long lastModified; 40 | 41 | /** 42 | * Singleton for empty image 43 | */ 44 | public static final AvatarImage EMPTY = new AvatarImage(null, 0); 45 | 46 | public AvatarImage(final BufferedImage image, final long lastModified) { 47 | this.image = image; 48 | this.lastModified = lastModified; 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/avatars/AvatarImageSource.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 | package jenkins.scm.impl.avatars; 25 | 26 | /** 27 | * 28 | * Interface for Avatar Cache Item Source 29 | *

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 flags) { 36 | return flags.contains(MockRepositoryFlags.FORKABLE); 37 | } 38 | }, 39 | UNTRUSTED { 40 | @Override 41 | public boolean isApplicable(Set flags) { 42 | return flags.contains(MockRepositoryFlags.TRUST_AWARE); 43 | } 44 | }; 45 | 46 | public abstract boolean isApplicable(Set flags); 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMFileSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2018, 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.CheckForNull; 28 | import edu.umd.cs.findbugs.annotations.NonNull; 29 | import jenkins.scm.api.SCMFile; 30 | import jenkins.scm.api.SCMFileSystem; 31 | import jenkins.scm.api.SCMRevision; 32 | 33 | import java.io.IOException; 34 | 35 | public class MockSCMFileSystem extends SCMFileSystem { 36 | public MockSCMFileSystem(@CheckForNull SCMRevision rev) { 37 | super(rev); 38 | } 39 | 40 | @Override 41 | public long lastModified() throws IOException, InterruptedException { 42 | return 1; 43 | } 44 | 45 | @NonNull 46 | public SCMFile getRoot() { 47 | return new MockSCMFile(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockFailure.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 java.io.IOException; 30 | 31 | /** 32 | * Represents a failure in {@link MockSCMNavigator} and/or {@link MockSCMSource} 33 | */ 34 | public abstract class MockFailure { 35 | /** 36 | * Checks whether this combination should fail. 37 | * 38 | * @param repository the repository. 39 | * @param branchOrCR the branch, tag or change request 40 | * @param revision the revision. 41 | * @param actions 42 | * @throws IOException if you want a fault. 43 | */ 44 | public abstract void check(@CheckForNull String repository, @CheckForNull String branchOrCR, 45 | @CheckForNull String revision, boolean actions) throws IOException; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/SCMEventListener.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.api; 27 | 28 | import hudson.ExtensionPoint; 29 | 30 | /** 31 | * Base class for listeners to {@link SCMEvent}s 32 | * 33 | * @since 2.0 34 | */ 35 | public class SCMEventListener implements ExtensionPoint { 36 | 37 | /** 38 | * Callback for a {@link SCMHeadEvent} 39 | * 40 | * @param event the event. 41 | */ 42 | public void onSCMHeadEvent(SCMHeadEvent event) { 43 | 44 | } 45 | 46 | /** 47 | * Callback for a {@link SCMNavigatorEvent} 48 | * 49 | * @param event the event. 50 | */ 51 | public void onSCMNavigatorEvent(SCMNavigatorEvent event) { 52 | 53 | } 54 | 55 | /** 56 | * Callback for a {@link SCMSourceEvent} 57 | * 58 | * @param event the event. 59 | */ 60 | public void onSCMSourceEvent(SCMSourceEvent event) { 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/mixin/ChangeRequestSCMHead.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.api.mixin; 27 | 28 | import edu.umd.cs.findbugs.annotations.NonNull; 29 | import jenkins.scm.api.SCMHead; 30 | import jenkins.scm.api.SCMSource; 31 | import org.kohsuke.stapler.export.Exported; 32 | 33 | /** 34 | * Mixin interface to identify {@link SCMHead} instances that correspond to a change request. 35 | * 36 | * @since 2.0 37 | */ 38 | public interface ChangeRequestSCMHead extends SCMHeadMixin { 39 | 40 | /** 41 | * Identifier of this change request. 42 | * Expected to be unique among requests coming from a given {@link SCMSource}. 43 | * 44 | * @return an ID of some kind, such as a pull request number (decimal) or a Gerrit change ID 45 | */ 46 | @Exported 47 | @NonNull 48 | String getId(); 49 | 50 | /** 51 | * Branch to which this change would be merged or applied if it were accepted. 52 | * 53 | * @return a "target" or "base" branch 54 | */ 55 | @Exported 56 | @NonNull 57 | SCMHead getTarget(); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMBuilder.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.CheckForNull; 28 | import edu.umd.cs.findbugs.annotations.NonNull; 29 | import jenkins.scm.api.trait.SCMBuilder; 30 | import jenkins.scm.api.SCMHead; 31 | import jenkins.scm.api.SCMRevision; 32 | 33 | public class MockSCMBuilder extends SCMBuilder { 34 | 35 | private final MockSCMSource source; 36 | 37 | public MockSCMBuilder(@NonNull MockSCMSource source, @NonNull SCMHead head, 38 | @CheckForNull SCMRevision revision) { 39 | super(MockSCM.class, head, revision); 40 | this.source = source; 41 | } 42 | 43 | @NonNull 44 | @Override 45 | public MockSCM build() { 46 | SCMRevision revision = revision(); 47 | return new MockSCM(source, head(), 48 | revision instanceof MockSCMRevision || revision instanceof MockChangeRequestSCMRevision 49 | ? revision 50 | : null); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/trait/Discovery.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.SCMSource; 34 | import jenkins.scm.api.mixin.TagSCMHead; 35 | import jenkins.scm.api.trait.SCMNavigatorTrait; 36 | import jenkins.scm.api.trait.SCMSourceTrait; 37 | import jenkins.scm.api.trait.SCMTraitDescriptor; 38 | 39 | /** 40 | * Annotation to apply to {@link SCMTraitDescriptor} types that are control the initial scope of discovery. For example 41 | * a {@link SCMSourceTrait} that will enable the discovery of {@link TagSCMHead} instances on its {@link SCMSource} 42 | * or a {@link SCMNavigatorTrait} that will enable the discovery of projects from a "forks". 43 | * 44 | * @since 2.2.0 45 | */ 46 | @Target(ElementType.TYPE) 47 | @Retention(RetentionPolicy.RUNTIME) 48 | @Documented 49 | @Inherited 50 | public @interface Discovery { 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMRevision.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.NonNull; 29 | import jenkins.scm.api.SCMHead; 30 | import jenkins.scm.api.SCMRevision; 31 | 32 | public class MockSCMRevision extends SCMRevision { 33 | 34 | private final String hash; 35 | 36 | public MockSCMRevision(@NonNull SCMHead head, String hash) { 37 | super(head); 38 | this.hash = hash; 39 | } 40 | 41 | public String getHash() { 42 | return hash; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object o) { 47 | if (this == o) { 48 | return true; 49 | } 50 | if (o == null || getClass() != o.getClass()) { 51 | return false; 52 | } 53 | 54 | MockSCMRevision that = (MockSCMRevision) o; 55 | 56 | return hash.equals(that.hash); 57 | 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return hash.hashCode(); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return hash; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/UncategorizedSCMSourceCategoryTest.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 jenkins.scm.api.SCMSource; 29 | import org.junit.experimental.theories.DataPoint; 30 | import org.junit.experimental.theories.Theories; 31 | import org.junit.experimental.theories.Theory; 32 | import org.junit.runner.RunWith; 33 | 34 | import static org.hamcrest.MatcherAssert.assertThat; 35 | import static org.hamcrest.Matchers.is; 36 | import static org.mockito.Mockito.mock; 37 | 38 | @RunWith(Theories.class) 39 | public class UncategorizedSCMSourceCategoryTest { 40 | 41 | @DataPoint 42 | public static UncategorizedSCMSourceCategory defInstance = UncategorizedSCMSourceCategory.DEFAULT; 43 | 44 | @DataPoint 45 | public static UncategorizedSCMSourceCategory custInstance = new UncategorizedSCMSourceCategory(Messages._UncategorizedSCMSourceCategory_DisplayName()); 46 | 47 | @Theory 48 | public void given_source_when_isMatch_then_confirmMatch(UncategorizedSCMSourceCategory instance) throws Exception { 49 | SCMSource mock = mock(SCMSource.class); 50 | assertThat(instance.isMatch(mock), is(true)); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMChangeLogEntry.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 hudson.model.User; 29 | import hudson.scm.ChangeLogSet; 30 | import java.util.Collection; 31 | 32 | public class MockSCMChangeLogEntry extends ChangeLogSet.Entry { 33 | 34 | private final MockSCMController.LogEntry delegate; 35 | 36 | public MockSCMChangeLogEntry(MockSCMController.LogEntry delegate) { 37 | this.delegate = delegate; 38 | } 39 | 40 | protected void setParent(MockSCMChangeLogSet parent) { 41 | super.setParent(parent); 42 | } 43 | 44 | @Override 45 | public String getCommitId() { 46 | return delegate.getHash(); 47 | } 48 | 49 | @Override 50 | public long getTimestamp() { 51 | return delegate.getTimestamp(); 52 | } 53 | 54 | @Override 55 | public String getMsg() { 56 | return delegate.getMessage(); 57 | } 58 | 59 | @Override 60 | public User getAuthor() { 61 | return User.getUnknown(); 62 | } 63 | 64 | @Override 65 | public Collection getAffectedPaths() { 66 | return delegate.getFiles(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMChangeLogSet.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 hudson.model.Run; 29 | import hudson.scm.ChangeLogSet; 30 | import hudson.scm.RepositoryBrowser; 31 | import java.util.ArrayList; 32 | import java.util.Iterator; 33 | import java.util.List; 34 | 35 | public class MockSCMChangeLogSet extends ChangeLogSet { 36 | 37 | private List entries; 38 | 39 | public MockSCMChangeLogSet(Run build, RepositoryBrowser browser, 40 | List entries) { 41 | super(build, browser); 42 | this.entries = new ArrayList<>(entries.size()); 43 | for (MockSCMController.LogEntry e : entries) { 44 | MockSCMChangeLogEntry entry = new MockSCMChangeLogEntry(e); 45 | entry.setParent(this); 46 | this.entries.add(entry); 47 | } 48 | } 49 | 50 | @Override 51 | public boolean isEmptySet() { 52 | return entries.isEmpty(); 53 | } 54 | 55 | public Iterator iterator() { 56 | return entries.iterator(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/NoOpProjectObserverTest.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 jenkins.scm.api.SCMSource; 29 | import org.junit.Test; 30 | import org.mockito.InOrder; 31 | 32 | import static org.hamcrest.MatcherAssert.assertThat; 33 | import static org.hamcrest.Matchers.notNullValue; 34 | import static org.mockito.Mockito.inOrder; 35 | import static org.mockito.Mockito.mock; 36 | 37 | public class NoOpProjectObserverTest { 38 | @Test 39 | public void instance() throws Exception { 40 | assertThat(NoOpProjectObserver.instance(), notNullValue()); 41 | } 42 | 43 | @Test 44 | public void addSource() throws Exception { 45 | SCMSource source = mock(SCMSource.class); 46 | InOrder seq = inOrder(source); 47 | NoOpProjectObserver.instance().addSource(source); 48 | seq.verifyNoMoreInteractions(); 49 | } 50 | 51 | @Test 52 | public void addAttribute() throws Exception { 53 | NoOpProjectObserver.instance().addAttribute("key", "value"); 54 | } 55 | 56 | @Test 57 | public void complete() throws Exception { 58 | NoOpProjectObserver.instance().complete(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/mixin/ChangeRequestCheckoutStrategy.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.mixin; 26 | 27 | /** 28 | * The various strategies that can be used when checking out a change request. 29 | * 30 | * @since 2.2.0 31 | */ 32 | public enum ChangeRequestCheckoutStrategy { 33 | /** 34 | * The revision to be checked out will be independent of the revision of the 35 | * {@link ChangeRequestSCMHead#getTarget()}. For example, with GitHub, Bitbucket, etc this would correspond to 36 | * checking out the Head revision of the PR. 37 | */ 38 | HEAD, 39 | /** 40 | * The revision to be checked out will be the result of applying a merge algorithm between the the revision 41 | * of the change request and the revision of the {@link ChangeRequestSCMHead#getTarget()}. 42 | *

43 | * In the event that the merge operation cannot be completed then the checkout operation will fail. 44 | *

45 | *

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 | *

49 | */ 50 | MERGE 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMLink.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 hudson.model.Action; 29 | 30 | import java.util.Objects; 31 | 32 | public class MockSCMLink implements Action { 33 | private final String id; 34 | 35 | public MockSCMLink(String id) { 36 | this.id = id; 37 | } 38 | 39 | @Override 40 | public String getIconFileName() { 41 | return "help.png"; 42 | } 43 | 44 | @Override 45 | public String getDisplayName() { 46 | return "Mock SCM"; 47 | } 48 | 49 | @Override 50 | public String getUrlName() { 51 | return "mock-scm"; 52 | } 53 | 54 | public String getId() { 55 | return id; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object o) { 60 | if (this == o) { 61 | return true; 62 | } 63 | if (o == null || getClass() != o.getClass()) { 64 | return false; 65 | } 66 | 67 | MockSCMLink that = (MockSCMLink) o; 68 | 69 | return Objects.equals(id, that.id); 70 | 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return id != null ? id.hashCode() : 0; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/trait/SCMHeadPrefilter.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 jenkins.scm.api.SCMHead; 29 | import jenkins.scm.api.SCMSource; 30 | 31 | /** 32 | * A {@link SCMSourceRequest} independent filter of {@link SCMHead} instances. These filters may not make remote 33 | * requests in order to determine exclusion. 34 | * If multiple filters are used, if any exclude then the head is excluded. 35 | * The {@link SCMHeadPrefilter} instances are applied before {@link SCMHeadFilter} instances in order to minimize 36 | * remote requests. 37 | * 38 | * @see SCMHeadFilter for {@link SCMSourceRequest} dependent filters / filters that can may require on-line operation. 39 | * @since 3.4.0 40 | */ 41 | public abstract class SCMHeadPrefilter { 42 | 43 | /** 44 | * Checks if the supplied {@link SCMHead} is excluded from the specified {@link SCMSource}. 45 | * 46 | * @param source the {@link SCMSource}. 47 | * @param head the {@link SCMHead}. 48 | * @return {@code true} if and only if the {@link SCMHead} is excluded from the request. 49 | */ 50 | public abstract boolean isExcluded(@NonNull SCMSource source, @NonNull SCMHead head); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockAvatarMetadataAction.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 jenkins.scm.api.metadata.AvatarMetadataAction; 29 | 30 | import java.util.Objects; 31 | 32 | public class MockAvatarMetadataAction extends AvatarMetadataAction { 33 | private final String iconClassName; 34 | 35 | public MockAvatarMetadataAction( String iconClassName) { 36 | this.iconClassName = iconClassName; 37 | } 38 | 39 | @Override 40 | public String getAvatarIconClassName() { 41 | return iconClassName; 42 | } 43 | 44 | @Override 45 | public String getAvatarDescription() { 46 | return iconClassName == null ? null : "Mock SCM"; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | if (this == o) { 52 | return true; 53 | } 54 | if (o == null || getClass() != o.getClass()) { 55 | return false; 56 | } 57 | 58 | MockAvatarMetadataAction that = (MockAvatarMetadataAction) o; 59 | 60 | return Objects.equals(iconClassName, that.iconClassName); 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return iconClassName != null ? iconClassName.hashCode() : 0; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/trait/SCMSourcePrefilter.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 jenkins.scm.api.SCMHead; 29 | import jenkins.scm.api.SCMNavigator; 30 | 31 | /** 32 | * A {@link SCMNavigatorRequest} independent filter of project names. These filters may not make remote 33 | * requests in order to determine exclusion. 34 | * If multiple filters are used, if any exclude then the project name is excluded. 35 | * The {@link SCMSourcePrefilter} instances are applied before {@link SCMSourceFilter} instances in order to minimize 36 | * remote requests. 37 | * 38 | * @see SCMSourceFilter for {@link SCMNavigatorRequest} dependent filters / filters that can may require on-line 39 | * operation. 40 | * @since 3.4.0 41 | */ 42 | public abstract class SCMSourcePrefilter { 43 | 44 | /** 45 | * Checks if the supplied project name is excluded from the specified {@link SCMNavigator}. 46 | * 47 | * @param source the {@link SCMNavigator}. 48 | * @param projectName the project name. 49 | * @return {@code true} if and only if the {@link SCMHead} is excluded from the request. 50 | */ 51 | public abstract boolean isExcluded(@NonNull SCMNavigator source, @NonNull String projectName); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2018, 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 jenkins.scm.api.SCMFile; 29 | 30 | import java.io.ByteArrayInputStream; 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | import java.util.Collections; 34 | 35 | public class MockSCMFile extends SCMFile { 36 | public MockSCMFile() { 37 | super(); 38 | } 39 | 40 | @Override 41 | @NonNull 42 | public SCMFile newChild(@NonNull String name, boolean assumeIsDirectory) { 43 | return new MockSCMFile(); 44 | } 45 | 46 | @Override 47 | @NonNull 48 | public Iterable children() throws IOException, InterruptedException { 49 | return Collections.emptyList(); 50 | } 51 | 52 | @Override 53 | public long lastModified() throws IOException, InterruptedException { 54 | return 1; 55 | } 56 | 57 | @Override 58 | @NonNull 59 | public Type type() throws IOException, InterruptedException { 60 | return Type.OTHER; 61 | } 62 | 63 | @Override 64 | @NonNull 65 | public InputStream content() throws IOException, InterruptedException { 66 | return new ByteArrayInputStream("no content".getBytes()); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/trait/SCMSourceFilter.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 java.io.IOException; 29 | 30 | /** 31 | * A {@link SCMNavigatorRequest} dependent filter of project names. Typically these filters may need to 32 | * make remote requests in order to determine exclusion. 33 | * If multiple filters are used, if any exclude then the project name is excluded. 34 | * 35 | * @see SCMSourcePrefilter for {@link SCMSourceRequest} independent filters / filters that can perform completely 36 | * off-line. 37 | * @since 3.4.0 38 | */ 39 | public abstract class SCMSourceFilter { 40 | 41 | /** 42 | * Checks if the supplied project name is excluded from the specified {@link SCMNavigatorRequest}. 43 | * 44 | * @param request the {@link SCMNavigatorRequest}. 45 | * @param projectName the project name. 46 | * @return {@code true} if and only if the project name is excluded from the request. 47 | * @throws IOException if there was an I/O error when determining exclusion. 48 | * @throws InterruptedException if interrupted while determining exclusion. 49 | */ 50 | public abstract boolean isExcluded(@NonNull SCMNavigatorRequest request, @NonNull String projectName) 51 | throws IOException, InterruptedException; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMNavigatorEvent.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.SCMNavigatorEvent; 32 | 33 | public class MockSCMNavigatorEvent extends SCMNavigatorEvent { 34 | 35 | private final MockSCMController controller; 36 | 37 | private final String repository; 38 | 39 | @Deprecated 40 | public MockSCMNavigatorEvent(@NonNull Type type, MockSCMController controller, 41 | String repository) { 42 | super(type, repository); 43 | this.controller = controller; 44 | this.repository = repository; 45 | } 46 | 47 | public MockSCMNavigatorEvent(@CheckForNull String origin, @NonNull Type type, MockSCMController controller, 48 | String repository) { 49 | super(type, repository, origin); 50 | this.controller = controller; 51 | this.repository = repository; 52 | } 53 | 54 | @Override 55 | public boolean isMatch(@NonNull SCMNavigator navigator) { 56 | return navigator instanceof MockSCMNavigator 57 | && ((MockSCMNavigator) navigator).getControllerId().equals(controller.getId()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/trait/SCMHeadFilter.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 java.io.IOException; 29 | import jenkins.scm.api.SCMHead; 30 | 31 | /** 32 | * A {@link SCMSourceRequest} dependent filter of {@link SCMHead} instances. Typically these filters may need to 33 | * make remote requests in order to determine exclusion. 34 | * If multiple filters are used, if any exclude then the head is excluded. 35 | * 36 | * @see SCMHeadPrefilter for {@link SCMSourceRequest} independent filters / filters that can perform completely 37 | * off-line. 38 | * @since 3.4.0 39 | */ 40 | public abstract class SCMHeadFilter { 41 | 42 | /** 43 | * Checks if the supplied {@link SCMHead} is excluded from the specified {@link SCMSourceRequest}. 44 | * 45 | * @param request the {@link SCMSourceRequest}. 46 | * @param head the {@link SCMHead}. 47 | * @return {@code true} if and only if the {@link SCMHead} is excluded from the request. 48 | * @throws IOException if there was an I/O error when determining exclusion. 49 | * @throws InterruptedException if interrupted while determining exclusion. 50 | */ 51 | public abstract boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) 52 | throws IOException, InterruptedException; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/NoOpProjectObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 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 | package jenkins.scm.impl; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import edu.umd.cs.findbugs.annotations.Nullable; 29 | import jenkins.scm.api.SCMSource; 30 | import jenkins.scm.api.SCMSourceObserver; 31 | 32 | /** 33 | * A {@link SCMSourceObserver.ProjectObserver} that does nothing. 34 | * 35 | * @since 2.0 36 | */ 37 | public class NoOpProjectObserver extends SCMSourceObserver.ProjectObserver { 38 | /** 39 | * The singleton instance. 40 | */ 41 | private static final NoOpProjectObserver INSTANCE = new NoOpProjectObserver(); 42 | 43 | /** 44 | * Returns the singleton instance. 45 | * 46 | * @return the singleton instance. 47 | */ 48 | public static NoOpProjectObserver instance() { 49 | return INSTANCE; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public void addSource(@NonNull SCMSource source) { 57 | 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public void addAttribute(@NonNull String key, @Nullable Object value) 65 | throws IllegalArgumentException, ClassCastException { 66 | 67 | } 68 | 69 | /** 70 | * {@inheritDoc} 71 | */ 72 | @Override 73 | public void complete() throws IllegalStateException, InterruptedException { 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/ChangeRequestSCMHeadCategoryTest.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 jenkins.scm.impl.mock.MockChangeRequestSCMHead; 29 | import jenkins.scm.impl.mock.MockSCMHead; 30 | import org.junit.experimental.theories.DataPoint; 31 | import org.junit.experimental.theories.Theories; 32 | import org.junit.experimental.theories.Theory; 33 | import org.junit.runner.RunWith; 34 | 35 | import static org.hamcrest.MatcherAssert.assertThat; 36 | import static org.hamcrest.Matchers.is; 37 | 38 | @RunWith(Theories.class) 39 | public class ChangeRequestSCMHeadCategoryTest { 40 | 41 | @DataPoint 42 | public static ChangeRequestSCMHeadCategory defInstance = ChangeRequestSCMHeadCategory.DEFAULT; 43 | 44 | @DataPoint 45 | public static ChangeRequestSCMHeadCategory custInstance = new ChangeRequestSCMHeadCategory(Messages._ChangeRequestSCMHeadCategory_DisplayName()); 46 | 47 | @Theory 48 | public void given_changeRequestHead_when_isMatch_then_confirmMatch(ChangeRequestSCMHeadCategory instance) throws Exception { 49 | assertThat(instance.isMatch(new MockChangeRequestSCMHead(1, "master")), is(true)); 50 | } 51 | 52 | @Theory 53 | public void given_regularHead_when_isMatch_then_rejectMatch(ChangeRequestSCMHeadCategory instance) throws Exception { 54 | assertThat(instance.isMatch(new MockSCMHead("master")), is(false)); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/TagSCMHeadCategoryTest.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 jenkins.scm.impl.mock.MockChangeRequestSCMHead; 29 | import jenkins.scm.impl.mock.MockSCMHead; 30 | import jenkins.scm.impl.mock.MockTagSCMHead; 31 | import org.junit.experimental.theories.DataPoint; 32 | import org.junit.experimental.theories.Theories; 33 | import org.junit.experimental.theories.Theory; 34 | import org.junit.runner.RunWith; 35 | 36 | import static org.hamcrest.MatcherAssert.assertThat; 37 | import static org.hamcrest.Matchers.is; 38 | 39 | @RunWith(Theories.class) 40 | public class TagSCMHeadCategoryTest { 41 | 42 | @DataPoint 43 | public static TagSCMHeadCategory defInstance = TagSCMHeadCategory.DEFAULT; 44 | 45 | @DataPoint 46 | public static TagSCMHeadCategory custInstance = new TagSCMHeadCategory(Messages._TagSCMHeadCategory_DisplayName()); 47 | 48 | @Theory 49 | public void given_tagHead_when_isMatch_then_confirmMatch(TagSCMHeadCategory instance) throws Exception { 50 | assertThat(instance.isMatch(new MockTagSCMHead("1.0", 0L)), is(true)); 51 | } 52 | 53 | @Theory 54 | public void given_regularHead_when_isMatch_then_rejectMatch(TagSCMHeadCategory instance) throws Exception { 55 | assertThat(instance.isMatch(new MockSCMHead("master")), is(false)); 56 | } 57 | 58 | @Theory 59 | public void given_changeRequestHead_when_isMatch_then_rejectMatch(TagSCMHeadCategory instance) throws Exception { 60 | assertThat(instance.isMatch(new MockChangeRequestSCMHead(1, "master")), is(false)); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMSourceBuilder.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 jenkins.scm.api.trait.SCMSourceBuilder; 29 | 30 | public class MockSCMSourceBuilder extends SCMSourceBuilder { 31 | private String id; 32 | private final String controllerId; 33 | private final MockSCMController controller; 34 | private final String repository; 35 | 36 | public MockSCMSourceBuilder(MockSCMController controller, String repository) { 37 | super(MockSCMSource.class, repository); 38 | this.controllerId = controller.getId(); 39 | this.controller = controller; 40 | this.repository = repository; 41 | } 42 | 43 | public MockSCMSourceBuilder(String controllerId, String repository) { 44 | super(MockSCMSource.class, repository); 45 | this.controllerId = controllerId; 46 | this.controller = null; 47 | this.repository = repository; 48 | } 49 | 50 | public final MockSCMSourceBuilder withId(String id) { 51 | this.id = id; 52 | return this; 53 | } 54 | 55 | public final String id() { 56 | return id; 57 | } 58 | 59 | @NonNull 60 | @Override 61 | public MockSCMSource build() { 62 | MockSCMSource source = controller == null 63 | ? new MockSCMSource(controllerId, repository, traits()) 64 | : new MockSCMSource(controller, repository, traits()); 65 | source.setId(id()); 66 | return source; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockChangeRequestSCMRevision.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 jenkins.scm.api.SCMRevision; 29 | import jenkins.scm.api.mixin.ChangeRequestSCMRevision; 30 | 31 | public class MockChangeRequestSCMRevision extends ChangeRequestSCMRevision { 32 | private final String hash; 33 | 34 | /** 35 | * Constructor. 36 | * 37 | * @param head the {@link MockChangeRequestSCMHead} that the {@link SCMRevision} belongs to. 38 | * @param target the {@link SCMRevision} of the {@link MockChangeRequestSCMHead#getTarget()}. 39 | */ 40 | public MockChangeRequestSCMRevision( 41 | @NonNull MockChangeRequestSCMHead head, 42 | @NonNull SCMRevision target, String hash) { 43 | super(head, target); 44 | this.hash = hash; 45 | } 46 | 47 | public String getHash() { 48 | return hash; 49 | } 50 | 51 | @Override 52 | public boolean equivalent(ChangeRequestSCMRevision o) { 53 | if (this == o) { 54 | return true; 55 | } 56 | if (o == null || getClass() != o.getClass()) { 57 | return false; 58 | } 59 | 60 | MockChangeRequestSCMRevision that = (MockChangeRequestSCMRevision) o; 61 | 62 | return hash.equals(that.hash); 63 | } 64 | 65 | @Override 66 | protected int _hashCode() { 67 | return hash.hashCode(); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return hash; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMSourceRequest.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 hudson.model.TaskListener; 28 | import java.util.Collections; 29 | import java.util.EnumSet; 30 | import java.util.Set; 31 | import jenkins.scm.api.SCMSource; 32 | import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; 33 | import jenkins.scm.api.trait.SCMSourceRequest; 34 | 35 | public class MockSCMSourceRequest extends SCMSourceRequest { 36 | private final boolean fetchBranches; 37 | private final boolean fetchTags; 38 | private final boolean fetchChangeRequests; 39 | private final Set checkoutStrategies; 40 | 41 | MockSCMSourceRequest(SCMSource source, MockSCMSourceContext builder, TaskListener listener) { 42 | super(source, builder, listener); 43 | this.fetchBranches = builder.needsBranches(); 44 | this.fetchTags = builder.needsTags(); 45 | this.fetchChangeRequests = builder.needsChangeRequests(); 46 | this.checkoutStrategies = builder.checkoutStrategies().isEmpty() 47 | ? Collections.emptySet() 48 | : Collections.unmodifiableSet(EnumSet.copyOf(builder.checkoutStrategies())); 49 | } 50 | 51 | public boolean isFetchBranches() { 52 | return fetchBranches; 53 | } 54 | 55 | public boolean isFetchTags() { 56 | return fetchTags; 57 | } 58 | 59 | public boolean isFetchChangeRequests() { 60 | return fetchChangeRequests; 61 | } 62 | 63 | public Set getCheckoutStrategies() { 64 | return checkoutStrategies; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/trait/RegexSCMHeadFilterTraitTest.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.util.Map; 28 | import java.util.Set; 29 | import java.util.TreeSet; 30 | import jenkins.scm.api.SCMHead; 31 | import jenkins.scm.api.SCMHeadObserver; 32 | import jenkins.scm.api.SCMRevision; 33 | import jenkins.scm.impl.mock.MockSCMController; 34 | import jenkins.scm.impl.mock.MockSCMDiscoverBranches; 35 | import jenkins.scm.impl.mock.MockSCMSource; 36 | import org.junit.ClassRule; 37 | import org.junit.Test; 38 | import org.jvnet.hudson.test.JenkinsRule; 39 | 40 | import static org.hamcrest.MatcherAssert.assertThat; 41 | import static org.hamcrest.Matchers.containsInAnyOrder; 42 | 43 | public class RegexSCMHeadFilterTraitTest { 44 | @ClassRule 45 | public static JenkinsRule r = new JenkinsRule(); 46 | 47 | @Test 48 | public void given_sourceWithRegexRule_when_scanning_then_ruleApplied() throws Exception { 49 | try (MockSCMController c = MockSCMController.create()) { 50 | c.createRepository("foo"); 51 | c.createBranch("foo", "fork"); 52 | c.createBranch("foo", "alt"); 53 | MockSCMSource src = new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(), new RegexSCMHeadFilterTrait("[fm].*")); 54 | Map result = src.fetch(null, SCMHeadObserver.collect(), null, null).result(); 55 | Set names = new TreeSet<>(); 56 | for (SCMHead h: result.keySet()) { 57 | names.add(h.getName()); 58 | } 59 | assertThat(names, containsInAnyOrder("master", "fork")); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/UncategorizedSCMHeadCategoryTest.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 jenkins.scm.impl.mock.MockChangeRequestSCMHead; 29 | import jenkins.scm.impl.mock.MockSCMHead; 30 | import jenkins.scm.impl.mock.MockTagSCMHead; 31 | import org.junit.experimental.theories.DataPoint; 32 | import org.junit.experimental.theories.Theories; 33 | import org.junit.experimental.theories.Theory; 34 | import org.junit.runner.RunWith; 35 | 36 | import static org.hamcrest.MatcherAssert.assertThat; 37 | import static org.hamcrest.Matchers.is; 38 | 39 | @RunWith(Theories.class) 40 | public class UncategorizedSCMHeadCategoryTest { 41 | 42 | @DataPoint 43 | public static UncategorizedSCMHeadCategory defInstance = UncategorizedSCMHeadCategory.DEFAULT; 44 | 45 | @DataPoint 46 | public static UncategorizedSCMHeadCategory custInstance = new UncategorizedSCMHeadCategory(Messages._UncategorizedSCMHeadCategory_DisplayName()); 47 | 48 | @Theory 49 | public void given_tagHead_when_isMatch_then_confirmMatch(UncategorizedSCMHeadCategory instance) throws Exception { 50 | assertThat(instance.isMatch(new MockTagSCMHead("1.0", 0L)), is(true)); 51 | } 52 | 53 | @Theory 54 | public void given_regularHead_when_isMatch_then_confirmMatch(UncategorizedSCMHeadCategory instance) throws Exception { 55 | assertThat(instance.isMatch(new MockSCMHead("master")), is(true)); 56 | } 57 | 58 | @Theory 59 | public void given_changeRequestHead_when_isMatch_then_confirmMatch(UncategorizedSCMHeadCategory instance) throws Exception { 60 | assertThat(instance.isMatch(new MockChangeRequestSCMHead(1, "master")), is(true)); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/NullSCMSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011-2013, CloudBees, Inc., Stephen Connolly. 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 | package jenkins.scm.impl; 25 | 26 | import edu.umd.cs.findbugs.annotations.CheckForNull; 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import hudson.model.TaskListener; 29 | import hudson.scm.NullSCM; 30 | import hudson.scm.SCM; 31 | import java.io.IOException; 32 | import jenkins.scm.api.SCMHead; 33 | import jenkins.scm.api.SCMHeadEvent; 34 | import jenkins.scm.api.SCMHeadObserver; 35 | import jenkins.scm.api.SCMRevision; 36 | import jenkins.scm.api.SCMSource; 37 | import jenkins.scm.api.SCMSourceCriteria; 38 | 39 | /** 40 | * A special {@link SCMSource} that does not fetch any {@link SCMHead} instances and will build instances of 41 | * {@link NullSCM}. 42 | */ 43 | public class NullSCMSource extends SCMSource { 44 | /** 45 | * The "magic" id of the {@link NullSCMSource}. 46 | */ 47 | public static final String ID = "::" + NullSCMSource.class.getSimpleName() + "::"; 48 | 49 | /** 50 | * Constructor. 51 | */ 52 | public NullSCMSource() { 53 | super(); 54 | setId(ID); 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer, 62 | @CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) 63 | throws IOException, InterruptedException { 64 | 65 | } 66 | 67 | /** 68 | * {@inheritDoc} 69 | */ 70 | @NonNull 71 | @Override 72 | public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { 73 | return new NullSCM(); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/mixin/TagSCMHead.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.api.mixin; 27 | 28 | import jenkins.scm.api.SCMHead; 29 | import jenkins.scm.api.SCMSource; 30 | 31 | /** 32 | * Mixin interface to identify {@link SCMHead} instances that correspond to a semi-immutable tag. 33 | * Tags cannot be changed once created, but it may be possible to delete a tag and recreate a new tag with the same 34 | * name as a previous tag. 35 | * 36 | * @since 2.0 37 | */ 38 | public interface TagSCMHead { 39 | /** 40 | * Returns the timestamp of the tag. The timestamp is important because when iterating a newly 41 | * configured {@link SCMSource} the consumer may not want to process old tags and instead may prefer to process 42 | * tags created after some specific date. 43 | *

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 contextClass) { 65 | return MockSCMSourceContext.class.isAssignableFrom(contextClass); 66 | } 67 | 68 | @Override 69 | public boolean isApplicableToBuilder(@NonNull Class 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 contextClass) { 66 | return MockSCMSourceContext.class.isAssignableFrom(contextClass); 67 | } 68 | 69 | @Override 70 | public boolean isApplicableToBuilder(@NonNull Class 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 { 35 | 36 | private final MockSCMController controller; 37 | 38 | private final String repository; 39 | 40 | @Deprecated 41 | public MockSCMSourceEvent(@NonNull Type type, MockSCMController controller, 42 | String repository) { 43 | super(type, repository); 44 | this.controller = controller; 45 | this.repository = repository; 46 | } 47 | 48 | public MockSCMSourceEvent(@CheckForNull String origin, @NonNull Type type, MockSCMController controller, 49 | String repository) { 50 | super(type, repository, origin); 51 | this.controller = controller; 52 | this.repository = repository; 53 | } 54 | 55 | @Override 56 | public boolean isMatch(@NonNull SCMNavigator navigator) { 57 | return navigator instanceof MockSCMNavigator 58 | && ((MockSCMNavigator) navigator).getControllerId().equals(controller.getId()); 59 | } 60 | 61 | @Override 62 | public boolean isMatch(@NonNull SCMSource source) { 63 | return source instanceof MockSCMSource 64 | && ((MockSCMSource) source).getControllerId().equals(controller.getId()) 65 | && repository.equals(((MockSCMSource) source).getRepository()); 66 | } 67 | 68 | @NonNull 69 | @Override 70 | public String getSourceName() { 71 | return repository; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/actions/ChangeRequestAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 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 | package jenkins.scm.api.actions; 26 | 27 | import edu.umd.cs.findbugs.annotations.CheckForNull; 28 | import hudson.model.InvisibleAction; 29 | import java.io.Serializable; 30 | import java.net.URL; 31 | import jenkins.scm.api.SCMHead; 32 | import jenkins.scm.api.metadata.ContributorMetadataAction; 33 | import jenkins.scm.api.metadata.ObjectMetadataAction; 34 | import jenkins.scm.api.mixin.ChangeRequestSCMHead; 35 | import org.kohsuke.accmod.Restricted; 36 | import org.kohsuke.accmod.restrictions.DoNotUse; 37 | 38 | /** 39 | * Class retained for on-disk compatibility only for instances upgrading and deserializing data from disk. 40 | * @since 1.1 41 | * @deprecated use {@link ContributorMetadataAction} for the author information, {@link ObjectMetadataAction} for the 42 | * title and links and {@link ChangeRequestSCMHead#getId()} and 43 | * {@link ChangeRequestSCMHead#getTarget()} 44 | */ 45 | @Restricted(DoNotUse.class) 46 | @Deprecated 47 | public abstract class ChangeRequestAction extends InvisibleAction implements Serializable { 48 | 49 | private static final long serialVersionUID = 1L; 50 | 51 | @CheckForNull 52 | public String getId() { 53 | return null; 54 | } 55 | 56 | @CheckForNull 57 | public URL getURL() { 58 | return null; 59 | } 60 | 61 | @CheckForNull 62 | public String getTitle() { 63 | return null; 64 | } 65 | 66 | @CheckForNull 67 | public String getAuthor() { 68 | return null; 69 | } 70 | 71 | @CheckForNull 72 | public String getAuthorDisplayName() { 73 | return null; 74 | } 75 | 76 | @CheckForNull 77 | public String getAuthorEmail() { 78 | return null; 79 | } 80 | 81 | @CheckForNull 82 | public SCMHead getTarget() { 83 | return null; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/resources/jenkins/scm/impl/SingleSCMSource/config-detail.jelly: -------------------------------------------------------------------------------- 1 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/ChangeRequestSCMHeadCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 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 | package jenkins.scm.impl; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 29 | import jenkins.scm.api.mixin.ChangeRequestSCMHead; 30 | import jenkins.scm.api.SCMHead; 31 | import jenkins.scm.api.SCMHeadCategory; 32 | import jenkins.scm.api.SCMSource; 33 | import org.jvnet.localizer.Localizable; 34 | 35 | /** 36 | * Standard category for {@link SCMHead} instances that implement {@link ChangeRequestSCMHead}. 37 | * 38 | * @since 2.0 39 | */ 40 | public final class ChangeRequestSCMHeadCategory extends SCMHeadCategory { 41 | /** 42 | * The {@link ChangeRequestSCMHeadCategory} singleton with the default naming. 43 | */ 44 | public static final ChangeRequestSCMHeadCategory DEFAULT = new ChangeRequestSCMHeadCategory(); 45 | 46 | /** 47 | * Constructs a {@link ChangeRequestSCMHeadCategory} using the default naming. 48 | */ 49 | private ChangeRequestSCMHeadCategory() { 50 | super("change-requests", Messages._ChangeRequestSCMHeadCategory_DisplayName()); 51 | } 52 | 53 | /** 54 | * Constructs a {@link ChangeRequestSCMHeadCategory} with customized naming. Use this constructor when the generic 55 | * naming is not appropriate terminology for the specific {@link SCMSource}'s naming of change requests. 56 | * 57 | * @param displayName the display name for change requests. 58 | */ 59 | @SuppressFBWarnings("NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION") 60 | public ChangeRequestSCMHeadCategory(@NonNull Localizable displayName) { 61 | super("change-requests", displayName); 62 | } 63 | 64 | /** 65 | * {@inheritDoc} 66 | */ 67 | @Override 68 | public boolean isMatch(@NonNull SCMHead instance) { 69 | return instance instanceof ChangeRequestSCMHead; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/SCMProbe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2016, CloudBees, Inc., Stephen Connolly. 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 | package jenkins.scm.api; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | import hudson.model.TaskListener; 28 | import java.io.Closeable; 29 | import java.io.IOException; 30 | 31 | /** 32 | * An unmanaged {@link SCMSourceCriteria.Probe} that has its lifecycle managed outside of 33 | * {@link SCMSource#fetch(TaskListener)}. A {@link SCMProbe} is used to check and recheck {@link SCMSourceCriteria} 34 | * so implementations are strongly recommended to provide caching of results from {@link #stat(String)} and 35 | * {@link #lastModified()}. 36 | * 37 | * @since 2.0 38 | */ 39 | public abstract class SCMProbe extends SCMSourceCriteria.Probe implements Closeable { 40 | /** 41 | * Checks if the path, relative to the head candidate root, exists or not. The results of this method should 42 | * be cached where possible but can involve a remote network call. 43 | * 44 | * @param path the path. 45 | * @return {@code true} iff the path exists (may be a file or a directory or a symlink or whatever). 46 | * @throws IOException if a remote network call failed and the result is therefore indeterminate. 47 | * @deprecated use {@link #stat(String)} 48 | */ 49 | @Deprecated 50 | public final boolean exists(@NonNull String path) throws IOException { 51 | return stat(path).exists(); 52 | } 53 | 54 | /** 55 | * Checks if the path, relative to the head candidate root, exists or not. The results of this method should 56 | * be cached where possible but can involve a remote network call. 57 | * 58 | * @param path the path. 59 | * @return The results of the check. 60 | * @throws IOException if a remote network call failed and the result is therefore indeterminate. 61 | */ 62 | @NonNull 63 | public abstract SCMProbeStat stat(@NonNull String path) throws IOException; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/mixin/ChangeRequestSCMHead2.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.mixin; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import jenkins.scm.api.SCMHead; 29 | import jenkins.scm.api.SCMSource; 30 | 31 | /** 32 | * Additional attributes of a {@link ChangeRequestSCMHead} that should have been in the original mixin but we are not 33 | * targeting Java 8 so we cannot add the default methods to the interface and must have an ugly {@code 2} class instead. 34 | * @since 2.2.0 35 | */ 36 | // TODO once Java 8 is baseline move method to ChangeRequestSCMHead with default return value, 37 | // TODO deprecate this interface and add @Restricted(NoExternalUse.class) (retain empty interface for binary compat) 38 | public interface ChangeRequestSCMHead2 extends ChangeRequestSCMHead { 39 | /** 40 | * Returns the {@link ChangeRequestCheckoutStrategy} of this {@link ChangeRequestSCMHead}. 41 | * 42 | * @return the {@link ChangeRequestCheckoutStrategy}. 43 | */ 44 | @NonNull 45 | ChangeRequestCheckoutStrategy getCheckoutStrategy(); 46 | 47 | /** 48 | * Returns the name of the actual head on the source control system which may or may not be different from 49 | * {@link #getName()}. For example in GitHub or Bitbucket this method would return the name of the origin branch 50 | * whereas {@link #getName()} would return something like {@code PR-24}. It is perfectly acceptable for a SCM 51 | * implementation to return the same value as {@link #getName()} where the SCM implementation does not have a 52 | * separate concept of origin name. 53 | * 54 | * @return the name this {@link ChangeRequestSCMHead} would have if the {@link SCMSource} were configured 55 | * against the {@link #getOrigin()} directly and the change request were be discoverable as a regular 56 | * {@link SCMHead} or {@link #getName()} if such a concept is not possible in the backing source control system. 57 | */ 58 | @NonNull 59 | String getOriginName(); 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/NullSCMSourceTest.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 hudson.scm.NullSCM; 29 | import jenkins.scm.api.SCMHead; 30 | import jenkins.scm.api.SCMHeadObserver; 31 | import jenkins.scm.api.SCMRevision; 32 | import org.junit.ClassRule; 33 | import org.junit.Test; 34 | import org.jvnet.hudson.test.JenkinsRule; 35 | 36 | import static org.hamcrest.MatcherAssert.assertThat; 37 | import static org.hamcrest.Matchers.allOf; 38 | import static org.hamcrest.Matchers.hasProperty; 39 | import static org.hamcrest.Matchers.instanceOf; 40 | import static org.hamcrest.Matchers.is; 41 | import static org.mockito.Mockito.mock; 42 | import static org.mockito.Mockito.never; 43 | import static org.mockito.Mockito.verify; 44 | import static org.mockito.hamcrest.MockitoHamcrest.argThat; 45 | 46 | public class NullSCMSourceTest { 47 | 48 | @ClassRule 49 | public static JenkinsRule r = new JenkinsRule(); 50 | 51 | @Test 52 | public void given_instance_when_fetch_then_noRevisionObserved() throws Exception { 53 | SCMHeadObserver observer = mock(SCMHeadObserver.class); 54 | NullSCMSource instance = new NullSCMSource(); 55 | instance.fetch(null, observer, null); 56 | verify(observer, never()).observe( 57 | argThat( 58 | allOf( 59 | instanceOf(SCMHead.class), 60 | hasProperty("name", is("the-name")) 61 | ) 62 | ), 63 | argThat( 64 | allOf( 65 | instanceOf(SCMRevision.class), 66 | hasProperty("head", hasProperty("name", is("the-name"))), 67 | hasProperty("deterministic", is(false)) 68 | ) 69 | ) 70 | ); 71 | } 72 | 73 | @Test 74 | public void given_instance_when_fetchingNonObservedHead_then_nullScmReturned() throws Exception { 75 | NullSCMSource instance = new NullSCMSource(); 76 | assertThat(instance.build(new SCMHead("foo"), mock(SCMRevision.class)), instanceOf(NullSCM.class)); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/api/SCMNameTest.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; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.hamcrest.MatcherAssert.assertThat; 30 | import static org.hamcrest.Matchers.is; 31 | import static org.hamcrest.Matchers.nullValue; 32 | 33 | public class SCMNameTest { 34 | @Test 35 | public void given__url_without_hostname__when__naming__then__no_name_inferred() throws Exception { 36 | assertThat(SCMName.fromUrl("file:///some/random/file"), is(nullValue())); 37 | } 38 | 39 | @Test 40 | public void given__url_with_hostname__when__naming__then__public_tld_removed() throws Exception { 41 | assertThat(SCMName.fromUrl("http://scm.example.com"), is("scm example")); 42 | } 43 | 44 | @Test 45 | public void given__url_with_hostname__when__naming__then__public_sld_removed() throws Exception { 46 | assertThat(SCMName.fromUrl("http://scm.example.co.uk"), is("scm example")); 47 | } 48 | 49 | @Test 50 | public void given__url_with_hostname__when__naming__then__prefix_is_removed() throws Exception { 51 | assertThat(SCMName.fromUrl("http://scm.example.ie", "scm"), is("example")); 52 | } 53 | 54 | @Test 55 | public void given__url_with_punycode__when__naming__then__hostname_is_decoded() throws Exception { 56 | assertThat(SCMName.fromUrl("http://xn--e1afmkfd.xn--p1ai/"), 57 | is("\u043F\u0440\u0438\u043C\u0435\u0440" /*пример*/)); 58 | } 59 | 60 | @Test 61 | public void given__url_with_idn__when__naming__then__punycode_is_roundtripped() throws Exception { 62 | assertThat(SCMName.fromUrl("http://\u043F\u0440\u0438\u043C\u0435\u0440.\u0440\u0444" /*пример.рф*/), 63 | is("\u043F\u0440\u0438\u043C\u0435\u0440" /*пример*/)); 64 | } 65 | 66 | @Test 67 | public void given__url_with_idn__when__naming__then__punycode_is_roundtripped2() throws Exception { 68 | assertThat(SCMName.fromUrl("http://\u4F8B\u5B50.\u4E2D\u56FD/"), is("\u4F8B\u5B50")); 69 | } 70 | 71 | @Test 72 | public void given__url_with_ipv4address__when__naming__then__no_name_inferred() throws Exception { 73 | assertThat(SCMName.fromUrl("http://127.0.0.1/scm"), is(nullValue())); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockChangeRequestSCMHead.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 | package jenkins.scm.impl.mock; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import java.util.Locale; 29 | import jenkins.scm.api.SCMHeadOrigin; 30 | import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; 31 | import jenkins.scm.api.SCMHead; 32 | import jenkins.scm.api.mixin.ChangeRequestSCMHead2; 33 | 34 | public class MockChangeRequestSCMHead extends SCMHead implements ChangeRequestSCMHead2 { 35 | private final String target; 36 | private final Integer number; 37 | private final SCMHeadOrigin origin; 38 | private final ChangeRequestCheckoutStrategy strategy; 39 | 40 | public MockChangeRequestSCMHead(SCMHeadOrigin origin, Integer number, String target, 41 | ChangeRequestCheckoutStrategy strategy, boolean singleStrategy) { 42 | super("CR-"+number + (singleStrategy ? "" : "-"+strategy.name().toLowerCase(Locale.ENGLISH))); 43 | this.number = number; 44 | this.target = target; 45 | this.origin = origin; 46 | this.strategy = strategy; 47 | } 48 | 49 | public MockChangeRequestSCMHead(Integer number, String target) { 50 | this(null, number, target, ChangeRequestCheckoutStrategy.HEAD, true); 51 | } 52 | 53 | @NonNull 54 | @Override 55 | public String getId() { 56 | return number.toString(); 57 | } 58 | 59 | @NonNull 60 | @Override 61 | public SCMHead getTarget() { 62 | return new MockSCMHead(target); 63 | } 64 | 65 | public Integer getNumber() { 66 | return number; 67 | } 68 | 69 | @NonNull 70 | @Override 71 | public SCMHeadOrigin getOrigin() { 72 | return origin == null ? SCMHeadOrigin.DEFAULT : origin; 73 | } 74 | 75 | @NonNull 76 | @Override 77 | public ChangeRequestCheckoutStrategy getCheckoutStrategy() { 78 | return strategy; 79 | } 80 | 81 | @NonNull 82 | @Override 83 | public String getOriginName() { 84 | // MockSCMController maintains a separate list of change-requests independent from the branches 85 | // so unlike GitHub or Bitbucket, the name of a change request in the origin is the name. 86 | return getName(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/SingleSCMNavigator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2015-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 | package jenkins.scm.impl; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import hudson.Util; 29 | import hudson.model.Items; 30 | import jenkins.scm.api.SCMNavigator; 31 | import jenkins.scm.api.SCMNavigatorDescriptor; 32 | import hudson.Extension; 33 | import java.io.IOException; 34 | import java.util.List; 35 | import jenkins.scm.api.SCMSource; 36 | import jenkins.scm.api.SCMSourceObserver; 37 | import org.jenkinsci.Symbol; 38 | import org.kohsuke.accmod.Restricted; 39 | import org.kohsuke.accmod.restrictions.NoExternalUse; 40 | import org.kohsuke.stapler.DataBoundConstructor; 41 | 42 | /** 43 | * Degenerate navigator which only ever returns a single repository. 44 | */ 45 | @Restricted(NoExternalUse.class) 46 | public class SingleSCMNavigator extends SCMNavigator { 47 | 48 | private final String name; 49 | private final List sources; 50 | 51 | @DataBoundConstructor 52 | public SingleSCMNavigator(String name, List sources) { 53 | this.name = name; 54 | this.sources = sources; 55 | } 56 | 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | public List getSources() { 62 | return sources; 63 | } 64 | 65 | @NonNull 66 | @Override 67 | protected String id() { 68 | return Util.getDigestOf(Items.XSTREAM.toXML(sources) 69 | .replaceAll(" plugin=(('[^']+@[^']+')|(\"[^\"]+@[^\"]+\"))", "")) + "::" + name; 70 | } 71 | 72 | @Override 73 | public void visitSources(@NonNull SCMSourceObserver observer) throws IOException, InterruptedException { 74 | SCMSourceObserver.ProjectObserver projectObserver = observer.observe(name); 75 | for (SCMSource source : sources) { 76 | projectObserver.addSource(source); 77 | } 78 | projectObserver.complete(); 79 | } 80 | 81 | @Symbol("fromSource") 82 | @Extension 83 | public static class DescriptorImpl extends SCMNavigatorDescriptor { 84 | 85 | @NonNull 86 | @Override 87 | public String getDisplayName() { 88 | return Messages.SingleSCMNavigator_DisplayName(); 89 | } 90 | 91 | @Override 92 | public SCMNavigator newInstance(String name) { 93 | return null; 94 | } 95 | 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/api/SCMRevision.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2011-2013, CloudBees, Inc., Stephen Connolly. 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 | package jenkins.scm.api; 25 | 26 | import edu.umd.cs.findbugs.annotations.NonNull; 27 | 28 | import java.io.Serializable; 29 | import java.util.Objects; 30 | import org.kohsuke.stapler.export.Exported; 31 | import org.kohsuke.stapler.export.ExportedBean; 32 | 33 | /** 34 | * Base class that represents a specific (or not so specific) revision of a {@link SCMHead}. 35 | */ 36 | @ExportedBean 37 | public abstract class SCMRevision implements Serializable { 38 | 39 | /** 40 | * The {@link SCMHead} that this revision belongs to. 41 | */ 42 | @NonNull 43 | private final SCMHead head; 44 | 45 | /** 46 | * Constructor. 47 | * 48 | * @param head the {@link SCMHead} that the {@link SCMRevision} belongs to. 49 | */ 50 | protected SCMRevision(@NonNull SCMHead head) { 51 | Objects.requireNonNull(head); 52 | this.head = head; 53 | } 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public abstract boolean equals(Object obj); // force implementers to implement. 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | @Override 65 | public abstract int hashCode(); // force implementers to implement. 66 | 67 | /** 68 | * Should provide a concise, human-readable summary of this revision in an implementation-dependent format. 69 | *

{@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> extends Descriptor { 38 | 39 | // Constructors are package private in order to restrict trait specializations to the ones defined in this plugin 40 | 41 | /** 42 | * Constructor to use when type inference using {@link #SCMTraitDescriptor()} does not work. 43 | * 44 | * @param clazz Pass in the type of {@link SCMTrait} 45 | */ 46 | /*package*/ SCMTraitDescriptor(@NonNull Class clazz) { 47 | super(clazz); 48 | } 49 | 50 | /** 51 | * Infers the type of the corresponding {@link SCMTrait} from the outer class. 52 | * This version works when you follow the common convention, where a descriptor 53 | * is written as the static nested class of the describable class. 54 | */ 55 | /*package*/ SCMTraitDescriptor() { 56 | super(); 57 | } 58 | 59 | /** 60 | * Returns the type of {@link SCM} that this {@link SCMTrait} is applicable to. 61 | * 62 | * @return the type of {@link SCM} that this {@link SCMTrait} is applicable to. 63 | */ 64 | public Class getScmClass() { 65 | return SCM.class; 66 | } 67 | 68 | /** 69 | * Checks if the {@link SCMTrait} is relevant to the specified type of {@link SCM}. 70 | * 71 | * @param scmClass the type of {@link SCM}. 72 | * @return {@code true} if applicable to the specified type of {@link SCM}. 73 | */ 74 | public boolean isApplicableToSCM(@NonNull Class scmClass) { 75 | return getScmClass().isAssignableFrom(scmClass); 76 | } 77 | 78 | /** 79 | * Checks if the {@link SCMTrait} is relevant to the specified {@link SCM}. 80 | * 81 | * @param scm the {@link SCMDescriptor} for the type of {@link SCM}. 82 | * @return {@code true} if applicable to the specified type of {@link SCM}. 83 | */ 84 | public boolean isApplicableToSCM(@NonNull SCMDescriptor scm) { 85 | return isApplicableToSCM(scm.clazz); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/MockSCMSourceContext.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.CheckForNull; 28 | import edu.umd.cs.findbugs.annotations.NonNull; 29 | import hudson.model.TaskListener; 30 | import java.util.EnumSet; 31 | import java.util.Set; 32 | import jenkins.scm.api.SCMHeadObserver; 33 | import jenkins.scm.api.SCMSource; 34 | import jenkins.scm.api.SCMSourceCriteria; 35 | import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy; 36 | import jenkins.scm.api.trait.SCMSourceContext; 37 | 38 | public class MockSCMSourceContext extends SCMSourceContext { 39 | 40 | private boolean needsBranches; 41 | private boolean needsTags; 42 | private boolean needsChangeRequests; 43 | private Set checkoutStrategies = EnumSet.noneOf(ChangeRequestCheckoutStrategy.class); 44 | 45 | public MockSCMSourceContext(MockSCMSource source, SCMSourceCriteria criteria, SCMHeadObserver observer) { 46 | super(criteria, observer); 47 | } 48 | 49 | public MockSCMSourceContext withBranches(boolean included) { 50 | needsBranches = needsBranches || included; 51 | return this; 52 | } 53 | 54 | public MockSCMSourceContext withTags(boolean included) { 55 | needsTags = needsTags || included; 56 | return this; 57 | } 58 | 59 | public MockSCMSourceContext withChangeRequests(boolean included) { 60 | needsChangeRequests = needsChangeRequests || included; 61 | return this; 62 | } 63 | 64 | public boolean needsBranches() { 65 | return needsBranches; 66 | } 67 | 68 | public boolean needsTags() { 69 | return needsTags; 70 | } 71 | 72 | public boolean needsChangeRequests() { 73 | return needsChangeRequests; 74 | } 75 | 76 | public Set checkoutStrategies() { 77 | return checkoutStrategies; 78 | } 79 | 80 | public MockSCMSourceContext withCheckoutStrategies(Set checkoutStrategies) { 81 | this.checkoutStrategies.addAll(checkoutStrategies); 82 | return this; 83 | } 84 | 85 | @NonNull 86 | @Override 87 | public MockSCMSourceRequest newRequest(@NonNull SCMSource source, @CheckForNull TaskListener listener) { 88 | return new MockSCMSourceRequest(source, this, listener); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/UncategorizedSCMHeadCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 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 | package jenkins.scm.impl; 26 | 27 | import edu.umd.cs.findbugs.annotations.NonNull; 28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 29 | import jenkins.scm.api.SCMHead; 30 | import jenkins.scm.api.SCMHeadCategory; 31 | import jenkins.scm.api.SCMSource; 32 | import org.jvnet.localizer.Localizable; 33 | 34 | /** 35 | * Standard category for uncategorized instances. 36 | * 37 | * @since 2.0 38 | */ 39 | public final class UncategorizedSCMHeadCategory extends SCMHeadCategory { 40 | /** 41 | * The {@link UncategorizedSCMHeadCategory} singleton with the default naming. 42 | */ 43 | public static final UncategorizedSCMHeadCategory DEFAULT = new UncategorizedSCMHeadCategory(); 44 | 45 | /** 46 | * Constructs a {@link UncategorizedSCMHeadCategory} using the default naming. 47 | */ 48 | private UncategorizedSCMHeadCategory() { 49 | super(Messages._UncategorizedSCMHeadCategory_DisplayName()); 50 | } 51 | 52 | /** 53 | * Constructs a {@link UncategorizedSCMHeadCategory} with customized naming. Use this constructor when the generic 54 | * naming is not appropriate terminology for the specific {@link SCMSource}'s naming of branches. 55 | *

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 args = new ArrayList<>(); 85 | args.add(tool); 86 | args.addAll(Arrays.asList(cmds)); 87 | run(false, sampleRepo, args.toArray(new String[0])); 88 | } 89 | 90 | /** 91 | * Like {@link #fileUrl} but expressed only as a path, not a URL with protocol. 92 | */ 93 | public final String bareUrl() throws UnsupportedEncodingException { 94 | return URLEncoder.encode(toString(), StandardCharsets.UTF_8); 95 | } 96 | 97 | /** 98 | * {@code file}-protocol URL to {@link #sampleRepo}. 99 | */ 100 | public final String fileUrl() { 101 | return sampleRepo.toURI().toString(); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/test/java/jenkins/scm/impl/mock/AbstractSampleRepoRule.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 hudson.Launcher; 28 | import hudson.model.TaskListener; 29 | import hudson.triggers.SCMTrigger; 30 | import hudson.util.StreamTaskListener; 31 | import java.io.File; 32 | import java.util.Arrays; 33 | 34 | import static org.hamcrest.MatcherAssert.assertThat; 35 | import static org.hamcrest.Matchers.is; 36 | import org.junit.Assume; 37 | import org.junit.AssumptionViolatedException; 38 | import org.junit.Rule; 39 | import org.junit.rules.ExternalResource; 40 | import org.junit.rules.TemporaryFolder; 41 | import org.jvnet.hudson.test.JenkinsRule; 42 | 43 | /** 44 | * Basis for {@link Rule} classes which run a concrete SCM tool on a sample repository, for integration testing. 45 | * 46 | * @since 2.0.8 47 | */ 48 | public abstract class AbstractSampleRepoRule extends ExternalResource { 49 | 50 | /** 51 | * Run a given command. 52 | * @param probing if true, throw {@link AssumptionViolatedException} rather than {@link AssertionError} in case of problems 53 | * @param cwd working directory to use 54 | * @param cmds command and arguments to run 55 | */ 56 | public static void run(boolean probing, File cwd, String... cmds) throws Exception { 57 | try { 58 | TaskListener listener = StreamTaskListener.fromStdout(); 59 | int r = new Launcher.LocalLauncher(listener).launch().cmds(cmds).pwd(cwd).stdout(listener).join(); 60 | String message = Arrays.toString(cmds) + " failed with error code"; 61 | if (probing) { 62 | Assume.assumeThat(message, r, is(0)); 63 | } else { 64 | assertThat(message, r, is(0)); 65 | } 66 | } catch (Exception x) { 67 | if (probing) { 68 | Assume.assumeNoException(Arrays.toString(cmds) + " failed with exception (required tooling not installed?)", x); 69 | } else { 70 | throw x; 71 | } 72 | } 73 | } 74 | 75 | protected final TemporaryFolder tmp; 76 | 77 | protected AbstractSampleRepoRule() { 78 | this.tmp = new TemporaryFolder(); 79 | } 80 | 81 | @Override 82 | protected void before() throws Throwable { 83 | tmp.create(); 84 | } 85 | 86 | @Override 87 | protected void after() { 88 | tmp.delete(); 89 | } 90 | 91 | /** Otherwise {@link JenkinsRule#waitUntilNoActivity()} is ineffective when we have just pinged a commit notification endpoint. */ 92 | protected final void synchronousPolling(JenkinsRule r) { 93 | r.jenkins.getDescriptorByType(SCMTrigger.DescriptorImpl.class).synchronousPolling = true; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/jenkins/scm/impl/SCMTriggerListener.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 hudson.Extension; 29 | import hudson.model.Action; 30 | import hudson.model.Cause; 31 | import hudson.model.CauseAction; 32 | import hudson.model.Item; 33 | import hudson.scm.SCM; 34 | import hudson.triggers.SCMTrigger; 35 | import java.util.logging.Level; 36 | import java.util.logging.Logger; 37 | import jenkins.model.Jenkins; 38 | import jenkins.scm.api.SCMEventListener; 39 | import jenkins.scm.api.SCMHeadEvent; 40 | import jenkins.triggers.SCMTriggerItem; 41 | 42 | /** 43 | * A {@link SCMEventListener} that will trigger the post commit hooks enabled by {@link SCMTrigger} for any 44 | * {@link SCMHeadEvent} which return a positive match against a {@link SCM} through {@link SCMHeadEvent#isMatch(SCM)}. 45 | * 46 | * @since 2.0 47 | */ 48 | @Extension 49 | public class SCMTriggerListener extends SCMEventListener { 50 | /** 51 | * Our logger 52 | */ 53 | private static final Logger LOGGER = Logger.getLogger(SCMTriggerListener.class.getName()); 54 | 55 | /** 56 | * {@inheritDoc} 57 | */ 58 | @Override 59 | public void onSCMHeadEvent(SCMHeadEvent event) { 60 | switch (event.getType()) { 61 | case CREATED: 62 | case UPDATED: 63 | // only trigger polling for create/update 64 | for (Item project : Jenkins.get().allItems()) { 65 | SCMTriggerItem scmTriggerItem = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project); 66 | if (scmTriggerItem == null) { 67 | // if it is not a SCMTriggerItem => ignore it 68 | continue; 69 | } 70 | SCMTrigger trigger = scmTriggerItem.getSCMTrigger(); 71 | if (trigger == null || trigger.isIgnorePostCommitHooks()) { 72 | // if it is not enabled for triggering => ignore it 73 | continue; 74 | } 75 | for (SCM scm : scmTriggerItem.getSCMs()) { 76 | if (event.isMatch(scm)) { 77 | // only interested in SCMs that match the event 78 | LOGGER.log(Level.INFO, "Triggering polling of {0}", project.getFullName()); 79 | Cause[] causes = event.asCauses(); 80 | trigger.run(causes.length == 0 ? null : new Action[]{new CauseAction(causes)}); 81 | break; 82 | } 83 | } 84 | } 85 | break; 86 | default: 87 | break; 88 | } 89 | } 90 | } 91 | --------------------------------------------------------------------------------