From b515f6bb5427d1d1dd93008b547a7023468e634b Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 7 Feb 2020 11:21:18 +0100 Subject: [PATCH] Adding an Android Module Kotlin template --- .../cookiecutter.json | 6 ++ .../custom-fields.json | 57 +++++++++++++++++++ .../out/SampleModule/.gitignore | 1 + .../out/SampleModule/build.gradle | 36 ++++++++++++ .../out/SampleModule/consumer-rules.pro | 0 .../out/SampleModule/proguard-rules.pro | 21 +++++++ .../ExampleInstrumentedTest.kt | 24 ++++++++ .../SampleModule/src/main/AndroidManifest.xml | 2 + .../com.example.module/ExampleModuleClass.kt | 8 +++ .../com.example.module/ExampleUnitTest.kt | 17 ++++++ .../{{cookiecutter.module_name}}/.gitignore | 1 + .../{{cookiecutter.module_name}}/build.gradle | 36 ++++++++++++ .../consumer-rules.pro | 0 .../proguard-rules.pro | 21 +++++++ .../ExampleInstrumentedTest.kt | 24 ++++++++ .../src/main/AndroidManifest.xml | 2 + .../ExampleModuleClass.kt | 8 +++ .../ExampleUnitTest.kt | 17 ++++++ 18 files changed, 281 insertions(+) create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/cookiecutter.json create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/custom-fields.json create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/.gitignore create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/build.gradle create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/consumer-rules.pro create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/proguard-rules.pro create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/androidTest/java/com.example.module/ExampleInstrumentedTest.kt create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/AndroidManifest.xml create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/java/com.example.module/ExampleModuleClass.kt create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/test/java/com.example.module/ExampleUnitTest.kt create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/.gitignore create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/build.gradle create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/consumer-rules.pro create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/proguard-rules.pro create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/androidTest/java/{{cookiecutter.module_id}}/ExampleInstrumentedTest.kt create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/AndroidManifest.xml create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/java/{{cookiecutter.module_id}}/ExampleModuleClass.kt create mode 100644 backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/test/java/{{cookiecutter.module_id}}/ExampleUnitTest.kt diff --git a/backend/scaffolder/templates/android-kotlin-module-template/cookiecutter.json b/backend/scaffolder/templates/android-kotlin-module-template/cookiecutter.json new file mode 100644 index 0000000000..3e454acc28 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/cookiecutter.json @@ -0,0 +1,6 @@ +{ + "module_id": "com.example.module", + "module_name": "SampleModule", + "owner": "", + "description": "We promise to update this description /{{cookiecutter.owner}}" +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/custom-fields.json b/backend/scaffolder/templates/android-kotlin-module-template/custom-fields.json new file mode 100644 index 0000000000..1dc68ee741 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/custom-fields.json @@ -0,0 +1,57 @@ +{ + "schema": [ + { + "id": "module_name", + "title": "Module name", + "type": "text", + "description": "Module name used to generate Android Studio files and class names. CamelCase e.g. 'MyNewModule'", + "validators": [ + { + "type": "required" + }, + { + "type": "regex", + "match": "^[A-Z][A-Za-z]+$", + "message": "Module name must be CamelCase" + } + ] + }, + { + "id": "module_id", + "title": "Module ID", + "type": "text", + "description": "Module id used as package for the new module. FQDN e.g. 'com.example.module'", + "validators": [ + { + "type": "required" + }, + { + "type": "regex", + "match": "^[a-z][a-z.]+$", + "message": "Module ID must be a fully qualified domain name" + } + ] + }, + { + "id": "owner", + "title": "owner", + "type": "text", + "description": "The owner name used to identify the owner of this component", + "validators": [ + { + "type": "required" + }, + { + "type": "string-range", + "min": 4, + "max": 33 + }, + { + "type": "regex", + "match": "^[a-z][a-z0-9]+$", + "message": "Owner names must consist only of lowercase letters" + } + ] + } + ] +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/.gitignore b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/.gitignore @@ -0,0 +1 @@ +/build diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/build.gradle b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/build.gradle new file mode 100644 index 0000000000..468d82a835 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/consumer-rules.pro b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/proguard-rules.pro b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/androidTest/java/com.example.module/ExampleInstrumentedTest.kt b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/androidTest/java/com.example.module/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..3e5ff59ba7 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/androidTest/java/com.example.module/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.module + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.mylibrary.test", appContext.packageName) + } +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/AndroidManifest.xml b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..6b99aadb41 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/java/com.example.module/ExampleModuleClass.kt b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/java/com.example.module/ExampleModuleClass.kt new file mode 100644 index 0000000000..a37d158a99 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/main/java/com.example.module/ExampleModuleClass.kt @@ -0,0 +1,8 @@ +package com.example.module + +/** + * This is just an entry point for your new module + */ +class ExampleModuleClass { + +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/test/java/com.example.module/ExampleUnitTest.kt b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/test/java/com.example.module/ExampleUnitTest.kt new file mode 100644 index 0000000000..c4a02135f3 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/out/SampleModule/src/test/java/com.example.module/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.module + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/.gitignore b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/.gitignore @@ -0,0 +1 @@ +/build diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/build.gradle b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/build.gradle new file mode 100644 index 0000000000..468d82a835 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + + defaultConfig { + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/consumer-rules.pro b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/proguard-rules.pro b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/androidTest/java/{{cookiecutter.module_id}}/ExampleInstrumentedTest.kt b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/androidTest/java/{{cookiecutter.module_id}}/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..8c900adf7b --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/androidTest/java/{{cookiecutter.module_id}}/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package {{cookiecutter.module_id}} + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.mylibrary.test", appContext.packageName) + } +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/AndroidManifest.xml b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..98ec238da0 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/java/{{cookiecutter.module_id}}/ExampleModuleClass.kt b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/java/{{cookiecutter.module_id}}/ExampleModuleClass.kt new file mode 100644 index 0000000000..17f98324b0 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/main/java/{{cookiecutter.module_id}}/ExampleModuleClass.kt @@ -0,0 +1,8 @@ +package {{cookiecutter.module_id}} + +/** + * This is just an entry point for your new module + */ +class ExampleModuleClass { + +} diff --git a/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/test/java/{{cookiecutter.module_id}}/ExampleUnitTest.kt b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/test/java/{{cookiecutter.module_id}}/ExampleUnitTest.kt new file mode 100644 index 0000000000..d245652f81 --- /dev/null +++ b/backend/scaffolder/templates/android-kotlin-module-template/{{cookiecutter.module_name}}/src/test/java/{{cookiecutter.module_id}}/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package {{cookiecutter.module_id}} + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +}