From ff869b52d4aae33036e71a54cb5bb70f005ab1cd Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 4 Jul 2025 07:52:51 +0000 Subject: [PATCH] Cleanup --- .../impl/ConnectionAddExchangeImpl.java | 2 +- .../xpipe/app/ext}/ValidationException.java | 2 +- .../app/hub/comp/StoreCreationModel.java | 2 +- .../io/xpipe/app/icon/SystemIconManager.java | 2 +- .../io/xpipe/app/icon/SystemIconSource.java | 2 +- .../app/util/SecretRetrievalStrategy.java | 2 +- .../java/io/xpipe/app/util/Validators.java | 2 +- .../io/xpipe/core/util/CoreJacksonModule.java | 19 ----- .../java/io/xpipe/core/util/Identifiers.java | 22 ------ .../io/xpipe/core/util/StreamCharset.java | 77 ++++--------------- .../ext/base/identity/IdentityValue.java | 2 +- .../base/identity/SshIdentityStrategy.java | 2 +- .../base/identity/SyncedIdentityStore.java | 2 +- .../ext/base/script/SimpleScriptStore.java | 2 +- 14 files changed, 26 insertions(+), 114 deletions(-) rename {core/src/main/java/io/xpipe/core/util => app/src/main/java/io/xpipe/app/ext}/ValidationException.java (81%) delete mode 100644 core/src/main/java/io/xpipe/core/util/Identifiers.java diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionAddExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionAddExchangeImpl.java index 0ab17b7b6..dcc322a6c 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionAddExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/ConnectionAddExchangeImpl.java @@ -5,7 +5,7 @@ import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.beacon.BeaconClientException; import io.xpipe.beacon.api.ConnectionAddExchange; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.sun.net.httpserver.HttpExchange; diff --git a/core/src/main/java/io/xpipe/core/util/ValidationException.java b/app/src/main/java/io/xpipe/app/ext/ValidationException.java similarity index 81% rename from core/src/main/java/io/xpipe/core/util/ValidationException.java rename to app/src/main/java/io/xpipe/app/ext/ValidationException.java index a94ab39d4..e347e77be 100644 --- a/core/src/main/java/io/xpipe/core/util/ValidationException.java +++ b/app/src/main/java/io/xpipe/app/ext/ValidationException.java @@ -1,4 +1,4 @@ -package io.xpipe.core.util; +package io.xpipe.app.ext; import lombok.experimental.StandardException; diff --git a/app/src/main/java/io/xpipe/app/hub/comp/StoreCreationModel.java b/app/src/main/java/io/xpipe/app/hub/comp/StoreCreationModel.java index f84d6668c..799084f5f 100644 --- a/app/src/main/java/io/xpipe/app/hub/comp/StoreCreationModel.java +++ b/app/src/main/java/io/xpipe/app/hub/comp/StoreCreationModel.java @@ -11,7 +11,7 @@ import io.xpipe.app.util.*; import io.xpipe.core.process.ShellTtyState; import io.xpipe.core.store.DataStore; import io.xpipe.core.store.ValidatableStore; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import javafx.application.Platform; import javafx.beans.binding.Bindings; diff --git a/app/src/main/java/io/xpipe/app/icon/SystemIconManager.java b/app/src/main/java/io/xpipe/app/icon/SystemIconManager.java index c443ce4f4..feacf7038 100644 --- a/app/src/main/java/io/xpipe/app/icon/SystemIconManager.java +++ b/app/src/main/java/io/xpipe/app/icon/SystemIconManager.java @@ -7,7 +7,7 @@ import io.xpipe.app.issue.ErrorEventFactory; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.SupportedLocale; import io.xpipe.app.storage.DataStorage; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/app/src/main/java/io/xpipe/app/icon/SystemIconSource.java b/app/src/main/java/io/xpipe/app/icon/SystemIconSource.java index 02ab0bfcc..3c25dfe74 100644 --- a/app/src/main/java/io/xpipe/app/icon/SystemIconSource.java +++ b/app/src/main/java/io/xpipe/app/icon/SystemIconSource.java @@ -8,7 +8,7 @@ import io.xpipe.app.util.Validators; import io.xpipe.core.process.CommandBuilder; import io.xpipe.core.store.FilePath; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/app/src/main/java/io/xpipe/app/util/SecretRetrievalStrategy.java b/app/src/main/java/io/xpipe/app/util/SecretRetrievalStrategy.java index dce245655..6c4d7a4ef 100644 --- a/app/src/main/java/io/xpipe/app/util/SecretRetrievalStrategy.java +++ b/app/src/main/java/io/xpipe/app/util/SecretRetrievalStrategy.java @@ -4,7 +4,7 @@ import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.ErrorEventFactory; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.core.util.InPlaceSecretValue; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/app/src/main/java/io/xpipe/app/util/Validators.java b/app/src/main/java/io/xpipe/app/util/Validators.java index 2f761eab0..0e0d42182 100644 --- a/app/src/main/java/io/xpipe/app/util/Validators.java +++ b/app/src/main/java/io/xpipe/app/util/Validators.java @@ -3,7 +3,7 @@ package io.xpipe.app.util; import io.xpipe.app.core.AppI18n; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.core.store.DataStore; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import java.util.List; diff --git a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java index 2076e37b3..ad7e546e3 100644 --- a/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java +++ b/core/src/main/java/io/xpipe/core/util/CoreJacksonModule.java @@ -44,9 +44,6 @@ public class CoreJacksonModule extends SimpleModule { addSerializer(ShellDialect.class, new ShellDialectSerializer()); addDeserializer(ShellDialect.class, new ShellDialectDeserializer()); - addSerializer(StreamCharset.class, new StreamCharsetSerializer()); - addDeserializer(StreamCharset.class, new StreamCharsetDeserializer()); - addSerializer(NewLine.class, new NewLineSerializer()); addDeserializer(NewLine.class, new NewLineDeserializer()); @@ -175,22 +172,6 @@ public class CoreJacksonModule extends SimpleModule { } } - public static class StreamCharsetSerializer extends JsonSerializer { - - @Override - public void serialize(StreamCharset value, JsonGenerator jgen, SerializerProvider provider) throws IOException { - jgen.writeString(value.toString()); - } - } - - public static class StreamCharsetDeserializer extends JsonDeserializer { - - @Override - public StreamCharset deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - return StreamCharset.get(p.getValueAsString()); - } - } - public static class LocalPathSerializer extends JsonSerializer { @Override diff --git a/core/src/main/java/io/xpipe/core/util/Identifiers.java b/core/src/main/java/io/xpipe/core/util/Identifiers.java deleted file mode 100644 index a1d1a2166..000000000 --- a/core/src/main/java/io/xpipe/core/util/Identifiers.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.xpipe.core.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class Identifiers { - - @SafeVarargs - public static List join(List... s) { - return Arrays.stream(s).flatMap(Collection::stream).toList(); - } - - public static List get(String... s) { - return nameAlternatives(Arrays.asList(s)); - } - - private static List nameAlternatives(List split) { - return List.of( - String.join("", split), String.join(" ", split), String.join("_", split), String.join("-", split)); - } -} diff --git a/core/src/main/java/io/xpipe/core/util/StreamCharset.java b/core/src/main/java/io/xpipe/core/util/StreamCharset.java index 657b1e43b..010a185b9 100644 --- a/core/src/main/java/io/xpipe/core/util/StreamCharset.java +++ b/core/src/main/java/io/xpipe/core/util/StreamCharset.java @@ -17,32 +17,29 @@ import java.util.stream.Stream; public class StreamCharset { public static final StreamCharset UTF8 = - new StreamCharset(StandardCharsets.UTF_8, null, Identifiers.get("utf", "8")); + new StreamCharset(StandardCharsets.UTF_8, null); public static final StreamCharset UTF8_BOM = new StreamCharset( StandardCharsets.UTF_8, - new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}, - Identifiers.get("utf", "8", "bom")); + new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}); // ====== // UTF-16 // ====== public static final StreamCharset UTF16_BE = - new StreamCharset(StandardCharsets.UTF_16BE, null, Identifiers.get("utf", "16", "be")); + new StreamCharset(StandardCharsets.UTF_16BE, null); public static final StreamCharset UTF16_BE_BOM = new StreamCharset( StandardCharsets.UTF_16BE, - new byte[] {(byte) 0xFE, (byte) 0xFF}, - Identifiers.get("utf", "16", "be", "bom")); + new byte[] {(byte) 0xFE, (byte) 0xFF}); public static final StreamCharset UTF16_LE = - new StreamCharset(StandardCharsets.UTF_16LE, null, Identifiers.get("utf", "16", "le")); + new StreamCharset(StandardCharsets.UTF_16LE, null); public static final StreamCharset UTF16_LE_BOM = new StreamCharset( StandardCharsets.UTF_16LE, - new byte[] {(byte) 0xFF, (byte) 0xFE}, - Identifiers.get("utf", "16", "le", "bom")); + new byte[] {(byte) 0xFF, (byte) 0xFE}); public static final StreamCharset UTF16 = UTF16_LE; @@ -55,69 +52,40 @@ public class StreamCharset { UTF16_BOM, new StreamCharset( StandardCharsets.US_ASCII, - null, - Identifiers.join(Identifiers.get("ascii"), Identifiers.get("us", "ascii"))), + null), new StreamCharset( StandardCharsets.ISO_8859_1, - null, - Identifiers.join( - Identifiers.get("iso", "8859"), - Identifiers.get("iso", "8859", "1"), - Identifiers.get("8859"), - Identifiers.get("8859", "1"))), + null), new StreamCharset( Charset.forName("Windows-1251"), - null, - Identifiers.join(Identifiers.get("windows", "1251"), Identifiers.get("1251"))), + null), new StreamCharset( Charset.forName("Windows-1252"), - null, - Identifiers.join(Identifiers.get("windows", "1252"), Identifiers.get("1252")))); + null)); // ====== // UTF-32 // ====== public static final StreamCharset UTF32_LE = - new StreamCharset(Charset.forName("utf-32le"), null, Identifiers.get("utf", "32", "le")); + new StreamCharset(Charset.forName("utf-32le"), null); public static final StreamCharset UTF32_LE_BOM = new StreamCharset( Charset.forName("utf-32le"), - new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF}, - Identifiers.get("utf", "32", "le", "bom")); + new byte[] {0x00, 0x00, (byte) 0xFE, (byte) 0xFF}); public static final StreamCharset UTF32_BE = - new StreamCharset(Charset.forName("utf-32be"), null, Identifiers.get("utf", "32", "be")); + new StreamCharset(Charset.forName("utf-32be"), null); public static final StreamCharset UTF32_BE_BOM = new StreamCharset( Charset.forName("utf-32be"), new byte[] { (byte) 0xFF, (byte) 0xFE, 0x00, 0x00, - }, - Identifiers.get("utf", "32", "be", "bom")); - private static final List RARE_NAMED = + }); + private static final List RARE = List.of(UTF16_LE, UTF16_LE_BOM, UTF16_BE, UTF16_BE_BOM, UTF32_LE, UTF32_LE_BOM, UTF32_BE, UTF32_BE_BOM); - public static final List RARE = Stream.concat( - RARE_NAMED.stream(), - Charset.availableCharsets().values().stream() - .filter(charset -> !charset.equals(StandardCharsets.UTF_16) - && !charset.equals(Charset.forName("utf-32")) - && !charset.displayName().startsWith("x-") - && !charset.displayName().startsWith("X-") - && !charset.displayName().endsWith("-BOM") - && COMMON.stream() - .noneMatch(c -> c.getCharset().equals(charset)) - && RARE_NAMED.stream() - .noneMatch(c -> c.getCharset().equals(charset))) - .map(charset -> new StreamCharset( - charset, - null, - Identifiers.get(charset.name().split("-"))))) - .toList(); - public static final List ALL = Stream.concat(COMMON.stream(), RARE.stream()).toList(); Charset charset; byte[] byteOrderMark; - List names; public static StreamCharset get(Charset charset, boolean byteOrderMark) { return ALL.stream() @@ -127,17 +95,6 @@ public class StreamCharset { .orElseThrow(); } - public static StreamCharset get(String s) { - var found = ALL.stream() - .filter(streamCharset -> streamCharset.getNames().contains(s.toLowerCase(Locale.ROOT))) - .findFirst(); - if (found.isEmpty()) { - throw new IllegalArgumentException("Unknown charset name: " + s); - } - - return found.get(); - } - public static InputStreamReader detectedReader(InputStream inputStream) throws Exception { StreamCharset detected = null; for (var charset : StreamCharset.COMMON) { @@ -215,10 +172,6 @@ public class StreamCharset { return charset.equals(that.charset) && Arrays.equals(byteOrderMark, that.byteOrderMark); } - public String toString() { - return getNames().getFirst(); - } - public boolean hasByteOrderMark() { return byteOrderMark != null; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentityValue.java b/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentityValue.java index 976c97981..1f4add993 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentityValue.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentityValue.java @@ -7,7 +7,7 @@ import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.EncryptedValue; import io.xpipe.app.util.SecretRetrievalStrategy; import io.xpipe.app.util.Validators; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/identity/SshIdentityStrategy.java b/ext/base/src/main/java/io/xpipe/ext/base/identity/SshIdentityStrategy.java index ec698e41a..67d8b9f35 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/identity/SshIdentityStrategy.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/identity/SshIdentityStrategy.java @@ -9,7 +9,7 @@ import io.xpipe.core.process.*; import io.xpipe.core.store.FilePath; import io.xpipe.core.util.KeyValue; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/identity/SyncedIdentityStore.java b/ext/base/src/main/java/io/xpipe/ext/base/identity/SyncedIdentityStore.java index 1f47c3564..f64b60331 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/identity/SyncedIdentityStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/identity/SyncedIdentityStore.java @@ -3,7 +3,7 @@ package io.xpipe.ext.base.identity; import io.xpipe.app.ext.UserScopeStore; import io.xpipe.app.util.EncryptedValue; import io.xpipe.app.util.SecretRetrievalStrategy; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.EqualsAndHashCode; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/SimpleScriptStore.java b/ext/base/src/main/java/io/xpipe/ext/base/script/SimpleScriptStore.java index 25d255a1a..18d65ad19 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/SimpleScriptStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/SimpleScriptStore.java @@ -6,7 +6,7 @@ import io.xpipe.app.util.ScriptHelper; import io.xpipe.app.util.Validators; import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellDialect; -import io.xpipe.core.util.ValidationException; +import io.xpipe.app.ext.ValidationException; import io.xpipe.app.ext.SelfReferentialStore; import com.fasterxml.jackson.annotation.JsonTypeName;