Convert Velocity buildscripts to Kotlin DSL (#918)
Spiritually indebted to #518 and @alexstaeding. There's a minor break - we're going up to 3.2.0-SNAPSHOT as the API now compiles against Java 11. But this is more academic in practice.
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'checkstyle'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
apply plugin: 'org.cadixdev.licenser'
|
||||
apply from: '../gradle/checkstyle.gradle'
|
||||
apply from: '../gradle/publish.gradle'
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
license {
|
||||
header = project.rootProject.file('HEADER.txt')
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "com.google.guava:guava:${guavaVersion}"
|
||||
implementation "io.netty:netty-handler:${nettyVersion}"
|
||||
implementation "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
|
||||
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
18
native/build.gradle.kts
Normal file
18
native/build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
license {
|
||||
header(project.rootProject.file("HEADER.txt"))
|
||||
}
|
||||
|
||||
val guavaVersion: String by project.extra
|
||||
val nettyVersion: String by project.extra
|
||||
val checkerFrameworkVersion: String by project.extra
|
||||
|
||||
dependencies {
|
||||
implementation("com.google.guava:guava:${guavaVersion}")
|
||||
implementation("io.netty:netty-handler:${nettyVersion}")
|
||||
implementation("org.checkerframework:checker-qual:${checkerFrameworkVersion}")
|
||||
}
|
@@ -19,6 +19,9 @@ package com.velocitypowered.natives;
|
||||
|
||||
import com.velocitypowered.natives.util.BufferPreference;
|
||||
|
||||
/**
|
||||
* Generic interface for any Velocity native.
|
||||
*/
|
||||
public interface Native {
|
||||
BufferPreference preferredBufferType();
|
||||
}
|
||||
|
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.velocitypowered.natives;
|
||||
|
||||
/**
|
||||
* Thrown when we cannot set up a variant of a native library.
|
||||
*/
|
||||
public class NativeSetupException extends RuntimeException {
|
||||
|
||||
public NativeSetupException() {
|
||||
|
@@ -28,6 +28,7 @@ class CompressorUtils {
|
||||
|
||||
/**
|
||||
* Ensures that the buffer does not go over {@code max}.
|
||||
*
|
||||
* @param buf the buffer for check
|
||||
* @param max the maximum size for the buffer
|
||||
* @throws DataFormatException if the buffer becomes too bug
|
||||
|
@@ -28,6 +28,9 @@ import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
/**
|
||||
* Implements deflate compression by wrapping {@link Deflater} and {@link Inflater}.
|
||||
*/
|
||||
public class JavaVelocityCompressor implements VelocityCompressor {
|
||||
|
||||
public static final VelocityCompressorFactory FACTORY = JavaVelocityCompressor::new;
|
||||
|
@@ -22,6 +22,9 @@ import com.velocitypowered.natives.util.BufferPreference;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
||||
/**
|
||||
* Implements deflate compression using the {@code libdeflate} native C library.
|
||||
*/
|
||||
public class LibdeflateVelocityCompressor implements VelocityCompressor {
|
||||
|
||||
public static final VelocityCompressorFactory FACTORY = LibdeflateVelocityCompressor::new;
|
||||
|
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.velocitypowered.natives.compression;
|
||||
|
||||
/**
|
||||
* Factory for {@link VelocityCompressor}.
|
||||
*/
|
||||
public interface VelocityCompressorFactory {
|
||||
|
||||
VelocityCompressor create(int level);
|
||||
|
@@ -26,6 +26,9 @@ import javax.crypto.SecretKey;
|
||||
import javax.crypto.ShortBufferException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* Implements AES-CFB8 encryption/decryption using {@link Cipher}.
|
||||
*/
|
||||
public class JavaVelocityCipher implements VelocityCipher {
|
||||
|
||||
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
||||
|
@@ -23,6 +23,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import java.security.GeneralSecurityException;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
/**
|
||||
* Implements AES-CFB8 encryption/decryption using a native library.
|
||||
*/
|
||||
public class NativeVelocityCipher implements VelocityCipher {
|
||||
|
||||
public static final VelocityCipherFactory FACTORY = new VelocityCipherFactory() {
|
||||
|
@@ -21,6 +21,15 @@ import com.velocitypowered.natives.Disposable;
|
||||
import com.velocitypowered.natives.Native;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Implements an AES-CFB8 cipher that either encrypts or decrypts connection data.
|
||||
*/
|
||||
public interface VelocityCipher extends Disposable, Native {
|
||||
|
||||
/**
|
||||
* Encrypts the given {@link ByteBuf} in-place.
|
||||
*
|
||||
* @param source the buffer to encrypt
|
||||
*/
|
||||
void process(ByteBuf source);
|
||||
}
|
||||
|
@@ -20,6 +20,9 @@ package com.velocitypowered.natives.encryption;
|
||||
import java.security.GeneralSecurityException;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
/**
|
||||
* A factory interface for {@link VelocityCipher}.
|
||||
*/
|
||||
public interface VelocityCipherFactory {
|
||||
|
||||
VelocityCipher forEncryption(SecretKey key) throws GeneralSecurityException;
|
||||
|
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.velocitypowered.natives.util;
|
||||
|
||||
/**
|
||||
* Emumerates Netty buffer preferences and requirements for use with Netty.
|
||||
*/
|
||||
public enum BufferPreference {
|
||||
/**
|
||||
* A heap buffer is required.
|
||||
|
@@ -21,6 +21,9 @@ import com.velocitypowered.natives.Native;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
|
||||
/**
|
||||
* Additional utilities for {@link ByteBuf}.
|
||||
*/
|
||||
public class MoreByteBufUtils {
|
||||
private MoreByteBufUtils() {
|
||||
throw new AssertionError();
|
||||
|
@@ -22,6 +22,11 @@ import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Supplier;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A loader for native code.
|
||||
*
|
||||
* @param <T> the interface of the instance to load
|
||||
*/
|
||||
public final class NativeCodeLoader<T> implements Supplier<T> {
|
||||
|
||||
private final Variant<T> selected;
|
||||
|
@@ -21,6 +21,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Statically-computed constraints for native code.
|
||||
*/
|
||||
public class NativeConstraints {
|
||||
private static final boolean NATIVES_ENABLED = !Boolean.getBoolean("velocity.natives-disabled");
|
||||
private static final boolean IS_AMD64;
|
||||
|
@@ -31,6 +31,9 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
* Enumerates all supported natives for Velocity.
|
||||
*/
|
||||
public class Natives {
|
||||
|
||||
private Natives() {
|
||||
|
Reference in New Issue
Block a user