Skip to content

Commit 9d8460b

Browse files
committed
Enable automatic code formatter with CI validation
This may be controversial but it we're doing it. Having code formatting needs to be consistent and a non-issue during code review. I'm willing modify the configuration if people see a strong need, but formatting needs to be present and enforced.
1 parent 8943af9 commit 9d8460b

169 files changed

Lines changed: 3716 additions & 4045 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/maven-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- name: Maven Download all dependencies
2020
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
2121
- name: Maven Build
22-
run: mvn -B install site --file pom.xml
22+
run: mvn -B install site -P ci --file pom.xml

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<hamcrest.version>2.2</hamcrest.version>
3636
<okhttp3.version>4.2.2</okhttp3.version>
3737
<okio.version>2.4.1</okio.version>
38+
<formatter-maven-plugin.goal>format</formatter-maven-plugin.goal>
3839
<jacoco.coverage.target.class>.80</jacoco.coverage.target.class>
3940
<jacoco.coverage.target.method>0.20</jacoco.coverage.target.method>
4041
<jacoco.coverage.target.line>0.50</jacoco.coverage.target.line>
@@ -164,6 +165,18 @@
164165
</execution>
165166
</executions>
166167
</plugin>
168+
<plugin>
169+
<groupId>net.revelc.code.formatter</groupId>
170+
<artifactId>formatter-maven-plugin</artifactId>
171+
<version>2.11.0</version>
172+
<executions>
173+
<execution>
174+
<goals>
175+
<goal>${formatter-maven-plugin.goal}</goal>
176+
</goals>
177+
</execution>
178+
</executions>
179+
</plugin>
167180
<plugin>
168181
<groupId>com.github.spotbugs</groupId>
169182
<artifactId>spotbugs-maven-plugin</artifactId>
@@ -338,6 +351,14 @@
338351
</pluginRepository>
339352
</pluginRepositories>
340353
<profiles>
354+
<profile>
355+
<id>ci</id>
356+
<properties>
357+
<formatter-maven-plugin.goal>validate</formatter-maven-plugin.goal>
358+
</properties>
359+
<build>
360+
</build>
361+
</profile>
341362
<profile>
342363
<id>jacoco</id>
343364
<activation>

src/main/java/org/kohsuke/github/AbuseLimitHandler.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public abstract class AbuseLimitHandler {
1717
* Called when the library encounters HTTP error indicating that the API abuse limit is reached.
1818
*
1919
* <p>
20-
* Any exception thrown from this method will cause the request to fail, and the caller of github-api
21-
* will receive an exception. If this method returns normally, another request will be attempted.
22-
* For that to make sense, the implementation needs to wait for some time.
20+
* Any exception thrown from this method will cause the request to fail, and the caller of github-api will receive
21+
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the
22+
* implementation needs to wait for some time.
2323
*
2424
* @see <a href="https://developer.github.com/v3/#abuse-rate-limits">API documentation from GitHub</a>
2525
* @param e
26-
* Exception from Java I/O layer. If you decide to fail the processing, you can throw
27-
* this exception (or wrap this exception into another exception and throw it).
26+
* Exception from Java I/O layer. If you decide to fail the processing, you can throw this exception (or
27+
* wrap this exception into another exception and throw it).
2828
* @param uc
29-
* Connection that resulted in an error. Useful for accessing other response headers.
29+
* Connection that resulted in an error. Useful for accessing other response headers.
3030
* @throws IOException
3131
*/
3232
public abstract void onError(IOException e, HttpURLConnection uc) throws IOException;
@@ -40,15 +40,16 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException {
4040
try {
4141
Thread.sleep(parseWaitTime(uc));
4242
} catch (InterruptedException ex) {
43-
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
43+
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
4444
}
4545
}
4646

4747
private long parseWaitTime(HttpURLConnection uc) {
4848
String v = uc.getHeaderField("Retry-After");
49-
if (v==null) return 60 * 1000; // can't tell, return 1 min
49+
if (v == null)
50+
return 60 * 1000; // can't tell, return 1 min
5051

51-
return Math.max(1000, Long.parseLong(v)*1000);
52+
return Math.max(1000, Long.parseLong(v) * 1000);
5253
}
5354
};
5455

@@ -58,7 +59,7 @@ private long parseWaitTime(HttpURLConnection uc) {
5859
public static final AbuseLimitHandler FAIL = new AbuseLimitHandler() {
5960
@Override
6061
public void onError(IOException e, HttpURLConnection uc) throws IOException {
61-
throw (IOException)new IOException("Abuse limit reached").initCause(e);
62+
throw (IOException) new IOException("Abuse limit reached").initCause(e);
6263
}
6364
};
6465
}

src/main/java/org/kohsuke/github/DeleteToken.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/**
2929
* @author Kohsuke Kawaguchi
3030
*/
31-
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD",
32-
justification = "Being constructed by JSON deserialization")
31+
@SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", justification = "Being constructed by JSON deserialization")
3332
class DeleteToken {
3433
public String delete_token;
3534
}

src/main/java/org/kohsuke/github/GHApp.java

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ public class GHApp extends GHObject {
2525
private String description;
2626
@JsonProperty("external_url")
2727
private String externalUrl;
28-
private Map<String,String> permissions;
28+
private Map<String, String> permissions;
2929
private List<GHEvent> events;
3030
@JsonProperty("installations_count")
3131
private long installationsCount;
3232
@JsonProperty("html_url")
3333
private String htmlUrl;
3434

35-
3635
public GHUser getOwner() {
3736
return owner;
3837
}
@@ -93,7 +92,7 @@ public void setPermissions(Map<String, String> permissions) {
9392
this.permissions = permissions;
9493
}
9594

96-
/*package*/ GHApp wrapUp(GitHub root) {
95+
/* package */ GHApp wrapUp(GitHub root) {
9796
this.root = root;
9897
return this;
9998
}
@@ -106,67 +105,84 @@ public void setPermissions(Map<String, String> permissions) {
106105
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
107106
* @return a list of App installations
108107
*/
109-
@Preview @Deprecated
108+
@Preview
109+
@Deprecated
110110
public PagedIterable<GHAppInstallation> listInstallations() {
111-
return root.retrieve().withPreview(MACHINE_MAN)
112-
.asPagedIterable(
113-
"/app/installations",
114-
GHAppInstallation[].class,
115-
item -> item.wrapUp(root) );
111+
return root.retrieve().withPreview(MACHINE_MAN).asPagedIterable("/app/installations", GHAppInstallation[].class,
112+
item -> item.wrapUp(root));
116113
}
117114

118115
/**
119116
* Obtain an installation associated with this app
120-
* @param id - Installation Id
117+
*
118+
* @param id
119+
* Installation Id
121120
*
122-
* You must use a JWT to access this endpoint.
121+
* You must use a JWT to access this endpoint.
123122
*
124123
* @see <a href="https://developer.github.com/v3/apps/#get-an-installation">Get an installation</a>
125124
*/
126-
@Preview @Deprecated
125+
@Preview
126+
@Deprecated
127127
public GHAppInstallation getInstallationById(long id) throws IOException {
128-
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root);
128+
return root.retrieve().withPreview(MACHINE_MAN)
129+
.to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root);
129130
}
130131

131132
/**
132133
* Obtain an organization installation associated with this app
133-
* @param name - Organization name
134+
*
135+
* @param name
136+
* Organization name
134137
*
135-
* You must use a JWT to access this endpoint.
138+
* You must use a JWT to access this endpoint.
136139
*
137-
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization installation</a>
140+
* @see <a href="https://developer.github.com/v3/apps/#get-an-organization-installation">Get an organization
141+
* installation</a>
138142
*/
139-
@Preview @Deprecated
143+
@Preview
144+
@Deprecated
140145
public GHAppInstallation getInstallationByOrganization(String name) throws IOException {
141-
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root);
146+
return root.retrieve().withPreview(MACHINE_MAN)
147+
.to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root);
142148
}
143149

144150
/**
145151
* Obtain an repository installation associated with this app
146-
* @param ownerName - Organization or user name
147-
* @param repositoryName - Repository name
152+
*
153+
* @param ownerName
154+
* Organization or user name
155+
* @param repositoryName
156+
* Repository name
148157
*
149-
* You must use a JWT to access this endpoint.
158+
* You must use a JWT to access this endpoint.
150159
*
151-
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository installation</a>
160+
* @see <a href="https://developer.github.com/v3/apps/#get-a-repository-installation">Get a repository
161+
* installation</a>
152162
*/
153-
@Preview @Deprecated
163+
@Preview
164+
@Deprecated
154165
public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException {
155-
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class).wrapUp(root);
166+
return root.retrieve().withPreview(MACHINE_MAN)
167+
.to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class)
168+
.wrapUp(root);
156169
}
157170

158171
/**
159172
* Obtain a user installation associated with this app
160-
* @param name - user name
173+
*
174+
* @param name
175+
* user name
161176
*
162-
* You must use a JWT to access this endpoint.
177+
* You must use a JWT to access this endpoint.
163178
*
164179
* @see <a href="https://developer.github.com/v3/apps/#get-a-user-installation">Get a user installation</a>
165180
*/
166-
@Preview @Deprecated
181+
@Preview
182+
@Deprecated
167183
public GHAppInstallation getInstallationByUser(String name) throws IOException {
168-
return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root);
184+
return root.retrieve().withPreview(MACHINE_MAN)
185+
.to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root);
169186
}
170187

171188
}
172-

src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ public class GHAppCreateTokenBuilder {
1818
protected final Requester builder;
1919
private final String apiUrlTail;
2020

21-
@Preview @Deprecated
22-
/*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
21+
@Preview
22+
@Deprecated
23+
/* package */ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
2324
this.root = root;
2425
this.apiUrlTail = apiUrlTail;
2526
this.builder = new Requester(root);
26-
this.builder.withPermissions("permissions",permissions);
27+
this.builder.withPermissions("permissions", permissions);
2728
}
2829

2930
/**
3031
* By default the installation token has access to all repositories that the installation can access. To restrict
3132
* the access to specific repositories, you can provide the repository_ids when creating the token. When you omit
3233
* repository_ids, the response does not contain neither the repositories nor the permissions key.
3334
*
34-
* @param repositoryIds - Array containing the repositories Ids
35+
* @param repositoryIds
36+
* Array containing the repositories Ids
3537
*
3638
*/
37-
@Preview @Deprecated
39+
@Preview
40+
@Deprecated
3841
public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
39-
this.builder.with("repository_ids",repositoryIds);
42+
this.builder.with("repository_ids", repositoryIds);
4043
return this;
4144
}
4245

@@ -45,9 +48,11 @@ public GHAppCreateTokenBuilder repositoryIds(List<Long> repositoryIds) {
4548
*
4649
* You must use a JWT to access this endpoint.
4750
*/
48-
@Preview @Deprecated
51+
@Preview
52+
@Deprecated
4953
public GHAppInstallationToken create() throws IOException {
50-
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class).wrapUp(root);
54+
return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class)
55+
.wrapUp(root);
5156
}
5257

5358
}

src/main/java/org/kohsuke/github/GHAppInstallation.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
135135
this.repositorySelection = repositorySelection;
136136
}
137137

138-
/*package*/ GHAppInstallation wrapUp(GitHub root) {
138+
/* package */ GHAppInstallation wrapUp(GitHub root) {
139139
this.root = root;
140140
return this;
141141
}
@@ -147,21 +147,22 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
147147
*
148148
* @see <a href="https://developer.github.com/v3/apps/#delete-an-installation">Delete an installation</a>
149149
*/
150-
@Preview @Deprecated
150+
@Preview
151+
@Deprecated
151152
public void deleteInstallation() throws IOException {
152153
root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id));
153154
}
154155

155-
156156
/**
157157
* Starts a builder that creates a new App Installation Token.
158158
*
159159
* <p>
160-
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()}
161-
* to finally create an access token.
160+
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
161+
* finally create an access token.
162162
*/
163-
@Preview @Deprecated
164-
public GHAppCreateTokenBuilder createToken(Map<String,GHPermissionType> permissions){
165-
return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions);
163+
@Preview
164+
@Deprecated
165+
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
166+
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", id), permissions);
166167
}
167168
}

src/main/java/org/kohsuke/github/GHAppInstallationToken.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) {
7070
/**
7171
* When was this tokens expires?
7272
*/
73-
@WithBridgeMethods(value=String.class, adapterMethod="expiresAtStr")
73+
@WithBridgeMethods(value = String.class, adapterMethod = "expiresAtStr")
7474
public Date getExpiresAt() throws IOException {
7575
return GitHub.parseDate(expires_at);
7676
}
@@ -80,7 +80,7 @@ private Object expiresAtStr(Date id, Class type) {
8080
return expires_at;
8181
}
8282

83-
/*package*/ GHAppInstallationToken wrapUp(GitHub root) {
83+
/* package */ GHAppInstallationToken wrapUp(GitHub root) {
8484
this.root = root;
8585
return this;
8686
}

src/main/java/org/kohsuke/github/GHAsset.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public void delete() throws IOException {
8181
new Requester(root).method("DELETE").to(getApiRoute());
8282
}
8383

84-
8584
private String getApiRoute() {
8685
return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/releases/assets/" + id;
8786
}

src/main/java/org/kohsuke/github/GHAuthorization.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class GHAuthorization extends GHObject {
4242
private String note;
4343
private String note_url;
4444
private String fingerprint;
45-
//TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
46-
//private GHUser user;
45+
// TODO add some user class for https://developer.github.com/v3/oauth_authorizations/#check-an-authorization ?
46+
// private GHUser user;
4747

4848
public GitHub getRoot() {
4949
return root;
@@ -73,8 +73,7 @@ public String getAppName() {
7373
return app.name;
7474
}
7575

76-
@SuppressFBWarnings(value = "NM_CONFUSING",
77-
justification = "It's a part of the library API, cannot be changed")
76+
@SuppressFBWarnings(value = "NM_CONFUSING", justification = "It's a part of the library API, cannot be changed")
7877
public URL getApiURL() {
7978
return GitHub.parseURL(url);
8079
}
@@ -99,13 +98,13 @@ public String getFingerprint() {
9998
return fingerprint;
10099
}
101100

102-
/*package*/ GHAuthorization wrap(GitHub root) {
101+
/* package */ GHAuthorization wrap(GitHub root) {
103102
this.root = root;
104103
return this;
105104
}
106105

107-
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD"},
108-
justification = "JSON API")
106+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD",
107+
"UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
109108
private static class App {
110109
private String url;
111110
private String name;

0 commit comments

Comments
 (0)