@@ -53,35 +53,18 @@ import (
5353// LanguageRuntimeServer RPC endpoint.
5454func main () {
5555 var tracing string
56- var root string
57- var binary string
5856 flag .StringVar (& tracing , "tracing" , "" , "Emit tracing to a Zipkin-compatible tracing endpoint" )
59- flag .StringVar (& root , "root" , "" , "Project root path to use" )
60- flag .StringVar (& binary , "binary" , "" , "JAR or a JBang entry-point file to execute" )
6157
62- // You can use the below flag to request that the language host load a specific executor instead of probing the
63- // PATH. This can be used during testing to override the default location.
64- var useExecutor string
65- flag .StringVar (& useExecutor , "use-executor" , "" ,
66- "Use the given program as the executor instead of looking for one on PATH" )
58+ flag .String ("root" , "" , "[obsolete] Project root path to use" )
59+ flag .String ("binary" , "" , "[obsolete] JAR or a JBang entry-point file to execute" )
60+ flag .String ("use-executor" , "" , "[obsolete] Use the given program as the executor instead of looking for one on PATH" )
6761
6862 flag .Parse ()
6963 var cancelChannel chan bool
7064 args := flag .Args ()
7165 logging .InitLogging (false , 0 , false )
7266 cmdutil .InitTracing ("pulumi-language-java" , "pulumi-language-java" , tracing )
7367
74- wd , err := os .Getwd ()
75- if err != nil {
76- cmdutil .Exit (fmt .Errorf ("could not get the working directory: %w" , err ))
77- }
78-
79- javaExecOptions := executors.JavaExecutorOptions {
80- Binary : binary ,
81- UseExecutor : useExecutor ,
82- WD : fsys .DirFS (wd ),
83- }
84-
8568 // Optionally pluck out the engine so we can do logging, etc.
8669 var engineAddress string
8770 if len (args ) > 0 {
@@ -97,7 +80,7 @@ func main() {
9780 handle , err := rpcutil .ServeWithOptions (rpcutil.ServeOptions {
9881 Cancel : cancelChannel ,
9982 Init : func (srv * grpc.Server ) error {
100- host := newLanguageHost (javaExecOptions , engineAddress , tracing )
83+ host := newLanguageHost (engineAddress , tracing )
10184 pulumirpc .RegisterLanguageRuntimeServer (srv , host )
10285 return nil
10386 },
@@ -142,37 +125,68 @@ func setupHealthChecks(engineAddress string) (chan bool, error) {
142125type javaLanguageHost struct {
143126 pulumirpc.UnimplementedLanguageRuntimeServer
144127
145- execOptions executors.JavaExecutorOptions
146128 engineAddress string
147129 tracing string
148130}
149131
150- func newLanguageHost (execOptions executors. JavaExecutorOptions ,
132+ func newLanguageHost (
151133 engineAddress , tracing string ,
152134) pulumirpc.LanguageRuntimeServer {
153135 return & javaLanguageHost {
154- execOptions : execOptions ,
155136 engineAddress : engineAddress ,
156137 tracing : tracing ,
157138 }
158139}
159140
160- func (host * javaLanguageHost ) Executor (attachDebugger bool ) (* executors.JavaExecutor , error ) {
161- executor , err := executors .NewJavaExecutor (host .execOptions , attachDebugger )
141+ func (host * javaLanguageHost ) Executor (
142+ execOptions executors.JavaExecutorOptions , attachDebugger bool ,
143+ ) (* executors.JavaExecutor , error ) {
144+ executor , err := executors .NewJavaExecutor (execOptions , attachDebugger )
162145 if err != nil {
163146 return nil , err
164147 }
165148 return executor , nil
166149}
167150
151+ func (host * javaLanguageHost ) parseExecOptions (info * pulumirpc.ProgramInfo ) (executors.JavaExecutorOptions , error ) {
152+ javaOptions := executors.JavaExecutorOptions {
153+ WD : fsys .DirFS (info .ProgramDirectory ),
154+ }
155+
156+ options := info .Options .AsMap ()
157+
158+ if binary , ok := options ["binary" ]; ok {
159+ if binary , ok := binary .(string ); ok {
160+ javaOptions .Binary = binary
161+ } else {
162+ return javaOptions , errors .New ("binary option must be a string" )
163+ }
164+ }
165+
166+ if executor , ok := options ["use-executor" ]; ok {
167+ if executor , ok := executor .(string ); ok {
168+ javaOptions .UseExecutor = executor
169+ } else {
170+ return javaOptions , errors .New ("use-executor option must be a string" )
171+ }
172+ }
173+
174+ return javaOptions , nil
175+ }
176+
168177// GetRequiredPackages computes the complete set of anticipated packages required by a program.
169178func (host * javaLanguageHost ) GetRequiredPackages (
170179 ctx context.Context ,
171180 req * pulumirpc.GetRequiredPackagesRequest ,
172181) (* pulumirpc.GetRequiredPackagesResponse , error ) {
173182 logging .V (5 ).Infof ("GetRequiredPackages: programDirectory=%v" , req .Info .ProgramDirectory )
174183
175- pulumiPackages , err := host .determinePulumiPackages (ctx , req .Info .ProgramDirectory )
184+ execOptions , err := host .parseExecOptions (req .Info )
185+ if err != nil {
186+ return nil , fmt .Errorf ("parsing options: %w" , err )
187+ }
188+
189+ pulumiPackages , err := host .determinePulumiPackages (ctx , execOptions , req .Info .ProgramDirectory )
176190 if err != nil {
177191 return nil , errors .Wrapf (err , "language host could not determine Pulumi packages" )
178192 }
@@ -215,11 +229,12 @@ func (host *javaLanguageHost) GetRequiredPlugins(
215229
216230func (host * javaLanguageHost ) determinePulumiPackages (
217231 ctx context.Context ,
232+ execOptions executors.JavaExecutorOptions ,
218233 programDirectory string ,
219234) ([]plugin.PulumiPluginJSON , error ) {
220235 logging .V (3 ).Infof ("GetRequiredPlugins: Determining Pulumi plugins" )
221236
222- exec , err := host .Executor (false )
237+ exec , err := host .Executor (execOptions , false )
223238 if err != nil {
224239 return nil , err
225240 }
@@ -324,6 +339,12 @@ func (host *javaLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
324339 }
325340 defer contract .IgnoreClose (closer )
326341
342+ execOptions , err := host .parseExecOptions (req .Info )
343+ if err != nil {
344+ return nil , fmt .Errorf ("parsing options: %w" , err )
345+ }
346+ execOptions .ProgramArgs = req .Args
347+
327348 config , err := host .constructConfig (req )
328349 if err != nil {
329350 err = errors .Wrap (err , "failed to serialize configuration" )
@@ -335,7 +356,7 @@ func (host *javaLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
335356 return nil , err
336357 }
337358
338- executor , err := host .Executor (req .GetAttachDebugger ())
359+ executor , err := host .Executor (execOptions , req .GetAttachDebugger ())
339360 if err != nil {
340361 return nil , err
341362 }
@@ -421,15 +442,13 @@ func (host *javaLanguageHost) RunPlugin(
421442 // Best effort close, but we try an explicit close and error check at the end as well
422443 defer closer .Close ()
423444
424- // Create new executor options with the plugin directory and runtime args
425- pluginExecOptions := executors.JavaExecutorOptions {
426- Binary : host .execOptions .Binary ,
427- UseExecutor : host .execOptions .UseExecutor ,
428- WD : fsys .DirFS (req .Info .ProgramDirectory ),
429- ProgramArgs : req .Args ,
445+ execOptions , err := host .parseExecOptions (req .Info )
446+ if err != nil {
447+ return fmt .Errorf ("parsing options: %w" , err )
430448 }
449+ execOptions .ProgramArgs = req .Args
431450
432- executor , err := executors .NewJavaExecutor (pluginExecOptions , req .GetAttachDebugger ())
451+ executor , err := executors .NewJavaExecutor (execOptions , req .GetAttachDebugger ())
433452 if err != nil {
434453 return err
435454 }
@@ -645,7 +664,12 @@ func (host *javaLanguageHost) GetPluginInfo(_ context.Context, _ *pbempty.Empty)
645664func (host * javaLanguageHost ) InstallDependencies (req * pulumirpc.InstallDependenciesRequest ,
646665 server pulumirpc.LanguageRuntime_InstallDependenciesServer ,
647666) error {
648- executor , err := host .Executor (false )
667+ execOptions , err := host .parseExecOptions (req .Info )
668+ if err != nil {
669+ return fmt .Errorf ("parsing options: %w" , err )
670+ }
671+
672+ executor , err := host .Executor (execOptions , false )
649673 if err != nil {
650674 return err
651675 }
@@ -683,7 +707,12 @@ func (host *javaLanguageHost) GetProgramDependencies(
683707 ctx context.Context ,
684708 req * pulumirpc.GetProgramDependenciesRequest ,
685709) (* pulumirpc.GetProgramDependenciesResponse , error ) {
686- executor , err := host .Executor (false )
710+ execOptions , err := host .parseExecOptions (req .Info )
711+ if err != nil {
712+ return nil , fmt .Errorf ("parsing options: %w" , err )
713+ }
714+
715+ executor , err := host .Executor (execOptions , false )
687716 if err != nil {
688717 return nil , err
689718 }
0 commit comments