use of org.gradle.api.resources.ResourceException in project gradle by gradle.
the class SftpResourceLister method list.
public List<String> list(URI directory) {
LockableSftpClient client = sftpClientFactory.createSftpClient(directory, credentials);
try {
@SuppressWarnings("unchecked") Vector<ChannelSftp.LsEntry> entries = client.getSftpClient().ls(directory.getPath());
List<String> list = new ArrayList<String>();
for (ChannelSftp.LsEntry entry : entries) {
list.add(entry.getFilename());
}
return list;
} catch (com.jcraft.jsch.SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
return null;
}
throw new ResourceException(directory, String.format("Could not list children for resource '%s'.", directory), e);
} finally {
sftpClientFactory.releaseSftpClient(client);
}
}
use of org.gradle.api.resources.ResourceException in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.
private HashValue getResourceSha1(URI location, boolean revalidate) {
try {
URI sha1Location = new URI(location.toASCIIString() + ".sha1");
ExternalResource resource = delegate.getResource(sha1Location, revalidate);
if (resource == null) {
return null;
}
try {
return resource.withContent(new Transformer<HashValue, InputStream>() {
@Override
public HashValue transform(InputStream inputStream) {
try {
String sha = IOUtils.toString(inputStream, "us-ascii");
return HashValue.parse(sha);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
} finally {
resource.close();
}
} catch (Exception e) {
throw new ResourceException(location, String.format("Failed to download SHA1 for resource '%s'.", location), e);
}
}
use of org.gradle.api.resources.ResourceException in project gradle by gradle.
the class ApacheDirectoryListingParser method parse.
public List<String> parse(URI baseURI, InputStream content, String contentType) throws Exception {
baseURI = addTrailingSlashes(baseURI);
if (contentType == null || !contentType.startsWith("text/html")) {
throw new ResourceException(baseURI, String.format("Unsupported ContentType %s for directory listing '%s'", contentType, baseURI));
}
Charset contentEncoding = UriTextResource.extractCharacterEncoding(contentType, Charsets.UTF_8);
final Reader htmlText = new InputStreamReader(content, contentEncoding);
final InputSource inputSource = new InputSource(htmlText);
final SAXParser htmlParser = new SAXParser();
final AnchorListerHandler anchorListerHandler = new AnchorListerHandler();
htmlParser.setContentHandler(anchorListerHandler);
htmlParser.parse(inputSource);
List<String> hrefs = anchorListerHandler.getHrefs();
List<URI> uris = resolveURIs(baseURI, hrefs);
return filterNonDirectChilds(baseURI, uris);
}
use of org.gradle.api.resources.ResourceException in project gradle by gradle.
the class SftpResourceLister method list.
@Override
public List<String> list(ExternalResourceName directory) {
LockableSftpClient client = sftpClientFactory.createSftpClient(directory.getUri(), credentials);
try {
@SuppressWarnings("unchecked") Vector<ChannelSftp.LsEntry> entries = client.getSftpClient().ls(directory.getPath());
List<String> list = new ArrayList<String>();
for (ChannelSftp.LsEntry entry : entries) {
list.add(entry.getFilename());
}
return list;
} catch (com.jcraft.jsch.SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
return null;
}
throw new ResourceException(directory.getUri(), String.format("Could not list children for resource '%s'.", directory.getUri()), e);
} finally {
sftpClientFactory.releaseSftpClient(client);
}
}
Aggregations