GUI -- Clean up of index.html and onos.js generation.
Change-Id: Icc1cdeb0e36b29bb76cee9d90fb342e131b78644
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
index a30c047..ac1a8bb 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
@@ -62,9 +62,9 @@
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
- int p1s = split(index, 0, INJECT_JS_START);
+ int p1s = split(index, 0, INJECT_JS_START) - INJECT_JS_START.length();
int p1e = split(index, p1s, INJECT_JS_END);
- int p2s = split(index, p1e, INJECT_CSS_START);
+ int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
int p2e = split(index, p2s, INJECT_CSS_END);
int p3s = split(index, p2e, null);
@@ -78,17 +78,23 @@
return Response.ok(new SequenceInputStream(streams)).build();
}
- // Produces an input stream including CSS injections from all extensions.
- private InputStream includeCss(UiExtensionService service) {
- Builder<InputStream> builder = ImmutableList.builder();
- service.getExtensions().forEach(ext -> add(builder, ext.css()));
- return new SequenceInputStream(new StreamEnumeration(builder.build()));
- }
-
// Produces an input stream including JS injections from all extensions.
private InputStream includeJs(UiExtensionService service) {
Builder<InputStream> builder = ImmutableList.builder();
- service.getExtensions().forEach(ext -> add(builder, ext.js()));
+ service.getExtensions().forEach(ext -> {
+ add(builder, ext.js());
+ add(builder, new NewlineInputStream());
+ });
+ return new SequenceInputStream(new StreamEnumeration(builder.build()));
+ }
+
+ // Produces an input stream including CSS injections from all extensions.
+ private InputStream includeCss(UiExtensionService service) {
+ Builder<InputStream> builder = ImmutableList.builder();
+ service.getExtensions().forEach(ext -> {
+ add(builder, ext.css());
+ add(builder, new NewlineInputStream());
+ });
return new SequenceInputStream(new StreamEnumeration(builder.build()));
}
@@ -99,4 +105,19 @@
}
}
+ private static final String NL = String.format("%n");
+ private static final byte[] NL_BYTES = NL.getBytes();
+
+ private static class NewlineInputStream extends InputStream {
+ private int index = 0;
+
+ @Override
+ public int read() throws IOException {
+ if (index == NL_BYTES.length) {
+ return -1;
+ }
+ return NL_BYTES[index++];
+ }
+ }
+
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
index 42d1dff..92725d9 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainModuleResource.java
@@ -43,6 +43,8 @@
private static final String INJECT_VIEW_IDS_START = "// {INJECTED-VIEW-IDS-START}";
private static final String INJECT_VIEW_IDS_END = "// {INJECTED-VIEW-IDS-END}";
+ private static final String PREFIX = " '";
+ private static final String SUFFIX = String.format("',%n");
@GET
@Produces(SCRIPT)
@@ -51,7 +53,7 @@
InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
String js = new String(toByteArray(jsTemplate));
- int p1s = split(js, 0, INJECT_VIEW_IDS_START);
+ int p1s = split(js, 0, INJECT_VIEW_IDS_START) - INJECT_VIEW_IDS_START.length();
int p1e = split(js, 0, INJECT_VIEW_IDS_END);
int p2s = split(js, p1e, null);
@@ -68,7 +70,7 @@
StringBuilder sb = new StringBuilder("\n");
for (UiExtension extension : service.getExtensions()) {
for (UiView view : extension.views()) {
- sb.append(" '").append(view.id()).append("',");
+ sb.append(PREFIX).append(view.id()).append(SUFFIX);
}
}
return new ByteArrayInputStream(sb.toString().getBytes());