Java 类org.gradle.api.resources.ResourceException 实例源码

项目:Reer    文件:MavenVersionLister.java   
public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) {
    return new VersionPatternVisitor() {
        final Set<ExternalResourceName> searched = new HashSet<ExternalResourceName>();

        public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException {
            ExternalResourceName metadataLocation = pattern.toModulePath(module).resolve("maven-metadata.xml");
            if (!searched.add(metadataLocation)) {
                return;
            }
            result.attempted(metadataLocation);
            MavenMetadata mavenMetaData = mavenMetadataLoader.load(metadataLocation.getUri());
            for (String version : mavenMetaData.versions) {
                dest.add(version);
            }
        }
    };
}
项目:Reer    文件:SftpClientFactory.java   
public LockableSftpClient createNewClient(SftpHost sftpHost) {
    try {
        Session session = createJsch().getSession(sftpHost.getUsername(), sftpHost.getHostname(), sftpHost.getPort());
        session.setPassword(sftpHost.getPassword());
        session.connect();
        Channel channel = session.openChannel("sftp");
        channel.connect();
        return new DefaultLockableSftpClient(sftpHost, (ChannelSftp) channel, session);
    } catch (JSchException e) {
        URI serverUri = URI.create(String.format("sftp://%s:%d", sftpHost.getHostname(), sftpHost.getPort()));
        if (e.getMessage().equals("Auth fail")) {
            throw new ResourceException(serverUri, String.format("Password authentication not supported or invalid credentials for SFTP server at %s", serverUri), e);
        }
        throw new ResourceException(serverUri, String.format("Could not connect to SFTP server at %s", serverUri), e);
    }
}
项目:Reer    文件:ApacheDirectoryListingParser.java   
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));
    }
    String contentEncoding = UriTextResource.extractCharacterEncoding(contentType, "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);
}
项目:Reer    文件:RepositoryTransportWagonAdapter.java   
public boolean getRemoteFile(File destination, String resourceName) throws ResourceException {
    URI uriForResource = getUriForResource(resourceName);
    ExternalResource resource = transport.getRepository().getResource(uriForResource, false);
    if (resource == null) {
        return false;
    }
    try {
        resource.writeTo(destination);
    } finally {
        resource.close();
    }
    return true;
}
项目:Reer    文件:DefaultExternalResource.java   
@Override
public void close() {
    try {
        response.close();
    } catch (IOException e) {
        throw new ResourceException(uri, String.format("Could not close resource '%s'.", uri), e);
    }
}
项目:Reer    文件:StringBackedTextResource.java   
public File asFile(String charset) {
    File file = tempFileProvider.createTemporaryFile("string", ".txt", "resource");
    try {
        Files.write(string, file, Charset.forName(charset));
    } catch (IOException e) {
        throw new ResourceException("Could not write " + getDisplayName() + " content to " + file + ".", e);
    }
    return file;
}
项目:Pushjet-Android    文件:GzipArchiver.java   
public InputStream read() {
    InputStream is = resource.read();
    try {
        return new GZIPInputStream(is);
    } catch (Exception e) {
        String message = String.format("Unable to create gzip input stream for resource %s.", resource.getDisplayName());
        throw new ResourceException(message, e);
    }
}
项目:Pushjet-Android    文件:Bzip2Archiver.java   
public InputStream read() {
    InputStream is = resource.read();
    try {
        // CBZip2InputStream expects the opening "BZ" to be skipped
        byte[] skip = new byte[2];
        is.read(skip);
        return new CBZip2InputStream(is);
    } catch (Exception e) {
        String message = String.format("Unable to create bzip2 input stream for resource %s.", resource.getDisplayName());
        throw new ResourceException(message, e);
    }
}
项目:Pushjet-Android    文件:GzipArchiver.java   
public InputStream read() {
    InputStream is = resource.read();
    try {
        return new GZIPInputStream(is);
    } catch (Exception e) {
        String message = String.format("Unable to create gzip input stream for resource %s.", resource.getDisplayName());
        throw new ResourceException(message, e);
    }
}
项目:Pushjet-Android    文件:Bzip2Archiver.java   
public InputStream read() {
    InputStream is = resource.read();
    try {
        // CBZip2InputStream expects the opening "BZ" to be skipped
        byte[] skip = new byte[2];
        is.read(skip);
        return new CBZip2InputStream(is);
    } catch (Exception e) {
        String message = String.format("Unable to create bzip2 input stream for resource %s.", resource.getDisplayName());
        throw new ResourceException(message, e);
    }
}
项目:Reer    文件:ResourceExceptions.java   
public static ResourceException readFailed(File location, Throwable failure) {
    return failure(location.toURI(), String.format("Could not read '%s'.", location), failure);
}
项目:Reer    文件:ResourceExceptions.java   
public static ResourceException readFailed(String displayName, Throwable failure) {
    return new ResourceException(String.format("Could not read %s.", displayName), failure);
}
项目:Reer    文件:ResourceExceptions.java   
public static ResourceException getFailed(URI location, Throwable failure) {
    return failure(location, String.format("Could not get resource '%s'.", location), failure);
}
项目:Reer    文件:ResourceExceptions.java   
public static ResourceException putFailed(URI location, Throwable failure) {
    return failure(location, String.format("Could not write to resource '%s'.", location), failure);
}
项目:Reer    文件:UnknownBackingFileReadableResource.java   
@Override
public InputStream read() throws MissingResourceException, ResourceException {
    return resource.read();
}
项目:Reer    文件:LocalResource.java   
/**
 * Unbuffered input stream to read contents of resource.
 */
InputStream open() throws ResourceException;
项目:Reer    文件:ExternalResource.java   
/**
 * Copies the contents of this resource to the given file.
 *
 * @throws ResourceException on failure to copy the content.
 */
void writeTo(File destination) throws ResourceException;
项目:Reer    文件:ExternalResource.java   
/**
 * Copies the binary contents of this resource to the given stream. Does not close the provided stream.
 *
 * @throws ResourceException on failure to copy the content.
 */
void writeTo(OutputStream destination) throws ResourceException;
项目:Reer    文件:ExternalResource.java   
/**
 * Executes the given action against the binary contents of this resource.
 *
 * @throws ResourceException on failure to read the content.
 * @throws org.gradle.api.resources.MissingResourceException when the resource does not exist
 */
void withContent(Action<? super InputStream> readAction) throws ResourceException;
项目:Reer    文件:ExternalResource.java   
/**
 * Executes the given action against the binary contents of this resource.
 *
 * @throws ResourceException on failure to read the content.
 * @throws org.gradle.api.resources.MissingResourceException when the resource does not exist
 */
<T> T withContent(Transformer<? extends T, ? super InputStream> readAction) throws ResourceException;
项目:Reer    文件:ExternalResource.java   
/**
 * Executes the given action against the binary contents and meta-data of this resource.
 * Generally, this method will be less efficient than one of the other {@code withContent} methods that do
 * not provide the meta-data, as additional requests may need to be made to obtain the meta-data.
 *
 * @throws ResourceException on failure to read the content.
 * @throws org.gradle.api.resources.MissingResourceException when the resource does not exist
 */
<T> T withContent(ContentAction<? extends T> readAction) throws ResourceException;
项目:Reer    文件:ExternalResourceLister.java   
/**
 * Lists the direct children of the parent resource
 *
 * @param parent the resource to list from
 * @return A list of the direct children of the <code>parent</code>
 */
@Nullable
List<String> list(URI parent) throws ResourceException;
项目:Reer    文件:ExternalResourceAccessor.java   
/**
 * Read the resource at the given location.
 *
 * If the resource does not exist, this method should return null.
 *
 * If the resource may exist but can't be accessed due to some configuration issue, the implementation
 * must throw an {@link ResourceException} to indicate a fatal condition.
 *
 * @param location The address of the resource to obtain
 * @param revalidate The resource should be revalidated as part of the request
 * @return The resource if it exists, otherwise null. Caller is responsible for closing the result.
 * @throws ResourceException If the resource may exist, but not could be obtained for some reason.
 */
@Nullable
ExternalResourceReadResponse openResource(URI location, boolean revalidate) throws ResourceException;
项目:Reer    文件:ExternalResourceAccessor.java   
/**
 * Obtains only the metadata about the resource.
 *
 * If it is determined that the resource does not exist, this method should return null.
 *
 * If the resource may exist but can't be accessed due to some configuration issue, the implementation
 * must throw an {@link ResourceException} to indicate a fatal condition.
 *
 * @param location The location of the resource to obtain the metadata for
 * @param revalidate The resource should be revalidated as part of the request
 * @return The available metadata, null if the resource doesn't exist
 * @throws ResourceException If the resource may exist, but not could be obtained for some reason
 */
@Nullable
ExternalResourceMetaData getMetaData(URI location, boolean revalidate) throws ResourceException;
项目:Reer    文件:TextResource.java   
/**
 * Returns true if this resource exists, false if it does not exist. A resource exists when it has content associated with it.
 *
 * <p>Note that this method may be expensive when {@link #isContentCached()} returns false, depending on the implementation.
 *
 * @return true if this resource exists.
 * @throws ResourceException On failure to check whether resource exists.
 */
boolean getExists() throws ResourceException;
项目:Reer    文件:TextResource.java   
/**
 * Returns true when the content of this resource is empty. This method is may be more efficient than calling {@link #getText()} and checking the length.
 *
 * <p>Note that this method may be expensive when {@link #isContentCached()} returns false, depending on the implementation.
 *
 * @throws org.gradle.api.resources.MissingResourceException When this resource does not exist.
 * @throws ResourceException On failure to read content.
 */
boolean getHasEmptyContent() throws ResourceException;
项目:Reer    文件:TextResource.java   
/**
 * Returns an *unbuffered* reader over the content of this resource.
 *
 * <p>Note that this method, or reading from the provided reader, may be expensive when {@link #isContentCached()} returns false, depending on the implementation.
 *
 * @throws org.gradle.api.resources.MissingResourceException When this resource does not exist.
 * @throws ResourceException On failure to read content.
 */
Reader getAsReader() throws ResourceException;
项目:Reer    文件:TextResource.java   
/**
 * Returns the content of this resource, as a String.
 *
 * <p>Note that this method may be expensive when {@link #isContentCached()} returns false, depending on the implementation.
 *
 * @return the content. Never returns null.
 * @throws org.gradle.api.resources.MissingResourceException When this resource does not exist.
 * @throws ResourceException On failure to read content.
 */
String getText() throws ResourceException;
项目:Reer    文件:VersionPatternVisitor.java   
/**
 * <p>Adds those versions available for the given pattern.</p>
 *
 * If no versions are listed with the given pattern, then no versions are added.
 * 
 * @throws ResourceException If information for versions cannot be loaded.
 */
void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException;
项目:Reer    文件:ExternalResourceRepository.java   
/**
 * Attempts to fetch the given resource.
 *
 * @param source The location of the resource to obtain
 * @param revalidate Ensure the external resource is not stale
 * @return null if the resource is not found.
 * @throws ResourceException On failure to fetch resource.
 */
@Nullable
ExternalResource getResource(URI source, boolean revalidate) throws ResourceException;
项目:Reer    文件:ExternalResourceRepository.java   
/**
 * Fetches only the metadata for the result.
 *
 * @param source The location of the resource to obtain the metadata for
 * @param revalidate Ensure the external resource is not stale
 * @return The resource metadata, or null if the resource does not exist
 * @throws ResourceException On failure to fetch resource metadata.
 */
@Nullable
ExternalResourceMetaData getResourceMetaData(URI source, boolean revalidate) throws ResourceException;
项目:Reer    文件:ExternalResourceRepository.java   
/**
 * Return a listing of child resources names.
 *
 * @param parent The parent directory from which to generate the listing.
 * @return A listing of the direct children of the given parent. Returns null when the parent resource does not exist.
 * @throws ResourceException On listing failure.
 */
@Nullable
List<String> list(URI parent) throws ResourceException;
项目:Reer    文件:ExternalResource.java   
void close() throws ResourceException;