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