kaby76 / Antlr4BuildTasks

Third-party build tool for 'Official' Antlr4 tool and runtime parsers using .Net. Drop-in replacement for 'Antlr4cs' Antlr4 tool and build rules.
MIT License
75 stars 10 forks source link

ANT02 Cannot find Java executable'' With csproj multitargeting #48

Open lionelberton opened 2 years ago

lionelberton commented 2 years ago

In csproj files, we are using multiple targets <TargetFrameworks>net472;net6.0-windows</TargetFrameworks>. This is not working with antlr4buildtasks when it downloads automatically java. Msbuild compile both targets at the same time and I suspect that antl4builtasks is trying to download and unzip java in the same folder at the same time which is not working. If I remove one target, it builds fine.

You should change the way you manage ".jre" folder to handle multiple projects building in parallel.

error ANT02: Cannot find Java executable''   à Antlr4.Build.Tasks.RunAntlrTool.SetupJava()
error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.Execute()
error ANT02: The Antlr4 tool failed.
kaby76 commented 2 years ago

The easy workaround is to just repeat the build. The second time the directory .jre will be unpacked with java. Will see if I can add a lock to the code for a later fix.

kaby76 commented 2 years ago

I added a lock around the download/extraction of Java, and it seems to work on Windows 11 on my machine. Version 11.3 of Antlr4BuildTasks.

lionelberton commented 2 years ago

11.3 does not solve the problem. I still can't regenerate the project in multitargeting. Cleanup also has the problem. Both threads seems to try to clean the same folder.

detailed log is as follow:

1>      Antlr4Compile cible :
1>        Utilisation de la tâche "RunAntlrTool" à partir de l'assembly "C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.3.0\build\..\lib\netstandard2.0\Antlr4BuildTasks.dll".
1>        Tâche "RunAntlrTool"
1>          Génération complète de la cible "Antlr4Compile".
1>          Le fichier de sortie "obj\Debug\net472\DOTCore.csproj.AntlrToCompileList.txt" n'existe pas.
1>          Tâche "Message"
1>            Running the Java Antlr Tool over the grammar files 'DOTParser\DotParser.g4'.
1>          Exécution de la tâche "Message" terminée.
1>          Utilisation de la tâche "RunAntlrTool" à partir de l'assembly "C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.3.0\build\..\lib\netstandard2.0\Antlr4BuildTasks.dll".
1>          Tâche "RunAntlrTool"
1>            Starting Antlr4 Build Tasks.
1>            Placing generated files in IntermediateOutputPath C:\Users\Lionel BERTON\source\repos\Flowers\Tools\DOTViewerWPF\DOTCore\obj\Debug\net472\
1>            Antlr4BuildTasks identified that you are looking for version 4.11.1 of the Antlr4 tool jar.
1>            Version '4.11.1' v2 match='', v3 match='4.11.1'
1>            Location to stuff Antlr tool jar, if not found, is C:/Users/Lionel BERTON/.m2/
1>            Paths to search for Antlr4 jar, in order, are: file:///C:/Users/Lionel BERTON/.m2/;file:///C:\Users\Lionel BERTON\source\repos\Flowers\Tools\DOTViewerWPF\DOTCore\obj\Debug\net472\;https://repo1.maven.org/maven2/org/antlr/antlr4/
1>            path is file:///C:/Users/Lionel BERTON/.m2/
1>            place_path is C:/Users/Lionel BERTON/.m2/
1>            Probing file:///C:/Users/Lionel BERTON/.m2/antlr4-4.11.1-complete.jar
1>            Local path C:\Users\Lionel BERTON\.m2\antlr4-4.11.1-complete.jar
1>            Found.
1>            AntlrToolJar is "C:\Users\Lionel BERTON\.m2\antlr4-4.11.1-complete.jar"
1>            Location to stuff JRE, if not found, is C:/Users/Lionel BERTON/.jre/
1>            Paths to search for Antlr4 jar, in order, are: PATH;DOWNLOAD
1>            path is PATH
1>            java.exe not found on path
1>            path is DOWNLOAD
1>            Probing DOWNLOAD
1>            Downloading OpenJDK11U-jre_x64_windows_hotspot_11.0.15_10.zip
1>            C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.3.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: Cannot find Java executable''   à Antlr4.Build.Tasks.RunAntlrTool.SetupJava()
1>            C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.3.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.Execute()
1>            C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.3.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed.
1>          Exécution de la tâche "RunAntlrTool" terminée -- ÉCHEC.
1>        Génération de la cible "Antlr4Compile" terminée dans le projet "DOTCore.csproj" -- ÉCHEC.
kaby76 commented 2 years ago

The problem is specific to Windows.

Added Windows to CI builds. The Mac OS decompression code does not work, but I can't get a Mac environment without java in Github Actions because it automatically installs one, and the java that is installed does not take "java --version".

kaby76 commented 2 years ago
The process cannot access the file 'C:\Users\runneradmin\.jre\OpenJDK11U-jre_x64_windows_hotspot_11.0.15_10.zip' because it is being used by another process.

I've assumed that dotnet was a single process, multi-threaded. It isn't. Need to lock across all processes. Easy fix.

kaby76 commented 2 years ago

Please try version 11.4. I think it should fix the problem you are seeing. (I added a test to the CI build for multitarget builds, for both Windows and Ubuntu.)

lionelberton commented 2 years ago

It does not work any better with 11.5.0:

1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.5.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: Cannot find Java executable''   à Antlr4.Build.Tasks.RunAntlrTool.SetupJava()
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.5.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.Execute()
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.5.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed.
lionelberton commented 2 years ago

With 11.4.0, it does not work either but the message is different:

1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: Le processus ne peut pas accéder au fichier 'C:\Users\Lionel BERTON\.jre\OpenJDK11U-jre_x64_windows_hotspot_11.0.15_10.zip', car il est en cours d'utilisation par un autre processus.   à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à System.IO.Compression.ZipFile.Open(String archiveFileName, ZipArchiveMode mode, Encoding entryNameEncoding)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.DecompressJava(String uncompressed_root_dir, String archive_name)
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: Cannot find Java executable''   à Antlr4.Build.Tasks.RunAntlrTool.SetupJava()
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.Execute()
1>C:\Users\Lionel BERTON\.nuget\packages\antlr4buildtasks\11.4.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed.