Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support Java 21 (code tweak and CI tests) #1551

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
}
}
Expand Down
36 changes: 6 additions & 30 deletions src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -58,7 +55,6 @@ public void setUp()
public void tearDown()
{
Locale.setDefault(defaultLocale);
System.setSecurityManager(this.originalManager);
System.setOut(originalOut);
System.setErr(originalErr);
}
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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);
}

}
44 changes: 0 additions & 44 deletions src/test/java/com/adobe/epubcheck/tools/NoExitSecurityManager.java

This file was deleted.

Loading