From 48a958dc7f1c52d4ec6d51b9ae1034c2a513af79 Mon Sep 17 00:00:00 2001 From: Shawn Aten Date: Tue, 29 Aug 2017 12:09:50 -0500 Subject: [PATCH 01/20] Reorganize build.gradle and add integ test config --- build.gradle | 111 ++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index b057508..ee44a5e 100644 --- a/build.gradle +++ b/build.gradle @@ -11,16 +11,20 @@ apply plugin: 'maven-publish' group = 'com.filestack' sourceCompatibility = 1.7 -version = getVersion() +version = file(new File('VERSION')).text.trim() // Get version string from VERSION text file -repositories { - jcenter() +// ***************************************** Config *********************************************** + +configurations { + integTestCompile.extendsFrom testCompile + integTestRuntime.extendsFrom testRuntime + integTestImplementation.extendsFrom testImplementation } dependencies { testImplementation 'junit:junit:4.12' // Testing testImplementation 'org.mockito:mockito-core:2.8.47' // Mocking - testImplementation 'com.squareup.retrofit2:retrofit-mock:2.3.0' // Testing helpers for Retrofit + testImplementation 'com.squareup.retrofit2:retrofit-mock:2.3.0' // Helpers for Retrofit compile 'com.squareup.okhttp3:okhttp:3.8.0' // Low-level HTTP client compile 'com.squareup.retrofit2:retrofit:2.3.0' // High-level HTTP client @@ -34,36 +38,40 @@ dependencies { compile 'io.reactivex.rxjava2:rxjava:2.1.2' // Observable pattern for async methods } - -// ***************************************** General Config *************************************** - -checkstyle { - toolVersion '8.1' -} - -jacocoTestReport { - reports { - xml.enabled = true - html.enabled = true - } -} - javadoc { destinationDir new File("./docs") options.optionFiles(new File('./config/javadoc/javadoc.txt')) } -// ***************************************** General Config *************************************** - +// Publications define artifacts to upload to Bintray +publishing { + publications { + Maven(MavenPublication) { + from components.java + artifact sourcesJar + artifact javadocJar + } + } +} -// ***************************************** Version Config *************************************** +repositories { + jcenter() +} -// Get version string from VERSION text file -def getVersion() { - return file(new File('VERSION')).text.trim() +sourceSets { + integTest { + java { + compileClasspath += main.output + test.output + runtimeClasspath += main.output + test.output + srcDir file('src/integTest/java') + } + resources.srcDir file('src/integTest/resources') + } } -// Create version properties file from VERSION text file +// ***************************************** Tasks ************************************************ + +// Output version to version.properties file task createProperties(dependsOn: processResources) { doLast { new File("$buildDir/resources/main/version.properties").withWriter { w -> @@ -74,28 +82,33 @@ task createProperties(dependsOn: processResources) { } } -// Add task to build process -classes { - dependsOn createProperties +// Run integration tests +task integTest(type: Test) { + testClassesDir = sourceSets.integTest.output.classesDir + classpath = sourceSets.integTest.runtimeClasspath + outputs.upToDateWhen { false } } -// ***************************************** Version Config *************************************** - +// Create javadoc artifact jar +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} -// ***************************************** Bintray Config *************************************** +// Create source artifact jar +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource +} -// Publications define artifacts to upload to Bintray -publishing { - publications { - Maven(MavenPublication) { - from components.java - artifact sourcesJar - artifact javadocJar - } - } +classes.dependsOn createProperties // Create version.properties as part of build +integTest.mustRunAfter test // Run integration tests after unit tests +tasks.withType(Test) { // Put unit and integration test reports in separate directories + reports.html.destination = file("${reporting.baseDir}/${name}") } -// Bintray publishing config +// *************************************** Plugin Config ****************************************** + bintray { user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') @@ -127,15 +140,13 @@ bintray { } } -// Tasks for creating artifact jars -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource +checkstyle { + toolVersion '8.1' } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir +jacocoTestReport { + reports { + xml.enabled = true + html.enabled = true + } } - -// ***************************************** Bintray Config *************************************** From 787580ac7ceb0b8e6ce789095446f7ca9f80d847 Mon Sep 17 00:00:00 2001 From: Shawn Aten Date: Tue, 29 Aug 2017 15:33:42 -0500 Subject: [PATCH 02/20] Add generalized StorageOptions to replace StoreOptions and UploadOptions --- .../java/com/filestack/StorageOptions.java | 108 ++++++++++++++++++ .../filestack/transforms/TransformTask.java | 2 +- 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/filestack/StorageOptions.java diff --git a/src/main/java/com/filestack/StorageOptions.java b/src/main/java/com/filestack/StorageOptions.java new file mode 100644 index 0000000..493c1d8 --- /dev/null +++ b/src/main/java/com/filestack/StorageOptions.java @@ -0,0 +1,108 @@ +package com.filestack; + +import com.filestack.transforms.TransformTask; +import com.filestack.util.Util; +import java.util.HashMap; +import java.util.Map; +import okhttp3.RequestBody; + +public class StorageOptions { + private String access; + private Boolean base64Decode; + private String container; + private String filename; + private String location; + private String path; + private String region; + + public StorageOptions() { } + + public TransformTask getAsTask() { + TransformTask task = new TransformTask("store"); + addToTask(task); + return task; + } + + public void addToTask(TransformTask task) { + task.addOption("access", access); + task.addOption("base64decode", base64Decode); + task.addOption("container", container); + task.addOption("filename", filename); + task.addOption("location", location); + task.addOption("path", path); + task.addOption("region", region); + } + + public Map getAsPartMap() { + HashMap map = new HashMap<>(); + addToMap(map, "store_access", access); + addToMap(map, "store_container", container); + addToMap(map, "store_location", location != null ? location : "s3"); + addToMap(map, "store_path", path); + addToMap(map, "store_region", region); + return map; + } + + private static void addToMap(Map map, String key, String value) { + if (value != null) { + map.put(key, Util.createStringPart(value)); + } + } + + public static class Builder { + private String access; + private Boolean base64Decode; + private String container; + private String filename; + private String location; + private String path; + private String region; + + public Builder access(String access) { + this.access = access; + return this; + } + + public Builder base64Decode(boolean base64Decode) { + this.base64Decode = base64Decode; + return this; + } + + public Builder container(String container) { + this.container = container; + return this; + } + + public Builder filename(String filename) { + this.filename = filename; + return this; + } + + public Builder location(String location) { + this.location = location; + return this; + } + + public Builder path(String path) { + this.path = path; + return this; + } + + public Builder region(String region) { + this.region = region; + return this; + } + + public StorageOptions build() { + StorageOptions building = new StorageOptions(); + building.access = access; + building.base64Decode = base64Decode; + building.container = container; + building.filename = filename; + building.location = location; + building.path = path; + building.region = region; + return building; + } + } +} diff --git a/src/main/java/com/filestack/transforms/TransformTask.java b/src/main/java/com/filestack/transforms/TransformTask.java index 0f01adf..82a76d4 100644 --- a/src/main/java/com/filestack/transforms/TransformTask.java +++ b/src/main/java/com/filestack/transforms/TransformTask.java @@ -12,7 +12,7 @@ public class TransformTask { String name; ArrayList