Misc improvements and cleanups (#47)

* Add kotlin plugin to cache module

* Remove custom accessors in StoreDefaults as default values are effectively constant.

* Update JUnit to 4.13 RC2 to enable  asserting specific error message on expected exception.

* Remove custom accessors in MemoryPolicy as all values are calculated from constants.

* Remove checkstyle and pmd as the codebase will be 100% Kotlin.

* Fix IDE warning in build.gradle by removing static imports.

* Remove unused guava dependencies.

* Improve StoreDefaults docs.
This commit is contained in:
ychescale9 2019-12-27 05:21:52 +11:00 committed by Mike Nakhimovich
parent 3b43bc6283
commit ba3bf9fd2e
11 changed files with 41 additions and 99 deletions

View file

@ -41,7 +41,6 @@ dependencies {
testImplementation libraries.junit
testImplementation libraries.mockito
testImplementation libraries.junit
testImplementation libraries.coroutinesTest
testCompileOnly libraries.jsr305
implementation libraries.supportRecyclerView
@ -56,7 +55,6 @@ dependencies {
implementation libraries.lifecycleExtensions
implementation libraries.picasso
implementation libraries.guava
implementation libraries.moshi
implementation libraries.retrofitMoshiConverter
kapt(libraries.moshiCodegen)

View file

@ -1,6 +1,3 @@
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
buildscript {
repositories {
mavenCentral()
@ -89,6 +86,6 @@ subprojects {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
project.plugins.withType(AppPlugin).whenPluginAdded(preDexClosure)
project.plugins.withType(LibraryPlugin).whenPluginAdded(preDexClosure)
project.plugins.withType(com.android.build.gradle.AppPlugin).whenPluginAdded(preDexClosure)
project.plugins.withType(com.android.build.gradle.LibraryPlugin).whenPluginAdded(preDexClosure)
}

View file

@ -17,14 +17,13 @@ ext.versions = [
okio : '2.4.1',
gson : '2.8.6',
moshi : '1.9.2',
guava : '28.1-jre',
javax : '1',
room : '2.2.2',
coreKtx : '1.1.0',
lifecycle : '2.2.0-alpha04',
// Testing.
junit : '4.12',
junit : '4.13-rc-2',
truth : '1.0',
mockito : '2.24.0',
mockitoKotlin : '2.2.0',
@ -52,7 +51,6 @@ ext.libraries = [
gson : "com.google.code.gson:gson:$versions.gson",
moshi : "com.squareup.moshi:moshi:$versions.moshi",
moshiCodegen : "com.squareup.moshi:moshi-kotlin-codegen:$versions.moshi",
guava : "com.google.guava:guava:$versions.guava",
javax : "javax.inject:javax.inject:$versions.javax",
kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin",
roomCompiler : "androidx.room:room-compiler:$versions.room",

28
cache/build.gradle vendored
View file

@ -1,10 +1,12 @@
apply plugin: 'java'
group = GROUP
version = VERSION_NAME
apply plugin: 'java' // TODO remove once migrated to kotlin
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.dokka'
dependencies {
compileOnly libraries.jsr305
implementation libraries.kotlinStdLib
testImplementation libraries.junit
testImplementation libraries.truth
}
buildscript {
@ -14,4 +16,22 @@ buildscript {
}
}
group = GROUP
version = VERSION_NAME
apply from: rootProject.file("gradle/maven-push.gradle")
targetCompatibility = 1.8
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

View file

@ -27,14 +27,9 @@ dependencies {
testImplementation libraries.mockitoKotlin
testImplementation libraries.truth
testImplementation libraries.junit
testImplementation libraries.guava
testImplementation libraries.gson
testImplementation libraries.coroutinesTest
testCompileOnly libraries.jsr305
}
apply from: rootProject.file("gradle/maven-push.gradle")
apply from: rootProject.file("gradle/checkstyle.gradle")
apply from: rootProject.file("gradle/pmd.gradle")

View file

@ -1,35 +0,0 @@
apply plugin: 'checkstyle'
if(tasks.findByName('lint') != null) {
assemble.dependsOn('lint')
}
check.dependsOn('checkstyle')
configurations {
checksytleOverride
}
dependencies {
checksytleOverride('com.puppycrawl.tools:checkstyle:7.1.1')
}
tasks.withType(Checkstyle) {
checkstyleClasspath = project.configurations.checksytleOverride
}
checkstyle {
configFile file("${project.rootDir}/checkstyle-ruleset.xml")
}
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/checkstyle-ruleset.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = true
}
classpath = files()
}

View file

@ -1,17 +0,0 @@
apply plugin: 'pmd'
check.dependsOn('pmd')
task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/pmd-ruleset.xml")
ignoreFailures = false
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = true
html.enabled = true
}
}

View file

@ -11,8 +11,6 @@ dependencies {
group = GROUP
version = VERSION_NAME
apply from: rootProject.file("gradle/maven-push.gradle")
apply from: rootProject.file("gradle/checkstyle.gradle")
apply from: rootProject.file("gradle/pmd.gradle")
targetCompatibility = 1.8
sourceCompatibility = 1.8

View file

@ -39,8 +39,6 @@ dependencies {
}
apply from: rootProject.file("gradle/maven-push.gradle")
apply from: rootProject.file("gradle/checkstyle.gradle")
apply from: rootProject.file("gradle/pmd.gradle")
targetCompatibility = 1.8
sourceCompatibility = 1.8
repositories {

View file

@ -23,26 +23,19 @@ class MemoryPolicy internal constructor(
private val maxSizeNotDefault: Long
) {
val isDefaultWritePolicy: Boolean
get() = expireAfterWrite == DEFAULT_POLICY
val isDefaultWritePolicy: Boolean = expireAfterWrite == DEFAULT_POLICY
val isDefaultAccessPolicy: Boolean
get() = expireAfterAccess == DEFAULT_POLICY
val isDefaultAccessPolicy: Boolean = expireAfterAccess == DEFAULT_POLICY
val isDefaultMaxSize: Boolean
get() = maxSizeNotDefault == DEFAULT_POLICY
val isDefaultMaxSize: Boolean = maxSizeNotDefault == DEFAULT_POLICY
val maxSize: Long
get() = if (isDefaultMaxSize) 1 else maxSizeNotDefault
val maxSize: Long = if (isDefaultMaxSize) 1 else maxSizeNotDefault
val hasWritePolicy: Boolean
get() = expireAfterWrite != DEFAULT_POLICY
val hasWritePolicy: Boolean = expireAfterWrite != DEFAULT_POLICY
val hasAccessPolicy: Boolean
get() = expireAfterAccess != DEFAULT_POLICY
val hasAccessPolicy: Boolean = expireAfterAccess != DEFAULT_POLICY
val hasMaxSize: Boolean
get() = maxSize != DEFAULT_POLICY
val hasMaxSize: Boolean = maxSize != DEFAULT_POLICY
class MemoryPolicyBuilder {
private var expireAfterWrite = DEFAULT_POLICY

View file

@ -5,23 +5,20 @@ import java.util.concurrent.TimeUnit
internal object StoreDefaults {
/**
* Default Cache TTL, can be overridden
* Cache TTL (default is 24 hours), can be overridden
*
* @return memory persister ttl
* @return memory cache TTL
*/
val cacheTTL: Long
get() = TimeUnit.HOURS.toSeconds(24)
val cacheTTL: Long = TimeUnit.HOURS.toSeconds(24)
/**
* Default mem persister is 1, can be overridden otherwise
* Cache size (default is 100), can be overridden
*
* @return memory persister size
* @return memory cache size
*/
val cacheSize: Long
get() = 100
val cacheSize: Long = 100
val cacheTTLTimeUnit: TimeUnit
get() = TimeUnit.SECONDS
val cacheTTLTimeUnit: TimeUnit = TimeUnit.SECONDS
val memoryPolicy = MemoryPolicy.builder()
.setMemorySize(cacheSize)