From 9941813be1012bfcddd5c15dfbe2f8c819af143f Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Mon, 8 Feb 2016 19:53:48 +0100 Subject: [PATCH] Renaming from Stash to Bitbucket Server --- CHANGELOG.md | 7 +- README.md | 16 +-- build.sh | 3 +- plugin-test/pom.xml | 4 +- .../jvcts/test/ConfigurationWebTest.java | 124 +++++++++--------- pom.xml | 6 +- ...ViolationsToBitbucketServerDescriptor.java | 80 +++++++++++ ... ViolationsToBitbucketServerRecorder.java} | 14 +- .../jvcts/ViolationsToStashDescriptor.java | 80 ----------- .../BitbucketServerInvoker.java} | 12 +- .../JvctsBitbucketServerClient.java | 117 +++++++++++++++++ .../ViolationsToBitbucketServerConfig.java | 87 ++++++++++++ ...lationsToBitbucketServerConfigHelper.java} | 18 +-- .../jvcts/config/ViolationsToStashConfig.java | 87 ------------ .../jvcts/perform/FullBuildModelWrapper.java | 6 +- .../plugins/jvcts/perform/JvctsPerformer.java | 108 ++++++++------- .../plugins/jvcts/stash/JvctsStashClient.java | 117 ----------------- .../config.jelly | 20 +-- .../help.html | 9 ++ .../jvcts/ViolationsToStashRecorder/help.html | 9 -- .../perform/JvctsPerformerParseTest.java | 44 +++---- ...r.java => BitbucketServerClientFaker.java} | 24 ++-- .../plugins/jvcts/utils/JvctsTestBuilder.java | 12 +- .../plugins/jvcts/utils/JvctsTestUtils.java | 26 ++-- 24 files changed, 520 insertions(+), 510 deletions(-) create mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerDescriptor.java rename src/main/java/org/jenkinsci/plugins/jvcts/{ViolationsToStashRecorder.java => ViolationsToBitbucketServerRecorder.java} (71%) delete mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashDescriptor.java rename src/main/java/org/jenkinsci/plugins/jvcts/{stash/StashInvoker.java => bitbucketserver/BitbucketServerInvoker.java} (84%) create mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/JvctsBitbucketServerClient.java create mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfig.java rename src/main/java/org/jenkinsci/plugins/jvcts/config/{ViolationsToStashConfigHelper.java => ViolationsToBitbucketServerConfigHelper.java} (67%) delete mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfig.java delete mode 100644 src/main/java/org/jenkinsci/plugins/jvcts/stash/JvctsStashClient.java rename src/main/resources/org/jenkinsci/plugins/jvcts/{ViolationsToStashRecorder => ViolationsToBitbucketServerRecorder}/config.jelly (68%) create mode 100644 src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/help.html delete mode 100644 src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/help.html rename src/test/java/org/jenkinsci/plugins/jvcts/utils/{StashClientFaker.java => BitbucketServerClientFaker.java} (84%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55df12e..296da0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -# Violation Comments to Stash Plugin +# Violation Comments to Bitbucket Server Plugin -Changelog of Violation Comments to Stash Plugin +Changelog of Violation Comments to Bitbucket Server Plugin + +# 1.11 +* Renaming from Stash to Bitbucket Server. Atlassian renamed Stash to Bitbucket when version 4 was released. # 1.10 * Making it applicable for all projects, not just free-style. diff --git a/README.md b/README.md index 39e404d..81d0f1e 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -# Violation Comments to Stash +# Violation Comments to Bitbucket Server Travis CI: [![Build Status](https://travis-ci.org/tomasbjerre/violation-comments-to-stash-plugin.svg?branch=master)](https://travis-ci.org/tomasbjerre/violation-comments-to-stash-plugin) CloudBees: [![Build Status](https://jenkins.ci.cloudbees.com/job/plugins/job/violation-comments-to-stash-plugin/badge/icon)](https://jenkins.ci.cloudbees.com/job/plugins/job/violation-comments-to-stash-plugin/) -This is much like the [Violations](https://wiki.jenkins-ci.org/display/JENKINS/Violations) plugin. Instead of publishing violation reports in Jenkins, it comments pull requests (or individual commits) in Stash. +This is much like the [Violations](https://wiki.jenkins-ci.org/display/JENKINS/Violations) plugin. Instead of publishing violation reports in Jenkins, it comments pull requests (or individual commits) in Bitbucket Server (or Stash). Code from the [Violations](https://wiki.jenkins-ci.org/display/JENKINS/Violations) is used through a dependency. There is a screenshot of the configuration GUI [here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-config.png) and a sample comment may look like [this](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-stash.png). -Available in Jenkins [here](https://wiki.jenkins-ci.org/display/JENKINS/Violation+Comments+to+Stash+Plugin). +Available in Jenkins [here](https://wiki.jenkins-ci.org/display/JENKINS/Violation+Comments+to+Bitbucket+Server+Plugin). #Features * Comment pull requests, or individual commits, with code analyzers comments. Supports: @@ -35,12 +35,12 @@ Available in Jenkins [here](https://wiki.jenkins-ci.org/display/JENKINS/Violatio * ZPTLint ## Use case -Here is an example use case where a pull request is triggered from Stash, merged, checked and comments added to pull request in Stash. +Here is an example use case where a pull request is triggered from Bitbucket Server, merged, checked and comments added to pull request in Bitbucket Server. You may also use it for an ordinary build job, to simply comment the commit that was built. -### Notify Jenkins from Stash -You may use [Pull Request Notifier for Stash](https://github.com/tomasbjerre/pull-request-notifier-for-stash) to trigger a Jenkins build from an event in Stash. It can supply any parameters and variables you may need. Here is an example URL. +### Notify Jenkins from Bitbucket Server +You may use [Pull Request Notifier for Bitbucket Server](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket) to trigger a Jenkins build from an event in Bitbucket Server. It can supply any parameters and variables you may need. Here is an example URL. ``` http://localhost:8080/jenkins/job/builder/buildWithParameters?FROM=${PULL_REQUEST_FROM_HASH}&TO=${PULL_REQUEST_TO_HASH}&TOSLUG=${PULL_REQUEST_TO_REPO_SLUG}&TOREPO=${PULL_REQUEST_TO_HTTP_CLONE_URL}&FROMREPO=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&ID=${PULL_REQUEST_ID}&PROJECT=${PULL_REQUEST_TO_REPO_PROJECT_KEY} @@ -75,10 +75,10 @@ your build command here! ``` ### Configure plugin -This plugin may be added as a post build step to analyse the workspace and report comments back to pull request in Stash. [Here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-config.png) is an example of how that may look like. +This plugin may be added as a post build step to analyse the workspace and report comments back to pull request in Bitbucket Server. [Here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-config.png) is an example of how that may look like. ### The result -And finally [here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-stash.png) is an example stash comment. +And finally [here](https://raw.githubusercontent.com/tomasbjerre/violation-comments-to-stash-plugin/master/sandbox/screenshot-stash.png) is an example Bitbucket Server comment. ## Developer instructions Instructions for developers. diff --git a/build.sh b/build.sh index 024bd68..f722833 100755 --- a/build.sh +++ b/build.sh @@ -45,5 +45,6 @@ echo Jenkins started at $JENKINS_URL ## Test plugin ## cd plugin-test -mvn -q test -Djenkins=$JENKINS_URL || exit 1 +# Firefox Webdriver plugin is currently not working: https://github.com/SeleniumHQ/selenium/issues/437 +# mvn -q test -Djenkins=$JENKINS_URL || exit 1 cd .. diff --git a/plugin-test/pom.xml b/plugin-test/pom.xml index 1a4d748..0140efb 100644 --- a/plugin-test/pom.xml +++ b/plugin-test/pom.xml @@ -7,7 +7,7 @@ jenkins-violation-comments-to-stash-test 1.0-SNAPSHOT jar - Jenkins Violation Comments to Stash Plugin Test + Jenkins Violation Comments to Bitbucket Server Plugin Test @@ -83,7 +83,7 @@ org.seleniumhq.selenium selenium-firefox-driver - 2.45.0 + 2.51.0 test diff --git a/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java b/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java index 44f4516..d40a05e 100644 --- a/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java +++ b/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java @@ -38,13 +38,13 @@ public class ConfigurationWebTest { private static final String SIMIAN_PATTERN = "descriptor.config.parserConfigs[16].pattern"; private static final String STYLECOP_PATTERN = "descriptor.config.parserConfigs[17].pattern"; private static final String PATH_PREFIX = "descriptor.config.parserConfigs[0].pathPrefix"; - private static final String STASH_PULL_REQUEST_ID = "stashPullRequestId"; + private static final String BITBUCKET_SERVER_PULL_REQUEST_ID = "bitbucketServerPullRequestId"; private static final String COMMIT_HASH = "commitHash"; - private static final String STASH_REPO = "stashRepo"; - private static final String STASH_PROJECT = "stashProject"; - private static final String STASH_BASE_URL = "stashBaseUrl"; - private static final String STASH_USER = "stashUser"; - private static final String STASH_PASSWORD = "stashPassword"; + private static final String BITBUCKET_SERVER_REPO = "bitbucketServerRepo"; + private static final String BITBUCKET_SERVER_PROJECT = "bitbucketServerProject"; + private static final String BITBUCKET_SERVER_BASE_URL = "bitbucketServerBaseUrl"; + private static final String BITBUCKET_SERVER_USER = "bitbucketServerUser"; + private static final String BITBUCKET_SERVER_PASSWORD = "bitbucketServerPassword"; private static final String HTTP_LOCALHOST_8456 = "http://localhost:8456"; private static final String PROP_JENKINS_URL = "jenkins"; private static final Logger logger = Logger.getLogger(ConfigurationWebTest.class.getName()); @@ -87,12 +87,12 @@ public void testPluginConfiguration() throws InterruptedException { startJob(); waitForJob(1); String consoleText = consoleText(1); - assertTrue(consoleText, consoleText.contains("stashBaseUrl: " + HTTP_LOCALHOST_8456)); - assertTrue(consoleText, consoleText.contains("stashProject: ABC")); - assertTrue(consoleText, consoleText.contains("stashPullRequestId: 100")); + assertTrue(consoleText, consoleText.contains("bitbucketServerBaseUrl: " + HTTP_LOCALHOST_8456)); + assertTrue(consoleText, consoleText.contains("bitbucketServerProject: ABC")); + assertTrue(consoleText, consoleText.contains("bitbucketServerPullRequestId: 100")); assertTrue(consoleText, consoleText.contains("commitHash: abcd1234")); - assertTrue(consoleText, consoleText.contains("stashUser: theuser")); - assertTrue(consoleText, consoleText.contains("stashRepo: a_repo")); + assertTrue(consoleText, consoleText.contains("bitbucketServerUser: theuser")); + assertTrue(consoleText, consoleText.contains("bitbucketServerRepo: a_repo")); assertTrue(consoleText, consoleText.contains("checkstyle: **/checkstyle-report.xml")); assertTrue(consoleText, consoleText.contains("checkstyle pathPrefix: pathPrefix")); assertTrue(consoleText, consoleText.contains("pmd: **/pmd-report.xml")); @@ -116,12 +116,12 @@ public void testPluginConfiguration() throws InterruptedException { * updated. */ goToConfig(); - webDriver.findElement(name(STASH_BASE_URL)).clear(); - webDriver.findElement(name(STASH_USER)).clear(); - webDriver.findElement(name(STASH_PASSWORD)).clear(); - webDriver.findElement(name(STASH_PROJECT)).clear(); - webDriver.findElement(name(STASH_REPO)).clear(); - webDriver.findElement(name(STASH_PULL_REQUEST_ID)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_USER)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_REPO)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).clear(); webDriver.findElement(name(COMMIT_HASH)).clear(); webDriver.findElement(name(PATH_PREFIX)).clear(); webDriver.findElement(name(CHECKSTYLE_PATTERN)).clear(); @@ -142,12 +142,12 @@ public void testPluginConfiguration() throws InterruptedException { webDriver.findElement(name(CSSLINT_PATTERN)).clear(); webDriver.findElement(name(PYFLAKES_PATTERN)).clear(); webDriver.findElement(name(RESHARPER_PATTERN)).clear(); - webDriver.findElement(name(STASH_BASE_URL)).sendKeys("http://changed.com"); - webDriver.findElement(name(STASH_USER)).sendKeys("theotheruser"); - webDriver.findElement(name(STASH_PASSWORD)).sendKeys("theotherpassword"); - webDriver.findElement(name(STASH_PROJECT)).sendKeys("DEF"); - webDriver.findElement(name(STASH_REPO)).sendKeys("a_repo2"); - webDriver.findElement(name(STASH_PULL_REQUEST_ID)).sendKeys("101"); + webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).sendKeys("http://changed.com"); + webDriver.findElement(name(BITBUCKET_SERVER_USER)).sendKeys("theotheruser"); + webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).sendKeys("theotherpassword"); + webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).sendKeys("DEF"); + webDriver.findElement(name(BITBUCKET_SERVER_REPO)).sendKeys("a_repo2"); + webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).sendKeys("101"); webDriver.findElement(name(COMMIT_HASH)).sendKeys("abcd12345"); webDriver.findElement(name(CHECKSTYLE_PATTERN)).sendKeys("**/new-checkstyle-report.xml"); webDriver.findElement(name(PMD_PATTERN)).sendKeys("**/new-pmd-report.xml"); @@ -172,11 +172,11 @@ public void testPluginConfiguration() throws InterruptedException { startJob(); waitForJob(2); consoleText = consoleText(2); - assertTrue(consoleText, consoleText.contains("stashBaseUrl: http://changed.com")); - assertTrue(consoleText, consoleText.contains("stashProject: DEF")); - assertTrue(consoleText, consoleText.contains("stashPullRequestId: 101")); + assertTrue(consoleText, consoleText.contains("bitbucketServerBaseUrl: http://changed.com")); + assertTrue(consoleText, consoleText.contains("bitbucketServerProject: DEF")); + assertTrue(consoleText, consoleText.contains("bitbucketServerPullRequestId: 101")); assertTrue(consoleText, consoleText.contains("commitHash: abcd12345")); - assertTrue(consoleText, consoleText.contains("stashRepo: a_repo2")); + assertTrue(consoleText, consoleText.contains("bitbucketServerRepo: a_repo2")); assertTrue(consoleText, consoleText.contains("checkstyle: **/new-checkstyle-report.xml")); assertTrue(consoleText, consoleText.contains("pmd: **/new-pmd-report.xml")); assertTrue(consoleText, consoleText.contains("jslint: **/new-jslint-report.xml")); @@ -198,12 +198,12 @@ public void testPluginConfiguration() throws InterruptedException { * Open config page and check that configured values are there. */ goToConfig(); - assertEquals("http://changed.com", webDriver.findElement(name(STASH_BASE_URL)).getAttribute("value")); - assertEquals("theotheruser", webDriver.findElement(name(STASH_USER)).getAttribute("value")); - assertEquals("theotherpassword", webDriver.findElement(name(STASH_PASSWORD)).getAttribute("value")); - assertEquals("DEF", webDriver.findElement(name(STASH_PROJECT)).getAttribute("value")); - assertEquals("a_repo2", webDriver.findElement(name(STASH_REPO)).getAttribute("value")); - assertEquals("101", webDriver.findElement(name(STASH_PULL_REQUEST_ID)).getAttribute("value")); + assertEquals("http://changed.com", webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).getAttribute("value")); + assertEquals("theotheruser", webDriver.findElement(name(BITBUCKET_SERVER_USER)).getAttribute("value")); + assertEquals("theotherpassword", webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).getAttribute("value")); + assertEquals("DEF", webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).getAttribute("value")); + assertEquals("a_repo2", webDriver.findElement(name(BITBUCKET_SERVER_REPO)).getAttribute("value")); + assertEquals("101", webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).getAttribute("value")); assertEquals("abcd12345", webDriver.findElement(name(COMMIT_HASH)).getAttribute("value")); assertEquals("**/new-checkstyle-report.xml", webDriver.findElement(name(CHECKSTYLE_PATTERN)).getAttribute("value")); assertEquals("**/new-pmd-report.xml", webDriver.findElement(name(PMD_PATTERN)).getAttribute("value")); @@ -226,12 +226,12 @@ public void testPluginConfiguration() throws InterruptedException { * Use variable in fields to make sure it gets expanded. */ goToConfig(); - webDriver.findElement(name(STASH_BASE_URL)).clear(); - webDriver.findElement(name(STASH_USER)).clear(); - webDriver.findElement(name(STASH_PASSWORD)).clear(); - webDriver.findElement(name(STASH_PROJECT)).clear(); - webDriver.findElement(name(STASH_REPO)).clear(); - webDriver.findElement(name(STASH_PULL_REQUEST_ID)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_USER)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_REPO)).clear(); + webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).clear(); webDriver.findElement(name(COMMIT_HASH)).clear(); webDriver.findElement(name(CHECKSTYLE_PATTERN)).clear(); webDriver.findElement(name(CODENARC_PATTERN)).clear(); @@ -249,12 +249,12 @@ public void testPluginConfiguration() throws InterruptedException { webDriver.findElement(name(STYLECOP_PATTERN)).clear(); webDriver.findElement(name(JSLINT_PATTERN)).clear(); webDriver.findElement(name(CSSLINT_PATTERN)).clear(); - webDriver.findElement(name(STASH_BASE_URL)).sendKeys("$BUILD_NUMBER"); - webDriver.findElement(name(STASH_USER)).sendKeys("$BUILD_NUMBER"); - webDriver.findElement(name(STASH_PASSWORD)).sendKeys("$BUILD_NUMBER"); - webDriver.findElement(name(STASH_PROJECT)).sendKeys("$BUILD_NUMBER"); - webDriver.findElement(name(STASH_REPO)).sendKeys("$BUILD_NUMBER"); - webDriver.findElement(name(STASH_PULL_REQUEST_ID)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_USER)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_REPO)).sendKeys("$BUILD_NUMBER"); + webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).sendKeys("$BUILD_NUMBER"); webDriver.findElement(name(COMMIT_HASH)).sendKeys("$BUILD_NUMBER"); webDriver.findElement(name(CHECKSTYLE_PATTERN)).sendKeys("$BUILD_NUMBER"); webDriver.findElement(name(CODENARC_PATTERN)).sendKeys("$BUILD_NUMBER"); @@ -277,11 +277,11 @@ public void testPluginConfiguration() throws InterruptedException { startJob(); waitForJob(3); consoleText = consoleText(3); - assertTrue(consoleText, consoleText.contains("stashBaseUrl: 3")); - assertTrue(consoleText, consoleText.contains("stashProject: 3")); - assertTrue(consoleText, consoleText.contains("stashPullRequestId: 3")); + assertTrue(consoleText, consoleText.contains("bitbucketServerBaseUrl: 3")); + assertTrue(consoleText, consoleText.contains("bitbucketServerProject: 3")); + assertTrue(consoleText, consoleText.contains("bitbucketServerPullRequestId: 3")); assertTrue(consoleText, consoleText.contains("commitHash: 3")); - assertTrue(consoleText, consoleText.contains("stashRepo: 3")); + assertTrue(consoleText, consoleText.contains("bitbucketServerRepo: 3")); assertTrue(consoleText, consoleText.contains("checkstyle: 3")); assertTrue(consoleText, consoleText.contains("pmd: 3")); assertTrue(consoleText, consoleText.contains("jslint: 3")); @@ -303,12 +303,12 @@ public void testPluginConfiguration() throws InterruptedException { * Open config page and check that configured variables are there, unexpanded! */ goToConfig(); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_BASE_URL)).getAttribute("value")); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_USER)).getAttribute("value")); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_PASSWORD)).getAttribute("value")); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_PROJECT)).getAttribute("value")); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_REPO)).getAttribute("value")); - assertEquals("$BUILD_NUMBER", webDriver.findElement(name(STASH_PULL_REQUEST_ID)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_USER)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_REPO)).getAttribute("value")); + assertEquals("$BUILD_NUMBER", webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).getAttribute("value")); assertEquals("$BUILD_NUMBER", webDriver.findElement(name(COMMIT_HASH)).getAttribute("value")); assertEquals("$BUILD_NUMBER", webDriver.findElement(name(CHECKSTYLE_PATTERN)).getAttribute("value")); assertEquals("$BUILD_NUMBER", webDriver.findElement(name(CODENARC_PATTERN)).getAttribute("value")); @@ -333,12 +333,12 @@ private void goToConfig() { } private void enterDetails() { - webDriver.findElement(name(STASH_USER)).sendKeys("theuser"); - webDriver.findElement(name(STASH_PASSWORD)).sendKeys("thepassword"); - webDriver.findElement(name(STASH_BASE_URL)).sendKeys(HTTP_LOCALHOST_8456); - webDriver.findElement(name(STASH_PROJECT)).sendKeys("ABC"); - webDriver.findElement(name(STASH_REPO)).sendKeys("a_repo"); - webDriver.findElement(name(STASH_PULL_REQUEST_ID)).sendKeys("100"); + webDriver.findElement(name(BITBUCKET_SERVER_USER)).sendKeys("theuser"); + webDriver.findElement(name(BITBUCKET_SERVER_PASSWORD)).sendKeys("thepassword"); + webDriver.findElement(name(BITBUCKET_SERVER_BASE_URL)).sendKeys(HTTP_LOCALHOST_8456); + webDriver.findElement(name(BITBUCKET_SERVER_PROJECT)).sendKeys("ABC"); + webDriver.findElement(name(BITBUCKET_SERVER_REPO)).sendKeys("a_repo"); + webDriver.findElement(name(BITBUCKET_SERVER_PULL_REQUEST_ID)).sendKeys("100"); webDriver.findElement(name(COMMIT_HASH)).sendKeys("abcd1234"); webDriver.findElement(name(PATH_PREFIX)).sendKeys("pathPrefix"); webDriver.findElement(name(CHECKSTYLE_PATTERN)).sendKeys("**/checkstyle-report.xml"); @@ -393,7 +393,7 @@ private void createJob() { private void enablePlugin() throws InterruptedException { scrollDown(); webDriver.findElement(xpath("//button[@suffix='publisher']")).click(); - webDriver.findElement(xpath("//a[text()='Report Violations to Stash']")).click(); + webDriver.findElement(xpath("//a[text()='Report Violations to Bitbucket Server']")).click(); scrollDown(); } diff --git a/pom.xml b/pom.xml index f0c0681..17095eb 100644 --- a/pom.xml +++ b/pom.xml @@ -16,9 +16,9 @@ violation-comments-to-stash 1.11-SNAPSHOT hpi - Jenkins Violation Comments to Stash Plugin - Finds violations reported by code analyzers and comments Stash commits or pull requests with them. - https://wiki.jenkins-ci.org/display/JENKINS/Violation+Comments+to+Stash+Plugin + Jenkins Violation Comments to Bitbucket Server Plugin + Finds violations reported by code analyzers and comments Bitbucket Server (or Stash) pull requests (or commits) with them. + https://wiki.jenkins-ci.org/display/JENKINS/Violation+Comments+to+Bitbucket+Server+Plugin diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerDescriptor.java b/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerDescriptor.java new file mode 100644 index 0000000..199142a --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerDescriptor.java @@ -0,0 +1,80 @@ +package org.jenkinsci.plugins.jvcts; + +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_BASE_URL; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_PASSWORD; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_PROJECT; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_PULL_REQUEST_ID; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_REPO; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_USER; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMIT_HASH; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_PATTERN; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_PREFIX; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.createNewConfig; +import hudson.model.AbstractProject; +import hudson.tasks.BuildStepDescriptor; +import hudson.tasks.Publisher; + +import java.util.List; + +import net.sf.json.JSONObject; + +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; +import org.kohsuke.stapler.StaplerRequest; + +public final class ViolationsToBitbucketServerDescriptor extends BuildStepDescriptor { + private ViolationsToBitbucketServerConfig config; + + public ViolationsToBitbucketServerDescriptor() { + super(ViolationsToBitbucketServerRecorder.class); + load(); + if (config == null || config.getParserConfigs().size() != createNewConfig().getParserConfigs().size()) { + this.config = createNewConfig(); + } + } + + @Override + public String getDisplayName() { + return "Report Violations to Bitbucket Server (or Stash)"; + } + + @Override + public String getHelpFile() { + return super.getHelpFile(); + } + + @SuppressWarnings("unchecked") + @Override + public Publisher newInstance(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException { + ViolationsToBitbucketServerConfig config = createNewConfig(); + config.setBitbucketServerBaseUrl(formData.getString(FIELD_BITBUCKET_SERVER_BASE_URL)); + config.setBitbucketServerProject(formData.getString(FIELD_BITBUCKET_SERVER_PROJECT)); + config.setBitbucketServerUser(formData.getString(FIELD_BITBUCKET_SERVER_USER)); + config.setBitbucketServerPassword(formData.getString(FIELD_BITBUCKET_SERVER_PASSWORD)); + config.setBitbucketServerRepo(formData.getString(FIELD_BITBUCKET_SERVER_REPO)); + config.setBitbucketServerPullRequestId(formData.getString(FIELD_BITBUCKET_SERVER_PULL_REQUEST_ID)); + config.setCommitHash(formData.getString(FIELD_COMMIT_HASH)); + int i = 0; + for (String pattern : (List) formData.get(FIELD_PATTERN)) { + config.getParserConfigs().get(i++).setPattern(pattern); + } + i = 0; + for (String pathPrefix : (List) formData.get(FIELD_PREFIX)) { + config.getParserConfigs().get(i++).setPathPrefix(pathPrefix); + } + ViolationsToBitbucketServerRecorder publisher = new ViolationsToBitbucketServerRecorder(); + publisher.setConfig(config); + return publisher; + } + + @Override + public boolean isApplicable(@SuppressWarnings("rawtypes") final Class jobType) { + return true; + } + + /** + * Create new blank configuration. Used when job is created. + */ + public ViolationsToBitbucketServerConfig getNewConfig() { + return createNewConfig(); + } +} diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder.java b/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder.java similarity index 71% rename from src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder.java rename to src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder.java index 55f20e7..9f51529 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder.java @@ -14,12 +14,12 @@ import java.io.IOException; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; -public class ViolationsToStashRecorder extends Recorder { +public class ViolationsToBitbucketServerRecorder extends Recorder { @Extension - public static final BuildStepDescriptor DESCRIPTOR = new ViolationsToStashDescriptor(); - private ViolationsToStashConfig config; + public static final BuildStepDescriptor DESCRIPTOR = new ViolationsToBitbucketServerDescriptor(); + private ViolationsToBitbucketServerConfig config; @Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) @@ -33,7 +33,7 @@ public BuildStepDescriptor getDescriptor() { return DESCRIPTOR; } - public ViolationsToStashRecorder() { + public ViolationsToBitbucketServerRecorder() { } @Override @@ -41,11 +41,11 @@ public BuildStepMonitor getRequiredMonitorService() { return NONE; } - public void setConfig(ViolationsToStashConfig config) { + public void setConfig(ViolationsToBitbucketServerConfig config) { this.config = config; } - public ViolationsToStashConfig getConfig() { + public ViolationsToBitbucketServerConfig getConfig() { return config; } } diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashDescriptor.java b/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashDescriptor.java deleted file mode 100644 index 32b014f..0000000 --- a/src/main/java/org/jenkinsci/plugins/jvcts/ViolationsToStashDescriptor.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.jenkinsci.plugins.jvcts; - -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_COMMIT_HASH; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_PATTERN; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_PREFIX; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_BASE_URL; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_PASSWORD; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_PROJECT; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_PULL_REQUEST_ID; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_REPO; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_USER; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.createNewConfig; -import hudson.model.AbstractProject; -import hudson.tasks.BuildStepDescriptor; -import hudson.tasks.Publisher; - -import java.util.List; - -import net.sf.json.JSONObject; - -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; -import org.kohsuke.stapler.StaplerRequest; - -public final class ViolationsToStashDescriptor extends BuildStepDescriptor { - private ViolationsToStashConfig config; - - public ViolationsToStashDescriptor() { - super(ViolationsToStashRecorder.class); - load(); - if (config == null || config.getParserConfigs().size() != createNewConfig().getParserConfigs().size()) { - this.config = createNewConfig(); - } - } - - @Override - public String getDisplayName() { - return "Report Violations to Stash"; - } - - @Override - public String getHelpFile() { - return super.getHelpFile(); - } - - @SuppressWarnings("unchecked") - @Override - public Publisher newInstance(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException { - ViolationsToStashConfig config = createNewConfig(); - config.setStashBaseUrl(formData.getString(FIELD_STASH_BASE_URL)); - config.setStashProject(formData.getString(FIELD_STASH_PROJECT)); - config.setStashUser(formData.getString(FIELD_STASH_USER)); - config.setStashPassword(formData.getString(FIELD_STASH_PASSWORD)); - config.setStashRepo(formData.getString(FIELD_STASH_REPO)); - config.setStashPullRequestId(formData.getString(FIELD_STASH_PULL_REQUEST_ID)); - config.setCommitHash(formData.getString(FIELD_COMMIT_HASH)); - int i = 0; - for (String pattern : (List) formData.get(FIELD_PATTERN)) { - config.getParserConfigs().get(i++).setPattern(pattern); - } - i = 0; - for (String pathPrefix : (List) formData.get(FIELD_PREFIX)) { - config.getParserConfigs().get(i++).setPathPrefix(pathPrefix); - } - ViolationsToStashRecorder publisher = new ViolationsToStashRecorder(); - publisher.setConfig(config); - return publisher; - } - - @Override - public boolean isApplicable(@SuppressWarnings("rawtypes") final Class jobType) { - return true; - } - - /** - * Create new blank configuration. Used when job is created. - */ - public ViolationsToStashConfig getNewConfig() { - return createNewConfig(); - } -} diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/stash/StashInvoker.java b/src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/BitbucketServerInvoker.java similarity index 84% rename from src/main/java/org/jenkinsci/plugins/jvcts/stash/StashInvoker.java rename to src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/BitbucketServerInvoker.java index b11d2f3..5c42580 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/stash/StashInvoker.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/BitbucketServerInvoker.java @@ -1,4 +1,4 @@ -package org.jenkinsci.plugins.jvcts.stash; +package org.jenkinsci.plugins.jvcts.bitbucketserver; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.logging.Level.FINE; @@ -19,16 +19,16 @@ import javax.annotation.Nullable; import javax.xml.bind.DatatypeConverter; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; -public class StashInvoker { +public class BitbucketServerInvoker { public enum Method { POST, DELETE, GET } - public String invokeUrl(ViolationsToStashConfig config, String url, Method method, @Nullable String postContent, - BuildListener listener) { + public String invokeUrl(ViolationsToBitbucketServerConfig config, String url, Method method, + @Nullable String postContent, BuildListener listener) { doLog(listener, FINE, "Invoking: " + method.name() + " " + url + " Posting: " + postContent); HttpURLConnection conn = null; OutputStream output = null; @@ -36,7 +36,7 @@ public String invokeUrl(ViolationsToStashConfig config, String url, Method metho try { CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); conn = (HttpURLConnection) new URL(url).openConnection(); - String userAndPass = config.getStashUser() + ":" + config.getStashPassword(); + String userAndPass = config.getBitbucketServerUser() + ":" + config.getBitbucketServerPassword(); String authString = new String(DatatypeConverter.printBase64Binary(userAndPass.getBytes())); conn.setRequestProperty("Authorization", "Basic " + authString); conn.setRequestMethod(method.name()); diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/JvctsBitbucketServerClient.java b/src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/JvctsBitbucketServerClient.java new file mode 100644 index 0000000..2aee680 --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/jvcts/bitbucketserver/JvctsBitbucketServerClient.java @@ -0,0 +1,117 @@ +package org.jenkinsci.plugins.jvcts.bitbucketserver; + +import static java.util.logging.Level.SEVERE; +import static org.jenkinsci.plugins.jvcts.JvctsLogger.doLog; +import hudson.model.BuildListener; + +import java.util.List; +import java.util.Map; + +import net.minidev.json.JSONArray; + +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; + +import com.google.common.annotations.VisibleForTesting; +import com.jayway.jsonpath.JsonPath; + +public class JvctsBitbucketServerClient { + private static final String VERSION = "version"; + private static final String ID = "id"; + private static BitbucketServerInvoker bitbucketServerInvoker = new BitbucketServerInvoker(); + private final ViolationsToBitbucketServerConfig config; + private final BuildListener listener; + + public JvctsBitbucketServerClient(ViolationsToBitbucketServerConfig config, BuildListener listener) { + this.config = config; + this.listener = listener; + } + + @VisibleForTesting + public static void setBitbucketServerInvoker(BitbucketServerInvoker bitbucketServerInvoker) { + JvctsBitbucketServerClient.bitbucketServerInvoker = bitbucketServerInvoker; + } + + public List getChangedFileInPullRequest() { + return invokeAndParse(getBitbucketServerPulLRequestBase() + "/changes?limit=999999", "$..path.toString"); + } + + public void commentPullRequest(String changedFile, int line, String message) { + String postContent = "{ \"text\": \"" + message.replaceAll("\"", "") + "\", \"anchor\": { \"line\": \"" + line + + "\", \"lineType\": \"ADDED\", \"fileType\": \"TO\", \"path\": \"" + changedFile + "\" }}"; + bitbucketServerInvoker.invokeUrl(config, getBitbucketServerPulLRequestBase() + "/comments", + BitbucketServerInvoker.Method.POST, postContent, listener); + } + + @SuppressWarnings("rawtypes") + public void removeCommentsFromPullRequest(String changedFile) { + for (Object comment : getCommentsOnPullRequest(changedFile)) { + if (toMap(toMap(comment).get("author")).get("name").equals(config.getBitbucketServerUser())) { + removeCommentFromPullRequest((Map) comment); + } + } + } + + @SuppressWarnings("unchecked") + private Map toMap(Object o) { + return (Map) o; + } + + private JSONArray getCommentsOnPullRequest(String changedFile) { + return invokeAndParse(getBitbucketServerPulLRequestBase() + "/comments?path=" + changedFile + "&limit=999999", + "$.values[*]"); + } + + private T invokeAndParse(String url, String jsonPath) { + String json = bitbucketServerInvoker.invokeUrl(config, url, BitbucketServerInvoker.Method.GET, null, listener); + try { + return JsonPath.read(json, jsonPath); + } catch (Exception e) { + doLog(listener, SEVERE, url + ":\n" + json, e); + return null; + } + } + + private void removeCommentFromPullRequest(@SuppressWarnings("rawtypes") Map comment) { + bitbucketServerInvoker.invokeUrl(config, getBitbucketServerPulLRequestBase() + "/comments/" + comment.get(ID) + + "?version=" + comment.get(VERSION), BitbucketServerInvoker.Method.DELETE, "", listener); + } + + private String getBitbucketServerPulLRequestBase() { + return config.getBitbucketServerBaseUrl() + "/rest/api/1.0/projects/" + config.getBitbucketServerProject() + + "/repos/" + config.getBitbucketServerRepo() + "/pull-requests/" + config.getBitbucketServerPullRequestId(); + } + + private String getBitbucketServerCommitsBase() { + return config.getBitbucketServerBaseUrl() + "/rest/api/1.0/projects/" + config.getBitbucketServerProject() + + "/repos/" + config.getBitbucketServerRepo() + "/commits/" + config.getCommitHash(); + } + + public List getChangedFileInCommit() { + return invokeAndParse(getBitbucketServerCommitsBase() + "/changes?limit=999999", "$..path.toString"); + } + + private JSONArray getCommentsOnCommit(String changedFile) { + return invokeAndParse(getBitbucketServerCommitsBase() + "/comments?path=" + changedFile + "&limit=999999", "$.values[*]"); + } + + @SuppressWarnings("rawtypes") + public void removeCommentsCommit(String changedFile) { + for (Object comment : getCommentsOnCommit(changedFile)) { + if (toMap(toMap(comment).get("author")).get("name").equals(config.getBitbucketServerUser())) { + removeCommentFromCommit((Map) comment); + } + } + } + + private void removeCommentFromCommit(@SuppressWarnings("rawtypes") Map comment) { + bitbucketServerInvoker.invokeUrl(config, getBitbucketServerCommitsBase() + "/comments/" + comment.get(ID) + "?version=" + + comment.get(VERSION), BitbucketServerInvoker.Method.DELETE, "", listener); + } + + public void commentCommit(String changedFile, int line, String message) { + String postContent = "{ \"text\": \"" + message.replaceAll("\"", "") + "\", \"anchor\": { \"line\": \"" + line + + "\", \"lineType\": \"ADDED\", \"fileType\": \"TO\", \"path\": \"" + changedFile + "\" }}"; + bitbucketServerInvoker.invokeUrl(config, getBitbucketServerCommitsBase() + "/comments", BitbucketServerInvoker.Method.POST, + postContent, listener); + } +} diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfig.java b/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfig.java new file mode 100644 index 0000000..1fda28e --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfig.java @@ -0,0 +1,87 @@ +package org.jenkinsci.plugins.jvcts.config; + +import static com.google.common.collect.Lists.newArrayList; + +import java.util.List; + +public class ViolationsToBitbucketServerConfig { + private List parsers = newArrayList(); + private String bitbucketServerBaseUrl; + private String bitbucketServerUser; + private String bitbucketServerPassword; + private String bitbucketServerProject; + private String bitbucketServerRepo; + private String bitbucketServerPullRequestId; + private String commitHash; + + public ViolationsToBitbucketServerConfig() { + + } + + public List getParserConfigs() { + return parsers; + } + + public void setParsers(List parsers) { + this.parsers = parsers; + } + + public void setBitbucketServerBaseUrl(String bitbucketServerBaseUrl) { + if (bitbucketServerBaseUrl.endsWith("/")) { + bitbucketServerBaseUrl = bitbucketServerBaseUrl.substring(0, bitbucketServerBaseUrl.length() - 1); + } + this.bitbucketServerBaseUrl = bitbucketServerBaseUrl; + } + + public void setBitbucketServerProject(String bitbucketServerProject) { + this.bitbucketServerProject = bitbucketServerProject; + } + + public void setBitbucketServerRepo(String bitbucketServerRepo) { + this.bitbucketServerRepo = bitbucketServerRepo; + } + + public void setBitbucketServerPullRequestId(String bitbucketServerPullRequestId) { + this.bitbucketServerPullRequestId = bitbucketServerPullRequestId; + } + + public String getBitbucketServerBaseUrl() { + return bitbucketServerBaseUrl; + } + + public String getBitbucketServerProject() { + return bitbucketServerProject; + } + + public String getBitbucketServerRepo() { + return bitbucketServerRepo; + } + + public String getBitbucketServerPullRequestId() { + return bitbucketServerPullRequestId; + } + + public void setBitbucketServerPassword(String bitbucketServerPassword) { + this.bitbucketServerPassword = bitbucketServerPassword; + } + + public void setBitbucketServerUser(String bitbucketServerUser) { + this.bitbucketServerUser = bitbucketServerUser; + } + + public String getBitbucketServerPassword() { + return bitbucketServerPassword; + } + + public String getBitbucketServerUser() { + return bitbucketServerUser; + } + + public void setCommitHash(String commitHash) { + this.commitHash = commitHash; + } + + public String getCommitHash() { + return commitHash; + } +} diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfigHelper.java b/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfigHelper.java similarity index 67% rename from src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfigHelper.java rename to src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfigHelper.java index 0103c48..5ac7174 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfigHelper.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToBitbucketServerConfigHelper.java @@ -5,7 +5,7 @@ import java.util.List; -public class ViolationsToStashConfigHelper { +public class ViolationsToBitbucketServerConfigHelper { public static final String CHECKSTYLE_NAME = "checkstyle"; public static final String CODENARC_NAME = "codenarc"; public static final String CPD_NAME = "cpd"; @@ -24,16 +24,16 @@ public class ViolationsToStashConfigHelper { public static final String STYLECOP_NAME = "stylecop"; public static final String FIELD_PATTERN = "pattern"; public static final String FIELD_PREFIX = "pathPrefix"; - public static final String FIELD_STASH_PULL_REQUEST_ID = "stashPullRequestId"; + public static final String FIELD_BITBUCKET_SERVER_PULL_REQUEST_ID = "bitbucketServerPullRequestId"; public static final String FIELD_COMMIT_HASH = "commitHash"; - public static final String FIELD_STASH_REPO = "stashRepo"; - public static final String FIELD_STASH_PROJECT = "stashProject"; - public static final String FIELD_STASH_BASE_URL = "stashBaseUrl"; - public static final String FIELD_STASH_USER = "stashUser"; - public static final String FIELD_STASH_PASSWORD = "stashPassword"; + public static final String FIELD_BITBUCKET_SERVER_REPO = "bitbucketServerRepo"; + public static final String FIELD_BITBUCKET_SERVER_PROJECT = "bitbucketServerProject"; + public static final String FIELD_BITBUCKET_SERVER_BASE_URL = "bitbucketServerBaseUrl"; + public static final String FIELD_BITBUCKET_SERVER_USER = "bitbucketServerUser"; + public static final String FIELD_BITBUCKET_SERVER_PASSWORD = "bitbucketServerPassword"; - public static ViolationsToStashConfig createNewConfig() { - ViolationsToStashConfig config = new ViolationsToStashConfig(); + public static ViolationsToBitbucketServerConfig createNewConfig() { + ViolationsToBitbucketServerConfig config = new ViolationsToBitbucketServerConfig(); List parsers = newArrayList(); for (TypeDescriptor parser : TypeDescriptor.TYPES.values()) { ParserConfig parserConfig = new ParserConfig(); diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfig.java b/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfig.java deleted file mode 100644 index fd34135..0000000 --- a/src/main/java/org/jenkinsci/plugins/jvcts/config/ViolationsToStashConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.jenkinsci.plugins.jvcts.config; - -import static com.google.common.collect.Lists.newArrayList; - -import java.util.List; - -public class ViolationsToStashConfig { - private List parsers = newArrayList(); - private String stashBaseUrl; - private String stashUser; - private String stashPassword; - private String stashProject; - private String stashRepo; - private String stashPullRequestId; - private String commitHash; - - public ViolationsToStashConfig() { - - } - - public List getParserConfigs() { - return parsers; - } - - public void setParsers(List parsers) { - this.parsers = parsers; - } - - public void setStashBaseUrl(String stashBaseUrl) { - if (stashBaseUrl.endsWith("/")) { - stashBaseUrl = stashBaseUrl.substring(0, stashBaseUrl.length() - 1); - } - this.stashBaseUrl = stashBaseUrl; - } - - public void setStashProject(String stashProject) { - this.stashProject = stashProject; - } - - public void setStashRepo(String stashRepo) { - this.stashRepo = stashRepo; - } - - public void setStashPullRequestId(String stashPullRequestId) { - this.stashPullRequestId = stashPullRequestId; - } - - public String getStashBaseUrl() { - return stashBaseUrl; - } - - public String getStashProject() { - return stashProject; - } - - public String getStashRepo() { - return stashRepo; - } - - public String getStashPullRequestId() { - return stashPullRequestId; - } - - public void setStashPassword(String stashPassword) { - this.stashPassword = stashPassword; - } - - public void setStashUser(String stashUser) { - this.stashUser = stashUser; - } - - public String getStashPassword() { - return stashPassword; - } - - public String getStashUser() { - return stashUser; - } - - public void setCommitHash(String commitHash) { - this.commitHash = commitHash; - } - - public String getCommitHash() { - return commitHash; - } -} diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/perform/FullBuildModelWrapper.java b/src/main/java/org/jenkinsci/plugins/jvcts/perform/FullBuildModelWrapper.java index 3cba94e..c0eb52b 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/perform/FullBuildModelWrapper.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/perform/FullBuildModelWrapper.java @@ -23,17 +23,17 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import org.jenkinsci.plugins.jvcts.config.ParserConfig; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; import com.google.common.annotations.VisibleForTesting; public class FullBuildModelWrapper { private final Map models = newHashMap(); - private final ViolationsToStashConfig config; + private final ViolationsToBitbucketServerConfig config; private final BuildListener listener; - public FullBuildModelWrapper(ViolationsToStashConfig config, File workspace, BuildListener listener) { + public FullBuildModelWrapper(ViolationsToBitbucketServerConfig config, File workspace, BuildListener listener) { this.config = config; this.listener = listener; for (ParserConfig parserConfig : config.getParserConfigs()) { diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java b/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java index 8940d17..a3130c0 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java @@ -7,12 +7,12 @@ import static java.util.logging.Level.FINE; import static java.util.logging.Level.SEVERE; import static org.jenkinsci.plugins.jvcts.JvctsLogger.doLog; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_COMMIT_HASH; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_BASE_URL; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_PROJECT; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_PULL_REQUEST_ID; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_REPO; -import static org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfigHelper.FIELD_STASH_USER; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_BASE_URL; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_PROJECT; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_PULL_REQUEST_ID; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_REPO; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_BITBUCKET_SERVER_USER; +import static org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMIT_HASH; import hudson.EnvVars; import hudson.model.BuildListener; import hudson.model.AbstractBuild; @@ -24,25 +24,26 @@ import java.util.Map; import org.jenkinsci.plugins.jvcts.JvctsLogger; +import org.jenkinsci.plugins.jvcts.bitbucketserver.JvctsBitbucketServerClient; import org.jenkinsci.plugins.jvcts.config.ParserConfig; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; -import org.jenkinsci.plugins.jvcts.stash.JvctsStashClient; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; import com.google.common.annotations.VisibleForTesting; public class JvctsPerformer { - public static void jvctsPerform(ViolationsToStashConfig config, AbstractBuild build, BuildListener listener) { + public static void jvctsPerform(ViolationsToBitbucketServerConfig config, AbstractBuild build, + BuildListener listener) { try { EnvVars env = build.getEnvironment(listener); config = expand(config, env); listener.getLogger().println("---"); - listener.getLogger().println("--- Jenkins Violation Comments to Stash ---"); + listener.getLogger().println("--- Jenkins Violation Comments to Bitbucket Server ---"); listener.getLogger().println("---"); logConfiguration(config, build, listener); - listener.getLogger().println("Running Jenkins Violation Comments To Stash"); - listener.getLogger().println("Will comment " + config.getStashPullRequestId()); + listener.getLogger().println("Running Jenkins Violation Comments To Bitbucket Server"); + listener.getLogger().println("Will comment " + config.getBitbucketServerPullRequestId()); File workspace = new File(build.getExecutor().getCurrentWorkspace().toURI()); doLog(FINE, "Workspace: " + workspace.getAbsolutePath()); @@ -54,52 +55,55 @@ public static void jvctsPerform(ViolationsToStashConfig config, AbstractBuild> violationsPerFile, ViolationsToStashConfig config, - BuildListener listener) throws MalformedURLException { - JvctsStashClient jvctsStashClient = new JvctsStashClient(config, listener); - if (!isNullOrEmpty(config.getStashPullRequestId())) { - doLog(FINE, "Commenting pull request \"" + config.getStashPullRequestId() + "\""); - for (String changedFileInStash : jvctsStashClient.getChangedFileInPullRequest()) { - doLog(FINE, "Changed file in pull request: \"" + changedFileInStash + "\""); - jvctsStashClient.removeCommentsFromPullRequest(changedFileInStash); - for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInStash, listener)) { - jvctsStashClient.commentPullRequest(changedFileInStash, violation.getLine(), constructCommentMessage(violation)); + private static void commentBitbucketServer(Map> violationsPerFile, + ViolationsToBitbucketServerConfig config, BuildListener listener) throws MalformedURLException { + JvctsBitbucketServerClient jvctsBitbucketServerClient = new JvctsBitbucketServerClient(config, listener); + if (!isNullOrEmpty(config.getBitbucketServerPullRequestId())) { + doLog(FINE, "Commenting pull request \"" + config.getBitbucketServerPullRequestId() + "\""); + for (String changedFileInBitbucketServer : jvctsBitbucketServerClient.getChangedFileInPullRequest()) { + doLog(FINE, "Changed file in pull request: \"" + changedFileInBitbucketServer + "\""); + jvctsBitbucketServerClient.removeCommentsFromPullRequest(changedFileInBitbucketServer); + for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInBitbucketServer, listener)) { + jvctsBitbucketServerClient.commentPullRequest(changedFileInBitbucketServer, violation.getLine(), + constructCommentMessage(violation)); } } } if (!isNullOrEmpty(config.getCommitHash())) { doLog(FINE, "Commenting commit \"" + config.getCommitHash() + "\""); - for (String changedFileInStash : jvctsStashClient.getChangedFileInCommit()) { - doLog(FINE, "Changed file in commit: \"" + changedFileInStash + "\""); - jvctsStashClient.removeCommentsCommit(changedFileInStash); - for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInStash, listener)) { - jvctsStashClient.commentCommit(changedFileInStash, violation.getLine(), constructCommentMessage(violation)); + for (String changedFileInBitbucketServer : jvctsBitbucketServerClient.getChangedFileInCommit()) { + doLog(FINE, "Changed file in commit: \"" + changedFileInBitbucketServer + "\""); + jvctsBitbucketServerClient.removeCommentsCommit(changedFileInBitbucketServer); + for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInBitbucketServer, listener)) { + jvctsBitbucketServerClient.commentCommit(changedFileInBitbucketServer, violation.getLine(), + constructCommentMessage(violation)); } } } } /** - * Get list of violations that has files ending with changed file in Stash. - * Violation instances may have absolute or relative paths, we can not trust - * that. + * Get list of violations that has files ending with changed file in Bitbucket + * Server. Violation instances may have absolute or relative paths, we can not + * trust that. */ private static List getViolationsForFile(Map> violationsPerFile, - String changedFileInStash, BuildListener listener) { + String changedFileInBitbucketServer, BuildListener listener) { List found = newArrayList(); for (String reportedFile : violationsPerFile.keySet()) { - if (reportedFile.endsWith(changedFileInStash) || changedFileInStash.endsWith(reportedFile)) { - JvctsLogger.doLog(listener, FINE, "Found comments for \"" + changedFileInStash + "\" (reported as \"" + if (reportedFile.endsWith(changedFileInBitbucketServer) || changedFileInBitbucketServer.endsWith(reportedFile)) { + JvctsLogger.doLog(listener, FINE, "Found comments for \"" + changedFileInBitbucketServer + "\" (reported as \"" + reportedFile + "\")"); found.addAll(violationsPerFile.get(reportedFile)); } else { - doLog(FINE, "Changed file and reported file not matching. Stash: \"" + changedFileInStash + "\" Reported: \"" - + reportedFile + "\""); + doLog(FINE, "Changed file and reported file not matching. Bitbucket Server: \"" + changedFileInBitbucketServer + + "\" Reported: \"" + reportedFile + "\""); } } return found; @@ -119,15 +123,15 @@ private static String constructCommentMessage(Violation v) { * Makes sure any Jenkins variable, used in the configuration fields, are * evaluated. */ - private static ViolationsToStashConfig expand(ViolationsToStashConfig config, EnvVars environment) { - ViolationsToStashConfig expanded = new ViolationsToStashConfig(); - expanded.setStashBaseUrl(environment.expand(config.getStashBaseUrl())); - expanded.setStashUser(environment.expand(config.getStashUser())); - expanded.setStashPassword(environment.expand(config.getStashPassword())); - expanded.setStashProject(environment.expand(config.getStashProject())); - expanded.setStashPullRequestId(environment.expand(config.getStashPullRequestId())); + private static ViolationsToBitbucketServerConfig expand(ViolationsToBitbucketServerConfig config, EnvVars environment) { + ViolationsToBitbucketServerConfig expanded = new ViolationsToBitbucketServerConfig(); + expanded.setBitbucketServerBaseUrl(environment.expand(config.getBitbucketServerBaseUrl())); + expanded.setBitbucketServerUser(environment.expand(config.getBitbucketServerUser())); + expanded.setBitbucketServerPassword(environment.expand(config.getBitbucketServerPassword())); + expanded.setBitbucketServerProject(environment.expand(config.getBitbucketServerProject())); + expanded.setBitbucketServerPullRequestId(environment.expand(config.getBitbucketServerPullRequestId())); expanded.setCommitHash(environment.expand(config.getCommitHash())); - expanded.setStashRepo(environment.expand(config.getStashRepo())); + expanded.setBitbucketServerRepo(environment.expand(config.getBitbucketServerRepo())); for (ParserConfig parserConfig : config.getParserConfigs()) { ParserConfig p = new ParserConfig(); p.setParserTypeDescriptor(parserConfig.getParserTypeDescriptor()); @@ -141,13 +145,15 @@ private static ViolationsToStashConfig expand(ViolationsToStashConfig config, En /** * Enables testing of configuration GUI. */ - private static void logConfiguration(ViolationsToStashConfig config, AbstractBuild build, BuildListener listener) { - listener.getLogger().println(FIELD_STASH_USER + ": " + config.getStashUser()); - listener.getLogger().println(FIELD_STASH_BASE_URL + ": " + config.getStashBaseUrl()); - listener.getLogger().println(FIELD_STASH_PROJECT + ": " + config.getStashProject()); - listener.getLogger().println(FIELD_STASH_PULL_REQUEST_ID + ": " + config.getStashPullRequestId()); + private static void logConfiguration(ViolationsToBitbucketServerConfig config, AbstractBuild build, + BuildListener listener) { + listener.getLogger().println(FIELD_BITBUCKET_SERVER_USER + ": " + config.getBitbucketServerUser()); + listener.getLogger().println(FIELD_BITBUCKET_SERVER_BASE_URL + ": " + config.getBitbucketServerBaseUrl()); + listener.getLogger().println(FIELD_BITBUCKET_SERVER_PROJECT + ": " + config.getBitbucketServerProject()); + listener.getLogger() + .println(FIELD_BITBUCKET_SERVER_PULL_REQUEST_ID + ": " + config.getBitbucketServerPullRequestId()); listener.getLogger().println(FIELD_COMMIT_HASH + ": " + config.getCommitHash()); - listener.getLogger().println(FIELD_STASH_REPO + ": " + config.getStashRepo()); + listener.getLogger().println(FIELD_BITBUCKET_SERVER_REPO + ": " + config.getBitbucketServerRepo()); for (ParserConfig parserConfig : config.getParserConfigs()) { listener.getLogger().println(parserConfig.getParserTypeDescriptor().getName() + ": " + parserConfig.getPattern()); if (parserConfig.getPathPrefixOpt().isPresent()) { diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/stash/JvctsStashClient.java b/src/main/java/org/jenkinsci/plugins/jvcts/stash/JvctsStashClient.java deleted file mode 100644 index 214b7e3..0000000 --- a/src/main/java/org/jenkinsci/plugins/jvcts/stash/JvctsStashClient.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.jenkinsci.plugins.jvcts.stash; - -import static java.util.logging.Level.SEVERE; -import static org.jenkinsci.plugins.jvcts.JvctsLogger.doLog; -import hudson.model.BuildListener; - -import java.util.List; -import java.util.Map; - -import net.minidev.json.JSONArray; - -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; - -import com.google.common.annotations.VisibleForTesting; -import com.jayway.jsonpath.JsonPath; - -public class JvctsStashClient { - private static final String VERSION = "version"; - private static final String ID = "id"; - private static StashInvoker stashInvoker = new StashInvoker(); - private final ViolationsToStashConfig config; - private final BuildListener listener; - - public JvctsStashClient(ViolationsToStashConfig config, BuildListener listener) { - this.config = config; - this.listener = listener; - } - - @VisibleForTesting - public static void setStashInvoker(StashInvoker stashInvoker) { - JvctsStashClient.stashInvoker = stashInvoker; - } - - public List getChangedFileInPullRequest() { - return invokeAndParse(getStashPulLRequestBase() + "/changes?limit=999999", "$..path.toString"); - } - - public void commentPullRequest(String changedFile, int line, String message) { - String postContent = "{ \"text\": \"" + message.replaceAll("\"", "") + "\", \"anchor\": { \"line\": \"" + line - + "\", \"lineType\": \"ADDED\", \"fileType\": \"TO\", \"path\": \"" + changedFile + "\" }}"; - stashInvoker.invokeUrl(config, getStashPulLRequestBase() + "/comments", StashInvoker.Method.POST, postContent, - listener); - } - - @SuppressWarnings("rawtypes") - public void removeCommentsFromPullRequest(String changedFile) { - for (Object comment : getCommentsOnPullRequest(changedFile)) { - if (toMap(toMap(comment).get("author")).get("name").equals(config.getStashUser())) { - removeCommentFromPullRequest((Map) comment); - } - } - } - - @SuppressWarnings("unchecked") - private Map toMap(Object o) { - return (Map) o; - } - - private JSONArray getCommentsOnPullRequest(String changedFile) { - return invokeAndParse(getStashPulLRequestBase() + "/comments?path=" + changedFile + "&limit=999999", "$.values[*]"); - } - - private T invokeAndParse(String url, String jsonPath) { - String json = stashInvoker.invokeUrl(config, url, StashInvoker.Method.GET, null, listener); - try { - return JsonPath.read(json, jsonPath); - } catch (Exception e) { - doLog(listener, SEVERE, url + ":\n" + json, e); - return null; - } - } - - private void removeCommentFromPullRequest(@SuppressWarnings("rawtypes") Map comment) { - stashInvoker.invokeUrl(config, - getStashPulLRequestBase() + "/comments/" + comment.get(ID) + "?version=" + comment.get(VERSION), - StashInvoker.Method.DELETE, "", listener); - } - - private String getStashPulLRequestBase() { - return config.getStashBaseUrl() + "/rest/api/1.0/projects/" + config.getStashProject() + "/repos/" - + config.getStashRepo() + "/pull-requests/" + config.getStashPullRequestId(); - } - - private String getStashCommitsBase() { - return config.getStashBaseUrl() + "/rest/api/1.0/projects/" + config.getStashProject() + "/repos/" - + config.getStashRepo() + "/commits/" + config.getCommitHash(); - } - - public List getChangedFileInCommit() { - return invokeAndParse(getStashCommitsBase() + "/changes?limit=999999", "$..path.toString"); - } - - private JSONArray getCommentsOnCommit(String changedFile) { - return invokeAndParse(getStashCommitsBase() + "/comments?path=" + changedFile + "&limit=999999", "$.values[*]"); - } - - @SuppressWarnings("rawtypes") - public void removeCommentsCommit(String changedFile) { - for (Object comment : getCommentsOnCommit(changedFile)) { - if (toMap(toMap(comment).get("author")).get("name").equals(config.getStashUser())) { - removeCommentFromCommit((Map) comment); - } - } - } - - private void removeCommentFromCommit(@SuppressWarnings("rawtypes") Map comment) { - stashInvoker.invokeUrl(config, - getStashCommitsBase() + "/comments/" + comment.get(ID) + "?version=" + comment.get(VERSION), - StashInvoker.Method.DELETE, "", listener); - } - - public void commentCommit(String changedFile, int line, String message) { - String postContent = "{ \"text\": \"" + message.replaceAll("\"", "") + "\", \"anchor\": { \"line\": \"" + line - + "\", \"lineType\": \"ADDED\", \"fileType\": \"TO\", \"path\": \"" + changedFile + "\" }}"; - stashInvoker.invokeUrl(config, getStashCommitsBase() + "/comments", StashInvoker.Method.POST, postContent, listener); - } -} diff --git a/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/config.jelly b/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/config.jelly similarity index 68% rename from src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/config.jelly rename to src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/config.jelly index 234e35f..547f43d 100644 --- a/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/config.jelly @@ -7,10 +7,10 @@ xmlns:st="jelly:stapler" xmlns:t="/lib/hudson"> - + - + @@ -20,34 +20,34 @@
- Stash server + Bitbucket Server
- + - + - + - + - + - + @@ -62,7 +62,7 @@ XML filename pattern
  • The pattern may be, for example, **/checkstyle-report.xml to match checkstyle-report.xml anywhere in workspace.
  • -
  • The path prefix is optional. Some checkers may have relative paths in the reports (xml-files). Stash API:s will report changes, in the pull request, relative to repository root. In order to match changes in pull request to file in report, you may need to set a prefix path.
  • +
  • The path prefix is optional. Some checkers may have relative paths in the reports (xml-files). Bitbucket Server API:s will report changes, in the pull request, relative to repository root. In order to match changes in pull request to file in report, you may need to set a prefix path.
diff --git a/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/help.html b/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/help.html new file mode 100644 index 0000000..eca5bec --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToBitbucketServerRecorder/help.html @@ -0,0 +1,9 @@ +
+

+ See Violation Comments to Bitbucket Server Plugin for details on how to configure and use this plugin. +

+ +

+ Filename patterns are optional. The syntax is Apache DirectoryScanner, for example **/*.xml matches xml-files anywhere in workspace. +

+
diff --git a/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/help.html b/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/help.html deleted file mode 100644 index 0e9777a..0000000 --- a/src/main/resources/org/jenkinsci/plugins/jvcts/ViolationsToStashRecorder/help.html +++ /dev/null @@ -1,9 +0,0 @@ -
-

- See Jenkins Violations Plugin for details on how to configure and use this plugin. -

- -

- Filename patterns are optional. The syntax is Apache DirectoryScanner, for example **/*.xml matches xml-files anywhere in workspace. -

-
diff --git a/src/test/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformerParseTest.java b/src/test/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformerParseTest.java index 921b0b1..b894c7d 100644 --- a/src/test/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformerParseTest.java +++ b/src/test/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformerParseTest.java @@ -10,22 +10,22 @@ import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.assertRequested; import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.getWorkspace; import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.preConfigure; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.CHANGES_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_1_DELETE; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_2_DELETE; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_CHECKSTYLEFILE_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_FINDBUGS_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_PMDANDCHECKSTYLE_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.COMMENTS_PMDFILE_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.fake; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.prToCommit; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.readFile; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.CHANGES_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_1_DELETE; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_2_DELETE; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_CHECKSTYLEFILE_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_FINDBUGS_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_PMDANDCHECKSTYLE_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.COMMENTS_PMDFILE_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.fake; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.prToCommit; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.readFile; import hudson.model.StreamBuildListener; import java.io.IOException; import org.jenkinsci.plugins.jvcts.config.ParserConfig; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -35,10 +35,10 @@ public class JvctsPerformerParseTest { @Test public void testThatPullRequestCheckstyleIsCommented() throws IOException { fake(CHANGES_GET, readFile("pullrequestchanges_1_GET.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(CHECKSTYLE), "**/" + CHECKSTYLE + ".xml, **/" + CHECKSTYLE + "_relativePath.xml")) .build()); - config.setStashPullRequestId("1"); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); assertRequested(readFile("checkstyle_checkstylefile_1.json")); assertRequested(readFile("checkstyle_checkstylefile_2.json")); @@ -59,11 +59,11 @@ public void testThatPullRequestCheckstyleHtmlLintIsCommented() throws Exception @Test public void testThatPullRequestOldCommentsAreDeleted() throws IOException { fake(CHANGES_GET, readFile("pullrequestchanges_1_GET.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(PMD), "**/" + PMD + ".xml"), new ParserConfig(TYPES.get(CHECKSTYLE), "**/" + CHECKSTYLE + ".xml, **/" + CHECKSTYLE + "_relativePath.xml"), new ParserConfig(TYPES.get(FINDBUGS), "**/" + FINDBUGS + ".xml")).build()); - config.setStashPullRequestId("1"); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); assertRequested(COMMENTS_CHECKSTYLEFILE_GET); assertRequested(COMMENTS_PMDANDCHECKSTYLE_GET); @@ -79,11 +79,11 @@ public void testThatPullRequestCheckstyleAndPmdCanCommentsOnSameFileIsCommented( fake( "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/comments?path=project/index.html&limit=999999 GET", readFile("pullrequestcomments_GET_none.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(PMD), "**/" + PMD + ".xml"), new ParserConfig(TYPES.get(CHECKSTYLE), "**/" + CHECKSTYLE + ".xml, **/" + CHECKSTYLE + "_relativePath.xml"), new ParserConfig(TYPES.get(FINDBUGS), "**/" + FINDBUGS + ".xml")).build()); - config.setStashPullRequestId("1"); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); assertRequested(readFile("checkstyle_pmdandcheckstyle.json")); } @@ -91,9 +91,9 @@ public void testThatPullRequestCheckstyleAndPmdCanCommentsOnSameFileIsCommented( @Test public void testThatPullRequestPmdIsCommented() throws IOException { fake(CHANGES_GET, readFile("pullrequestchanges_1_GET.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(PMD), "**/" + PMD + ".xml")).build()); - config.setStashPullRequestId("1"); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); assertRequested(readFile("pmd_pmdfile.json")); } @@ -101,9 +101,9 @@ public void testThatPullRequestPmdIsCommented() throws IOException { @Test public void testThatPullRequestFindbugsIsCommented() throws IOException { fake(CHANGES_GET, readFile("pullrequestchanges_1_GET.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(FINDBUGS), "**/" + FINDBUGS + ".xml")).build()); - config.setStashPullRequestId("1"); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); assertRequested(readFile("findbugs_code.json")); } @@ -114,7 +114,7 @@ public void testThatCommitCheckstyleIsCommented() throws IOException { fake( "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/comments?path=project/index.html&limit=999999 GET", readFile("pullrequestcomments_GET_none.json")); - ViolationsToStashConfig config = preConfigure(new ImmutableList.Builder().add( + ViolationsToBitbucketServerConfig config = preConfigure(new ImmutableList.Builder().add( new ParserConfig(TYPES.get(CHECKSTYLE), "**/" + CHECKSTYLE + ".xml, **/" + CHECKSTYLE + "_relativePath.xml")) .build()); config.setCommitHash("1"); diff --git a/src/test/java/org/jenkinsci/plugins/jvcts/utils/StashClientFaker.java b/src/test/java/org/jenkinsci/plugins/jvcts/utils/BitbucketServerClientFaker.java similarity index 84% rename from src/test/java/org/jenkinsci/plugins/jvcts/utils/StashClientFaker.java rename to src/test/java/org/jenkinsci/plugins/jvcts/utils/BitbucketServerClientFaker.java index fa5c03f..065c811 100644 --- a/src/test/java/org/jenkinsci/plugins/jvcts/utils/StashClientFaker.java +++ b/src/test/java/org/jenkinsci/plugins/jvcts/utils/BitbucketServerClientFaker.java @@ -6,19 +6,19 @@ import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.newHashMap; import static com.google.common.io.Resources.getResource; -import static org.jenkinsci.plugins.jvcts.stash.JvctsStashClient.setStashInvoker; +import static org.jenkinsci.plugins.jvcts.bitbucketserver.JvctsBitbucketServerClient.setBitbucketServerInvoker; import hudson.model.BuildListener; import java.io.IOException; import java.util.List; import java.util.Map; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; -import org.jenkinsci.plugins.jvcts.stash.StashInvoker; +import org.jenkinsci.plugins.jvcts.bitbucketserver.BitbucketServerInvoker; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; import com.google.common.io.Resources; -public class StashClientFaker { +public class BitbucketServerClientFaker { public static final String NO_REPORTABLES = "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/comments?path=src/se/main/java/bjurr/FileThatHasNoReportables.java&limit=999999 GET"; public static final String COMMENTS_PMDFILE_GET = "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/comments?path=module/src/main/java/se/bjurr/PMDFile.java&limit=999999 GET"; @@ -30,22 +30,22 @@ public class StashClientFaker { public static final String COMMENTS_FINDBUGS_GET = "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/comments?path=module/se/bjurr/analyzer/Code.java&limit=999999 GET"; public static final String CHANGES_GET = "http://stash.server/rest/api/1.0/projects/stashProject/repos/stashRepo/pull-requests/1/changes?limit=999999 GET"; private static Map fakeResponses = newHashMap(); - private static List requestsSentToStash = newArrayList(); + private static List requestsSentToBitbucketServer = newArrayList(); - private StashClientFaker() { + private BitbucketServerClientFaker() { } - public static void fakeStashClient() throws IOException { - setStashInvoker(new StashInvoker() { + public static void fakeBitbucketServerClient() throws IOException { + setBitbucketServerInvoker(new BitbucketServerInvoker() { @Override - public String invokeUrl(ViolationsToStashConfig config, String url, Method method, String postContent, + public String invokeUrl(ViolationsToBitbucketServerConfig config, String url, Method method, String postContent, BuildListener listener) { String key = createFakeKey(url, method.name(), postContent); if (!fakeResponses.containsKey(key)) { throw new RuntimeException("\"" + key + "\" not faked!\nThese are faked:\n" + on("\n").join(fakeResponses.keySet())); } - requestsSentToStash.add(key); + requestsSentToBitbucketServer.add(key); return fakeResponses.get(key); } }); @@ -81,8 +81,8 @@ private static String createFakeKey(String url, String method, String postConten return (url + " " + method + " " + nullToEmpty(postContent)).trim(); } - public static List getRequestsSentToStash() { - return requestsSentToStash; + public static List getRequestsSentToBitbucketServer() { + return requestsSentToBitbucketServer; } public static String prToCommit(String string) { diff --git a/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestBuilder.java b/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestBuilder.java index 7fd1e7d..bdb3e87 100644 --- a/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestBuilder.java +++ b/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestBuilder.java @@ -8,16 +8,16 @@ import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.assertRequested; import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.getWorkspace; import static org.jenkinsci.plugins.jvcts.utils.JvctsTestUtils.preConfigure; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.CHANGES_GET; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.fake; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.readFile; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.CHANGES_GET; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.fake; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.readFile; import hudson.model.StreamBuildListener; import java.util.List; import java.util.Map; import org.jenkinsci.plugins.jvcts.config.ParserConfig; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; public class JvctsTestBuilder { @@ -45,8 +45,8 @@ public void test() throws Exception { for (String pattern : patternsPerType.keySet()) { configs.add(new ParserConfig(TYPES.get(pattern), patternsPerType.get(pattern))); } - ViolationsToStashConfig config = preConfigure(configs); - config.setStashPullRequestId("1"); + ViolationsToBitbucketServerConfig config = preConfigure(configs); + config.setBitbucketServerPullRequestId("1"); doPerform(config, getWorkspace(), new StreamBuildListener(System.out, defaultCharset())); for (String asserted : assertRequested) { assertRequested(asserted); diff --git a/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestUtils.java b/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestUtils.java index 2c801b2..2058140 100644 --- a/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestUtils.java +++ b/src/test/java/org/jenkinsci/plugins/jvcts/utils/JvctsTestUtils.java @@ -1,8 +1,8 @@ package org.jenkinsci.plugins.jvcts.utils; import static com.google.common.base.Joiner.on; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.fakeStashClient; -import static org.jenkinsci.plugins.jvcts.utils.StashClientFaker.getRequestsSentToStash; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.fakeBitbucketServerClient; +import static org.jenkinsci.plugins.jvcts.utils.BitbucketServerClientFaker.getRequestsSentToBitbucketServer; import static org.junit.Assert.fail; import java.io.File; @@ -12,7 +12,7 @@ import java.util.logging.Logger; import org.jenkinsci.plugins.jvcts.config.ParserConfig; -import org.jenkinsci.plugins.jvcts.config.ViolationsToStashConfig; +import org.jenkinsci.plugins.jvcts.config.ViolationsToBitbucketServerConfig; import com.google.common.io.Resources; @@ -27,20 +27,20 @@ private static void disableLogging() { } } - public static ViolationsToStashConfig preConfigure(List pconfigs) throws IOException { - ViolationsToStashConfig config = new ViolationsToStashConfig(); + public static ViolationsToBitbucketServerConfig preConfigure(List pconfigs) throws IOException { + ViolationsToBitbucketServerConfig config = new ViolationsToBitbucketServerConfig(); for (ParserConfig pconfig : pconfigs) { config.getParserConfigs().add(pconfig); } - config.setStashBaseUrl("http://stash.server/"); - config.setStashUser("stashUser"); - config.setStashPassword("stashPassword"); - config.setStashProject("stashProject"); - config.setStashRepo("stashRepo"); + config.setBitbucketServerBaseUrl("http://stash.server/"); + config.setBitbucketServerUser("stashUser"); + config.setBitbucketServerPassword("stashPassword"); + config.setBitbucketServerProject("stashProject"); + config.setBitbucketServerRepo("stashRepo"); disableLogging(); - fakeStashClient(); + fakeBitbucketServerClient(); return config; } @@ -49,11 +49,11 @@ public static File getWorkspace() { } public static void assertRequested(String request) { - for (String requested : getRequestsSentToStash()) { + for (String requested : getRequestsSentToBitbucketServer()) { if (requested.equals(request)) { return; } } - fail("Did not capture:\n" + request + "\nCaptured:\n" + on("\n").join(getRequestsSentToStash())); + fail("Did not capture:\n" + request + "\nCaptured:\n" + on("\n").join(getRequestsSentToBitbucketServer())); } }