Spotless for the Java Client (#2924)
This commit is contained in:
parent
f18c1d7159
commit
39e6c6ff2f
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'maven'
|
||||
id "com.diffplug.gradle.spotless" version "3.14.0"
|
||||
}
|
||||
|
||||
group 'com.microsoft.aspnet'
|
||||
|
|
@ -21,6 +22,25 @@ dependencies {
|
|||
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) {
|
||||
classifier "sources"
|
||||
from sourceSets.main.allJava
|
||||
|
|
|
|||
|
|
@ -31,4 +31,3 @@ public class CallbackMap {
|
|||
handlers.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class ConsoleLogger implements Logger {
|
|||
|
||||
@Override
|
||||
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());
|
||||
message = String.format("[%s] [%s] %s", timeStamp, logLevel, message);
|
||||
switch (logLevel) {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ public class HandshakeProtocol {
|
|||
public static Gson gson = new Gson();
|
||||
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
|
||||
return gson.toJson(message) + RECORD_SEPARATOR;
|
||||
}
|
||||
|
||||
public static HandshakeResponseMessage parseHandshakeResponse(String message){
|
||||
public static HandshakeResponseMessage parseHandshakeResponse(String message) {
|
||||
return gson.fromJson(message, HandshakeResponseMessage.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
public class HubConnection {
|
||||
private String url;
|
||||
private Transport transport;
|
||||
|
|
|
|||
|
|
@ -25,4 +25,3 @@ public interface HubProtocol {
|
|||
*/
|
||||
String writeMessage(HubMessage message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonHubProtocol implements HubProtocol {
|
||||
private final JsonParser jsonParser = new JsonParser();
|
||||
private final Gson gson = new Gson();
|
||||
|
|
@ -57,7 +57,7 @@ public class JsonHubProtocol implements HubProtocol {
|
|||
break;
|
||||
case CLOSE:
|
||||
CloseMessage closeMessage;
|
||||
if (jsonMessage.has("error")){
|
||||
if (jsonMessage.has("error")) {
|
||||
String error = jsonMessage.get("error").getAsString();
|
||||
closeMessage = new CloseMessage(error);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Negotiate {
|
||||
|
||||
public static NegotiateResponse processNegotiate(String url) throws IOException {
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
package com.microsoft.aspnet.signalr;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NegotiateResponse {
|
||||
private String connectionId;
|
||||
private Set<String> availableTransports = new HashSet<>();
|
||||
|
|
@ -49,4 +49,3 @@ public class NegotiateResponse {
|
|||
return accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class Subscription {
|
|||
|
||||
public void unsubscribe() {
|
||||
List<ActionBase> actions = this.handlers.get(target);
|
||||
if (actions != null){
|
||||
if (actions != null) {
|
||||
actions.remove(action);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ package com.microsoft.aspnet.signalr;
|
|||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
// 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.
|
||||
|
||||
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.HandshakeRequestMessage;
|
||||
import com.microsoft.aspnet.signalr.HandshakeResponseMessage;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class HandshakeProtocolTest {
|
||||
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
|
@ -9,7 +12,7 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
|
||||
public class HubConnectionTest {
|
||||
private static final String RECORD_SEPARATOR = "\u001e";
|
||||
|
|
@ -673,7 +676,7 @@ public class HubConnectionTest {
|
|||
|
||||
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void CallingStartOnStartedHubConnectionNoOps() throws Exception {
|
||||
Transport mockTransport = new MockTransport();
|
||||
|
|
@ -729,7 +732,7 @@ public class HubConnectionTest {
|
|||
this.onReceive(message);
|
||||
}
|
||||
|
||||
public String[] getSentMessages(){
|
||||
public String[] getSentMessages() {
|
||||
return sentMessages.toArray(new String[sentMessages.size()]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.HubException;
|
||||
import org.junit.Test;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.microsoft.aspnet.signalr.HubException;
|
||||
|
||||
public class HubExceptionTest {
|
||||
@Test
|
||||
public void VeryHubExceptionMesssageIsSet() {
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
// 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.
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.microsoft.aspnet.signalr.*;
|
||||
|
||||
public class JsonHubProtocolTest {
|
||||
private JsonHubProtocol jsonHubProtocol = new JsonHubProtocol();
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.NegotiateResponse;
|
||||
import org.junit.Test;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.microsoft.aspnet.signalr.NegotiateResponse;
|
||||
|
||||
public class NegotiateResponseTest {
|
||||
|
||||
@Test
|
||||
|
|
@ -1,15 +1,18 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.Negotiate;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
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)
|
||||
public class ResolveNegotiateUrlTest {
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
// 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.
|
||||
|
||||
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.Transport;
|
||||
import com.microsoft.aspnet.signalr.WebSocketTransport;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class WebSocketTransportTest {
|
||||
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
// 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.
|
||||
|
||||
import com.microsoft.aspnet.signalr.NullLogger;
|
||||
import com.microsoft.aspnet.signalr.WebSocketTransport;
|
||||
package com.microsoft.aspnet.signalr.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -12,7 +13,8 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
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)
|
||||
public class WebSocketTransportUrlFormatTest {
|
||||
Loading…
Reference in New Issue