Skip to content

Commit ff4e274

Browse files
committed
Google Java Format
1 parent 43f7f0f commit ff4e274

File tree

16 files changed

+1023
-941
lines changed

16 files changed

+1023
-941
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# Changelog
3-
## Unreleased
3+
## 1.30
44
### No issue
55

66
**Keeping comments and adjusting checkstyle**
@@ -9,7 +9,7 @@
99
* Comments can optionaly be kept and not removed when new comments are added.
1010
* Will no longer re-create identical comments.
1111

12-
[75375780b599622](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/75375780b599622) Tomas Bjerre *2017-09-02 09:18:53*
12+
[4e2cc9662e53323](https://github.com/tomasbjerre/violation-comments-to-bitbucket-server-lib/commit/4e2cc9662e53323) Tomas Bjerre *2017-09-02 09:19:51*
1313

1414

1515
## 1.29

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
1010
classpath 'net.researchgate:gradle-release:2.2.2'
1111
classpath "gradle.plugin.se.bjurr.gitchangelog:git-changelog-gradle-plugin:1.36"
12+
classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6'
1213
}
1314
}
1415

@@ -19,6 +20,7 @@ apply plugin: 'signing'
1920
apply plugin: 'com.bmuschko.nexus'
2021
apply plugin: 'net.researchgate.release'
2122
apply plugin: "se.bjurr.gitchangelog.git-changelog-gradle-plugin"
23+
apply plugin: 'com.github.sherter.google-java-format'
2224

2325
task gitChangelogTask(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
2426
filePath = "CHANGELOG.md";
@@ -134,6 +136,8 @@ extraArchive {
134136
javadoc = true
135137
}
136138

139+
compileJava.dependsOn 'googleJavaFormat'
140+
137141
afterReleaseBuild.dependsOn {
138142
[install, uploadArchives]
139143
}

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/BitbucketServerCommentsProvider.java

Lines changed: 138 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import static java.util.concurrent.TimeUnit.SECONDS;
77
import static se.bjurr.violations.comments.bitbucketserver.lib.client.model.DIFFTYPE.ADDED;
88

9+
import com.google.common.annotations.VisibleForTesting;
10+
import com.google.common.base.Supplier;
911
import java.util.ArrayList;
1012
import java.util.List;
11-
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
14-
1515
import se.bjurr.violations.comments.bitbucketserver.lib.client.BitbucketServerClient;
1616
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerComment;
1717
import se.bjurr.violations.comments.bitbucketserver.lib.client.model.BitbucketServerDiff;
@@ -26,150 +26,160 @@
2626
import se.bjurr.violations.lib.model.Violation;
2727
import se.bjurr.violations.lib.util.Optional;
2828

29-
import com.google.common.annotations.VisibleForTesting;
30-
import com.google.common.base.Supplier;
31-
3229
public class BitbucketServerCommentsProvider implements CommentsProvider {
3330

34-
private static final Logger LOG = LoggerFactory.getLogger(BitbucketServerCommentsProvider.class);
31+
private static final Logger LOG = LoggerFactory.getLogger(BitbucketServerCommentsProvider.class);
32+
33+
private final BitbucketServerClient client;
34+
35+
private final Supplier<BitbucketServerDiffResponse> diffResponse =
36+
memoizeWithExpiration(
37+
new Supplier<BitbucketServerDiffResponse>() {
38+
@Override
39+
public BitbucketServerDiffResponse get() {
40+
return client.pullRequestDiff();
41+
}
42+
},
43+
10,
44+
SECONDS);
3545

36-
private final BitbucketServerClient client;
46+
private final ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi;
47+
48+
@VisibleForTesting
49+
BitbucketServerCommentsProvider() {
50+
client = null;
51+
violationCommentsToBitbucketApi = null;
52+
}
53+
54+
public BitbucketServerCommentsProvider(
55+
ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi) {
56+
final String bitbucketServerBaseUrl = violationCommentsToBitbucketApi.getBitbucketServerUrl();
57+
final String bitbucketServerProject = violationCommentsToBitbucketApi.getProjectKey();
58+
final String bitbucketServerRepo = violationCommentsToBitbucketApi.getRepoSlug();
59+
final Integer bitbucketServerPullRequestId = violationCommentsToBitbucketApi.getPullRequestId();
60+
final String bitbucketServerUser = violationCommentsToBitbucketApi.getUsername();
61+
final String bitbucketServerPassword = violationCommentsToBitbucketApi.getPassword();
62+
client =
63+
new BitbucketServerClient(
64+
bitbucketServerBaseUrl,
65+
bitbucketServerProject,
66+
bitbucketServerRepo,
67+
bitbucketServerPullRequestId,
68+
bitbucketServerUser,
69+
bitbucketServerPassword);
70+
this.violationCommentsToBitbucketApi = violationCommentsToBitbucketApi;
71+
}
72+
73+
@Override
74+
public void createCommentWithAllSingleFileComments(String comment) {
75+
client.pullRequestComment(comment);
76+
}
77+
78+
@Override
79+
public void createSingleFileComment(ChangedFile file, Integer line, String comment) {
80+
client.pullRequestComment(file.getFilename(), line, comment);
81+
}
3782

38-
private final Supplier<BitbucketServerDiffResponse> diffResponse = memoizeWithExpiration(
39-
new Supplier<BitbucketServerDiffResponse>() {
40-
@Override
41-
public BitbucketServerDiffResponse get() {
42-
return client.pullRequestDiff();
83+
@Override
84+
public List<Comment> getComments() {
85+
final List<Comment> comments = newArrayList();
86+
for (final String changedFile : client.pullRequestChanges()) {
87+
final List<BitbucketServerComment> bitbucketServerCommentsOnFile =
88+
client.pullRequestComments(changedFile);
89+
for (final BitbucketServerComment fileComment : bitbucketServerCommentsOnFile) {
90+
final List<String> specifics = newArrayList(fileComment.getVersion() + "", changedFile);
91+
comments.add(new Comment(fileComment.getId() + "", fileComment.getText(), null, specifics));
92+
}
4393
}
44-
}, 10, SECONDS);
45-
46-
private final ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi;
47-
48-
@VisibleForTesting
49-
BitbucketServerCommentsProvider() {
50-
client = null;
51-
violationCommentsToBitbucketApi = null;
52-
}
53-
54-
public BitbucketServerCommentsProvider(ViolationCommentsToBitbucketServerApi violationCommentsToBitbucketApi) {
55-
final String bitbucketServerBaseUrl = violationCommentsToBitbucketApi.getBitbucketServerUrl();
56-
final String bitbucketServerProject = violationCommentsToBitbucketApi.getProjectKey();
57-
final String bitbucketServerRepo = violationCommentsToBitbucketApi.getRepoSlug();
58-
final Integer bitbucketServerPullRequestId = violationCommentsToBitbucketApi.getPullRequestId();
59-
final String bitbucketServerUser = violationCommentsToBitbucketApi.getUsername();
60-
final String bitbucketServerPassword = violationCommentsToBitbucketApi.getPassword();
61-
client = new BitbucketServerClient(bitbucketServerBaseUrl, bitbucketServerProject, bitbucketServerRepo,
62-
bitbucketServerPullRequestId, bitbucketServerUser, bitbucketServerPassword);
63-
this.violationCommentsToBitbucketApi = violationCommentsToBitbucketApi;
64-
}
65-
66-
@Override
67-
public void createCommentWithAllSingleFileComments(String comment) {
68-
client.pullRequestComment(comment);
69-
}
70-
71-
@Override
72-
public void createSingleFileComment(ChangedFile file, Integer line, String comment) {
73-
client.pullRequestComment(file.getFilename(), line, comment);
74-
}
75-
76-
@Override
77-
public List<Comment> getComments() {
78-
final List<Comment> comments = newArrayList();
79-
for (final String changedFile : client.pullRequestChanges()) {
80-
final List<BitbucketServerComment> bitbucketServerCommentsOnFile = client.pullRequestComments(changedFile);
81-
for (final BitbucketServerComment fileComment : bitbucketServerCommentsOnFile) {
82-
final List<String> specifics = newArrayList(fileComment.getVersion() + "", changedFile);
83-
comments.add(new Comment(fileComment.getId() + "", fileComment.getText(), null, specifics));
84-
}
94+
95+
return comments;
8596
}
8697

87-
return comments;
88-
}
98+
@Override
99+
public List<ChangedFile> getFiles() {
100+
final List<ChangedFile> changedFiles = newArrayList();
89101

90-
@Override
91-
public List<ChangedFile> getFiles() {
92-
final List<ChangedFile> changedFiles = newArrayList();
102+
final List<String> bitbucketServerChangedFiles = client.pullRequestChanges();
93103

94-
final List<String> bitbucketServerChangedFiles = client.pullRequestChanges();
104+
for (final String changedFile : bitbucketServerChangedFiles) {
105+
changedFiles.add(new ChangedFile(changedFile, new ArrayList<String>()));
106+
}
95107

96-
for (final String changedFile : bitbucketServerChangedFiles) {
97-
changedFiles.add(new ChangedFile(changedFile, new ArrayList<String>()));
108+
return changedFiles;
98109
}
99110

100-
return changedFiles;
101-
}
102-
103-
@Override
104-
public void removeComments(List<Comment> comments) {
105-
for (final Comment comment : comments) {
106-
Integer commentId = null;
107-
Integer commentVersion = null;
108-
try {
109-
commentId = Integer.valueOf(comment.getIdentifier());
110-
commentVersion = Integer.valueOf(comment.getSpecifics().get(0));
111-
client.pullRequestRemoveComment(commentId, commentVersion);
112-
} catch (final Exception e) {
113-
LOG.warn("Was unable to remove comment " + commentId + " " + commentVersion, e);
114-
}
111+
@Override
112+
public void removeComments(List<Comment> comments) {
113+
for (final Comment comment : comments) {
114+
Integer commentId = null;
115+
Integer commentVersion = null;
116+
try {
117+
commentId = Integer.valueOf(comment.getIdentifier());
118+
commentVersion = Integer.valueOf(comment.getSpecifics().get(0));
119+
client.pullRequestRemoveComment(commentId, commentVersion);
120+
} catch (final Exception e) {
121+
LOG.warn("Was unable to remove comment " + commentId + " " + commentVersion, e);
122+
}
123+
}
115124
}
116-
}
117125

118-
@Override
119-
public boolean shouldComment(ChangedFile changedFile, Integer changedLine) {
120-
if (!violationCommentsToBitbucketApi.getCommentOnlyChangedContent()) {
121-
return true;
126+
@Override
127+
public boolean shouldComment(ChangedFile changedFile, Integer changedLine) {
128+
if (!violationCommentsToBitbucketApi.getCommentOnlyChangedContent()) {
129+
return true;
130+
}
131+
final int context = violationCommentsToBitbucketApi.getCommentOnlyChangedContentContext();
132+
final List<BitbucketServerDiff> diffs = diffResponse.get().getDiffs();
133+
return shouldComment(changedFile, changedLine, context, diffs);
122134
}
123-
final int context = violationCommentsToBitbucketApi.getCommentOnlyChangedContentContext();
124-
final List<BitbucketServerDiff> diffs = diffResponse.get().getDiffs();
125-
return shouldComment(changedFile, changedLine, context, diffs);
126-
}
127-
128-
@VisibleForTesting
129-
boolean shouldComment(ChangedFile changedFile, Integer changedLine, int context, List<BitbucketServerDiff> diffs) {
130-
for (final BitbucketServerDiff diff : diffs) {
131-
final DiffDestination destination = diff.getDestination();
132-
if (destination != null) {
133-
final String destinationToString = destination.getToString();
134-
if (!isNullOrEmpty(destinationToString)) {
135-
if (destinationToString.equals(changedFile.getFilename())) {
136-
if (diff.getHunks() != null) {
137-
for (final DiffHunk hunk : diff.getHunks()) {
138-
for (final Segment segment : hunk.getSegments()) {
139-
if (segment.getType() == ADDED) {
140-
for (final Line line : segment.getLines()) {
141-
if (line.getDestination() >= changedLine - context && line.getDestination() <= changedLine + context) {
142-
return true;
143-
}
135+
136+
@VisibleForTesting
137+
boolean shouldComment(
138+
ChangedFile changedFile, Integer changedLine, int context, List<BitbucketServerDiff> diffs) {
139+
for (final BitbucketServerDiff diff : diffs) {
140+
final DiffDestination destination = diff.getDestination();
141+
if (destination != null) {
142+
final String destinationToString = destination.getToString();
143+
if (!isNullOrEmpty(destinationToString)) {
144+
if (destinationToString.equals(changedFile.getFilename())) {
145+
if (diff.getHunks() != null) {
146+
for (final DiffHunk hunk : diff.getHunks()) {
147+
for (final Segment segment : hunk.getSegments()) {
148+
if (segment.getType() == ADDED) {
149+
for (final Line line : segment.getLines()) {
150+
if (line.getDestination() >= changedLine - context
151+
&& line.getDestination() <= changedLine + context) {
152+
return true;
153+
}
154+
}
155+
}
156+
}
157+
}
158+
}
144159
}
145-
}
146160
}
147-
}
148161
}
149-
}
150162
}
151-
}
163+
return false;
164+
}
165+
166+
@Override
167+
public boolean shouldCreateCommentWithAllSingleFileComments() {
168+
return violationCommentsToBitbucketApi.getCreateCommentWithAllSingleFileComments();
169+
}
170+
171+
@Override
172+
public boolean shouldCreateSingleFileComment() {
173+
return violationCommentsToBitbucketApi.getCreateSingleFileComments();
174+
}
175+
176+
@Override
177+
public Optional<String> findCommentFormat(ChangedFile changedFile, Violation violation) {
178+
return Optional.absent();
179+
}
180+
181+
@Override
182+
public boolean shouldKeepOldComments() {
183+
return violationCommentsToBitbucketApi.getShouldKeepOldComments();
152184
}
153-
return false;
154-
}
155-
156-
@Override
157-
public boolean shouldCreateCommentWithAllSingleFileComments() {
158-
return violationCommentsToBitbucketApi.getCreateCommentWithAllSingleFileComments();
159-
}
160-
161-
@Override
162-
public boolean shouldCreateSingleFileComment() {
163-
return violationCommentsToBitbucketApi.getCreateSingleFileComments();
164-
}
165-
166-
@Override
167-
public Optional<String> findCommentFormat(ChangedFile changedFile, Violation violation) {
168-
return Optional.absent();
169-
}
170-
171-
@Override
172-
public boolean shouldKeepOldComments() {
173-
return violationCommentsToBitbucketApi.getShouldKeepOldComments();
174-
}
175185
}

0 commit comments

Comments
 (0)