BREAKING: modularize
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Johannes Frohnmeyer 2023-09-21 21:08:40 +02:00
parent 8d741c5e49
commit 8aebf179d4
Signed by: Johannes
GPG Key ID: E76429612C2929F4
125 changed files with 772 additions and 517 deletions

View File

@ -1,5 +0,0 @@
module io.gitlab.jfronny.commons.gson.dsl {
requires io.gitlab.jfronny.commons.gson;
requires kotlin.stdlib;
exports io.gitlab.jfronny.commons.serialize.gson.dsl;
}

View File

@ -1,62 +0,0 @@
package io.gitlab.jfronny.commons.serialize.gson.api.v1;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonTransformer;
import io.gitlab.jfronny.gson.*;
import java.lang.reflect.Type;
import java.util.function.Consumer;
/**
* Holds a common instance of the Gson object.
* Supports registering type adapters/etc. as needed
*/
@Deprecated
public class GsonHolder {
private final io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolder impl;
public GsonHolder() {
this(new io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolder());
}
public GsonHolder(io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolder impl) {
this.impl = impl;
}
/**
* Get the current gson instance or build it if needed
*
* @return The Gson instance
*/
public Gson getGson() {
return impl.getGson();
}
/**
* Register a type adapter and mark the gson instance as unclean
*
* @param type The type for which to register the adapter
* @param typeAdapter The adapter type
*/
public GsonHolder registerTypeAdapter(Type type, Object typeAdapter) {
impl.registerTypeAdapter(type, typeAdapter);
return this;
}
/**
* Register a type adapter factory and mark the gson instance as unclean
*
* @param factory The factory to register
*/
public GsonHolder registerTypeAdapterFactory(TypeAdapterFactory factory) {
impl.registerTypeAdapterFactory(factory);
return this;
}
/**
* Run a function on the builder for modifying it and mark the gson instance as unclean
*
* @param func The function to run
*/
public GsonHolder modifyBuilder(Consumer<GsonBuilder> func) {
impl.apply(GsonTransformer.byConsumer(func));
return this;
}
}

View File

@ -1,34 +0,0 @@
package io.gitlab.jfronny.commons.serialize.gson.api.v1;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonTransformer;
import io.gitlab.jfronny.gson.GsonBuilder;
import io.gitlab.jfronny.gson.TypeAdapterFactory;
import java.lang.reflect.Type;
import java.util.function.Consumer;
@Deprecated
public class GsonHolders {
public static final GsonHolder API = new GsonHolder(io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders.API);
public static final GsonHolder CONFIG = new GsonHolder(io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders.CONFIG);
public static void registerTypeAdapter(Type type, Object typeAdapter) {
modifyBuilder(GsonTransformer.byTypeAdapter(type, typeAdapter));
}
public static void registerTypeAdapterFactory(TypeAdapterFactory factory) {
modifyBuilder(GsonTransformer.byTypeAdapterFactory(factory));
}
public static void modifyBuilder(Consumer<GsonBuilder> func) {
modifyBuilder(GsonTransformer.byConsumer(func));
}
private static void modifyBuilder(GsonTransformer transformer) {
io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders.applyTransform(transformer);
}
public static void registerSerializer() {
io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders.registerSerializer();
}
}

View File

@ -1,13 +0,0 @@
package io.gitlab.jfronny.commons.serialize.gson.api.v1;
import java.lang.annotation.*;
/**
* Mark a class/field to be ignored by Gson.
* May be used for metadata in serialized classes
*/
@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface Ignore {
}

View File

@ -1,22 +0,0 @@
package io.gitlab.jfronny.commons.serialize.gson.impl;
import io.gitlab.jfronny.commons.serialize.gson.api.v1.Ignore;
import io.gitlab.jfronny.gson.*;
/**
* An exclusion strategy that ignores fields with the GsonIgnore attribute
*/
public class GsonIgnoreExclusionStrategy implements ExclusionStrategy {
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return clazz.isAnnotationPresent(Ignore.class)
|| clazz.isAnnotationPresent(io.gitlab.jfronny.commons.serialize.gson.api.v2.Ignore.class);
}
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(Ignore.class) != null
|| f.getAnnotation(io.gitlab.jfronny.commons.serialize.gson.api.v2.Ignore.class) != null
|| shouldSkipClass(f.getDeclaringClass());
}
}

View File

@ -0,0 +1,19 @@
plugins {
id("commons.library")
}
dependencies {
implementation(project(":commons"))
implementation(project(":commons-serialize"))
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-http-client"
from(components["java"])
}
}
}

View File

@ -1,28 +1,32 @@
package io.gitlab.jfronny.commons;
package io.gitlab.jfronny.commons.http.client;
import io.gitlab.jfronny.commons.serialize.Serializer;
import java.io.*;
import java.lang.reflect.Type;
import java.net.*;
import java.net.http.*;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.Base64;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class HttpUtils {
public class HttpClient {
private static String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
private static final String PROXY_AUTH;
private static final HttpClient CLIENT;
private static final java.net.http.HttpClient CLIENT;
static {
// Enables HTTPS proxying
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
HttpClient.Builder clientBuilder = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS);
java.net.http.HttpClient.Builder clientBuilder = java.net.http.HttpClient.newBuilder().followRedirects(java.net.http.HttpClient.Redirect.ALWAYS);
String host = System.getProperty("http.proxyHost");
String port = System.getProperty("http.proxyPort");
@ -47,7 +51,7 @@ public class HttpUtils {
public static void setUserAgent(String hostname) {
if (hostname == null || hostname.isEmpty()) throw new IllegalArgumentException("Hostname cannot be empty");
HttpUtils.userAgent = hostname;
userAgent = hostname;
}
private enum Method {
@ -182,7 +186,7 @@ public class HttpUtils {
// Redirect
if (location.isPresent() && method == Method.GET) {
try {
yield HttpUtils.get(location.get())._send(accept, responseBodyHandler);
yield get(location.get())._send(accept, responseBodyHandler);
} catch (URISyntaxException e) {
throw new IOException("Could not follow redirect" + exceptionSuffix, e);
}

View File

@ -0,0 +1,6 @@
module io.gitlab.jfronny.commons.http.client {
requires java.net.http;
requires io.gitlab.jfronny.commons;
requires io.gitlab.jfronny.commons.serialize;
exports io.gitlab.jfronny.commons.http.client;
}

View File

@ -11,7 +11,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-jlhttp"
artifactId = "commons-http-server"
from(components["java"])
}

View File

@ -1,8 +1,13 @@
package io.gitlab.jfronny.commons.jlhttp;
package io.gitlab.jfronny.commons.http.server;
import io.gitlab.jfronny.commons.jlhttp.api.*;
import io.gitlab.jfronny.commons.jlhttp.io.*;
import io.gitlab.jfronny.commons.jlhttp.util.*;
import io.gitlab.jfronny.commons.http.server.api.ContextHandler;
import io.gitlab.jfronny.commons.http.server.io.ChunkedInputStream;
import io.gitlab.jfronny.commons.http.server.io.ChunkedOutputStream;
import io.gitlab.jfronny.commons.http.server.io.LimitedInputStream;
import io.gitlab.jfronny.commons.http.server.util.FileContextHandler;
import io.gitlab.jfronny.commons.http.server.util.Header;
import io.gitlab.jfronny.commons.http.server.util.Headers;
import io.gitlab.jfronny.commons.http.server.util.VirtualHost;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;
@ -13,7 +18,9 @@ import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPOutputStream;

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.commons.jlhttp.api;
package io.gitlab.jfronny.commons.http.server.api;
import io.gitlab.jfronny.commons.jlhttp.util.VirtualHost;
import io.gitlab.jfronny.commons.http.server.util.VirtualHost;
import java.lang.annotation.*;

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.jlhttp.api;
package io.gitlab.jfronny.commons.http.server.api;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.jlhttp.util.VirtualHost;
import io.gitlab.jfronny.commons.http.server.util.VirtualHost;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import java.io.IOException;

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.jlhttp.io;
package io.gitlab.jfronny.commons.http.server.io;
import io.gitlab.jfronny.commons.jlhttp.*;
import io.gitlab.jfronny.commons.jlhttp.util.Headers;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.util.Headers;
import java.io.IOException;
import java.io.InputStream;

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.jlhttp.io;
package io.gitlab.jfronny.commons.http.server.io;
import io.gitlab.jfronny.commons.jlhttp.util.Headers;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.util.Headers;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import java.io.*;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.jlhttp.io;
package io.gitlab.jfronny.commons.http.server.io;
import java.io.*;

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.commons.jlhttp.io;
package io.gitlab.jfronny.commons.http.server.io;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import java.io.*;

View File

@ -1,9 +1,9 @@
package io.gitlab.jfronny.commons.jlhttp.io;
package io.gitlab.jfronny.commons.http.server.io;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.jlhttp.util.VirtualHost;
import io.gitlab.jfronny.commons.jlhttp.api.Context;
import io.gitlab.jfronny.commons.jlhttp.util.Headers;
import io.gitlab.jfronny.commons.http.server.util.VirtualHost;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.api.Context;
import io.gitlab.jfronny.commons.http.server.util.Headers;
import java.io.IOException;
import java.io.InputStream;

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.jlhttp.util;
package io.gitlab.jfronny.commons.http.server.util;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.jlhttp.api.ContextHandler;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.api.ContextHandler;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.jlhttp.util;
package io.gitlab.jfronny.commons.http.server.util;
/**
* The {@code Header} class encapsulates a single HTTP header.

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.commons.jlhttp.util;
package io.gitlab.jfronny.commons.http.server.util;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import java.io.IOException;
import java.io.OutputStream;

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.jlhttp.util;
package io.gitlab.jfronny.commons.http.server.util;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.jlhttp.api.ContextHandler;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.api.ContextHandler;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

View File

@ -1,8 +1,8 @@
package io.gitlab.jfronny.commons.jlhttp.util;
package io.gitlab.jfronny.commons.http.server.util;
import io.gitlab.jfronny.commons.jlhttp.JLHTTPServer;
import io.gitlab.jfronny.commons.jlhttp.api.Context;
import io.gitlab.jfronny.commons.jlhttp.api.ContextHandler;
import io.gitlab.jfronny.commons.http.server.JLHTTPServer;
import io.gitlab.jfronny.commons.http.server.api.Context;
import io.gitlab.jfronny.commons.http.server.api.ContextHandler;
import java.lang.reflect.Method;
import java.util.*;

View File

@ -0,0 +1,6 @@
module io.gitlab.jfronny.commons.http.server {
exports io.gitlab.jfronny.commons.http.server;
exports io.gitlab.jfronny.commons.http.server.api;
exports io.gitlab.jfronny.commons.http.server.io;
exports io.gitlab.jfronny.commons.http.server.util;
}

View File

@ -0,0 +1,21 @@
import io.gitlab.jfronny.scripts.*
plugins {
id("commons.library")
}
dependencies {
implementation(project(":commons"))
implementation(project(":commons-serialize"))
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-io"
from(components["java"])
}
}
}

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons;
package io.gitlab.jfronny.commons.io;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

View File

@ -74,16 +74,6 @@ public class JFiles {
} else Files.delete(path);
}
@Deprecated
public static void copyContent(Path source, Path destination) throws IOException {
copyRecursive(source, destination);
}
@Deprecated
public static void copyContent(Path source, Path target, CopyOption... copyOptions) throws IOException {
copyRecursive(source, target, copyOptions);
}
/**
* If the source is a file, copy it to the target. If it is a directory, create the target directory if it doesn't exist and copy the source directories content there
*

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.cache;
package io.gitlab.jfronny.commons.io.cache;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.cache;
package io.gitlab.jfronny.commons.io.cache;
import io.gitlab.jfronny.commons.io.JFiles;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.cache;
package io.gitlab.jfronny.commons.io.cache;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.cache;
package io.gitlab.jfronny.commons.io.cache;
import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.cache;
package io.gitlab.jfronny.commons.io.cache;
import io.gitlab.jfronny.commons.throwable.ThrowingSupplier;

View File

@ -0,0 +1,7 @@
module io.gitlab.jfronny.commons.io {
requires io.gitlab.jfronny.commons;
requires io.gitlab.jfronny.commons.serialize;
requires static org.jetbrains.annotations;
exports io.gitlab.jfronny.commons.io;
exports io.gitlab.jfronny.commons.io.cache;
}

View File

@ -1,6 +0,0 @@
module io.gitlab.jfronny.commons.jlhttp {
exports io.gitlab.jfronny.commons.jlhttp;
exports io.gitlab.jfronny.commons.jlhttp.api;
exports io.gitlab.jfronny.commons.jlhttp.io;
exports io.gitlab.jfronny.commons.jlhttp.util;
}

View File

@ -7,6 +7,7 @@ plugins {
dependencies {
implementation("org.slf4j:slf4j-api:2.0.7")
implementation(project(":commons"))
implementation(project(":commons-logging"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
@ -16,7 +17,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-slf4j"
artifactId = "commons-logging-slf4j"
from(components["java"])
}

View File

@ -1,11 +1,11 @@
package io.gitlab.jfronny.commons.log.slf4j;
package io.gitlab.jfronny.commons.logging.slf4j;
import org.slf4j.Logger;
import org.slf4j.Marker;
public record CommonsLogger(io.gitlab.jfronny.commons.log.Logger delegate) implements Logger {
public record CommonsLogger(io.gitlab.jfronny.commons.logging.Logger delegate) implements Logger {
public CommonsLogger(String name) {
this(io.gitlab.jfronny.commons.log.Logger.forName(name));
this(io.gitlab.jfronny.commons.logging.Logger.forName(name));
}
@Override

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log.slf4j;
package io.gitlab.jfronny.commons.logging.slf4j;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log.slf4j;
package io.gitlab.jfronny.commons.logging.slf4j;
import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.commons.log.slf4j;
package io.gitlab.jfronny.commons.logging.slf4j;
import io.gitlab.jfronny.commons.log.Logger;
import io.gitlab.jfronny.commons.logging.Logger;
import org.slf4j.LoggerFactory;
public class SLF4JLogger implements Logger {

View File

@ -0,0 +1,6 @@
module io.gitlab.jfronny.commons.logging.slf4j {
requires io.gitlab.jfronny.commons;
requires io.gitlab.jfronny.commons.logging;
requires org.slf4j;
exports io.gitlab.jfronny.commons.logging.slf4j;
}

View File

@ -1,7 +1,7 @@
package io.gitlab.jfronny.commons.test;
import io.gitlab.jfronny.commons.log.HotSwappingDelegateLogger;
import io.gitlab.jfronny.commons.log.slf4j.SLF4JLogger;
import io.gitlab.jfronny.commons.logging.HotSwappingDelegateLogger;
import io.gitlab.jfronny.commons.logging.slf4j.SLF4JLogger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

View File

@ -0,0 +1,20 @@
import io.gitlab.jfronny.scripts.*
plugins {
id("commons.library")
}
dependencies {
implementation(project(":commons"))
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-logging"
from(components["java"])
}
}
}

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import io.gitlab.jfronny.commons.ref.WeakSet;
import org.jetbrains.annotations.NotNull;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import java.util.logging.Level;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
public enum Level {
TRACE(OutputColors.WHITE),

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import io.gitlab.jfronny.commons.StringFormatter;
import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,5 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import io.gitlab.jfronny.commons.cache.FixedSizeSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -9,16 +8,19 @@ import java.util.function.Consumer;
public class MemoryLogger implements Logger, Iterable<String> {
private final String name;
private final Set<String> lines;
private final List<String> lines;
private final int size;
public MemoryLogger(String name) {
this.name = name;
this.lines = new LinkedHashSet<>();
this.lines = new LinkedList<>();
this.size = -1;
}
public MemoryLogger(String name, int size) {
this.name = name;
this.lines = new FixedSizeSet<>(size);
this.lines = new ArrayList<>(size);
this.size = size;
}
@Override
@ -26,29 +28,40 @@ public class MemoryLogger implements Logger, Iterable<String> {
return name;
}
private void add(String msg) {
synchronized (lines) {
int lz = lines.size();
if (size != -1 && lz >= size - 1) {
Iterator<String> iterator = lines.iterator();
for (int i = 0, max = lz - size + 1; i < max; i++) iterator.remove();
}
lines.add(msg);
}
}
@Override
public void trace(String msg) {
lines.add("[T] " + msg);
add("[T] " + msg);
}
@Override
public void debug(String msg) {
lines.add("[D] " + msg);
add("[D] " + msg);
}
@Override
public void info(String msg) {
lines.add("[I] " + msg);
add("[I] " + msg);
}
@Override
public void warn(String msg) {
lines.add("[W] " + msg);
add("[W] " + msg);
}
@Override
public void error(String msg) {
lines.add("[E] " + msg);
add("[E] " + msg);
}
@NotNull

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
public class NopLogger implements Logger {
@Override

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
public class OutputColors {
// Reset

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.commons.log;
package io.gitlab.jfronny.commons.logging;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

View File

@ -0,0 +1,6 @@
module io.gitlab.jfronny.commons.logging {
exports io.gitlab.jfronny.commons.logging;
requires static org.jetbrains.annotations;
requires io.gitlab.jfronny.commons;
requires java.logging;
}

View File

@ -1,9 +1,14 @@
package io.gitlab.jfronny.commons.test;
package io.gitlab.jfronny.commons.logging.test;
import io.gitlab.jfronny.commons.log.*;
import org.junit.jupiter.api.*;
import io.gitlab.jfronny.commons.logging.HotSwappingDelegateLogger;
import io.gitlab.jfronny.commons.logging.Logger;
import io.gitlab.jfronny.commons.logging.NopLogger;
import io.gitlab.jfronny.commons.logging.StdoutLogger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
public class LoggerTest {
@BeforeEach

View File

@ -6,7 +6,7 @@ plugins {
}
dependencies {
implementation(project(":commons-gson"))
implementation(project(":commons-serialize-gson"))
testImplementation(kotlin("test"))
}
@ -29,6 +29,7 @@ tasks.compileKotlin {
tasks.javadoc {
enabled = false
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons/$version/raw", project(":commons"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-gson"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-serialize"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-serialize-gson"))
//TODO link gson javadoc (harder to generate than expected)
}

View File

@ -0,0 +1,5 @@
module io.gitlab.jfronny.commons.serialize.gson.dsl {
requires io.gitlab.jfronny.commons.serialize.gson;
requires kotlin.stdlib;
exports io.gitlab.jfronny.commons.serialize.gson.dsl;
}

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.commons.serialize.gson.dsl.test
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders
import io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders
import io.gitlab.jfronny.commons.serialize.gson.dsl.jObjectString
import kotlin.test.Test
import kotlin.test.assertEquals

View File

@ -7,6 +7,7 @@ plugins {
dependencies {
api("io.gitlab.jfronny:gson:2.10.3-SNAPSHOT")
implementation(project(":commons"))
implementation(project(":commons-serialize"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
@ -16,7 +17,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-gson"
artifactId = "commons-serialize-gson"
from(components["java"])
}
@ -25,5 +26,6 @@ publishing {
tasks.javadoc {
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons/$version/raw", project(":commons"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons/$version/raw", project(":commons-serialize"))
//TODO link gson javadoc (harder to generate than expected)
}

View File

@ -0,0 +1,19 @@
package io.gitlab.jfronny.commons.serialize.gson.impl;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.Ignore;
import io.gitlab.jfronny.gson.*;
/**
* An exclusion strategy that ignores fields with the GsonIgnore attribute
*/
public class GsonIgnoreExclusionStrategy implements ExclusionStrategy {
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return clazz.isAnnotationPresent(Ignore.class);
}
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getAnnotation(Ignore.class) != null || shouldSkipClass(f.getDeclaringClass());
}
}

View File

@ -1,8 +1,8 @@
module io.gitlab.jfronny.commons.gson {
module io.gitlab.jfronny.commons.serialize.gson {
uses io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonTransformer;
requires io.gitlab.jfronny.commons;
requires io.gitlab.jfronny.commons.serialize;
requires transitive io.gitlab.jfronny.gson;
requires static org.jetbrains.annotations;
exports io.gitlab.jfronny.commons.serialize.gson.api.v1;
exports io.gitlab.jfronny.commons.serialize.gson.api.v2;
}

View File

@ -3,8 +3,8 @@ package io.gitlab.jfronny.commons.test;
import io.gitlab.jfronny.commons.ComparableVersion;
import io.gitlab.jfronny.commons.data.String2ObjectMap;
import io.gitlab.jfronny.commons.serialize.Serializer;
import io.gitlab.jfronny.commons.serialize.gson.api.v1.Ignore;
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.Ignore;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders;
import io.gitlab.jfronny.gson.reflect.TypeToken;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

View File

@ -0,0 +1,16 @@
import io.gitlab.jfronny.scripts.*
plugins {
id("commons.library")
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-serialize"
from(components["java"])
}
}
}

View File

@ -0,0 +1,4 @@
module io.gitlab.jfronny.commons.serialize {
requires static org.jetbrains.annotations;
exports io.gitlab.jfronny.commons.serialize;
}

View File

@ -1,5 +0,0 @@
module io.gitlab.jfronny.commons.slf4j {
requires io.gitlab.jfronny.commons;
requires org.slf4j;
exports io.gitlab.jfronny.commons.log.slf4j;
}

View File

@ -0,0 +1,18 @@
plugins {
id("commons.library")
}
dependencies {
implementation(project(":commons"))
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-unsafe"
from(components["java"])
}
}
}

View File

@ -0,0 +1,347 @@
package io.gitlab.jfronny.commons.unsafe;
import io.gitlab.jfronny.commons.throwable.Try;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
@SuppressWarnings({"unchecked", "unused"})
public class Unsafe {
public static final sun.misc.Unsafe theUnsafe = Try.orThrow(() -> {
Field unsafeField = Try.orThrow(() -> sun.misc.Unsafe.class.getDeclaredField("theUnsafe"));
unsafeField.setAccessible(true);
return (sun.misc.Unsafe) unsafeField.get(null);
});
public static int getInt(Object o, long offset) {
return theUnsafe.getInt(o, offset);
}
public static void putInt(Object o, long offset, int x) {
theUnsafe.putInt(o, offset, x);
}
public static <T> T getObject(Object o, long offset) {
return (T) theUnsafe.getObject(o, offset);
}
public static void putObject(Object o, long offset, Object x) {
theUnsafe.putObject(o, offset, x);
}
public static boolean getBoolean(Object o, long offset) {
return theUnsafe.getBoolean(o, offset);
}
public static void putBoolean(Object o, long offset, boolean x) {
theUnsafe.putBoolean(o, offset, x);
}
public static byte getByte(Object o, long offset) {
return theUnsafe.getByte(o, offset);
}
public static void putByte(Object o, long offset, byte x) {
theUnsafe.putByte(o, offset, x);
}
public static short getShort(Object o, long offset) {
return theUnsafe.getShort(o, offset);
}
public static void putShort(Object o, long offset, short x) {
theUnsafe.putShort(o, offset, x);
}
public static char getChar(Object o, long offset) {
return theUnsafe.getChar(o, offset);
}
public static void putChar(Object o, long offset, char x) {
theUnsafe.putChar(o, offset, x);
}
public static long getLong(Object o, long offset) {
return theUnsafe.getLong(o, offset);
}
public static void putLong(Object o, long offset, long x) {
theUnsafe.putLong(o, offset, x);
}
public static float getFloat(Object o, long offset) {
return theUnsafe.getFloat(o, offset);
}
public static void putFloat(Object o, long offset, float x) {
theUnsafe.putFloat(o, offset, x);
}
public static double getDouble(Object o, long offset) {
return theUnsafe.getDouble(o, offset);
}
public static void putDouble(Object o, long offset, double x) {
theUnsafe.putDouble(o, offset, x);
}
public static byte getByte(long address) {
return theUnsafe.getByte(address);
}
public static void putByte(long address, byte x) {
theUnsafe.putByte(address, x);
}
public static short getShort(long address) {
return theUnsafe.getShort(address);
}
public static void putShort(long address, short x) {
theUnsafe.putShort(address, x);
}
public static char getChar(long address) {
return theUnsafe.getChar(address);
}
public static void putChar(long address, char x) {
theUnsafe.putChar(address, x);
}
public static int getInt(long address) {
return theUnsafe.getInt(address);
}
public static void putInt(long address, int x) {
theUnsafe.putInt(address, x);
}
public static long getLong(long address) {
return theUnsafe.getLong(address);
}
public static void putLong(long address, long x) {
theUnsafe.putLong(address, x);
}
public static float getFloat(long address) {
return theUnsafe.getFloat(address);
}
public static void putFloat(long address, float x) {
theUnsafe.putFloat(address, x);
}
public static double getDouble(long address) {
return theUnsafe.getDouble(address);
}
public static void putDouble(long address, double x) {
theUnsafe.putDouble(address, x);
}
public static long getAddress(long address) {
return theUnsafe.getAddress(address);
}
public static void putAddress(long address, long x) {
theUnsafe.putAddress(address, x);
}
public static long allocateMemory(long bytes) {
return theUnsafe.allocateMemory(bytes);
}
public static long reallocateMemory(long address, long bytes) {
return theUnsafe.reallocateMemory(address, bytes);
}
public static void setMemory(Object o, long offset, long bytes, byte value) {
theUnsafe.setMemory(o, offset, bytes, value);
}
public static void setMemory(long address, long bytes, byte value) {
theUnsafe.setMemory(address, bytes, value);
}
public static void copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) {
theUnsafe.copyMemory(srcBase, srcOffset, destBase, destOffset, bytes);
}
public static void copyMemory(long srcAddress, long destAddress, long bytes) {
theUnsafe.copyMemory(srcAddress, destAddress, bytes);
}
public static void freeMemory(long address) {
theUnsafe.freeMemory(address);
}
public static int arrayBaseOffset(Class<?> arrayClass) {
return theUnsafe.arrayBaseOffset(arrayClass);
}
public static int arrayIndexScale(Class<?> arrayClass) {
return theUnsafe.arrayIndexScale(arrayClass);
}
public static int addressSize() {
return theUnsafe.addressSize();
}
public static int pageSize() {
return theUnsafe.pageSize();
}
public static <T> T allocateInstance(Class<T> cls) throws InstantiationException {
return (T) theUnsafe.allocateInstance(cls);
}
public static void throwException(Throwable ee) {
theUnsafe.throwException(ee);
}
public static boolean compareAndSwapObject(Object o, long offset, Object expected, Object x) {
return theUnsafe.compareAndSwapObject(o, offset, expected, x);
}
public static boolean compareAndSwapInt(Object o, long offset, int expected, int x) {
return theUnsafe.compareAndSwapInt(o, offset, expected, x);
}
public static boolean compareAndSwapLong(Object o, long offset, long expected, long x) {
return theUnsafe.compareAndSwapLong(o, offset, expected, x);
}
public static <T> T getObjectVolatile(Object o, long offset) {
return (T) theUnsafe.getObjectVolatile(o, offset);
}
public static void putObjectVolatile(Object o, long offset, Object x) {
theUnsafe.putObjectVolatile(o, offset, x);
}
public static int getIntVolatile(Object o, long offset) {
return theUnsafe.getIntVolatile(o, offset);
}
public static void putIntVolatile(Object o, long offset, int x) {
theUnsafe.putIntVolatile(o, offset, x);
}
public static boolean getBooleanVolatile(Object o, long offset) {
return theUnsafe.getBooleanVolatile(o, offset);
}
public static void putBooleanVolatile(Object o, long offset, boolean x) {
theUnsafe.putBooleanVolatile(o, offset, x);
}
public static byte getByteVolatile(Object o, long offset) {
return theUnsafe.getByteVolatile(o, offset);
}
public static void putByteVolatile(Object o, long offset, byte x) {
theUnsafe.putByteVolatile(o, offset, x);
}
public static short getShortVolatile(Object o, long offset) {
return theUnsafe.getShortVolatile(o, offset);
}
public static void putShortVolatile(Object o, long offset, short x) {
theUnsafe.putShortVolatile(o, offset, x);
}
public static char getCharVolatile(Object o, long offset) {
return theUnsafe.getCharVolatile(o, offset);
}
public static void putCharVolatile(Object o, long offset, char x) {
theUnsafe.putCharVolatile(o, offset, x);
}
public static long getLongVolatile(Object o, long offset) {
return theUnsafe.getLongVolatile(o, offset);
}
public static void putLongVolatile(Object o, long offset, long x) {
theUnsafe.putLongVolatile(o, offset, x);
}
public static float getFloatVolatile(Object o, long offset) {
return theUnsafe.getFloatVolatile(o, offset);
}
public static void putFloatVolatile(Object o, long offset, float x) {
theUnsafe.putFloatVolatile(o, offset, x);
}
public static double getDoubleVolatile(Object o, long offset) {
return theUnsafe.getDoubleVolatile(o, offset);
}
public static void putDoubleVolatile(Object o, long offset, double x) {
theUnsafe.putDoubleVolatile(o, offset, x);
}
public static void putOrderedObject(Object o, long offset, Object x) {
theUnsafe.putOrderedObject(o, offset, x);
}
public static void putOrderedInt(Object o, long offset, int x) {
theUnsafe.putOrderedInt(o, offset, x);
}
public static void putOrderedLong(Object o, long offset, long x) {
theUnsafe.putOrderedLong(o, offset, x);
}
public static void unpark(Object thread) {
theUnsafe.unpark(thread);
}
public static void park(boolean isAbsolute, long time) {
theUnsafe.park(isAbsolute, time);
}
public static int getLoadAverage(double[] loadavg, int nelems) {
return theUnsafe.getLoadAverage(loadavg, nelems);
}
public static int getAndAddInt(Object o, long offset, int delta) {
return theUnsafe.getAndAddInt(o, offset, delta);
}
public static long getAndAddLong(Object o, long offset, long delta) {
return theUnsafe.getAndAddLong(o, offset, delta);
}
public static int getAndSetInt(Object o, long offset, int newValue) {
return theUnsafe.getAndSetInt(o, offset, newValue);
}
public static long getAndSetLong(Object o, long offset, long newValue) {
return theUnsafe.getAndSetLong(o, offset, newValue);
}
public static <T> T getAndSetObject(Object o, long offset, T newValue) {
return (T) theUnsafe.getAndSetObject(o, offset, newValue);
}
public static void loadFence() {
theUnsafe.loadFence();
}
public static void storeFence() {
theUnsafe.storeFence();
}
public static void fullFence() {
theUnsafe.fullFence();
}
public static void invokeCleaner(ByteBuffer directBuffer) {
theUnsafe.invokeCleaner(directBuffer);
}
}

View File

@ -1,6 +1,9 @@
package io.gitlab.jfronny.commons.reflect;
package io.gitlab.jfronny.commons.unsafe.reflect;
import java.lang.invoke.*;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.function.*;
@SuppressWarnings("unchecked")

View File

@ -1,45 +1,10 @@
package io.gitlab.jfronny.commons.reflect;
import io.gitlab.jfronny.commons.throwable.*;
package io.gitlab.jfronny.commons.unsafe.reflect;
import java.lang.invoke.MethodHandles;
import java.util.function.*;
@SuppressWarnings("unchecked")
public class Reflect {
@Deprecated
public static <TOut> ThrowingSupplier<TOut, ReflectiveOperationException> getConstructor(Class<TOut> toConstruct) throws Throwable {
Supplier<TOut> constructor = constructor(toConstruct);
return constructor::get;
}
@Deprecated
public static <TOut> ThrowingSupplier<TOut, ReflectiveOperationException> getConstructor(String targetClassName) throws Throwable {
return Reflect.getConstructor((Class<TOut>) Class.forName(targetClassName));
}
@Deprecated
public static <TIn, TOut> ThrowingFunction<TIn, TOut, ReflectiveOperationException> getConstructor(Class<TOut> toConstruct, Class<TIn> parameterType) throws Throwable {
Function<TIn, TOut> constructor = constructor(toConstruct, parameterType);
return constructor::apply;
}
@Deprecated
public static <TIn, TOut> ThrowingFunction<TIn, TOut, ReflectiveOperationException> getConstructor(String targetClassName, Class<TIn> parameterType) throws Throwable {
return getConstructor((Class<TOut>) Class.forName(targetClassName), parameterType);
}
@Deprecated
public static <TIn1, TIn2, TOut> ThrowingBiFunction<TIn1, TIn2, TOut, ReflectiveOperationException> getConstructor(Class<TOut> toConstruct, Class<TIn1> parameterType1, Class<TIn2> parameterType2) throws Throwable {
BiFunction<TIn1, TIn2, TOut> constructor = constructor(toConstruct, parameterType1, parameterType2);
return constructor::apply;
}
@Deprecated
public static <TIn1, TIn2, TOut> ThrowingBiFunction<TIn1, TIn2, TOut, ReflectiveOperationException> getConstructor(String targetClassName, Class<TIn1> parameterType1, Class<TIn2> parameterType2) throws Throwable {
return getConstructor((Class<TOut>) Class.forName(targetClassName), parameterType1, parameterType2);
}
// Constructor without parameters
public static <TOut> Supplier<TOut> constructor(Class<TOut> toConstruct) throws Throwable {
MethodHandles.Lookup lookup = LambdaFactory.lookup(toConstruct);

View File

@ -0,0 +1,7 @@
module io.gitlab.jfronny.commons.unsafe {
requires io.gitlab.jfronny.commons;
requires jdk.unsupported;
exports io.gitlab.jfronny.commons.unsafe;
exports io.gitlab.jfronny.commons.unsafe.reflect;
}

View File

@ -1,14 +1,15 @@
package io.gitlab.jfronny.commons.test;
package io.gitlab.jfronny.commons.unsafe.test;
import io.gitlab.jfronny.commons.reflect.Reflect;
import io.gitlab.jfronny.commons.unsafe.reflect.Reflect;
import org.junit.jupiter.api.Test;
import some.other.location.InstanceConstruct;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ReflectTest {
public class ReflectTest {
private static final String CLASS_NAME = "some.other.location.ToConstruct";
@Test

View File

@ -8,7 +8,7 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.gitlab.jfronny"
artifactId = "commons-gson"
artifactId = "commons"
from(components["java"])
}

View File

@ -96,45 +96,6 @@ public class Coerce {
return tr;
}
/**
* Example:
* {@code interface Test<T> {
* T get();
* void consume(T t);
* }
* class Example {
* Test<?> instance;
* void function() {
* Coerce.pin(instance.get(), v -> instance.consume(v)); // This can compile
* instance.consume(instance.get()); // This cannot
* }
* }}
*
* @param value The value to pin
* @param func The function to apply to the pinned value
* @param <TIn> The type of the value to pin
* @param <TOut> The return type of the function
* @param <TEx> An exception type (if needed)
* @return The result of the function
* @throws TEx If the function throws, nothing is handled here
*/
@Deprecated
public static <TIn, TOut, TEx extends Throwable> TOut pin(@Nullable TIn value, @NotNull ThrowingFunction<TIn, TOut, TEx> func) throws TEx {
return Objects.requireNonNull(func).apply(value);
}
/**
* @param value The value to pin
* @param func The function to apply to the pinned value
* @param <TIn> The type of the value to pin
* @param <TEx> An exception type (if needed)
* @throws TEx If the function throws, nothing is handled here
*/
@Deprecated
public static <TIn, TEx extends Throwable> void pin(@Nullable TIn value, @NotNull ThrowingConsumer<TIn, TEx> func) throws TEx {
Objects.requireNonNull(func).accept(value);
}
/**
* Example:
* {@code interface Test<T> {

View File

@ -3,15 +3,10 @@ module io.gitlab.jfronny.commons {
requires java.net.http;
requires java.logging;
exports io.gitlab.jfronny.commons;
exports io.gitlab.jfronny.commons.cache;
exports io.gitlab.jfronny.commons.concurrent;
exports io.gitlab.jfronny.commons.data;
exports io.gitlab.jfronny.commons.data.delegate;
exports io.gitlab.jfronny.commons.io;
exports io.gitlab.jfronny.commons.log;
exports io.gitlab.jfronny.commons.ref;
exports io.gitlab.jfronny.commons.reflect;
exports io.gitlab.jfronny.commons.serialize;
exports io.gitlab.jfronny.commons.throwable;
exports io.gitlab.jfronny.commons.tuple;
}

View File

@ -6,7 +6,7 @@ plugins {
dependencies {
implementation(project(":muscript"))
implementation(project(":commons-gson"))
implementation(project(":commons-serialize-gson"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
@ -25,6 +25,7 @@ publishing {
tasks.javadoc {
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons/$version/raw", project(":commons"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-gson"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-serialize"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/commons-gson/$version/raw", project(":commons-serialize-gson"))
linksOffline("https://maven.frohnmeyer-wds.de/javadoc/artifacts/io/gitlab/jfronny/muscript-gson/$version/raw", project(":muscript"))
}

View File

@ -1,7 +1,7 @@
module io.gitlab.jfronny.commons.muscript.gson {
requires io.gitlab.jfronny.gson;
requires io.gitlab.jfronny.commons.muscript;
requires io.gitlab.jfronny.commons.gson;
requires io.gitlab.jfronny.commons.serialize.gson;
exports io.gitlab.jfronny.muscript.gson;
// provides io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonTransformer with io.gitlab.jfronny.muscript.gson.DynamicGsonTransformer;
}

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.muscript.gson.test;
import io.gitlab.jfronny.commons.serialize.gson.api.v2.GsonHolders;
import io.gitlab.jfronny.muscript.compiler.MuScriptVersion;
import io.gitlab.jfronny.muscript.libs.StandardLib;
import io.gitlab.jfronny.muscript.compiler.Parser;
import io.gitlab.jfronny.muscript.data.Scope;
@ -37,11 +38,11 @@ class JsonTest {
}
private Scope createScope() {
return GsonLib.addTo(StandardLib.createScope());
return GsonLib.addTo(StandardLib.createScope(MuScriptVersion.DEFAULT));
}
private Dynamic execute(String source, String... args) {
return Parser.parse(source)
return Parser.parse(MuScriptVersion.DEFAULT, source)
.asDynamicExpr()
.get(createScope()
.set("args", DFinal.of(Arrays.stream(args).map(DFinal::of).toList()))

View File

@ -6,6 +6,7 @@ plugins {
dependencies {
implementation(project(":commons"))
implementation(project(":commons-logging"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")

View File

@ -1,6 +1,6 @@
package io.gitlab.jfronny.muscript;
import io.gitlab.jfronny.commons.log.Logger;
import io.gitlab.jfronny.commons.logging.Logger;
import io.gitlab.jfronny.muscript.compiler.Decompilable;
public class StarScriptIngester {

View File

@ -25,10 +25,6 @@ public abstract sealed class Expr<T> extends Decompilable
public T get(DObject dataRoot) {
return get(dataRoot instanceof Scope scope ? scope : new Scope(dataRoot));
}
@Deprecated
public T get(Dynamic dataRoot) {
return get(dataRoot.asObject());
}
public abstract Expr<T> optimize();
public BoolExpr asBoolExpr() {
@ -70,46 +66,6 @@ public abstract sealed class Expr<T> extends Decompilable
return literalNull(CodeLocation.NONE);
}
@Deprecated
public static BoolExpr literal(int character, boolean bool) {
return literal(new CodeLocation(character), bool);
}
@Deprecated
public static StringExpr literal(int character, String string) {
return literal(new CodeLocation(character), string);
}
@Deprecated
public static NumberExpr literal(int character, double number) {
return literal(new CodeLocation(character), number);
}
@Deprecated
public static NullLiteral literalNull(int character) {
return literalNull(new CodeLocation(character));
}
@Deprecated
public static BoolExpr literal(int chStart, int chEnd, boolean bool) {
return literal(new CodeLocation(chStart, chEnd), bool);
}
@Deprecated
public static StringExpr literal(int chStart, int chEnd, String string) {
return literal(new CodeLocation(chStart, chEnd), string);
}
@Deprecated
public static NumberExpr literal(int chStart, int chEnd, double number) {
return literal(new CodeLocation(chStart, chEnd), number);
}
@Deprecated
public static NullLiteral literalNull(int chStart, int chEnd) {
return literalNull(new CodeLocation(chStart, chEnd));
}
public static BoolExpr literal(CodeLocation location, boolean bool) {
return new BoolLiteral(location, bool);
}

View File

@ -24,16 +24,6 @@ public class Lexer extends VersionedComponent {
public boolean passedNewline = false;
@Deprecated
public Lexer(String source) {
this(MuScriptVersion.DEFAULT, source);
}
@Deprecated
public Lexer(String source, String file) {
this(MuScriptVersion.DEFAULT, source, file);
}
public Lexer(MuScriptVersion version, String source) {
this(version, source, null);
}

View File

@ -23,31 +23,6 @@ public class Parser extends VersionedComponent {
private final TokenData previous = new TokenData();
private final TokenData current = new TokenData();
@Deprecated
public static Expr<?> parse(String source) {
return parse(MuScriptVersion.DEFAULT, source);
}
@Deprecated
public static Expr<?> parse(String source, String file) {
return parse(MuScriptVersion.DEFAULT, source, file);
}
@Deprecated
public static Script parseScript(String source) {
return parseScript(MuScriptVersion.DEFAULT, source);
}
@Deprecated
public static Script parseScript(String source, String file) {
return parseScript(MuScriptVersion.DEFAULT, source, file);
}
@Deprecated
public static Script parseMultiScript(String startFile, SourceFS filesystem) {
return parseMultiScript(MuScriptVersion.DEFAULT, startFile, filesystem);
}
public static Expr<?> parse(MuScriptVersion version, String source) {
return parse(version, source, null);
}
@ -97,7 +72,7 @@ public class Parser extends VersionedComponent {
src.append(s).append("\n");
}
}
includes.add(parseScript(src.toString(), startFile));
includes.add(parseScript(version, src.toString(), startFile));
return includes;
}

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.muscript.data.dynamic;
import io.gitlab.jfronny.commons.StringFormatter;
import io.gitlab.jfronny.muscript.compiler.MuScriptVersion;
import io.gitlab.jfronny.muscript.libs.StandardLib;
import io.gitlab.jfronny.muscript.ast.DynamicExpr;
import io.gitlab.jfronny.muscript.ast.Expr;
@ -23,9 +24,9 @@ public sealed interface Dynamic permits DBool, DCallable, DList, DNull, DNumber,
* Use Parser.parse() if you truly need to deserialize them, but be aware that that might enable DOS attacks
*/
static Dynamic deserialize(String source) {
DynamicExpr expr = Parser.parse(source).asDynamicExpr();
DynamicExpr expr = Parser.parse(MuScriptVersion.DEFAULT, source).asDynamicExpr();
if (!DirectPreconditionVisitor.visit(expr)) throw new IllegalArgumentException("This expression does not directly express a dynamic and may not be loaded this way");
return expr.get(StandardLib.createScope());
return expr.get(StandardLib.createScope(MuScriptVersion.DEFAULT));
}
static String serialize(Dynamic dynamic) {

View File

@ -48,7 +48,7 @@ public class DFinal {
}
public static DCallable of(Function<DList, ? extends Dynamic> b, Supplier<String> serialized, String name) {
return of(name, b, () -> Parser.parse(serialized.get()));
return of(name, b, () -> Parser.parse(MuScriptVersion.DEFAULT, serialized.get()));
}
public static DCallable of(String name, Function<DList, ? extends Dynamic> b, Supplier<Expr<?>> serialized) {

Some files were not shown because too many files have changed in this diff Show More