public List getFileList()

in wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java [209:279]


    public List<String> getFileList(String destinationDirectory)
            throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
        String repositoryUrl = repository.getUrl();
        String url = repositoryUrl + (repositoryUrl.endsWith("/") ? "" : "/") + destinationDirectory;

        HttpPropfind method = null;
        CloseableHttpResponse closeableHttpResponse = null;
        try {
            if (isDirectory(url)) {
                DavPropertyNameSet nameSet = new DavPropertyNameSet();
                nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_DISPLAYNAME));

                method = new HttpPropfind(url, nameSet, DavConstants.DEPTH_1);
                closeableHttpResponse = execute(method);
                if (method.succeeded(closeableHttpResponse)) {
                    ArrayList<String> dirs = new ArrayList<>();
                    MultiStatus multiStatus = method.getResponseBodyAsMultiStatus(closeableHttpResponse);
                    for (int i = 0; i < multiStatus.getResponses().length; i++) {
                        MultiStatusResponse response = multiStatus.getResponses()[i];
                        String entryUrl = response.getHref();
                        String fileName = PathUtils.filename(URLDecoder.decode(entryUrl));
                        if (entryUrl.endsWith("/")) {
                            if (i == 0) {
                                // by design jackrabbit WebDAV sticks parent directory as the first entry
                                // so we need to ignore this entry
                                // http://www.webdav.org/specs/rfc4918.html#rfc.section.9.1
                                continue;
                            }

                            // extract "dir/" part of "path.to.dir/"
                            fileName = PathUtils.filename(PathUtils.dirname(URLDecoder.decode(entryUrl))) + "/";
                        }

                        if (!(fileName == null || fileName.isEmpty())) {
                            dirs.add(fileName);
                        }
                    }
                    return dirs;
                }

                int statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
                String reasonPhrase = closeableHttpResponse.getStatusLine().getReasonPhrase();
                if (statusCode == HttpStatus.SC_NOT_FOUND || statusCode == HttpStatus.SC_GONE) {
                    EntityUtils.consumeQuietly(closeableHttpResponse.getEntity());
                    throw new ResourceDoesNotExistException(
                            formatResourceDoesNotExistMessage(url, statusCode, reasonPhrase, getProxyInfo()));
                }
            }
        } catch (HttpException e) {
            throw new TransferFailedException(e.getMessage(), e);
        } catch (DavException e) {
            throw new TransferFailedException(e.getMessage(), e);
        } catch (IOException e) {
            throw new TransferFailedException(e.getMessage(), e);
        } finally {
            // TODO olamy: not sure we still need this!!
            if (method != null) {
                method.releaseConnection();
            }
            if (closeableHttpResponse != null) {
                try {
                    closeableHttpResponse.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
        // FIXME WAGON-580; actually the exception is wrong here; we need an IllegalStateException here
        throw new ResourceDoesNotExistException(
                "Destination path exists but is not a " + "WebDAV collection (directory): " + url);
    }