Skip to content
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
33 changes: 33 additions & 0 deletions buildSrc/src/main/groovy/moco-java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

// Guava was removed in 2.0.0. This keeps it from creeping back in one import at a time.
def checkNoGuava = tasks.register('checkNoGuava') {
description = 'Fails if any source file imports com.google.common.'
group = 'verification'

def sources = sourceSets.collect { it.allJava.asFileTree }
inputs.files(sources)

doLast {
def offenders = []
sources.each { tree ->
tree.visit { details ->
if (!details.directory && details.file.name.endsWith('.java')) {
details.file.eachLine { line, number ->
if (line.startsWith('import ') && line.contains('com.google.common')) {
offenders << "${details.file}:${number}: ${line.trim()}"
}
}
}
}
}

if (!offenders.isEmpty()) {
throw new GradleException("Guava was removed in 2.0.0, but these files import it:\n "
+ offenders.join('\n '))
}
}
}

tasks.named('check').configure {
dependsOn checkNoGuava
}

jar {
manifest {
attributes(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
guava = "33.6.0-jre"
jspecify = "1.0.0"
netty = "4.2.12.Final"
slf4j = "2.0.17"
jackson = "3.1.3"
Expand All @@ -20,7 +20,7 @@ tyrus-client = "2.0.0"
maven-publish-plugin = "0.36.0"

[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" }
netty-codec-http = { module = "io.netty:netty-codec-http", version.ref = "netty" }
netty-codec-http2 = { module = "io.netty:netty-codec-http2", version.ref = "netty" }
netty-handler = { module = "io.netty:netty-handler", version.ref = "netty" }
Expand Down
3 changes: 2 additions & 1 deletion moco-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ plugins {
apply from: rootProject.file('moco-publishing.gradle')

dependencies {
implementation(libs.guava)
compileOnly(libs.jspecify)

implementation(libs.netty.codec.http)
implementation(libs.netty.codec.http2)
implementation(libs.netty.handler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.github.dreamhead.moco;

import com.github.dreamhead.moco.model.MessageContent;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.HttpHeaders;
import com.github.dreamhead.moco.util.HttpHeaders;

import java.util.Map;

public interface HttpMessage extends Message {
HttpProtocolVersion getVersion();

ImmutableMap<String, String[]> getHeaders();
Map<String, String[]> getHeaders();

String getHeader(String name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import tools.jackson.databind.annotation.JsonDeserialize;
import com.github.dreamhead.moco.model.DefaultHttpRequest;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

@JsonDeserialize(as = DefaultHttpRequest.class)
public interface HttpRequest extends Request, HttpMessage {
String getUri();

HttpMethod getMethod();

ImmutableMap<String, String[]> getQueries();
Map<String, String[]> getQueries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.dreamhead.moco.model.MessageContent;
import com.github.dreamhead.moco.resource.ContentResource;
import com.google.common.io.Closeables;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
Expand All @@ -12,7 +11,7 @@
import java.security.Security;

import static com.github.dreamhead.moco.util.Preconditions.checkNotNullOrEmpty;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

public final class HttpsCertificate {
private static final String PROTOCOL = "TLS";
Expand Down Expand Up @@ -44,8 +43,7 @@ public ContentResource getResource() {
}

private SSLContext createServerContext() {
InputStream is = this.getKeyStore();
try {
try (InputStream is = this.getKeyStore()) {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(is, this.getKeyStorePassword());
KeyManagerFactory factory = KeyManagerFactory.getInstance(getAlgorithm());
Expand All @@ -56,8 +54,6 @@ private SSLContext createServerContext() {
return serverContext;
} catch (Exception e) {
throw new MocoException("Failed to initialize the server-side SSLContext", e);
} finally {
Closeables.closeQuietly(is);
}
}

Expand All @@ -78,7 +74,7 @@ private InputStream getKeyStore() {
public static HttpsCertificate certificate(final ContentResource resource,
final String keyStorePassword,
final String certPassword) {
return new HttpsCertificate(checkNotNull(resource),
return new HttpsCertificate(requireNonNull(resource),
checkNotNullOrEmpty(keyStorePassword, "Key store password should not be null"),
checkNotNullOrEmpty(certPassword, "Cert password should not be null"));
}
Expand Down
Loading
Loading