diff --git a/CHANGELOG.md b/CHANGELOG.md index 6146a66..e70a6ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,24 @@ Changelog of Violation Comments to Bitbucket Server Plugin. ## Unreleased +### GitHub [#37](https://github.com/jenkinsci/violation-comments-to-stash-plugin/issues/37) Individual comments and keeping previous comments + +**Keeping comments and adjusting checkstyle #37** + + * Checkstyle now allows empty source attribute. + * Comments can optionaly be kept and not removed when new comments are added. + * Will no longer re-create identical comments. + +[a2c186f61ea1ea4](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/a2c186f61ea1ea4) Tomas Bjerre *2017-09-02 16:55:28* + + +## 1.53 ### GitHub [#36](https://github.com/jenkinsci/violation-comments-to-stash-plugin/issues/36) java.lang.NullPointerException from violations-lib **Ignoring violation configs with null config #36** -[3371d0a64306695](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/3371d0a64306695) Tomas Bjerre *2017-08-11 10:17:17* +[0f4e03444485c59](https://github.com/jenkinsci/violation-comments-to-stash-plugin/commit/0f4e03444485c59) Tomas Bjerre *2017-08-11 11:30:01* ### No issue diff --git a/README.md b/README.md index 903e654..a31cbe3 100644 --- a/README.md +++ b/README.md @@ -209,10 +209,10 @@ git --no-pager log --max-count=10 --graph --abbrev-commit minSeverity('INFO') createSingleFileComments(true) - createCommentWithAllSingleFileComments(true) - createCommentWithAllSingleFileComments(true) + createCommentWithAllSingleFileComments(false) commentOnlyChangedContent(true) commentOnlyChangedContentContext(5) + keepOldComments(false) violationConfigs { violationConfig { @@ -256,7 +256,7 @@ node { $class: 'ViolationsToBitbucketServerRecorder', config: [ bitbucketServerUrl: 'http://localhost:7990/bitbucket', - createCommentWithAllSingleFileComments: true, + createCommentWithAllSingleFileComments: false, createSingleFileComments: true, projectKey: 'PROJECT_1', repoSlug: 'rep_1', @@ -266,6 +266,7 @@ node { password: 'admin', useUsernamePasswordCredentials: false, minSeverity: 'INFO', + keepOldComments: false, violationConfigs: [ [ pattern: '.*/checkstyle-result\\.xml$', parser: 'CHECKSTYLE', reporter: 'Checkstyle' ], [ pattern: '.*/findbugsXml\\.xml$', parser: 'FINDBUGS', reporter: 'Findbugs' ], diff --git a/pom.xml b/pom.xml index c98ea4f..afd6795 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ - 2.1 + 2.7.4 1.115 2.19 false @@ -202,7 +202,7 @@ Changelog of Violation Comments to Bitbucket Server Plugin. se.bjurr.violations violation-comments-to-bitbucket-server-lib - 1.29 + 1.31 diff --git a/sandbox/violations-test.jenkinsfile b/sandbox/violations-test.jenkinsfile new file mode 100644 index 0000000..26cb49e --- /dev/null +++ b/sandbox/violations-test.jenkinsfile @@ -0,0 +1,41 @@ +node { + deleteDir() + + stage('Merge') { + sh "git init" + sh "git fetch --no-tags --progress https://github.com/tomasbjerre/violations-test.git +refs/heads/*:refs/remotes/origin/* --depth=200" + sh "git checkout origin/master" + sh "git merge origin/feature/addingcrap" + sh "git log --graph --abbrev-commit --max-count=10" + } + + stage('Analyze') { + sh "./gradlew build" + sh "find" + } + + stage('Static code analysis') { + step([ + $class: 'ViolationsToBitbucketServerRecorder', + config: [ + bitbucketServerUrl: 'http://localhost:7990/', + createCommentWithAllSingleFileComments: false, + createSingleFileComments: true, + projectKey: 'PROJ', + repoSlug: 'violations-test', + pullRequestId: '1', + useUsernamePassword: true, + username: 'admin', + password: 'admin', + useUsernamePasswordCredentials: false, + minSeverity: 'INFO', + keepOldComments: false, + violationConfigs: [ + [ pattern: '.*/checkstyle/.*\\.xml$', parser: 'CHECKSTYLE', reporter: 'Checkstyle' ], + [ pattern: '.*/findbugs/.*\\.xml$', parser: 'FINDBUGS', reporter: 'Findbugs' ], + [ pattern: '.*/pmd/.*\\.xml$', parser: 'PMD', reporter: 'PMD' ], + ] + ] + ]) + } +} diff --git a/src/main/java/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerDescriptor.java b/src/main/java/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerDescriptor.java index 9b6e24f..b701c9b 100644 --- a/src/main/java/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerDescriptor.java +++ b/src/main/java/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerDescriptor.java @@ -6,6 +6,7 @@ import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMENTONLYCHANGEDCONTENTCONTEXT; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATECOMMENTWITHALLSINGLEFILECOMMENTS; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATESINGLEFILECOMMENTS; +import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_KEEP_OLD_COMMENTS; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_MINSEVERITY; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PASSWORD; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PATTERN; @@ -75,7 +76,7 @@ public boolean isApplicable( @Override public Publisher newInstance(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException { - ViolationsToBitbucketServerConfig config = createNewConfig(); + final ViolationsToBitbucketServerConfig config = createNewConfig(); config.setBitbucketServerUrl(formData.getString(FIELD_BITBUCKETSERVERURL)); config.setRepoSlug(formData.getString(FIELD_REPOSLUG)); config.setProjectKey(formData.getString(FIELD_PROJECTKEY)); @@ -100,7 +101,8 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) config.setCommentOnlyChangedContentContext( formData.getInt(FIELD_COMMENTONLYCHANGEDCONTENTCONTEXT)); - String minSeverityString = formData.getString(FIELD_MINSEVERITY); + final String minSeverityString = formData.getString(FIELD_MINSEVERITY); + config.setKeepOldComments(formData.getString(FIELD_KEEP_OLD_COMMENTS).equalsIgnoreCase("true")); if (!isNullOrEmpty(minSeverityString)) { config.setMinSeverity(SEVERITY.valueOf(minSeverityString)); } else { @@ -108,16 +110,16 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) } int i = 0; - List patterns = (List) formData.get(FIELD_PATTERN); - List reporters = (List) formData.get(FIELD_REPORTER); - for (String pattern : patterns) { - ViolationConfig violationConfig = config.getViolationConfigs().get(i); + final List patterns = (List) formData.get(FIELD_PATTERN); + final List reporters = (List) formData.get(FIELD_REPORTER); + for (final String pattern : patterns) { + final ViolationConfig violationConfig = config.getViolationConfigs().get(i); violationConfig.setPattern(pattern); - String reporter = reporters.get(i); + final String reporter = reporters.get(i); violationConfig.setReporter(reporter); i++; } - ViolationsToBitbucketServerRecorder publisher = new ViolationsToBitbucketServerRecorder(); + final ViolationsToBitbucketServerRecorder publisher = new ViolationsToBitbucketServerRecorder(); publisher.setConfig(config); return publisher; } diff --git a/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfig.java b/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfig.java index df5b9e0..9e58cac 100644 --- a/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfig.java +++ b/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfig.java @@ -28,6 +28,7 @@ public class ViolationsToBitbucketServerConfig implements Serializable { private List violationConfigs = newArrayList(); private int commentOnlyChangedContentContext; private SEVERITY minSeverity; + private boolean keepOldComments; public ViolationsToBitbucketServerConfig() {} @@ -47,9 +48,10 @@ public ViolationsToBitbucketServerConfig( boolean useUsernamePassword, boolean commentOnlyChangedContent, int commentOnlyChangedContentContext, - SEVERITY minSeverity) { + SEVERITY minSeverity, + boolean keepOldComments) { - List allViolationConfigs = includeAllReporters(violationConfigs); + final List allViolationConfigs = includeAllReporters(violationConfigs); this.violationConfigs = allViolationConfigs; this.createSingleFileComments = createSingleFileComments; @@ -66,6 +68,7 @@ public ViolationsToBitbucketServerConfig( this.commentOnlyChangedContent = commentOnlyChangedContent; this.commentOnlyChangedContentContext = commentOnlyChangedContentContext; this.minSeverity = minSeverity; + this.keepOldComments = keepOldComments; } public ViolationsToBitbucketServerConfig(ViolationsToBitbucketServerConfig rhs) { @@ -84,6 +87,7 @@ public ViolationsToBitbucketServerConfig(ViolationsToBitbucketServerConfig rhs) commentOnlyChangedContent = rhs.commentOnlyChangedContent; commentOnlyChangedContentContext = rhs.commentOnlyChangedContentContext; this.minSeverity = rhs.minSeverity; + this.keepOldComments = rhs.keepOldComments; } public void applyDefaults(ViolationsToBitbucketServerGlobalConfiguration defaults) { @@ -121,7 +125,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - ViolationsToBitbucketServerConfig other = (ViolationsToBitbucketServerConfig) obj; + final ViolationsToBitbucketServerConfig other = (ViolationsToBitbucketServerConfig) obj; if (bitbucketServerUrl == null) { if (other.bitbucketServerUrl != null) { return false; @@ -141,6 +145,9 @@ public boolean equals(Object obj) { if (createSingleFileComments != other.createSingleFileComments) { return false; } + if (keepOldComments != other.keepOldComments) { + return false; + } if (minSeverity != other.minSeverity) { return false; } @@ -259,6 +266,7 @@ public int hashCode() { result = prime * result + commentOnlyChangedContentContext; result = prime * result + (createCommentWithAllSingleFileComments ? 1231 : 1237); result = prime * result + (createSingleFileComments ? 1231 : 1237); + result = prime * result + (keepOldComments ? 1231 : 1237); result = prime * result + (minSeverity == null ? 0 : minSeverity.hashCode()); result = prime * result + (password == null ? 0 : password.hashCode()); result = prime * result + (projectKey == null ? 0 : projectKey.hashCode()); @@ -277,10 +285,10 @@ public int hashCode() { } private List includeAllReporters(List violationConfigs) { - List allViolationConfigs = + final List allViolationConfigs = ViolationsToBitbucketServerConfigHelper.getAllViolationConfigs(); - for (ViolationConfig candidate : allViolationConfigs) { - for (ViolationConfig input : violationConfigs) { + for (final ViolationConfig candidate : allViolationConfigs) { + for (final ViolationConfig input : violationConfigs) { if (candidate.getParser() == input.getParser()) { candidate.setPattern(input.getPattern()); candidate.setReporter(input.getReporter()); @@ -395,6 +403,16 @@ public String toString() { + commentOnlyChangedContentContext + ", minSeverity=" + minSeverity + + ", keepOldComments=" + + keepOldComments + "]"; } + + public boolean isKeepOldComments() { + return keepOldComments; + } + + public void setKeepOldComments(boolean keepOldComments) { + this.keepOldComments = keepOldComments; + } } diff --git a/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfigHelper.java b/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfigHelper.java index dc948f7..f6adbca 100644 --- a/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfigHelper.java +++ b/src/main/java/org/jenkinsci/plugins/jvctb/config/ViolationsToBitbucketServerConfigHelper.java @@ -26,18 +26,19 @@ public class ViolationsToBitbucketServerConfigHelper { public static final String FIELD_USEUSERNAMEPASSWORDCREDENTIALS = "useUsernamePasswordCredentials"; public static final String FIELD_MINSEVERITY = "minSeverity"; + public static final String FIELD_KEEP_OLD_COMMENTS = "keepOldComments"; public static ViolationsToBitbucketServerConfig createNewConfig() { - ViolationsToBitbucketServerConfig config = new ViolationsToBitbucketServerConfig(); - List violationConfigs = getAllViolationConfigs(); + final ViolationsToBitbucketServerConfig config = new ViolationsToBitbucketServerConfig(); + final List violationConfigs = getAllViolationConfigs(); config.setViolationConfigs(violationConfigs); return config; } public static List getAllViolationConfigs() { - List violationConfigs = newArrayList(); - for (Parser parser : Parser.values()) { - ViolationConfig violationConfig = new ViolationConfig(); + final List violationConfigs = newArrayList(); + for (final Parser parser : Parser.values()) { + final ViolationConfig violationConfig = new ViolationConfig(); violationConfig.setParser(parser); violationConfigs.add(violationConfig); } diff --git a/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java b/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java index e3d39e0..cdd8884 100644 --- a/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java +++ b/src/main/java/org/jenkinsci/plugins/jvctb/perform/JvctbPerformer.java @@ -13,6 +13,7 @@ import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_COMMENTONLYCHANGEDCONTENTCONTEXT; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATECOMMENTWITHALLSINGLEFILECOMMENTS; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_CREATESINGLEFILECOMMENTS; +import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_KEEP_OLD_COMMENTS; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_MINSEVERITY; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PASSWORD; import static org.jenkinsci.plugins.jvctb.config.ViolationsToBitbucketServerConfigHelper.FIELD_PROJECTKEY; @@ -101,7 +102,7 @@ public static void doPerform( listener .getLogger() .println( - "Will comment PR " + "PR: " + config.getProjectKey() + "/" + config.getRepoSlug() @@ -124,6 +125,7 @@ public static void doPerform( .withCreateSingleFileComments(config.getCreateSingleFileComments()) // .withCommentOnlyChangedContent(config.getCommentOnlyChangedContent()) // .withCommentOnlyChangedContentContext(config.getCommentOnlyChangedContentContext()) // + .withShouldKeepOldComments(config.isKeepOldComments()) // .toPullRequest(); } catch (final Exception e) { Logger.getLogger(JvctbPerformer.class.getName()).log(SEVERE, "", e); @@ -153,6 +155,7 @@ static ViolationsToBitbucketServerConfig expand( expanded.setCommentOnlyChangedContent(config.getCommentOnlyChangedContent()); expanded.setCommentOnlyChangedContentContext(config.getCommentOnlyChangedContentContext()); expanded.setMinSeverity(config.getMinSeverity()); + expanded.setKeepOldComments(config.isKeepOldComments()); for (final ViolationConfig violationConfig : config.getViolationConfigs()) { final String pattern = environment.expand(violationConfig.getPattern()); @@ -186,7 +189,7 @@ public static void jvctsPerform( setCredentialsIfExists(listener, configExpanded); - listener.getLogger().println("Will comment " + configExpanded.getPullRequestId()); + listener.getLogger().println("Pull request: " + configExpanded.getPullRequestId()); fp.act( new FileCallable() { @@ -242,6 +245,7 @@ private static void logConfiguration( + ": " + config.getCommentOnlyChangedContentContext()); logger.println(FIELD_MINSEVERITY + ": " + config.getMinSeverity()); + logger.println(FIELD_KEEP_OLD_COMMENTS + ": " + config.isKeepOldComments()); for (final ViolationConfig violationConfig : config.getViolationConfigs()) { logger.println( diff --git a/src/main/resources/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerRecorder/config.jelly b/src/main/resources/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerRecorder/config.jelly index b8a51d9..615b519 100644 --- a/src/main/resources/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerRecorder/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/jvctb/ViolationsToBitbucketServerRecorder/config.jelly @@ -79,6 +79,10 @@ + + + +