diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java index edcc55cdfd..7db5ecb3b2 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioConsoleCommandExtension.java @@ -42,8 +42,8 @@ import org.osgi.service.component.annotations.Reference; * @author Christoph Weitkamp - Added parameter to adjust the volume * @author Wouter Born - Sort audio sink and source options */ -@NonNullByDefault @Component(service = ConsoleCommandExtension.class) +@NonNullByDefault public class AudioConsoleCommandExtension extends AbstractConsoleCommandExtension { static final String SUBCMD_PLAY = "play"; diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java index fb54bba24a..2020acfc65 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java @@ -18,6 +18,7 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.List; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.config.discovery.DiscoveryService; import org.openhab.core.config.discovery.DiscoveryServiceRegistry; import org.openhab.core.io.console.Console; @@ -26,6 +27,7 @@ import org.openhab.core.io.console.extensions.ConsoleCommandExtension; import org.openhab.core.thing.ThingTypeUID; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; @@ -38,6 +40,7 @@ import org.slf4j.LoggerFactory; * @author Dennis Nobel - Added background discovery commands */ @Component(immediate = true, service = ConsoleCommandExtension.class) +@NonNullByDefault public class DiscoveryConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String SUBCMD_START = "start"; @@ -46,12 +49,15 @@ public class DiscoveryConsoleCommandExtension extends AbstractConsoleCommandExte private final Logger logger = LoggerFactory.getLogger(DiscoveryConsoleCommandExtension.class); - private DiscoveryServiceRegistry discoveryServiceRegistry; + private final DiscoveryServiceRegistry discoveryServiceRegistry; + private final ConfigurationAdmin configurationAdmin; - private ConfigurationAdmin configurationAdmin; - - public DiscoveryConsoleCommandExtension() { + @Activate + public DiscoveryConsoleCommandExtension(final @Reference DiscoveryServiceRegistry discoveryServiceRegistry, + final @Reference ConfigurationAdmin configurationAdmin) { super("discovery", "Control the discovery mechanism."); + this.discoveryServiceRegistry = discoveryServiceRegistry; + this.configurationAdmin = configurationAdmin; } @Override @@ -136,22 +142,4 @@ public class DiscoveryConsoleCommandExtension extends AbstractConsoleCommandExte buildCommandUsage(SUBCMD_BACKGROUND_DISCOVERY_DISABLE + " ", "disables background discovery for the discovery service with the given PID") }); } - - @Reference - protected void setDiscoveryServiceRegistry(DiscoveryServiceRegistry discoveryServiceRegistry) { - this.discoveryServiceRegistry = discoveryServiceRegistry; - } - - protected void unsetDiscoveryServiceRegistry(DiscoveryServiceRegistry discoveryServiceRegistry) { - this.discoveryServiceRegistry = null; - } - - @Reference - protected void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) { - this.configurationAdmin = configurationAdmin; - } - - protected void unsetConfigurationAdmin(ConfigurationAdmin configurationAdmin) { - this.configurationAdmin = null; - } } diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java index 5bfbe91540..32c751ea39 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.config.discovery.DiscoveryResult; import org.openhab.core.config.discovery.DiscoveryResultFlag; import org.openhab.core.config.discovery.inbox.Inbox; @@ -29,6 +30,7 @@ import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension; import org.openhab.core.io.console.extensions.ConsoleCommandExtension; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingUID; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -38,6 +40,7 @@ import org.osgi.service.component.annotations.Reference; * @author Kai Kreuzer - Initial contribution */ @Component(immediate = true, service = ConsoleCommandExtension.class) +@NonNullByDefault public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String SUBCMD_APPROVE = "approve"; @@ -47,10 +50,12 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio private static final String SUBCMD_CLEAR = "clear"; private static final String SUBCMD_REMOVE = "remove"; - private Inbox inbox; + private final Inbox inbox; - public InboxConsoleCommandExtension() { + @Activate + public InboxConsoleCommandExtension(final @Reference Inbox inbox) { super("inbox", "Manage your inbox."); + this.inbox = inbox; } @Override @@ -196,13 +201,4 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio "remove the inbox entries of a given thing id or thing type"), buildCommandUsage(SUBCMD_IGNORE + " ", "ignores an inbox entry permanently") }); } - - @Reference - protected void setInbox(Inbox inbox) { - this.inbox = inbox; - } - - protected void unsetInbox(Inbox inbox) { - this.inbox = null; - } } diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/FirmwareUpdateConsoleCommandExtension.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/FirmwareUpdateConsoleCommandExtension.java index d4ef8ad7f0..7607ab7363 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/FirmwareUpdateConsoleCommandExtension.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/FirmwareUpdateConsoleCommandExtension.java @@ -17,6 +17,8 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.io.console.Console; import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension; import org.openhab.core.io.console.extensions.ConsoleCommandExtension; @@ -28,6 +30,7 @@ import org.openhab.core.thing.binding.firmware.FirmwareUpdateHandler; import org.openhab.core.thing.firmware.FirmwareRegistry; import org.openhab.core.thing.firmware.FirmwareStatusInfo; import org.openhab.core.thing.firmware.FirmwareUpdateService; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; @@ -41,6 +44,7 @@ import org.osgi.service.component.annotations.ReferencePolicy; * @author Dimitar Ivanov - The listing of the firmwares is done for thing UID */ @Component(immediate = true, service = ConsoleCommandExtension.class) +@NonNullByDefault public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String SUBCMD_LIST = "list"; @@ -48,13 +52,18 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole private static final String SUBCMD_UPDATE = "update"; private static final String SUBCMD_CANCEL = "cancel"; - private FirmwareUpdateService firmwareUpdateService; - private FirmwareRegistry firmwareRegistry; - private ThingRegistry thingRegistry; + private final FirmwareUpdateService firmwareUpdateService; + private final FirmwareRegistry firmwareRegistry; + private final ThingRegistry thingRegistry; private final List firmwareUpdateHandlers = new CopyOnWriteArrayList<>(); - public FirmwareUpdateConsoleCommandExtension() { + @Activate + public FirmwareUpdateConsoleCommandExtension(final @Reference FirmwareUpdateService firmwareUpdateService, + final @Reference FirmwareRegistry firmwareRegistry, final @Reference ThingRegistry thingRegistry) { super("firmware", "Manage your things' firmwares."); + this.firmwareUpdateService = firmwareUpdateService; + this.firmwareRegistry = firmwareRegistry; + this.thingRegistry = thingRegistry; } @Override @@ -176,7 +185,7 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole console.println("Firmware update started."); } - private FirmwareUpdateHandler getFirmwareUpdateHandler(ThingUID thingUID) { + private @Nullable FirmwareUpdateHandler getFirmwareUpdateHandler(ThingUID thingUID) { for (FirmwareUpdateHandler firmwareUpdateHandler : firmwareUpdateHandlers) { if (thingUID.equals(firmwareUpdateHandler.getThing().getUID())) { return firmwareUpdateHandler; @@ -194,33 +203,6 @@ public final class FirmwareUpdateConsoleCommandExtension extends AbstractConsole SUBCMD_UPDATE + " ", "updates the firmware for a thing") }); } - @Reference - protected void setFirmwareUpdateService(FirmwareUpdateService firmwareUpdateService) { - this.firmwareUpdateService = firmwareUpdateService; - } - - protected void unsetFirmwareUpdateService(FirmwareUpdateService firmwareUpdateService) { - this.firmwareUpdateService = null; - } - - @Reference - protected void setFirmwareRegistry(FirmwareRegistry firmwareRegistry) { - this.firmwareRegistry = firmwareRegistry; - } - - protected void unsetFirmwareRegistry(FirmwareRegistry firmwareRegistry) { - this.firmwareRegistry = null; - } - - @Reference - protected void setThingRegistry(ThingRegistry thingRegistry) { - this.thingRegistry = thingRegistry; - } - - protected void unsetThingRegistry(ThingRegistry thingRegistry) { - this.thingRegistry = null; - } - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) protected void addFirmwareUpdateHandler(FirmwareUpdateHandler firmwareUpdateHandler) { firmwareUpdateHandlers.add(firmwareUpdateHandler); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/LinkConsoleCommandExtension.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/LinkConsoleCommandExtension.java index 3dfb15866b..5704b6435c 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/LinkConsoleCommandExtension.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/LinkConsoleCommandExtension.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.io.console.Console; import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension; import org.openhab.core.io.console.extensions.ConsoleCommandExtension; @@ -43,6 +44,7 @@ import org.osgi.service.component.annotations.Reference; * @author Jan N. Klug - Add orphan link handling */ @Component(immediate = true, service = ConsoleCommandExtension.class) +@NonNullByDefault public class LinkConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String SUBCMD_LIST = "list"; diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/ThingConsoleCommandExtension.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/ThingConsoleCommandExtension.java index 8faa053cab..ba3ec0f3e1 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/ThingConsoleCommandExtension.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/console/ThingConsoleCommandExtension.java @@ -12,8 +12,6 @@ */ package org.openhab.core.thing.internal.console; -import static java.util.Arrays.asList; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -21,6 +19,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.events.EventPublisher; import org.openhab.core.io.console.Console; import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension; @@ -36,6 +36,7 @@ import org.openhab.core.thing.ThingStatusInfo; import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.events.ThingEventFactory; import org.openhab.core.thing.i18n.ThingStatusInfoI18nLocalizationService; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -48,6 +49,7 @@ import org.osgi.service.component.annotations.Reference; * @author Henning Sudbrock - Added show command */ @Component(immediate = true, service = ConsoleCommandExtension.class) +@NonNullByDefault public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String CMD_THINGS = "things"; @@ -59,14 +61,23 @@ public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtensio private static final String SUBCMD_DISABLE = "disable"; private static final String SUBCMD_ENABLE = "enable"; - private ManagedThingProvider managedThingProvider; - private ThingRegistry thingRegistry; - private ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; - private EventPublisher eventPublisher; - private ThingManager thingManager; + private final ManagedThingProvider managedThingProvider; + private final ThingRegistry thingRegistry; + private final ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; + private final EventPublisher eventPublisher; + private final ThingManager thingManager; - public ThingConsoleCommandExtension() { + @Activate + public ThingConsoleCommandExtension(final @Reference ManagedThingProvider managedThingProvider, + final @Reference ThingRegistry thingRegistry, + final @Reference ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService, + final @Reference EventPublisher eventPublisher, final @Reference ThingManager thingManager) { super(CMD_THINGS, "Access your thing registry."); + this.managedThingProvider = managedThingProvider; + this.thingRegistry = thingRegistry; + this.thingStatusInfoI18nLocalizationService = thingStatusInfoI18nLocalizationService; + this.eventPublisher = eventPublisher; + this.thingManager = thingManager; } @Override @@ -79,7 +90,7 @@ public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtensio printThings(console, things); return; case SUBCMD_SHOW: - printThingsDetails(console, asList(args).subList(1, args.length)); + printThingsDetails(console, Arrays.asList(args).subList(1, args.length)); return; case SUBCMD_CLEAR: removeAllThings(console, things); @@ -119,7 +130,7 @@ public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtensio } } - private void triggerChannel(Console console, String channelUid, String event) { + private void triggerChannel(Console console, String channelUid, @Nullable String event) { eventPublisher.post(ThingEventFactory.createTriggerEvent(event, new ChannelUID(channelUid))); } @@ -267,51 +278,4 @@ public class ThingConsoleCommandExtension extends AbstractConsoleCommandExtensio } } } - - @Reference - protected void setManagedThingProvider(ManagedThingProvider managedThingProvider) { - this.managedThingProvider = managedThingProvider; - } - - @Reference - protected void setThingRegistry(ThingRegistry thingRegistry) { - this.thingRegistry = thingRegistry; - } - - protected void unsetManagedThingProvider(ManagedThingProvider managedThingProvider) { - this.managedThingProvider = null; - } - - protected void unsetThingRegistry(ThingRegistry thingRegistry) { - this.thingRegistry = null; - } - - @Reference - protected void setThingStatusInfoI18nLocalizationService( - ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService) { - this.thingStatusInfoI18nLocalizationService = thingStatusInfoI18nLocalizationService; - } - - protected void unsetThingStatusInfoI18nLocalizationService( - ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService) { - this.thingStatusInfoI18nLocalizationService = null; - } - - @Reference - protected void setEventPublisher(EventPublisher eventPublisher) { - this.eventPublisher = eventPublisher; - } - - protected void unsetEventPublisher(EventPublisher eventPublisher) { - this.eventPublisher = null; - } - - @Reference - protected void setThingManager(ThingManager thingManager) { - this.thingManager = thingManager; - } - - protected void unsetThingManager(ThingManager thingManager) { - this.thingManager = null; - } } diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java index fe29b335a2..d990f0b240 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java @@ -16,6 +16,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.io.console.Console; @@ -40,6 +41,7 @@ import org.osgi.service.component.annotations.Reference; * @author Wouter Born - Sort TTS voices */ @Component(service = ConsoleCommandExtension.class) +@NonNullByDefault public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtension { private static final String SUBCMD_SAY = "say";