Skip to content

Commit 2faabd9

Browse files
committed
[jrubyscripting] Support using Gemfile with Bundler
Signed-off-by: Jimmy Tanagra <[email protected]>
1 parent 95d3179 commit 2faabd9

File tree

6 files changed

+283
-176
lines changed

6 files changed

+283
-176
lines changed

bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java

+26-15
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ private void info(Console console) {
220220
}
221221
console.println(groupLabel);
222222
parameters.forEach(parameter -> {
223-
console.println(" " + parameter.getName() + ": " + config.get(parameter.getName()));
223+
console.print(" " + parameter.getName() + ": ");
224+
String value = config.get(parameter.getName());
225+
if (value.contains("\n")) {
226+
console.println(" (multiline)");
227+
console.println(" " + value.replace("\n", "\n "));
228+
} else {
229+
console.println(value);
230+
}
224231
});
225232
console.println("");
226233
});
@@ -303,7 +310,20 @@ private void startConsole(Console console, Session session, String[] args) {
303310
}
304311

305312
synchronized private void bundler(Console console, String[] args) {
313+
final String gemfilePath = jRubyScriptEngineFactory.getConfiguration().getGemfilePath();
314+
if (gemfilePath == null) {
315+
console.println(
316+
"No Gemfile configured. Please set the 'bundle_gemfile_path' or 'bundle_gemfile_content' property in the add-on configuration.");
317+
return;
318+
}
319+
320+
// we have to split this because we dont want to format the string with ruby '%w' in it
306321
final String BUNDLER = """
322+
require 'jruby'
323+
JRuby.runtime.instance_config.update_native_env_enabled = false
324+
ENV['BUNDLE_GEMFILE'] = '%s'
325+
""".formatted(gemfilePath) + """
326+
307327
require "bundler"
308328
require "bundler/friendly_errors"
309329
@@ -319,20 +339,11 @@ synchronized private void bundler(Console console, String[] args) {
319339
end
320340
""";
321341

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-
}
342+
executeWithPlainJRuby(console, engine -> {
343+
engine.put(ScriptEngine.ARGV, args);
344+
engine.eval(BUNDLER);
345+
return null;
346+
});
336347
}
337348

338349
synchronized private void gem(Console console, String[] args) {

0 commit comments

Comments
 (0)