From 73565855d5b1bc308d35d2f15318fb00cd7d9f49 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Sun, 5 Feb 2023 23:24:28 +0000 Subject: [PATCH] Workaround for getting tests to work. --- .../plugin/multivm/VMCompactLibraryTask.java | 3 +- .../plugin/multivm/VMCompactLibraryTaskAction.java | 40 ++++++++++++++++++---- .../cc/squirreljme/plugin/multivm/VMHelpers.java | 31 +++++++++++++---- .../src/test/java/io/MarkableInputStreamTest.java | 2 +- .../net/multiphasicapps/tac/TestBiConsumer.java | 3 ++ .../net/multiphasicapps/tac/TestBiFunction.java | 3 ++ .../java/net/multiphasicapps/tac/TestBoolean.java | 3 ++ .../java/net/multiphasicapps/tac/TestConsumer.java | 3 ++ .../java/net/multiphasicapps/tac/TestFunction.java | 3 ++ .../java/net/multiphasicapps/tac/TestInteger.java | 3 ++ .../java/net/multiphasicapps/tac/TestLong.java | 3 ++ .../java/net/multiphasicapps/tac/TestRunnable.java | 3 ++ .../java/net/multiphasicapps/tac/TestSupplier.java | 3 ++ .../java/net/multiphasicapps/tac/__CoreTest__.java | 2 ++ 14 files changed, 91 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTask.java b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTask.java index d2c93b174d..d795bd5ecc 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTask.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTask.java @@ -96,7 +96,8 @@ public class VMCompactLibraryTask // well! this.getInputs().property("squirreljme.proguardOptionsDefault", this.getProject().provider(() -> Arrays.toString( - VMCompactLibraryTaskAction._PARSE_SETTINGS))); + VMCompactLibraryTaskAction._PARSE_SETTINGS) + + Arrays.toString(VMCompactLibraryTaskAction._TEST_SETTINGS))); // The output of this JAR is just where it should be placed, this // includes the mapping file for incremental mapping diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTaskAction.java b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTaskAction.java index 8f91f07c72..4409a05a1b 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTaskAction.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMCompactLibraryTaskAction.java @@ -24,6 +24,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.gradle.api.Action; import org.gradle.api.Task; +import org.gradle.api.tasks.SourceSet; import proguard.ClassPath; import proguard.ClassPathEntry; import proguard.Configuration; @@ -101,6 +102,17 @@ public class VMCompactLibraryTaskAction "}", }; + /** Settings for tests. */ + static final String[] _TEST_SETTINGS = + { + // This keeps everything about tests but will use pre-existing + // mappings and otherwise if we are using obfuscated classes + // This is the only thing I have found that works + "-keep", "class", "*", + "-keepnames", "class", "*", + "-keepclassmembernames", "class", "*", + }; + /** The source set used. */ public final String sourceSet; @@ -193,11 +205,15 @@ public class VMCompactLibraryTaskAction VMHelpers.compactLibTaskDepends(__task.getProject(), this.sourceSet)) { + Path baseJarFile = compactDep.baseJar.getOutputs().getFiles() + .getSingleFile().toPath(); + // Add the library, but the pre-obfuscated form since we need // to know what it is - libraryJars.add(new ClassPathEntry( - compactDep.baseJar.getOutputs().getFiles().getSingleFile(), - false)); + if (Files.exists(baseJarFile)) + libraryJars.add(new ClassPathEntry( + compactDep.baseJar.getOutputs().getFiles() + .getSingleFile(), false)); // If the mapping file exists, concatenate it if (Files.exists(compactDep.outputMapPath().get())) @@ -217,6 +233,16 @@ public class VMCompactLibraryTaskAction proGuardOptions.addAll( Arrays.asList(VMCompactLibraryTaskAction._PARSE_SETTINGS)); + // Are we testing? + boolean isTesting = + SourceSet.TEST_SOURCE_SET_NAME.equals(this.sourceSet) || + VMHelpers.TEST_FIXTURES_SOURCE_SET_NAME.equals(this.sourceSet); + + // Test settings? + if (isTesting) + proGuardOptions.addAll(Arrays.asList( + VMCompactLibraryTaskAction._TEST_SETTINGS)); + // Add any additional options as needed if (projectConfig.proGuardOptions != null && !projectConfig.proGuardOptions.isEmpty()) @@ -302,9 +328,11 @@ public class VMCompactLibraryTaskAction Files.move(tempJarFile, outputJarPath, StandardCopyOption.REPLACE_EXISTING); - Files.move(tempOutputMapFile, - outputMapPath, - StandardCopyOption.REPLACE_EXISTING); + + if (Files.exists(tempOutputMapFile)) + Files.move(tempOutputMapFile, + outputMapPath, + StandardCopyOption.REPLACE_EXISTING); } catch (Exception __e) { diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java index 019a0e286d..ffd09f6e45 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; -import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; @@ -58,7 +57,6 @@ import org.gradle.api.file.FileCollection; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.jvm.tasks.Jar; -import proguard.ClassPathEntry; /** * Helpers for the multi-VM handlers. @@ -367,7 +365,12 @@ public final class VMHelpers throw new NullPointerException("NARG"); // Where does this go? - Collection result = new ArrayList<>(); + Collection result = new LinkedHashSet<>(); + + // Are we testing? + boolean isTest = SourceSet.TEST_SOURCE_SET_NAME.equals(__sourceSet); + boolean isTestFixtures = + VMHelpers.TEST_FIXTURES_SOURCE_SET_NAME.equals(__sourceSet); // This is a bit messy but it works for now Collection runTasks = @@ -385,8 +388,8 @@ public final class VMHelpers // Find the referenced project Project subProject = __project.project(projectAndTask.project); - // Ignore our own project - if (__project.equals(subProject)) + // Ignore our own project, if not testing + if (__project.equals(subProject) && !isTest && !isTestFixtures) continue; // Check the main source set @@ -394,7 +397,23 @@ public final class VMHelpers SourceSet.MAIN_SOURCE_SET_NAME); Task maybe = subProject.getTasks().findByName(checkName); if (maybe instanceof VMCompactLibraryTask) - result.add((VMCompactLibraryTask)maybe); + { + VMCompactLibraryTask task = (VMCompactLibraryTask)maybe; + result.add(task); + } + + // If we are testing, see if we can pull in any test fixtures + if (isTest) + { + String check = TaskInitialization.task("compactLib", + VMHelpers.TEST_FIXTURES_SOURCE_SET_NAME); + Task fixture = subProject.getTasks().findByName(check); + if (fixture instanceof VMCompactLibraryTask) + { + VMCompactLibraryTask task = (VMCompactLibraryTask)fixture; + result.add(task); + } + } } return result; diff --git a/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java b/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java index 57c06cec50..75bb2783ad 100644 --- a/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java +++ b/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java @@ -26,7 +26,7 @@ import net.multiphasicapps.tac.TestRunnable; */ public class MarkableInputStreamTest extends TestRunnable - implements RandomAccess, cc.squirreljme.jvm.Framebuffer + implements RandomAccess { /** Byte message to read. */ private static final byte[] _BYTES = diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiConsumer.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiConsumer.java index 48b142f405..b5d32850eb 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiConsumer.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiConsumer.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -18,6 +19,7 @@ import org.junit.Test; * @param The second argument type. * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestBiConsumer extends __CoreTest__ { @@ -30,6 +32,7 @@ public abstract class TestBiConsumer * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract void test(A __a, B __b) throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiFunction.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiFunction.java index 43244d03b1..08fb270452 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiFunction.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBiFunction.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -19,6 +20,7 @@ import org.junit.Test; * @param The result type. * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestBiFunction extends __CoreTest__ { @@ -32,6 +34,7 @@ public abstract class TestBiFunction * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract R test(A __a, B __b) throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBoolean.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBoolean.java index 4296020973..4b3147da03 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestBoolean.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestBoolean.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -16,6 +17,7 @@ import org.junit.Test; * * @since 2019/12/25 */ +@SquirrelJMEVendorApi public abstract class TestBoolean extends __CoreTest__ { @@ -27,6 +29,7 @@ public abstract class TestBoolean * @since 2019/12/25 */ @Test + @SquirrelJMEVendorApi public abstract boolean test() throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestConsumer.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestConsumer.java index f62a0633f6..0c48c3744f 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestConsumer.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestConsumer.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -17,6 +18,7 @@ import org.junit.Test; * @param The first argument type. * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestConsumer extends __CoreTest__ { @@ -28,6 +30,7 @@ public abstract class TestConsumer * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract void test(A __a) throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestFunction.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestFunction.java index 8ef285f5c6..713b8b2d5f 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestFunction.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestFunction.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -18,6 +19,7 @@ import org.junit.Test; * @param The result type. * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestFunction extends __CoreTest__ { @@ -30,6 +32,7 @@ public abstract class TestFunction * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract R test(A __a) throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestInteger.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestInteger.java index 897f3d2df5..bace41cd27 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestInteger.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestInteger.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -16,6 +17,7 @@ import org.junit.Test; * * @since 2019/12/24 */ +@SquirrelJMEVendorApi public abstract class TestInteger extends __CoreTest__ { @@ -27,6 +29,7 @@ public abstract class TestInteger * @since 2019/12/24 */ @Test + @SquirrelJMEVendorApi public abstract int test() throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestLong.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestLong.java index e38a357826..24b5f5a88a 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestLong.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestLong.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -16,6 +17,7 @@ import org.junit.Test; * * @since 2019/12/24 */ +@SquirrelJMEVendorApi public abstract class TestLong extends __CoreTest__ { @@ -27,6 +29,7 @@ public abstract class TestLong * @since 2019/12/24 */ @Test + @SquirrelJMEVendorApi public abstract long test() throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestRunnable.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestRunnable.java index 27eee19541..0df8c410ba 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestRunnable.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestRunnable.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -16,6 +17,7 @@ import org.junit.Test; * * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestRunnable extends __CoreTest__ { @@ -26,6 +28,7 @@ public abstract class TestRunnable * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract void test() throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/TestSupplier.java b/modules/tac/src/main/java/net/multiphasicapps/tac/TestSupplier.java index 02ff72d3fd..4167ba5a3f 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/TestSupplier.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/TestSupplier.java @@ -9,6 +9,7 @@ package net.multiphasicapps.tac; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import org.junit.Test; /** @@ -17,6 +18,7 @@ import org.junit.Test; * @param The return type. * @since 2018/10/06 */ +@SquirrelJMEVendorApi public abstract class TestSupplier extends __CoreTest__ { @@ -28,6 +30,7 @@ public abstract class TestSupplier * @since 2018/10/06 */ @Test + @SquirrelJMEVendorApi public abstract R test() throws Throwable; diff --git a/modules/tac/src/main/java/net/multiphasicapps/tac/__CoreTest__.java b/modules/tac/src/main/java/net/multiphasicapps/tac/__CoreTest__.java index 0406c693f7..9e551180d7 100644 --- a/modules/tac/src/main/java/net/multiphasicapps/tac/__CoreTest__.java +++ b/modules/tac/src/main/java/net/multiphasicapps/tac/__CoreTest__.java @@ -13,6 +13,7 @@ import cc.squirreljme.jvm.manifest.JavaManifest; import cc.squirreljme.jvm.manifest.JavaManifestAttributes; import cc.squirreljme.jvm.mle.RuntimeShelf; import cc.squirreljme.jvm.mle.constants.VMType; +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; import cc.squirreljme.runtime.cldc.debug.Debugging; import java.io.IOException; import java.io.InputStream; @@ -29,6 +30,7 @@ import org.junit.Test; * * @since 2018/10/06 */ +@SquirrelJMEVendorApi abstract class __CoreTest__ implements TestInterface { -- 2.11.4.GIT