Remove apache.commons.io and apache.commons.lang libraries

This commit is contained in:
Lukas Rieger (Blue) 2024-05-28 21:54:14 +02:00
parent e04e46fa5f
commit 0cc0247930
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
22 changed files with 66 additions and 132 deletions

View File

@ -47,7 +47,6 @@
import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.world.World;
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
@ -399,7 +398,7 @@ private synchronized Deque<Path> getPackRoots(Iterable<Path> additionalRoots) th
URL resourceExtensionsUrl = Objects.requireNonNull(
Plugin.class.getResource("/de/bluecolored/bluemap/resourceExtensions.zip")
);
FileUtils.copyURLToFile(resourceExtensionsUrl, resourceExtensionsFile.toFile(), 10000, 10000);
FileHelper.copy(resourceExtensionsUrl, resourceExtensionsFile);
} catch (IOException ex) {
throw new ConfigurationException(
"Failed to create resourceExtensions.zip!\n" +

View File

@ -29,7 +29,6 @@
import de.bluecolored.bluemap.common.config.typeserializer.Vector2iTypeSerializer;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.util.Key;
import org.apache.commons.io.IOUtils;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.loader.AbstractConfigurationLoader;
@ -38,6 +37,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -73,10 +74,15 @@ public <T> T loadConfig(Path file, Class<T> type) throws ConfigurationException
public ConfigTemplate loadConfigTemplate(String name) throws IOException {
String resource = CONFIG_TEMPLATE_RESOURCE_PATH + name + ConfigLoader.DEFAULT.getFileSuffix();
InputStream in = BlueMap.class.getResourceAsStream(resource);
if (in == null) throw new IOException("Resource not found: " + resource);
String configTemplate = IOUtils.toString(in, StandardCharsets.UTF_8);
return new ConfigTemplate(configTemplate);
try (InputStream in = BlueMap.class.getResourceAsStream(resource)) {
if (in == null) throw new IOException("Resource not found: " + resource);
StringWriter writer = new StringWriter();
InputStreamReader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
reader.transferTo(writer);
return new ConfigTemplate(writer.toString());
}
}
public Path resolveConfigFile(String name) {

View File

@ -30,12 +30,13 @@
import de.bluecolored.bluemap.common.plugin.text.TextFormat;
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
import de.bluecolored.bluemap.common.rendermanager.RenderTask;
import org.apache.commons.lang3.time.DurationFormatUtils;
import java.lang.ref.WeakReference;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
public class CommandHelper {
@ -96,7 +97,13 @@ public List<Text> createStatusMessage(){
long etaMs = renderer.estimateCurrentRenderTaskTimeRemaining();
if (etaMs > 0) {
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0ETA: ", TextColor.WHITE, DurationFormatUtils.formatDuration(etaMs, "HH:mm:ss")));
Duration eta = Duration.of(etaMs, ChronoUnit.MILLIS);
String etaString = "%d:%02d:%02d".formatted(
eta.toHours(),
eta.toMinutesPart(),
eta.toSecondsPart()
);
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0ETA: ", TextColor.WHITE, etaString));
}
}
}

View File

@ -29,17 +29,15 @@
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.concurrent.TimeUnit;
@Getter @Setter
@ -114,11 +112,11 @@ private HttpResponse generateResponse(HttpRequest request) throws IOException {
HttpHeader modHeader = request.getHeader("If-Modified-Since");
if (modHeader != null){
try {
long since = stringToTimestamp(modHeader.getValue());
long since = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(modHeader.getValue())).toEpochMilli();
if (since + 1000 >= lastModified){
return new HttpResponse(HttpStatusCode.NOT_MODIFIED);
}
} catch (IllegalArgumentException ignored){}
} catch (DateTimeParseException ignored){}
}
//check ETag
@ -136,7 +134,7 @@ private HttpResponse generateResponse(HttpRequest request) throws IOException {
//create response
HttpResponse response = new HttpResponse(HttpStatusCode.OK);
response.addHeader("ETag", eTag);
if (lastModified > 0) response.addHeader("Last-Modified", timestampToString(lastModified));
if (lastModified > 0) response.addHeader("Last-Modified", DateTimeFormatter.RFC_1123_DATE_TIME.format(Instant.ofEpochMilli(lastModified)));
response.addHeader("Cache-Control", "public");
response.addHeader("Cache-Control", "max-age=" + TimeUnit.DAYS.toSeconds(1));
@ -156,40 +154,6 @@ private HttpResponse generateResponse(HttpRequest request) throws IOException {
}
}
private static String timestampToString(long time){
return DateFormatUtils.format(time, "EEE, dd MMM yyy HH:mm:ss 'GMT'", TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
}
private static long stringToTimestamp(String timeString) throws IllegalArgumentException {
try {
int day = Integer.parseInt(timeString.substring(5, 7));
int month = switch (timeString.substring(8, 11)) {
case "Jan" -> Calendar.JANUARY;
case "Feb" -> Calendar.FEBRUARY;
case "Mar" -> Calendar.MARCH;
case "Apr" -> Calendar.APRIL;
case "May" -> Calendar.MAY;
case "Jun" -> Calendar.JUNE;
case "Jul" -> Calendar.JULY;
case "Aug" -> Calendar.AUGUST;
case "Sep" -> Calendar.SEPTEMBER;
case "Oct" -> Calendar.OCTOBER;
case "Nov" -> Calendar.NOVEMBER;
case "Dec" -> Calendar.DECEMBER;
default -> throw new IllegalArgumentException("Invalid timestamp format");
};
int year = Integer.parseInt(timeString.substring(12, 16));
int hour = Integer.parseInt(timeString.substring(17, 19));
int min = Integer.parseInt(timeString.substring(20, 22));
int sec = Integer.parseInt(timeString.substring(23, 25));
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.set(year, month, day, hour, min, sec);
return cal.getTimeInMillis();
} catch (NumberFormatException | IndexOutOfBoundsException e){
throw new IllegalArgumentException(e);
}
}
private static String toContentType(String fileEnding) {
return switch (fileEnding) {
case "json" -> "application/json";

View File

@ -38,7 +38,6 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.commons.io.IOUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -132,7 +131,7 @@ private void writeToResponse(CompressedInputStream data, HttpResponse response,
response.addHeader("Content-Encoding", Compression.GZIP.getId());
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try (OutputStream os = Compression.GZIP.compress(byteOut)) {
IOUtils.copyLarge(data.decompress(), os);
data.decompress().transferTo(os);
}
byte[] compressedData = byteOut.toByteArray();
response.setData(new ByteArrayInputStream(compressedData));

View File

@ -61,8 +61,6 @@ repositories {
@Suppress("GradlePackageUpdate")
dependencies {
api ("com.github.ben-manes.caffeine:caffeine:3.1.8")
api ("org.apache.commons:commons-lang3:3.6")
api ("commons-io:commons-io:2.5")
api ("org.spongepowered:configurate-hocon:4.1.2")
api ("org.spongepowered:configurate-gson:4.1.2")
api ("de.bluecolored.bluenbt:BlueNBT:2.3.0")

View File

@ -30,7 +30,7 @@
import com.google.gson.stream.JsonToken;
import de.bluecolored.bluemap.core.resources.AbstractTypeAdapterFactory;
import de.bluecolored.bluemap.core.world.BlockState;
import org.apache.commons.lang3.StringUtils;
import lombok.Getter;
import java.io.IOException;
import java.util.ArrayList;
@ -41,14 +41,11 @@
@JsonAdapter(Multipart.Adapter.class)
public class Multipart {
@Getter
private VariantSet[] parts = new VariantSet[0];
private Multipart(){}
public VariantSet[] getParts() {
return parts;
}
public void forEach(BlockState blockState, int x, int y, int z, Consumer<Variant> consumer) {
for (VariantSet part : parts) {
if (part.getCondition().matches(blockState)) {
@ -99,32 +96,32 @@ public BlockStateCondition readCondition(JsonReader in) throws IOException {
in.beginObject();
while (in.hasNext()) {
String name = in.nextName();
if (name.equals(JSON_COMMENT)) {
in.skipValue();
continue;
}
if (name.equals("OR")) {
List<BlockStateCondition> orConditions = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
orConditions.add(readCondition(in));
switch (name) {
case JSON_COMMENT -> in.skipValue();
case "OR" -> {
List<BlockStateCondition> orConditions = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
orConditions.add(readCondition(in));
}
in.endArray();
andConditions.add(
BlockStateCondition.or(orConditions.toArray(new BlockStateCondition[0])));
}
in.endArray();
andConditions.add(
BlockStateCondition.or(orConditions.toArray(new BlockStateCondition[0])));
} else if (name.equals("AND")) {
List<BlockStateCondition> andArray = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
andArray.add(readCondition(in));
case "AND" -> {
List<BlockStateCondition> andArray = new ArrayList<>();
in.beginArray();
while (in.hasNext()) {
andArray.add(readCondition(in));
}
in.endArray();
andConditions.add(
BlockStateCondition.and(andArray.toArray(new BlockStateCondition[0])));
}
default -> {
String[] values = nextStringOrBoolean(in).split("\\|");
andConditions.add(BlockStateCondition.property(name, values));
}
in.endArray();
andConditions.add(
BlockStateCondition.and(andArray.toArray(new BlockStateCondition[0])));
} else {
String[] values = StringUtils.split(nextStringOrBoolean(in), '|');
andConditions.add(BlockStateCondition.property(name, values));
}
}
in.endObject();

View File

@ -30,7 +30,6 @@
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resources.AbstractTypeAdapterFactory;
import de.bluecolored.bluemap.core.world.BlockState;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
@ -111,9 +110,9 @@ private BlockStateCondition parseConditionString(String conditionString) {
List<BlockStateCondition> conditions = new ArrayList<>();
boolean invalid = false;
if (!conditionString.isEmpty() && !conditionString.equals("default") && !conditionString.equals("normal")) {
String[] conditionSplit = StringUtils.split(conditionString, ',');
String[] conditionSplit = conditionString.split(",");
for (String element : conditionSplit) {
String[] keyval = StringUtils.split(element, "=", 2);
String[] keyval = element.split("=", 2);
if (keyval.length < 2) {
Logger.global.logDebug("Failed to parse condition: Condition-String '" + conditionString + "' is invalid!");
invalid = true;

View File

@ -24,7 +24,6 @@ repositories {
dependencies {
api ("de.bluecolored.bluemap:BlueMapCommon")
@Suppress("GradlePackageUpdate")
implementation ("commons-cli:commons-cli:1.5.0")
testImplementation ("org.junit.jupiter:junit-jupiter:5.8.2")
@ -68,23 +67,6 @@ tasks.jar {
tasks.shadowJar {
destinationDirectory.set(file("../../build/release"))
archiveFileName.set("BlueMap-${project.version}-${project.name}.jar")
//relocate ("com.flowpowered.math", "de.bluecolored.shadow.flowpowered.math") //DON"T relocate this, because the API depends on it
relocate ("com.google", "de.bluecolored.shadow.google")
relocate ("com.typesafe", "de.bluecolored.shadow.typesafe")
relocate ("de.bluecolored.bluenbt", "de.bluecolored.shadow.bluenbt")
relocate ("org.spongepowered.configurate", "de.bluecolored.shadow.configurate")
relocate ("com.github.benmanes.caffeine", "de.bluecolored.shadow.benmanes.caffeine")
relocate ("org.aopalliance", "de.bluecolored.shadow.aopalliance")
relocate ("javax.inject", "de.bluecolored.shadow.javax.inject")
relocate ("javax.annotation", "de.bluecolored.shadow.javax.annotation")
relocate ("com.mojang.brigadier", "de.bluecolored.shadow.mojang.brigadier")
relocate ("org.checkerframework", "de.bluecolored.shadow.checkerframework")
relocate ("org.codehaus", "de.bluecolored.shadow.codehaus")
relocate ("io.leangen.geantyref", "de.bluecolored.shadow.geantyref")
relocate ("io.airlift", "de.bluecolored.shadow.airlift")
relocate ("org.apache.commons", "de.bluecolored.shadow.apache.commons")
relocate ("net.jpountz", "de.bluecolored.shadow.jpountz")
}
tasks.register("release") {

View File

@ -47,7 +47,6 @@
import de.bluecolored.bluemap.core.storage.MapStorage;
import de.bluecolored.bluemap.core.util.FileHelper;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
@ -56,9 +55,11 @@
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
@ -136,8 +137,12 @@ public void run() {
String eta = "";
if (etaMs > 0) {
String etrDurationString = DurationFormatUtils.formatDuration(etaMs, "HH:mm:ss");
eta = " (ETA: " + etrDurationString + ")";
Duration duration = Duration.of(etaMs, ChronoUnit.MILLIS);
eta = " (ETA: %d:%02d:%02d)".formatted(
duration.toHours(),
duration.toMinutesPart(),
duration.toSecondsPart()
);
}
Logger.global.logInfo(task.getDescription() + ": " + (Math.round(progress * 100000) / 1000.0) + "%" + eta);
}

View File

@ -45,8 +45,6 @@ dependencies {
//exclude dependencies provided by fabric
exclude (group = "com.google.guava", module = "guava")
exclude (group = "com.google.code.gson", module = "gson")
exclude (group = "org.apache.commons", module = "commons-lang3")
exclude (group = "commons-io", module = "commons-io")
exclude (group = "com.mojang", module = "brigadier")
}

View File

@ -45,8 +45,6 @@ dependencies {
//exclude dependencies provided by fabric
exclude (group = "com.google.guava", module = "guava")
exclude (group = "com.google.code.gson", module = "gson")
exclude (group = "org.apache.commons", module = "commons-lang3")
exclude (group = "commons-io", module = "commons-io")
exclude (group = "com.mojang", module = "brigadier")
}

View File

@ -45,8 +45,6 @@ dependencies {
//exclude dependencies provided by fabric
exclude (group = "com.google.guava", module = "guava")
exclude (group = "com.google.code.gson", module = "gson")
exclude (group = "org.apache.commons", module = "commons-lang3")
exclude (group = "commons-io", module = "commons-io")
exclude (group = "com.mojang", module = "brigadier")
}

View File

@ -68,8 +68,6 @@ dependencies {
//exclude dependencies provided by forge
exclude (group: "com.google.guava", module: "guava")
exclude (group: "com.google.code.gson", module: "gson")
exclude (group: "org.apache.commons", module: "commons-lang3")
exclude (group: "commons-io", module: "commons-io")
exclude (group: "com.mojang", module: "brigadier")
}

View File

@ -67,8 +67,6 @@ dependencies {
//exclude dependencies provided by forge
exclude (group: "com.google.guava", module: "guava")
exclude (group: "com.google.code.gson", module: "gson")
exclude (group: "org.apache.commons", module: "commons-lang3")
exclude (group: "commons-io", module: "commons-io")
exclude (group: "com.mojang", module: "brigadier")
}

View File

@ -67,8 +67,6 @@ dependencies {
//exclude dependencies provided by forge
exclude (group: "com.google.guava", module: "guava")
exclude (group: "com.google.code.gson", module: "gson")
exclude (group: "org.apache.commons", module: "commons-lang3")
exclude (group: "commons-io", module: "commons-io")
exclude (group: "com.mojang", module: "brigadier")
}

View File

@ -36,8 +36,6 @@ dependencies {
//exclude dependencies provided by forge
exclude (group: "com.google.guava", module: "guava")
exclude (group: "com.google.code.gson", module: "gson")
exclude (group: "org.apache.commons", module: "commons-lang3")
exclude (group: "commons-io", module: "commons-io")
exclude (group: "com.mojang", module: "brigadier")
}

View File

@ -98,8 +98,6 @@ tasks.shadowJar {
relocate ("com.google.inject", "de.bluecolored.shadow.google.inject")
relocate ("org.apache.commons.dbcp2", "de.bluecolored.shadow.apache.commons.dbcp2")
relocate ("org.apache.commons.io", "de.bluecolored.shadow.apache.commons.io")
relocate ("org.apache.commons.lang3", "de.bluecolored.shadow.apache.commons.lang3")
relocate ("org.apache.commons.logging", "de.bluecolored.shadow.apache.commons.logging")
relocate ("org.apache.commons.pool2", "de.bluecolored.shadow.apache.commons.pool2")
}

View File

@ -33,7 +33,6 @@
import de.bluecolored.bluemap.common.plugin.commands.Commands;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.RemoteConsoleCommandSender;
@ -123,7 +122,7 @@ protected CommandProxy(String name) {
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, String[] args) {
String command = commandLabel;
if (args.length > 0) {
command += " " + StringUtils.join(args, ' ');
command += " " + String.join(" ", args);
}
try {

View File

@ -101,8 +101,6 @@ tasks.shadowJar {
relocate ("com.google.inject", "de.bluecolored.shadow.google.inject")
relocate ("org.apache.commons.dbcp2", "de.bluecolored.shadow.apache.commons.dbcp2")
relocate ("org.apache.commons.io", "de.bluecolored.shadow.apache.commons.io")
relocate ("org.apache.commons.lang3", "de.bluecolored.shadow.apache.commons.lang3")
relocate ("org.apache.commons.logging", "de.bluecolored.shadow.apache.commons.logging")
relocate ("org.apache.commons.pool2", "de.bluecolored.shadow.apache.commons.pool2")
}

View File

@ -31,7 +31,6 @@
import com.mojang.brigadier.tree.CommandNode;
import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.plugin.commands.Commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -121,7 +120,7 @@ protected CommandProxy(String name) {
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
String command = commandLabel;
if (args.length > 0) {
command += " " + StringUtils.join(args, ' ');
command += " " + String.join(" ", args);
}
try {

View File

@ -31,7 +31,6 @@ dependencies {
//exclude dependencies provided by sponge
exclude( group = "com.google.guava", module = "guava" )
exclude( group = "com.google.code.gson", module = "gson" )
exclude( group = "org.apache.commons", module = "commons-lang3" )
exclude( group = "javax.inject" )
exclude( group = "com.google.inject" )
}
@ -119,7 +118,6 @@ tasks.shadowJar {
relocate ("net.jpountz", "de.bluecolored.shadow.jpountz")
relocate ("org.apache.commons.dbcp2", "de.bluecolored.shadow.apache.commons.dbcp2")
relocate ("org.apache.commons.io", "de.bluecolored.shadow.apache.commons.io")
relocate ("org.apache.commons.logging", "de.bluecolored.shadow.apache.commons.logging")
relocate ("org.apache.commons.pool2", "de.bluecolored.shadow.apache.commons.pool2")
}