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); - } -}