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:
Andrew Steinborn
2023-01-01 17:53:37 -05:00
committed by GitHub
parent ffa4c95435
commit d72d707b1c
300 changed files with 2880 additions and 2169 deletions

View File

@@ -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();
}

View File

@@ -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() {

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -17,6 +17,9 @@
package com.velocitypowered.natives.compression;
/**
* Factory for {@link VelocityCompressor}.
*/
public interface VelocityCompressorFactory {
VelocityCompressor create(int level);

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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.

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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() {