Java 16 update
parent
24455d2e5c
commit
adc14273d0
|
@ -3,8 +3,8 @@ plugins {
|
|||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = "${project.mod_version}-${getMcMinor(project.minecraft_version)}"
|
||||
|
|
|
@ -59,9 +59,10 @@ public class TextileBackup implements ModInitializer {
|
|||
if(Statics.CONFIG.format == ConfigHandler.ArchiveFormat.ZIP) {
|
||||
Statics.tmpAvailable = Utilities.isTmpAvailable();
|
||||
if(!Statics.tmpAvailable) {
|
||||
Statics.LOGGER.warn("WARNING! It seems like the temporary folder is not accessible on this system!\n" +
|
||||
"This will cause problems with multithreaded zip compression, so a normal one will be used instead.\n" +
|
||||
"For more info please read: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
|
||||
Statics.LOGGER.warn("""
|
||||
WARNING! It seems like the temporary folder is not accessible on this system!
|
||||
This will cause problems with multithreaded zip compression, so a normal one will be used instead.
|
||||
For more info please read: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems""");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,11 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||
import net.szum123321.textile_backup.core.ActionInitiator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BackupContext {
|
||||
private final MinecraftServer server;
|
||||
private final ServerCommandSource commandSource;
|
||||
private final ActionInitiator initiator;
|
||||
private final boolean save;
|
||||
private final String comment;
|
||||
|
||||
protected BackupContext(@NotNull MinecraftServer server, ServerCommandSource commandSource, @NotNull ActionInitiator initiator, boolean save, String comment) {
|
||||
public record BackupContext(MinecraftServer server,
|
||||
ServerCommandSource commandSource,
|
||||
ActionInitiator initiator, boolean save,
|
||||
String comment) {
|
||||
public BackupContext(@NotNull MinecraftServer server, ServerCommandSource commandSource, @NotNull ActionInitiator initiator, boolean save, String comment) {
|
||||
this.server = server;
|
||||
this.commandSource = commandSource;
|
||||
this.initiator = initiator;
|
||||
|
@ -117,14 +114,14 @@ public class BackupContext {
|
|||
}
|
||||
|
||||
public BackupContext build() {
|
||||
if(guessInitiator) {
|
||||
if (guessInitiator) {
|
||||
initiator = commandSource.getEntity() instanceof PlayerEntity ? ActionInitiator.Player : ActionInitiator.ServerConsole;
|
||||
} else if(initiator == null) {
|
||||
} else if (initiator == null) {
|
||||
initiator = ActionInitiator.Null;
|
||||
}
|
||||
|
||||
if(server == null) {
|
||||
if(commandSource != null)
|
||||
if (server == null) {
|
||||
if (commandSource != null)
|
||||
setServer(commandSource.getMinecraftServer());
|
||||
else
|
||||
throw new RuntimeException("Both MinecraftServer and ServerCommandSource weren't provided!");
|
||||
|
|
|
@ -23,9 +23,10 @@ import net.szum123321.textile_backup.core.ActionInitiator;
|
|||
import net.szum123321.textile_backup.core.create.compressors.*;
|
||||
import net.szum123321.textile_backup.core.Utilities;
|
||||
import net.szum123321.textile_backup.core.create.compressors.tar.AbstractTarArchiver;
|
||||
import net.szum123321.textile_backup.core.create.compressors.tar.LZMACompressor;
|
||||
import net.szum123321.textile_backup.core.create.compressors.tar.ParallelBZip2Compressor;
|
||||
import net.szum123321.textile_backup.core.create.compressors.tar.ParallelGzipCompressor;
|
||||
import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@ -81,42 +82,26 @@ public class MakeBackupRunnable implements Runnable {
|
|||
Statics.LOGGER.trace("Running compression on {} threads. Available cores: {}", coreCount, Runtime.getRuntime().availableProcessors());
|
||||
|
||||
switch (Statics.CONFIG.format) {
|
||||
case ZIP: {
|
||||
if(Statics.tmpAvailable && coreCount > 1)
|
||||
case ZIP -> {
|
||||
if (Statics.tmpAvailable && coreCount > 1)
|
||||
ParallelZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
else
|
||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
}
|
||||
|
||||
case BZIP2:
|
||||
ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
|
||||
case GZIP:
|
||||
ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
|
||||
case LZMA:
|
||||
LZMACompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
|
||||
case TAR:
|
||||
new AbstractTarArchiver() {
|
||||
protected OutputStream getCompressorOutputStream(OutputStream stream, BackupContext ctx, int coreLimit) {
|
||||
return stream;
|
||||
}
|
||||
}.createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
|
||||
default:
|
||||
case BZIP2 -> ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
case GZIP -> ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
case LZMA -> new AbstractTarArchiver() {
|
||||
protected OutputStream getCompressorOutputStream(OutputStream stream, BackupContext ctx, int coreLimit) throws IOException {
|
||||
return new LZMACompressorOutputStream(stream);
|
||||
}
|
||||
}.createArchive(world, outFile, context, coreCount);
|
||||
case TAR -> new AbstractTarArchiver().createArchive(world, outFile, context, coreCount);
|
||||
default -> {
|
||||
Statics.LOGGER.warn("Specified compressor ({}) is not supported! Zip will be used instead!", Statics.CONFIG.format);
|
||||
|
||||
if(context.getInitiator() == ActionInitiator.Player)
|
||||
if (context.getInitiator() == ActionInitiator.Player)
|
||||
Statics.LOGGER.sendError(context.getCommandSource(), "Error! No correct compression format specified! Using default compressor!");
|
||||
|
||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BackupHelper.executeFileLimit(context.getCommandSource(), Utilities.getLevelName(context.getServer()));
|
||||
|
|
|
@ -106,17 +106,11 @@ public class ParallelZipCompressor extends ZipCompressor {
|
|||
}
|
||||
}
|
||||
|
||||
private static class SimpleStackTraceElement {
|
||||
private final String className;
|
||||
private final String methodName;
|
||||
private final boolean isNative;
|
||||
|
||||
public SimpleStackTraceElement(String className, String methodName, boolean isNative) {
|
||||
this.className = className;
|
||||
this.methodName = methodName;
|
||||
this.isNative = isNative;
|
||||
}
|
||||
|
||||
private static record SimpleStackTraceElement (
|
||||
String className,
|
||||
String methodName,
|
||||
boolean isNative
|
||||
) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -131,13 +125,7 @@ public class ParallelZipCompressor extends ZipCompressor {
|
|||
}
|
||||
}
|
||||
|
||||
static class FileInputStreamSupplier implements InputStreamSupplier {
|
||||
private final File sourceFile;
|
||||
|
||||
FileInputStreamSupplier(File sourceFile) {
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
|
||||
record FileInputStreamSupplier(File sourceFile) implements InputStreamSupplier {
|
||||
public InputStream get() {
|
||||
try {
|
||||
return new FileInputStream(sourceFile);
|
||||
|
|
|
@ -29,9 +29,10 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class AbstractTarArchiver extends AbstractCompressor {
|
||||
|
||||
protected abstract OutputStream getCompressorOutputStream(OutputStream stream, BackupContext ctx, int coreLimit) throws IOException;
|
||||
public class AbstractTarArchiver extends AbstractCompressor {
|
||||
protected OutputStream getCompressorOutputStream(OutputStream stream, BackupContext ctx, int coreLimit) throws IOException {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OutputStream createArchiveOutputStream(OutputStream stream, BackupContext ctx, int coreLimit) throws IOException {
|
||||
|
|
|
@ -25,14 +25,10 @@ import net.szum123321.textile_backup.core.ActionInitiator;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RestoreContext {
|
||||
private final RestoreHelper.RestoreableFile file;
|
||||
private final MinecraftServer server;
|
||||
@Nullable
|
||||
private final String comment;
|
||||
private final ActionInitiator initiator;
|
||||
private final ServerCommandSource commandSource;
|
||||
|
||||
public record RestoreContext(RestoreHelper.RestoreableFile file,
|
||||
MinecraftServer server, @Nullable String comment,
|
||||
ActionInitiator initiator,
|
||||
ServerCommandSource commandSource) {
|
||||
public RestoreContext(RestoreHelper.RestoreableFile file, MinecraftServer server, @Nullable String comment, ActionInitiator initiator, ServerCommandSource commandSource) {
|
||||
this.file = file;
|
||||
this.server = server;
|
||||
|
@ -96,7 +92,7 @@ public class RestoreContext {
|
|||
}
|
||||
|
||||
public RestoreContext build() {
|
||||
if(server == null) server = serverCommandSource.getMinecraftServer();
|
||||
if (server == null) server = serverCommandSource.getMinecraftServer();
|
||||
|
||||
ActionInitiator initiator = serverCommandSource.getEntity() instanceof PlayerEntity ? ActionInitiator.Player : ActionInitiator.ServerConsole;
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.io.File;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class RestoreHelper {
|
||||
public static Optional<RestoreableFile> findFileAndLockIfPresent(LocalDateTime backupTime, MinecraftServer server) {
|
||||
|
@ -42,7 +41,7 @@ public class RestoreHelper {
|
|||
|
||||
Optional<RestoreableFile> optionalFile = Arrays.stream(root.listFiles())
|
||||
.map(RestoreableFile::newInstance)
|
||||
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
|
||||
.flatMap(Optional::stream)
|
||||
.filter(rf -> rf.getCreationTime().equals(backupTime))
|
||||
.findFirst();
|
||||
|
||||
|
@ -95,7 +94,7 @@ public class RestoreHelper {
|
|||
return Arrays.stream(root.listFiles())
|
||||
.filter(Utilities::isValidBackup)
|
||||
.map(RestoreableFile::newInstance)
|
||||
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
|
||||
.flatMap(Optional::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
"depends": {
|
||||
"fabricloader": ">=0.11",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.17.*"
|
||||
"minecraft": "1.17.*",
|
||||
"java": ">=16"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"required": true,
|
||||
"package": "net.szum123321.textile_backup.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"MinecraftServerMixin",
|
||||
"MinecraftServerSessionAccessor"
|
||||
|
|
Loading…
Reference in New Issue