@@ -181,14 +181,17 @@ public Object execute(Session session, List<Object> argList) throws Exception {
181
181
}
182
182
183
183
private void info (Console console ) {
184
+ String gemfile = jRubyScriptEngineFactory .getConfiguration ().getGemfilePath ();
184
185
final String PRINT_VERSION_NUMBERS = """
185
186
library_version = defined?(OpenHAB::DSL::VERSION) && OpenHAB::DSL::VERSION
186
187
187
188
puts "JRuby #{JRUBY_VERSION}"
188
189
puts "JRuby Scripting Library #{library_version || 'is not installed'}"
189
- puts "GEM_HOME: #{ENV['GEM_HOME']}"
190
- puts "RUBYLIB: #{ENV['RUBYLIB']}"
191
- """ ;
190
+ puts "ENV['GEM_HOME']: #{ENV['GEM_HOME']}"
191
+ puts "ENV['RUBYLIB']: #{ENV['RUBYLIB']}"
192
+ """ + (gemfile == null ? "" : """
193
+ puts "ENV['BUNDLE_GEMFILE']: #{ENV['BUNDLE_GEMFILE']}"
194
+ """ );
192
195
193
196
executeWithFullJRuby (console , engine -> engine .eval (PRINT_VERSION_NUMBERS ));
194
197
console .println ("Script path: " + scriptFileWatcher .getWatchPath ());
@@ -220,7 +223,14 @@ private void info(Console console) {
220
223
}
221
224
console .println (groupLabel );
222
225
parameters .forEach (parameter -> {
223
- console .println (" " + parameter .getName () + ": " + config .get (parameter .getName ()));
226
+ console .print (" " + parameter .getName () + ": " );
227
+ String value = config .get (parameter .getName ());
228
+ if (value .contains ("\n " )) {
229
+ console .println (" (multiline)" );
230
+ console .println (" " + value .replace ("\n " , "\n " ));
231
+ } else {
232
+ console .println (value );
233
+ }
224
234
});
225
235
console .println ("" );
226
236
});
@@ -303,7 +313,20 @@ private void startConsole(Console console, Session session, String[] args) {
303
313
}
304
314
305
315
synchronized private void bundler (Console console , String [] args ) {
316
+ final String gemfilePath = jRubyScriptEngineFactory .getConfiguration ().getGemfilePath ();
317
+ if (gemfilePath == null ) {
318
+ console .println (
319
+ "No Gemfile configured. Please set the 'bundle_gemfile_path' or 'bundle_gemfile_content' property in the add-on configuration." );
320
+ return ;
321
+ }
322
+
323
+ // we have to split this because we dont want to format the string with ruby '%w' in it
306
324
final String BUNDLER = """
325
+ require 'jruby'
326
+ JRuby.runtime.instance_config.update_native_env_enabled = false
327
+ ENV['BUNDLE_GEMFILE'] = '%s'
328
+ """ .formatted (gemfilePath ) + """
329
+
307
330
require "bundler"
308
331
require "bundler/friendly_errors"
309
332
@@ -319,20 +342,11 @@ synchronized private void bundler(Console console, String[] args) {
319
342
end
320
343
""" ;
321
344
322
- String originalDir = System .setProperty ("user.dir" , scriptFileWatcher .getWatchPath ().toString ());
323
- try {
324
- executeWithPlainJRuby (console , engine -> {
325
- engine .put (ScriptEngine .ARGV , args );
326
- engine .eval (BUNDLER );
327
- return null ;
328
- });
329
- } finally {
330
- if (originalDir == null ) {
331
- System .clearProperty ("user.dir" );
332
- } else {
333
- System .setProperty ("user.dir" , originalDir );
334
- }
335
- }
345
+ executeWithPlainJRuby (console , engine -> {
346
+ engine .put (ScriptEngine .ARGV , args );
347
+ engine .eval (BUNDLER );
348
+ return null ;
349
+ });
336
350
}
337
351
338
352
synchronized private void gem (Console console , String [] args ) {
@@ -488,7 +502,7 @@ private List<String> getUsages() {
488
502
buildCommandUsage (INFO , "displays information about JRuby Scripting add-on" ), //
489
503
buildCommandUsage (CONSOLE + " [--list|-l|--help|-h] | [script] [options]" ,
490
504
"starts an interactive JRuby console" ), //
491
- buildCommandUsage (BUNDLE + " [arguments]" , "runs Ruby bundler in the main Script path " ), //
505
+ buildCommandUsage (BUNDLE + " [arguments]" , "runs Ruby bundler with the configured Gemfile " ), //
492
506
buildCommandUsage (GEM + " [arguments]" , "manages JRuby Scripting add-on's RubyGems" ), //
493
507
buildCommandUsage (UPDATE , "updates the configured gems" ), //
494
508
buildCommandUsage (PRUNE + " [-f|--force]" , "cleans up older versions in the .gem directory" ) //
0 commit comments