Spotless for the Java Client (#2924)

This commit is contained in:
Mikael Mengistu 2018-09-07 10:39:05 -07:00 committed by GitHub
parent f18c1d7159
commit 39e6c6ff2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 84 additions and 45 deletions

View File

@ -1,6 +1,7 @@
plugins { plugins {
id 'java' id 'java'
id 'maven' id 'maven'
id "com.diffplug.gradle.spotless" version "3.14.0"
} }
group 'com.microsoft.aspnet' group 'com.microsoft.aspnet'
@ -21,6 +22,25 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.11.0' implementation 'com.squareup.okhttp3:okhttp:3.11.0'
} }
spotless {
java {
licenseHeader '// Copyright (c) .NET Foundation. All rights reserved.\n' +
'// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n\n' // License header
importOrder 'java', 'javax', 'org', 'com', 'com.diffplug', '' // A sequence of package names
replace 'Not enough space after if', 'if(', 'if ('
replace 'Not enough space after )', '){', ') {'
replace 'Not enough space after for', 'for(', 'for ('
replace 'Not enough space after while', 'while (', 'while ('
replace 'Not enough space after switch', 'switch(', 'switch ('
replaceRegex 'Too much space after if', 'if +\\(', 'if ('
trimTrailingWhitespace()
indentWithSpaces(4)
removeUnusedImports() // removes any unused imports
}
}
task sourceJar(type: Jar) { task sourceJar(type: Jar) {
classifier "sources" classifier "sources"
from sourceSets.main.allJava from sourceSets.main.allJava

View File

@ -31,4 +31,3 @@ public class CallbackMap {
handlers.remove(key); handlers.remove(key);
} }
} }

View File

@ -17,7 +17,7 @@ public class ConsoleLogger implements Logger {
@Override @Override
public void log(LogLevel logLevel, String message) { public void log(LogLevel logLevel, String message) {
if(logLevel.value >= this.logLevel.value){ if (logLevel.value >= this.logLevel.value) {
String timeStamp = dateFormat.format(new Date()); String timeStamp = dateFormat.format(new Date());
message = String.format("[%s] [%s] %s", timeStamp, logLevel, message); message = String.format("[%s] [%s] %s", timeStamp, logLevel, message);
switch (logLevel) { switch (logLevel) {

View File

@ -9,12 +9,12 @@ public class HandshakeProtocol {
public static Gson gson = new Gson(); public static Gson gson = new Gson();
private static final String RECORD_SEPARATOR = "\u001e"; private static final String RECORD_SEPARATOR = "\u001e";
public static String createHandshakeRequestMessage(HandshakeRequestMessage message){ public static String createHandshakeRequestMessage(HandshakeRequestMessage message) {
// The handshake request is always in the JSON format // The handshake request is always in the JSON format
return gson.toJson(message) + RECORD_SEPARATOR; return gson.toJson(message) + RECORD_SEPARATOR;
} }
public static HandshakeResponseMessage parseHandshakeResponse(String message){ public static HandshakeResponseMessage parseHandshakeResponse(String message) {
return gson.fromJson(message, HandshakeResponseMessage.class); return gson.fromJson(message, HandshakeResponseMessage.class);
} }
} }

View File

@ -3,15 +3,15 @@
package com.microsoft.aspnet.signalr; package com.microsoft.aspnet.signalr;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
public class HubConnection { public class HubConnection {
private String url; private String url;
private Transport transport; private Transport transport;

View File

@ -25,4 +25,3 @@ public interface HubProtocol {
*/ */
String writeMessage(HubMessage message); String writeMessage(HubMessage message);
} }

View File

@ -3,14 +3,14 @@
package com.microsoft.aspnet.signalr; package com.microsoft.aspnet.signalr;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.List;
public class JsonHubProtocol implements HubProtocol { public class JsonHubProtocol implements HubProtocol {
private final JsonParser jsonParser = new JsonParser(); private final JsonParser jsonParser = new JsonParser();
private final Gson gson = new Gson(); private final Gson gson = new Gson();
@ -57,7 +57,7 @@ public class JsonHubProtocol implements HubProtocol {
break; break;
case CLOSE: case CLOSE:
CloseMessage closeMessage; CloseMessage closeMessage;
if (jsonMessage.has("error")){ if (jsonMessage.has("error")) {
String error = jsonMessage.get("error").getAsString(); String error = jsonMessage.get("error").getAsString();
closeMessage = new CloseMessage(error); closeMessage = new CloseMessage(error);
} else { } else {

View File

@ -3,13 +3,13 @@
package com.microsoft.aspnet.signalr; package com.microsoft.aspnet.signalr;
import java.io.IOException;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import java.io.IOException;
public class Negotiate { public class Negotiate {
public static NegotiateResponse processNegotiate(String url) throws IOException { public static NegotiateResponse processNegotiate(String url) throws IOException {

View File

@ -3,13 +3,13 @@
package com.microsoft.aspnet.signalr; package com.microsoft.aspnet.signalr;
import java.util.HashSet;
import java.util.Set;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import java.util.HashSet;
import java.util.Set;
public class NegotiateResponse { public class NegotiateResponse {
private String connectionId; private String connectionId;
private Set<String> availableTransports = new HashSet<>(); private Set<String> availableTransports = new HashSet<>();
@ -49,4 +49,3 @@ public class NegotiateResponse {
return accessToken; return accessToken;
} }
} }

View File

@ -18,7 +18,7 @@ public class Subscription {
public void unsubscribe() { public void unsubscribe() {
List<ActionBase> actions = this.handlers.get(target); List<ActionBase> actions = this.handlers.get(target);
if (actions != null){ if (actions != null) {
actions.remove(action); actions.remove(action);
} }
} }

View File

@ -5,7 +5,6 @@ package com.microsoft.aspnet.signalr;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.java_websocket.client.WebSocketClient; import org.java_websocket.client.WebSocketClient;

View File

@ -1,12 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr.test;
import static org.junit.Assert.*;
import org.junit.Test;
import com.microsoft.aspnet.signalr.HandshakeProtocol; import com.microsoft.aspnet.signalr.HandshakeProtocol;
import com.microsoft.aspnet.signalr.HandshakeRequestMessage; import com.microsoft.aspnet.signalr.HandshakeRequestMessage;
import com.microsoft.aspnet.signalr.HandshakeResponseMessage; import com.microsoft.aspnet.signalr.HandshakeResponseMessage;
import org.junit.Test;
import static org.junit.Assert.*;
public class HandshakeProtocolTest { public class HandshakeProtocolTest {

View File

@ -1,7 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.*; package com.microsoft.aspnet.signalr.test;
import static org.junit.Assert.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -9,7 +12,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import static org.junit.Assert.*; import com.microsoft.aspnet.signalr.*;
public class HubConnectionTest { public class HubConnectionTest {
private static final String RECORD_SEPARATOR = "\u001e"; private static final String RECORD_SEPARATOR = "\u001e";
@ -673,7 +676,7 @@ public class HubConnectionTest {
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState()); assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
} }
@Test @Test
public void CallingStartOnStartedHubConnectionNoOps() throws Exception { public void CallingStartOnStartedHubConnectionNoOps() throws Exception {
Transport mockTransport = new MockTransport(); Transport mockTransport = new MockTransport();
@ -729,7 +732,7 @@ public class HubConnectionTest {
this.onReceive(message); this.onReceive(message);
} }
public String[] getSentMessages(){ public String[] getSentMessages() {
return sentMessages.toArray(new String[sentMessages.size()]); return sentMessages.toArray(new String[sentMessages.size()]);
} }
} }

View File

@ -1,11 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.HubException; package com.microsoft.aspnet.signalr.test;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.microsoft.aspnet.signalr.HubException;
public class HubExceptionTest { public class HubExceptionTest {
@Test @Test
public void VeryHubExceptionMesssageIsSet() { public void VeryHubExceptionMesssageIsSet() {

View File

@ -1,13 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.google.gson.JsonArray; package com.microsoft.aspnet.signalr.test;
import com.microsoft.aspnet.signalr.*;
import static org.junit.Assert.*;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import static org.junit.Assert.*; import com.google.gson.JsonArray;
import com.microsoft.aspnet.signalr.*;
public class JsonHubProtocolTest { public class JsonHubProtocolTest {
private JsonHubProtocol jsonHubProtocol = new JsonHubProtocol(); private JsonHubProtocol jsonHubProtocol = new JsonHubProtocol();

View File

@ -1,11 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.NegotiateResponse; package com.microsoft.aspnet.signalr.test;
import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test;
import com.microsoft.aspnet.signalr.NegotiateResponse;
public class NegotiateResponseTest { public class NegotiateResponseTest {
@Test @Test

View File

@ -1,15 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.Negotiate; package com.microsoft.aspnet.signalr.test;
import org.junit.Test;
import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals;
import org.junit.runners.Parameterized;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import static org.junit.Assert.assertEquals; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.microsoft.aspnet.signalr.Negotiate;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class ResolveNegotiateUrlTest { public class ResolveNegotiateUrlTest {

View File

@ -1,12 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
package com.microsoft.aspnet.signalr.test;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.microsoft.aspnet.signalr.NullLogger; import com.microsoft.aspnet.signalr.NullLogger;
import com.microsoft.aspnet.signalr.Transport; import com.microsoft.aspnet.signalr.Transport;
import com.microsoft.aspnet.signalr.WebSocketTransport; import com.microsoft.aspnet.signalr.WebSocketTransport;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class WebSocketTransportTest { public class WebSocketTransportTest {

View File

@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
import com.microsoft.aspnet.signalr.NullLogger; package com.microsoft.aspnet.signalr.test;
import com.microsoft.aspnet.signalr.WebSocketTransport;
import static org.junit.Assert.*;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
@ -12,7 +13,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import static org.junit.Assert.*; import com.microsoft.aspnet.signalr.NullLogger;
import com.microsoft.aspnet.signalr.WebSocketTransport;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class WebSocketTransportUrlFormatTest { public class WebSocketTransportUrlFormatTest {