From 183a3a658acc73b6776fcd7c0124e904ed844e9e Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Fri, 8 Dec 2023 15:14:15 +0100 Subject: [PATCH 1/2] chore: use latest Java LTS version (21) in CI tests - update the setup-java action to v4 - add Java 21 to the Java version matrix - update the JDK distribution to Eclipse Temurin (formerly AdoptOpenJDK) --- .github/workflows/maven-ci.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index d06444c02..1886df10a 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -12,16 +12,17 @@ jobs: name: "Build on Java ${{ matrix.java }}" strategy: matrix: - java: [8, 11, 16] + java: [8, 11, 17, 21] runs-on: ubuntu-latest steps: - name: "Checkout sources" uses: actions/checkout@v2 - name: "Set up Java" - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java }} - distribution: "adopt" + distribution: "temurin" + cache: 'maven' - name: "Get Maven dependencies from cache" uses: actions/cache@v2 with: @@ -40,10 +41,10 @@ jobs: - name: "Checkout sources" uses: actions/checkout@v2 - name: "Setup Java" - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - java-version: 11 - distribution: "adopt" + java-version: 21 + distribution: "temurin" server-id: ossrh server-username: OSSRH_USERNAME server-password: OSSRH_PASSWORD From 9888fcc0ef9624dfdccfd1b5901ae4cb24b3e30d Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Fri, 8 Dec 2023 15:19:40 +0100 Subject: [PATCH 2/2] fix: tweak code and tests to better support Java 21 - adapt code in OFCChecker to a slight rewording of the OpenJDK message reported for invalid ZIP headers, so that EPUBCheck can issue the right error code (PKG-017) - update the command line tests to no longer rely on the deprecated SecurityManager API to catch system exit codes. The tests now get the integer return code directly from the EpubChecker API --- .../com/adobe/epubcheck/ocf/OCFChecker.java | 18 +++++--- .../epubcheck/tools/CommandLineTest.java | 36 +++------------ .../tools/NoExitSecurityManager.java | 44 ------------------- 3 files changed, 17 insertions(+), 81 deletions(-) delete mode 100644 src/test/java/com/adobe/epubcheck/tools/NoExitSecurityManager.java diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java index 1e055d619..1461b3f86 100755 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java @@ -345,15 +345,18 @@ private boolean checkContainerStructure(OCFCheckerState state) return true; } catch (Exception e) { - switch (e.getMessage()) + if (e.getMessage() != null && + ( + // reported by Open JDK: + e.getMessage().startsWith("invalid CEN header") + // reported by Oracle JDK 1.8: + || e.getMessage().equals("MALFORMED"))) { - case "invalid CEN header (bad entry name)": // reported by OpenJDK - case "MALFORMED": // reported by Oracle JDK 1.8 report.message(MessageId.PKG_027, EPUBLocation.of(context), e.getLocalizedMessage()); - break; - default: + } + else + { report.message(MessageId.PKG_008, EPUBLocation.of(context), e.getLocalizedMessage()); - break; } return false; } @@ -556,7 +559,8 @@ private void reportFeatures(OCFResource resource) { for (FeatureEnum feature : resource.getProperties().keySet()) { -// report.info(context.path, feature, resource.getProperties().get(feature)); + // report.info(context.path, feature, + // resource.getProperties().get(feature)); report.info(resource.getPath(), feature, resource.getProperties().get(feature)); } } diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index b7dc20235..20a51ff3b 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import com.adobe.epubcheck.api.EpubCheck; -import com.adobe.epubcheck.tool.Checker; +import com.adobe.epubcheck.tool.EpubChecker; import com.adobe.epubcheck.util.Messages; public class CommandLineTest @@ -35,7 +35,6 @@ public class CommandLineTest private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - private SecurityManager originalManager; private PrintStream originalOut; private PrintStream originalErr; private final Messages messages = Messages.getInstance(Locale.ENGLISH); @@ -46,8 +45,6 @@ public void setUp() { defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); - this.originalManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); originalOut = System.out; originalErr = System.err; System.setOut(new PrintStream(outContent)); @@ -58,7 +55,6 @@ public void setUp() public void tearDown() { Locale.setDefault(defaultLocale); - System.setSecurityManager(this.originalManager); System.setOut(originalOut); System.setErr(originalErr); } @@ -292,14 +288,7 @@ public void missingTranslationShouldFallbackTest() Locale.setDefault(Locale.FRANCE); URL inputUrl = CommandLineTest.class.getResource("valid.epub"); - - try - { - Checker.main(new String[] { inputUrl.getPath(), "--locale", "ar-eg" }); - } catch (NoExitSecurityManager.ExitException e) - { - assertEquals("Return code should be zero", 0, e.status); - } + runCommandLineTest(0, inputUrl.getPath(), "--locale", "ar-eg"); assertTrue("Valid Locale without translation should fallback to JVM default.", outContent.toString().contains("faites en utilisant")); @@ -345,13 +334,7 @@ public void incorrectLocaleShouldFailTest() URL inputUrl = CommandLineTest.class.getResource("valid.epub"); - try - { - Checker.main(new String[] { inputUrl.getPath(), "--locale", "foobar" }); - } catch (NoExitSecurityManager.ExitException e) - { - assertEquals("Return code should be zero", 0, e.status); - } + runCommandLineTest(0, inputUrl.getPath(), "--locale", "foobar"); assertTrue("Invalid Locale should use JVM default.", outContent.toString().contains("faites en utilisant")); @@ -756,18 +739,11 @@ public void xmpFileTest() } } - public static void runCommandLineTest(int expectedReturnCode, String... args) + public void runCommandLineTest(int expectedReturnCode, String... args) { - int result = Integer.MAX_VALUE; - try - { - Checker.main(args); - } catch (NoExitSecurityManager.ExitException e) - { - result = e.status; - } - assertEquals("Return code", expectedReturnCode, result); + int returnCode = new EpubChecker().run(args); + assertEquals("Return code", expectedReturnCode, returnCode); } } \ No newline at end of file diff --git a/src/test/java/com/adobe/epubcheck/tools/NoExitSecurityManager.java b/src/test/java/com/adobe/epubcheck/tools/NoExitSecurityManager.java deleted file mode 100644 index 1307f2fc2..000000000 --- a/src/test/java/com/adobe/epubcheck/tools/NoExitSecurityManager.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.adobe.epubcheck.tools; - -import java.security.Permission; - -/** - * Created with IntelliJ IDEA. - * User: apond - * Date: 6/4/12 - * Time: 9:24 AM - * To change this template use File | Settings | File Templates. - */ - - -public class NoExitSecurityManager extends SecurityManager -{ - - public static class ExitException extends SecurityException - { - public final int status; - - public ExitException(int status) - { - super("There is no escape!"); - this.status = status; - } - } - - @Override - public void checkPermission(Permission perm) - { // allow anything. - } - - @Override - public void checkPermission(Permission perm, Object context) - { // allow anything. - } - - @Override - public void checkExit(int status) - { - super.checkExit(status); - throw new ExitException(status); - } -}