├── .editorconfig ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ └── github-actions.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE.txt ├── README.md ├── RELEASE_NOTES.md ├── build.gradle ├── gradle.properties ├── gradle ├── additional-artifacts.gradle ├── dependencies.gradle ├── publishing.gradle ├── release.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── docker │ ├── Dockerfile │ ├── README.md │ ├── init.groovy.d │ │ └── Security.groovy │ └── plugins.yml └── java │ └── com │ └── cdancy │ └── jenkins │ └── rest │ ├── JenkinsApi.java │ ├── JenkinsApiMetadata.java │ ├── JenkinsAuthentication.java │ ├── JenkinsClient.java │ ├── JenkinsConstants.java │ ├── JenkinsUtils.java │ ├── auth │ └── AuthenticationType.java │ ├── binders │ └── BindMapToForm.java │ ├── config │ ├── JenkinsAuthenticationModule.java │ ├── JenkinsAuthenticationProvider.java │ └── JenkinsHttpApiModule.java │ ├── domain │ ├── common │ │ ├── Error.java │ │ ├── ErrorsHolder.java │ │ ├── LongResponse.java │ │ ├── RequestStatus.java │ │ └── Value.java │ ├── crumb │ │ └── Crumb.java │ ├── job │ │ ├── Action.java │ │ ├── Artifact.java │ │ ├── BuildInfo.java │ │ ├── Cause.java │ │ ├── ChangeSet.java │ │ ├── ChangeSetList.java │ │ ├── Culprit.java │ │ ├── Job.java │ │ ├── JobInfo.java │ │ ├── JobList.java │ │ ├── Parameter.java │ │ ├── PipelineNode.java │ │ ├── PipelineNodeLog.java │ │ ├── ProgressiveText.java │ │ ├── Stage.java │ │ ├── StageFlowNode.java │ │ └── Workflow.java │ ├── plugins │ │ ├── Plugin.java │ │ └── Plugins.java │ ├── queue │ │ ├── Executable.java │ │ ├── QueueItem.java │ │ └── Task.java │ ├── statistics │ │ └── OverallLoad.java │ ├── system │ │ └── SystemInfo.java │ └── user │ │ ├── ApiToken.java │ │ ├── ApiTokenData.java │ │ ├── Property.java │ │ └── User.java │ ├── exception │ ├── ForbiddenException.java │ ├── MethodNotAllowedException.java │ ├── RedirectTo404Exception.java │ ├── UndetectableIdentityException.java │ └── UnsupportedMediaTypeException.java │ ├── fallbacks │ └── JenkinsFallbacks.java │ ├── features │ ├── ConfigurationAsCodeApi.java │ ├── CrumbIssuerApi.java │ ├── JobsApi.java │ ├── PluginManagerApi.java │ ├── QueueApi.java │ ├── StatisticsApi.java │ ├── SystemApi.java │ └── UserApi.java │ ├── filters │ ├── JenkinsAuthenticationFilter.java │ ├── JenkinsNoCrumbAuthenticationFilter.java │ ├── JenkinsUserInjectionFilter.java │ └── ScrubNullFolderParam.java │ ├── handlers │ └── JenkinsErrorHandler.java │ └── parsers │ ├── BuildNumberToInteger.java │ ├── CrumbParser.java │ ├── FolderPathParser.java │ ├── LocationToQueueId.java │ ├── OptionalFolderPathParser.java │ ├── OutputToProgressiveText.java │ ├── RequestStatusParser.java │ └── SystemInfoFromJenkinsHeaders.java └── test ├── java └── com │ └── cdancy │ └── jenkins │ └── rest │ ├── BaseJenkinsApiLiveTest.java │ ├── BaseJenkinsMockTest.java │ ├── BaseJenkinsTest.java │ ├── JenkinsApiMetadataTest.java │ ├── JenkinsAuthenticationMockTest.java │ ├── TestUtilities.java │ ├── features │ ├── ConfigurationAsCodeApiLiveTest.java │ ├── ConfigurationAsCodeApiMockTest.java │ ├── CrumbIssuerApiLiveTest.java │ ├── CrumbIssuerApiMockTest.java │ ├── JobsApiLiveTest.java │ ├── JobsApiMockTest.java │ ├── PluginManagerApiLiveTest.java │ ├── PluginManagerApiMockTest.java │ ├── QueueApiLiveTest.java │ ├── QueueApiMockTest.java │ ├── StatisticsApiLiveTest.java │ ├── StatisticsApiMockTest.java │ ├── SystemApiLiveTest.java │ ├── SystemApiMockTest.java │ ├── UserApiLiveTest.java │ └── UserApiMockTest.java │ └── filters │ ├── JenkinsAuthenticationFilterLiveTest.java │ └── JenkinsAuthenticationFilterMockTest.java └── resources ├── api-token.json ├── build-consoleText.txt ├── build-info-empty-and-null-params.json ├── build-info-git-commit.json ├── build-info-no-params.json ├── build-info.json ├── build-number.txt ├── build-timestamp.txt ├── casc-bad.yml ├── casc.yml ├── computer.json ├── folder-config.xml ├── freestyle-project-empty-and-null-params.xml ├── freestyle-project-no-params.xml ├── freestyle-project-sleep-10-task.xml ├── freestyle-project-sleep-task-multiple-params.xml ├── freestyle-project-sleep-task.xml ├── freestyle-project.xml ├── job-info.json ├── jobsInJenkinsFolder.json ├── jobsInRootFolder.json ├── overall-load.json ├── pipeline-node.json ├── pipeline-with-action.xml ├── pipeline.xml ├── pipelineNodeLog.json ├── plugins.json ├── progressive-text.txt ├── queue.json ├── queueItemCancelled.json ├── queueItemEmptyParameterValue.json ├── queueItemMissingTaskUrl.json ├── queueItemMultipleParameters.json ├── queueItemNullTaskName.json ├── queueItemPending.json ├── queueItemRunning.json ├── runHistory.json ├── user.json └── workflow.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | 7 | [*.{java,groovy,gradle}] 8 | indent_style = space 9 | indent_size = 4 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | 14 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Handle line endings automatically for files detected as text 2 | # and leave all files detected as binary untouched. 3 | * text=auto 4 | 5 | # 6 | # The above will handle all files NOT found below 7 | # 8 | # These files are text and should be normalized (Convert crlf => lf) 9 | *.css text 10 | *.df text 11 | *.htm text 12 | *.html text 13 | *.java text 14 | *.js text 15 | *.json text 16 | *.jsp text 17 | *.jspf text 18 | *.properties text 19 | *.sh text 20 | *.bat text 21 | *.tld text 22 | *.txt text 23 | *.xml text 24 | *.bat text 25 | 26 | # These files are binary and should be left untouched 27 | # (binary is a macro for -text -diff) 28 | *.class binary 29 | *.dll binary 30 | *.ear binary 31 | *.gif binary 32 | *.ico binary 33 | *.jar binary 34 | *.jpg binary 35 | *.jpeg binary 36 | *.png binary 37 | *.so binary 38 | *.war binary 39 | 40 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # How to contribute 3 | 4 | ## Getting Started 5 | 6 | * Make sure you have a [GitHub account](https://github.com/signup/free) 7 | * Submit a ticket for your issue, assuming one does not already exist. 8 | * Clearly describe the issue including steps to reproduce when it is a bug. 9 | * Make sure you fill in the earliest version that you know has the issue. 10 | * Fork the repository on GitHub 11 | 12 | ## Making Changes 13 | 14 | * Create a topic branch from where you want to base your work. 15 | * This is usually the master branch. 16 | * Only target release branches if you are certain your fix must be on that 17 | branch. 18 | * To quickly create a topic branch based on master; `git checkout -b 19 | fix/master/my_contribution master`. Please avoid working directly on the 20 | `master` branch. 21 | * Make commits of logical units. 22 | * Check for unnecessary whitespace with `git diff --check` before committing. 23 | * Make sure your commit messages are in the proper format: 24 | 25 | `ISSUE-1234: terse and to the point message describing change` 26 | 27 | * Make sure you have added the necessary tests for your changes. 28 | * Run _all_ the tests to assure nothing else was accidentally broken. 29 | * Make sure you've done a squash and rebase before submitting 30 | 31 | ## Submitting Changes 32 | 33 | * Push your changes to a topic branch in your fork of the repository. 34 | * Submit a pull request. 35 | * After feedback has been given we expect responses within two weeks. After two 36 | weeks we may close the pull request if it isn't showing any activity. 37 | 38 | # Additional Resources 39 | 40 | * [General GitHub documentation](https://help.github.com/) 41 | * [GitHub pull request documentation](https://help.github.com/send-pull-requests/) 42 | * [Squash and Rebase](https://github.com/ginatrapani/todo.txt-android/wiki/Squash-All-Commits-Related-to-a-Single-Issue-into-a-Single-Commit) 43 | 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ### Expected Behavior 7 | 8 | 9 | 10 | ### Current Behavior 11 | 12 | 13 | 14 | ### Context 15 | 16 | 17 | 18 | ### Steps to Reproduce (for bugs) 19 | 20 | 21 | 22 | ### Your Environment 23 | 24 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please do not create a Pull Request without first creating an ISSUE. 2 | Any change needs to be discussed before proceeding. 3 | Failure to do so may result in the rejection of the Pull Request. 4 | 5 | Explain the **details** for making this change: What existing problem does the Pull Request solve? Why is this feature beneficial? 6 | 7 | **On adding new feautes/endpoints** 8 | 9 | No more than 1 endpoint should be coded within a Pull Request. 10 | This alone requires enough code to review and adding more than 1 WILL result in your Pull Request either being ignored or rejected outright. 11 | 12 | **On adding Mock and Integ Tests** 13 | 14 | At _least_ 2 mock tests and 2 integ tests are required prior to merging. 15 | Each pair should should test what the success and failure of added change looks like. 16 | More complicated additions will of course require more tests. 17 | 18 | **On CI testing (currently using travis)** 19 | 20 | Code will not be reviewed until CI passes. 21 | Current CI does NOT exercise `integ` tests and so each Pull Request will have to be run manually by one of the maintainers to confirm it works as expected: please be patient. 22 | 23 | **On automtatic closing of ISSUES** 24 | 25 | Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such). 26 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gradle 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "10:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: com.google.inject.extensions:guice-assistedinject 11 | versions: 12 | - 5.0.0 13 | - dependency-name: com.google.inject:guice 14 | versions: 15 | - 5.0.0 16 | -------------------------------------------------------------------------------- /.github/workflows/github-actions.yaml: -------------------------------------------------------------------------------- 1 | name: Jenkins REST CI Build 2 | run-name: ${{ github.actor }} is running Jenkins REST CI Build on GitHub Actions 🚀 3 | on: [push, pull_request_target] 4 | jobs: 5 | build: 6 | # You must use a Linux environment when using service containers or container jobs 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | java-version: [ 11, 17 ] 11 | steps: 12 | - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." 13 | - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" 14 | - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." 15 | - name: Check out repository code 16 | uses: actions/checkout@v3 17 | - uses: actions/setup-java@v3 18 | with: 19 | distribution: temurin 20 | java-version: ${{ matrix.java-version }} 21 | - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." 22 | - name: Build Jenkins LTS docker images 23 | run: docker build -t jenkins-rest/jenkins src/main/docker 24 | 25 | - name: Run Jenkins LTS docker images 26 | run: docker run -d --rm -p 8080:8080 --name jenkins-rest jenkins-rest/jenkins 27 | 28 | - name: Setup Gradle Build Action 29 | uses: gradle/gradle-build-action@v2.7.0 30 | 31 | - name: Execute Gradle build 32 | run: ./gradlew clean build mockTest integTest --stacktrace 33 | 34 | - run: echo "🍏 This job's status is ${{ job.status }}." 35 | - name: Stop docker 36 | run: docker stop jenkins-rest 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories # 2 | ###################### 3 | build 4 | bin 5 | out 6 | .gradle 7 | 8 | # OS generated files # 9 | ###################### 10 | .DS_Store 11 | 12 | # IDE generated files # 13 | ###################### 14 | .settings/ 15 | .classpath 16 | .project 17 | .README* 18 | .idea 19 | *.iml 20 | *.ipr 21 | *.iws 22 | /.nb-gradle/ -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at Chris.Dancy@pega.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | group = io.github.cdancy 2 | version = 1.0.2 3 | 4 | artifactoryURL = http://127.0.0.1:8080/artifactory 5 | artifactoryUser = admin 6 | artifactoryPassword = password 7 | 8 | snapshotRepository = libs-snapshot-local 9 | releaseRepository = libs-release-local 10 | 11 | testJenkinsRestEndpoint = http://127.0.0.1:8080 12 | testJenkinsUsernamePassword = admin:admin 13 | 14 | # Next line is optional. 15 | # Use it if you want to provide your own account with a pre-existing API Token, 16 | # instead of letting the test generate its own API Token. 17 | #testJenkinsUsernameApiToken = "admin:fixme" 18 | 19 | githubUsername=fixme 20 | githubPassword=fixme 21 | 22 | signing.keyId=fixme 23 | signing.password=fixme 24 | signing.secretKeyRingFile=fixme 25 | 26 | sonatypeUsername=fixme 27 | sonatypePassword=fixme 28 | sonatypeURL=https://s01.oss.sonatype.org 29 | -------------------------------------------------------------------------------- /gradle/additional-artifacts.gradle: -------------------------------------------------------------------------------- 1 | shadowJar { 2 | archiveClassifier = 'all' 3 | mergeServiceFiles() 4 | 5 | def foundGroup = rootProject.findProperty('group') 6 | def foundName = rootProject.name.replaceAll('-', '.') 7 | def newBasePackage = "${foundGroup}.${foundName}" 8 | 9 | relocate 'org.aopalliance', "${newBasePackage}.shaded.org.aopalliance" 10 | relocate 'org.objectweb', "${newBasePackage}.shaded.org.objectweb" 11 | relocate 'com.google', "${newBasePackage}.shaded.com.google" 12 | relocate 'net.sf', "${newBasePackage}.shaded.net.sf" 13 | relocate 'javax.inject', "${newBasePackage}.shaded.javax.inject" 14 | relocate 'org.jclouds', "${newBasePackage}.shaded.org.jclouds" 15 | relocate 'javax.inject', "${newBasePackage}.shaded.javax.inject" 16 | relocate 'javax.annotation', "${newBasePackage}.shaded.javax.annotation" 17 | relocate 'javax.ws.rs', "${newBasePackage}.shaded.javax.ws.rs" 18 | relocate 'javax.xml.bind', "${newBasePackage}.shaded.javax.xml.bind" 19 | } 20 | 21 | task sourcesJar(type: Jar) { 22 | classifier 'sources' 23 | from sourceSets.main.allSource 24 | } 25 | 26 | task docsJar(type: Jar, dependsOn: javadoc) { 27 | classifier 'javadoc' 28 | from javadoc.destinationDir 29 | } 30 | 31 | task testsJar(type: Jar) { 32 | classifier 'tests' 33 | from sourceSets.test.output 34 | } 35 | -------------------------------------------------------------------------------- /gradle/dependencies.gradle: -------------------------------------------------------------------------------- 1 | ext.depVersions = ['gradleGit': '1.6.0'] 2 | 3 | -------------------------------------------------------------------------------- /gradle/publishing.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | nexusPublishing { 5 | repositories { 6 | sonatype { 7 | nexusUrl.set(uri("$sonatypeURL/service/local/")) 8 | snapshotRepositoryUrl.set(uri("$sonatypeURL/content/repositories/snapshots/")) 9 | } 10 | } 11 | } 12 | 13 | publishing { 14 | publications { 15 | mavenJava(MavenPublication) { 16 | from components.java 17 | artifact sourcesJar 18 | artifact testsJar 19 | artifact docsJar 20 | 21 | pom.withXml { 22 | def root = asNode() 23 | root.appendNode('name', 'Jenkins Rest') 24 | root.appendNode('description', 'Java client for working with Jenkins REST API.') 25 | root.appendNode('url', 'https://github.com/cdancy/jenkins-rest') 26 | root.appendNode('inceptionYear', '2016') 27 | 28 | def scm = root.appendNode('scm') 29 | scm.appendNode('url', 'https://github.com/cdancy/jenkins-rest') 30 | scm.appendNode('connection', 'scm:https://cdancy@github.com/cdancy/jenkins-rest.git') 31 | scm.appendNode('developerConnection', 'scm:git://github.com/cdancy/jenkins-rest.git') 32 | 33 | def license = root.appendNode('licenses').appendNode('license') 34 | license.appendNode('name', 'The Apache Software License, Version 2.0') 35 | license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt') 36 | license.appendNode('distribution', 'repo') 37 | 38 | def developers = root.appendNode('developers') 39 | def cdancy = developers.appendNode('developer') 40 | cdancy.appendNode('id', 'cdancy') 41 | cdancy.appendNode('name', 'Christopher Dancy') 42 | cdancy.appendNode('email', 'christoforever@gmail.com') 43 | def martinda = developers.appendNode('developer') 44 | martinda.appendNode('id', 'martinda') 45 | martinda.appendNode('name', "Martin d'Anjou") 46 | martinda.appendNode('email', 'martin.danjou14@gmail.com') 47 | } 48 | } 49 | } 50 | } 51 | 52 | signing { 53 | sign publishing.publications.mavenJava 54 | } 55 | -------------------------------------------------------------------------------- /gradle/release.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r' 7 | } 8 | } 9 | 10 | import org.eclipse.jgit.api.Git 11 | import org.eclipse.jgit.api.DeleteTagCommand 12 | import org.eclipse.jgit.api.TagCommand 13 | import org.eclipse.jgit.api.PushCommand 14 | import org.eclipse.jgit.lib.Repository 15 | import org.eclipse.jgit.storage.file.FileRepositoryBuilder 16 | import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider 17 | 18 | File repoDir = new File("${projectDir}") 19 | FileRepositoryBuilder builder = new FileRepositoryBuilder() 20 | Repository repo = builder.findGitDir(repoDir).build() 21 | Git git = new Git(repo) 22 | 23 | task createTag { 24 | description = 'Creates repository tag with current project version.' 25 | ext.tagName = "v${project.version}" 26 | 27 | doLast { 28 | logger.quiet "Creating tag '$tagName'." 29 | 30 | // Remove potentially existing tag 31 | DeleteTagCommand delTag = git.tagDelete() 32 | delTag.setTags(tagName).call() 33 | 34 | // Create tag 35 | TagCommand tag = git.tag() 36 | tag.setName(tagName).setMessage("Version ${project.version}").call() 37 | } 38 | } 39 | 40 | task pushTag { 41 | description = 'Pushes tag to remote repository.' 42 | dependsOn createTag 43 | 44 | doLast { 45 | logger.quiet "Pushing tag '$createTag.tagName' to remote." 46 | PushCommand push = git.push() 47 | push.add(createTag.tagName) 48 | push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(project.githubUsername, project.githubPassword)) 49 | push.call() 50 | } 51 | } 52 | 53 | task tag { 54 | dependsOn pushTag 55 | mustRunAfter "publishToSonatype", "closeAndReleaseSonatypeStagingRepository" 56 | } 57 | 58 | task release { 59 | description = 'Publishes artifacts to Bintray and tags repository with current project version.' 60 | dependsOn assemble, "publishToSonatype", "closeAndReleaseSonatypeStagingRepository", tag 61 | } 62 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdancy/jenkins-rest/c44ba18df13a45aaaab178d35825e466b64ccf69/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | rootProject.name = "jenkins-rest" 9 | -------------------------------------------------------------------------------- /src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG jenkins_tag=2.401.3-lts-jdk17 2 | FROM jenkins/jenkins:$jenkins_tag 3 | 4 | COPY --chown=jenkins:jenkins init.groovy.d/ /usr/share/jenkins/ref/init.groovy.d/ 5 | 6 | # Plugins 7 | COPY --chown=jenkins:jenkins plugins.yml /usr/share/jenkins/ref/plugins.yml 8 | # the grep command allows to ignore all comments in the plugins.txt file 9 | RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.yml 10 | 11 | # Skip initial setup 12 | ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false 13 | -------------------------------------------------------------------------------- /src/main/docker/README.md: -------------------------------------------------------------------------------- 1 | # Building and running a Jenkins master with Docker 2 | 3 | This Jenkins master image is configured to be used by integration tests, see the [main README](../../../../../README.md) 4 | 5 | 6 | Build the image 7 | ```bash 8 | docker build -t jenkins-rest/jenkins . 9 | ``` 10 | 11 | You can decide which Jenkins version to used by passing the `jenkins_tag` docker build argument like in the following 12 | ```bash 13 | docker build --build-arg jenkins_tag=2.164.3-slim -t jenkins-rest/jenkins . 14 | ``` 15 | 16 | Run the jenkins master container 17 | ```bash 18 | docker run -d --rm -p 8080:8080 --name jenkins-rest jenkins-rest/jenkins 19 | ``` -------------------------------------------------------------------------------- /src/main/docker/init.groovy.d/Security.groovy: -------------------------------------------------------------------------------- 1 | import hudson.markup.RawHtmlMarkupFormatter 2 | import hudson.security.HudsonPrivateSecurityRealm 3 | import hudson.security.FullControlOnceLoggedInAuthorizationStrategy 4 | import hudson.security.csrf.DefaultCrumbIssuer 5 | import jenkins.model.Jenkins 6 | 7 | def instance = Jenkins.instanceOrNull 8 | 9 | // ===================================================================================================================== 10 | // Allow html markup with syntax highlighting 11 | // ===================================================================================================================== 12 | instance.setMarkupFormatter(new RawHtmlMarkupFormatter(false)) 13 | 14 | 15 | // ===================================================================================================================== 16 | // Enable CSRF protection (see: https://wiki.jenkins.io/display/JENKINS/CSRF+Protection) 17 | // ===================================================================================================================== 18 | instance.setCrumbIssuer(new DefaultCrumbIssuer(true)) 19 | 20 | 21 | // ===================================================================================================================== 22 | // Create the admin user 23 | // ===================================================================================================================== 24 | 25 | def jenkinsRealm = new HudsonPrivateSecurityRealm(false) 26 | jenkinsRealm.createAccount('admin', 'admin') 27 | instance.setSecurityRealm(jenkinsRealm) 28 | 29 | // ===================================================================================================================== 30 | // Save everything 31 | // ===================================================================================================================== 32 | instance.save() 33 | -------------------------------------------------------------------------------- /src/main/docker/plugins.yml: -------------------------------------------------------------------------------- 1 | plugins: 2 | - artifactId: antisamy-markup-formatter 3 | - artifactId: cloudbees-credentials 4 | - artifactId: cloudbees-folder 5 | - artifactId: configuration-as-code 6 | - artifactId: workflow-aggregator 7 | - artifactId: badge 8 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/JenkinsApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest; 19 | 20 | import java.io.Closeable; 21 | 22 | import org.jclouds.rest.annotations.Delegate; 23 | 24 | import com.cdancy.jenkins.rest.features.ConfigurationAsCodeApi; 25 | import com.cdancy.jenkins.rest.features.CrumbIssuerApi; 26 | import com.cdancy.jenkins.rest.features.JobsApi; 27 | import com.cdancy.jenkins.rest.features.PluginManagerApi; 28 | import com.cdancy.jenkins.rest.features.QueueApi; 29 | import com.cdancy.jenkins.rest.features.StatisticsApi; 30 | import com.cdancy.jenkins.rest.features.SystemApi; 31 | import com.cdancy.jenkins.rest.features.UserApi; 32 | 33 | public interface JenkinsApi extends Closeable { 34 | 35 | @Delegate 36 | CrumbIssuerApi crumbIssuerApi(); 37 | 38 | @Delegate 39 | JobsApi jobsApi(); 40 | 41 | @Delegate 42 | PluginManagerApi pluginManagerApi(); 43 | 44 | @Delegate 45 | QueueApi queueApi(); 46 | 47 | @Delegate 48 | StatisticsApi statisticsApi(); 49 | 50 | @Delegate 51 | SystemApi systemApi(); 52 | 53 | @Delegate 54 | ConfigurationAsCodeApi configurationAsCodeApi(); 55 | 56 | @Delegate 57 | UserApi userApi(); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/JenkinsApiMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest; 19 | 20 | import java.net.URI; 21 | import java.util.Properties; 22 | 23 | import org.jclouds.apis.ApiMetadata; 24 | import org.jclouds.rest.internal.BaseHttpApiMetadata; 25 | 26 | import com.cdancy.jenkins.rest.config.JenkinsHttpApiModule; 27 | import com.google.auto.service.AutoService; 28 | import com.google.common.collect.ImmutableSet; 29 | import com.google.inject.Module; 30 | 31 | @AutoService(ApiMetadata.class) 32 | public class JenkinsApiMetadata extends BaseHttpApiMetadata { 33 | 34 | public static final String API_VERSION = "1.0"; 35 | public static final String BUILD_VERSION = "2.0"; 36 | 37 | @Override 38 | public Builder toBuilder() { 39 | return new Builder().fromApiMetadata(this); 40 | } 41 | 42 | public JenkinsApiMetadata() { 43 | this(new Builder()); 44 | } 45 | 46 | protected JenkinsApiMetadata(Builder builder) { 47 | super(builder); 48 | } 49 | 50 | public static Properties defaultProperties() { 51 | return BaseHttpApiMetadata.defaultProperties(); 52 | } 53 | 54 | public static class Builder extends BaseHttpApiMetadata.Builder { 55 | 56 | protected Builder() { 57 | super(JenkinsApi.class); 58 | id("jenkins").name("Jenkins API").identityName("Optional Username").credentialName("Optional Password") 59 | .defaultIdentity("").defaultCredential("") 60 | .documentation(URI.create("http://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API")) 61 | .version(API_VERSION).buildVersion(BUILD_VERSION).defaultEndpoint("http://127.0.0.1:8080") 62 | .defaultProperties(JenkinsApiMetadata.defaultProperties()) 63 | .defaultModules(ImmutableSet.of(JenkinsHttpApiModule.class)); 64 | } 65 | 66 | @Override 67 | public JenkinsApiMetadata build() { 68 | return new JenkinsApiMetadata(this); 69 | } 70 | 71 | @Override 72 | protected Builder self() { 73 | return this; 74 | } 75 | 76 | @Override 77 | public Builder fromApiMetadata(ApiMetadata in) { 78 | return this; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/JenkinsConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest; 19 | 20 | /** 21 | * Various constants that can be used in a global context. 22 | */ 23 | public class JenkinsConstants { 24 | 25 | public static final String ENDPOINT_SYSTEM_PROPERTY = "jenkins.rest.endpoint"; 26 | public static final String ENDPOINT_ENVIRONMENT_VARIABLE = ENDPOINT_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); 27 | 28 | public static final String CREDENTIALS_SYSTEM_PROPERTY = "jenkins.rest.credentials"; 29 | public static final String CREDENTIALS_ENVIRONMENT_VARIABLE = CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); 30 | 31 | public static final String API_TOKEN_SYSTEM_PROPERTY = "jenkins.rest.api.token"; 32 | public static final String API_TOKEN_ENVIRONMENT_VARIABLE = API_TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); 33 | 34 | public static final String DEFAULT_ENDPOINT = "http://127.0.0.1:7990"; 35 | 36 | public static final String JCLOUDS_PROPERTY_ID = "jclouds."; 37 | public static final String JENKINS_REST_PROPERTY_ID = "jenkins.rest." + JCLOUDS_PROPERTY_ID; 38 | 39 | public static final String JCLOUDS_VARIABLE_ID = "JCLOUDS_"; 40 | public static final String JENKINS_REST_VARIABLE_ID = "JENKINS_REST_" + JCLOUDS_VARIABLE_ID; 41 | 42 | public static final String OPTIONAL_FOLDER_PATH_PARAM = "optionalFolderPath"; 43 | 44 | public static final String USER_IN_USER_API = "user"; 45 | 46 | public static final String JENKINS_COOKIES_JSESSIONID = "JSESSIONID"; 47 | 48 | protected JenkinsConstants() { 49 | throw new UnsupportedOperationException("Purposefully not implemented"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/auth/AuthenticationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.auth; 19 | 20 | /** 21 | * Supported Authentication Types for Jenkins. 22 | */ 23 | public enum AuthenticationType { 24 | 25 | UsernamePassword("UsernamePassword", "Basic"), 26 | UsernameApiToken("UsernameApiToken", "Basic"), 27 | Anonymous("Anonymous", ""); 28 | 29 | private final String authName; 30 | private final String authScheme; 31 | 32 | AuthenticationType(final String authName, final String authScheme) { 33 | this.authName = authName; 34 | this.authScheme = authScheme; 35 | } 36 | 37 | public String getAuthScheme() { 38 | return authScheme; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return authName; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/binders/BindMapToForm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.binders; 18 | 19 | import static com.google.common.base.Preconditions.checkArgument; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import javax.inject.Singleton; 25 | 26 | import com.google.common.collect.Lists; 27 | import org.jclouds.http.HttpRequest; 28 | import org.jclouds.http.HttpRequest.Builder; 29 | import org.jclouds.rest.Binder; 30 | 31 | @Singleton 32 | public class BindMapToForm implements Binder { 33 | @SuppressWarnings("unchecked") 34 | @Override 35 | public R bindToRequest(final R request, final Object properties) { 36 | 37 | if (properties == null) { 38 | return (R) request.toBuilder().build(); 39 | } 40 | 41 | checkArgument(properties instanceof Map, "binder is only valid for Map"); 42 | Map> props = (Map>) properties; 43 | 44 | Builder builder = request.toBuilder(); 45 | for (Map.Entry> prop : props.entrySet()) { 46 | if (prop.getKey() != null) { 47 | String potentialKey = prop.getKey().trim(); 48 | if (potentialKey.length() > 0) { 49 | if (prop.getValue() == null) { 50 | prop.setValue(Lists.newArrayList("")); 51 | } 52 | 53 | builder.addFormParam(potentialKey, prop.getValue().toArray(new String[prop.getValue().size()])); 54 | } 55 | } 56 | } 57 | 58 | return (R) builder.build(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/config/JenkinsAuthenticationModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.config; 19 | 20 | import com.cdancy.jenkins.rest.JenkinsAuthentication; 21 | import com.google.inject.AbstractModule; 22 | import java.util.Objects; 23 | 24 | /** 25 | * Configure the provider for JenkinsAuthentication. 26 | */ 27 | public class JenkinsAuthenticationModule extends AbstractModule { 28 | 29 | private final JenkinsAuthentication authentication; 30 | 31 | public JenkinsAuthenticationModule(final JenkinsAuthentication authentication) { 32 | this.authentication = Objects.requireNonNull(authentication); 33 | } 34 | 35 | @Override 36 | protected void configure() { 37 | bind(JenkinsAuthentication.class).toProvider(new JenkinsAuthenticationProvider(authentication)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/config/JenkinsAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.config; 19 | 20 | import com.cdancy.jenkins.rest.JenkinsAuthentication; 21 | import com.google.inject.Inject; 22 | import com.google.inject.Provider; 23 | 24 | /** 25 | * Provider for JenkinsAuthentication objects. The JenkinsAuthentication 26 | * should be created ahead of time with this module simply handing it out 27 | * to downstream objects for injection. 28 | */ 29 | public class JenkinsAuthenticationProvider implements Provider { 30 | 31 | private final JenkinsAuthentication creds; 32 | 33 | @Inject 34 | public JenkinsAuthenticationProvider(final JenkinsAuthentication creds) { 35 | this.creds = creds; 36 | } 37 | 38 | @Override 39 | public JenkinsAuthentication get() { 40 | return creds; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/config/JenkinsHttpApiModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.config; 19 | 20 | import org.jclouds.http.HttpErrorHandler; 21 | import org.jclouds.http.annotation.ClientError; 22 | import org.jclouds.http.annotation.Redirection; 23 | import org.jclouds.http.annotation.ServerError; 24 | import org.jclouds.rest.ConfiguresHttpApi; 25 | import org.jclouds.rest.config.HttpApiModule; 26 | 27 | import com.cdancy.jenkins.rest.JenkinsApi; 28 | import com.cdancy.jenkins.rest.handlers.JenkinsErrorHandler; 29 | 30 | @ConfiguresHttpApi 31 | public class JenkinsHttpApiModule extends HttpApiModule { 32 | 33 | @Override 34 | protected void bindErrorHandlers() { 35 | bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(JenkinsErrorHandler.class); 36 | bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(JenkinsErrorHandler.class); 37 | bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(JenkinsErrorHandler.class); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/common/Error.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.common; 19 | 20 | import org.jclouds.javax.annotation.Nullable; 21 | import org.jclouds.json.SerializedNames; 22 | 23 | import com.google.auto.value.AutoValue; 24 | 25 | @AutoValue 26 | public abstract class Error { 27 | 28 | @Nullable 29 | public abstract String context(); 30 | 31 | @Nullable 32 | public abstract String message(); 33 | 34 | public abstract String exceptionName(); 35 | 36 | Error() { 37 | } 38 | 39 | @SerializedNames({ "context", "message", "exceptionName" }) 40 | public static Error create(final String context, 41 | final String message, 42 | final String exceptionName) { 43 | 44 | return new AutoValue_Error(context, 45 | message, 46 | exceptionName); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/common/ErrorsHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.common; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * This interface should NOT be applied to "option" like classes and/or used 24 | * in instances where this is applied to outgoing http traffic. This interface 25 | * should ONLY be used for classes modeled after incoming http traffic. 26 | */ 27 | public interface ErrorsHolder { 28 | 29 | List errors(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/common/LongResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.common; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.cdancy.jenkins.rest.JenkinsUtils; 26 | import com.google.auto.value.AutoValue; 27 | 28 | /** 29 | * Long response to be returned when an endpoint returns 30 | * an long. 31 | * 32 | *

When the HTTP response code is valid the `value` parameter will 33 | * be set to the long value while a non-valid response has the `value` set to 34 | * null along with any potential `error` objects returned from Jenkins. 35 | */ 36 | @AutoValue 37 | public abstract class LongResponse implements Value, ErrorsHolder { 38 | 39 | @SerializedNames({ "value", "errors" }) 40 | public static LongResponse create(@Nullable final Long value, 41 | final List errors) { 42 | 43 | return new AutoValue_LongResponse(value, 44 | JenkinsUtils.nullToEmpty(errors)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/common/RequestStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.common; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.cdancy.jenkins.rest.JenkinsUtils; 26 | import com.google.auto.value.AutoValue; 27 | 28 | /** 29 | * Generic response to be returned when an endpoint returns 30 | * no content (i.e. 204 response code). 31 | * 32 | *

When the response code is valid the `value` parameter will 33 | * be set to true while a non-valid response has the `value` set to 34 | * false along with any potential `error` objects returned from Jenkins. 35 | */ 36 | @AutoValue 37 | public abstract class RequestStatus implements Value, ErrorsHolder { 38 | 39 | @SerializedNames({ "value", "errors" }) 40 | public static RequestStatus create(@Nullable final Boolean value, 41 | final List errors) { 42 | 43 | return new AutoValue_RequestStatus(value, 44 | JenkinsUtils.nullToEmpty(errors)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/common/Value.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.common; 19 | 20 | import org.jclouds.javax.annotation.Nullable; 21 | 22 | public interface Value { 23 | 24 | @Nullable 25 | public abstract T value(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/crumb/Crumb.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.crumb; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.cdancy.jenkins.rest.domain.common.Error; 26 | import com.cdancy.jenkins.rest.domain.common.ErrorsHolder; 27 | import com.cdancy.jenkins.rest.JenkinsUtils; 28 | import com.google.auto.value.AutoValue; 29 | 30 | @AutoValue 31 | public abstract class Crumb implements ErrorsHolder { 32 | 33 | @Nullable 34 | public abstract String value(); 35 | 36 | @Nullable 37 | public abstract String sessionIdCookie(); 38 | 39 | @SerializedNames({ "value", "errors" }) 40 | public static Crumb create(final String value, 41 | final List errors) { 42 | 43 | return create(value, null, errors); 44 | } 45 | 46 | @SerializedNames({ "value", "sessionIdCookie" }) 47 | public static Crumb create(final String value, final String sessionIdCookie) { 48 | return create(value, sessionIdCookie, null); 49 | } 50 | 51 | private static Crumb create(final String value, final String sessionIdCookie, 52 | final List errors) { 53 | 54 | return new AutoValue_Crumb(JenkinsUtils.nullToEmpty(errors), value, 55 | sessionIdCookie); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import com.google.auto.value.AutoValue; 21 | import com.google.common.collect.ImmutableList; 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import java.util.List; 26 | 27 | @AutoValue 28 | public abstract class Action { 29 | 30 | public abstract List causes(); 31 | 32 | public abstract List parameters(); 33 | 34 | @Nullable 35 | public abstract String text(); 36 | 37 | @Nullable 38 | public abstract String iconPath(); 39 | 40 | @Nullable 41 | public abstract String _class(); 42 | Action() { 43 | } 44 | 45 | @SerializedNames({"causes", "parameters", "text", "iconPath", "_class"}) 46 | public static Action create(final List causes, final List parameters, final String text, final String iconPath, final String _class) { 47 | return new AutoValue_Action( 48 | causes != null ? ImmutableList.copyOf(causes) : ImmutableList.of(), 49 | parameters != null ? ImmutableList.copyOf(parameters) : ImmutableList.of(), 50 | text, iconPath, _class 51 | ); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Artifact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import org.jclouds.javax.annotation.Nullable; 21 | import org.jclouds.json.SerializedNames; 22 | 23 | import com.google.auto.value.AutoValue; 24 | 25 | @AutoValue 26 | public abstract class Artifact { 27 | 28 | @Nullable 29 | public abstract String displayPath(); 30 | 31 | public abstract String fileName(); 32 | 33 | public abstract String relativePath(); 34 | 35 | Artifact() { 36 | } 37 | 38 | @SerializedNames({ "displayPath", "fileName", "relativePath" }) 39 | public static Artifact create(String displayPath, String fileName, String relativePath) { 40 | return new AutoValue_Artifact(displayPath, fileName, relativePath); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/BuildInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.google.auto.value.AutoValue; 26 | import com.google.common.collect.ImmutableList; 27 | 28 | @AutoValue 29 | public abstract class BuildInfo { 30 | 31 | public abstract List artifacts(); 32 | 33 | public abstract List actions(); 34 | 35 | public abstract boolean building(); 36 | 37 | @Nullable 38 | public abstract String description(); 39 | 40 | @Nullable 41 | public abstract String displayName(); 42 | 43 | public abstract long duration(); 44 | 45 | public abstract long estimatedDuration(); 46 | 47 | @Nullable 48 | public abstract String fullDisplayName(); 49 | 50 | @Nullable 51 | public abstract String id(); 52 | 53 | public abstract boolean keepLog(); 54 | 55 | public abstract int number(); 56 | 57 | public abstract int queueId(); 58 | 59 | @Nullable 60 | public abstract String result(); 61 | 62 | public abstract long timestamp(); 63 | 64 | @Nullable 65 | public abstract String url(); 66 | 67 | public abstract List changeSets(); 68 | 69 | @Nullable 70 | public abstract String builtOn(); 71 | 72 | public abstract List culprits(); 73 | 74 | BuildInfo() { 75 | } 76 | 77 | @SerializedNames({ "artifacts", "actions", "building", "description", "displayName", "duration", "estimatedDuration", 78 | "fullDisplayName", "id", "keepLog", "number", "queueId", "result", "timestamp", "url", "changeSets", "builtOn", "culprits" }) 79 | public static BuildInfo create(List artifacts, List actions, boolean building, String description, String displayName, 80 | long duration, long estimatedDuration, String fullDisplayName, String id, boolean keepLog, int number, 81 | int queueId, String result, long timestamp, String url, List changeSets, String builtOn, List culprits) { 82 | return new AutoValue_BuildInfo( 83 | artifacts != null ? ImmutableList.copyOf(artifacts) : ImmutableList. of(), 84 | actions != null ? ImmutableList.copyOf(actions) : ImmutableList. of(), 85 | building, description, displayName, duration, estimatedDuration, fullDisplayName, 86 | id, keepLog, number, queueId, result, timestamp, url, 87 | changeSets != null ? ImmutableList.copyOf(changeSets) : ImmutableList. of(), 88 | builtOn, 89 | culprits != null ? ImmutableList.copyOf(culprits) : ImmutableList. of()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Cause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import com.google.auto.value.AutoValue; 21 | import org.jclouds.javax.annotation.Nullable; 22 | import org.jclouds.json.SerializedNames; 23 | 24 | @AutoValue 25 | public abstract class Cause { 26 | 27 | @Nullable 28 | public abstract String clazz(); 29 | 30 | public abstract String shortDescription(); 31 | 32 | @Nullable 33 | public abstract String userId(); 34 | 35 | @Nullable 36 | public abstract String userName(); 37 | 38 | Cause() { 39 | } 40 | 41 | @SerializedNames({"_class", "shortDescription", "userId", "userName"}) 42 | public static Cause create(final String clazz, final String shortDescription, final String userId, final String userName) { 43 | return new AutoValue_Cause(clazz, shortDescription, userId, userName); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/ChangeSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.google.auto.value.AutoValue; 26 | import com.google.common.collect.ImmutableList; 27 | 28 | @AutoValue 29 | public abstract class ChangeSet { 30 | 31 | public abstract List affectedPaths(); 32 | 33 | public abstract String commitId(); 34 | 35 | public abstract long timestamp(); 36 | 37 | public abstract Culprit author(); 38 | 39 | @Nullable 40 | public abstract String authorEmail(); 41 | 42 | @Nullable 43 | public abstract String comment(); 44 | 45 | ChangeSet() { 46 | } 47 | 48 | @SerializedNames({ "affectedPaths", "commitId", "timestamp", "author", "authorEmail", "comment" }) 49 | public static ChangeSet create(List affectedPaths, String commitId, long timestamp, Culprit author, String authorEmail, String comment) { 50 | return new AutoValue_ChangeSet( 51 | affectedPaths != null ? ImmutableList.copyOf(affectedPaths) : ImmutableList. of(), 52 | commitId, timestamp, author, authorEmail, comment); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/ChangeSetList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import java.util.List; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.google.auto.value.AutoValue; 26 | import com.google.common.collect.ImmutableList; 27 | 28 | @AutoValue 29 | public abstract class ChangeSetList { 30 | 31 | public abstract List items(); 32 | 33 | @Nullable 34 | public abstract String kind(); 35 | 36 | ChangeSetList() { 37 | } 38 | 39 | @SerializedNames({ "items", "kind" }) 40 | public static ChangeSetList create(List items, String kind) { 41 | return new AutoValue_ChangeSetList( 42 | items != null ? ImmutableList.copyOf(items) : ImmutableList. of(), 43 | kind); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Culprit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import org.jclouds.json.SerializedNames; 21 | 22 | import com.google.auto.value.AutoValue; 23 | 24 | @AutoValue 25 | public abstract class Culprit { 26 | 27 | public abstract String absoluteUrl(); 28 | 29 | public abstract String fullName(); 30 | 31 | Culprit() { 32 | } 33 | 34 | @SerializedNames({ "absoluteUrl", "fullName" }) 35 | public static Culprit create(String absoluteUrl, String fullName) { 36 | return new AutoValue_Culprit(absoluteUrl, fullName); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Job.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.domain.job; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jclouds.javax.annotation.Nullable; 5 | import org.jclouds.json.SerializedNames; 6 | 7 | @AutoValue 8 | public abstract class Job { 9 | 10 | @Nullable 11 | public abstract String clazz(); 12 | 13 | public abstract String name(); 14 | 15 | public abstract String url(); 16 | 17 | @Nullable 18 | public abstract String color(); 19 | 20 | Job() { 21 | } 22 | 23 | @SerializedNames({"_class", "name", "url", "color"}) 24 | public static Job create(final String clazz, final String name, final String url, final String color) { 25 | return new AutoValue_Job(clazz, name, url, color); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/JobList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import com.google.auto.value.AutoValue; 21 | import org.jclouds.javax.annotation.Nullable; 22 | import org.jclouds.json.SerializedNames; 23 | 24 | import java.util.List; 25 | 26 | @AutoValue 27 | public abstract class JobList { 28 | 29 | @Nullable 30 | public abstract String clazz(); 31 | 32 | public abstract List jobs(); 33 | 34 | @Nullable 35 | public abstract String url(); 36 | 37 | JobList() { 38 | } 39 | 40 | @SerializedNames({"_class", "jobs", "url"}) 41 | public static JobList create(final String clazz, final List jobs, final String url) { 42 | return new AutoValue_JobList(clazz, jobs, url); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import com.google.auto.value.AutoValue; 21 | import org.jclouds.javax.annotation.Nullable; 22 | import org.jclouds.json.SerializedNames; 23 | 24 | @AutoValue 25 | public abstract class Parameter { 26 | 27 | @Nullable 28 | public abstract String clazz(); 29 | 30 | public abstract String name(); 31 | 32 | @Nullable 33 | public abstract String value(); 34 | 35 | Parameter() { 36 | } 37 | 38 | @SerializedNames({"_class", "name", "value"}) 39 | public static Parameter create(final String clazz, final String name, final String value) { 40 | return new AutoValue_Parameter(clazz, name, value); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/PipelineNode.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.domain.job; 2 | 3 | import java.util.List; 4 | 5 | import com.google.auto.value.AutoValue; 6 | import org.jclouds.json.SerializedNames; 7 | 8 | @AutoValue 9 | public abstract class PipelineNode { 10 | 11 | public abstract String name(); 12 | 13 | public abstract String status(); 14 | 15 | public abstract long startTimeMillis(); 16 | 17 | public abstract long durationTimeMillis(); 18 | 19 | public abstract List stageFlowNodes(); 20 | 21 | PipelineNode() { 22 | } 23 | 24 | @SerializedNames({ "name", "status", "startTimeMillis", "durationTimeMillis", "stageFlowNodes" }) 25 | public static PipelineNode create(String name, String status, long startTimeMillis, long durationTimeMillis, List stageFlowNodes) { 26 | return new AutoValue_PipelineNode(name, status, startTimeMillis, durationTimeMillis, stageFlowNodes); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/PipelineNodeLog.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.domain.job; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jclouds.json.SerializedNames; 5 | 6 | @AutoValue 7 | public abstract class PipelineNodeLog { 8 | 9 | public abstract String nodeId(); 10 | 11 | public abstract String nodeStatus(); 12 | 13 | public abstract int length(); 14 | 15 | public abstract boolean hasMore(); 16 | 17 | public abstract String text(); 18 | 19 | public abstract String consoleUrl(); 20 | 21 | PipelineNodeLog() { 22 | } 23 | 24 | @SerializedNames({ "nodeId", "nodeStatus", "length", "hasMore", "text", "consoleUrl" }) 25 | public static PipelineNodeLog create(String nodeId, String nodeStatus, int length, boolean hasMore, String text, String consoleUrl) { 26 | return new AutoValue_PipelineNodeLog(nodeId, nodeStatus, length, hasMore, text, consoleUrl); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/ProgressiveText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import org.jclouds.json.SerializedNames; 21 | 22 | import com.google.auto.value.AutoValue; 23 | 24 | @AutoValue 25 | public abstract class ProgressiveText { 26 | 27 | public abstract String text(); 28 | 29 | public abstract int size(); 30 | 31 | public abstract boolean hasMoreData(); 32 | 33 | ProgressiveText() { 34 | } 35 | 36 | @SerializedNames({ "text", "size", "hasMoreData" }) 37 | public static ProgressiveText create(String text, int size, boolean hasMoreData) { 38 | return new AutoValue_ProgressiveText(text, size, hasMoreData); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Stage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import com.google.auto.value.AutoValue; 21 | import org.jclouds.json.SerializedNames; 22 | 23 | @AutoValue 24 | public abstract class Stage { 25 | public abstract String id(); 26 | 27 | public abstract String name(); 28 | 29 | public abstract String status(); 30 | 31 | public abstract long startTimeMillis(); 32 | 33 | public abstract long endTimeMillis(); 34 | 35 | public abstract long pauseDurationMillis(); 36 | 37 | public abstract long durationMillis(); 38 | 39 | Stage() { 40 | } 41 | 42 | @SerializedNames({ "id", "name", "status", "startTimeMillis", "endTimeMillis", "pauseDurationMillis", "durationMillis" }) 43 | public static Stage create(String id, String name, String status, long startTimeMillis, long endTimeMillis, long pauseDurationMillis, long durationMillis) { 44 | return new AutoValue_Stage(id, name, status, startTimeMillis, endTimeMillis, pauseDurationMillis, durationMillis); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/StageFlowNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import java.util.List; 21 | 22 | import com.google.auto.value.AutoValue; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | @AutoValue 26 | public abstract class StageFlowNode { 27 | 28 | public abstract String name(); 29 | 30 | public abstract String status(); 31 | 32 | public abstract long startTimeMillis(); 33 | 34 | public abstract long durationTimeMillis(); 35 | 36 | public abstract List parentNodes(); 37 | 38 | StageFlowNode() { 39 | } 40 | 41 | @SerializedNames({ "name", "status", "startTimeMillis", "durationTimeMillis", "parentNodes" }) 42 | public static StageFlowNode create(String name, String status, long startTimeMillis, long durationTimeMillis, List parentNodes) { 43 | return new AutoValue_StageFlowNode(name, status, startTimeMillis, durationTimeMillis, parentNodes); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/job/Workflow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.job; 19 | 20 | import java.util.List; 21 | 22 | import com.google.auto.value.AutoValue; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | @AutoValue 26 | public abstract class Workflow { 27 | 28 | public abstract String name(); 29 | 30 | public abstract String status(); 31 | 32 | public abstract long startTimeMillis(); 33 | 34 | public abstract long durationTimeMillis(); 35 | 36 | public abstract List stages(); 37 | 38 | Workflow() { 39 | } 40 | 41 | @SerializedNames({ "name", "status", "startTimeMillis", "durationTimeMillis", "stages" }) 42 | public static Workflow create(String name, String status, long startTimeMillis, long durationTimeMillis, List stages) { 43 | return new AutoValue_Workflow(name, status, startTimeMillis, durationTimeMillis, stages); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/plugins/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.plugins; 19 | 20 | 21 | import org.jclouds.json.SerializedNames; 22 | 23 | import com.google.auto.value.AutoValue; 24 | import org.jclouds.javax.annotation.Nullable; 25 | 26 | @AutoValue 27 | public abstract class Plugin { 28 | 29 | @Nullable 30 | public abstract Boolean active(); 31 | 32 | @Nullable 33 | public abstract String backupVersion(); 34 | 35 | @Nullable 36 | public abstract Boolean bundled(); 37 | 38 | @Nullable 39 | public abstract Boolean deleted(); 40 | 41 | @Nullable 42 | public abstract Boolean downgradable(); 43 | 44 | @Nullable 45 | public abstract Boolean enabled(); 46 | 47 | @Nullable 48 | public abstract Boolean hasUpdate(); 49 | 50 | @Nullable 51 | public abstract String longName(); 52 | 53 | @Nullable 54 | public abstract Boolean pinned(); 55 | 56 | @Nullable 57 | public abstract String requiredCoreVersion(); 58 | 59 | @Nullable 60 | public abstract String shortName(); 61 | 62 | @Nullable 63 | public abstract String supportsDynamicLoad(); 64 | 65 | @Nullable 66 | public abstract String url(); 67 | 68 | @Nullable 69 | public abstract String version(); 70 | 71 | Plugin() { 72 | } 73 | 74 | @SerializedNames({ "active", "backupVersion", "bundled", 75 | "deleted", "downgradable", "enabled", 76 | "hasUpdate", "longName", "pinned", 77 | "requiredCoreVersion", "shortName", "supportsDynamicLoad", 78 | "url", "version"}) 79 | public static Plugin create(Boolean active, String backupVersion, Boolean bundled, 80 | Boolean deleted, Boolean downgradable, Boolean enabled, 81 | Boolean hasUpdate, String longName, Boolean pinned, 82 | String requiredCoreVersion, String shortName, String supportsDynamicLoad, 83 | String url, String version) { 84 | return new AutoValue_Plugin(active, backupVersion, bundled, 85 | deleted, downgradable, enabled, 86 | hasUpdate, longName, pinned, 87 | requiredCoreVersion, shortName, supportsDynamicLoad, 88 | url, version); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/plugins/Plugins.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.plugins; 19 | 20 | import com.cdancy.jenkins.rest.JenkinsUtils; 21 | import com.cdancy.jenkins.rest.domain.common.ErrorsHolder; 22 | import com.cdancy.jenkins.rest.domain.common.Error; 23 | 24 | import org.jclouds.javax.annotation.Nullable; 25 | import org.jclouds.json.SerializedNames; 26 | 27 | import com.google.auto.value.AutoValue; 28 | 29 | import java.util.List; 30 | 31 | @AutoValue 32 | public abstract class Plugins implements ErrorsHolder { 33 | 34 | @Nullable 35 | public abstract String clazz(); 36 | 37 | public abstract List plugins(); 38 | 39 | Plugins() { 40 | } 41 | 42 | @SerializedNames({ "_class", "plugins", "errors" }) 43 | public static Plugins create(final String clazz, 44 | final List plugins, 45 | final List errors) { 46 | return new AutoValue_Plugins(JenkinsUtils.nullToEmpty(errors), 47 | clazz, 48 | JenkinsUtils.nullToEmpty(plugins)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/queue/Executable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.queue; 19 | 20 | import org.jclouds.json.SerializedNames; 21 | 22 | import com.google.auto.value.AutoValue; 23 | 24 | @AutoValue 25 | public abstract class Executable { 26 | 27 | public abstract Integer number(); 28 | 29 | public abstract String url(); 30 | 31 | Executable() { 32 | } 33 | 34 | @SerializedNames({ "number", "url" }) 35 | public static Executable create(Integer number, String url) { 36 | return new AutoValue_Executable(number, url); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/queue/QueueItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.queue; 19 | 20 | import java.util.Map; 21 | 22 | import org.jclouds.json.SerializedNames; 23 | import org.jclouds.javax.annotation.Nullable; 24 | 25 | import com.google.auto.value.AutoValue; 26 | import com.google.common.collect.Maps; 27 | 28 | @AutoValue 29 | public abstract class QueueItem { 30 | 31 | public abstract boolean blocked(); 32 | 33 | public abstract boolean buildable(); 34 | 35 | public abstract int id(); 36 | 37 | public abstract long inQueueSince(); 38 | 39 | public abstract Map params(); 40 | 41 | public abstract boolean stuck(); 42 | 43 | public abstract Task task(); 44 | 45 | public abstract String url(); 46 | 47 | @Nullable 48 | public abstract String why(); 49 | 50 | // https://javadoc.jenkins.io/hudson/model/Queue.NotWaitingItem.html 51 | /** 52 | * When did this job exit the Queue.waitingList phase? 53 | * For a Queue.NotWaitingItem 54 | * @return The time expressed in milliseconds after January 1, 1970, 0:00:00 GMT. 55 | */ 56 | public abstract long buildableStartMilliseconds(); 57 | 58 | public abstract boolean cancelled(); 59 | 60 | @Nullable 61 | public abstract Executable executable(); 62 | 63 | // https://javadoc.jenkins.io/hudson/model/Queue.WaitingItem.html 64 | /** 65 | * This item can be run after this time. 66 | * For a Queue.WaitingItem 67 | * @return The time expressed in milliseconds after January 1, 1970, 0:00:00 GMT. 68 | */ 69 | @Nullable 70 | public abstract Long timestamp(); 71 | 72 | QueueItem() { 73 | } 74 | 75 | @SerializedNames({ "blocked", "buildable", "id", "inQueueSince", "params", "stuck", "task", "url", "why", 76 | "buildableStartMilliseconds", "cancelled", "executable", "timestamp"}) 77 | public static QueueItem create(boolean blocked, boolean buildable, int id, long inQueueSince, String params, 78 | boolean stuck, Task task, String url, String why, long buildableStartMilliseconds, 79 | boolean cancelled, Executable executable, Long timestamp) { 80 | Map parameters = Maps.newHashMap(); 81 | if (params != null) { 82 | params = params.trim(); 83 | if (params.length() > 0) { 84 | for (String keyValue : params.split("\n")) { 85 | String[] pair = keyValue.split("="); 86 | parameters.put(pair[0], pair.length > 1 ? pair[1] : ""); 87 | } 88 | } 89 | } 90 | return new AutoValue_QueueItem(blocked, buildable, id, inQueueSince, parameters, stuck, task, url, why, 91 | buildableStartMilliseconds, cancelled, executable, timestamp); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/queue/Task.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.queue; 19 | 20 | import org.jclouds.javax.annotation.Nullable; 21 | import org.jclouds.json.SerializedNames; 22 | 23 | import com.google.auto.value.AutoValue; 24 | 25 | @AutoValue 26 | public abstract class Task { 27 | 28 | @Nullable 29 | public abstract String name(); 30 | 31 | @Nullable 32 | public abstract String url(); 33 | 34 | Task() { 35 | } 36 | 37 | @SerializedNames({ "name", "url" }) 38 | public static Task create(String name, String url) { 39 | return new AutoValue_Task(name, url); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/statistics/OverallLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.statistics; 19 | 20 | import java.util.Map; 21 | 22 | import org.jclouds.javax.annotation.Nullable; 23 | import org.jclouds.json.SerializedNames; 24 | 25 | import com.google.auto.value.AutoValue; 26 | 27 | @AutoValue 28 | public abstract class OverallLoad { 29 | 30 | @Nullable 31 | public abstract Map availableExecutors(); 32 | 33 | @Nullable 34 | public abstract Map busyExecutors(); 35 | 36 | @Nullable 37 | public abstract Map connectingExecutors(); 38 | 39 | @Nullable 40 | public abstract Map definedExecutors(); 41 | 42 | @Nullable 43 | public abstract Map idleExecutors(); 44 | 45 | @Nullable 46 | public abstract Map onlineExecutors(); 47 | 48 | @Nullable 49 | public abstract Map queueLength(); 50 | 51 | @Nullable 52 | public abstract Map totalExecutors(); 53 | 54 | @Nullable 55 | public abstract Map totalQueueLength(); 56 | 57 | OverallLoad() { 58 | } 59 | 60 | @SerializedNames({ "availableExecutors", "busyExecutors", "connectingExecutors", "definedExecutors", "idleExecutors", 61 | "onlineExecutors", "queueLength", "totalExecutors", "totalQueueLength" }) 62 | public static OverallLoad create(Map availableExecutors, Map busyExecutors, 63 | Map connectingExecutors, Map definedExecutors, 64 | Map idleExecutors, Map onlineExecutors, Map queueLength, 65 | Map totalExecutors, Map totalQueueLength) { 66 | return new AutoValue_OverallLoad(availableExecutors, busyExecutors, 67 | connectingExecutors, definedExecutors, 68 | idleExecutors, onlineExecutors, 69 | queueLength, totalExecutors, 70 | totalQueueLength); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/system/SystemInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.domain.system; 19 | 20 | import com.cdancy.jenkins.rest.JenkinsUtils; 21 | import com.cdancy.jenkins.rest.domain.common.ErrorsHolder; 22 | import com.cdancy.jenkins.rest.domain.common.Error; 23 | 24 | import org.jclouds.json.SerializedNames; 25 | import org.jclouds.javax.annotation.Nullable; 26 | 27 | import com.google.auto.value.AutoValue; 28 | 29 | import java.util.List; 30 | 31 | @AutoValue 32 | public abstract class SystemInfo implements ErrorsHolder { 33 | 34 | public abstract String hudsonVersion(); 35 | 36 | public abstract String jenkinsVersion(); 37 | 38 | public abstract String jenkinsSession(); 39 | 40 | public abstract String instanceIdentity(); 41 | 42 | @Nullable 43 | public abstract String sshEndpoint(); 44 | 45 | public abstract String server(); 46 | 47 | SystemInfo() { 48 | } 49 | 50 | @SerializedNames({ "hudsonVersion", "jenkinsVersion", "jenkinsSession", 51 | "instanceIdentity", "sshEndpoint", "server", "errors" }) 52 | public static SystemInfo create(String hudsonVersion, String jenkinsVersion, String jenkinsSession, 53 | String instanceIdentity, 54 | String sshEndpoint, String server, final List errors) { 55 | return new AutoValue_SystemInfo(JenkinsUtils.nullToEmpty(errors), 56 | hudsonVersion, jenkinsVersion, jenkinsSession, 57 | instanceIdentity, sshEndpoint, server); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/user/ApiToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.domain.user; 18 | 19 | import com.google.auto.value.AutoValue; 20 | import org.jclouds.json.SerializedNames; 21 | 22 | @AutoValue 23 | public abstract class ApiToken { 24 | 25 | public abstract String status(); 26 | 27 | public abstract ApiTokenData data(); 28 | 29 | ApiToken() { 30 | } 31 | 32 | @SerializedNames({"status", "data"}) 33 | public static ApiToken create(final String status, final ApiTokenData data) { 34 | return new AutoValue_ApiToken(status, data); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/user/ApiTokenData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.domain.user; 18 | 19 | import com.google.auto.value.AutoValue; 20 | import org.jclouds.json.SerializedNames; 21 | 22 | @AutoValue 23 | public abstract class ApiTokenData { 24 | 25 | public abstract String tokenName(); 26 | public abstract String tokenUuid(); 27 | public abstract String tokenValue(); 28 | 29 | ApiTokenData() { 30 | } 31 | 32 | @SerializedNames({"tokenName", "tokenUuid", "tokenValue"}) 33 | public static ApiTokenData create(final String tokenName, final String tokenUuid, final String tokenValue) { 34 | return new AutoValue_ApiTokenData(tokenName, tokenUuid, tokenValue); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/user/Property.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.domain.user; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jclouds.json.SerializedNames; 5 | 6 | @AutoValue 7 | public abstract class Property { 8 | 9 | public abstract String clazz(); 10 | 11 | Property() { 12 | } 13 | 14 | @SerializedNames({"_class"}) 15 | public static Property create(final String clazz) { 16 | return new AutoValue_Property(clazz); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/domain/user/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.domain.user; 18 | 19 | import java.util.List; 20 | 21 | import com.google.auto.value.AutoValue; 22 | import com.google.common.collect.ImmutableList; 23 | import org.jclouds.javax.annotation.Nullable; 24 | import org.jclouds.json.SerializedNames; 25 | 26 | @AutoValue 27 | public abstract class User { 28 | 29 | public abstract String absoluteUrl(); 30 | 31 | @Nullable 32 | public abstract String description(); 33 | 34 | public abstract String fullName(); 35 | 36 | public abstract String id(); 37 | 38 | // TODO: Find a way to support properties, which is a list of different extensions of a base class 39 | // public abstract List properties(); 40 | 41 | User() { 42 | } 43 | 44 | @SerializedNames({"absoluteUrl", "description", "fullName", "id"}) 45 | public static User create(final String absoluteUrl, final String description, final String fullName, final String id) { 46 | return new AutoValue_User(absoluteUrl, description, fullName, id); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/exception/ForbiddenException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.exception; 19 | 20 | /** 21 | * Thrown when an action has breached the licensed user limit of the server, or 22 | * degrading the authenticated user's permission level. 23 | */ 24 | public class ForbiddenException extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public ForbiddenException(final String arg0) { 29 | super(arg0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/exception/MethodNotAllowedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.exception; 19 | 20 | /** 21 | * Thrown when a method was used that is not supported by this endpoint. 22 | */ 23 | public class MethodNotAllowedException extends RuntimeException { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | public MethodNotAllowedException(final String arg0) { 28 | super(arg0); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/exception/RedirectTo404Exception.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.exception; 19 | 20 | /** 21 | * Thrown when an action has breached the licensed user limit of the server, or 22 | * degrading the authenticated user's permission level. 23 | */ 24 | public class RedirectTo404Exception extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public RedirectTo404Exception(final String arg0) { 29 | super(arg0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/exception/UndetectableIdentityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.exception; 19 | 20 | /** 21 | * The credential being passed cannot be processed. 22 | * 23 | * A valid credential is either 24 | *

    25 | *
  1. a colon separated identity and password or token (tuple of )identity:password or identity:token); or
  2. 26 | *
  3. the base64 encoded form of identity:password or identity:token
  4. 27 | *
28 | * When the credential does not contain a colon, an attempt is made at decoding it to extract the identity. 29 | * When this fails, this exception is thrown. 30 | * 31 | */ 32 | public class UndetectableIdentityException extends RuntimeException { 33 | private static final long serialVersionUID = 1L; 34 | 35 | public UndetectableIdentityException(final String arg0) { 36 | super(arg0); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/exception/UnsupportedMediaTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.exception; 19 | 20 | /** 21 | * The request entity has a Content-Type that the server does not support. 22 | * Some Jenkins REST API accept application/json format, but 23 | * check the individual resource documentation for more details. Additionally, 24 | * double-check that you are setting the Content-Type header correctly on your 25 | * request (e.g. using -H "Content-Type: application/json" in cURL). 26 | */ 27 | public class UnsupportedMediaTypeException extends RuntimeException { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | public UnsupportedMediaTypeException(final String arg0) { 32 | super(arg0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/ConfigurationAsCodeApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.POST; 22 | import javax.ws.rs.Path; 23 | 24 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 25 | import com.cdancy.jenkins.rest.parsers.RequestStatusParser; 26 | import org.jclouds.rest.annotations.RequestFilters; 27 | import org.jclouds.rest.annotations.ResponseParser; 28 | import org.jclouds.rest.annotations.Fallback; 29 | import org.jclouds.rest.annotations.Payload; 30 | import org.jclouds.rest.annotations.PayloadParam; 31 | 32 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 33 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 34 | 35 | @RequestFilters(JenkinsAuthenticationFilter.class) 36 | @Path("/configuration-as-code") 37 | public interface ConfigurationAsCodeApi { 38 | 39 | @Named("casc:check") 40 | @Path("/check") 41 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 42 | @ResponseParser(RequestStatusParser.class) 43 | @Payload("{cascYml}") 44 | @POST 45 | RequestStatus check(@PayloadParam(value = "cascYml") String cascYml); 46 | 47 | @Named("casc:apply") 48 | @Path("/apply") 49 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 50 | @ResponseParser(RequestStatusParser.class) 51 | @Payload("{cascYml}") 52 | @POST 53 | RequestStatus apply(@PayloadParam(value = "cascYml") String cascYml); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/CrumbIssuerApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.MediaType; 25 | 26 | import org.jclouds.rest.annotations.Fallback; 27 | import org.jclouds.rest.annotations.ResponseParser; 28 | import org.jclouds.rest.annotations.RequestFilters; 29 | import org.jclouds.rest.annotations.QueryParams; 30 | 31 | import com.cdancy.jenkins.rest.domain.crumb.Crumb; 32 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 33 | import com.cdancy.jenkins.rest.filters.JenkinsNoCrumbAuthenticationFilter; 34 | import com.cdancy.jenkins.rest.parsers.CrumbParser; 35 | 36 | @RequestFilters(JenkinsNoCrumbAuthenticationFilter.class) 37 | @Path("/crumbIssuer/api/xml") 38 | public interface CrumbIssuerApi { 39 | 40 | @Named("crumb-issuer:crumb") 41 | @Fallback(JenkinsFallbacks.CrumbOnError.class) 42 | @ResponseParser(CrumbParser.class) 43 | @QueryParams(keys = { "xpath" }, values = { "concat(//crumbRequestField,\":\",//crumb)" }) 44 | @Consumes(MediaType.TEXT_PLAIN) 45 | @GET 46 | Crumb crumb(); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/PluginManagerApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.MediaType; 25 | import javax.ws.rs.QueryParam; 26 | import javax.ws.rs.POST; 27 | import javax.ws.rs.Produces; 28 | 29 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 30 | import com.cdancy.jenkins.rest.domain.plugins.Plugins; 31 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 32 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 33 | import com.cdancy.jenkins.rest.parsers.RequestStatusParser; 34 | 35 | import org.jclouds.rest.annotations.RequestFilters; 36 | import org.jclouds.javax.annotation.Nullable; 37 | import org.jclouds.rest.annotations.Fallback; 38 | import org.jclouds.rest.annotations.Payload; 39 | import org.jclouds.rest.annotations.PayloadParam; 40 | import org.jclouds.rest.annotations.ResponseParser; 41 | 42 | @RequestFilters(JenkinsAuthenticationFilter.class) 43 | @Consumes(MediaType.APPLICATION_JSON) 44 | @Path("/pluginManager") 45 | public interface PluginManagerApi { 46 | 47 | @Named("pluginManager:plugins") 48 | @Path("/api/json") 49 | @Fallback(JenkinsFallbacks.PluginsOnError.class) 50 | @GET 51 | Plugins plugins(@Nullable @QueryParam("depth") Integer depth, 52 | @Nullable @QueryParam("tree") String tree); 53 | 54 | @Named("pluginManager:install-necessary-plugins") 55 | @Path("/installNecessaryPlugins") 56 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 57 | @ResponseParser(RequestStatusParser.class) 58 | @Produces(MediaType.APPLICATION_XML) 59 | @Payload("") 60 | @POST 61 | RequestStatus installNecessaryPlugins(@PayloadParam(value = "pluginID") String pluginID); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/QueueApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 21 | import java.util.List; 22 | 23 | import javax.inject.Named; 24 | import javax.ws.rs.Consumes; 25 | import javax.ws.rs.FormParam; 26 | import javax.ws.rs.GET; 27 | import javax.ws.rs.POST; 28 | import javax.ws.rs.Path; 29 | import javax.ws.rs.PathParam; 30 | import javax.ws.rs.core.MediaType; 31 | 32 | import org.jclouds.rest.annotations.Fallback; 33 | import org.jclouds.rest.annotations.RequestFilters; 34 | import org.jclouds.rest.annotations.SelectJson; 35 | 36 | import com.cdancy.jenkins.rest.domain.queue.QueueItem; 37 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 38 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 39 | import com.cdancy.jenkins.rest.parsers.RequestStatusParser; 40 | import org.jclouds.rest.annotations.ResponseParser; 41 | 42 | @RequestFilters(JenkinsAuthenticationFilter.class) 43 | @Consumes(MediaType.APPLICATION_JSON) 44 | @Path("/queue") 45 | public interface QueueApi { 46 | 47 | @Named("queue:queue") 48 | @Path("/api/json") 49 | @SelectJson("items") 50 | @GET 51 | List queue(); 52 | 53 | /** 54 | * Get a specific queue item. 55 | * 56 | * Queue items are builds that have been scheduled to run, but are waiting for a slot. 57 | * You can poll the queueItem that corresponds to a build to detect whether the build is still pending or is executing. 58 | * @param queueId The queue id value as returned by the JobsApi build or buildWithParameters methods. 59 | * @return The queue item corresponding to the queue id. 60 | */ 61 | @Named("queue:item") 62 | @Path("/item/{queueId}/api/json") 63 | @GET 64 | QueueItem queueItem(@PathParam("queueId") long queueId); 65 | 66 | /** 67 | * Cancel a queue item before it gets built. 68 | * 69 | * @param id The queue id value of the queue item to cancel. 70 | * This is the value is returned by the JobsApi build or buildWithParameters methods. 71 | * @return Always returns true due to JENKINS-21311. 72 | */ 73 | @Named("queue:cancel") 74 | @Path("/cancelItem") 75 | @Fallback(JenkinsFallbacks.JENKINS_21311.class) 76 | @ResponseParser(RequestStatusParser.class) 77 | @POST 78 | RequestStatus cancel(@FormParam("id") long id); 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/StatisticsApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.core.MediaType; 25 | 26 | import org.jclouds.rest.annotations.RequestFilters; 27 | 28 | import com.cdancy.jenkins.rest.domain.statistics.OverallLoad; 29 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 30 | 31 | @RequestFilters(JenkinsAuthenticationFilter.class) 32 | @Consumes(MediaType.APPLICATION_JSON) 33 | @Path("/") 34 | public interface StatisticsApi { 35 | 36 | @Named("statistics:overall-load") 37 | @Path("/overallLoad/api/json") 38 | @GET 39 | OverallLoad overallLoad(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/SystemApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.HEAD; 23 | import javax.ws.rs.POST; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.core.MediaType; 26 | 27 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 28 | import com.cdancy.jenkins.rest.parsers.RequestStatusParser; 29 | import org.jclouds.rest.annotations.RequestFilters; 30 | import org.jclouds.rest.annotations.ResponseParser; 31 | import org.jclouds.rest.annotations.Fallback; 32 | 33 | import com.cdancy.jenkins.rest.domain.system.SystemInfo; 34 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 35 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 36 | import com.cdancy.jenkins.rest.parsers.SystemInfoFromJenkinsHeaders; 37 | 38 | @RequestFilters(JenkinsAuthenticationFilter.class) 39 | @Consumes(MediaType.APPLICATION_JSON) 40 | @Path("/") 41 | public interface SystemApi { 42 | 43 | @Named("system:info") 44 | @Fallback(JenkinsFallbacks.SystemInfoOnError.class) 45 | @ResponseParser(SystemInfoFromJenkinsHeaders.class) 46 | @HEAD 47 | SystemInfo systemInfo(); 48 | 49 | @Named("system:quiet-down") 50 | @Path("quietDown") 51 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 52 | @ResponseParser(RequestStatusParser.class) 53 | @Consumes(MediaType.TEXT_HTML) 54 | @POST 55 | RequestStatus quietDown(); 56 | 57 | @Named("system:cancel-quiet-down") 58 | @Path("cancelQuietDown") 59 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 60 | @ResponseParser(RequestStatusParser.class) 61 | @Consumes(MediaType.TEXT_HTML) 62 | @POST 63 | RequestStatus cancelQuietDown(); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/features/UserApi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.features; 19 | 20 | import javax.inject.Named; 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.POST; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.core.MediaType; 27 | 28 | import org.jclouds.Fallbacks; 29 | import org.jclouds.rest.annotations.Fallback; 30 | import org.jclouds.rest.annotations.Payload; 31 | import org.jclouds.rest.annotations.PayloadParam; 32 | import org.jclouds.rest.annotations.RequestFilters; 33 | 34 | import com.cdancy.jenkins.rest.domain.user.ApiToken; 35 | import com.cdancy.jenkins.rest.domain.user.User; 36 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 37 | import com.cdancy.jenkins.rest.fallbacks.JenkinsFallbacks; 38 | import com.cdancy.jenkins.rest.filters.JenkinsAuthenticationFilter; 39 | import com.cdancy.jenkins.rest.filters.JenkinsUserInjectionFilter; 40 | import com.cdancy.jenkins.rest.parsers.RequestStatusParser; 41 | import org.jclouds.rest.annotations.ResponseParser; 42 | 43 | /** 44 | * The UserApi. 45 | * 46 | * Implements some of the User Rest Api defined in Jenkins. 47 | * For the User Api, see User.java 48 | * For the Api Token, see ApiTokenProperty.java. 49 | */ 50 | @RequestFilters({JenkinsAuthenticationFilter.class, JenkinsUserInjectionFilter.class}) 51 | @Path("/user") 52 | public interface UserApi { 53 | 54 | @Named("user:get") 55 | @Path("/{user}/api/json") 56 | @Fallback(Fallbacks.NullOnNotFoundOr404.class) 57 | @Consumes(MediaType.APPLICATION_JSON) 58 | @GET 59 | User get(); 60 | 61 | @Named("user:generateNewToken") 62 | @Path("/{user}/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken") 63 | @Fallback(Fallbacks.NullOnNotFoundOr404.class) 64 | @Consumes(MediaType.APPLICATION_JSON) 65 | @Produces(MediaType.APPLICATION_FORM_URLENCODED) 66 | @Payload("newTokenName={tokenName}") 67 | @POST 68 | ApiToken generateNewToken(@PayloadParam(value = "tokenName") String tokenName); 69 | 70 | @Named("user:revoke") 71 | @Path("/{user}/descriptorByName/jenkins.security.ApiTokenProperty/revoke") 72 | @Fallback(JenkinsFallbacks.RequestStatusOnError.class) 73 | @ResponseParser(RequestStatusParser.class) 74 | @Produces(MediaType.APPLICATION_FORM_URLENCODED) 75 | @Payload("tokenUuid={tokenUuid}") 76 | @POST 77 | RequestStatus revoke(@PayloadParam(value = "tokenUuid") String tokenUuid); 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/filters/JenkinsNoCrumbAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.filters; 19 | 20 | import javax.inject.Inject; 21 | import javax.inject.Singleton; 22 | 23 | import com.cdancy.jenkins.rest.JenkinsAuthentication; 24 | import com.cdancy.jenkins.rest.auth.AuthenticationType; 25 | 26 | import org.jclouds.http.HttpException; 27 | import org.jclouds.http.HttpRequest; 28 | import org.jclouds.http.HttpRequestFilter; 29 | import com.google.common.net.HttpHeaders; 30 | 31 | @Singleton 32 | public class JenkinsNoCrumbAuthenticationFilter implements HttpRequestFilter { 33 | private final JenkinsAuthentication creds; 34 | 35 | @Inject 36 | JenkinsNoCrumbAuthenticationFilter(final JenkinsAuthentication creds) { 37 | this.creds = creds; 38 | } 39 | 40 | @Override 41 | public HttpRequest filter(final HttpRequest request) throws HttpException { 42 | if (creds.authType() == AuthenticationType.Anonymous) { 43 | return request; 44 | } else { 45 | final String authHeader = creds.authType().getAuthScheme() + " " + creds.authValue(); 46 | return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, authHeader).build(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/filters/JenkinsUserInjectionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.filters; 19 | 20 | import org.jclouds.http.HttpException; 21 | import org.jclouds.http.HttpRequest; 22 | import org.jclouds.http.HttpRequestFilter; 23 | 24 | import com.cdancy.jenkins.rest.JenkinsAuthentication; 25 | import static com.cdancy.jenkins.rest.JenkinsConstants.USER_IN_USER_API; 26 | 27 | import javax.inject.Inject; 28 | import javax.inject.Singleton; 29 | 30 | @Singleton 31 | public class JenkinsUserInjectionFilter implements HttpRequestFilter { 32 | 33 | private static final String USER_PLACE_HOLDER = "%7B" + USER_IN_USER_API + "%7D"; 34 | private final JenkinsAuthentication creds; 35 | 36 | @Inject 37 | public JenkinsUserInjectionFilter(final JenkinsAuthentication creds) { 38 | this.creds = creds; 39 | } 40 | 41 | @Override 42 | public HttpRequest filter(final HttpRequest request) throws HttpException { 43 | final String requestPath = request.getEndpoint().getRawPath().replaceAll(USER_PLACE_HOLDER, creds.identity); 44 | return request.toBuilder().fromHttpRequest(request).replacePath(requestPath).build(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/filters/ScrubNullFolderParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.filters; 19 | 20 | import org.jclouds.http.HttpException; 21 | import org.jclouds.http.HttpRequest; 22 | import org.jclouds.http.HttpRequestFilter; 23 | 24 | import javax.inject.Singleton; 25 | 26 | import static com.cdancy.jenkins.rest.JenkinsConstants.OPTIONAL_FOLDER_PATH_PARAM; 27 | 28 | @Singleton 29 | public class ScrubNullFolderParam implements HttpRequestFilter { 30 | 31 | private static final String SCRUB_NULL_PARAM = "/%7B" + OPTIONAL_FOLDER_PATH_PARAM + "%7D"; 32 | private static final String EMPTY_STRING = ""; 33 | 34 | @Override 35 | public HttpRequest filter(final HttpRequest request) throws HttpException { 36 | final String requestPath = request.getEndpoint().getRawPath().replaceAll(SCRUB_NULL_PARAM, EMPTY_STRING); 37 | return request.toBuilder().fromHttpRequest(request).replacePath(requestPath).build(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/BuildNumberToInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import java.io.InputStream; 21 | import java.io.InputStreamReader; 22 | 23 | import javax.inject.Singleton; 24 | 25 | import org.jclouds.http.HttpResponse; 26 | 27 | import com.google.common.base.Charsets; 28 | import com.google.common.base.Function; 29 | import com.google.common.base.Throwables; 30 | import com.google.common.io.CharStreams; 31 | 32 | /** 33 | * Created by dancc on 3/11/16. 34 | */ 35 | @Singleton 36 | public class BuildNumberToInteger implements Function { 37 | 38 | public Integer apply(HttpResponse response) { 39 | return Integer.valueOf(getTextOutput(response)); 40 | } 41 | 42 | public String getTextOutput(HttpResponse response) { 43 | InputStream is = null; 44 | try { 45 | is = response.getPayload().openStream(); 46 | return CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)).trim(); 47 | } catch (Exception e) { 48 | Throwables.propagate(e); 49 | } finally { 50 | if (is != null) { 51 | try { 52 | is.close(); 53 | } catch (Exception e) { 54 | Throwables.propagate(e); 55 | } 56 | } 57 | } 58 | 59 | return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/CrumbParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import static com.cdancy.jenkins.rest.JenkinsConstants.JENKINS_COOKIES_JSESSIONID; 21 | 22 | import com.cdancy.jenkins.rest.domain.crumb.Crumb; 23 | 24 | import com.google.common.base.Function; 25 | import java.io.IOException; 26 | import java.util.Collection; 27 | 28 | import javax.inject.Singleton; 29 | import javax.ws.rs.core.HttpHeaders; 30 | 31 | import org.jclouds.http.HttpResponse; 32 | import org.jclouds.util.Strings2; 33 | 34 | /** 35 | * Turn a valid response, but one that has no body, into a Crumb. 36 | */ 37 | @Singleton 38 | public class CrumbParser implements Function { 39 | 40 | @Override 41 | public Crumb apply(final HttpResponse input) { 42 | if (input == null) { 43 | throw new RuntimeException("Unexpected NULL HttpResponse object"); 44 | } 45 | 46 | final int statusCode = input.getStatusCode(); 47 | if (statusCode >= 200 && statusCode < 400) { 48 | try { 49 | return Crumb.create(crumbValue(input), sessionIdCookie(input)); 50 | } catch (final IOException e) { 51 | throw new RuntimeException(input.getStatusLine(), e); 52 | } 53 | } else { 54 | throw new RuntimeException(input.getStatusLine()); 55 | } 56 | } 57 | 58 | private static String crumbValue(HttpResponse input) throws IOException { 59 | return Strings2.toStringAndClose(input.getPayload().openStream()) 60 | .split(":")[1]; 61 | } 62 | 63 | private static String sessionIdCookie(HttpResponse input) { 64 | return setCookieValues(input).stream() 65 | .filter(c -> c.startsWith(JENKINS_COOKIES_JSESSIONID)) 66 | .findFirst() 67 | .orElse(""); 68 | } 69 | 70 | private static Collection setCookieValues(HttpResponse input) { 71 | Collection setCookieValues = input.getHeaders().get(HttpHeaders.SET_COOKIE); 72 | if(setCookieValues.isEmpty()) { 73 | return input.getHeaders().get(HttpHeaders.SET_COOKIE.toLowerCase()); 74 | } else { 75 | return setCookieValues; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/FolderPathParser.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.parsers; 2 | 3 | import com.google.common.base.Function; 4 | 5 | import javax.inject.Singleton; 6 | 7 | /* 8 | * Turn the optionalFolderPath param to jenkins URL style 9 | */ 10 | @Singleton 11 | public class FolderPathParser implements Function { 12 | 13 | public static final String EMPTY_STRING = ""; 14 | public static final String FOLDER_NAME_PREFIX = "job/"; 15 | public static final Character FOLDER_NAME_SEPARATOR = '/'; 16 | 17 | @Override 18 | public String apply(Object folderPath) { 19 | if(folderPath == null) { 20 | return EMPTY_STRING; 21 | } 22 | 23 | final StringBuilder path = new StringBuilder((String) folderPath); 24 | if (path.length() == 0) { 25 | return EMPTY_STRING; 26 | } 27 | 28 | if(path.charAt(0) == FOLDER_NAME_SEPARATOR){ 29 | path.deleteCharAt(0); 30 | } 31 | if (path.length() == 0) { 32 | return EMPTY_STRING; 33 | } 34 | 35 | if(path.charAt(path.length() - 1) == FOLDER_NAME_SEPARATOR) { 36 | path.deleteCharAt(path.length() - 1); 37 | } 38 | if (path.length() == 0) { 39 | return EMPTY_STRING; 40 | } 41 | 42 | final String[] folders = path.toString().split(Character.toString(FOLDER_NAME_SEPARATOR)); 43 | path.setLength(0); 44 | for(final String folder : folders) { 45 | path.append(FOLDER_NAME_PREFIX).append(folder).append(FOLDER_NAME_SEPARATOR); 46 | } 47 | return path.toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/LocationToQueueId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import java.util.regex.Matcher; 21 | import java.util.regex.Pattern; 22 | 23 | import javax.inject.Singleton; 24 | 25 | import org.jclouds.http.HttpResponse; 26 | 27 | import com.google.common.base.Function; 28 | import com.google.common.collect.Lists; 29 | 30 | import com.cdancy.jenkins.rest.domain.common.Error; 31 | import com.cdancy.jenkins.rest.domain.common.LongResponse; 32 | 33 | /** 34 | * Created by dancc on 3/11/16. 35 | */ 36 | @Singleton 37 | public class LocationToQueueId implements Function { 38 | 39 | private static final Pattern pattern = Pattern.compile("^.*/queue/item/(\\d+)/$"); 40 | 41 | public LongResponse apply(HttpResponse response) { 42 | if (response == null) { 43 | throw new RuntimeException("Unexpected NULL HttpResponse object"); 44 | } 45 | 46 | String url = response.getFirstHeaderOrNull("Location"); 47 | if (url != null) { 48 | Matcher matcher = pattern.matcher(url); 49 | if (matcher.find() && matcher.groupCount() == 1) { 50 | return LongResponse.create(Long.valueOf(matcher.group(1)), null); 51 | } 52 | } 53 | final Error error = Error.create(null, 54 | "No queue item Location header could be found despite getting a valid HTTP response.", 55 | NumberFormatException.class.getCanonicalName()); 56 | return LongResponse.create(null, Lists.newArrayList(error)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/OptionalFolderPathParser.java: -------------------------------------------------------------------------------- 1 | package com.cdancy.jenkins.rest.parsers; 2 | 3 | import com.google.common.base.Function; 4 | 5 | import javax.inject.Singleton; 6 | 7 | /* 8 | * Turn the optionalFolderPath param to jenkins URL style 9 | */ 10 | @Singleton 11 | public class OptionalFolderPathParser implements Function { 12 | 13 | public static final String EMPTY_STRING = ""; 14 | public static final String FOLDER_NAME_PREFIX = "job/"; 15 | public static final Character FOLDER_NAME_SEPARATOR = '/'; 16 | 17 | @Override 18 | public String apply(Object optionalFolderPath) { 19 | if(optionalFolderPath == null) { 20 | return EMPTY_STRING; 21 | } 22 | 23 | final StringBuilder path = new StringBuilder((String) optionalFolderPath); 24 | if (path.length() == 0) { 25 | return EMPTY_STRING; 26 | } 27 | 28 | if(path.charAt(0) == FOLDER_NAME_SEPARATOR){ 29 | path.deleteCharAt(0); 30 | } 31 | if (path.length() == 0) { 32 | return EMPTY_STRING; 33 | } 34 | 35 | if(path.charAt(path.length() - 1) == FOLDER_NAME_SEPARATOR) { 36 | path.deleteCharAt(path.length() - 1); 37 | } 38 | if (path.length() == 0) { 39 | return EMPTY_STRING; 40 | } 41 | 42 | final String[] folders = path.toString().split(Character.toString(FOLDER_NAME_SEPARATOR)); 43 | path.setLength(0); 44 | for(final String folder : folders) { 45 | path.append(FOLDER_NAME_PREFIX).append(folder).append(FOLDER_NAME_SEPARATOR); 46 | } 47 | 48 | return path.toString(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/OutputToProgressiveText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import java.io.InputStream; 21 | import java.io.InputStreamReader; 22 | 23 | import javax.inject.Singleton; 24 | 25 | import org.jclouds.http.HttpResponse; 26 | 27 | import com.cdancy.jenkins.rest.domain.job.ProgressiveText; 28 | import com.google.common.base.Charsets; 29 | import com.google.common.base.Function; 30 | import com.google.common.io.CharStreams; 31 | 32 | /** 33 | * Created by dancc on 3/11/16. 34 | */ 35 | @Singleton 36 | public class OutputToProgressiveText implements Function { 37 | 38 | public ProgressiveText apply(HttpResponse response) { 39 | 40 | String text = getTextOutput(response); 41 | int size = getTextSize(response); 42 | boolean hasMoreData = getMoreData(response); 43 | return ProgressiveText.create(text, size, hasMoreData); 44 | } 45 | 46 | public String getTextOutput(HttpResponse response) { 47 | try (InputStream is = response.getPayload().openStream()) { 48 | return CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); 49 | } catch (Exception e) { 50 | // ignore 51 | } 52 | // ignore 53 | 54 | return null; 55 | } 56 | 57 | public int getTextSize(HttpResponse response) { 58 | String textSize = response.getFirstHeaderOrNull("X-Text-Size"); 59 | return textSize != null ? Integer.parseInt(textSize) : -1; 60 | } 61 | 62 | public boolean getMoreData(HttpResponse response) { 63 | String moreData = response.getFirstHeaderOrNull("X-More-Data"); 64 | return Boolean.parseBoolean(moreData); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/RequestStatusParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 21 | import com.google.common.base.Function; 22 | import javax.inject.Singleton; 23 | import org.jclouds.http.HttpResponse; 24 | 25 | /** 26 | * Turn a valid response, but one that has no body, into a RequestStatus. 27 | */ 28 | @Singleton 29 | public class RequestStatusParser implements Function { 30 | 31 | @Override 32 | public RequestStatus apply(final HttpResponse input) { 33 | if (input == null) { 34 | throw new RuntimeException("Unexpected NULL HttpResponse object"); 35 | } 36 | 37 | final int statusCode = input.getStatusCode(); 38 | if (statusCode >= 200 && statusCode < 400) { 39 | return RequestStatus.create(true, null); 40 | } else { 41 | throw new RuntimeException(input.getStatusLine()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/cdancy/jenkins/rest/parsers/SystemInfoFromJenkinsHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest.parsers; 19 | 20 | import javax.inject.Singleton; 21 | 22 | import org.jclouds.http.HttpResponse; 23 | 24 | import com.cdancy.jenkins.rest.domain.system.SystemInfo; 25 | 26 | import com.google.common.base.Function; 27 | 28 | /** 29 | * Created by dancc on 3/11/16. 30 | */ 31 | @Singleton 32 | public class SystemInfoFromJenkinsHeaders implements Function { 33 | 34 | @Override 35 | public SystemInfo apply(HttpResponse response) { 36 | if (response == null) { 37 | throw new RuntimeException("Unexpected NULL HttpResponse object"); 38 | } 39 | 40 | final int statusCode = response.getStatusCode(); 41 | if (statusCode >= 200 && statusCode < 400) { 42 | return SystemInfo.create(response.getFirstHeaderOrNull("X-Hudson"), response.getFirstHeaderOrNull("X-Jenkins"), 43 | response.getFirstHeaderOrNull("X-Jenkins-Session"), 44 | response.getFirstHeaderOrNull("X-Instance-Identity"), response.getFirstHeaderOrNull("X-SSH-Endpoint"), 45 | response.getFirstHeaderOrNull("Server"), null); 46 | } else { 47 | throw new RuntimeException(response.getStatusLine()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/JenkinsApiMetadataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest; 19 | 20 | import org.jclouds.apis.ApiMetadata; 21 | import org.jclouds.apis.Apis; 22 | import org.jclouds.apis.internal.BaseApiMetadataTest; 23 | import org.testng.annotations.Test; 24 | 25 | import java.util.HashSet; 26 | 27 | import static org.testng.Assert.*; 28 | 29 | /** 30 | * Unit tests for the {@link JenkinsApiMetadata} class. 31 | */ 32 | @Test(groups = "unit", testName = "JenkinsApiMetadataTest") 33 | public class JenkinsApiMetadataTest extends BaseApiMetadataTest { 34 | 35 | public JenkinsApiMetadataTest() { 36 | super(new JenkinsApiMetadata(), new HashSet<>()); 37 | } 38 | 39 | public void testEtcdApiRegistered() { 40 | ApiMetadata api = Apis.withId("jenkins"); 41 | 42 | assertNotNull(api); 43 | assertTrue(api instanceof JenkinsApiMetadata); 44 | assertEquals(api.getId(), "jenkins"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/TestUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.cdancy.jenkins.rest; 19 | 20 | /** 21 | * Static methods for generating test data. 22 | */ 23 | public class TestUtilities extends JenkinsUtils { 24 | 25 | public static final String TEST_CREDENTIALS_SYSTEM_PROPERTY = "test.jenkins.usernamePassword"; 26 | public static final String TEST_CREDENTIALS_ENVIRONMENT_VARIABLE = TEST_CREDENTIALS_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); 27 | 28 | public static final String TEST_API_TOKEN_SYSTEM_PROPERTY = "test.jenkins.usernameApiToken"; 29 | public static final String TEST_API_TOKEN_ENVIRONMENT_VARIABLE = TEST_API_TOKEN_SYSTEM_PROPERTY.replaceAll("\\.", "_").toUpperCase(); 30 | 31 | /** 32 | * Find credentials (ApiToken, UsernamePassword, or Anonymous) from system/environment. 33 | * 34 | * @return JenkinsCredentials 35 | */ 36 | public static JenkinsAuthentication inferTestAuthentication() { 37 | 38 | final JenkinsAuthentication.Builder inferAuth = JenkinsAuthentication.builder(); 39 | 40 | // 1.) Check for API Token as this requires no crumb hence is faster 41 | String authValue = JenkinsUtils 42 | .retriveExternalValue(TEST_API_TOKEN_SYSTEM_PROPERTY, 43 | TEST_API_TOKEN_ENVIRONMENT_VARIABLE); 44 | if (authValue != null) { 45 | inferAuth.apiToken(authValue); 46 | return inferAuth.build(); 47 | } 48 | 49 | // 2.) Check for UsernamePassword auth credentials. 50 | authValue = JenkinsUtils 51 | .retriveExternalValue(TEST_CREDENTIALS_SYSTEM_PROPERTY, 52 | TEST_CREDENTIALS_ENVIRONMENT_VARIABLE); 53 | if (authValue != null) { 54 | inferAuth.credentials(authValue); 55 | return inferAuth.build(); 56 | } 57 | 58 | // 3.) If neither #1 or #2 find anything "Anonymous" access is assumed. 59 | return inferAuth.build(); 60 | } 61 | 62 | private TestUtilities() { 63 | throw new UnsupportedOperationException("Purposefully not implemented"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/ConfigurationAsCodeApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertTrue; 20 | import static org.testng.Assert.assertFalse; 21 | 22 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 23 | import org.testng.annotations.Test; 24 | 25 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 26 | 27 | @Test(groups = "live", testName = "ConfigurationAsCodeApiLiveTest", singleThreaded = true) 28 | public class ConfigurationAsCodeApiLiveTest extends BaseJenkinsApiLiveTest { 29 | 30 | @Test 31 | public void testCascCheck() { 32 | String config = payloadFromResource("/casc.yml"); 33 | RequestStatus success = api().check(config); 34 | assertTrue(success.value()); 35 | } 36 | 37 | @Test 38 | public void testCascApply() { 39 | String config = payloadFromResource("/casc.yml"); 40 | RequestStatus success = api().apply(config); 41 | assertTrue(success.value()); 42 | } 43 | 44 | @Test 45 | public void testBadCascCheck() { 46 | String config = payloadFromResource("/casc-bad.yml"); 47 | RequestStatus success = api().check(config); 48 | assertFalse(success.value()); 49 | } 50 | 51 | @Test 52 | public void testBadCascApply() { 53 | String config = payloadFromResource("/casc-bad.yml"); 54 | RequestStatus success = api().apply(config); 55 | assertFalse(success.value()); 56 | } 57 | 58 | private ConfigurationAsCodeApi api() { 59 | return api.configurationAsCodeApi(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/CrumbIssuerApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertNotNull; 20 | import static org.testng.Assert.assertTrue; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 25 | import com.cdancy.jenkins.rest.domain.crumb.Crumb; 26 | 27 | @Test(groups = "live", testName = "CrumbIssuerApiLiveTest", singleThreaded = true) 28 | public class CrumbIssuerApiLiveTest extends BaseJenkinsApiLiveTest { 29 | 30 | @Test 31 | public void testGetCrumb() { 32 | final Crumb crumb = api().crumb(); 33 | assertNotNull(crumb); 34 | assertNotNull(crumb.value()); 35 | assertTrue(crumb.errors().isEmpty()); 36 | } 37 | 38 | private CrumbIssuerApi api() { 39 | return api.crumbIssuerApi(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/CrumbIssuerApiMockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import okhttp3.mockwebserver.MockResponse; 20 | import okhttp3.mockwebserver.MockWebServer; 21 | import org.testng.annotations.Test; 22 | 23 | import com.cdancy.jenkins.rest.JenkinsApi; 24 | import com.cdancy.jenkins.rest.BaseJenkinsMockTest; 25 | import com.cdancy.jenkins.rest.domain.crumb.Crumb; 26 | 27 | import javax.ws.rs.core.MediaType; 28 | 29 | import static org.testng.Assert.*; 30 | 31 | /** 32 | * Mock tests for the {@link com.cdancy.jenkins.rest.features.CrumbIssuerApi} class. 33 | */ 34 | @Test(groups = "unit", testName = "CrumbIssuerApiMockTest") 35 | public class CrumbIssuerApiMockTest extends BaseJenkinsMockTest { 36 | 37 | public void testGetSystemInfo() throws Exception { 38 | MockWebServer server = mockWebServer(); 39 | 40 | final String value = "04a1109fc2db171362c966ebe9fc87f0"; 41 | server.enqueue(new MockResponse().setBody("Jenkins-Crumb:" + value).setResponseCode(200)); 42 | JenkinsApi jenkinsApi = api(server.url("/").url()); 43 | CrumbIssuerApi api = jenkinsApi.crumbIssuerApi(); 44 | try { 45 | final Crumb instance = api.crumb(); 46 | assertNotNull(instance); 47 | assertEquals(instance.value(), value); 48 | assertSentAccept(server, "GET", "/crumbIssuer/api/xml?xpath=concat%28//crumbRequestField,%22%3A%22,//crumb%29", MediaType.TEXT_PLAIN); 49 | } finally { 50 | jenkinsApi.close(); 51 | server.shutdown(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/PluginManagerApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertFalse; 20 | import static org.testng.Assert.assertNotNull; 21 | import static org.testng.Assert.assertTrue; 22 | 23 | import org.testng.annotations.Test; 24 | 25 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 26 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 27 | import com.cdancy.jenkins.rest.domain.plugins.Plugins; 28 | 29 | @Test(groups = "live", testName = "PluginManagerApiLiveTest", singleThreaded = true) 30 | public class PluginManagerApiLiveTest extends BaseJenkinsApiLiveTest { 31 | 32 | @Test 33 | public void testGetPlugins() { 34 | final Plugins plugins = api().plugins(3, null); 35 | assertNotNull(plugins); 36 | assertTrue(plugins.errors().isEmpty()); 37 | assertFalse(plugins.plugins().isEmpty()); 38 | assertNotNull(plugins.plugins().get(0).shortName()); 39 | } 40 | 41 | @Test 42 | public void testInstallNecessaryPlugins() { 43 | final RequestStatus status = api().installNecessaryPlugins("artifactory@2.2.1"); 44 | assertNotNull(status); 45 | assertTrue(status.value()); 46 | assertTrue(status.errors().isEmpty()); 47 | } 48 | 49 | private PluginManagerApi api() { 50 | return api.pluginManagerApi(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/StatisticsApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertNotNull; 20 | 21 | import org.testng.annotations.Test; 22 | 23 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 24 | import com.cdancy.jenkins.rest.domain.statistics.OverallLoad; 25 | 26 | @Test(groups = "live", testName = "StatisticsApiLiveTest", singleThreaded = true) 27 | public class StatisticsApiLiveTest extends BaseJenkinsApiLiveTest { 28 | @Test 29 | public void testOverallLoad() { 30 | OverallLoad load = api().overallLoad(); 31 | assertNotNull(load); 32 | } 33 | private StatisticsApi api() { 34 | return api.statisticsApi(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/StatisticsApiMockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertNotNull; 20 | 21 | import okhttp3.mockwebserver.MockResponse; 22 | import okhttp3.mockwebserver.MockWebServer; 23 | import org.testng.annotations.Test; 24 | 25 | import com.cdancy.jenkins.rest.JenkinsApi; 26 | import com.cdancy.jenkins.rest.domain.statistics.OverallLoad; 27 | import com.cdancy.jenkins.rest.BaseJenkinsMockTest; 28 | 29 | /** 30 | * Mock tests for the {@link com.cdancy.jenkins.rest.features.StatisticsApi} 31 | * class. 32 | */ 33 | @Test(groups = "unit", testName = "StatisticsApiMockTest") 34 | public class StatisticsApiMockTest extends BaseJenkinsMockTest { 35 | 36 | public void testOverallLoad() throws Exception { 37 | MockWebServer server = mockWebServer(); 38 | 39 | server.enqueue(new MockResponse().setBody(payloadFromResource("/overall-load.json")).setResponseCode(200)); 40 | JenkinsApi jenkinsApi = api(server.url("/").url()); 41 | StatisticsApi api = jenkinsApi.statisticsApi(); 42 | try { 43 | OverallLoad load = api.overallLoad(); 44 | assertNotNull(load); 45 | assertSent(server, "GET", "/overallLoad/api/json"); 46 | } finally { 47 | jenkinsApi.close(); 48 | server.shutdown(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/SystemApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import static org.testng.Assert.assertNotNull; 20 | import static org.testng.Assert.assertTrue; 21 | 22 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 23 | import org.testng.annotations.Test; 24 | 25 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 26 | import com.cdancy.jenkins.rest.domain.system.SystemInfo; 27 | 28 | @Test(groups = "live", testName = "SystemApiLiveTest", singleThreaded = true) 29 | public class SystemApiLiveTest extends BaseJenkinsApiLiveTest { 30 | 31 | @Test 32 | public void testGetSystemInfo() { 33 | final SystemInfo version = api().systemInfo(); 34 | assertNotNull(version); 35 | assertNotNull(version.jenkinsVersion()); 36 | } 37 | 38 | @Test 39 | public void testQuietDown() { 40 | RequestStatus success = api().quietDown(); 41 | assertNotNull(success); 42 | assertTrue(success.value()); 43 | } 44 | 45 | @Test(dependsOnMethods = "testQuietDown") 46 | public void testAlreadyQuietDown() { 47 | RequestStatus success = api().quietDown(); 48 | assertNotNull(success); 49 | assertTrue(success.value()); 50 | } 51 | 52 | @Test(dependsOnMethods = "testAlreadyQuietDown") 53 | public void testCancelQuietDown() { 54 | RequestStatus success = api().cancelQuietDown(); 55 | assertNotNull(success); 56 | assertTrue(success.value()); 57 | } 58 | 59 | @Test(dependsOnMethods = "testCancelQuietDown") 60 | public void testAlreadyCanceledQuietDown() { 61 | RequestStatus success = api().cancelQuietDown(); 62 | assertNotNull(success); 63 | assertTrue(success.value()); 64 | } 65 | 66 | private SystemApi api() { 67 | return api.systemApi(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/cdancy/jenkins/rest/features/UserApiLiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.cdancy.jenkins.rest.features; 18 | 19 | import com.cdancy.jenkins.rest.BaseJenkinsApiLiveTest; 20 | import com.cdancy.jenkins.rest.domain.common.RequestStatus; 21 | import com.cdancy.jenkins.rest.domain.user.*; 22 | import org.testng.annotations.Test; 23 | 24 | import static org.testng.Assert.*; 25 | 26 | @Test(groups = "live", testName = "UserApiLiveTest", singleThreaded = true) 27 | public class UserApiLiveTest extends BaseJenkinsApiLiveTest { 28 | 29 | ApiToken token; 30 | 31 | @Test 32 | public void testGetUser() { 33 | User user = api().get(); 34 | assertNotNull(user); 35 | assertNotNull(user.absoluteUrl()); 36 | assertEquals(user.absoluteUrl(), System.getProperty("test.jenkins.endpoint") + "/user/admin"); 37 | assertTrue(user.description() == null || user.description().equals("")); 38 | assertNotNull(user.fullName()); 39 | assertEquals(user.fullName(), "admin"); 40 | assertNotNull(user.id()); 41 | assertEquals(user.id(), "admin"); 42 | } 43 | 44 | @Test 45 | public void testGenerateNewToken() { 46 | token = api().generateNewToken("user-api-test-token"); 47 | assertNotNull(token); 48 | assertEquals(token.status(), "ok"); 49 | assertNotNull(token.data()); 50 | assertNotNull(token.data().tokenName()); 51 | assertEquals(token.data().tokenName(), "user-api-test-token"); 52 | assertNotNull(token.data().tokenUuid()); 53 | assertNotNull(token.data().tokenValue()); 54 | } 55 | 56 | @Test(dependsOnMethods = "testGenerateNewToken") 57 | public void testRevokeApiToken() { 58 | RequestStatus status = api().revoke(token.data().tokenUuid()); 59 | // Jenkins returns 200 whether the tokenUuid is correct or not. 60 | assertTrue(status.value()); 61 | } 62 | 63 | @Test 64 | public void testRevokeApiTokenWithEmptyUuid() { 65 | RequestStatus status = api().revoke(""); 66 | assertFalse(status.value()); 67 | // TODO: Deal with the HTML response from Jenkins Stapler 68 | } 69 | 70 | private UserApi api() { 71 | return api.userApi(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/resources/api-token.json: -------------------------------------------------------------------------------- 1 | { 2 | "status":"ok", 3 | "data":{ 4 | "tokenName":"kb-token", 5 | "tokenUuid":"8c42630b-4be5-4f51-b4e9-f17a8ac07521", 6 | "tokenValue":"112fe6e9b1b94eb1ee58f0ea4f5a1ac7bf" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/resources/build-info-empty-and-null-params.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions" : [ 3 | { 4 | "parameters" : [ 5 | { 6 | "name" : "bear", 7 | "value" : "null" 8 | }, 9 | { 10 | "name" : "fish", 11 | "value" : "" 12 | } 13 | ] 14 | }, 15 | { 16 | "causes" : [ 17 | { 18 | "shortDescription" : "Started by user anonymous", 19 | "userId" : null, 20 | "userName" : "anonymous" 21 | } 22 | ] 23 | } 24 | ], 25 | "artifacts" : [ 26 | { 27 | "displayPath" : "fish.txt", 28 | "fileName" : "fish.txt", 29 | "relativePath" : "fish.txt" 30 | } 31 | ], 32 | "building" : false, 33 | "description" : null, 34 | "displayName" : "#10", 35 | "duration" : 60750, 36 | "estimatedDuration" : 60258, 37 | "executor" : null, 38 | "fullDisplayName" : "fish #10", 39 | "id" : "10", 40 | "keepLog" : false, 41 | "number" : 10, 42 | "queueId" : 73, 43 | "result" : "SUCCESS", 44 | "timestamp" : 1461091892486, 45 | "url" : "http://localhost:32769/job/fish/10/", 46 | "builtOn" : "", 47 | "changeSet" : { 48 | "items" : [ 49 | 50 | ], 51 | "kind" : null 52 | }, 53 | "culprits" : [ 54 | { 55 | "absoluteUrl": "http://localhost:8080/user/username", 56 | "fullName": "username" 57 | } 58 | ] 59 | } -------------------------------------------------------------------------------- /src/test/resources/build-info-git-commit.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions" : [ 3 | { 4 | "parameters" : [ 5 | { 6 | "name" : "bear", 7 | "value" : true 8 | }, 9 | { 10 | "name" : "fish", 11 | "value" : "salmon" 12 | } 13 | ] 14 | }, 15 | { 16 | "causes" : [ 17 | { 18 | "shortDescription" : "Started by user anonymous", 19 | "userId" : null, 20 | "userName" : "anonymous" 21 | } 22 | ] 23 | } 24 | ], 25 | "artifacts" : [ 26 | { 27 | "displayPath" : "fish.txt", 28 | "fileName" : "fish.txt", 29 | "relativePath" : "fish.txt" 30 | } 31 | ], 32 | "building" : false, 33 | "description" : null, 34 | "displayName" : "#10", 35 | "duration" : 60750, 36 | "estimatedDuration" : 60258, 37 | "executor" : null, 38 | "fullDisplayName" : "fish #10", 39 | "id" : "10", 40 | "keepLog" : false, 41 | "number" : 10, 42 | "queueId" : 73, 43 | "result" : "SUCCESS", 44 | "timestamp" : 1461091892486, 45 | "url" : "http://localhost:32769/job/fish/10/", 46 | "builtOn" : "", 47 | "changeSets" : [ 48 | { 49 | "_class" : "hudson.plugins.git.GitChangeSetList", 50 | "items" : [ 51 | { 52 | "_class" : "hudson.plugins.git.GitChangeSet", 53 | "affectedPaths" : [ 54 | "some/path/in/the/repository" 55 | ], 56 | "commitId" : "d27afa0805201322d846d7defc29b82c88d9b5ce", 57 | "timestamp" : 1461091892486, 58 | "author" : { 59 | "absoluteUrl": "http://localhost:8080/user/username", 60 | "fullName": "username" 61 | }, 62 | "authorEmail" : "username@localhost", 63 | "comment" : "Commit comment\n", 64 | "date" : "2016-04-19 18:51:32 GMT", 65 | "id" : "d27afa0805201322d846d7defc29b82c88d9b5ce", 66 | "msg" : "Commit comment", 67 | "paths" : [ 68 | { 69 | "editType" : "add", 70 | "file" : "some/path/in/the/repository" 71 | } 72 | ] 73 | } 74 | ], 75 | "kind" : "git" 76 | } 77 | 78 | ], 79 | "culprits" : [ 80 | { 81 | "absoluteUrl": "http://localhost:8080/user/username", 82 | "fullName": "username" 83 | } 84 | ] 85 | } -------------------------------------------------------------------------------- /src/test/resources/build-info-no-params.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.CauseAction", 6 | "causes" : [ 7 | { 8 | "_class" : "hudson.model.Cause$UserIdCause", 9 | "shortDescription" : "Started by user anonymous", 10 | "userId" : null, 11 | "userName" : "anonymous" 12 | } 13 | ] 14 | }, 15 | { 16 | "_class" : "jenkins.metrics.impl.TimeInQueueAction" 17 | }, 18 | { 19 | 20 | }, 21 | { 22 | 23 | }, 24 | { 25 | 26 | }, 27 | { 28 | 29 | }, 30 | { 31 | "_class" : "org.jenkinsci.plugins.workflow.job.views.FlowGraphAction" 32 | }, 33 | { 34 | 35 | }, 36 | { 37 | 38 | } 39 | ], 40 | "artifacts" : [ 41 | 42 | ], 43 | "building" : false, 44 | "description" : null, 45 | "displayName" : "#10", 46 | "duration" : 60750, 47 | "estimatedDuration" : 60258, 48 | "executor" : null, 49 | "fullDisplayName" : "fish #10", 50 | "id" : "10", 51 | "keepLog" : false, 52 | "number" : 10, 53 | "queueId" : 73, 54 | "result" : "SUCCESS", 55 | "timestamp" : 1461091892486, 56 | "url" : "http://localhost:32769/job/fish/10/", 57 | "builtOn" : "", 58 | "changeSet" : { 59 | "items" : [ 60 | 61 | ], 62 | "kind" : null 63 | }, 64 | "culprits" : [ 65 | { 66 | "absoluteUrl": "http://localhost:8080/user/username", 67 | "fullName": "username" 68 | } 69 | ] 70 | } -------------------------------------------------------------------------------- /src/test/resources/build-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions" : [ 3 | { 4 | "parameters" : [ 5 | { 6 | "name" : "bear", 7 | "value" : true 8 | }, 9 | { 10 | "name" : "fish", 11 | "value" : "salmon" 12 | } 13 | ] 14 | }, 15 | { 16 | "causes" : [ 17 | { 18 | "shortDescription" : "Started by user anonymous", 19 | "userId" : null, 20 | "userName" : "anonymous" 21 | } 22 | ] 23 | }, 24 | { 25 | "text" : "There could be HTML text here", 26 | "iconPath" : "clipboard.png", 27 | "_class" : "com.jenkinsci.plugins.badge.action.BadgeSummaryAction" 28 | }, 29 | {}, 30 | { 31 | "_class" : "org.jenkinsci.plugins.displayurlapi.actions.RunDisplayAction" 32 | } 33 | ], 34 | "artifacts" : [ 35 | { 36 | "displayPath" : "fish.txt", 37 | "fileName" : "fish.txt", 38 | "relativePath" : "fish.txt" 39 | } 40 | ], 41 | "building" : false, 42 | "description" : null, 43 | "displayName" : "#10", 44 | "duration" : 60750, 45 | "estimatedDuration" : 60258, 46 | "executor" : null, 47 | "fullDisplayName" : "fish #10", 48 | "id" : "10", 49 | "keepLog" : false, 50 | "number" : 10, 51 | "queueId" : 73, 52 | "result" : "SUCCESS", 53 | "timestamp" : 1461091892486, 54 | "url" : "http://localhost:32769/job/fish/10/", 55 | "builtOn" : "", 56 | "changeSet" : { 57 | "items" : [ 58 | 59 | ], 60 | "kind" : null 61 | }, 62 | "culprits" : [ 63 | { 64 | "absoluteUrl": "http://localhost:8080/user/username", 65 | "fullName": "username" 66 | } 67 | ] 68 | } 69 | -------------------------------------------------------------------------------- /src/test/resources/build-number.txt: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /src/test/resources/build-timestamp.txt: -------------------------------------------------------------------------------- 1 | 4/15/16 6:26 PM -------------------------------------------------------------------------------- /src/test/resources/casc-bad.yml: -------------------------------------------------------------------------------- 1 | jenk 2 | -------------------------------------------------------------------------------- /src/test/resources/casc.yml: -------------------------------------------------------------------------------- 1 | jenkins: 2 | systemMessage: "Jenkins REST API Configuration as code test" 3 | -------------------------------------------------------------------------------- /src/test/resources/folder-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All 8 | false 9 | false 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | false 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project-empty-and-null-params.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HelloWorld 5 | false 6 | 7 | 8 | 9 | 10 | SomeKey1 11 | whatever1 12 | 13 | 14 | SomeKey2 15 | whatever2 16 | 17 | 18 | 19 | 20 | 21 | true 22 | false 23 | false 24 | false 25 | 26 | false 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project-no-params.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HelloWorld 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project-sleep-10-task.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | 15 | 16 | echo begin 17 | sleep 10 18 | echo end 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project-sleep-task-multiple-params.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HelloWorld 5 | false 6 | 7 | 8 | 9 | 10 | SomeKey1 11 | whatever1 12 | SomeValue1 13 | 14 | 15 | SomeKey2 16 | whatever2 17 | SomeValue2 18 | 19 | 20 | SomeKey3 21 | whatever3 22 | SomeValue3 23 | 24 | 25 | 26 | 27 | 28 | true 29 | false 30 | false 31 | false 32 | 33 | false 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project-sleep-task.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | true 9 | false 10 | false 11 | false 12 | 13 | false 14 | 15 | 16 | echo begin 17 | sleep 2 18 | echo end 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/resources/freestyle-project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HelloWorld 5 | false 6 | 7 | 8 | 9 | 10 | SomeKey 11 | whatever 12 | SomeValue 13 | 14 | 15 | 16 | 17 | 18 | true 19 | false 20 | false 21 | false 22 | 23 | false 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/test/resources/jobsInJenkinsFolder.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "com.cloudbees.hudson.plugins.folder.Folder", 3 | "jobs" : [ 4 | { 5 | "_class" : "hudson.model.FreeStyleProject", 6 | "name" : "Test Project", 7 | "url": "http://localhost:8080/job/username" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /src/test/resources/jobsInRootFolder.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Hudson", 3 | "jobs" : [ 4 | { 5 | "_class" : "hudson.maven.MavenModuleSet", 6 | "name" : "Test Tool", 7 | "url": "http://localhost:32769/job/fish-test/" 8 | }, 9 | { 10 | "_class" : "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject", 11 | "name" : "Test MultiBranch Project", 12 | "url": "http://localhost:32769/job/fish-multibranch/" 13 | }, 14 | { 15 | "_class" : "com.cloudbees.hudson.plugins.folder.Folder", 16 | "name" : "Test Folder", 17 | "url": "http://localhost:32769/job/fish-folder/" 18 | }, 19 | { 20 | "_class" : "com.cloudbees.tiger.plugins.palace.templates.DockerSlaveTemplate", 21 | "name" : "Test Docker Slave", 22 | "url":"http://localhost:32769/job/fish-agent/" 23 | }, 24 | { 25 | "_class" : "hudson.model.FreeStyleProject", 26 | "name" : "Test Free Style", 27 | "url": "http://localhost:32769/job/fish-project/", 28 | "color": "red" 29 | }, 30 | { 31 | "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowJob", 32 | "name" : "Test Workflow Job", 33 | "url": "http://localhost:32769/job/fish-workflow/" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resources/overall-load.json: -------------------------------------------------------------------------------- 1 | { 2 | "availableExecutors":{ 3 | 4 | }, 5 | "busyExecutors":{ 6 | 7 | }, 8 | "connectingExecutors":{ 9 | 10 | }, 11 | "definedExecutors":{ 12 | 13 | }, 14 | "idleExecutors":{ 15 | 16 | }, 17 | "onlineExecutors":{ 18 | 19 | }, 20 | "queueLength":{ 21 | 22 | }, 23 | "totalExecutors":{ 24 | 25 | }, 26 | "totalQueueLength":{ 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /src/test/resources/pipeline-node.json: -------------------------------------------------------------------------------- 1 | { 2 | "_links": { 3 | "self": { 4 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/5/wfapi/describe" 5 | } 6 | }, 7 | "id": "5", 8 | "name": "Build", 9 | "status": "SUCCESS", 10 | "startTimeMillis": 1413461275770, 11 | "durationMillis": 5228, 12 | "stageFlowNodes": [ 13 | { 14 | "_links": { 15 | "self": { 16 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/6/wfapi/describe" 17 | }, 18 | "log": { 19 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/6/wfapi/log" 20 | } 21 | }, 22 | "id": "6", 23 | "name": "Git", 24 | "status": "SUCCESS", 25 | "startTimeMillis": 1413461275783, 26 | "durationMillis": 9, 27 | "parentNodes": [ 28 | "5" 29 | ] 30 | }, 31 | { 32 | "_links": { 33 | "self": { 34 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/7/wfapi/describe" 35 | }, 36 | "log": { 37 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/7/wfapi/log" 38 | } 39 | }, 40 | "id": "7", 41 | "name": "Shell Script", 42 | "status": "SUCCESS", 43 | "startTimeMillis": 1413461275792, 44 | "durationMillis": 5206, 45 | "parentNodes": [ 46 | "6" 47 | ] 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /src/test/resources/pipeline-with-action.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | 7 | 8 | true 9 | 10 | 11 | false 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/pipeline.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | 7 | 8 | true 9 | 10 | 11 | false 12 | 13 | -------------------------------------------------------------------------------- /src/test/resources/pipelineNodeLog.json: -------------------------------------------------------------------------------- 1 | { 2 | "nodeId": "6", 3 | "nodeStatus": "FAILED", 4 | "length": 295, 5 | "hasMore": false, 6 | "text": " > git rev-parse --is-inside-work-tree\nFetching changes from the remote Git repository\n > git config remote.origin.url https://github.com/tfennelly/simple-maven-project-with-test.git\nFetching upstream changes from https://github.com/tfennelly/simple-maven-project-with-test.git\n > git --version\n", 7 | "consoleUrl": "/jenkins/job/Build%20Github%20Repo/14/execution/node/6/log" 8 | } -------------------------------------------------------------------------------- /src/test/resources/plugins.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class":"hudson.LocalPluginManager", 3 | "plugins":[ 4 | { 5 | "active":true, 6 | "backupVersion":null, 7 | "bundled":false, 8 | "deleted":false, 9 | "dependencies":[ 10 | { 11 | "optional":false, 12 | "shortName":"pipeline-input-step", 13 | "version":"2.5" 14 | }, 15 | { 16 | "optional":false, 17 | "shortName":"workflow-job", 18 | "version":"2.9" 19 | }, 20 | { 21 | "optional":false, 22 | "shortName":"workflow-basic-steps", 23 | "version":"2.3" 24 | }, 25 | { 26 | "optional":false, 27 | "shortName":"workflow-durable-task-step", 28 | "version":"2.8" 29 | }, 30 | { 31 | "optional":false, 32 | "shortName":"workflow-api", 33 | "version":"2.8" 34 | }, 35 | { 36 | "optional":false, 37 | "shortName":"workflow-cps", 38 | "version":"2.24" 39 | }, 40 | { 41 | "optional":false, 42 | "shortName":"workflow-support", 43 | "version":"2.12" 44 | }, 45 | { 46 | "optional":false, 47 | "shortName":"workflow-cps-global-lib", 48 | "version":"2.5" 49 | }, 50 | { 51 | "optional":false, 52 | "shortName":"workflow-multibranch", 53 | "version":"2.9.2" 54 | }, 55 | { 56 | "optional":false, 57 | "shortName":"pipeline-stage-view", 58 | "version":"2.4" 59 | }, 60 | { 61 | "optional":false, 62 | "shortName":"workflow-scm-step", 63 | "version":"2.3" 64 | }, 65 | { 66 | "optional":false, 67 | "shortName":"workflow-step-api", 68 | "version":"2.7" 69 | }, 70 | { 71 | "optional":false, 72 | "shortName":"pipeline-model-definition", 73 | "version":"1.0" 74 | }, 75 | { 76 | "optional":false, 77 | "shortName":"pipeline-stage-step", 78 | "version":"2.2" 79 | }, 80 | { 81 | "optional":false, 82 | "shortName":"pipeline-build-step", 83 | "version":"2.4" 84 | }, 85 | { 86 | "optional":false, 87 | "shortName":"pipeline-milestone-step", 88 | "version":"1.3" 89 | }, 90 | { 91 | "optional":false, 92 | "shortName":"bouncycastle-api", 93 | "version":"2.16.0" 94 | }, 95 | { 96 | "optional":false, 97 | "shortName":"command-launcher", 98 | "version":"1.0" 99 | }, 100 | { 101 | "optional":false, 102 | "shortName":"jdk-tool", 103 | "version":"1.0" 104 | } 105 | ], 106 | "downgradable":false, 107 | "enabled":true, 108 | "hasUpdate":false, 109 | "longName":"Pipeline", 110 | "pinned":false, 111 | "requiredCoreVersion":"2.7.3", 112 | "shortName":"workflow-aggregator", 113 | "supportsDynamicLoad":"YES", 114 | "url":"https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin", 115 | "version":"2.5" 116 | } 117 | ] 118 | } 119 | -------------------------------------------------------------------------------- /src/test/resources/progressive-text.txt: -------------------------------------------------------------------------------- 1 | Started by user anonymous 2 | Building in workspace /var/jenkins_home/workspace/DevTest 3 | Finished: SUCCESS -------------------------------------------------------------------------------- /src/test/resources/queue.json: -------------------------------------------------------------------------------- 1 | { 2 | "discoverableItems":[ 3 | 4 | ], 5 | "items":[ 6 | { 7 | "actions":[ 8 | { 9 | "parameters":[ 10 | { 11 | "name":"feet", 12 | "value":false 13 | } 14 | ] 15 | }, 16 | { 17 | "causes":[ 18 | { 19 | "shortDescription":"Started by user anonymous", 20 | "userId":null, 21 | "userName":"anonymous" 22 | } 23 | ] 24 | } 25 | ], 26 | "blocked":false, 27 | "buildable":true, 28 | "id":7, 29 | "inQueueSince":1460738557584, 30 | "params":"\nfeet=false", 31 | "stuck":false, 32 | "task":{ 33 | "name":"chicken", 34 | "url":"http://localhost:32769/job/chicken/", 35 | "color":"blue" 36 | }, 37 | "url":"queue/item/7/", 38 | "why":"Waiting for next available executor", 39 | "buildableStartMilliseconds":1460738557585, 40 | "pending":false 41 | }, 42 | { 43 | "actions":[ 44 | { 45 | "parameters":[ 46 | { 47 | "name":"fish", 48 | "value":"bear" 49 | } 50 | ] 51 | }, 52 | { 53 | "causes":[ 54 | { 55 | "shortDescription":"Started by user anonymous", 56 | "userId":null, 57 | "userName":"anonymous" 58 | } 59 | ] 60 | } 61 | ], 62 | "blocked":false, 63 | "buildable":true, 64 | "id":6, 65 | "inQueueSince":1460738551155, 66 | "params":"\nfish=bear", 67 | "stuck":false, 68 | "task":{ 69 | "name":"Freestyle", 70 | "url":"http://localhost:32769/job/Freestyle/", 71 | "color":"blue" 72 | }, 73 | "url":"queue/item/6/", 74 | "why":"Waiting for next available executor", 75 | "buildableStartMilliseconds":1460738551156, 76 | "pending":false 77 | } 78 | ] 79 | } -------------------------------------------------------------------------------- /src/test/resources/queueItemCancelled.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$LeftItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "4" 11 | } 12 | ] 13 | }, 14 | { 15 | "_class" : "hudson.model.CauseAction", 16 | "causes" : [ 17 | { 18 | "_class" : "hudson.model.Cause$UserIdCause", 19 | "shortDescription" : "Started by user martin", 20 | "userId" : "martin", 21 | "userName" : "martin" 22 | } 23 | ] 24 | } 25 | ], 26 | "blocked" : false, 27 | "buildable" : false, 28 | "id" : 143, 29 | "inQueueSince" : 1524074568030, 30 | "params" : "\na=4", 31 | "stuck" : false, 32 | "task" : { 33 | "_class" : "hudson.model.FreeStyleProject", 34 | "name" : "test", 35 | "url" : "http://localhost:8082/job/test/", 36 | "color" : "blue_anime" 37 | }, 38 | "url" : "queue/item/143/", 39 | "why" : null, 40 | "cancelled" : true, 41 | "executable" : null 42 | } -------------------------------------------------------------------------------- /src/test/resources/queueItemEmptyParameterValue.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$LeftItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "1" 11 | }, 12 | { 13 | "_class" : "hudson.model.StringParameterValue", 14 | "name" : "b", 15 | "value" : "2" 16 | }, 17 | { 18 | "_class" : "hudson.model.StringParameterValue", 19 | "name" : "c", 20 | "value" : "3" 21 | } 22 | ] 23 | }, 24 | { 25 | "_class" : "hudson.model.CauseAction", 26 | "causes" : [ 27 | { 28 | "_class" : "hudson.model.Cause$UserIdCause", 29 | "shortDescription" : "Started by user martin", 30 | "userId" : "martin", 31 | "userName" : "martin" 32 | } 33 | ] 34 | } 35 | ], 36 | "blocked" : false, 37 | "buildable" : false, 38 | "id" : 143, 39 | "inQueueSince" : 1524074837590, 40 | "params" : "\na=1\nb=\nc=3", 41 | "stuck" : false, 42 | "task" : { 43 | "_class" : "hudson.model.FreeStyleProject", 44 | "name" : "test", 45 | "url" : "http://localhost:8082/job/test/", 46 | "color" : "blue_anime" 47 | }, 48 | "url" : "queue/item/143/", 49 | "why" : null, 50 | "cancelled" : false, 51 | "executable" : { 52 | "_class" : "hudson.model.FreeStyleBuild", 53 | "number" : 14, 54 | "url" : "http://localhost:8082/job/test/14/" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/resources/queueItemMissingTaskUrl.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class": "hudson.model.Queue$BuildableItem", 3 | "actions": [], 4 | "blocked": false, 5 | "buildable": true, 6 | "id": 3549, 7 | "inQueueSince": 1613541614644, 8 | "params": "", 9 | "stuck": true, 10 | "task": { 11 | "_class": "org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution$PlaceholderTask" 12 | }, 13 | "url": "queue/item/3549/", 14 | "why": "Just a random message here", 15 | "buildableStartMilliseconds": 1613541614649, 16 | "pending": false 17 | } 18 | -------------------------------------------------------------------------------- /src/test/resources/queueItemMultipleParameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$LeftItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "1" 11 | }, 12 | { 13 | "_class" : "hudson.model.StringParameterValue", 14 | "name" : "b", 15 | "value" : "2" 16 | }, 17 | { 18 | "_class" : "hudson.model.StringParameterValue", 19 | "name" : "c", 20 | "value" : "3" 21 | } 22 | ] 23 | }, 24 | { 25 | "_class" : "hudson.model.CauseAction", 26 | "causes" : [ 27 | { 28 | "_class" : "hudson.model.Cause$UserIdCause", 29 | "shortDescription" : "Started by user martin", 30 | "userId" : "martin", 31 | "userName" : "martin" 32 | } 33 | ] 34 | } 35 | ], 36 | "blocked" : false, 37 | "buildable" : false, 38 | "id" : 143, 39 | "inQueueSince" : 1524074837590, 40 | "params" : "\na=1\nb=2\nc=3", 41 | "stuck" : false, 42 | "task" : { 43 | "_class" : "hudson.model.FreeStyleProject", 44 | "name" : "test", 45 | "url" : "http://localhost:8082/job/test/", 46 | "color" : "blue_anime" 47 | }, 48 | "url" : "queue/item/143/", 49 | "why" : null, 50 | "cancelled" : false, 51 | "executable" : { 52 | "_class" : "hudson.model.FreeStyleBuild", 53 | "number" : 14, 54 | "url" : "http://localhost:8082/job/test/14/" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/resources/queueItemNullTaskName.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$BlockedItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "4" 11 | } 12 | ] 13 | }, 14 | { 15 | "_class" : "hudson.model.CauseAction", 16 | "causes" : [ 17 | { 18 | "_class" : "hudson.model.Cause$UserIdCause", 19 | "shortDescription" : "Started by user martin", 20 | "userId" : "martin", 21 | "userName" : "martin" 22 | } 23 | ] 24 | } 25 | ], 26 | "blocked" : true, 27 | "buildable" : false, 28 | "id" : 143, 29 | "inQueueSince" : 1524074568030, 30 | "params" : "\na=4", 31 | "stuck" : false, 32 | "task" : { 33 | "_class" : "hudson.model.FreeStyleProject", 34 | "name" : null, 35 | "url" : "http://localhost:8082/job/test/", 36 | "color" : "blue_anime" 37 | }, 38 | "url" : "queue/item/143/", 39 | "why" : "Build #9 is already in progress (ETA:15 sec)", 40 | "buildableStartMilliseconds" : 1524074568030 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/queueItemPending.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$BlockedItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "4" 11 | } 12 | ] 13 | }, 14 | { 15 | "_class" : "hudson.model.CauseAction", 16 | "causes" : [ 17 | { 18 | "_class" : "hudson.model.Cause$UserIdCause", 19 | "shortDescription" : "Started by user martin", 20 | "userId" : "martin", 21 | "userName" : "martin" 22 | } 23 | ] 24 | } 25 | ], 26 | "blocked" : true, 27 | "buildable" : false, 28 | "id" : 143, 29 | "inQueueSince" : 1524074568030, 30 | "params" : "\na=4", 31 | "stuck" : false, 32 | "task" : { 33 | "_class" : "hudson.model.FreeStyleProject", 34 | "name" : "test", 35 | "url" : "http://localhost:8082/job/test/", 36 | "color" : "blue_anime" 37 | }, 38 | "url" : "queue/item/143/", 39 | "why" : "Build #9 is already in progress (ETA:15 sec)", 40 | "buildableStartMilliseconds" : 1524074568030 41 | } -------------------------------------------------------------------------------- /src/test/resources/queueItemRunning.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.Queue$LeftItem", 3 | "actions" : [ 4 | { 5 | "_class" : "hudson.model.ParametersAction", 6 | "parameters" : [ 7 | { 8 | "_class" : "hudson.model.StringParameterValue", 9 | "name" : "a", 10 | "value" : "4" 11 | } 12 | ] 13 | }, 14 | { 15 | "_class" : "hudson.model.CauseAction", 16 | "causes" : [ 17 | { 18 | "_class" : "hudson.model.Cause$UserIdCause", 19 | "shortDescription" : "Started by user martin", 20 | "userId" : "martin", 21 | "userName" : "martin" 22 | } 23 | ] 24 | } 25 | ], 26 | "blocked" : false, 27 | "buildable" : false, 28 | "id" : 143, 29 | "inQueueSince" : 1524074837590, 30 | "params" : "\na=4", 31 | "stuck" : false, 32 | "task" : { 33 | "_class" : "hudson.model.FreeStyleProject", 34 | "name" : "test", 35 | "url" : "http://localhost:8082/job/test/", 36 | "color" : "blue_anime" 37 | }, 38 | "url" : "queue/item/143/", 39 | "why" : null, 40 | "cancelled" : false, 41 | "executable" : { 42 | "_class" : "hudson.model.FreeStyleBuild", 43 | "number" : 14, 44 | "url" : "http://localhost:8082/job/test/14/" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resources/runHistory.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "_links": { 4 | "self": { 5 | "href": "/jenkins/job/Test%20Workflow/16/wfapi/describe" 6 | }, 7 | "pendingInputActions": { 8 | "href": "/jenkins/job/Test%20Workflow/16/wfapi/pendingInputActions" 9 | } 10 | }, 11 | "id": "2014-10-16_13-07-52", 12 | "name": "#16", 13 | "status": "PAUSED_PENDING_INPUT", 14 | "startTimeMillis": 1413461275770, 15 | "endTimeMillis": 1413461285999, 16 | "durationMillis": 10229, 17 | "stages": [ 18 | { 19 | "_links": { 20 | "self": { 21 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/5/wfapi/describe" 22 | } 23 | }, 24 | "id": "5", 25 | "name": "Build", 26 | "status": "SUCCESS", 27 | "startTimeMillis": 1413461275770, 28 | "durationMillis": 5228 29 | }, 30 | { 31 | "_links": { 32 | "self": { 33 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/8/wfapi/describe" 34 | } 35 | }, 36 | "id": "8", 37 | "name": "Test", 38 | "status": "SUCCESS", 39 | "startTimeMillis": 1413461280998, 40 | "durationMillis": 4994 41 | }, 42 | { 43 | "_links": { 44 | "self": { 45 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/10/wfapi/describe" 46 | } 47 | }, 48 | "id": "10", 49 | "name": "Deploy", 50 | "status": "PAUSED_PENDING_INPUT", 51 | "startTimeMillis": 1413461285992, 52 | "durationMillis": 7 53 | } 54 | ] 55 | }, 56 | { 57 | "_links": { 58 | "self": { 59 | "href": "/jenkins/job/Test%20Workflow/15/wfapi/describe" 60 | }, 61 | "artifacts": { 62 | "href": "/jenkins/job/Test%20Workflow/15/wfapi/artifacts" 63 | } 64 | }, 65 | "id": "2014-10-16_12-45-06", 66 | "name": "#15", 67 | "status": "SUCCESS", 68 | "startTimeMillis": 1413459910289, 69 | "endTimeMillis": 1413459937070, 70 | "durationMillis": 26781, 71 | "stages": [ 72 | { 73 | "_links": { 74 | "self": { 75 | "href": "/jenkins/job/Test%20Workflow/15/execution/node/5/wfapi/describe" 76 | } 77 | }, 78 | "id": "5", 79 | "name": "Build", 80 | "status": "SUCCESS", 81 | "startTimeMillis": 1413459910289, 82 | "durationMillis": 6754 83 | }, 84 | { 85 | "_links": { 86 | "self": { 87 | "href": "/jenkins/job/Test%20Workflow/15/execution/node/8/wfapi/describe" 88 | } 89 | }, 90 | "id": "8", 91 | "name": "Test", 92 | "status": "SUCCESS", 93 | "startTimeMillis": 1413459917043, 94 | "durationMillis": 4998 95 | }, 96 | { 97 | "_links": { 98 | "self": { 99 | "href": "/jenkins/job/Test%20Workflow/15/execution/node/10/wfapi/describe" 100 | } 101 | }, 102 | "id": "10", 103 | "name": "Deploy", 104 | "status": "SUCCESS", 105 | "startTimeMillis": 1413459922041, 106 | "durationMillis": 15029 107 | } 108 | ] 109 | } 110 | ] -------------------------------------------------------------------------------- /src/test/resources/user.json: -------------------------------------------------------------------------------- 1 | { 2 | "_class" : "hudson.model.User", 3 | "absoluteUrl" : "http://localhost:8080/user/admin", 4 | "description" : null, 5 | "fullName" : "Administrator", 6 | "id" : "admin", 7 | "property" : [ 8 | { 9 | "_class" : "jenkins.security.ApiTokenProperty" 10 | }, 11 | { 12 | "_class" : "com.cloudbees.plugins.credentials.UserCredentialsProvider$UserCredentialsProperty" 13 | }, 14 | { 15 | "_class" : "hudson.model.MyViewsProperty" 16 | }, 17 | { 18 | "_class" : "hudson.model.PaneStatusProperties" 19 | }, 20 | { 21 | "_class" : "jenkins.security.seed.UserSeedProperty" 22 | }, 23 | { 24 | "_class" : "hudson.search.UserSearchProperty", 25 | "insensitiveSearch" : true 26 | }, 27 | { 28 | "_class" : "hudson.model.TimeZoneProperty" 29 | }, 30 | { 31 | "_class" : "hudson.security.HudsonPrivateSecurityRealm$Details" 32 | }, 33 | { 34 | "_class" : "jenkins.security.LastGrantedAuthoritiesProperty" 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resources/workflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "_links": { 3 | "self": { 4 | "href": "/jenkins/job/Test%20Workflow/16/wfapi/describe" 5 | }, 6 | "pendingInputActions": { 7 | "href": "/jenkins/job/Test%20Workflow/16/wfapi/pendingInputActions" 8 | } 9 | }, 10 | "id": "2014-10-16_13-07-52", 11 | "name": "#16", 12 | "status": "PAUSED_PENDING_INPUT", 13 | "startTimeMillis": 1413461275770, 14 | "endTimeMillis": 1413461285999, 15 | "durationMillis": 10229, 16 | "stages": [ 17 | { 18 | "_links": { 19 | "self": { 20 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/5/wfapi/describe" 21 | } 22 | }, 23 | "id": "5", 24 | "name": "Build", 25 | "status": "SUCCESS", 26 | "startTimeMillis": 1413461275770, 27 | "durationMillis": 5228 28 | }, 29 | { 30 | "_links": { 31 | "self": { 32 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/8/wfapi/describe" 33 | } 34 | }, 35 | "id": "8", 36 | "name": "Test", 37 | "status": "SUCCESS", 38 | "startTimeMillis": 1413461280998, 39 | "durationMillis": 4994 40 | }, 41 | { 42 | "_links": { 43 | "self": { 44 | "href": "/jenkins/job/Test%20Workflow/16/execution/node/10/wfapi/describe" 45 | } 46 | }, 47 | "id": "10", 48 | "name": "Deploy", 49 | "status": "PAUSED_PENDING_INPUT", 50 | "startTimeMillis": 1413461285992, 51 | "durationMillis": 7 52 | } 53 | ] 54 | } 55 | --------------------------------------------------------------------------------