openhab-jrubyscripting 5.0.0.rc2 → 5.0.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openhab/core/actions.rb +6 -2
- data/lib/openhab/core/items/generic_item.rb +13 -5
- data/lib/openhab/core/items/metadata/hash.rb +19 -35
- data/lib/openhab/core/items/persistence.rb +3 -1
- data/lib/openhab/core/items/semantics/enumerable.rb +6 -4
- data/lib/openhab/core/items/semantics.rb +18 -22
- data/lib/openhab/core/profile_factory.rb +15 -3
- data/lib/openhab/core/provider.rb +11 -4
- data/lib/openhab/core/rules/module.rb +26 -0
- data/lib/openhab/core/rules/provider.rb +40 -0
- data/lib/openhab/core/rules/registry.rb +76 -0
- data/lib/openhab/core/rules/rule.rb +150 -0
- data/lib/openhab/core/rules.rb +25 -0
- data/lib/openhab/core/script_handling.rb +32 -3
- data/lib/openhab/core/timer.rb +5 -7
- data/lib/openhab/core/types.rb +1 -1
- data/lib/openhab/core.rb +0 -16
- data/lib/openhab/core_ext/java/list.rb +436 -0
- data/lib/openhab/core_ext/java/map.rb +66 -0
- data/lib/openhab/core_ext/java/month.rb +1 -1
- data/lib/openhab/core_ext/java/zoned_date_time.rb +1 -2
- data/lib/openhab/core_ext/ruby/date.rb +3 -0
- data/lib/openhab/core_ext/ruby/date_time.rb +53 -0
- data/lib/openhab/core_ext/ruby/time.rb +88 -86
- data/lib/openhab/dsl/events/watch_event.rb +1 -1
- data/lib/openhab/dsl/items/builder.rb +8 -3
- data/lib/openhab/dsl/items/ensure.rb +6 -2
- data/lib/openhab/dsl/items/timed_command.rb +10 -11
- data/lib/openhab/dsl/rules/automation_rule.rb +36 -13
- data/lib/openhab/dsl/rules/builder.rb +100 -9
- data/lib/openhab/dsl/rules/name_inference.rb +0 -5
- data/lib/openhab/dsl/rules/rule_triggers.rb +1 -1
- data/lib/openhab/dsl/rules/terse.rb +1 -2
- data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +18 -54
- data/lib/openhab/dsl/rules/triggers/conditions/proc.rb +0 -3
- data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +1 -1
- data/lib/openhab/dsl/rules.rb +0 -21
- data/lib/openhab/dsl/thread_local.rb +2 -2
- data/lib/openhab/dsl/timer_manager.rb +3 -1
- data/lib/openhab/dsl/version.rb +1 -1
- data/lib/openhab/dsl.rb +12 -105
- data/lib/openhab/log.rb +9 -2
- data/lib/openhab/rspec/example_group.rb +42 -0
- data/lib/openhab/rspec/helpers.rb +31 -8
- data/lib/openhab/rspec/hooks.rb +6 -10
- data/lib/openhab/rspec/karaf.rb +50 -27
- data/lib/openhab/rspec/mocks/synchronous_executor.rb +11 -4
- data/lib/openhab/rspec/mocks/timer.rb +2 -1
- data/lib/openhab/rspec/suspend_rules.rb +4 -2
- metadata +24 -3
- data/lib/openhab/dsl/script_handling.rb +0 -6
data/lib/openhab/rspec/karaf.rb
CHANGED
@@ -77,7 +77,12 @@ module OpenHAB
|
|
77
77
|
|
78
78
|
return if service.get_instance("rspec")
|
79
79
|
|
80
|
-
|
80
|
+
begin
|
81
|
+
service.clone_instance(root_instance.name, "rspec", settings, false)
|
82
|
+
rescue java.lang.NullPointerException
|
83
|
+
retry if fix_rmi_registry_npe
|
84
|
+
raise
|
85
|
+
end
|
81
86
|
ensure
|
82
87
|
extra_loaders = ::JRuby.runtime.instance_config.extra_loaders
|
83
88
|
loader = extra_loaders.find { |l| l.class_loader == @karaf_instance_loader }
|
@@ -99,6 +104,7 @@ module OpenHAB
|
|
99
104
|
java.lang.System.set_property("felix.cm.dir", felix_cm)
|
100
105
|
# not handled by karaf instances
|
101
106
|
java.lang.System.set_property("openhab.userdata", path)
|
107
|
+
@oh_userdata = nil
|
102
108
|
java.lang.System.set_property("openhab.logdir", "#{path}/logs")
|
103
109
|
end
|
104
110
|
cleanup_instance
|
@@ -129,6 +135,7 @@ module OpenHAB
|
|
129
135
|
|
130
136
|
set_up_bundle_listener
|
131
137
|
wait_for_start
|
138
|
+
Mocks::SynchronousExecutor.instance.main_thread = Thread.current
|
132
139
|
set_jruby_script_presets
|
133
140
|
@main
|
134
141
|
end
|
@@ -258,8 +265,6 @@ module OpenHAB
|
|
258
265
|
props.remove("transformation")
|
259
266
|
props.remove("ui")
|
260
267
|
props.remove("binding") unless include_bindings
|
261
|
-
# except we need jrubyscripting
|
262
|
-
props.put("automation", "jrubyscripting")
|
263
268
|
cfg.update(props)
|
264
269
|
|
265
270
|
# configure persistence to use the mock service
|
@@ -302,7 +307,6 @@ module OpenHAB
|
|
302
307
|
private_constant :BLOCKED_BUNDLE_TREES
|
303
308
|
|
304
309
|
ALLOWED_BUNDLES = %w[
|
305
|
-
org.openhab.automation.jrubyscripting
|
306
310
|
org.openhab.core.io.monitor
|
307
311
|
].freeze
|
308
312
|
private_constant :ALLOWED_BUNDLES
|
@@ -420,12 +424,23 @@ module OpenHAB
|
|
420
424
|
java.util.Hashtable.new(org.osgi.framework.Constants::SERVICE_RANKING => 1.to_java(:int))
|
421
425
|
)
|
422
426
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
427
|
+
wait_for_service("org.openhab.core.thing.ThingManager") do |tm|
|
428
|
+
tm.class.field_accessor :bundleResolver
|
429
|
+
|
430
|
+
tm.bundleResolver = Mocks::BundleResolver.instance
|
431
|
+
|
432
|
+
require_relative "mocks/safe_caller"
|
433
|
+
field = tm.class.java_class.declared_field :safeCaller
|
434
|
+
field.accessible = true
|
435
|
+
field.set(tm, Mocks::SafeCaller.instance)
|
436
|
+
|
437
|
+
require_relative "mocks/thing_handler"
|
438
|
+
thf = Mocks::ThingHandlerFactory.instance
|
439
|
+
bundle = org.osgi.framework.FrameworkUtil.get_bundle(org.openhab.core.thing.Thing)
|
440
|
+
Mocks::BundleResolver.instance.register_class(thf.class, bundle)
|
441
|
+
bundle.bundle_context.register_service(org.openhab.core.thing.binding.ThingHandlerFactory.java_class, thf,
|
442
|
+
nil)
|
443
|
+
end
|
429
444
|
end
|
430
445
|
if bundle_name == "org.openhab.core.automation"
|
431
446
|
org.openhab.core.automation.internal.TriggerHandlerCallbackImpl.field_accessor :executor
|
@@ -549,31 +564,22 @@ module OpenHAB
|
|
549
564
|
# import global variables and constants that the DSL expects,
|
550
565
|
# since we're going to be running it in this same VM
|
551
566
|
def set_jruby_script_presets
|
552
|
-
wait_for_service("org.openhab.core.automation.module.script.
|
553
|
-
filter: "(service.config.description.uri=automation:jruby)") do |jrubyscripting|
|
554
|
-
# "org.openhab.core.automation.module.script.internal.ScriptExtensionManager") do |sem|
|
555
|
-
sem = OSGi.service(
|
556
|
-
"org.openhab.core.automation.module.script.internal.ScriptExtensionManager"
|
557
|
-
)
|
567
|
+
wait_for_service("org.openhab.core.automation.module.script.internal.ScriptExtensionManager") do |sem|
|
558
568
|
# since we're not created by the ScriptEngineManager, this never gets set; manually set it
|
559
569
|
$se = $scriptExtension = ScriptExtensionManagerWrapper.new(sem)
|
560
570
|
scope_values = sem.find_default_presets("rspec")
|
561
|
-
scope_values = scope_values.entry_set
|
562
|
-
|
563
|
-
%w[mapInstancePresets mapGlobalPresets].each do |method_name|
|
564
|
-
method = jrubyscripting.class.java_class.get_declared_method(method_name, java.util.Map::Entry.java_class)
|
565
|
-
|
566
|
-
method.accessible = true
|
567
|
-
scope_values = scope_values.map { |e| method.invoke(nil, e) }
|
568
|
-
end
|
571
|
+
scope_values = scope_values.entry_set.to_a
|
569
572
|
|
570
573
|
scope_values.each do |entry|
|
571
574
|
key = entry.key
|
572
575
|
value = entry.value
|
573
576
|
# convert Java classes to Ruby classes
|
574
577
|
value = value.ruby_class if value.is_a?(java.lang.Class) # rubocop:disable Lint/UselessAssignment
|
575
|
-
#
|
576
|
-
key =
|
578
|
+
# variables are globals; constants go into the global namespace
|
579
|
+
key = case key[0]
|
580
|
+
when "a".."z" then "$#{key}"
|
581
|
+
when "A".."Z" then "::#{key}"
|
582
|
+
end
|
577
583
|
eval("#{key} = value unless defined?(#{key})", nil, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
578
584
|
end
|
579
585
|
end
|
@@ -796,7 +802,6 @@ module OpenHAB
|
|
796
802
|
<f:feature>openhab-core-model-sitemap</f:feature>
|
797
803
|
<f:feature>openhab-core-model-thing</f:feature>
|
798
804
|
<f:feature>openhab-core-storage-json</f:feature>
|
799
|
-
<f:feature>openhab-automation-jrubyscripting</f:feature>
|
800
805
|
<f:feature>openhab-transport-http</f:feature>
|
801
806
|
<f:feature prerequisite="true">wrapper</f:feature>
|
802
807
|
<f:bundle>mvn:org.openhab.core.bundles/org.openhab.core.karaf/#{version}</f:bundle>
|
@@ -806,6 +811,24 @@ module OpenHAB
|
|
806
811
|
</featuresProcessing>
|
807
812
|
XML
|
808
813
|
end
|
814
|
+
|
815
|
+
def fix_rmi_registry_npe
|
816
|
+
full_path = File.join(oh_userdata, "etc/org.apache.karaf.management.cfg")
|
817
|
+
stat = File.stat(full_path)
|
818
|
+
return false unless stat.file? && stat.size.zero?
|
819
|
+
|
820
|
+
contents = <<~TEXT
|
821
|
+
# This file was autogenerated by openhab-jrubyscripting.
|
822
|
+
# Feel free to customize.
|
823
|
+
rmiRegistryPort = 1099
|
824
|
+
rmiServerPort = 44444
|
825
|
+
TEXT
|
826
|
+
begin
|
827
|
+
File.write(full_path, contents)
|
828
|
+
rescue Errno::EACCESS
|
829
|
+
abort "Unable to write to `#{full_path}`. Please use sudo and set it to:\n\n#{contents}"
|
830
|
+
end
|
831
|
+
end
|
809
832
|
end
|
810
833
|
end
|
811
834
|
end
|
@@ -16,19 +16,25 @@ module OpenHAB
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class SynchronousExecutor < java.util.concurrent.ScheduledThreadPoolExecutor
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
include Singleton
|
20
|
+
|
21
|
+
attr_accessor :main_thread
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
super(1)
|
23
25
|
end
|
24
26
|
|
25
27
|
def submit(runnable)
|
28
|
+
return super unless Thread.current == main_thread
|
29
|
+
|
26
30
|
runnable.respond_to?(:run) ? runnable.run : runnable.call
|
27
31
|
|
28
32
|
java.util.concurrent.CompletableFuture.completed_future(nil)
|
29
33
|
end
|
30
34
|
|
31
35
|
def execute(runnable)
|
36
|
+
return super unless Thread.current == main_thread
|
37
|
+
|
32
38
|
runnable.run
|
33
39
|
end
|
34
40
|
|
@@ -37,6 +43,7 @@ module OpenHAB
|
|
37
43
|
def shutdown_now
|
38
44
|
[]
|
39
45
|
end
|
46
|
+
alias_method :shutdownNow, :shutdown_now
|
40
47
|
end
|
41
48
|
|
42
49
|
class SynchronousExecutorMap
|
@@ -50,6 +50,7 @@ module OpenHAB
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def reschedule(time = nil)
|
53
|
+
Thread.current[:openhab_rescheduled_timer] = true if Thread.current[:openhab_rescheduled_timer] == self
|
53
54
|
@execution_time = new_execution_time(time || @time)
|
54
55
|
@executed = false
|
55
56
|
|
@@ -62,8 +63,8 @@ module OpenHAB
|
|
62
63
|
raise "Timer already cancelled" if cancelled?
|
63
64
|
raise "Timer already executed" if terminated?
|
64
65
|
|
65
|
-
super
|
66
66
|
@executed = true
|
67
|
+
super
|
67
68
|
end
|
68
69
|
|
69
70
|
def cancel
|
@@ -21,7 +21,9 @@ module OpenHAB
|
|
21
21
|
process_queue(create_queue(inputs), mod, inputs)
|
22
22
|
end
|
23
23
|
rescue Exception => e
|
24
|
-
|
24
|
+
raise if defined?(::RSpec) && ::RSpec.current_example.example_group.propagate_exceptions?
|
25
|
+
|
26
|
+
@run_context.send(:logger).log_exception(e)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
@@ -29,7 +31,7 @@ module OpenHAB
|
|
29
31
|
# DSL::Rules::AutomationRule.prepend(AutomationRule)
|
30
32
|
|
31
33
|
module DSL
|
32
|
-
def after(
|
34
|
+
def after(*, **)
|
33
35
|
return if SuspendRules.suspended?
|
34
36
|
|
35
37
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openhab-jrubyscripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.0.
|
4
|
+
version: 5.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby2_keywords
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: cucumber
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -354,6 +368,11 @@ files:
|
|
354
368
|
- lib/openhab/core/profile_factory.rb
|
355
369
|
- lib/openhab/core/provider.rb
|
356
370
|
- lib/openhab/core/registry.rb
|
371
|
+
- lib/openhab/core/rules.rb
|
372
|
+
- lib/openhab/core/rules/module.rb
|
373
|
+
- lib/openhab/core/rules/provider.rb
|
374
|
+
- lib/openhab/core/rules/registry.rb
|
375
|
+
- lib/openhab/core/rules/rule.rb
|
357
376
|
- lib/openhab/core/script_handling.rb
|
358
377
|
- lib/openhab/core/things.rb
|
359
378
|
- lib/openhab/core/things/channel.rb
|
@@ -392,8 +411,10 @@ files:
|
|
392
411
|
- lib/openhab/core_ext.rb
|
393
412
|
- lib/openhab/core_ext/java/class.rb
|
394
413
|
- lib/openhab/core_ext/java/duration.rb
|
414
|
+
- lib/openhab/core_ext/java/list.rb
|
395
415
|
- lib/openhab/core_ext/java/local_date.rb
|
396
416
|
- lib/openhab/core_ext/java/local_time.rb
|
417
|
+
- lib/openhab/core_ext/java/map.rb
|
397
418
|
- lib/openhab/core_ext/java/month.rb
|
398
419
|
- lib/openhab/core_ext/java/month_day.rb
|
399
420
|
- lib/openhab/core_ext/java/period.rb
|
@@ -404,6 +425,7 @@ files:
|
|
404
425
|
- lib/openhab/core_ext/ruby/array.rb
|
405
426
|
- lib/openhab/core_ext/ruby/class.rb
|
406
427
|
- lib/openhab/core_ext/ruby/date.rb
|
428
|
+
- lib/openhab/core_ext/ruby/date_time.rb
|
407
429
|
- lib/openhab/core_ext/ruby/numeric.rb
|
408
430
|
- lib/openhab/core_ext/ruby/range.rb
|
409
431
|
- lib/openhab/core_ext/ruby/time.rb
|
@@ -434,7 +456,6 @@ files:
|
|
434
456
|
- lib/openhab/dsl/rules/triggers/updated.rb
|
435
457
|
- lib/openhab/dsl/rules/triggers/watch/watch.rb
|
436
458
|
- lib/openhab/dsl/rules/triggers/watch/watch_handler.rb
|
437
|
-
- lib/openhab/dsl/script_handling.rb
|
438
459
|
- lib/openhab/dsl/things/builder.rb
|
439
460
|
- lib/openhab/dsl/thread_local.rb
|
440
461
|
- lib/openhab/dsl/timer_manager.rb
|