Skip to content

Commit

Permalink
Merge pull request #17 from loilo-inc/withOkhttp
Browse files Browse the repository at this point in the history
With okhttp
  • Loading branch information
hayama-junpei committed May 7, 2016
2 parents 04e0221 + 6463ce3 commit e2f6413
Show file tree
Hide file tree
Showing 141 changed files with 2,932 additions and 391 deletions.
4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Expand All @@ -17,6 +17,11 @@ allprojects {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}

task clean(type: Delete) {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ org.gradle.configureondemand=true

# for gradle-mvn-push.gradle
# Build and Push -> $ gradlew clean build uploadArchives
#VERSION_NAME=0.3.1
VERSION_NAME=0.3.1-SNAPSHOT
VERSION_CODE=7
#VERSION_NAME=0.4.0
VERSION_NAME=0.4.0-SNAPSHOT
VERSION_CODE=8
GROUP=tv.loilo.promise

POM_DESCRIPTION=A simple promise library for Android(Java and Kotlin)
Expand Down
21 changes: 18 additions & 3 deletions gradle/gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,23 @@ afterEvaluate { project ->
}

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
source = android.sourceSets.main.java.srcDirs
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = project.files(android.getBootClasspath().join(File.pathSeparator)) + files(ext.androidJar)

options {
links("http://docs.oracle.com/javase/jp/7/api/");
linksOffline("http://d.android.com/reference", "${android.sdkDirectory}/docs/reference")
setMemberLevel(JavadocMemberLevel.PUBLIC)
docEncoding = 'UTF-8'
encoding = 'UTF-8'
charSet = 'UTF-8'
}

exclude '**/BuildConfig.java'
exclude '**/R.java'

failOnError false
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
Expand All @@ -108,7 +123,7 @@ afterEvaluate { project ->

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
from android.sourceSets.main.java.srcDirs
}

artifacts {
Expand Down
1 change: 1 addition & 0 deletions promise-http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions promise-http/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode Integer.parseInt(VERSION_CODE)
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.google.code.gson:gson:2.6.2'
compile project(':promise')
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 changes: 3 additions & 0 deletions promise-http/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_NAME=loilo-promise-http
POM_ARTIFACT_ID=promise-http
POM_PACKAGING=aar
17 changes: 17 additions & 0 deletions promise-http/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/pepeotoito/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2015-2016 LoiLo inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package tv.loilo.promise.http;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2015-2016 LoiLo inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package tv.loilo.promise.http;

import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class HttpContentDispositionTest {

//see http://greenbytes.de/tech/tc2231/#attwithfn2231utf8

//@DataPoints
public static Fixture[] FIXTURES = {
new Fixture(true, "", null),
new Fixture(true, "inline", new Expected("inline", null, null, null)),
new Fixture(true, "inline; filename=\"foo.html\"", new Expected("inline", "foo.html", null, null)),
new Fixture(true, "inline; filename=\"Not an attachment!\"", new Expected("inline", "Not an attachment!", null, null)),
new Fixture(true, "inline; filename=\"foo.pdf\"", new Expected("inline", "foo.pdf", null, null)),
new Fixture(true, "attachment", new Expected("attachment", null, null, null)),
new Fixture(true, "ATTACHMENT", new Expected("attachment", null, null, null)),
new Fixture(true, "attachment; filename=\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; filename=\"0000000000111111111122222\"", new Expected("attachment", "0000000000111111111122222", null, null)),
new Fixture(true, "attachment; filename=\"00000000001111111111222222222233333\"", new Expected("attachment", "00000000001111111111222222222233333", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"f\\oo.html\"", new Expected("attachment", "f\\oo.html", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"\\\"quoting\\\" tested.html\"", new Expected("attachment", "\"quoting\" tested.html", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"Here's a semicolon;.html\"", new Expected("attachment", "Here's a semicolon;.html", null, null)),
new Fixture(true, "attachment; foo=\"bar\"; filename=\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; FILENAME=\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; filename=foo.html", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; filename='foo.bar'", new Expected("attachment", "foo.bar", null, null)),
new Fixture(true, "attachment; filename=\"foo-ä.html\"", new Expected("attachment", "foo-ä.html", null, null)),
new Fixture(true, "attachment; filename=\"foo-ä.html\"", new Expected("attachment", "foo-ä.html", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"foo-%41.html\"", new Expected("attachment", "foo-%41.html", null, null)),
new Fixture(true, "attachment; filename=\"50%.html\"", new Expected("attachment", "50%.html", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"foo-%\\41.html\"", new Expected("attachment", "foo-%41.html", null, null)),
new Fixture(true, "attachment; name=\"foo-%41.html\"", new Expected("attachment", null, null, "foo-%41.html")),
new Fixture(/* 失敗していい */false, "attachment; filename=\"ä-%41.html\"", new Expected("attachment", "ä-%41.html", null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"", new Expected("attachment", "foo-%c3%a4-%e2%82%ac.html", null, null)),
new Fixture(true, "attachment; filename =\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; xfilename=foo.html", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; filename=\"/foo.html\"", new Expected("attachment", "/foo.html", null, null)),
new Fixture(true, "attachment; filename=\"\\\\foo.html\"", new Expected("attachment", "\\foo.html", null, null)),
new Fixture(true, "attachment; creation-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"", new Expected("attachment", null, null, null)),
new Fixture(true, "attachment; modification-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */true, "foobar", new Expected("foobar", null, null, null)),
new Fixture(true, "attachment; example=\"filename=example.txt\"", new Expected("attachment", null, null, null)),
new Fixture(true, "attachment; filename*=iso-8859-1''foo-%E4.html", new Expected("attachment", null, "foo-ä.html", null)),
new Fixture(true, "attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html", new Expected("attachment", null, "foo-ä-€.html", null)),
new Fixture(true, "attachment; filename*=''foo-%c3%a4-%e2%82%ac.html", new Expected("attachment", null, "foo-%c3%a4-%e2%82%ac.html", null)),
new Fixture(true, "attachment; filename*=UTF-8''foo-a%cc%88.html", new Expected("attachment", null, "foo-ä.html", null)),
new Fixture(true, "attachment; filename*= UTF-8''foo-%c3%a4.html", new Expected("attachment", null, "foo-ä.html", null)),
new Fixture(true, "attachment; filename* =UTF-8''foo-%c3%a4.html", new Expected("attachment", null, "foo-ä.html", null)),
new Fixture(true, "attachment; filename*=UTF-8''A-%2541.html", new Expected("attachment", null, "A-%41.html", null)),
new Fixture(true, "attachment; filename*=UTF-8''%5cfoo.html", new Expected("attachment", null, "\\foo.html", null)),
new Fixture(/* 失敗していい */false, "attachment; filename*0=\"foo.\"; filename*1=\"html\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*0=\"foo\"; filename*1=\"\\b\\a\\r.html\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*0*=UTF-8''foo-%c3%a4; filename*1=\".html\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*0=\"foo\"; filename*01=\"bar\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*0=\"foo\"; filename*2=\"bar\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*1=\"foo.\"; filename*2=\"html\"", new Expected("attachment", null, null, null)),
new Fixture(/* 失敗していい */false, "attachment; filename*1=\"bar\"; filename*0=\"foo\"", new Expected("attachment", null, null, null)),
new Fixture(true, "attachment; filename*=UTF-8''foo-%c3%a4.html; filename=\"foo-ae.html\"", new Expected("attachment", "foo-ae.html", "foo-ä.html", null)),
new Fixture(true, "attachment; filename=\"foo-ae.html\"; filename*=UTF-8''foo-%c3%a4.html", new Expected("attachment", "foo-ae.html", "foo-ä.html", null)),
new Fixture(true, "attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4", new Expected("attachment", null, "currency-sign=¤", null)),
new Fixture(true, "attachment; foobar=x; filename=\"foo.html\"", new Expected("attachment", "foo.html", null, null)),
new Fixture(true, "attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"", new Expected("attachment", "=?ISO-8859-1?Q?foo-=E4.html?=", null, null))
};

@Test
public void testTryParse() throws Exception {
for(final Fixture fixture : FIXTURES){
testFixture(fixture);
}
}

public void testFixture(final Fixture fixture) throws Exception {
if (!fixture.mEnable) {
return;
}
final HttpContentDisposition result = HttpContentDisposition.tryParse(fixture.mInput);
if (fixture.mExpected == null) {
assertThat(result, nullValue());
} else {
assertThat(result, notNullValue());
assertThat(result.getDispositionType(), equalTo(fixture.mExpected.mDispositionType));
assertThat(result.getFileName(), equalTo(fixture.mExpected.mFileName));
assertThat(result.getFileNameStar(), equalTo(fixture.mExpected.mFileNameStar));
assertThat(result.getName(), equalTo(fixture.mExpected.mName));
}
}

public static class Expected {
private final String mDispositionType;
private final String mFileName;
private final String mFileNameStar;
private final String mName;

public Expected(final String dispositionType, final String fileName, final String fileNameStar, final String name) {
mDispositionType = dispositionType;
mFileName = fileName;
mFileNameStar = fileNameStar;
mName = name;
}
}

public static class Fixture {
private final boolean mEnable;
private final String mInput;
private final Expected mExpected;

public Fixture(final boolean enable, final String input, final Expected expected) {
mEnable = enable;
mInput = input;
mExpected = expected;
}
}
}
12 changes: 12 additions & 0 deletions promise-http/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tv.loilo.promise.http">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
>

</application>

</manifest>
Loading

0 comments on commit e2f6413

Please sign in to comment.