private void addBundle()

in src/main/java/org/apache/sling/adapter/internal/AdapterWebConsolePlugin.java [163:211]


    private void addBundle(final Bundle bundle) {
        final List<AdaptableDescription> descs = new ArrayList<>();
        try {
            final Enumeration<URL> files = bundle.getResources("SLING-INF/adapters.json");
            if (files != null) {
                while (files.hasMoreElements()) {
                    try (final Reader reader =
                            new InputStreamReader(files.nextElement().openStream(), StandardCharsets.UTF_8)) {
                        final Map<String, Object> config = new HashMap<>();
                        config.put("org.apache.johnzon.supports-comments", true);
                        final JsonObject obj = Json.createReaderFactory(config)
                                .createReader(reader)
                                .readObject();
                        for (final Iterator<String> adaptableNames =
                                        obj.keySet().iterator();
                                adaptableNames.hasNext(); ) {
                            final String adaptableName = adaptableNames.next();
                            final JsonObject adaptable = obj.getJsonObject(adaptableName);
                            for (final Iterator<String> conditions =
                                            adaptable.keySet().iterator();
                                    conditions.hasNext(); ) {
                                final String condition = conditions.next();
                                String[] adapters;
                                final Object value = adaptable.get(condition);
                                if (value instanceof JsonArray) {
                                    adapters = toStringArray((JsonArray) value);
                                } else {
                                    adapters = new String[] {unbox(value).toString()};
                                }
                                descs.add(new AdaptableDescription(bundle, adaptableName, adapters, condition, false));
                            }
                        }
                    }
                }
            }
            if (!descs.isEmpty()) {
                synchronized (this) {
                    adapterBundles.put(bundle, descs);
                    update();
                }
            }
        } catch (final IOException e) {
            logger.error("Unable to load adapter descriptors for bundle " + bundle, e);
        } catch (final JsonException e) {
            logger.error("Unable to load adapter descriptors for bundle " + bundle, e);
        } catch (IllegalStateException e) {
            logger.debug("Unable to load adapter descriptors for bundle " + bundle);
        }
    }