foal / gwt-time

Backport of functionality based on JSR-310 to GWT. This is NOT an implementation of JSR-310.
BSD 3-Clause "New" or "Revised" License
19 stars 6 forks source link

J2CL compatibility #17

Open salmonb opened 4 months ago

salmonb commented 4 months ago

hi,

Following the discussion I started (asking if your library was J2CL compatible), it appears that it's not according to my tests, so I think it's better to open an issue now. I will try to help you making it compatible.

I investigated further, and your library has the following dependencies:

  1. org.jresearch.gwt.tool.emu.apt.annotation
  2. org.jresearch.locale.languageTag
  3. value-annotations

It's possible to have dependencies with J2CL, but they must be J2CL compatible. Actually only 1. is J2CL compatible. 3. is not because it uses java.lang.ref (not emulated by J2CL). And therefore 2. is not (because it uses 3.). Also some classes of your library itself use javax.annotation.Nonnull (not provided by J2CL).

So I continued working on my repo1, and added some super sources for java.lang.ref and javax.annotation.Nonnull. But because J2CL compiles each module separately (as opposed to GWT that compiles the whole app in a monolithic manner), this doesn't fix the problem in the dependencies (compiled separately, so without my new super source). Therefore, I integrated them in my repo1 (see the maven-dependency-plugin in the pom.xml) instead of declaring them as dependencies. Actually I use this copy step to also filter their sources from everything else, because J2CL will try to compile everything you provide (it doesn't have a gwt.xml module file with filtering features like for GWT). In this way, the dependent sources are filtered and compiled together with my super source, which fixes that first issue mentioned above (at least temporarily for the scope of this investigation - maybe you will find a better way, like making your final super sources complete separate "clean" modules compatible with J2CL).

After solving the issues with the dependencies, I'm now getting the following J2CL errors on repo2:


[INFO] Starting com.google.elemental2:elemental2-promise:1.2.1/transpiled_js
[INFO] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/stripped_bytecode_headers: /Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/TimeEntryPoint.java:3: error: symbol not found com.google.gwt.core.client.EntryPoint
import com.google.gwt.core.client.EntryPoint;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/TimeEntryPoint.java:5: error: could not resolve EntryPoint
public class TimeEntryPoint implements EntryPoint {
                                       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/loader/TimeJsBundle.java:5: error: symbol not found com.google.gwt.resources.client.ClientBundle
import com.google.gwt.resources.client.ClientBundle;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/loader/TimeJsBundle.java:8: error: could not resolve ClientBundle
public interface TimeJsBundle extends ClientBundle {
                                      ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/loader/TimeJsBundle.java:6: error: symbol not found com.google.gwt.resources.client.TextResource
import com.google.gwt.resources.client.TextResource;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/loader/TimeJsBundle.java:12: error: could not resolve TextResource
        public TextResource support();
        ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/org/jresearch/threetenbp/gwt/time/client/loader/TimeJsBundle.java:11: error: could not resolve Source
        @Source("support.js")
 ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/Duration.java:59: error: symbol not found org.gwtproject.regexp.shared.RegExp
import org.gwtproject.regexp.shared.RegExp;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/Duration.java:114: error: could not resolve RegExp
    private final static RegExp PATTERN =
                         ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/Period.java:57: error: symbol not found org.gwtproject.regexp.shared.RegExp
import org.gwtproject.regexp.shared.RegExp;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/Period.java:108: error: could not resolve RegExp
    private final static RegExp PATTERN =
                         ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/ZoneId.java:56: error: symbol not found org.slf4j.Logger
import org.slf4j.Logger;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/ZoneId.java:141: error: could not resolve Logger
        private static final Logger LOGGER = LoggerFactory.getLogger(ZoneId.class);
                      ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/ZoneRegion.java:40: error: symbol not found org.gwtproject.regexp.shared.RegExp
import org.gwtproject.regexp.shared.RegExp;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/ZoneRegion.java:69: error: could not resolve RegExp
    private static final RegExp PATTERN = RegExp.compile("[A-Za-z][A-Za-z0-9~/._+-]+");
                         ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/format/DateTimeFormatterBuilder.java:83: error: symbol not found org.slf4j.Logger
import org.slf4j.Logger;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/format/DateTimeFormatterBuilder.java:3347: error: could not resolve Logger
                private static final Logger LOGGER = LoggerFactory
                       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/format/SimpleDateTimeTextProvider.java:61: error: symbol not found org.slf4j.Logger
import org.slf4j.Logger;
       ^
/Users/bruno/IdeaProjects/gwt-time-j2cl-test/target/gwt3BuildCache/0.22.0/dev.webfx-gwt-time-j2cl-0.1.0-SNAPSHOT/31ed6ee71cd879be16772fddc22e8ffc-stripped_sources/results/super/java/time/format/SimpleDateTimeTextProvider.java:74: error: could not resolve Logger
        private static final Logger LOGGER = LoggerFactory.getLogger(SimpleDateTimeTextProvider.class);
                      ^
[INFO] Finished dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/stripped_bytecode_headers in 954ms
[INFO] Finished com.google.elemental2:elemental2-promise:1.2.1/transpiled_js in 259ms
[INFO] Starting com.google.elemental2:elemental2-promise:1.1.0/stripped_bytecode_headers
[INFO] Finished com.google.elemental2:elemental2-promise:1.1.0/stripped_bytecode_headers in 59ms
[INFO] Starting com.google.elemental2:elemental2-core:1.2.1/transpiled_js
[INFO] Starting com.google.elemental2:elemental2-core:1.2.1/stripped_bytecode_headers
[INFO] Finished com.google.elemental2:elemental2-core:1.2.1/stripped_bytecode_headers in 595ms
[INFO] Starting com.google.elemental2:elemental2-core:1.1.0/stripped_bytecode_headers
[INFO] Finished com.google.elemental2:elemental2-core:1.1.0/stripped_bytecode_headers in 444ms
[INFO] Starting com.google.elemental2:elemental2-dom:1.2.1/stripped_bytecode_headers
[INFO] Finished com.google.elemental2:elemental2-dom:1.2.1/stripped_bytecode_headers in 2486ms
[INFO] Starting com.google.elemental2:elemental2-dom:1.2.1/transpiled_js
[INFO] Finished org.treblereel.j2cl.processors:processors:0.6.4/bytecode in 16273ms
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeEntryPoint.java:3: The import com.google.gwt.core.client.EntryPoint cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeEntryPoint.java:5: EntryPoint cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeEntryPoint.java:8: The method onModuleLoad() of type TimeEntryPoint must override or implement a supertype method
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeJsBundle.java:5: The import com.google.gwt.resources cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeJsBundle.java:6: The import com.google.gwt.resources cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeJsBundle.java:8: ClientBundle cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeJsBundle.java:11: Source cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:TimeJsBundle.java:12: TextResource cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Clock.java:45: The import java.util.TimeZone cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:58: The import org.gwtproject cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:59: The import org.gwtproject cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:114: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:115: RegExp cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:395: MatchResult cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Duration.java:395: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:56: The import org.gwtproject cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:57: The import org.gwtproject cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:108: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:109: RegExp cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:308: MatchResult cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Period.java:308: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneId.java:56: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneId.java:57: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneId.java:141: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneId.java:141: LoggerFactory cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneId.java:245: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRegion.java:40: The import org.gwtproject cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRegion.java:69: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRegion.java:69: RegExp cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRegion.java:133: RegExp cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ThaiBuddhistEra.java:36: The import java.io.DataInput cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ThaiBuddhistEra.java:37: The import java.io.DataOutput cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:47: The import java.text.DateFormat cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:83: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:84: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3347: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3347: LoggerFactory cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3423: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3431: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3439: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:DateTimeFormatterBuilder.java:3446: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeFormatStyleProvider.java:34: The import java.text.SimpleDateFormat cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:61: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:62: The import org.slf4j cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:74: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:74: LoggerFactory cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:97: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:250: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:SimpleDateTimeTextProvider.java:262: Logger cannot be resolved to a type
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRules.java:91: Type mismatch: cannot convert from StandardZoneRules to ZoneRules
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:ZoneRulesBuilder.java:454: Type mismatch: cannot convert from StandardZoneRules to ZoneRules
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Locale.java:14: The import com.google.gwt.i18n cannot be resolved
[ERROR] dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js: Error:Locale.java:55: LocaleInfo cannot be resolved
[ERROR] Exception executing task dev.webfx:gwt-time-j2cl:0.1.0-SNAPSHOT/transpiled_js

It's mainly because you use some GWT API not supported by J2CL such as RegEx, Logger, etc...

So the next step will be to rewrite all these calls using Elemental2 (which is GWT & J2CL compatible).

Let me know if you need help for this.

You can also contact me more directly if you wish on my WebFX support chat.

Thank you!

salmonb commented 4 months ago

I'm also discussing with the Vertispan team (who made the J2CL Maven plugin) on Gitter, and when I asked for a J2CL library for java.time, one participant mentioned this gwt-time library he worked on. It's not maintained anymore, but it is J2CL compatible. And he is happy that you take everything you want from it. I think it's good to look in particular at the way it is packaged so it is J2CL compatible.

If you want to look at it but have questions, I can probably connect you with the maintainer. Just let me know.