Search in sources :

Example 6 with DefaultExternalResourceMetaData

use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.

the class S3ResourceConnector method getMetaData.

@Override
public ExternalResourceMetaData getMetaData(ExternalResourceName location, boolean revalidate) {
    LOGGER.debug("Attempting to get resource metadata: {}", location);
    S3Object s3Object = s3Client.getMetaData(location.getUri());
    if (s3Object == null) {
        return null;
    }
    try {
        ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
        return new DefaultExternalResourceMetaData(location.getUri(), objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
        null);
    } finally {
        discardEmptyContentAndClose(s3Object);
    }
}
Also used : S3Object(com.amazonaws.services.s3.model.S3Object) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DefaultExternalResourceMetaData(org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData)

Example 7 with DefaultExternalResourceMetaData

use of org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData in project gradle by gradle.

the class S3Resource method getMetaData.

@Override
public ExternalResourceMetaData getMetaData() {
    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
    Date lastModified = objectMetadata.getLastModified();
    return new DefaultExternalResourceMetaData(uri, lastModified.getTime(), getContentLength(), s3Object.getObjectMetadata().getContentType(), s3Object.getObjectMetadata().getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
    null);
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DefaultExternalResourceMetaData(org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData) Date(java.util.Date)

Aggregations

DefaultExternalResourceMetaData (org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData)7 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 URLConnection (java.net.URLConnection)4 Nullable (javax.annotation.Nullable)4 ResourceException (org.gradle.api.resources.ResourceException)4 UncheckedException (org.gradle.internal.UncheckedException)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 S3Object (com.amazonaws.services.s3.model.S3Object)2 InputStream (java.io.InputStream)2 Date (java.util.Date)1