Search in sources :

Example 1 with IndyAddOn

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);
}
Also used : AddOnListing(org.commonjava.indy.model.spi.AddOnListing) IndyAddOn(org.commonjava.indy.spi.IndyAddOn) ArrayList(java.util.ArrayList) IndyAddOnID(org.commonjava.indy.model.spi.IndyAddOnID)

Example 2 with IndyAddOn

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());
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IndyAddOn(org.commonjava.indy.spi.IndyAddOn) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Aggregations

IndyAddOn (org.commonjava.indy.spi.IndyAddOn)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 AddOnListing (org.commonjava.indy.model.spi.AddOnListing)1 IndyAddOnID (org.commonjava.indy.model.spi.IndyAddOnID)1 IndyGroovyException (org.commonjava.indy.subsys.template.IndyGroovyException)1