Skip to content

Commit

Permalink
chore: Setup development environment (#27)
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
sdsantos authored Jun 29, 2020
1 parent 986d794 commit d27a8da
Show file tree
Hide file tree
Showing 56 changed files with 907 additions and 286 deletions.
102 changes: 92 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,127 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.diffplug.gradle.spotless'

apply from: 'jacoco.gradle'

android {
compileSdkVersion 29
compileSdkVersion 30
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "tech.relaycorp.gateway"
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
arg("room.incremental", "true")
}
}
}

buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/*'
}
lintOptions {
checkAllWarnings true
warningsAsErrors true
abortOnError true
lintConfig file('lint.xml')
}
sourceSets {
androidTest {
java.srcDirs += "src/sharedTest/java"
resources.srcDirs += "src/sharedTest/resources"
}
test {
java.srcDirs += "src/sharedTest/java"
resources.srcDirs += "src/sharedTest/resources"
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
// Java 8
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion"

// Android
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'com.google.android.material:material:1.2.0-beta01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'

// Dependency Injection
api 'com.google.dagger:dagger:2.28'
kapt 'com.google.dagger:dagger-compiler:2.28'

// Relaynet
implementation 'tech.relaycorp:relaynet:1.15.6'
implementation 'tech.relaycorp:relaynet-cogrpc:1.0.2'

// ORM
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"

// Testing
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion"
testImplementation 'org.mockito:mockito-inline:3.3.3'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'

// Instrumentation Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

androidTestImplementation('com.schibsted.spain:barista:3.5.0') {
exclude group: 'org.jetbrains.kotlin'
}
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.28'
}

spotless {
kotlin {
ktlint('0.37.1').userData(['disabled_rules': 'import-ordering'])
target '**/*.kt'
}
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.freeCompilerArgs += [
'-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi',
'-Xuse-experimental=kotlinx.coroutines.FlowPreview',
'-Xuse-experimental=kotlin.time.ExperimentalTime'
]
}
59 changes: 59 additions & 0 deletions app/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apply plugin: 'jacoco'

jacoco {
toolVersion '0.8.5'
}

task jacocoAndroidTestReport(type: JacocoReport) {

sourceDirectories.from = files(["$project.projectDir/src/main/java"])
classDirectories.from = files([
fileTree(
dir: project.buildDir,
includes: [
"intermediates/javac/debug/**",
"tmp/kotlin-classes/debug/**"
],
excludes: [
'android/**/*.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
// Dagger
'**/*Module.*',
'**/*Module*Factory.*',
'**/*Module$Companion.*',
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_Provide*Factory*.*',
'**/*_Factory.*',
// Epoxy
'**/*ViewModel_.*',
'**/EpoxyModelKotlinExtensionsKt.*',
]
)
])

executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec',
'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'
])

if (project.hasProperty('codeCoverageDataLocation')) {
executionData.from += fileTree(dir: codeCoverageDataLocation, includes: ['**/*.ec'])
}

reports {
html.enabled true
html.destination file("${buildDir}/reports/coverage")
xml.enabled true
xml.destination file("${buildDir}/reports/coverage.xml")
csv.enabled false
}

doLast {
println "Wrote HTML coverage report to ${reports.html.destination}/index.html"
}
}
17 changes: 17 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
<!-- We're using dependabot to keep dependencies up-to-date -->
<issue id="NewerVersionAvailable" severity="ignore"/>
<issue id="GradleDependency" severity="ignore"/>
<issue id="LockedOrientationActivity" severity="ignore"/>

<issue id="InvalidPackage">
<!-- Ignore errors about BC importing javax.naming because we don't use those modules -->
<ignore path="**/bcpkix-*.jar" />
<!-- Temporary until https://github.com/Kotlin/kotlinx.coroutines/issues/2004 is resolved. -->
<ignore path="**/kotlinx-coroutines-core-*.jar" />
</issue>
<issue id="TrustAllX509TrustManager">
<ignore path="org/bouncycastle/est/jcajce/*.class" />
</issue>
</lint>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "f4d34def0a467a21b391ecb53e2175d2",
"entities": [
{
"tableName": "Message",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f4d34def0a467a21b391ecb53e2175d2')"
]
}
}
15 changes: 15 additions & 0 deletions app/src/androidTest/java/tech/relaycorp/gateway/AppTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tech.relaycorp.gateway

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import tech.relaycorp.gateway.test.AppTestProvider.app

@RunWith(AndroidJUnit4::class)
class AppTest {
@Test
fun mode() {
assertEquals(App.Mode.Test, app.mode)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tech.relaycorp.gateway.test

import android.content.Context
import androidx.room.Room
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.test.TestCoroutineDispatcher
import tech.relaycorp.gateway.App
import tech.relaycorp.gateway.data.database.AppDatabase

object AppTestProvider {
private val context: Context
get() = InstrumentationRegistry.getInstrumentation().targetContext

val app
get() = context.applicationContext as App

val component
get() = app.component

val database
get() =
Room
.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
.setTransactionExecutor(testDispatcher.asExecutor())
.setQueryExecutor(testDispatcher.asExecutor())
.build()

private val testDispatcher by lazy { TestCoroutineDispatcher() }
}
13 changes: 9 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="tech.relaycorp.gateway">

<application
android:allowBackup="true"
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
android:theme="@style/Theme.Gateway"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".ui.main.MainActivity"
android:theme="@style/Theme.Gateway.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -18,4 +23,4 @@
</activity>
</application>

</manifest>
</manifest>
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d27a8da

Please sign in to comment.