gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

Windows: unable to run headless batch on a file with the absolute path #3682

Closed lesquoyb closed 1 year ago

lesquoyb commented 1 year ago

Describe the bug I have my gama installation on disk D and want to run a batch experiment from a file that is stored on my C drive through headless, but when I run this command:

.\gama-headless.bat -batch Optimization "C:\Users\baptiste\.eclipse\306334380_win32_win32_x86_64\configuration\org.eclipse.osgi\713\0\.cp\models\Tutorials\Predator Prey\models\Model 13.gaml"

It raises an error, and here is the corresponding log file content:

!SESSION 2023-03-23 14:37:11.666 -----------------------------------------------
eclipse.buildId=${build.id}
java.version=17.0.4.1
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -application msi.gama.headless.product -batch Optimization C:\Users\baptiste\.eclipse\306334380_win32_win32_x86_64\configuration\org.eclipse.osgi\713\0\.cp\models\Tutorials\Predator Prey\models\Model 13.gaml
Command-line arguments:  -application msi.gama.headless.product -data .work18743 -batch Optimization C:\Users\baptiste\.eclipse\306334380_win32_win32_x86_64\configuration\org.eclipse.osgi\713\0\.cp\models\Tutorials\Predator Prey\models\Model 13.gaml

!ENTRY org.eclipse.osgi 4 0 2023-03-23 14:37:14.072
!MESSAGE Application error
!STACK 1
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.net.MalformedURLException: unknown protocol: c
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
    at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:266)
    at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:33)
    at msi.gama.lang.gaml.validation.GamlModelBuilder.buildModelDescription(GamlModelBuilder.java:111)
    at msi.gama.lang.gaml.validation.GamlModelBuilder.compile(GamlModelBuilder.java:97)
    at msi.gama.headless.runtime.Application.runBatchSimulation(Application.java:576)
    at msi.gama.headless.runtime.Application.start(Application.java:359)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1440)
    at org.eclipse.core.launcher.Main.main(Main.java:44)
Caused by: java.net.MalformedURLException: unknown protocol: c
    at java.base/java.net.URL.<init>(URL.java:681)
    at java.base/java.net.URL.<init>(URL.java:569)
    at java.base/java.net.URL.<init>(URL.java:516)
    at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createInputStream(URIHandlerImpl.java:199)
    at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:358)
    at org.eclipse.xtext.resource.XtextResourceSet$1.createInputStream(XtextResourceSet.java:299)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1314)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
    ... 20 more

If I move the file to my D drive (the one from which I run the command) it still doesn't work if I give the absolute path:

.\gama-headless.bat -batch Optimization "D:\Model 13.gaml"

but if I change to a relative path, it finally works:

 .\gama-headless.bat -batch Optimization "..\..\..\..\..\..\Model 13.gaml"

To Reproduce Steps to reproduce the behavior:

  1. run a batch headless on a file, giving it's absolute path
  2. See error

Expected behavior Absolute paths work as well as relative paths for batch experiments.

Additional context Headless legacy doesn't seem to have that problem: I can run the other experiment stored in that same file with headless legacy with these commands without any problem:

.\gama-headless.bat -xml prey_predator 'C:\Users\baptiste\.eclipse\306334380_win32_win32_x86_64\configuration\org.eclipse.osgi\713\0\.cp\models\Tutorials\Predator Prey\models\Model 13.gaml' test2.xml
.\gama-headless.bat .\test2.xml output
AlexisDrogoul commented 1 year ago

I think it is more a problem of the "c:" and "d:", etc. than absolute or relative. There is no absolute root on Windows ? Maybe adding the correct protocol (like "file:") can help ?

lesquoyb commented 1 year ago

To my knowledge, absolute paths on windows start with the drive letter, there's no "absolute root" like it's the case on linux/macos. Using a path made following the file protocol way gives me another error:

Unable to read input file file:///C|Users/lesqu/.eclipse/306334380_win32_win32_x86_64/configuration/org.eclipse.osgi/241/0/.cp/models/Tutorials/Predator Prey/models/Model 13.gaml. File not exist!

I tried all the variations possible for the path (different separators, escaping or not, quotes around or not etc.)

AlexisDrogoul commented 1 year ago

So I assume that you tried all the combinations specified here : https://stackoverflow.com/questions/5032424/how-can-i-specify-a-windows-drive-letter-when-using-subversion-svnssh ?

AlexisDrogoul commented 1 year ago

I also found other weird combinations : properties.put(Context.PROVIDER_URL,"file://\\d:\\tmp\\mycontext"); (here: https://stackoverflow.com/questions/3688132/how-can-i-specifiy-the-drive-letter-windows-for-the-provider-url-of-the-jndi-i)

lesquoyb commented 1 year ago

Yes, though I realised I had another problem in my path with the spaces. So after some tweaking to get a model in a path without any space, turns out that using this protocol calls the Windows api to open the file with the default program associated with .gaml files (in my case gama GUI). And the script is still not able to read the path: image

AlexisDrogoul commented 1 year ago

This behavior is normal. The gui version of GAMA tries to open/import the file you are mentioning (default action is "openFile") and discovers it is not part of a project. Why do you try to run it instead of the .bat ?

lesquoyb commented 1 year ago

I didn't try to open it myself, that's what I've been trying to say, writing file:///... in the command calls that behaviour. What you see is only the result of the command at the first line in the command prompt. Trying to neutralise it by surrounding it with double quotes only brings us back to the file not exist stuff

hqnghi88 commented 1 year ago

Just in case, In msi.gama.headless, Application.java, line 576, if we change from createURI to createFileURI, it will recognize well the absolute path. image

hqnghi88 commented 1 year ago

Relate to this issue https://github.com/gama-platform/gama/issues/3417 and commit https://github.com/gama-platform/gama/commit/bbd38c85b6d93f4f7afe712a44d788c533d77dde @RoiArthurB

AlexisDrogoul commented 1 year ago

But are we going to always have FileURIs to launch Gama Headless ? Shouldn't we enable the possibility, in case createFileURI fails, to catch the Exception and try a simpler createURI?