public Map getCurrentConfigurations()

in src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java [241:309]


    public Map<String, FsResourceConfiguration> getCurrentConfigurations(final URI consoleTargetUrl)
            throws MojoExecutionException {
        final Map<String, FsResourceConfiguration> result = new HashMap<>();
        final URI getUrl = consoleTargetUrl.resolve("configMgr/(service.factoryPid=" + FS_FACTORY + ").json");
        log.debug("Getting current file provider configurations via GET from " + getUrl);
        final HttpGet get = new HttpGet(getUrl);

        try (CloseableHttpResponse response = httpClient.execute(get)) {
            final int status = response.getCode();
            if (status == HttpStatus.SC_OK) {
                String contentType = response.getHeader(HEADER_CONTENT_TYPE).getValue();
                int pos = contentType.indexOf(';');
                if (pos != -1) {
                    contentType = contentType.substring(0, pos);
                }
                if (!JsonSupport.JSON_MIME_TYPE.equals(contentType)) {
                    log.debug("Response type from web console is not JSON, but " + contentType);
                    throw new MojoExecutionException("The Apache Felix Web Console is too old to mount "
                            + "the initial content through file system provider configs. "
                            + "Either upgrade the web console or disable this feature.");
                }
                final String jsonText = EntityUtils.toString(response.getEntity());
                try {
                    JsonArray array = JsonSupport.parseArray(jsonText);
                    for (int i = 0; i < array.size(); i++) {
                        final JsonObject obj = array.getJsonObject(i);
                        final String pid = obj.getString("pid");
                        final JsonObject properties = obj.getJsonObject("properties");
                        final String fsmode = getConfigPropertyValue(properties, PROPERTY_FSMODE);
                        final String path = getConfigPropertyValue(properties, PROPERTY_PATH);
                        final String initialContentImportOptions =
                                getConfigPropertyValue(properties, PROPERTY_INITIAL_CONTENT_IMPORT_OPTIONS);
                        final String fileVaultFilterXml =
                                getConfigPropertyValue(properties, PROPERTY_FILEVAULT_FILTER_XML);
                        String root = getConfigPropertyValue(properties, PROPERTY_ROOTS);
                        if (root == null) {
                            root = getConfigPropertyValue(properties, PROPERTY_ROOT);
                        }
                        if (path != null
                                && path.startsWith(this.project.getBasedir().getAbsolutePath())
                                && root != null) {
                            FsResourceConfiguration cfg = new FsResourceConfiguration()
                                    .fsMode(fsmode)
                                    .resourceRootPath(root)
                                    .fsRootPath(new File(path))
                                    .initialContentImportOptions(initialContentImportOptions)
                                    .fileVaultFilterXml(fileVaultFilterXml);
                            log.debug("Found configuration with pid: " + pid + ", " + cfg);
                            result.put(pid, cfg);
                        }
                    }
                    if (array.isEmpty()) {
                        log.info("Found no existing configurations for factory PID " + FS_FACTORY);
                    }
                } catch (JsonException ex) {
                    throw new MojoExecutionException(
                            "Reading configuration from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
                }
            } else {
                throw new HttpResponseException(
                        response.getCode(),
                        "Unexpected status code " + response.getCode() + ": " + response.getReasonPhrase());
            }
        } catch (IOException | ProtocolException ex) {
            throw new MojoExecutionException(
                    "Reading configuration from " + getUrl + " failed, cause: " + ex.getMessage(), ex);
        }
        return result;
    }