use of org.commonjava.indy.spi.IndyAddOn in project indy by Commonjava.
the class StatsController method getActiveAddOns.
public AddOnListing getActiveAddOns() {
final List<IndyAddOnID> ids = new ArrayList<IndyAddOnID>();
if (addons != null) {
logger.info("Getting list of installed add-ons...");
for (final IndyAddOn addon : addons) {
final IndyAddOnID id = addon.getId();
logger.info("Adding {}", id);
ids.add(id);
}
}
return new AddOnListing(ids);
}
use of org.commonjava.indy.spi.IndyAddOn in project indy by Commonjava.
the class StatsController method getActiveAddOnsJavascript.
public String getActiveAddOnsJavascript() throws IndyWorkflowException {
try {
final String json = serializer.writeValueAsString(getActiveAddOns());
final Map<String, Object> params = new HashMap<>();
final Map<String, String> jsMap = new HashMap<>();
if (addons != null) {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (final IndyAddOn addon : addons) {
final String jsRef = addon.getId().getInitJavascriptHref();
if (jsRef == null) {
logger.debug("Add-On has no init javascript: {}", addon);
continue;
}
try (InputStream in = cl.getResourceAsStream(jsRef)) {
if (in == null) {
logger.error("Add-On failed to load: {}. Initialization javascript NOT FOUND in classpath: {}", addon, jsRef);
continue;
}
jsMap.put(jsRef, IOUtils.toString(in));
} catch (final IOException e) {
logger.error("Add-On failed to load: {}. Cannot load initialization javascript from classpath: {}", addon, jsRef);
}
}
}
params.put(ADDONS_KEY, json);
params.put(ADDONS_LOGIC, jsMap);
return templates.render(ACTIVE_ADDONS_JS, params);
} catch (final IndyGroovyException e) {
throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
} catch (final JsonProcessingException e) {
throw new IndyWorkflowException("Failed to render javascript wrapper for active addons. Reason: %s", e, e.getMessage());
}
}
Aggregations