boc-tothefuture / openhab-jruby

JRuby Libraries for Openhab
Eclipse Public License 2.0
6 stars 9 forks source link

fix(add-on): make compatible with latest add-on #659

Closed boc-tothefuture closed 1 year ago

boc-tothefuture commented 1 year ago

@jimtng - I noticed a PR was merged to the OpenHAB add-on and is now in the snapshot. I don't know the full background of the PR, from what I saw in the text of the PR it was only breaking if RUBYLIB wasn't set. The test harness sets RUBYLIB but it still appears to be failing the tests. Do you know what changes are necessary to ensure compatibility?

ccutrer commented 1 year ago

I've looked at the output from cucumber (but not the full logs), and it seems like it's complaining that some constants that come from the scopeValues of the default presets are missing. I have no explanation for that. My fork is passing against today's snapshot just fine.

jimtng commented 1 year ago

From what I can see, cucumber was failing because of missing constants like ON/PLAY that were supposed to have been imported by scopeValues. I can't figure out how the recent PRs to the addons could have caused it.

@boc-tothefuture could you try building a custom addon jar from the time before the addon PR, but with the latest openhab core in case there's something in core that caused it?

boc-tothefuture commented 1 year ago

From what I can see, cucumber was failing because of missing constants like ON/PLAY that were supposed to have been imported by scopeValues. I can't figure out how the recent PRs to the addons could have caused it.

@boc-tothefuture could you try building a custom addon jar from the time before the addon PR, but with the latest openhab core in case there's something in core that caused it?

Good idea! Let me try against the SNAPSHOT from before this was merged.

boc-tothefuture commented 1 year ago

@jimtng - Do you happen to know how to access old snapshots? From a quick glance I seem to only see the last two successful snapshots on ci.openhab.org. I think build 3202 is the latest one without this change - but before I built locally, I thought I would check in case you knew of a place besides ci.openhab.org that had the snapshots.

jimtng commented 1 year ago

Unfortunately no, I don't know if the previous snapshots were stored somewhere. I was thinking more along the same lines of the jruby 9.4 version of the addon, i.e. manually built + uploaded and referenced from the build.

boc-tothefuture commented 1 year ago

@jimtng - I am still seeing the same issue with the snapshot and using an older 9.4 build of the add-on.

Thanks for the idea.. I will look at what else changed in the core between M5 and the snapshot.

ccutrer commented 1 year ago

You might try adding https://github.com/openhab/openhab-core/pull/3185. Or removing https://github.com/openhab/openhab-core/commit/4bcc15daadb3c18d34bff36bbc52ae28ac3dbeb5. I swear the latter caused me issues that the former fixed, but I had a lot going on so can't be sure.

boc-tothefuture commented 1 year ago

You might try adding openhab/openhab-core#3185. Or removing openhab/openhab-core@4bcc15d. I swear the latter caused me issues that the former fixed, but I had a lot going on so can't be sure.

Thanks! I had just started to look for candidates. Those seem like possible options.

boc-tothefuture commented 1 year ago

Debugging update here (still not sure of the root cause). Items like OPEN/CLOSED,ON,OFF are no longer showing up as module constants in the snapshot M5, despite them appearing to be passed in scope values:

Milestone 5:

 Scope Values: {voice=org.openhab.core.voice
.internal.VoiceManagerImpl@21f7bf7c, DOWN=DOWN, StringType=class org.openhab.core.library.types.StringType, rules=or
g.openhab.core.automation.internal.RuleRegistryImpl@7f37b8db, NextPreviousType=class org.openhab.core.library.types.
NextPreviousType, PLAY=PLAY, Month=class java.time.Month, ImperialUnits=class org.openhab.core.library.unit.Imperial
Units, ZonedDateTime=class java.time.ZonedDateTime, INCREASE=INCREASE, OpenClosedType=class org.openhab.core.library
.types.OpenClosedType, things=org.openhab.core.thing.internal.ThingRegistryImpl@45f944bf, UP=UP, RawType=class org.o
penhab.core.library.types.RawType, StringListType=class org.openhab.core.library.types.StringListType, events=org.op
enhab.core.automation.module.script.internal.defaultscope.ScriptBusEventImpl@662aacb2, SIUnits=class org.openhab.cor
e.library.unit.SIUnits, itemRegistry=org.openhab.core.internal.items.ItemRegistryImpl@6cea721f, NULL=NULL, STOP=STOP
, UnDefType=class org.openhab.core.types.UnDefType, ir=org.openhab.core.internal.items.ItemRegistryImpl@6cea721f, Du
ration=class java.time.Duration, RefreshType=class org.openhab.core.types.RefreshType, Units=class org.openhab.core.
library.unit.Units, RewindFastforwardType=class org.openhab.core.library.types.RewindFastforwardType, DateTimeType=c
lass org.openhab.core.library.types.DateTimeType, QuantityType=class org.openhab.core.library.types.QuantityType, St
ate=interface org.openhab.core.types.State, DecimalType=class org.openhab.core.library.types.DecimalType, IncreaseDe
creaseType=class org.openhab.core.library.types.IncreaseDecreaseType, BinaryPrefix=class org.openhab.core.library.un
it.BinaryPrefix, File=class java.io.File, items=org.openhab.core.automation.module.script.internal.defaultscope.Item
RegistryDelegate@2e59fe39, actions=org.openhab.core.automation.module.script.internal.defaultscope.ScriptThingAction
sImpl@218a8bf1, CLOSED=CLOSED, REFRESH=REFRESH, MetricPrefix=class org.openhab.core.library.unit.MetricPrefix, DECRE
ASE=DECREASE, StopMoveType=class org.openhab.core.library.types.StopMoveType, OFF=OFF, PREVIOUS=PREVIOUS, PAUSE=PAUS
E, NEXT=NEXT, REWIND=REWIND, Paths=class java.nio.file.Paths, audio=org.openhab.core.audio.internal.AudioManagerImpl
@17489475, URLEncoder=class java.net.URLEncoder, Files=class java.nio.file.Files, HSBType=class org.openhab.core.lib
rary.types.HSBType, ON=ON, Path=interface java.nio.file.Path, DayOfWeek=class java.time.DayOfWeek, ZoneId=class java
.time.ZoneId, UpDownType=class org.openhab.core.library.types.UpDownType, PercentType=class org.openhab.core.library
.types.PercentType, OPEN=OPEN, MOVE=MOVE, OnOffType=class org.openhab.core.library.types.OnOffType, Command=interfac
e org.openhab.core.types.Command, lifecycleTracker=org.openhab.core.automation.module.script.LifecycleScriptExtensio
nProvider$LifecycleTracker@26c690f4, PlayPauseType=class org.openhab.core.library.types.PlayPauseType, FASTFORWARD=F
ASTFORWARD, PointType=class org.openhab.core.library.types.PointType, UNDEF=UNDEF, ChronoUnit=class java.time.tempor
al.ChronoUnit}

Output of Modules.constants

 [:Fixnum, :STDERR, :Rational, :MapJavaProxy
, :StringType, :String, :Resolv, :JavaUtilities, :PLATFORM, :JavaArrayUtilities, :Month, :TCPserver, :Enumerator, :I
NCREASE, :UNIXServer, :Enumerable, :UDPSocket, :StringListType, :STOP, :STDOUT, :SecureRandom, :Method, :RefreshType
, :Float, :Bignum, :SystemStackError, :ARGFClass, :MethodSource, :RUBY_PATCHLEVEL, :TypeError, :Marshal, :FloatDomai
nError, :ClosedQueueError, :StandardError, :Set, :TrueClass, :DECREASE, :FileTest, :PREVIOUS, :BigMath, :RUBY_REVISI
ON, :OpenHAB, :Paths, :URLEncoder, :Files, :Queue, :HSBType, :ConcreteJavaProxy, :Path, :Java, :StopIteration, :Sock
etError, :RUBY_ENGINE, :Dir, :OPEN, :IPSocket, :LoadError, :Dimmer, :PointType, :ObjectSpace, :RUBY_COPYRIGHT, :UNDE
F, :Socket, :Comparable, :DOWN, :RUBY_ENGINE_VERSION, :Regexp, :CROSS_COMPILING, :Forwardable, :Process, :RuntimeErr
or, :NoMatchingPatternError, :ImperialUnits, :RUBY_RELEASE_DATE, :Semantics, :NoMemoryError, :OpenClosedType, :UNIXS
ocket, :JavaInterfaceExtender, :RawType, :UP, :NativeException, :FalseClass, :Binding, :IPAddr, :SIUnits, :TCPsocket
, :Encoding, :Duration, :OpenSSL, :RUBY_VERSION, :QuantityType, :State, :DidYouMean, :Class, :IncreaseDecreaseType,
:ArrayJavaProxyCreator, :BasicObject, :Marcel, :EOFError, :SecurityError, :SystemCallError, :Fiber, :Time, :ENV, :AR
GF, :ConditionVariable, :STDIN, :ScriptError, :SingleForwardable, :TCPSocket, :NEXT, :GC, :DayOfWeek, :Continuation,
 :UNIXsocket, :SignalException, :PercentType, :MatchData, :ThreadError, :EncodingError, :Integer, :TOPLEVEL_BINDING,
 :Command, :OnOffType, :IOError, :BasicSocket, :RegexpError, :ArgumentError, :ARGV, :RUBY_PLATFORM, :Addrinfo, :Math
, :Hash, :NextPreviousType, :DateTime, :JavaProxy, :Numeric, :SystemExit, :PLAY, :ZonedDateTime, :JavaInterfaceTempl
ate, :InterruptedRegexpError, :InterfaceJavaProxy, :ConcurrencyError, :FiberError, :IO, :UnDefType, :Pathname, :NotI
mplementedError, :Mutex, :Interrupt, :Gem, :RUBY_DESCRIPTION, :Switch, :SizedQueue, :DecimalType, :Object, :BinaryPr
efix, :Module, :NilClass, :KeyError, :Warning, :Base64, :MetricPrefix, :Refinement, :ArrayJavaProxy, :URI, :SortedSe
t, :OFF, :StopMoveType, :Complex, :Proc, :PAUSE, :Signal, :UNIXserver, :RbConfig, :UDPsocket, :MatchingData, :REWIND
, :ThreadGroup, :JRUBY_VERSION, :MonitorMixin, :Thread, :PlayPauseType, :FASTFORWARD, :SimpleDelegator, :Net, :JRuby
, :TracePoint, :ZeroDivisionError, :NameError, :Random, :SyntaxError, :JRUBY_REVISION, :IndexError, :Kernel, :ENV_JA
VA, :NULL, :Timeout, :NoMethodError, :Range, :Units, :RewindFastforwardType, :DateTimeType, :RELEASE_DATE, :Singleto
n, :LocalJumpError, :File, :Zlib, :CLOSED, :REFRESH, :Symbol, :Errno, :Struct, :StringIO, :Monitor, :JavaProxyMethod
s, :TCPServer, :RangeError, :ON, :ZoneId, :UpDownType, :ServerSocket, :FrozenError, :Exception, :Date, :BigDecimal,
:Contact, :Array, :Delegator, :MOVE, :UnboundMethod, :UncaughtThrowError, :ChronoUnit]

Snapshot:


2022-12-10 12:45:35.955 [DEBUG] [ng.internal.JRubyScriptEngineFactory] - Scope Values: {voice=org.openhab.core.voice
.internal.VoiceManagerImpl@163b4bf2, DOWN=DOWN, StringType=class org.openhab.core.library.types.StringType, rules=or
g.openhab.core.automation.internal.RuleRegistryImpl@6edacd62, NextPreviousType=class org.openhab.core.library.types.
NextPreviousType, PLAY=PLAY, Month=class java.time.Month, ImperialUnits=class org.openhab.core.library.unit.Imperial
Units, ZonedDateTime=class java.time.ZonedDateTime, INCREASE=INCREASE, OpenClosedType=class org.openhab.core.library
.types.OpenClosedType, things=org.openhab.core.thing.internal.ThingRegistryImpl@3a0aa3e0, UP=UP, RawType=class org.o
penhab.core.library.types.RawType, StringListType=class org.openhab.core.library.types.StringListType, events=org.op
enhab.core.automation.module.script.internal.defaultscope.ScriptBusEventImpl@41387321, SIUnits=class org.openhab.cor
e.library.unit.SIUnits, itemRegistry=org.openhab.core.internal.items.ItemRegistryImpl@615a4d8d, NULL=NULL, STOP=STOP
, UnDefType=class org.openhab.core.types.UnDefType, ir=org.openhab.core.internal.items.ItemRegistryImpl@615a4d8d, Du
ration=class java.time.Duration, RefreshType=class org.openhab.core.types.RefreshType, Units=class org.openhab.core.
library.unit.Units, RewindFastforwardType=class org.openhab.core.library.types.RewindFastforwardType, DateTimeType=c
lass org.openhab.core.library.types.DateTimeType, QuantityType=class org.openhab.core.library.types.QuantityType, St
ate=interface org.openhab.core.types.State, DecimalType=class org.openhab.core.library.types.DecimalType, IncreaseDe
creaseType=class org.openhab.core.library.types.IncreaseDecreaseType, BinaryPrefix=class org.openhab.core.library.un
it.BinaryPrefix, File=class java.io.File, items=org.openhab.core.automation.module.script.internal.defaultscope.Item
RegistryDelegate@59d32d19, actions=org.openhab.core.automation.module.script.internal.defaultscope.ScriptThingAction
sImpl@36a99060, CLOSED=CLOSED, REFRESH=REFRESH, MetricPrefix=class org.openhab.core.library.unit.MetricPrefix, DECRE
ASE=DECREASE, StopMoveType=class org.openhab.core.library.types.StopMoveType, OFF=OFF, PREVIOUS=PREVIOUS, PAUSE=PAUS
E, NEXT=NEXT, REWIND=REWIND, Paths=class java.nio.file.Paths, audio=org.openhab.core.audio.internal.AudioManagerImpl
@12d5e58f, URLEncoder=class java.net.URLEncoder, Files=class java.nio.file.Files, HSBType=class org.openhab.core.lib
rary.types.HSBType, ON=ON, Path=interface java.nio.file.Path, DayOfWeek=class java.time.DayOfWeek, ZoneId=class java
.time.ZoneId, UpDownType=class org.openhab.core.library.types.UpDownType, PercentType=class org.openhab.core.library
.types.PercentType, OPEN=OPEN, MOVE=MOVE, OnOffType=class org.openhab.core.library.types.OnOffType, Command=interfac
e org.openhab.core.types.Command, lifecycleTracker=org.openhab.core.automation.module.script.LifecycleScriptExtensio
nProvider$LifecycleTracker@340a4cef, PlayPauseType=class org.openhab.core.library.types.PlayPauseType, FASTFORWARD=F
ASTFORWARD, PointType=class org.openhab.core.library.types.PointType, UNDEF=UNDEF, ChronoUnit=class java.time.tempor
al.ChronoUnit}

[:Fixnum, :STDERR, :Rational, :MapJavaProxy
, :StringType, :String, :Resolv, :JavaUtilities, :PLATFORM, :JavaArrayUtilities, :Month, :TCPserver, :Enumerator, :U
NIXServer, :Enumerable, :UDPSocket, :StringListType, :STDOUT, :SecureRandom, :Method, :RefreshType, :Float, :Bignum,
 :SystemStackError, :ARGFClass, :MethodSource, :RUBY_PATCHLEVEL, :TypeError, :Marshal, :FloatDomainError, :ClosedQue
ueError, :StandardError, :Set, :TrueClass, :FileTest, :BigMath, :RUBY_REVISION, :OpenHAB, :Paths, :URLEncoder, :File
s, :Queue, :HSBType, :ConcreteJavaProxy, :Path, :Java, :StopIteration, :SocketError, :RUBY_ENGINE, :Dir, :IPSocket,
:LoadError, :Dimmer, :ObjectSpace, :PointType, :RUBY_COPYRIGHT, :Socket, :Comparable, :RUBY_ENGINE_VERSION, :Regexp,
 :CROSS_COMPILING, :Forwardable, :Process, :RuntimeError, :NoMatchingPatternError, :ImperialUnits, :RUBY_RELEASE_DAT
E, :Semantics, :NoMemoryError, :OpenClosedType, :UNIXSocket, :JavaInterfaceExtender, :RawType, :NativeException, :Fa
lseClass, :Binding, :IPAddr, :SIUnits, :TCPsocket, :Encoding, :Duration, :OpenSSL, :RUBY_VERSION, :QuantityType, :St
ate, :DidYouMean, :Class, :IncreaseDecreaseType, :ArrayJavaProxyCreator, :BasicObject, :Marcel, :EOFError, :Security
Error, :SystemCallError, :Fiber, :Time, :ENV, :ARGF, :ConditionVariable, :STDIN, :ScriptError, :SingleForwardable, :
TCPSocket, :GC, :DayOfWeek, :Continuation, :UNIXsocket, :SignalException, :PercentType, :MatchData, :ThreadError, :E
ncodingError, :Integer, :TOPLEVEL_BINDING, :IOError, :OnOffType, :Command, :BasicSocket, :RegexpError, :ArgumentErro
r, :ARGV, :RUBY_PLATFORM, :Addrinfo, :Math, :Hash, :NextPreviousType, :DateTime, :JavaProxy, :Numeric, :SystemExit,
:ZonedDateTime, :JavaInterfaceTemplate, :InterruptedRegexpError, :InterfaceJavaProxy, :ConcurrencyError, :FiberError
, :IO, :UnDefType, :Pathname, :NotImplementedError, :Mutex, :Interrupt, :Gem, :RUBY_DESCRIPTION, :Switch, :SizedQueu
e, :DecimalType, :Object, :BinaryPrefix, :Module, :NilClass, :KeyError, :Warning, :Base64, :MetricPrefix, :Refinemen
t, :ArrayJavaProxy, :URI, :SortedSet, :StopMoveType, :Complex, :Proc, :Signal, :UNIXserver, :RbConfig, :UDPsocket, :
MatchingData, :ThreadGroup, :JRUBY_VERSION, :MonitorMixin, :Thread, :PlayPauseType, :SimpleDelegator, :Net, :JRuby,
:TracePoint, :ZeroDivisionError, :NameError, :Random, :SyntaxError, :JRUBY_REVISION, :IndexError, :Kernel, :ENV_JAVA
, :Timeout, :NoMethodError, :Range, :Units, :RewindFastforwardType, :DateTimeType, :RELEASE_DATE, :Singleton, :Local
JumpError, :File, :Zlib, :Symbol, :Errno, :Struct, :StringIO, :Monitor, :JavaProxyMethods, :TCPServer, :RangeError,
:ZoneId, :UpDownType, :ServerSocket, :FrozenError, :Exception, :Date, :BigDecimal, :Contact, :Array, :Delegator, :Un
boundMethod, :UncaughtThrowError, :ChronoUnit]

I haven't done a line by line comparison, but at a glance I don't see many of the all caps items. But I do see them show up in the scope values call.

ccutrer commented 1 year ago

Just glancing through, it looks like any that are enum values, but not classes, are missing. I don't see how that would work with https://github.com/openhab/openhab-addons/blob/5e73936aa890cee05d3c40fc33296a0232aa9f23/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java#L66, but at least it's a thread to tug on.

boc-tothefuture commented 1 year ago

Just glancing through, it looks like any that are enum values, but not classes, are missing. I don't see how that would work with https://github.com/openhab/openhab-addons/blob/5e73936aa890cee05d3c40fc33296a0232aa9f23/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java#L66, but at least it's a thread to tug on.

Thanks! I just started to add some more debugging.

ccutrer commented 1 year ago

So I'm thinking that https://github.com/openhab/openhab-addons/commit/7b8ae535e95ddd4e64d60a1988c4c22e71a366c1 is changing where the enums are getting set? On Object instead of Module?

boc-tothefuture commented 1 year ago

Large dump of logs here:

- Scope Values: {voice=org.openhab.core.voice
.internal.VoiceManagerImpl@1ff20a91, DOWN=DOWN, StringType=class org.openhab.core.library.types.StringType, rules=or
g.openhab.core.automation.internal.RuleRegistryImpl@2d1eb6db, NextPreviousType=class org.openhab.core.library.types.
NextPreviousType, PLAY=PLAY, Month=class java.time.Month, ImperialUnits=class org.openhab.core.library.unit.Imperial
Units, ZonedDateTime=class java.time.ZonedDateTime, INCREASE=INCREASE, OpenClosedType=class org.openhab.core.library
.types.OpenClosedType, things=org.openhab.core.thing.internal.ThingRegistryImpl@40bd89c4, UP=UP, RawType=class org.o
penhab.core.library.types.RawType, StringListType=class org.openhab.core.library.types.StringListType, events=org.op
enhab.core.automation.module.script.internal.defaultscope.ScriptBusEventImpl@422d0c60, SIUnits=class org.openhab.cor
e.library.unit.SIUnits, itemRegistry=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, NULL=NULL, STOP=STOP
, UnDefType=class org.openhab.core.types.UnDefType, ir=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, Du
ration=class java.time.Duration, RefreshType=class org.openhab.core.types.RefreshType, Units=class org.openhab.core.
library.unit.Units, RewindFastforwardType=class org.openhab.core.library.types.RewindFastforwardType, DateTimeType=c
lass org.openhab.core.library.types.DateTimeType, QuantityType=class org.openhab.core.library.types.QuantityType, St
ate=interface org.openhab.core.types.State, DecimalType=class org.openhab.core.library.types.DecimalType, IncreaseDe
creaseType=class org.openhab.core.library.types.IncreaseDecreaseType, BinaryPrefix=class org.openhab.core.library.un
it.BinaryPrefix, File=class java.io.File, items=org.openhab.core.automation.module.script.internal.defaultscope.Item
RegistryDelegate@6e8c4252, actions=org.openhab.core.automation.module.script.internal.defaultscope.ScriptThingAction
sImpl@42d305ee, CLOSED=CLOSED, REFRESH=REFRESH, MetricPrefix=class org.openhab.core.library.unit.MetricPrefix, DECRE
ASE=DECREASE, StopMoveType=class org.openhab.core.library.types.StopMoveType, OFF=OFF, PREVIOUS=PREVIOUS, PAUSE=PAUS
E, NEXT=NEXT, REWIND=REWIND, Paths=class java.nio.file.Paths, audio=org.openhab.core.audio.internal.AudioManagerImpl
@362237d4, URLEncoder=class java.net.URLEncoder, Files=class java.nio.file.Files, HSBType=class org.openhab.core.lib
rary.types.HSBType, ON=ON, Path=interface java.nio.file.Path, DayOfWeek=class java.time.DayOfWeek, ZoneId=class java
.time.ZoneId, UpDownType=class org.openhab.core.library.types.UpDownType, PercentType=class org.openhab.core.library
.types.PercentType, OPEN=OPEN, MOVE=MOVE, OnOffType=class org.openhab.core.library.types.OnOffType, Command=interfac
e org.openhab.core.types.Command, lifecycleTracker=org.openhab.core.automation.module.script.LifecycleScriptExtensio
nProvider$LifecycleTracker@68374fd8, PlayPauseType=class org.openhab.core.library.types.PlayPauseType, FASTFORWARD=F
ASTFORWARD, PointType=class org.openhab.core.library.types.PointType, UNDEF=UNDEF, ChronoUnit=class java.time.tempor
al.ChronoUnit}
Filtered Values: {DOWN=DOWN, StringType=cla
ss org.openhab.core.library.types.StringType, NextPreviousType=class org.openhab.core.library.types.NextPreviousType
, PLAY=PLAY, Month=class java.time.Month, ImperialUnits=class org.openhab.core.library.unit.ImperialUnits, ZonedDate
Time=class java.time.ZonedDateTime, INCREASE=INCREASE, OpenClosedType=class org.openhab.core.library.types.OpenClose
dType, UP=UP, RawType=class org.openhab.core.library.types.RawType, StringListType=class org.openhab.core.library.ty
pes.StringListType, SIUnits=class org.openhab.core.library.unit.SIUnits, NULL=NULL, STOP=STOP, UnDefType=class org.o
penhab.core.types.UnDefType, $itemRegistry=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, Duration=class
 java.time.Duration, RefreshType=class org.openhab.core.types.RefreshType, Units=class org.openhab.core.library.unit
.Units, $voice=org.openhab.core.voice.internal.VoiceManagerImpl@1ff20a91, RewindFastforwardType=class org.openhab.co
re.library.types.RewindFastforwardType, DateTimeType=class org.openhab.core.library.types.DateTimeType, $actions=org.openhab.core.automation.module.script.internal.defaultscope.ScriptThingActionsImpl@42d305ee, QuantityType=class org
.openhab.core.library.types.QuantityType, State=interface org.openhab.core.types.State, $rules=org.openhab.core.auto
mation.internal.RuleRegistryImpl@2d1eb6db, DecimalType=class org.openhab.core.library.types.DecimalType, IncreaseDec
reaseType=class org.openhab.core.library.types.IncreaseDecreaseType, BinaryPrefix=class org.openhab.core.library.uni
t.BinaryPrefix, File=class java.io.File, CLOSED=CLOSED, REFRESH=REFRESH, MetricPrefix=class org.openhab.core.library
.unit.MetricPrefix, DECREASE=DECREASE, $ir=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, StopMoveType=c
lass org.openhab.core.library.types.StopMoveType, OFF=OFF, PREVIOUS=PREVIOUS, $audio=org.openhab.core.audio.internal.AudioManagerImpl@362237d4, PAUSE=PAUSE, $things=org.openhab.core.thing.internal.ThingRegistryImpl@40bd89c4, $events
=org.openhab.core.automation.module.script.internal.defaultscope.ScriptBusEventImpl@422d0c60, NEXT=NEXT, REWIND=REWI
ND, Paths=class java.nio.file.Paths, URLEncoder=class java.net.URLEncoder, Files=class java.nio.file.Files, HSBType=
class org.openhab.core.library.types.HSBType, ON=ON, Path=interface java.nio.file.Path, DayOfWeek=class java.time.Da
yOfWeek, ZoneId=class java.time.ZoneId, UpDownType=class org.openhab.core.library.types.UpDownType, PercentType=clas
s org.openhab.core.library.types.PercentType, $lifecycleTracker=org.openhab.core.automation.module.script.LifecycleS
criptExtensionProvider$LifecycleTracker@68374fd8, OPEN=OPEN, $items=org.openhab.core.automation.module.script.intern
al.defaultscope.ItemRegistryDelegate@6e8c4252, MOVE=MOVE, OnOffType=class org.openhab.core.library.types.OnOffType,
Command=interface org.openhab.core.types.Command, PlayPauseType=class org.openhab.core.library.types.PlayPauseType,
FASTFORWARD=FASTFORWARD, PointType=class org.openhab.core.library.types.PointType, UNDEF=UNDEF, ChronoUnit=class jav
a.time.temporal.ChronoUnit}
 Classes Values: {StringType=class org.openhab.core.library.types.StringType, MetricPrefix=class org.openhab.core.library.unit.MetricPrefix, NextPreviousType=class org.openhab.core.library.types.NextPreviousType, StopMoveType=class org.openhab.core.library.types.StopMoveType, Month=class java.time.Month, ImperialUnits=class org.openhab.core.library.unit.ImperialUnits, ZonedDateTime=class java.time.ZonedDateTime, OpenClosedType=class org.openhab.core.library.types.OpenClosedType, RawType=class org.openhab.core.library.types.RawType, Paths=class java.nio.file.Paths, URLEncoder=class java.net.URLEncoder, Files=class java.nio.file.Files, HSBType=class org.openhab.core.library.types.HSBType, StringListType=class org.openhab.core.library.types.StringListType, Path=interface java.nio.file.Path, SIUnits=class org.openhab.core.library.unit.SIUnits, DayOfWeek=class java.time.DayOfWeek, ZoneId=class java.time.ZoneId, UnDefType=class org.openhab.core.types.UnDefType, Duration=class java.time.Duration, UpDownType=class org.openhab.core.library.types.UpDownType, PercentType=class org.openhab.core.library.types.PercentType, RefreshType=class org.openhab.core.types.RefreshType, Units=class org.openhab.core.library.unit.Units, RewindFastforwardType=class org.openhab.core.library.types.RewindFastforwardType, DateTimeType=class org.openhab.core.library.types.DateTimeType, QuantityType=class org.openhab.core.library.types.QuantityType, OnOffType=class org.openhab.core.library.types.OnOffType, Command=interface org.openhab.core.types.Command, State=interface org.openhab.core.types.State, PlayPauseType=class org.openhab.core.library.types.PlayPauseType, DecimalType=class org.openhab.core.library.types.DecimalType, PointType=class org.openhab.core.library.types.PointType, IncreaseDecreaseType=class org.openhab.core.library.types.IncreaseDecreaseType, BinaryPrefix=class org.openhab.core.library.unit.BinaryPrefix, File=class java.io.File, ChronoUnit=class java.time.temporal.ChronoUnit}

2022-12-10 13:43:30.023 [DEBUG] [ng.internal.JRubyScriptEngineFactory] - Super Values: {DOWN=DOWN, CLOSED=CLOSED, RE
FRESH=REFRESH, DECREASE=DECREASE, $ir=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, OFF=OFF, PREVIOUS=P
REVIOUS, $audio=org.openhab.core.audio.internal.AudioManagerImpl@362237d4, PAUSE=PAUSE, PLAY=PLAY, $things=org.openh
ab.core.thing.internal.ThingRegistryImpl@40bd89c4, $events=org.openhab.core.automation.module.script.internal.defaul
tscope.ScriptBusEventImpl@422d0c60, INCREASE=INCREASE, NEXT=NEXT, REWIND=REWIND, UP=UP, ON=ON, NULL=NULL, STOP=STOP,
 $itemRegistry=org.openhab.core.internal.items.ItemRegistryImpl@36fc8238, $lifecycleTracker=org.openhab.core.automat
ion.module.script.LifecycleScriptExtensionProvider$LifecycleTracker@68374fd8, $voice=org.openhab.core.voice.internal
.VoiceManagerImpl@1ff20a91, OPEN=OPEN, $items=org.openhab.core.automation.module.script.internal.defaultscope.ItemRe
gistryDelegate@6e8c4252, $actions=org.openhab.core.automation.module.script.internal.defaultscope.ScriptThingActions
Impl@42d305ee, MOVE=MOVE, $rules=org.openhab.core.automation.internal.RuleRegistryImpl@2d1eb6db, FASTFORWARD=FASTFOR
WARD, UNDEF=UNDEF}

So, what appears to be happening is this line is only allowing class objects (partitioning the map). Then the enums and other values are sent to super.scopeValues

However, I still don't understand why this behavior is changing between M5 and the snapshot.. (I am about to run the same thing against M5 and see what the differences are).

boc-tothefuture commented 1 year ago

The map partitioning @jimtng added 10 months ago, so that seems unlikely to be the issue.. And the scopeValues call in the AbstractScriptEngineFactory hasn't changed in 4 years.

Still digging on this one.

boc-tothefuture commented 1 year ago

So I'm thinking that openhab/openhab-addons@7b8ae53 is changing where the enums are getting set? On Object instead of Module?

I can't rule anything out.. But that commit date is from September. The breakage I am seeing is between Milestone 5 (working) and snapshot.

Looking at the code and the logs the enums should not have been going to that method for a while now.

boc-tothefuture commented 1 year ago

So.. I have it working now.. but no idea why what I did fixed it..

ccutrer commented 1 year ago

So.. I have it working now.. but no idea why what I did fixed it..

You can't leave us hanging like that! What'd you do?!

boc-tothefuture commented 1 year ago

So.. I have it working now.. but no idea why what I did fixed it..

You can't leave us hanging like that! What'd you do?!

LOL.. Sorry.. I just didn't want other wasting time.. I am trying to narrow it down.. But right now I have this in the add-on:

        Map<String, Object> nonClasses = partitionedMap.getOrDefault(false, new HashMap<String, Object>());
        logger.debug("Super Values: {}", nonClasses);

        for (Map.Entry<String, Object> entry : nonClasses.entrySet()) {
            logger.debug("Putting Entry: {}", entry);
            scriptEngine.put(entry.getKey(), entry.getValue());
        }

        importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>()));
        super.scopeValues(scriptEngine, partitionedMap.getOrDefault(false, new HashMap<>()));

I am trying to now narrow down:

  1. Is the double call to scriptEnginer.put fixing it (I do it once, super does it once).
  2. Do the calls to scriptEngine.put have to happen for some reason before importClasses?
  3. Does something happen where for some reason super.scopeValues doesn't actually call the scriptEngine.put? I noticed when I copied the scriptEngine.put loop in I was getting a runtime exception about Map.Entry vs Entry.. So was going to see if something was swallowing that exception or for some reason I only hit a type problem when I moved that loop into the same methom.
boc-tothefuture commented 1 year ago

Looks like it is the second option.. but I need to undo all my other changes to verify.. I also don't understand why that is different between M5 and now.

boc-tothefuture commented 1 year ago

That is it.. it needs to be called first.. I am going to put in a PR.. @ccutrer and @jimtng can you verify changing the order doesn't break anything for you?

The jar with only the order change is here

ccutrer commented 1 year ago

okay, this is weird. on current main of the addon, if I use auto-requires, then ON is defined at the top level. if I don't use auto-requires, and just require "openhab/dsl" in my test.rb, then it's not defined. so using auto-requires somehow works around it

boc-tothefuture commented 1 year ago

Closing as it now passes with latest snapshot.