Skip to content

Commit

Permalink
Keeping comments and adjusting checkstyle #37
Browse files Browse the repository at this point in the history
 * 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.
  • Loading branch information
tomasbjerre committed Sep 2, 2017
1 parent 88325dc commit 61d8abc
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 27 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand All @@ -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' ],
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<properties>
<jenkins.version>2.1</jenkins.version>
<jenkins.version>2.7.4</jenkins.version>
<hpi-plugin.version>1.115</hpi-plugin.version>
<jenkins-test-harness.version>2.19</jenkins-test-harness.version>
<findbugs.failOnError>false</findbugs.failOnError>
Expand Down Expand Up @@ -202,7 +202,7 @@ Changelog of Violation Comments to Bitbucket Server Plugin.
<dependency>
<groupId>se.bjurr.violations</groupId>
<artifactId>violation-comments-to-bitbucket-server-lib</artifactId>
<version>1.29</version>
<version>1.31</version>
</dependency>

<!-- test // -->
Expand Down
41 changes: 41 additions & 0 deletions sandbox/violations-test.jenkinsfile
Original file line number Diff line number Diff line change
@@ -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' ],
]
]
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -100,24 +101,25 @@ 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 {
config.setMinSeverity(null);
}

int i = 0;
List<String> patterns = (List<String>) formData.get(FIELD_PATTERN);
List<String> reporters = (List<String>) formData.get(FIELD_REPORTER);
for (String pattern : patterns) {
ViolationConfig violationConfig = config.getViolationConfigs().get(i);
final List<String> patterns = (List<String>) formData.get(FIELD_PATTERN);
final List<String> reporters = (List<String>) 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ViolationsToBitbucketServerConfig implements Serializable {
private List<ViolationConfig> violationConfigs = newArrayList();
private int commentOnlyChangedContentContext;
private SEVERITY minSeverity;
private boolean keepOldComments;

public ViolationsToBitbucketServerConfig() {}

Expand All @@ -47,9 +48,10 @@ public ViolationsToBitbucketServerConfig(
boolean useUsernamePassword,
boolean commentOnlyChangedContent,
int commentOnlyChangedContentContext,
SEVERITY minSeverity) {
SEVERITY minSeverity,
boolean keepOldComments) {

List<ViolationConfig> allViolationConfigs = includeAllReporters(violationConfigs);
final List<ViolationConfig> allViolationConfigs = includeAllReporters(violationConfigs);

this.violationConfigs = allViolationConfigs;
this.createSingleFileComments = createSingleFileComments;
Expand All @@ -66,6 +68,7 @@ public ViolationsToBitbucketServerConfig(
this.commentOnlyChangedContent = commentOnlyChangedContent;
this.commentOnlyChangedContentContext = commentOnlyChangedContentContext;
this.minSeverity = minSeverity;
this.keepOldComments = keepOldComments;
}

public ViolationsToBitbucketServerConfig(ViolationsToBitbucketServerConfig rhs) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
Expand All @@ -277,10 +285,10 @@ public int hashCode() {
}

private List<ViolationConfig> includeAllReporters(List<ViolationConfig> violationConfigs) {
List<ViolationConfig> allViolationConfigs =
final List<ViolationConfig> 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());
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViolationConfig> violationConfigs = getAllViolationConfigs();
final ViolationsToBitbucketServerConfig config = new ViolationsToBitbucketServerConfig();
final List<ViolationConfig> violationConfigs = getAllViolationConfigs();
config.setViolationConfigs(violationConfigs);
return config;
}

public static List<ViolationConfig> getAllViolationConfigs() {
List<ViolationConfig> violationConfigs = newArrayList();
for (Parser parser : Parser.values()) {
ViolationConfig violationConfig = new ViolationConfig();
final List<ViolationConfig> violationConfigs = newArrayList();
for (final Parser parser : Parser.values()) {
final ViolationConfig violationConfig = new ViolationConfig();
violationConfig.setParser(parser);
violationConfigs.add(violationConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static void doPerform(
listener
.getLogger()
.println(
"Will comment PR "
"PR: "
+ config.getProjectKey()
+ "/"
+ config.getRepoSlug()
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<Void>() {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
</select>
</f:entry>

<f:entry title="Keep old comments">
<f:checkbox name="keepOldComments" checked="${config.keepOldComments}"/>
</f:entry>

<f:entry title="Create one comment per violation">
<f:checkbox name="createSingleFileComments" checked="${config.createSingleFileComments}"/>
</f:entry>
Expand Down

0 comments on commit 61d8abc

Please sign in to comment.