From cfe4df1da2343b36ec7c9a707cd7c77fd637d5ba Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 15 Nov 2017 16:42:30 +0200 Subject: [PATCH 01/21] Moved closing of kryoOutput to finally block --- paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java b/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java index 46c2866..9aab65b 100644 --- a/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java +++ b/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java @@ -261,15 +261,16 @@ private File getOriginalFile(String key) { */ private void writeTableFile(String key, PaperTable paperTable, File originalFile, File backupFile) { + Output kryoOutput = null; try { FileOutputStream fileStream = new FileOutputStream(originalFile); - - final Output kryoOutput = new Output(fileStream); + kryoOutput = new Output(fileStream); getKryo().writeObject(kryoOutput, paperTable); kryoOutput.flush(); fileStream.flush(); sync(fileStream); kryoOutput.close(); //also close file stream + kryoOutput = null; // Writing was successful, delete the backup file if there is one. //noinspection ResultOfMethodCallIgnored @@ -284,6 +285,10 @@ private void writeTableFile(String key, PaperTable paperTable, } throw new PaperDbException("Couldn't save table: " + key + ". " + "Backed up table will be used on next read attempt", e); + } finally { + if (kryoOutput != null) { + kryoOutput.close(); // closing opened kryo output with initial file stream. + } } } From 3508e2a744739b138d4ff153de8d48206f91f56e Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Fri, 21 Feb 2020 23:47:20 +0200 Subject: [PATCH 02/21] upgrade gradle wrapper --- app/build.gradle | 9 ++++----- build.gradle | 3 ++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- paperdb/build.gradle | 17 ++++++++--------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9e228ce..f0f1763 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion 26 // Must be the same version as in travis.xml - buildToolsVersion "26.0.1" defaultConfig { applicationId "paperdb.io.paperdb" @@ -22,12 +21,12 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:26.1.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:26.1.0' //compile project(':paperdb') - compile 'io.paperdb:paperdb:2.6' + implementation 'io.paperdb:paperdb:2.6' - androidTestCompile('com.android.support.test:runner:0.5') { + androidTestImplementation('com.android.support.test:runner:0.5') { exclude group: 'com.android.support', module: 'support-annotations' } } diff --git a/build.gradle b/build.gradle index 03b9b6c..32cf264 100644 --- a/build.gradle +++ b/build.gradle @@ -7,9 +7,10 @@ buildscript { url 'https://maven.google.com/' name 'Google' } + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:3.5.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 01d0cfa..abad0e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Oct 05 10:39:58 BST 2016 +#Fri Feb 21 23:37:43 EET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/paperdb/build.gradle b/paperdb/build.gradle index 3e525cb..a0e2352 100644 --- a/paperdb/build.gradle +++ b/paperdb/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' buildscript { - ext.kotlin_version = '1.1.50' + ext.kotlin_version = '1.3.10' repositories { mavenCentral() } @@ -17,7 +17,6 @@ repositories { android { compileSdkVersion 26 // Must be the same version as in travis.xml - buildToolsVersion "26.0.1" defaultConfig { minSdkVersion 8 @@ -58,14 +57,14 @@ afterEvaluate { } dependencies { - compile 'com.esotericsoftware:kryo:4.0.1' - compile 'de.javakaffee:kryo-serializers:0.40' + implementation 'com.esotericsoftware:kryo:4.0.1' + implementation 'de.javakaffee:kryo-serializers:0.40' - androidTestCompile 'com.orhanobut:hawk:1.14' - androidTestCompile 'com.android.support.test:runner:0.5' - androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0' - androidTestCompile 'joda-time:joda-time:2.9.1' - androidTestCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + androidTestImplementation 'com.orhanobut:hawk:1.14' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.squareup.assertj:assertj-android:1.1.0' + androidTestImplementation 'joda-time:joda-time:2.9.6' + androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } apply from: '../publish.gradle' From ccddaf693fad7b864919903c93ef345661d22db2 Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Fri, 21 Feb 2020 23:50:24 +0200 Subject: [PATCH 03/21] upgrade compile SDK to 28 before migrating to Androidx --- app/build.gradle | 6 +++--- paperdb/build.gradle | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f0f1763..1576cf5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 + compileSdkVersion 28 // Must be the same version as in travis.xml defaultConfig { applicationId "paperdb.io.paperdb" minSdkVersion 15 - targetSdkVersion 26 + targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -22,7 +22,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:appcompat-v7:28.0.0' //compile project(':paperdb') implementation 'io.paperdb:paperdb:2.6' diff --git a/paperdb/build.gradle b/paperdb/build.gradle index a0e2352..80cd002 100644 --- a/paperdb/build.gradle +++ b/paperdb/build.gradle @@ -15,12 +15,12 @@ repositories { } android { - compileSdkVersion 26 + compileSdkVersion 28 // Must be the same version as in travis.xml defaultConfig { minSdkVersion 8 - targetSdkVersion 26 + targetSdkVersion 28 versionCode 1 versionName "1.0" From 0c8f9d251dc7f7a4111a134f52ded2cf3370e731 Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Sat, 22 Feb 2020 01:31:59 +0200 Subject: [PATCH 04/21] migrate to Androidx --- app/build.gradle | 10 +++++----- .../java/paperdb/io/paperdb/ReadBenchmark.java | 4 ++-- .../io/paperdb/testdata/TestDataGenerator.java | 2 +- .../main/java/paperdb/io/paperdb/MainActivity.java | 2 +- gradle.properties | 2 ++ paperdb/build.gradle | 12 ++++++------ .../java/io/paperdb/CompatibilityTest.java | 4 ++-- .../java/io/paperdb/CustomBookLocationTest.java | 4 ++-- .../androidTest/java/io/paperdb/CustomBookTest.java | 4 ++-- .../src/androidTest/java/io/paperdb/DataTest.java | 4 ++-- .../src/androidTest/java/io/paperdb/PaperTest.java | 4 ++-- .../java/io/paperdb/VersionUpgradeTest.java | 4 ++-- .../java/io/paperdb/benchmark/Benchmark.java | 4 ++-- .../java/io/paperdb/deprecated/DataTest.java | 4 ++-- .../paperdb/deprecated/PaperDeprecatedAPITest.java | 4 ++-- .../java/io/paperdb/multithread/MultiThreadTest.java | 6 +++--- .../java/io/paperdb/testdata/TestDataGenerator.java | 2 +- .../androidTest/java/io/paperdb/utils/TestUtils.java | 2 +- .../kotlin/io/paperdb/KotlinCompatibilityTest.kt | 4 ++-- 19 files changed, 42 insertions(+), 40 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1576cf5..ce48b41 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,17 +1,17 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 29 // Must be the same version as in travis.xml defaultConfig { applicationId "paperdb.io.paperdb" minSdkVersion 15 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -22,11 +22,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'androidx.appcompat:appcompat:1.1.0' //compile project(':paperdb') implementation 'io.paperdb:paperdb:2.6' - androidTestImplementation('com.android.support.test:runner:0.5') { + androidTestImplementation('androidx.test.ext:junit:1.1.1') { exclude group: 'com.android.support', module: 'support-annotations' } } diff --git a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java index dea7f5b..d8b6006 100644 --- a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java +++ b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java @@ -1,7 +1,7 @@ package paperdb.io.paperdb; import android.os.SystemClock; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import android.util.Log; import org.junit.Before; @@ -17,7 +17,7 @@ import paperdb.io.paperdb.testdata.Person; import paperdb.io.paperdb.testdata.TestDataGenerator; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) diff --git a/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java b/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java index 9448c84..81c8da6 100644 --- a/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java +++ b/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java @@ -1,6 +1,6 @@ package paperdb.io.paperdb.testdata; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import java.util.ArrayList; import java.util.HashMap; diff --git a/app/src/main/java/paperdb/io/paperdb/MainActivity.java b/app/src/main/java/paperdb/io/paperdb/MainActivity.java index 2fa9225..72c0760 100644 --- a/app/src/main/java/paperdb/io/paperdb/MainActivity.java +++ b/app/src/main/java/paperdb/io/paperdb/MainActivity.java @@ -1,7 +1,7 @@ package paperdb.io.paperdb; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; diff --git a/gradle.properties b/gradle.properties index 686b8df..22e8818 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,3 @@ +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m \ No newline at end of file diff --git a/paperdb/build.gradle b/paperdb/build.gradle index 80cd002..a4b35d7 100644 --- a/paperdb/build.gradle +++ b/paperdb/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' buildscript { - ext.kotlin_version = '1.3.10' + ext.kotlin_version = '1.3.61' repositories { mavenCentral() } @@ -15,18 +15,18 @@ repositories { } android { - compileSdkVersion 28 + compileSdkVersion 29 // Must be the same version as in travis.xml defaultConfig { - minSdkVersion 8 - targetSdkVersion 28 + minSdkVersion 14 + targetSdkVersion 29 versionCode 1 versionName "1.0" consumerProguardFiles 'proguard.txt' - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -61,7 +61,7 @@ dependencies { implementation 'de.javakaffee:kryo-serializers:0.40' androidTestImplementation 'com.orhanobut:hawk:1.14' - androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'com.squareup.assertj:assertj-android:1.1.0' androidTestImplementation 'joda-time:joda-time:2.9.6' androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java b/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java index b53d309..697baab 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java @@ -1,6 +1,6 @@ package io.paperdb; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; @@ -8,7 +8,7 @@ import java.lang.reflect.Field; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java b/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java index 6975b23..36f62f1 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java @@ -1,6 +1,6 @@ package io.paperdb; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import junit.framework.Assert; @@ -11,7 +11,7 @@ import java.io.File; import java.util.HashSet; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; diff --git a/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java b/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java index 51a0c80..ea24dc5 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java @@ -1,12 +1,12 @@ package io.paperdb; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertFalse; diff --git a/paperdb/src/androidTest/java/io/paperdb/DataTest.java b/paperdb/src/androidTest/java/io/paperdb/DataTest.java index ec29cd8..c69a1d6 100644 --- a/paperdb/src/androidTest/java/io/paperdb/DataTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/DataTest.java @@ -1,6 +1,6 @@ package io.paperdb; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; @@ -17,7 +17,7 @@ import io.paperdb.testdata.Person; import io.paperdb.testdata.PersonArg; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static io.paperdb.testdata.TestDataGenerator.genPerson; import static io.paperdb.testdata.TestDataGenerator.genPersonList; import static io.paperdb.testdata.TestDataGenerator.genPersonMap; diff --git a/paperdb/src/androidTest/java/io/paperdb/PaperTest.java b/paperdb/src/androidTest/java/io/paperdb/PaperTest.java index 1c17bca..a733a7c 100644 --- a/paperdb/src/androidTest/java/io/paperdb/PaperTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/PaperTest.java @@ -1,7 +1,7 @@ package io.paperdb; import android.os.SystemClock; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -16,7 +16,7 @@ import io.paperdb.testdata.TestDataGenerator; import io.paperdb.utils.TestUtils; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static junit.framework.Assert.assertEquals; import static junit.framework.TestCase.assertTrue; import static org.assertj.core.api.Assertions.assertThat; diff --git a/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java b/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java index ea397f8..36cf0b8 100644 --- a/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java @@ -1,6 +1,6 @@ package io.paperdb; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; @@ -11,7 +11,7 @@ import io.paperdb.utils.TestUtils; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static org.assertj.core.api.Assertions.assertThat; @RunWith(AndroidJUnit4.class) diff --git a/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java b/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java index 7956e2b..c501c13 100644 --- a/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java +++ b/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java @@ -1,7 +1,7 @@ package io.paperdb.benchmark; import android.os.SystemClock; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -18,7 +18,7 @@ import io.paperdb.testdata.PersonArg; import io.paperdb.testdata.TestDataGenerator; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; @RunWith(AndroidJUnit4.class) @LargeTest diff --git a/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java b/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java index d06d417..a7b5521 100644 --- a/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java @@ -1,6 +1,6 @@ package io.paperdb.deprecated; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; @@ -17,7 +17,7 @@ import io.paperdb.Paper; import io.paperdb.testdata.Person; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static io.paperdb.testdata.TestDataGenerator.genPerson; import static io.paperdb.testdata.TestDataGenerator.genPersonList; import static io.paperdb.testdata.TestDataGenerator.genPersonMap; diff --git a/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java b/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java index 391d7ce..58b9544 100644 --- a/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java +++ b/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java @@ -1,6 +1,6 @@ package io.paperdb.deprecated; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Before; import org.junit.Test; @@ -12,7 +12,7 @@ import io.paperdb.PaperDbException; import io.paperdb.testdata.TestDataGenerator; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static junit.framework.TestCase.assertTrue; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertFalse; diff --git a/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java b/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java index aedf000..0551c17 100644 --- a/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java @@ -1,7 +1,7 @@ package io.paperdb.multithread; -import android.support.annotation.NonNull; -import android.support.test.runner.AndroidJUnit4; +import androidx.annotation.NonNull; +import androidx.test.ext.junit.runners.AndroidJUnit4; import android.util.Log; import org.junit.Before; @@ -23,7 +23,7 @@ import io.paperdb.testdata.Person; import io.paperdb.testdata.TestDataGenerator; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/paperdb/src/androidTest/java/io/paperdb/testdata/TestDataGenerator.java b/paperdb/src/androidTest/java/io/paperdb/testdata/TestDataGenerator.java index 20d1fc2..d052c92 100644 --- a/paperdb/src/androidTest/java/io/paperdb/testdata/TestDataGenerator.java +++ b/paperdb/src/androidTest/java/io/paperdb/testdata/TestDataGenerator.java @@ -1,6 +1,6 @@ package io.paperdb.testdata; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import java.util.ArrayList; import java.util.HashMap; diff --git a/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java b/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java index 363ec26..b63d033 100644 --- a/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java +++ b/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java @@ -6,7 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; -import static android.support.test.InstrumentationRegistry.getTargetContext; +import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; public class TestUtils { diff --git a/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt b/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt index a074da7..06cd1b0 100644 --- a/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt +++ b/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt @@ -1,7 +1,7 @@ package io.paperdb -import android.support.test.InstrumentationRegistry.getTargetContext -import android.support.test.runner.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry.getTargetContext +import androidx.test.ext.junit.runners.AndroidJUnit4 import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test From b33cf8c7e3aa9bda4b6d0478991797c24592148b Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Sat, 22 Feb 2020 01:53:06 +0200 Subject: [PATCH 05/21] implementing paper module --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ce48b41..4901ec5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,8 +23,8 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' - //compile project(':paperdb') - implementation 'io.paperdb:paperdb:2.6' + implementation project(':paperdb') +// implementation 'io.paperdb:paperdb:2.6' androidTestImplementation('androidx.test.ext:junit:1.1.1') { exclude group: 'com.android.support', module: 'support-annotations' From 5334a04d14bcb43b52b4e016eaaa911b415b7e67 Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Fri, 13 Mar 2020 17:37:04 +0200 Subject: [PATCH 06/21] fixing android test and moving kotlin test to java package --- .../java/paperdb/io/paperdb/ReadBenchmark.java | 2 +- build.gradle | 3 ++- paperdb/build.gradle | 8 +++++++- .../androidTest/java/io/paperdb/CompatibilityTest.java | 2 +- .../java/io/paperdb/CustomBookLocationTest.java | 3 ++- .../src/androidTest/java/io/paperdb/CustomBookTest.java | 2 +- paperdb/src/androidTest/java/io/paperdb/DataTest.java | 2 +- paperdb/src/androidTest/java/io/paperdb/PaperTest.java | 2 +- .../androidTest/java/io/paperdb/VersionUpgradeTest.java | 2 +- .../androidTest/java/io/paperdb/benchmark/Benchmark.java | 5 +++-- .../androidTest/java/io/paperdb/deprecated/DataTest.java | 2 +- .../io/paperdb/deprecated/PaperDeprecatedAPITest.java | 2 +- .../io/paperdb/kotlin}/KotlinCompatibilityTest.kt | 7 ++++--- .../java/io/paperdb/multithread/MultiThreadTest.java | 2 +- .../src/androidTest/java/io/paperdb/utils/TestUtils.java | 2 +- 15 files changed, 28 insertions(+), 18 deletions(-) rename paperdb/src/androidTest/{kotlin/io/paperdb => java/io/paperdb/kotlin}/KotlinCompatibilityTest.kt (94%) diff --git a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java index d8b6006..4e639c2 100644 --- a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java +++ b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java @@ -17,7 +17,7 @@ import paperdb.io.paperdb.testdata.Person; import paperdb.io.paperdb.testdata.TestDataGenerator; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) diff --git a/build.gradle b/build.gradle index 32cf264..26889c3 100644 --- a/build.gradle +++ b/build.gradle @@ -3,11 +3,11 @@ buildscript { repositories { jcenter() + google() maven { url 'https://maven.google.com/' name 'Google' } - google() } dependencies { classpath 'com.android.tools.build:gradle:3.5.3' @@ -22,6 +22,7 @@ buildscript { allprojects { repositories { jcenter() + google() maven { url 'https://maven.google.com/' name 'Google' diff --git a/paperdb/build.gradle b/paperdb/build.gradle index a4b35d7..e0c7d09 100644 --- a/paperdb/build.gradle +++ b/paperdb/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-android-extensions' buildscript { ext.kotlin_version = '1.3.61' @@ -45,6 +47,9 @@ android { sourceSets { test.java.srcDirs += 'src/androidTest/kotlin' } + useLibrary 'android.test.runner' + useLibrary 'android.test.base' + useLibrary 'android.test.mock' } afterEvaluate { @@ -59,7 +64,8 @@ afterEvaluate { dependencies { implementation 'com.esotericsoftware:kryo:4.0.1' implementation 'de.javakaffee:kryo-serializers:0.40' - + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'com.orhanobut:hawk:1.14' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'com.squareup.assertj:assertj-android:1.1.0' diff --git a/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java b/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java index 697baab..b2c0caa 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CompatibilityTest.java @@ -8,7 +8,7 @@ import java.lang.reflect.Field; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java b/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java index 36f62f1..18605e1 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CustomBookLocationTest.java @@ -1,5 +1,6 @@ package io.paperdb; +import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import junit.framework.Assert; @@ -11,7 +12,7 @@ import java.io.File; import java.util.HashSet; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; diff --git a/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java b/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java index ea24dc5..1fcd529 100644 --- a/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/CustomBookTest.java @@ -6,7 +6,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertFalse; diff --git a/paperdb/src/androidTest/java/io/paperdb/DataTest.java b/paperdb/src/androidTest/java/io/paperdb/DataTest.java index c69a1d6..4f9a7da 100644 --- a/paperdb/src/androidTest/java/io/paperdb/DataTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/DataTest.java @@ -17,7 +17,7 @@ import io.paperdb.testdata.Person; import io.paperdb.testdata.PersonArg; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static io.paperdb.testdata.TestDataGenerator.genPerson; import static io.paperdb.testdata.TestDataGenerator.genPersonList; import static io.paperdb.testdata.TestDataGenerator.genPersonMap; diff --git a/paperdb/src/androidTest/java/io/paperdb/PaperTest.java b/paperdb/src/androidTest/java/io/paperdb/PaperTest.java index a733a7c..be79452 100644 --- a/paperdb/src/androidTest/java/io/paperdb/PaperTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/PaperTest.java @@ -16,7 +16,7 @@ import io.paperdb.testdata.TestDataGenerator; import io.paperdb.utils.TestUtils; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static junit.framework.Assert.assertEquals; import static junit.framework.TestCase.assertTrue; import static org.assertj.core.api.Assertions.assertThat; diff --git a/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java b/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java index 36cf0b8..0ca8ec6 100644 --- a/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/VersionUpgradeTest.java @@ -11,7 +11,7 @@ import io.paperdb.utils.TestUtils; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static org.assertj.core.api.Assertions.assertThat; @RunWith(AndroidJUnit4.class) diff --git a/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java b/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java index c501c13..07ccb9c 100644 --- a/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java +++ b/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java @@ -2,8 +2,9 @@ import android.os.SystemClock; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; import com.orhanobut.hawk.Hawk; @@ -18,7 +19,7 @@ import io.paperdb.testdata.PersonArg; import io.paperdb.testdata.TestDataGenerator; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; @RunWith(AndroidJUnit4.class) @LargeTest diff --git a/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java b/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java index a7b5521..e3c3c53 100644 --- a/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/deprecated/DataTest.java @@ -17,7 +17,7 @@ import io.paperdb.Paper; import io.paperdb.testdata.Person; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static io.paperdb.testdata.TestDataGenerator.genPerson; import static io.paperdb.testdata.TestDataGenerator.genPersonList; import static io.paperdb.testdata.TestDataGenerator.genPersonMap; diff --git a/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java b/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java index 58b9544..77a3908 100644 --- a/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java +++ b/paperdb/src/androidTest/java/io/paperdb/deprecated/PaperDeprecatedAPITest.java @@ -12,7 +12,7 @@ import io.paperdb.PaperDbException; import io.paperdb.testdata.TestDataGenerator; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static junit.framework.TestCase.assertTrue; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertFalse; diff --git a/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt b/paperdb/src/androidTest/java/io/paperdb/kotlin/KotlinCompatibilityTest.kt similarity index 94% rename from paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt rename to paperdb/src/androidTest/java/io/paperdb/kotlin/KotlinCompatibilityTest.kt index 06cd1b0..0da8e5f 100644 --- a/paperdb/src/androidTest/kotlin/io/paperdb/KotlinCompatibilityTest.kt +++ b/paperdb/src/androidTest/java/io/paperdb/kotlin/KotlinCompatibilityTest.kt @@ -1,14 +1,15 @@ -package io.paperdb +package io.paperdb.io.paperdb -import androidx.test.platform.app.InstrumentationRegistry.getTargetContext +import androidx.test.InstrumentationRegistry.getTargetContext import androidx.test.ext.junit.runners.AndroidJUnit4 +import io.paperdb.Paper import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) -class KotlinCompatibilityTest { +class KotlinCompatibilityTest{ @Before @Throws(Exception::class) diff --git a/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java b/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java index 0551c17..1074197 100644 --- a/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java +++ b/paperdb/src/androidTest/java/io/paperdb/multithread/MultiThreadTest.java @@ -23,7 +23,7 @@ import io.paperdb.testdata.Person; import io.paperdb.testdata.TestDataGenerator; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java b/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java index b63d033..327b234 100644 --- a/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java +++ b/paperdb/src/androidTest/java/io/paperdb/utils/TestUtils.java @@ -6,7 +6,7 @@ import java.io.InputStream; import java.io.OutputStream; -import static androidx.test.platform.app.InstrumentationRegistry.getTargetContext; +import static androidx.test.InstrumentationRegistry.getTargetContext; public class TestUtils { From d7000563daf7a4bc829180113e7df7dd7315c3fc Mon Sep 17 00:00:00 2001 From: Mohamed Wael Date: Fri, 13 Mar 2020 17:41:31 +0200 Subject: [PATCH 07/21] removing extra google maven repo --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 26889c3..3bf0e75 100644 --- a/build.gradle +++ b/build.gradle @@ -4,10 +4,6 @@ buildscript { repositories { jcenter() google() - maven { - url 'https://maven.google.com/' - name 'Google' - } } dependencies { classpath 'com.android.tools.build:gradle:3.5.3' @@ -23,10 +19,6 @@ allprojects { repositories { jcenter() google() - maven { - url 'https://maven.google.com/' - name 'Google' - } } tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') From 52d387dbec4c010ad11fd46f7d750543a43de3a6 Mon Sep 17 00:00:00 2001 From: pilgr Date: Mon, 17 Feb 2020 14:31:04 +0100 Subject: [PATCH 08/21] Reproduce the issue with crash on multi-thread paper db dir creation --- .../java/paperdb/io/paperdb/MainActivity.java | 31 +++++++++++++++- app/src/main/res/layout/activity_main.xml | 36 +++++++++++-------- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/paperdb/io/paperdb/MainActivity.java b/app/src/main/java/paperdb/io/paperdb/MainActivity.java index 72c0760..9740bc2 100644 --- a/app/src/main/java/paperdb/io/paperdb/MainActivity.java +++ b/app/src/main/java/paperdb/io/paperdb/MainActivity.java @@ -2,6 +2,7 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -36,7 +37,7 @@ public void onClick(View v) { } }); - final Button btnRead = (Button) findViewById(R.id.test_read); + final Button btnRead = findViewById(R.id.test_read); btnRead.setOnClickListener(new View.OnClickListener() { @Override @@ -50,6 +51,34 @@ public void onClick(View v) { btnRead.setText("Read: " + o1.getValue() + " : " + o2.getValue().get(0)); } }); + + final Button btnReadWriteAsync = findViewById(R.id.test_read_write_async); + btnReadWriteAsync.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + testReadWriteAsync(); + } + }); + } + + private void testReadWriteAsync() { + final int iterations = 10; + readWriteKey("key1", iterations); + readWriteKey("key2", iterations); + } + + private void readWriteKey(final String key, final int iterations) { + new Thread() { + @Override + public void run() { + for (int i = 0; i < iterations; i++) { + Paper.book().write(key, "key:" + key + " iteration#" + i); + Log.d("PAPER_APP", "" + Paper.book().read(key)); + // This caused the issue on multi-thread paper db dir creation + Paper.book().destroy(); + } + } + }.start(); } @Override diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c2d240d..ba005cb 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,28 +1,34 @@ - +