Revisit parents handling in drivers command
Change-Id: I35050a0790e871be69bb5517bb49223def97f624
diff --git a/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java b/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
index d18a2db..4349922 100644
--- a/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/DriversListCommand.java
@@ -15,7 +15,10 @@
*/
package org.onosproject.cli.net;
+import java.util.List;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
@@ -24,6 +27,7 @@
import org.onosproject.net.driver.DriverAdminService;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.google.common.collect.ImmutableList;
/**
* Lists device drivers.
@@ -68,19 +72,17 @@
private void printDriver(Driver driver) {
if (outputJson()) {
json(driver);
- } else if (driver.parents() != null) {
- driver.parents().forEach(parent -> {
- print(FMT, driver.name(), parent != null ? parent.name() : "none",
- driver.manufacturer(), driver.hwVersion(), driver.swVersion());
- driver.behaviours().forEach(b -> print(FMT_B, b.getCanonicalName(),
- driver.implementation(b).getCanonicalName()));
- driver.properties().forEach((k, v) -> print(FMT_P, k, v));
- });
- } else if (driver.parents() == null) {
- print(FMT, driver.name(), "none", driver.manufacturer(),
- driver.hwVersion(), driver.swVersion());
+ } else {
+ List<String> parents = Optional.ofNullable(driver.parents())
+ .orElse(ImmutableList.of())
+ .stream()
+ .map(Driver::name)
+ .collect(Collectors.toList());
+
+ print(FMT, driver.name(), parents,
+ driver.manufacturer(), driver.hwVersion(), driver.swVersion());
driver.behaviours().forEach(b -> print(FMT_B, b.getCanonicalName(),
- driver.implementation(b).getCanonicalName()));
+ driver.implementation(b).getCanonicalName()));
driver.properties().forEach((k, v) -> print(FMT_P, k, v));
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/Driver.java b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
index d82ea4b..7af83b4 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/Driver.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/Driver.java
@@ -45,6 +45,7 @@
@Deprecated
Driver parent();
+ // TODO should revise behaviour to return empty List when driver has no parent
/**
* Returns all the parent drivers from which this driver inherits behaviours
* and properties.