From f4518a05b50adcb34f583fea8a633df8a19ab0ba Mon Sep 17 00:00:00 2001 From: Markus Frohme Date: Thu, 13 Jun 2024 19:10:02 +0200 Subject: [PATCH] Replace xstream with fury (#127) * initial fury transition * switch to fury nightly * use new module names * switch to stable release * remove rebase artifact * bump version --- algorithms/active/lstar/pom.xml | 26 ----------------- algorithms/active/pom.xml | 22 --------------- examples/pom.xml | 13 ++++----- .../example/resumable/ResumableExample.java | 24 ++++------------ examples/src/main/java/module-info.java | 2 +- filters/cache/pom.xml | 28 ------------------- pom.xml | 10 +++---- test-support/test-support/pom.xml | 9 +++--- .../de/learnlib/testsupport/ResumeUtils.java | 15 +++++----- .../src/main/java/module-info.java | 2 +- 10 files changed, 29 insertions(+), 122 deletions(-) diff --git a/algorithms/active/lstar/pom.xml b/algorithms/active/lstar/pom.xml index 8abc9c786b..ab2875e2ac 100644 --- a/algorithms/active/lstar/pom.xml +++ b/algorithms/active/lstar/pom.xml @@ -140,30 +140,4 @@ limitations under the License. - - - - fix-xstream - - [16,) - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - @{argLine} - --add-reads=de.learnlib.algorithm.lstar=net.automatalib.util - --add-opens=java.base/java.util=ALL-UNNAMED - - - - - - - - diff --git a/algorithms/active/pom.xml b/algorithms/active/pom.xml index 87b61011f0..93331ea134 100644 --- a/algorithms/active/pom.xml +++ b/algorithms/active/pom.xml @@ -45,26 +45,4 @@ limitations under the License. ttt ttt-vpa - - - - fix-xstream - - [16,) - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - @{argLine} --add-opens=java.base/java.util=ALL-UNNAMED - - - - - - - diff --git a/examples/pom.xml b/examples/pom.xml index a04f707b26..fc2fba4faa 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -111,6 +111,12 @@ limitations under the License. de.learnlib learnlib-statistics + + de.learnlib.testsupport + learnlib-test-support + compile + + de.learnlib learnlib-ttt @@ -127,11 +133,6 @@ limitations under the License. runtime - - com.thoughtworks.xstream - xstream - - net.automatalib automata-api @@ -200,8 +201,6 @@ limitations under the License. com.github.caciocavallosilano.cacio.ctc.CTCGraphicsEnvironment false - - @{argLine} --add-opens=java.base/java.util=xstream diff --git a/examples/src/main/java/de/learnlib/example/resumable/ResumableExample.java b/examples/src/main/java/de/learnlib/example/resumable/ResumableExample.java index 0a5ffb8103..4b6ac70c58 100644 --- a/examples/src/main/java/de/learnlib/example/resumable/ResumableExample.java +++ b/examples/src/main/java/de/learnlib/example/resumable/ResumableExample.java @@ -15,10 +15,8 @@ */ package de.learnlib.example.resumable; -import java.nio.charset.StandardCharsets; import java.util.Random; -import com.thoughtworks.xstream.XStream; import de.learnlib.Resumable; import de.learnlib.algorithm.lstar.dfa.ClassicLStarDFA; import de.learnlib.filter.cache.dfa.DFACacheOracle; @@ -29,6 +27,7 @@ import de.learnlib.oracle.equivalence.DFASimulatorEQOracle; import de.learnlib.oracle.membership.DFASimulatorOracle; import de.learnlib.query.DefaultQuery; +import de.learnlib.testsupport.ResumeUtils; import net.automatalib.alphabet.Alphabet; import net.automatalib.alphabet.impl.Alphabets; import net.automatalib.alphabet.impl.GrowingMapAlphabet; @@ -44,7 +43,6 @@ public final class ResumableExample { private static final CompactDFA TARGET; private static final Alphabet INITIAL_ALPHABET; - private static final XStream X_STREAM; static { final int seed = 42; @@ -52,9 +50,6 @@ public final class ResumableExample { TARGET = RandomAutomata.randomDFA(new Random(seed), size, Alphabets.characters('a', 'd')); INITIAL_ALPHABET = Alphabets.characters('a', 'b'); - - X_STREAM = new XStream(); - X_STREAM.allowTypesByRegExp(new String[] {"net.automatalib.*", "de.learnlib.*"}); } private ResumableExample() { @@ -76,8 +71,8 @@ public static void main(String[] args) { printStats(setup); // serialize the current state of the learning setup which may be stored somewhere external - final byte[] learnerData = toBytes(setup.learner); - final byte[] cacheData = toBytes(setup.cache); + final byte[] learnerData = ResumeUtils.toBytes(setup.learner.suspend()); + final byte[] cacheData = ResumeUtils.toBytes(setup.cache.suspend()); // continue exploring the previous snapshot with new input symbol 'c' continueExploring(learnerData, cacheData, 'c'); @@ -92,10 +87,10 @@ private static void continueExploring(byte[] learnerData, byte[] cacheData, char final Setup setup = new Setup(); // resume from previous states and add new symbol - setup.cache.resume(fromBytes(cacheData)); + setup.cache.resume(ResumeUtils.fromBytes(cacheData)); setup.cache.addAlphabetSymbol(newSymbol); - setup.learner.resume(fromBytes(learnerData)); + setup.learner.resume(ResumeUtils.fromBytes(learnerData)); setup.learner.addAlphabetSymbol(newSymbol); // continue learning-loop @@ -114,15 +109,6 @@ private static void printStats(Setup setup) { System.out.println(); } - private static byte[] toBytes(Resumable resumable) { - return X_STREAM.toXML(resumable.suspend()).getBytes(StandardCharsets.UTF_8); - } - - @SuppressWarnings("unchecked") - private static T fromBytes(byte[] bytes) { - return (T) X_STREAM.fromXML(new String(bytes, StandardCharsets.UTF_8)); - } - private static class Setup { private final DFACounterOracle counter; diff --git a/examples/src/main/java/module-info.java b/examples/src/main/java/module-info.java index daf74c3ff0..5a64922568 100644 --- a/examples/src/main/java/module-info.java +++ b/examples/src/main/java/module-info.java @@ -41,6 +41,7 @@ requires de.learnlib.oracle.membership; requires de.learnlib.oracle.parallelism; requires de.learnlib.oracle.property; + requires de.learnlib.testsupport; requires de.learnlib.testsupport.example; requires net.automatalib.api; requires net.automatalib.common.util; @@ -49,7 +50,6 @@ requires net.automatalib.util; requires net.automatalib.serialization.dot; requires net.automatalib.visualization.dot; - requires xstream; // make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented requires static org.checkerframework.checker.qual; diff --git a/filters/cache/pom.xml b/filters/cache/pom.xml index 63bd7af300..96fe6e53b4 100644 --- a/filters/cache/pom.xml +++ b/filters/cache/pom.xml @@ -129,32 +129,4 @@ limitations under the License. - - - - fix-xstream - - [16,) - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - @{argLine} - --add-opens=java.base/java.util=ALL-UNNAMED - --add-reads=de.learnlib.filter.cache=de.learnlib.filter.statistic - --add-reads=de.learnlib.filter.cache=de.learnlib.oracle.membership - --add-reads=de.learnlib.filter.cache=de.learnlib.oracle.parallelism - - - - - - - - diff --git a/pom.xml b/pom.xml index 45b0e5788d..6868f35c1a 100644 --- a/pom.xml +++ b/pom.xml @@ -244,13 +244,13 @@ limitations under the License. 1.11.1 3.40.0 9.3 + 0.5.1 2.3.1 1.3.12 1.11 5.6.0 2.0.9 - 7.5.1 - 1.4.20 + 7.9.0 http://learnlib.github.io/automatalib/maven-site/${automatalib.version}/apidocs/ @@ -615,9 +615,9 @@ limitations under the License. - com.thoughtworks.xstream - xstream - ${xstream.version} + org.apache.fury + fury-core + ${fury.version} diff --git a/test-support/test-support/pom.xml b/test-support/test-support/pom.xml index 20a2d850e3..32c3bd86c6 100644 --- a/test-support/test-support/pom.xml +++ b/test-support/test-support/pom.xml @@ -40,11 +40,6 @@ - - com.thoughtworks.xstream - xstream - - net.automatalib automata-api @@ -66,6 +61,10 @@ org.checkerframework checker-qual + + org.apache.fury + fury-core + org.mockito mockito-core diff --git a/test-support/test-support/src/main/java/de/learnlib/testsupport/ResumeUtils.java b/test-support/test-support/src/main/java/de/learnlib/testsupport/ResumeUtils.java index b97dd00431..87bc7156c3 100644 --- a/test-support/test-support/src/main/java/de/learnlib/testsupport/ResumeUtils.java +++ b/test-support/test-support/src/main/java/de/learnlib/testsupport/ResumeUtils.java @@ -15,21 +15,20 @@ */ package de.learnlib.testsupport; -import java.nio.charset.StandardCharsets; - -import com.thoughtworks.xstream.XStream; import de.learnlib.Resumable; +import org.apache.fury.Fury; +import org.apache.fury.logging.LoggerFactory; /** * Utility functions for {@link Resumable} features. */ public final class ResumeUtils { - private static final XStream X_STREAM; + private static final Fury FURY; static { - X_STREAM = new XStream(); - X_STREAM.allowTypesByRegExp(new String[] {"net.automatalib.*", "de.learnlib.*"}); + LoggerFactory.useSlf4jLogging(true); + FURY = Fury.builder().withRefTracking(true).requireClassRegistration(false).build(); } private ResumeUtils() { @@ -37,12 +36,12 @@ private ResumeUtils() { } public static byte[] toBytes(T state) { - return X_STREAM.toXML(state).getBytes(StandardCharsets.UTF_8); + return FURY.serialize(state); } @SuppressWarnings("unchecked") public static T fromBytes(byte[] bytes) { - return (T) X_STREAM.fromXML(new String(bytes, StandardCharsets.UTF_8)); + return (T) FURY.deserialize(bytes); } } diff --git a/test-support/test-support/src/main/java/module-info.java b/test-support/test-support/src/main/java/module-info.java index a394fe2bc6..d615e4a4dc 100644 --- a/test-support/test-support/src/main/java/module-info.java +++ b/test-support/test-support/src/main/java/module-info.java @@ -39,9 +39,9 @@ requires net.automatalib.common.util; requires net.automatalib.core; requires net.automatalib.util; + requires org.apache.fury.core; requires org.mockito; requires org.testng; - requires xstream; // make non-static once https://github.com/typetools/checker-framework/issues/4559 is implemented requires static org.checkerframework.checker.qual;