UI-Lion: Better instrumentation of the Lion-bundle-building process.
Change-Id: I67bb035612ed76bda866a56e670674d29535fdd6
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 83af0d7..dfc4edf 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -81,6 +81,7 @@
import static org.onosproject.security.AppPermission.Type.UI_WRITE;
import static org.onosproject.ui.UiView.Category.NETWORK;
import static org.onosproject.ui.UiView.Category.PLATFORM;
+import static org.onosproject.ui.impl.lion.BundleStitcher.generateBundles;
/**
* Manages the user interface extensions.
@@ -223,9 +224,7 @@
);
return new UiExtension.Builder(CL, coreViews)
- // TODO: currently broken, until BundleStitcher & LionConfig
- // have been moved to web.gui module...
-// .lionBundles(generateBundles(LION_BASE, LION_TAGS))
+ .lionBundles(generateBundles(LION_BASE, LION_TAGS))
.messageHandlerFactory(messageHandlerFactory)
.topoOverlayFactory(topoOverlayFactory)
.topo2OverlayFactory(topo2OverlayFactory)
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/lion/BundleStitcher.java b/web/gui/src/main/java/org/onosproject/ui/impl/lion/BundleStitcher.java
index aaeab93..a6fc390 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/lion/BundleStitcher.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/lion/BundleStitcher.java
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
@@ -66,31 +67,52 @@
*
* @param id the bundle ID
* @return a corresponding lion bundle
- * @throws IllegalArgumentException if the bundle config cannot be loaded
+ * @throws IllegalArgumentException if the config cannot be loaded
+ * or the bundle cannot be stitched
*/
public LionBundle stitch(String id) {
String source = base + SLASH + CONFIG_DIR + SLASH + id + SUFFIX;
+
+ // the following may throw IllegalArgumentException...
LionConfig cfg = new LionConfig().load(source);
+
LionBundle.Builder builder = new LionBundle.Builder(id);
+ int total = 0;
+ int added = 0;
for (LionConfig.CmdFrom from : cfg.entries()) {
- addItemsToBuilder(builder, from);
+ total += 1;
+ log.debug(" processing: {}", from.orig());
+ if (addItemsToBuilder(builder, from)) {
+ added += 1;
+ }
}
-
+ log.debug(" added items for {}/{} FROM entries", added, total);
return builder.build();
}
- private void addItemsToBuilder(LionBundle.Builder builder,
- LionConfig.CmdFrom from) {
+ private boolean addItemsToBuilder(LionBundle.Builder builder,
+ LionConfig.CmdFrom from) {
String resBundleName = base + SLASH + from.res();
String resFqbn = convertToFqbn(resBundleName);
- ResourceBundle bundle = LionUtils.getBundledResource(resFqbn);
+ ResourceBundle bundle = null;
+ boolean ok = true;
- if (from.starred()) {
- addAllItems(builder, bundle);
- } else {
- addItems(builder, bundle, from.keys());
+ try {
+ bundle = LionUtils.getBundledResource(resFqbn);
+ } catch (MissingResourceException e) {
+ log.warn("Cannot find resource bundle: {}", resFqbn);
+ log.debug("BOOM!", e);
+ ok = false;
}
+
+ if (ok) {
+ Set<String> keys = from.starred() ? bundle.keySet() : from.keys();
+ addItems(builder, bundle, keys);
+ log.debug(" added {} item(s) from {}", keys.size(), from.res());
+ }
+
+ return ok;
}
// to fully-qualified-bundle-name
@@ -101,10 +123,6 @@
return path.substring(1).replaceAll(SLASH, DOT);
}
- private void addAllItems(LionBundle.Builder builder, ResourceBundle bundle) {
- addItems(builder, bundle, bundle.keySet());
- }
-
private void addItems(LionBundle.Builder builder, ResourceBundle bundle,
Set<String> keys) {
keys.forEach(k -> builder.addItem(k, bundle.getString(k)));
@@ -148,19 +166,20 @@
* @param tags the list of bundles to generate
* @return a list of generated localization bundles
*/
- public static List<LionBundle> generateBundles(String base,
- String... tags) {
- List<LionBundle> result = new ArrayList<>(tags.length);
+ public static List<LionBundle> generateBundles(String base, String... tags) {
+ List<LionBundle> bundles = new ArrayList<>(tags.length);
BundleStitcher stitcher = new BundleStitcher(base);
for (String tag : tags) {
try {
- LionBundle b = stitcher.stitch(tag);
- result.add(b);
+ LionBundle lion = stitcher.stitch(tag);
+ bundles.add(lion);
+ log.info("Generated LION bundle: {}", lion);
} catch (IllegalArgumentException e) {
log.warn("Unable to generate bundle: {} / {}", base, tag);
+ log.debug("BOOM!", e);
}
}
- return ImmutableList.copyOf(result);
+ return ImmutableList.copyOf(bundles);
}
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/lion/LionConfig.java b/web/gui/src/main/java/org/onosproject/ui/impl/lion/LionConfig.java
index 9147a1b..f324f99 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/lion/LionConfig.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/lion/LionConfig.java
@@ -283,6 +283,15 @@
Cmd(String orig) {
this.orig = orig;
}
+
+ /**
+ * Returns the original string from the configuration file.
+ *
+ * @return original from string
+ */
+ public String orig() {
+ return orig;
+ }
}
private static final class CmdBundle extends Cmd {