1010import se .bjurr .violations .lib .model .Violation ;
1111
1212public class ViolationCommentsToBitbucketServerApi {
13+ private static final Integer BITBUCKET_MAX_COMMENT_SIZE = 32767 ;
1314 public static final String DEFAULT_PROP_VIOLATIONS_PASSWORD = "VIOLATIONS_PASSWORD" ;
1415 public static final String DEFAULT_PROP_VIOLATIONS_USERNAME = "VIOLATIONS_USERNAME" ;
1516
@@ -33,51 +34,73 @@ private ViolationCommentsToBitbucketServerApi() {
3334
3435 }
3536
37+ private void checkState () {
38+ if (username == null || password == null ) {
39+ throw new IllegalStateException (
40+ "User and Password must be set! They can be set with the API or by setting properties.\n " + //
41+ "Username/password:\n " + //
42+ "-D" + DEFAULT_PROP_VIOLATIONS_USERNAME + "=theuser -D" + DEFAULT_PROP_VIOLATIONS_PASSWORD + "=thepassword" );
43+ }
44+ checkNotNull (bitbucketServerUrl , "BitbucketServerURL" );
45+ checkNotNull (pullRequestId , "PullRequestId" );
46+ checkNotNull (repoSlug , "repoSlug" );
47+ checkNotNull (projectKey , "projectKey" );
48+ }
49+
3650 public String getBitbucketServerUrl () {
37- return this . bitbucketServerUrl ;
51+ return bitbucketServerUrl ;
3852 }
3953
4054 public boolean getCreateCommentWithAllSingleFileComments () {
41- return this . createCommentWithAllSingleFileComments ;
55+ return createCommentWithAllSingleFileComments ;
4256 }
4357
4458 public boolean getCreateSingleFileComments () {
45- return this . createSingleFileComments ;
59+ return createSingleFileComments ;
4660 }
4761
4862 public String getPassword () {
49- return this . password ;
63+ return password ;
5064 }
5165
5266 public String getProjectKey () {
53- return this . projectKey ;
67+ return projectKey ;
5468 }
5569
5670 public String getPropPassword () {
57- return this . propPassword ;
71+ return propPassword ;
5872 }
5973
6074 public String getPropUsername () {
61- return this . propUsername ;
75+ return propUsername ;
6276 }
6377
6478 public int getPullRequestId () {
65- return this . pullRequestId ;
79+ return pullRequestId ;
6680 }
6781
6882 public String getRepoSlug () {
69- return this . repoSlug ;
83+ return repoSlug ;
7084 }
7185
7286 public String getUsername () {
73- return this .username ;
87+ return username ;
88+ }
89+
90+ private void populateFromEnvironmentVariables () {
91+ if (System .getProperty (propUsername ) != null ) {
92+ username = firstNonNull (username , System .getProperty (propUsername ));
93+ }
94+ if (System .getProperty (propPassword ) != null ) {
95+ password = firstNonNull (password , System .getProperty (propPassword ));
96+ }
7497 }
7598
7699 public void toPullRequest () throws Exception {
77100 populateFromEnvironmentVariables ();
78101 checkState ();
79102 CommentsProvider commentsProvider = new BitbucketServerCommentsProvider (this );
80- createComments (commentsProvider , this . violations );
103+ createComments (commentsProvider , violations , BITBUCKET_MAX_COMMENT_SIZE );
81104 }
82105
83106 public ViolationCommentsToBitbucketServerApi withBitbucketServerUrl (String bitbucketServerUrl ) {
@@ -107,11 +130,11 @@ public ViolationCommentsToBitbucketServerApi withProjectKey(String projectKey) {
107130 }
108131
109132 public void withPropPassword (String envPassword ) {
110- this . propPassword = envPassword ;
133+ propPassword = envPassword ;
111134 }
112135
113136 public void withPropUsername (String envUsername ) {
114- this . propUsername = envUsername ;
137+ propUsername = envUsername ;
115138 }
116139
117140 public ViolationCommentsToBitbucketServerApi withPullRequestId (int pullRequestId ) {
@@ -133,26 +156,4 @@ public ViolationCommentsToBitbucketServerApi withViolations(List<Violation> viol
133156 this .violations = violations ;
134157 return this ;
135158 }
136-
137- private void checkState () {
138- if (this .username == null || this .password == null ) {
139- throw new IllegalStateException (
140- "User and Password must be set! They can be set with the API or by setting properties.\n " + //
141- "Username/password:\n " + //
142- "-D" + DEFAULT_PROP_VIOLATIONS_USERNAME + "=theuser -D" + DEFAULT_PROP_VIOLATIONS_PASSWORD + "=thepassword" );
143- }
144- checkNotNull (this .bitbucketServerUrl , "BitbucketServerURL" );
145- checkNotNull (this .pullRequestId , "PullRequestId" );
146- checkNotNull (this .repoSlug , "repoSlug" );
147- checkNotNull (this .projectKey , "projectKey" );
148- }
149-
150- private void populateFromEnvironmentVariables () {
151- if (System .getProperty (this .propUsername ) != null ) {
152- this .username = firstNonNull (this .username , System .getProperty (this .propUsername ));
153- }
154- if (System .getProperty (this .propPassword ) != null ) {
155- this .password = firstNonNull (this .password , System .getProperty (this .propPassword ));
156- }
157- }
158159}
0 commit comments