krotoplus.script.cache.dir is not respected
AlexeySoshin opened this issue · comments
We have a case when KrotoPlus projects needs to run in a sandboxed environment.
In this case, it tries to create scripts cache, but fails, since sandbox doesn't allow it to generate a file at HOME
level.
In theory, there's krotoplus.script.cache.dir
property for that:
But it doesn't seem to work in any way:
-Dkrotoplus.script.cache.dir=./some_dir
Will reflect correctly when used as System.getProperty("krotoplus.script.cache.dir")
in the main script, but not by ScriptManager
My theory is there's some kind of forking happening while generating scripts, and the original property is lost. This is supported by the following stack trace:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: <screened> : warning: directory does not exist.
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at com.github.marcoferrer.krotoplus.script.ScriptManager.compileAndWriteToFs(ScriptManager.kt:125)
at com.github.marcoferrer.krotoplus.script.ScriptManager.getOrLoadCompiledClasses(ScriptManager.kt:118)
at com.github.marcoferrer.krotoplus.script.ScriptManager.getScript$protoc_gen_kroto_plus(ScriptManager.kt:90)
at com.github.marcoferrer.krotoplus.script.ScriptManager.getScript$protoc_gen_kroto_plus(ScriptManager.kt:96)
at com.github.marcoferrer.krotoplus.generators.GeneratorScriptsGenerator.invoke(GeneratorScriptsGenerator.kt:32)
at com.github.marcoferrer.krotoplus.generators.GeneratorScriptsGenerator.invoke(GeneratorScriptsGenerator.kt:22)
at com.github.marcoferrer.krotoplus.KrotoPlusProtoCMain$main$deferredGenResponse$1$2$1.invokeSuspend(KrotoPlusProtoCMain.kt:48)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
--kroto_out: protoc-gen-kroto: Plugin failed with status code 1.
Suggestion would be to use System.getenv
instead of System.getProperty()
, as ENV would propagate from OS.
Good catch. I think what’s happening is that since Gradle is invoking the plugin as an executable and not a jar, the properties are never propagated. I like the idea of using system env since protoc plugin options don’t play nice with path values on windows.