cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 160 forks source link

Trouble with jar file converting POJO to JS code #667

Open jkhuangg opened 3 years ago

jkhuangg commented 3 years ago

Hi all. I am involved in a project where I am trying to see if I can turn a POJO generated by H2O.AI, a data science/ML tool, into JavaScript code. I attached the POJO below in case anyone is interested. I used the Jsweet quickstart package and got the below error message: GLM_model_R_1611562757898_1.zip

[ERROR] ========================================= [ERROR] TRANSPILATION ERRORS SUMMARY: [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(24,50)[ts] Cannot find name 'hex'. [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(25,10)[ts] Cannot find namespace 'hex'. [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(25,56)[ts] Cannot find name 'hex'. [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(71,52)[ts] Cannot find name 'hex'. [ERROR]

The "Hex" probably comes from the genmodel.jar provided by H2O: https://mvnrepository.com/artifact/ai.h2o/h2o-genmodel/3.32.0.3

In my pom.xml file I included it as a dependency (even the j4ts for good measures):

            </dependency>
                    <groupId>ai.h2o</groupId>
                    <artifactId>h2o-genmodel</artifactId>
                    <version>3.32.0.3</version>
            </dependency>
            <dependency>
                    <groupId>org.jsweet</groupId>
                    <artifactId>j4ts</artifactId>
                    <version>2.0.0</version>
            </dependency>

I am pretty sure I'm not working Jsweet correctly. Apologies beforehand for any rookie mistakes committed beforehand. But I would appreciate any help I can get!

lgrignon commented 3 years ago

Hello,

If you want to package a candy (a JSweet compatible JAR library), please take a look at this repository: https://github.com/lgrignon/jsweet-candy-example

You can start from it, put your sources, and then mvn clean installit

jkhuangg commented 3 years ago

Thanks for the quick response! I'm still new to Java so I'll be a complete idiot and ask this here: based on the Github candy example, to use the h2o-genmodel.jar from here: https://mvnrepository.com/artifact/ai.h2o/h2o-genmodel/3.32.0.3

I should download this jar, and put it into src/main/java in the from the jsweet-candy-example directory, and then run mvn clean install? Then I just need to add

<dependency>
    <groupId>org.jsweet.candies.ext</groupId>
    <artifactId>candy-example</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

in the pom.xml of my original project (the one to convert GLM_model_R_1611562757898_1.java into JavaScript)?

jkhuangg commented 3 years ago

Hello again. Just for practice, I cloned the jsweet-candy-example directory and then ran the mvn clean install command. Then I started another Jsweet project using the quickstart files from: https://github.com/cincheo/jsweet-quickstart.

Then in the jsweet-quickstart/src/main/java/quickstart/QuickStart.java, I added the line import fr.mycompany.HelloWorldService to test the new candy. But I am getting this error when I ran mvn generate-sources:

[ERROR] Failed to execute goal org.jsweet:jsweet-maven-plugin:3.0.0:jsweet (generate-js) on project jsweet-quickstart: failed to create transpiler: Unable to get dependency information for org.jsweet.candies.ext:candy-example:jar:1.0.0-SNAPSHOT: Failed to retrieve POM for org.jsweet.candies.ext:candy-example:jar:1.0.0-SNAPSHOT: Could not transfer artifact org.jsweet.candies.ext:candy-example:pom:1.0.0-SNAPSHOT from/to jsweet-central (http://repository.jsweet.org/artifactory/libs-release-local): Failed to transfer file: http://repository.jsweet.org/artifactory/libs-release-local/org/jsweet/candies/ext/candy-example/1.0.0-SNAPSHOT/candy-example-1.0.0-SNAPSHOT.pom. Return code is: 409 , ReasonPhrase:Conflict. [ERROR] org.jsweet.candies.ext:candy-example:jar:1.0.0-SNAPSHOT [ERROR] [ERROR] from the specified remote repositories: [ERROR] jsweet-central (http://repository.jsweet.org/artifactory/libs-release-local, releases=true, snapshots=true), [ERROR] jsweet-snapshots (http://repository.jsweet.org/artifactory/libs-snapshot-local, releases=true, snapshots=true), [ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false) [ERROR] Path to dependency: [ERROR] 1) org.jsweet:jsweet-quickstart:jar:3.0.0 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Any ideas? Thanks in advance.

renaudpawlak commented 3 years ago

If you have the source code of https://mvnrepository.com/artifact/ai.h2o/h2o-genmodel/3.32.0.3, then you can just add it in the source code along with the POJOs... so that you don't need to create a candy. It would be the simple way.

renaudpawlak commented 3 years ago

However, when I look in Maven Central, the h2o-genmodel artifact has dependencies to other artifacts (for instance Google Gson) so it does not look too good. You should try to analyse wether you can easily re-implement or replace the missing hex.* elements.

jkhuangg commented 3 years ago

Hi @renaudpawlak thanks for the advice!

I followed your advice (which made wayyy more sense than what I was trying to do) and imported the hex files from H2O-3's Github: https://github.com/h2oai/h2o-3/tree/master/h2o-genmodel

So now my project directory looks more like this:

src
│   └── main
│       ├── java
│       │   ├── GLM_model_R_1611562757898_1
│       │   ├── doc-files
│       │   ├── hex
│       │   │   └── genmodel

However, I got this error when I ran mvn generate-sources: [ERROR] Failed to execute goal org.jsweet:jsweet-maven-plugin:3.0.0:jsweet (generate-js) on project jsweet-quickstart: transpilation failed: transpilation failed with 1 error(s) and 1 warning(s) [ERROR] [ERROR] ========================================= [ERROR] TRANSPILATION ERRORS SUMMARY: [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19,1)internal transpiler error [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/hex/genmodel/ModelMojoFactory.java(42,5)synchronization is ignored in JSweet [ERROR] [ERROR] [ERROR] ========================================= [ERROR] -> [Help 1]

Here's the line 19 at GLM_model_R_1611562757898_1.java: import java.util.Map;

and here's the function in line 42 in ModelMojoFactory that uses the synchronization feature:

  private ModelMojoReader loadMojoReader(String algo) {
    assert algo != null : "Name of algorithm should be != null!";
    synchronized (loader) {
      loader.reload();
      for (ModelMojoReader mrb : loader) {
        if (algo.equals(mrb.getModelName())) {
          return mrb;
        }
      }
    }
    return null;
  }

I know that Jsweet currently doesn't support synchronization but I am wondering if you are aware of a way to get around this? Thanks in advance!

renaudpawlak commented 3 years ago

Weird. Synchronization are just ignored and should trigger a warning... not an error. (Note that synchronized statements are useless in JS since it is not multithreaded. So they can just be dropped out.)

You don't have any stacktrace?? Normally an "internal error" should be followed by a stacktrace. If you can edit the source file, try to remove the synchronized keyword and see what happens. Try to change the code source to locate the issues.

jkhuangg commented 3 years ago

@renaudpawlak oops my bad. Here I ran it again with the -e option:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 31.103 s [INFO] Finished at: 2021-01-27T15:38:51-05:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.jsweet:jsweet-maven-plugin:3.0.0:jsweet (generate-js) on project jsweet-quickstart: transpilation failed: transpilation failed with 1 error(s) and 1 warning(s) [ERROR] [ERROR] ========================================= [ERROR] TRANSPILATION ERRORS SUMMARY: [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19,1)internal transpiler error [ERROR] /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/hex/genmodel/ModelMojoFactory.java(42,5)synchronization is ignored in JSweet [ERROR] [ERROR] [ERROR] ========================================= [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jsweet:jsweet-maven-plugin:3.0.0:jsweet (generate-js) on project jsweet-quickstart: transpilation failed at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: transpilation failed at org.jsweet.AbstractJSweetMojo.transpile (AbstractJSweetMojo.java:708) at org.jsweet.JSweetMojo.execute (JSweetMojo.java:43) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: org.apache.maven.plugin.MojoFailureException: transpilation failed with 1 error(s) and 1 warning(s)

========================================= TRANSPILATION ERRORS SUMMARY:

========================================= at org.jsweet.AbstractJSweetMojo.transpile (AbstractJSweetMojo.java:694) at org.jsweet.JSweetMojo.execute (JSweetMojo.java:43) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) [ERROR] [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

jkhuangg commented 3 years ago

Also I am curious about the [ERROR] * /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19,1)internal transpiler error

since at line 19 of GLM_model_R_1611562757898_1.java the line is just import java.util.Map;

Edit: here's a longer version I found while running the mvn generate-sources command: 2021-01-27 16:57:55.055 INFO JSweetTranspiler:944 - scanning /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java... 2021-01-27 16:57:55.055 ERROR output:55 - internal transpiler error at /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19) dumping transpiler's strack trace: [JCCompilationUnit] import java.util.Map;... (/mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19,1)) java.lang.NullPointerException at org.jsweet.transpiler.extension.PrinterAdapter.getModuleImportDescriptor(PrinterAdapter.java:855) at org.jsweet.transpiler.Java2TypeScriptTranslator.getModuleImportDescriptor(Java2TypeScriptTranslator.java:692) at org.jsweet.transpiler.Java2TypeScriptTranslator.detectAndUseImportedModules(Java2TypeScriptTranslator.java:1018) at org.jsweet.transpiler.Java2TypeScriptTranslator.visitCompilationUnit(Java2TypeScriptTranslator.java:775) at org.jsweet.transpiler.Java2TypeScriptTranslator.visitCompilationUnit(Java2TypeScriptTranslator.java:150) at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591) at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82) at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:279) at org.jsweet.transpiler.util.AbstractTreePrinter.print(AbstractTreePrinter.java:155) at org.jsweet.transpiler.JSweetTranspiler.generateTsFiles(JSweetTranspiler.java:947) at org.jsweet.transpiler.JSweetTranspiler.java2ts(JSweetTranspiler.java:898) at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:821) at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:779) at org.jsweet.AbstractJSweetMojo.transpile(AbstractJSweetMojo.java:674) at org.jsweet.JSweetMojo.execute(JSweetMojo.java:43) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:192) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

jkhuangg commented 3 years ago

@renaudpawlak I commented out the synchornized line and now I'm just left with the internal transpiler error above: [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 26.022 s [INFO] Finished at: 2021-01-27T18:33:53-05:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.jsweet:jsweet-maven-plugin:3.0.0:jsweet (generate-js) on project jsweet-quickstart: transpilation failed: transpilation failed with 1 error(s) and 0 warning(s) [ERROR] [ERROR] ========================================= [ERROR] TRANSPILATION ERRORS SUMMARY: [ERROR] * /mnt/c/Users/Yiju Huang/Desktop/jsweet-quickstart/src/main/java/GLM_model_R_1611562757898_1/GLM_model_R_1611562757898_1.java(19,1)internal transpiler error [ERROR] [ERROR] [ERROR] ========================================= [ERROR] -> [Help 1] [ERROR]

renaudpawlak commented 3 years ago

Looks like a bug with the modules: java.lang.NullPointerException at org.jsweet.transpiler.extension.PrinterAdapter.getModuleImportDescriptor(PrinterAdapter.java:855)

Did you keep J4TS as a dependency in your pom.xml?

            <dependency>
                    <groupId>org.jsweet</groupId>
                    <artifactId>j4ts</artifactId>
                    <version>2.0.0</version>
            </dependency>

If so, I would suggest to try with or without.

Also, can you give me your entire pom.xml so that I can check JSweet plugin configuration?

In last resort, you can also try to revert to JSweet version 2.x with a JDK1.8 installed. Maybe it is a regression in JSweet 3.0.

Looks like a bug with the Maven plugin with considers warning as errors... What do you think @lgrignon ? Have you tried to remove the line with the synchronized as I suggested ? (you need to remove the ending curly-bracket of the block too, of course).

jkhuangg commented 3 years ago

Hey @renaudpawlak thanks for all your help so far!

I've upload my entire project up to GitHub to make this easier: https://github.com/jkhuangg/H2O_P2JS

and here's the pom.xml (I've tried it with and without j4ts and I think it works about the same): https://github.com/jkhuangg/H2O_P2JS/blob/master/pom.xml

The only thing I've changed for the GitHub repo is that the main H2O-generated POJO in src/main/java is now named gbm_pojo_test.java, as per the official POJO object H2O created on their tutorial webpage: https://h2o-release.s3.amazonaws.com/h2o/rel-turing/1/docs-website/h2o-docs/pojo-quick-start.html

It seems like no matter how much I tweak the source code, when I run mvn generate-sources it would either be "missing hex*" or it can't read the java.util.Map import. Hopefully putting this up can make this easier to catch what's wrong.

Thanks for all your amazing help!

jkhuangg commented 3 years ago

Oh and I forgot to answer question #2 about synchronized. I did that back when I literally moved all the h2o-related directories from the H2O-3 GitHub (h2o-*/) to my src/main/java and ran mvn generate-sources from there. I did commented out the synchronized line plus its ending curly bracelet but the results were about the same.

renaudpawlak commented 3 years ago

Ummm. From what I see in the source code, I don't see where the error comes from (at least the error message does not make sense). I will try it out if I find the time.

In any case, your real deeper problem will be to have an implementation of hex.genmodel.GenModel.

Note that your generated pojo extends it !!!! So if you don't have an implementation of this class in TypeScript or JavaScript you ave no chance to run the generated code, even if you manage to transpile it with no errors.

Would by chance the H2O-3 already provide a JS implementation? If you had to transpile it with JSweet, I suspect it would be a lot of trouble.

If H2O-3 is Java only, maybe you should consider leaving the Java code server side, embed it in a Tomcat or whatever, and have a JS client to access it in the browser...

jkhuangg commented 3 years ago

I don't think H2O-3 has a JS implementation. And you're right, I think the main problem is with transpiling hex.genmodel.GenModel.

I totally see your point in leaving the Java code on the server side and have a JS client. In fact, the Professor I'm working with now actually has a server running H2O code (but in R I think, which H2O is also available in). But right now we are trying to see if there's a way to run the entire H2O codebase in JS so that we can run the whole thing in the browser so it could be faster.

Since H2O can generate a POJO, we were trying to see if there's a way to convert it JS so we can achieve that goal. Hence the start of this long thread :)

renaudpawlak commented 3 years ago

Sure, but the "POJO"... extends hex.genmodel.GenModel AND holds an annotation. Thats not really what I would have called a "POJO". In any case, I believe that what you are trying to do is more about transpiling H2O-3 in JS ;) If I were you, I would try this first and see what the problems would be...

jkhuangg commented 3 years ago

Yeah that does make more sense. Oh boy the work....

renaudpawlak commented 3 years ago

Indeed. My strategy would be to use a one-shot JSweet transpilation, then take the generated TypeScript code and modify it manually to try to fix the errors and implement in JS what is not available. I wish you good luck because I don't think I can allocate more "free" time here ;)

jkhuangg commented 3 years ago

Haha thanks for all your help!