Added nullness annotations and constructor injection for ConsoleCommandExtensions (#1549)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>pull/1554/head
parent
236efd5862
commit
4b77d29f13
|
@ -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";
|
||||
|
|
|
@ -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 + " <PID>",
|
||||
"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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 + " <thingUID>", "ignores an inbox entry permanently") });
|
||||
}
|
||||
|
||||
@Reference
|
||||
protected void setInbox(Inbox inbox) {
|
||||
this.inbox = inbox;
|
||||
}
|
||||
|
||||
protected void unsetInbox(Inbox inbox) {
|
||||
this.inbox = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FirmwareUpdateHandler> 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 + " <thingUID> <firmware version>", "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);
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue