Skip to content

Commit

Permalink
refactor: use more logger
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Jun 21, 2024
1 parent 28c3ac4 commit e1784ba
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 177 deletions.
2 changes: 1 addition & 1 deletion java21/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
implementation("org.slf4j:slf4j-api:$slf4jVersion")
implementation("org.jetbrains:annotations:$jbAnnotationsVersion")
implementation("org.spongepowered:mixin:$mixinVersion")
implementation("org.leavesmc.leaves:leaves-api:$leavesApiVersion")
// implementation("org.leavesmc.leaves:leaves-api:$leavesApiVersion")
implementation("io.sigpipe:jbsdiff:1.0")
}

Expand Down
2 changes: 1 addition & 1 deletion java21/src/main/java/launchwrapper/IClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public interface IClassTransformer {
/**
* Transforms class
*
* <p>
* Note that class names are using dots instead of slashes.
*
* @param name Class unmapped name
Expand Down
1 change: 1 addition & 0 deletions java21/src/main/java/launchwrapper/ITweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ default void acceptOptions(@NotNull List<String> args) {
* @param profile unknown
* @deprecated This method is not used internally. See {@link ITweaker#acceptOptions(List)}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
default void acceptOptions(@NotNull List<String> args, File gameDir, final File assetsDir, String profile) {
throw new IllegalStateException("Please implement this method.");
Expand Down
154 changes: 0 additions & 154 deletions java21/src/main/java/launchwrapper/Launch.java

This file was deleted.

3 changes: 2 additions & 1 deletion java21/src/main/java/launchwrapper/LaunchClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class LaunchClassLoader extends URLClassLoader {
private final Set<String> classLoaderExceptions = new HashSet<>();
private final Set<String> transformerExceptions = new HashSet<>();
private final Map<String, byte[]> resourceCache = new ConcurrentHashMap<>(1000);
private final Set<String> negativeResourceCache = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
private final Set<String> negativeResourceCache = Collections.newSetFromMap(new ConcurrentHashMap<>());

@Nullable
private IClassNameTransformer renameTransformer = null;
Expand All @@ -91,6 +91,7 @@ public class LaunchClassLoader extends URLClassLoader {
private static final boolean DEBUG_SAVE = DEBUG && Boolean.getBoolean("legacy.debugClassLoadingSave");
private static final Path DUMP_PATH = Paths.get(System.getProperty("legacy.classDumpPath", "./.classloader.out"));

@SuppressWarnings("CommentedOutCode")
public LaunchClassLoader(URL[] sources, ClassLoader parent) {
super(sources, null);
this.parent = parent;
Expand Down
14 changes: 9 additions & 5 deletions java21/src/main/java/org/leavesmc/leavesclip/AutoUpdate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.leavesmc.leavesclip;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.Arrays;
import java.util.zip.ZipEntry;
Expand All @@ -10,6 +13,7 @@ public class AutoUpdate {
public static String autoUpdateCorePath;
public static String autoUpdateDir = "auto_update";
public static boolean useAutoUpdateJar = false;
private static final Logger logger = LoggerFactory.getLogger("AutoUpdate");

public static void init() {
File workingDirFile = new File(autoUpdateDir);
Expand All @@ -32,21 +36,21 @@ public static void init() {
autoUpdateCorePath = firstLine;
File jarFile = new File(autoUpdateCorePath);
if (!jarFile.isFile() || !jarFile.exists()) {
System.out.println("The specified server core: " + autoUpdateCorePath + " does not exist. Using the original jar!");
logger.warn("The specified server core: {} does not exist. Using the original jar!", autoUpdateCorePath);
return;
}

useAutoUpdateJar = true;

if (!detectionLeavesclipVersion(autoUpdateCorePath)) {
System.out.println("Leavesclip version detection in server core: " + autoUpdateCorePath + " failed. Using the original jar!");
logger.warn("Leavesclip version detection in server core: {} failed. Using the original jar!", autoUpdateCorePath);
useAutoUpdateJar = false;
return;
}

System.out.println("Using server core: " + autoUpdateCorePath + " provide by Leavesclip-Auto-Update");
logger.info("Using server core: {} provide by Leavesclip-Auto-Update", autoUpdateCorePath);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getLocalizedMessage(), e);
}
}

Expand Down Expand Up @@ -98,7 +102,7 @@ public static InputStream getResourceAsStream(String jarPath, String name) {
throw new IOException(name + " not found in our jar or in the " + jarPath);
}
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getLocalizedMessage(), e);
}
return result;
}
Expand Down
33 changes: 18 additions & 15 deletions java21/src/main/java/org/leavesmc/leavesclip/Leavesclip.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
Expand Down Expand Up @@ -141,26 +139,31 @@ private Leavesclip(final String[] args) {
final String mainClassName = findMainClass();
logger.info("Starting {}", mainClassName);

final Thread runThread = new Thread(() -> {
try {
argumentList.addAll(Arrays.asList(args));
final Class<?> mainClass = Class.forName(mainClassName, true, classLoader);
final MethodHandle mainHandle = MethodHandles.lookup()
.findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class))
.asFixedArity();
mainHandle.invoke((Object) argumentList.toArray(new String[0]));
} catch (final Throwable t) {
throw Util.sneakyThrow(t);
}
}, "ServerMain");
runThread.setContextClassLoader(classLoader);
final Thread runThread = getServerMainThread(args, argumentList, mainClassName);
runThread.start();
} catch (Exception e) {
logger.error("Unable to launch", e);
System.exit(1);
}
}

private static @NotNull Thread getServerMainThread(String[] args, List<String> argumentList, String mainClassName) {
final Thread runThread = new Thread(() -> {
try {
argumentList.addAll(Arrays.asList(args));
final Class<?> mainClass = Class.forName(mainClassName, true, classLoader);
final MethodHandle mainHandle = MethodHandles.lookup()
.findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class))
.asFixedArity();
mainHandle.invoke((Object) argumentList.toArray(new String[0]));
} catch (final Throwable t) {
throw Util.sneakyThrow(t);
}
}, "ServerMain");
runThread.setContextClassLoader(classLoader);
return runThread;
}

private void configureMixin() {
MixinEnvironment.getDefaultEnvironment().setSide(MixinEnvironment.Side.SERVER);
Mixins.addConfiguration("mixins.akarin.core.json");
Expand Down

0 comments on commit e1784ba

Please sign in to comment.