-
Notifications
You must be signed in to change notification settings - Fork 1
ScriptWrappingStrategy: add more imports from the OH-JSR223 implicit preset #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScriptWrappingStrategy: add more imports from the OH-JSR223 implicit preset #19
Conversation
|
Thanks !
I added something to do this. |
|
Now WrappedStrategy inserts: import java.io.File;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.IncreaseDecreaseType;
import org.openhab.core.library.types.NextPreviousType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.PlayPauseType;
import org.openhab.core.library.types.PointType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.RawType;
import org.openhab.core.library.types.RewindFastforwardType;
import org.openhab.core.library.types.StopMoveType;
import org.openhab.core.library.types.StringListType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.types.UpDownType;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import static org.openhab.core.library.types.IncreaseDecreaseType.DECREASE;
import static org.openhab.core.library.types.IncreaseDecreaseType.INCREASE;
import static org.openhab.core.library.types.NextPreviousType.NEXT;
import static org.openhab.core.library.types.NextPreviousType.PREVIOUS;
import static org.openhab.core.library.types.OnOffType.OFF;
import static org.openhab.core.library.types.OnOffType.ON;
import static org.openhab.core.library.types.OpenClosedType.CLOSED;
import static org.openhab.core.library.types.OpenClosedType.OPEN;
import static org.openhab.core.library.types.PlayPauseType.PAUSE;
import static org.openhab.core.library.types.PlayPauseType.PLAY;
import static org.openhab.core.library.types.RewindFastforwardType.FASTFORWARD;
import static org.openhab.core.library.types.RewindFastforwardType.REWIND;
import static org.openhab.core.library.types.StopMoveType.MOVE;
import static org.openhab.core.library.types.StopMoveType.STOP;
import static org.openhab.core.library.types.UpDownType.DOWN;
import static org.openhab.core.library.types.UpDownType.UP;
import static org.openhab.core.types.RefreshType.REFRESH;
import static org.openhab.core.types.UnDefType.NULL;
import static org.openhab.core.types.UnDefType.UNDEF;
import helper.generated.Java223Script;
import org.openhab.core.library.items.*;
import org.openhab.core.library.types.*;
public class WrappedJavaScript extends Java223Script { The last import should not be necessary, as very much things from it ( |
|
An alternative way to get the content of the implicit presets is with Java223ScriptEngineFactory.java: @@ -116,7 +116,10 @@ public class Java223ScriptEngineFactory extends JavaScriptEngineFactory
@Reference ItemRegistry itemRegistry, @Reference ThingRegistry thingRegistry,
@Reference Java223DependencyTracker dependencyTracker, @Reference RuleManager ruleManager,
@Reference ThingManager thingManager, @Reference MetadataRegistry metadataRegistry,
- @Reference ScriptEngineManager scriptEngineManager) {
+ @Reference ScriptEngineManager scriptEngineManager,
+ @Reference org.openhab.core.automation.module.script.ScriptExtensionAccessor se) {
+ for (var e : se.findDefaultPresets("").entrySet())
+ logger.error("FOUND " + e.getKey() + " VALUE= " + e.getValue().toString());
try {
Files.createDirectories(LIB_DIR);
which prints: I think in ScriptWrappingStrategy.BOILERPLATE_CODE_INJECTED_MEMBERS_DECLARATION protected @InjectBinding ScriptExtensionManagerWrapper scriptExtension;
protected @InjectBinding ScriptExtensionManagerWrapper se;are not useful in statically compiled languages. It exists to call Can also the variables, besides the types, be imported in the same way, from the output of As for the instance variables,
Can these variables also be inserted from the output of |
|
With insertion of the variables from the implicit presets in ScriptWrappingStrategy, instead of hard coding them, I mean something like this, Java223ScriptEngineFactory: @@ -116,7 +116,16 @@ public class Java223ScriptEngineFactory extends JavaScriptEngineFactory
@Reference ItemRegistry itemRegistry, @Reference ThingRegistry thingRegistry,
@Reference Java223DependencyTracker dependencyTracker, @Reference RuleManager ruleManager,
@Reference ThingManager thingManager, @Reference MetadataRegistry metadataRegistry,
- @Reference ScriptEngineManager scriptEngineManager) {
+ @Reference ScriptEngineManager scriptEngineManager,
+ @Reference org.openhab.core.automation.module.script.ScriptExtensionAccessor se) {
+ for (var e : se.findDefaultPresets("").entrySet())
+ if (!(e.getValue() instanceof Class<?>) && !(e.getValue() instanceof Enum<?>)) {
+ Class<?> i[] = e.getValue().getClass().getInterfaces();
+ if (i.length == 0)
+ logger.error("OOO " + e.getValue().toString() + " " + e.getKey().toString() + ";");
+ else
+ logger.error("OOO " + i[0].toGenericString() + " " + e.getKey().toString() + ";");
+ }
try {
Files.createDirectories(LIB_DIR);prints |
Good catch !
Choosing the first interface feels a bit random. |
As spelled at openhab/openhab-docs#2571 the type java.time.ZonedDateTime is available in transformations, is part of the implicit presets. So this sitemap works
This sitemap does not work:
I have to put prefix
java.time.before ZonedDateTime, unless the current patch is applied.The other thing missing from ScriptWrappingStrategy, but part of the default preset, or rather part of the
lifecyclepreset, which like themediaanddefaultpresets is implicitly preloaded, as described at openhab/openhab-docs#2567 ⇔ https://deploy-preview-2567--openhab-docs-preview.netlify.app/docs/configuration/jsr223.html#lifecycle-preset-importpreset-not-required is thelifecycleTrackerobject.I think these imports should not be hard-coded in ScriptWrappingStrategy, but somehow implied, when
Java223ScriptEngineFactory.scopeValues()is invoked.