cincheo / jsweet

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

Compilation of awt classes like java.awt.Color fail since upgrade to version 3.1.0 #704

Open AlexGeller1 opened 2 years ago

AlexGeller1 commented 2 years ago

Steps to reproduce:

$unzip jsweet-quickstart-master.zip
$cd jsweet-quickstart-master
#generate src/main/java/java/awt/Color.java
$cat src/main/java/java/awt/Color.java
package java.awt;
public class Color
{
}
mvn generate-sources
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.jsweet:jsweet-quickstart:jar:3.1.0
[WARNING] 'version' contains an expression but should be a constant. @ org.jsweet:jsweet-quickstart:${jsweet.transpiler.version}, /home/alex/jsweet-bugs/bug3/pom.xml, line 6, column 11
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] --------------------< org.jsweet:jsweet-quickstart >--------------------
[INFO] Building JSweet quick start 3.1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- jsweet-maven-plugin:3.1.0:jsweet (generate-js) @ jsweet-quickstart ---
[INFO] maven version: 3.6.0
[INFO] JSweet transpiler version 3.1.0 (build date: 2021-04-21 20:24:55)
[INFO] dependencies=[Dependency {groupId=org.jsweet, artifactId=jsweet-core, version=6.3.0, type=jar}, Dependency {groupId=org.jsweet.candies, artifactId=jquery, version=1.10.0-20170726, type=jar}]
[INFO] candies detection: add project dependency Dependency {groupId=org.jsweet, artifactId=jsweet-core, version=6.3.0, type=jar} => org.jsweet:jsweet-core:jar:6.3.0:compile
[INFO] candies detection: add project dependency Dependency {groupId=org.jsweet.candies, artifactId=jquery, version=1.10.0-20170726, type=jar} => org.jsweet.candies:jquery:jar:1.10.0-20170726:compile
[INFO] all candies artifacts: [org.jsweet.candies:jquery:jar:1.10.0-20170726:compile (1; enabled), org.jsweet:jsweet-core:jar:6.3.0:compile (1; enabled)]
[INFO] candies jars: [/home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar, /home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar]
[INFO] classpath from maven: /home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar:/home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar
[INFO] jsOut: /home/alex/jsweet-bugs/bug3/target/js
[INFO] bundle: null
[INFO] tsOut: /home/alex/jsweet-bugs/bug3/target/ts
[INFO] tsOnly: null
[INFO] tsserver: true
[INFO] declarations: null
[INFO] ignoreDefinitions: null
[INFO] declarationOutDir: null
[INFO] candiesJsOutDir: /home/alex/jsweet-bugs/bug3/webapp/candies
[INFO] ecmaTargetVersion: ES6
[INFO] moduleKind: none
[INFO] sourceMap: null
[INFO] sourceRoot: null
[INFO] compileSourceRootsOverridenull
[INFO] verbose: true
[INFO] veryVerbose: null
[INFO] jdkHome: /usr/lib/jvm/java-11-openjdk-amd64
[INFO] factoryClassName: null
[INFO] ignoredProblems: null
[INFO] javaCompilerExtraOptions: null
[INFO] extraSystemPath: null
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:415 - no configuration file found at /home/alex/jsweet-bugs/bug3/jsweetconfig.json
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:520 - creating transpiler version 3.1.0 (build date: 2021-04-21 20:24:55)
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:522 - current dir: /home/alex/jsweet-bugs/bug3/.
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:523 - base directory: /home/alex/jsweet-bugs/bug3
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:524 - working directory: /home/alex/jsweet-bugs/bug3/.jsweet
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:525 - tsOut: /home/alex/jsweet-bugs/bug3/target/ts - /home/alex/jsweet-bugs/bug3/target/ts
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:526 - jsOut: /home/alex/jsweet-bugs/bug3/target/js - /home/alex/jsweet-bugs/bug3/target/js
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:527 - candyJsOut: /home/alex/jsweet-bugs/bug3/webapp/candies
2021-09-27 10:23:36.036 INFO  JSweetTranspiler:528 - factory: org.jsweet.transpiler.JSweetFactory@5ff90645
2021-09-27 10:23:36.036 DEBUG JSweetTranspiler:529 - compile classpath: /home/alex/jsweet-bugs/bug3/jsweet_extension:/home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar:/home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar
2021-09-27 10:23:36.036 DEBUG JSweetTranspiler:530 - runtime classpath: /usr/share/maven/boot/plexus-classworlds-2.x.jar
2021-09-27 10:23:36.036 DEBUG JSweetTranspiler:531 - extension directory: /home/alex/jsweet-bugs/bug3/jsweet_extension
2021-09-27 10:23:36.036 INFO  CandyProcessor:123 - candies processor classpath: /home/alex/jsweet-bugs/bug3/jsweet_extension:/home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar:/home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar
2021-09-27 10:23:36.036 INFO  CandyProcessor:141 - extracted candies directory: /home/alex/jsweet-bugs/bug3/webapp/candies
[INFO] source includes: {}
[INFO] source excludes: {}
[INFO] sources paths: [/home/alex/jsweet-bugs/bug3/src/main/java]
[INFO] sources paths from resources: [/home/alex/jsweet-bugs/bug3/src/main/java]
[INFO] sourceFiles=[/home/alex/jsweet-bugs/bug3/src/main/java/quickstart/QuickStart.java, /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java]
2021-09-27 10:23:36.036 DEBUG ProcessUtil:67 - extra path: 
2021-09-27 10:23:36.036 INFO  ProcessUtil:138 - cannot find tsc - searching in /home/alex/.jsweet.v3-node_modules
2021-09-27 10:23:36.036 INFO  CandyProcessor:226 - 2 candies found in classpath
2021-09-27 10:23:36.036 INFO  CandyProcessor:163 - candies are up to date
2021-09-27 10:23:36.036 DEBUG JavaCompilationComponents:106 - charset: UTF-8
2021-09-27 10:23:36.036 DEBUG JavaCompilationComponents:107 - strict mode: false
2021-09-27 10:23:36.036 INFO  JavaCompilationComponents:122 - creating JavaCompiler task with options: JavaCompilerOptions: [--module-path, /home/alex/jsweet-bugs/bug3/jsweet_extension:/home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar:/home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar, -cp, /home/alex/jsweet-bugs/bug3/jsweet_extension:/home/alex/.m2/repository/org/jsweet/candies/jquery/1.10.0-20170726/jquery-1.10.0-20170726.jar:/home/alex/.m2/repository/org/jsweet/jsweet-core/6.3.0/jsweet-core-6.3.0.jar, -Xlint:path, -encoding, UTF-8]
2021-09-27 10:23:37.037 ERROR output:55 - package exists in another module: java.desktop at /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java(1)
2021-09-27 10:23:37.037 ERROR JSweetTranspiler:99 - /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java:1: error: package exists in another module: java.desktop
package java.awt;
^
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:951 - scanning /home/alex/jsweet-bugs/bug3/src/main/java/quickstart/QuickStart.java...
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:977 - output file: quickstart/QuickStart.ts
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:1002 - created /home/alex/jsweet-bugs/bug3/target/ts/quickstart/QuickStart.ts
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:951 - scanning /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java...
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:977 - output file: java/awt/Color.ts
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:1002 - created /home/alex/jsweet-bugs/bug3/target/ts/java/awt/Color.ts
2021-09-27 10:23:38.038 INFO  JSweetTranspiler:841 - transpilation process finished in 1903 ms 
> java2ts: 1783.975263ms
> ts2js: 8.38E-4ms

[ERROR] transpilation failed
org.apache.maven.plugin.MojoFailureException: transpilation failed with 1 error(s) and 0 warning(s)

=========================================
TRANSPILATION ERRORS SUMMARY:
* /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java(1,1)package exists in another module: java.desktop

=========================================
    at org.jsweet.AbstractJSweetMojo.transpile (AbstractJSweetMojo.java:701)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.479 s
[INFO] Finished at: 2021-09-27T10:23:38+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jsweet:jsweet-maven-plugin:3.1.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] * /home/alex/jsweet-bugs/bug3/src/main/java/java/awt/Color.java(1,1)package exists in another module: java.desktop
[ERROR] 
[ERROR] 
[ERROR] =========================================
[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
lgrignon commented 2 years ago

JSweet 3's strategy for J4TS was to avoid overriding core packages since it's restricted and actually not necessary. Switching to a j4ts.awt package, with a @Name("java.awt") would work I think. The only important thing is to provide the proper .js and .d.ts in src/main/resources/META-INF/resources/webjars/${project.artifactId}/${project.version}/

AlexGeller1 commented 2 years ago

JSweet 3's strategy for J4TS was to avoid overriding core packages since it's restricted and actually not necessary.

If it is not necessary then of course I will not do it. But how then do I compile code that has references to java.awt.Color for example?

lgrignon commented 2 years ago

java.awt.Color is part of core Java classes, so Java compilation will pass, and you have to embed your j4ts.d.ts and j4ts.js (or any other def & runtime implementation) in a project's candy to make ts2js transpilation pass and the projet to run.

Is there any additional information that could help you?

AlexGeller1 commented 2 years ago

Is there any additional information that could help you?

Yes, I want to implement java.awt.Color in Java (not in TypeScript or JavaScript) since there is absolutely no need for native code in the implementation of this class and for many more classes from the java.awt package. Even Graphics2D is a purely abstract class without any browser dependencies in the original implementation. Is that possible (to implement these classes in Java) and if yes, how. Ideally we also want to implement those classes in a lazy fashion because there are so many and we don't use all of them and we don't call all methods from these classes and so there is no technical need for the implementations to be complete. Ideally I would like to implement java.awt.Color for example without the method Color.HSBtoRGB() if the code that I am porting never calls this method. We need a pragmatic and easy way to compile existing code that uses some core library functionality. Prior to version 3.1.0 this path existed. Correct me if I am wrong, I am currently under the impression that your approach to the implementation of core classes is, that they are implemented in TypeScript or there is some non standard or complicated way (I haven't yet evaluated your proposal for this so that I might be wrong on this) to implement them in Java. But the original core libraries themselves are written for the largest part in pure Java without native calls so that for us it would be nice if there were an easy way to do the same thing and write a class like java.awt.Color in Java.

lgrignon commented 2 years ago

That's totally possible, that's what we do. As I mentionned earlier, I would put my Java classes in a my.awt package, with a @Name("java.awt") on the package-info, and it should do the trick to be transpiled to a proper .d.ts and .js, to be bundled in a candy.