Skip to content

Separate MessagePackHubProtocol into its own package #25253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SignalR/clients/java/signalr/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.gradletasknamecache
.gradle/
build/
/test-results
test/test-results
.settings/
out/
*.class
Expand Down
105 changes: 11 additions & 94 deletions src/SignalR/clients/java/signalr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,26 @@ plugins {
id 'maven'
}

apply plugin: "java-library"
apply plugin: "com.diffplug.gradle.spotless"
apply plugin: 'org.junit.platform.gradle.plugin'
allprojects {
apply plugin: "java-library"
apply plugin: "com.diffplug.gradle.spotless"

group 'com.microsoft.signalr'
// If we're run from outside MSBuild, just assign a bogus dev version.
version project.findProperty('packageVersion') ?: "99.99.99-dev"

// If we're run from outside MSBuild, just assign a bogus dev version.
version project.findProperty('packageVersion') ?: "99.99.99-dev"
sourceCompatibility = 1.8

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.1'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testCompile 'org.slf4j:slf4j-jdk14:1.7.25'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
api 'io.reactivex.rxjava2:rxjava:2.2.3'
implementation 'org.slf4j:slf4j-api:1.7.25'
compile 'org.msgpack:msgpack-core:0.8.20'
compile 'org.msgpack:jackson-dataformat-msgpack:0.8.20'
repositories {
mavenCentral()
}
}

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
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 else', 'else{', 'else {'
Expand All @@ -66,73 +52,4 @@ spotless {
indentWithSpaces(4)
removeUnusedImports() // removes any unused imports
}
}

junitPlatform {
reportsDir file('test-results')
}

task sourceJar(type: Jar) {
classifier "sources"
from sourceSets.main.allJava
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier "javadoc"
from javadoc.destinationDir
}

task generatePOM {
pom {
project {
inceptionYear '2018'
description 'ASP.NET Core SignalR Client for Java applications'
url 'https://github.com/dotnet/aspnetcore'
name groupId + ':' + artifactId
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'scm:git:git://github.com/dotnet/aspnetcore.git'
developerConnection 'scm:git:git://github.com/dotnet/aspnetcore.git'
url 'http://github.com/dotnet/aspnetcore/tree/master'
}
developers {
developer {
id 'microsoft'
name 'Microsoft'
}
}
}
}.writeTo("${buildDir}/libs/signalr-${project.version}.pom")
}

task createPackage(dependsOn: [jar,sourceJar,javadocJar,generatePOM])

task generateVersionClass {
inputs.property "version", project.version
outputs.dir "$buildDir/generated"
doFirst {
def versionFile = file("$buildDir/../src/main/java/com/microsoft/signalr/Version.java")
versionFile.parentFile.mkdirs()
versionFile.text =
"""
// 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.signalr;

class Version {
public static String getDetailedVersion() {
return "$project.version";
}
}
"""
}
}

compileJava.dependsOn generateVersionClass
}
75 changes: 75 additions & 0 deletions src/SignalR/clients/java/signalr/core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
group 'com.microsoft.signalr'

dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
api 'io.reactivex.rxjava2:rxjava:2.2.3'
implementation 'org.slf4j:slf4j-api:1.7.25'
}

archivesBaseName = 'signalr'

task sourceJar(type: Jar) {
classifier "sources"
from sourceSets.main.allJava
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier "javadoc"
from javadoc.destinationDir
}

task generatePOM {
pom {
project {
inceptionYear '2018'
description 'ASP.NET Core SignalR Client for Java applications'
url 'https://github.com/dotnet/aspnetcore'
name groupId + ':' + artifactId
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'scm:git:git://github.com/dotnet/aspnetcore.git'
developerConnection 'scm:git:git://github.com/dotnet/aspnetcore.git'
url 'http://github.com/dotnet/aspnetcore/tree/master'
}
developers {
developer {
id 'microsoft'
name 'Microsoft'
}
}
}
}.writeTo("${buildDir}/libs/signalr-${project.version}.pom")
}

task createPackage(dependsOn: [jar,sourceJar,javadocJar,generatePOM])

task generateVersionClass {
inputs.property "version", project.version
outputs.dir "$buildDir/generated"
doFirst {
def versionFile = file("$buildDir/../src/main/java/com/microsoft/signalr/Version.java")
versionFile.parentFile.mkdirs()
versionFile.text =
"""
// 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.signalr;

class Version {
public static String getDetailedVersion() {
return "$project.version";
}
}
"""
}
}

compileJava.dependsOn generateVersionClass
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />

<PropertyGroup>
<!-- This package ID is only ever used along with eng/PatchConfig.props to determine when to patch the Java client. -->
<PackageId>java:signalr</PackageId>
<!-- In servicing builds, this will be set to value if the Java client is not configured to be released in the currently building patch. -->
<IsPackable>true</IsPackable>
<IsTestProject>false</IsTestProject>
<!-- Disable gradle daemon on CI since the CI seems to try to wait for the daemon to shut down, which it doesn't do :) -->
<GradleOptions Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(GradleOptions) -Dorg.gradle.daemon=false</GradleOptions>
<PublishDir>$(OutputPath)</PublishDir>
</PropertyGroup>

<ItemGroup>
<Jars Include="
signalr-$(PackageVersion).jar;
signalr-$(PackageVersion)-javadoc.jar;
signalr-$(PackageVersion)-sources.jar;" />
<PomFile Include="signalr-$(PackageVersion).pom" />
<JavaBuildFiles Include="@(Jars);@(PomFile)"/>
</ItemGroup>

<Target Name="Restore" />

<PropertyGroup>
<PackDependsOn Condition=" '$(NoBuild)' != 'true' ">
$(PackDependsOn);
Build
</PackDependsOn>
</PropertyGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.targets))\Directory.Build.targets" />

<PropertyGroup>
<GradleOptions>$(GradleOptions) -PpackageVersion="$(PackageVersion)"</GradleOptions>
</PropertyGroup>

<!-- Define Target overrides after importing Directory.Build.targets so these don't get overridden -->
<Target Name="Pack" DependsOnTargets="$(PackDependsOn)" Condition="'$(IsPackable)' == 'true'">
<Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Pack" />
<Message Text="> gradlew $(GradleOptions) createPackage" Importance="high" />
<Exec Command="../gradlew $(GradleOptions) createPackage" />
<Message Importance="high" Text="java:signalr -> $(PackageOutputPath)%(JavaBuildFiles.Identity)" />
<Copy SourceFiles="$(MSBuildThisFileDirectory)build\libs\%(JavaBuildFiles.Identity)" DestinationFolder="$(PackageOutputPath)" />
</Target>

<Target Name="Build">
<Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Build" />
<Exec Command="../gradlew $(GradleOptions) compileJava" />
</Target>

<Target Name="Test" />

<Target Name="Publish" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.Map;

final class CancelInvocationMessage extends HubMessage {
public final class CancelInvocationMessage extends HubMessage {
private final int type = HubMessageType.CANCEL_INVOCATION.value;
private Map<String, String> headers;
private final String invocationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.microsoft.signalr;

final class CloseMessage extends HubMessage {
public final class CloseMessage extends HubMessage {
private final String error;
private final boolean allowReconnect;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.Map;

final class CompletionMessage extends HubMessage {
public final class CompletionMessage extends HubMessage {
private final int type = HubMessageType.COMPLETION.value;
private Map<String, String> headers;
private final String invocationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ HttpHubConnectionBuilder withHttpClient(HttpClient httpClient) {
}

/**
* Sets MessagePack as the {@link HubProtocol} to be used by the {@link HubConnection}.
* Sets the {@link HubProtocol} to be used by the {@link HubConnection}.
*
* @param protocol The {@link HubProtocol} to be used by the {@link HubConnection}.
* @return This instance of the HttpHubConnectionBuilder.
*/
public HttpHubConnectionBuilder withMessagePackHubProtocol() {
this.protocol = new MessagePackHubProtocol();
public HttpHubConnectionBuilder withHubProtocol(HubProtocol protocol) {
this.protocol = protocol;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
/**
* A base class for hub messages.
*/
abstract class HubMessage {
public abstract class HubMessage {
public abstract HubMessageType getMessageType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.microsoft.signalr;

enum HubMessageType {
public enum HubMessageType {
INVOCATION(1),
STREAM_ITEM(2),
COMPLETION(3),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
/**
* A protocol abstraction for communicating with SignalR hubs.
*/
interface HubProtocol {
public interface HubProtocol {
String getName();
int getVersion();
TransferFormat getTransferFormat();

/**
* Creates a new list of {@link HubMessage}s.
* @param message A ByteBuffer representation of one or more {@link HubMessage}s.
* @param binder The {@link InvocationBinder} to use for this Protocol instance.
* @return A list of {@link HubMessage}s.
*/
List<HubMessage> parseMessages(ByteBuffer message, InvocationBinder binder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* An abstraction for passing around information about method signatures.
*/
interface InvocationBinder {
public interface InvocationBinder {
Type getReturnType(String invocationId);
List<Type> getParameterTypes(String methodName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.microsoft.signalr;

class InvocationBindingFailureMessage extends HubMessage {
public class InvocationBindingFailureMessage extends HubMessage {
private final String invocationId;
private final String target;
private final Exception exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Collection;
import java.util.Map;

class InvocationMessage extends HubMessage {
public class InvocationMessage extends HubMessage {
int type = HubMessageType.INVOCATION.value;
private Map<String, String> headers;
private final String invocationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public int getVersion() {
return 1;
}

@Override
public TransferFormat getTransferFormat() {
return TransferFormat.TEXT;
}

@Override
public List<HubMessage> parseMessages(ByteBuffer payload, InvocationBinder binder) {
String payloadStr;
Expand Down
Loading