Vertispan / j2clmavenplugin

Maven plugin to launch new J2CL compilation
https://vertispan.github.io/j2clmavenplugin/
Apache License 2.0
53 stars 26 forks source link

Translations validation breaks with closure-compiler v20221004 #192

Closed niloc132 closed 9 months ago

niloc132 commented 1 year ago

https://github.com/google/closure-compiler/commit/da77937ff5db2dce54f1bbde0b38711c74523350#diff-c36853adf65b1c9aa8fec01a29f192fd26431a1652cb9cc2099f6e74617b6cd9R324-R327 enforces stricter constraints on placeholder names - only uppercase, with underscores and numbers.

java.lang.IllegalArgumentException: not a canonical placeholder name format: 'arg'
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:220)
    at com.google.javascript.jscomp.JsMessage$PlaceholderReference.createForCanonicalName(JsMessage.java:320)
    at com.google.javascript.jscomp.JsMessage$Builder.appendCanonicalPlaceholderReference(JsMessage.java:452)
    at com.google.javascript.jscomp.XtbMessageBundle$Handler.startElement(XtbMessageBundle.java:164)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
[ERROR] Exception executing task translation.test:zr_escape:1.0-test-example/test/AppTest.js/optimized_js
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
java.lang.IllegalStateException: Closure Compiler failed, check log for details
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at com.google.javascript.jscomp.XtbMessageBundle.<init>(XtbMessageBundle.java:72)
    at com.google.javascript.jscomp.CommandLineRunner.createOptions(CommandLineRunner.java:1967)
    at com.vertispan.j2cl.tools.Closure$InProcessJsCompRunner.createOptions(Closure.java:212)
    at com.google.javascript.jscomp.AbstractCommandLineRunner.doRun(AbstractCommandLineRunner.java:1186)
    at com.google.javascript.jscomp.AbstractCommandLineRunner.run(AbstractCommandLineRunner.java:556)
    at com.vertispan.j2cl.tools.Closure.compile(Closure.java:178)
    at com.vertispan.j2cl.build.provided.ClosureTask$4.execute(ClosureTask.java:246)

It looks like the placeholder names in the xml are now expected to be formatted using uppercase only:

  /**
   * In XMB and XTB files we expect the placeholder name to be in UPPER_SNAKE_CASE with optional
   * _123_456 suffix.
   *
   * <p>This pattern will allow alpha sections after numeric sections (e.g. NOT_A_1234_VALID_NAME),
   * but it is still probably good enough, since these name are usually automatically generated from
   * the JS formatted lowerCamelCase_with_optional_12_34 names.
   *
   * <p>The pattern also allows leading and trailing underscores. There are known cases of messages
   * containing those.
   */
  private static final Pattern CANONICAL_PLACEHOLDER_NAME_RE = Pattern.compile("[A-Z\\d_]*");

However, the placeholder name must still be lowercase in the js files.

niloc132 commented 1 year ago

See https://github.com/niloc132/j2clmavenplugin/pull/new/192-partial-fix for a partial fix that compiles, but doesn't pass its tests:

[INFO] fetching http://localhost:42401/zr_escape/test-example.test.AppTest.html
[INFO] 14:02:04.965 : Starting tests: j2cl-maven-plugin test runner
[INFO] 14:02:04.966 : Running test: test_value
[INFO] A()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:17
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:104
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:82
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:81
V()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:99
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:77
V()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:99
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:77
F()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:25
Wd()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:77
Je()@http://localhost:42401/zr_escape/test-example.test.AppTest.js:116
@http://localhost:42401/zr_escape/test-example.test.AppTest.js:123

[INFO] 14:02:04.990 : test_value : FAILED
[INFO] 14:02:04.991 : 1 of 1 tests run in 26 ms.
0 passed, 1 failed.
26 ms/test. 1 files loaded.
[INFO] 14:02:04.991 : Tests Failed
[ERROR] Test failed!
[ERROR] Test example.test.AppTest failed, please try manually example/test/AppTest.js
niloc132 commented 9 months ago

Fixed by at least 0.21, closing.