├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ └── layout
│ │ │ │ └── example_activity.xml
│ │ ├── java
│ │ │ └── be
│ │ │ │ └── vergauwen
│ │ │ │ └── simon
│ │ │ │ └── androidqualitycontrol
│ │ │ │ ├── core
│ │ │ │ ├── rx
│ │ │ │ │ ├── Transformers.java
│ │ │ │ │ └── RxUtil.java
│ │ │ │ ├── di
│ │ │ │ │ ├── ActivityScope.java
│ │ │ │ │ ├── ApplicationScope.java
│ │ │ │ │ ├── ApplicationComponent.java
│ │ │ │ │ ├── ApplicationModule.java
│ │ │ │ │ └── ServiceModule.java
│ │ │ │ ├── service
│ │ │ │ │ └── GithubAPI.java
│ │ │ │ └── model
│ │ │ │ │ └── GitHubRepo.java
│ │ │ │ ├── ui
│ │ │ │ ├── ExampleComponent.java
│ │ │ │ ├── ExampleContract.java
│ │ │ │ ├── ExampleActivity.java
│ │ │ │ └── ExamplePresenter.java
│ │ │ │ └── ExampleApp.java
│ │ └── AndroidManifest.xml
│ ├── free
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ ├── paid
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ ├── test
│ │ └── kotlin
│ │ │ └── be
│ │ │ └── vergauwen
│ │ │ └── simon
│ │ │ └── androidqualitycontrol
│ │ │ ├── ui
│ │ │ ├── MockExampleView.kt
│ │ │ ├── ExamplePresenterTest.kt
│ │ │ └── ExampleActivityTest.kt
│ │ │ ├── core
│ │ │ ├── di
│ │ │ │ ├── TestServiceModule.kt
│ │ │ │ └── TestApplicationModule.kt
│ │ │ ├── rx
│ │ │ │ └── MockRxUtil.kt
│ │ │ └── service
│ │ │ │ └── MockGithubAPI.kt
│ │ │ └── TestExampleApp.kt
│ ├── androidTest
│ │ └── java
│ │ │ └── be
│ │ │ └── vergauwen
│ │ │ └── simon
│ │ │ └── androidqualitycontrol
│ │ │ └── ApplicationTest.java
│ ├── testPaid
│ │ └── kotlin
│ │ │ └── be
│ │ │ └── vergauwen
│ │ │ └── simon
│ │ │ └── androidqualitycontrol
│ │ │ └── ui
│ │ │ └── ExampleActivityTestFull.kt
│ └── testFree
│ │ └── kotlin
│ │ └── be.vergauwen.simon.androidqualitycontrol
│ │ └── ui
│ │ └── ExampleActivityTestDemo.kt
├── proguard-rules.pro
└── build.gradle
├── himura-kt
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ └── be
│ │ └── vergauwen
│ │ └── simon
│ │ └── himurakotlin
│ │ ├── MVPContract.kt
│ │ ├── MVPPresenter.kt
│ │ ├── MVPActivity.kt
│ │ └── MVPDaggerActivity.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── pmd.gradle
├── config
│ ├── findbugs
│ │ └── exclude.xml
│ ├── pmd
│ │ └── pmd.xml
│ └── checkstyle
│ │ └── checkstyle.xml
├── checkstyle.gradle
└── findbugs.gradle
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/himura-kt/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ":himura-kt"
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/himura-kt/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Himura Kotlin
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidGradleJacoco
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nomisRev/AndroidQualityControl/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/free/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Free version only.
4 |
--------------------------------------------------------------------------------
/app/src/paid/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Paid version only.
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | .idea/
6 | .DS_Store
7 | /build
8 | /captures
9 | *.apk
10 | *.ap_
11 | *.dex
12 | *.class
13 | bin/
14 | gen/
15 | out/
16 | .gradle/
17 | build/
18 | local.properties
19 | proguard/
20 | *.log
21 | .navigation/
22 | captures/
23 | *.jks
24 | gen-external-apklibs
25 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/rx/Transformers.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.rx;
2 |
3 | import rx.Observable;
4 |
5 | public interface Transformers {
6 | Observable.Transformer applyComputationSchedulers();
7 | Observable.Transformer applyIOSchedulers();
8 | }
--------------------------------------------------------------------------------
/himura-kt/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/di/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 | import javax.inject.Scope;
6 |
7 | @Scope
8 | @Retention(RetentionPolicy.RUNTIME)
9 | public @interface ActivityScope {}
10 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/di/ApplicationScope.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 | import javax.inject.Scope;
6 |
7 | @Scope
8 | @Retention(RetentionPolicy.RUNTIME)
9 | public @interface ApplicationScope {}
10 |
--------------------------------------------------------------------------------
/himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPContract.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.himurakotlin
2 |
3 | interface MVPContract {
4 | interface View
5 |
6 | interface Presenter {
7 | fun getView(): V?
8 | fun attachView(view: V)
9 | fun detachView()
10 | }
11 |
12 | interface Component> {
13 | fun presenter(): P
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/ui/MockExampleView.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui
2 |
3 | class MockExampleView() : ExampleContract.View {
4 | var printedRepo = false
5 | var errorShown = false
6 |
7 | override fun printRepo(repoName: String) {
8 | printedRepo = true
9 | }
10 |
11 | override fun showError() {
12 | errorShown = true
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/service/GithubAPI.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.service;
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.model.GitHubRepo;
4 | import java.util.List;
5 | import retrofit2.http.GET;
6 | import rx.Observable;
7 |
8 | public interface GithubAPI {
9 | @GET("/users/google/repos")
10 | Observable> getRepos();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/be/vergauwen/simon/androidqualitycontrol/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/ui/ExampleComponent.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui;
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.di.ActivityScope;
4 | import be.vergauwen.simon.androidqualitycontrol.core.di.ApplicationComponent;
5 | import dagger.Component;
6 |
7 | @ActivityScope
8 | @Component(dependencies = ApplicationComponent.class)
9 | public interface ExampleComponent extends ExampleContract.Component{}
10 |
--------------------------------------------------------------------------------
/himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPPresenter.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.himurakotlin
2 |
3 | import java.lang.ref.WeakReference
4 |
5 |
6 | abstract class MVPPresenter : MVPContract.Presenter {
7 | private var viewRef: WeakReference? = null
8 |
9 | override fun getView(): V? = if (viewRef == null) null else viewRef?.get()
10 |
11 | override fun attachView(view: V) {
12 | viewRef = WeakReference(view)
13 | }
14 |
15 | override fun detachView() {
16 | viewRef?.clear()
17 | viewRef = null
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/core/di/TestServiceModule.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.service.GithubAPI
4 | import be.vergauwen.simon.androidqualitycontrol.core.service.MockGithubAPI
5 | import dagger.Module
6 | import dagger.Provides
7 | import retrofit2.Retrofit
8 |
9 | @Module
10 | class TestServiceModule : ServiceModule() {
11 |
12 | @ApplicationScope
13 | @Provides
14 | override fun provideGithubAPI(retrofit: Retrofit): GithubAPI {
15 | return MockGithubAPI()
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/di/ApplicationComponent.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di;
2 |
3 | import android.content.Context;
4 | import be.vergauwen.simon.androidqualitycontrol.core.rx.Transformers;
5 | import be.vergauwen.simon.androidqualitycontrol.core.service.GithubAPI;
6 | import dagger.Component;
7 |
8 | @ApplicationScope
9 | @Component(modules = {ApplicationModule.class,ServiceModule.class})
10 | public interface ApplicationComponent {
11 | Context getApplicationContext();
12 | Transformers getTransfomers();
13 | GithubAPI getGithubAPI();
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/ui/ExampleContract.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui;
2 |
3 | import be.vergauwen.simon.himurakotlin.MVPContract;
4 |
5 | public interface ExampleContract {
6 | interface View extends MVPContract.View {
7 | void printRepo(String repoName);
8 | void showError();
9 | }
10 |
11 | interface Presenter extends MVPContract.Presenter {
12 | void getRepos();
13 | }
14 |
15 | interface Component> extends MVPContract.Component{}
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/example_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/TestExampleApp.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.di.ApplicationComponent
4 | import be.vergauwen.simon.androidqualitycontrol.core.di.DaggerApplicationComponent
5 | import be.vergauwen.simon.androidqualitycontrol.core.di.TestApplicationModule
6 | import be.vergauwen.simon.androidqualitycontrol.core.di.TestServiceModule
7 |
8 | class TestExampleApp : ExampleApp() {
9 | override fun createComponent(): ApplicationComponent = DaggerApplicationComponent.builder().applicationModule(
10 | TestApplicationModule(this)).serviceModule(TestServiceModule()).build()
11 | }
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/core/rx/MockRxUtil.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.rx
2 |
3 | import rx.Observable
4 | import rx.schedulers.Schedulers
5 |
6 | class MockRxUtil : Transformers {
7 | override fun applyComputationSchedulers(): Observable.Transformer =
8 | Observable.Transformer {
9 | it.subscribeOn(Schedulers.immediate())
10 | .observeOn(Schedulers.immediate())
11 | }
12 |
13 | override fun applyIOSchedulers(): Observable.Transformer =
14 | Observable.Transformer {
15 | it.subscribeOn(Schedulers.immediate())
16 | .observeOn(Schedulers.immediate())
17 | }
18 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/core/service/MockGithubAPI.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.service
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.model.GitHubRepo
4 | import rx.Observable
5 |
6 | class MockGithubAPI() : GithubAPI {
7 |
8 | val repos : List
9 | var throwError = false
10 |
11 | init{
12 | val githubRepo = GitHubRepo()
13 | githubRepo.name = "test"
14 | githubRepo.url = "www.test.com"
15 | githubRepo.description = "test_desc"
16 | repos = listOf(githubRepo)
17 | }
18 |
19 | override fun getRepos(): Observable> {
20 | return if (throwError) Observable.error(Exception("exception")) else Observable.just(repos)
21 | }
22 | }
--------------------------------------------------------------------------------
/himura-kt/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/simonvergauwen/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/gradle/pmd.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'pmd'
2 |
3 | check.dependsOn 'pmd'
4 |
5 | task pmd(type: Pmd) {
6 |
7 | description "Generate PMD reports for this build"
8 |
9 | ignoreFailures true
10 |
11 | ruleSets = [
12 | "java-basic",
13 | "java-braces",
14 | "java-naming",
15 | "java-android",
16 | "java-codesize",
17 | "java-design",
18 | "java-finalizers",
19 | "java-junit",
20 | "java-optimizations",
21 | "java-strictexception",
22 | "java-strings",
23 | "java-unusedcode"
24 | ]
25 |
26 | source 'src'
27 | include '**/*.java'
28 | exclude '**/gen/**'
29 |
30 | reports {
31 | xml.enabled = true
32 | html.enabled = true
33 | }
34 | }
--------------------------------------------------------------------------------
/himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPActivity.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.himurakotlin
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 |
6 | abstract class MVPActivity> : AppCompatActivity(), MVPContract.View {
7 |
8 | protected val presenter: P by lazy { createPresenter() }
9 | protected abstract fun createPresenter(): P
10 |
11 | //This happens under the hood in java.
12 | @Suppress("UNCHECKED_CAST")
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | presenter.attachView(this as V)
16 | }
17 |
18 | override fun onDestroy() {
19 | super.onDestroy()
20 | presenter.detachView()
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/core/di/TestApplicationModule.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import be.vergauwen.simon.androidqualitycontrol.core.rx.MockRxUtil
6 | import be.vergauwen.simon.androidqualitycontrol.core.rx.Transformers
7 | import dagger.Module
8 | import dagger.Provides
9 |
10 | @Module
11 | class TestApplicationModule(private val application: Application) : ApplicationModule(application) {
12 |
13 | @ApplicationScope
14 | @Provides
15 | override fun provideApplicationContext(): Context {
16 | return application
17 | }
18 |
19 | @ApplicationScope
20 | @Provides
21 | override fun provideTransformers(): Transformers {
22 | return MockRxUtil()
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/himura-kt/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 7
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | sourceSets {
21 | main.java.srcDirs += 'src/main/kotlin'
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | provided 'com.android.support:appcompat-v7:23.3.0'
28 | provided "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
29 | provided "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
30 | }
31 |
--------------------------------------------------------------------------------
/himura-kt/src/main/kotlin/be/vergauwen/simon/himurakotlin/MVPDaggerActivity.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.himurakotlin
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 |
6 | abstract class MVPDaggerActivity,
7 | C : MVPContract.Component> : AppCompatActivity(), MVPContract.View {
8 |
9 | protected val presenter: P by lazy { component.presenter() }
10 | protected val component: C by lazy { createComponent() }
11 |
12 | protected abstract fun createComponent(): C
13 |
14 | //This happens under the hood in java.
15 | @Suppress("UNCHECKED_CAST")
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | presenter.attachView(this as V)
19 | }
20 |
21 | override fun onDestroy() {
22 | super.onDestroy()
23 | presenter.detachView()
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/di/ApplicationModule.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import be.vergauwen.simon.androidqualitycontrol.core.rx.RxUtil;
6 | import be.vergauwen.simon.androidqualitycontrol.core.rx.Transformers;
7 | import dagger.Module;
8 | import dagger.Provides;
9 |
10 | @Module
11 | public class ApplicationModule {
12 |
13 | private Application application;
14 |
15 | public ApplicationModule(Application application){
16 | this.application = application;
17 | }
18 |
19 | @ApplicationScope
20 | @Provides
21 | Context provideApplicationContext(){
22 | return application;
23 | }
24 |
25 | @ApplicationScope
26 | @Provides
27 | Transformers provideTransformers(){
28 | return new RxUtil();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/model/GitHubRepo.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | public class GitHubRepo {
6 | @SerializedName("name")
7 | String name;
8 |
9 | @SerializedName("html_url")
10 | String url;
11 |
12 | @SerializedName("description")
13 | String description;
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public String getUrl() {
20 | return url;
21 | }
22 |
23 | public String getDescription() {
24 | return description;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | public void setUrl(String url) {
32 | this.url = url;
33 | }
34 |
35 | public void setDescription(String description) {
36 | this.description = description;
37 | }
38 | }
--------------------------------------------------------------------------------
/gradle/config/findbugs/exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/di/ServiceModule.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.di;
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.BuildConfig;
4 | import be.vergauwen.simon.androidqualitycontrol.core.service.GithubAPI;
5 | import dagger.Module;
6 | import dagger.Provides;
7 | import retrofit2.Retrofit;
8 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
9 | import retrofit2.converter.gson.GsonConverterFactory;
10 |
11 | @Module
12 | public class ServiceModule {
13 |
14 | @ApplicationScope
15 | @Provides
16 | Retrofit provideRestAdapter(){
17 | return new Retrofit.Builder().baseUrl(BuildConfig.URI).addConverterFactory(
18 | GsonConverterFactory.create()).addCallAdapterFactory(
19 | RxJavaCallAdapterFactory.create()).build();
20 | }
21 |
22 | @ApplicationScope
23 | @Provides
24 | GithubAPI provideGithubAPI(Retrofit retrofit){
25 | return retrofit.create(GithubAPI.class);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/gradle/checkstyle.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'checkstyle'
2 |
3 | //adds script to 'check' task
4 | check.dependsOn 'checkstyle'
5 |
6 | //Create new gradle task checkstyle
7 | task checkstyle(type: Checkstyle) {
8 |
9 | // group 'Verification tasks' - Already added to app:check by check.dependsOn 'checkstyle'
10 | description "Generate Checkstyle reports for this build" //Add description to task
11 |
12 | ignoreFailures true //if false build will fail when checkstyle warning is detected!! (Ultra strict)
13 |
14 | //Config file for checkstyle
15 | configFile file("${rootProject.projectDir}/gradle/config/checkstyle/checkstyle.xml")
16 |
17 | //Add source that should be checked by checkstyle
18 | source 'src'
19 | include '**/*.java'
20 | include '**/*.kt'
21 | exclude '**/gen/**', '**/test/**'
22 |
23 | //reports checkstyle should output
24 | reports {
25 | xml.enabled = true
26 | html.enabled = true
27 | }
28 |
29 | classpath = files(file("${project.rootDir}/app/build/intermediates/classes"))
30 | }
--------------------------------------------------------------------------------
/app/src/testPaid/kotlin/be/vergauwen/simon/androidqualitycontrol/ui/ExampleActivityTestFull.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui
2 |
3 | import android.widget.TextView
4 | import be.vergauwen.simon.androidqualitycontrol.BuildConfig
5 | import be.vergauwen.simon.androidqualitycontrol.R
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 | import org.robolectric.Robolectric
9 | import org.robolectric.RobolectricGradleTestRunner
10 | import org.robolectric.annotation.Config
11 | import kotlin.test.assertEquals
12 |
13 | @RunWith(RobolectricGradleTestRunner::class)
14 | @Config(constants = BuildConfig::class, sdk = intArrayOf(21))
15 | class ExampleActivityTestFull {
16 | @Test
17 | fun testString() {
18 | val activity = Robolectric.buildActivity(
19 | ExampleActivity::class.java).create().start().resume().visible().get()
20 |
21 | val string = activity.getString(R.string.hello_world)
22 | assertEquals("Paid version only.",string)
23 | assertEquals(string,(activity.findViewById(R.id.hello_world) as TextView).text)
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/testFree/kotlin/be.vergauwen.simon.androidqualitycontrol/ui/ExampleActivityTestDemo.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui
2 |
3 | import android.widget.TextView
4 | import be.vergauwen.simon.androidqualitycontrol.BuildConfig
5 | import be.vergauwen.simon.androidqualitycontrol.R
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 | import org.robolectric.Robolectric
9 | import org.robolectric.RobolectricGradleTestRunner
10 | import org.robolectric.annotation.Config
11 | import kotlin.test.assertEquals
12 |
13 | @RunWith(RobolectricGradleTestRunner::class)
14 | @Config(constants = BuildConfig::class, sdk = intArrayOf(21))
15 | class ExampleActivityTestDemo {
16 |
17 | @Test
18 | fun testString() {
19 | val activity = Robolectric.buildActivity(
20 | ExampleActivity::class.java).create().start().resume().visible().get()
21 |
22 | val string = activity.getString(R.string.hello_world)
23 | assertEquals(string, "Free version only.")
24 | assertEquals(string,(activity.findViewById(R.id.hello_world) as TextView).text)
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/ExampleApp.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol;
2 |
3 | import android.app.Application;
4 | import be.vergauwen.simon.androidqualitycontrol.core.di.ApplicationComponent;
5 | import be.vergauwen.simon.androidqualitycontrol.core.di.ApplicationModule;
6 | import be.vergauwen.simon.androidqualitycontrol.core.di.DaggerApplicationComponent;
7 | import be.vergauwen.simon.androidqualitycontrol.core.di.ServiceModule;
8 |
9 | public class ExampleApp extends Application {
10 | private ApplicationComponent component;
11 |
12 | public ApplicationComponent getComponent() {
13 | return component;
14 | }
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | component = createComponent();
20 | }
21 |
22 | ApplicationComponent createComponent() {
23 | return DaggerApplicationComponent.builder()
24 | .applicationModule(new ApplicationModule(this))
25 | .serviceModule(new ServiceModule())
26 | .build();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/core/rx/RxUtil.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.core.rx;
2 |
3 | import rx.Observable;
4 | import rx.android.schedulers.AndroidSchedulers;
5 | import rx.schedulers.Schedulers;
6 |
7 | public class RxUtil implements Transformers {
8 | @Override
9 | public Observable.Transformer applyComputationSchedulers() {
10 | return new Observable.Transformer() {
11 | @Override
12 | public Observable call(Observable tObservable) {
13 | return tObservable.observeOn(AndroidSchedulers.mainThread())
14 | .subscribeOn(Schedulers.computation());
15 | }
16 | };
17 | }
18 |
19 | @Override
20 | public Observable.Transformer applyIOSchedulers() {
21 | return new Observable.Transformer() {
22 | @Override
23 | public Observable call(Observable tObservable) {
24 | return tObservable.observeOn(AndroidSchedulers.mainThread())
25 | .subscribeOn(Schedulers.io());
26 | }
27 | };
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/ui/ExamplePresenterTest.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.rx.MockRxUtil
4 | import be.vergauwen.simon.androidqualitycontrol.core.service.MockGithubAPI
5 | import org.junit.Assert.*
6 | import org.junit.Before
7 | import org.junit.Test
8 |
9 | class ExamplePresenterTest {
10 |
11 | lateinit var presenter: ExamplePresenter
12 | lateinit var view: MockExampleView
13 | lateinit var githubAPI : MockGithubAPI
14 |
15 | @Before
16 | fun setUp() {
17 | githubAPI = MockGithubAPI()
18 | presenter = ExamplePresenter(githubAPI, MockRxUtil())
19 | view = MockExampleView()
20 | }
21 |
22 | @Test
23 | fun preConditions() {
24 | assertNotNull(presenter)
25 | assertFalse(view.printedRepo)
26 | }
27 |
28 | @Test
29 | fun testAssertViewAttached() {
30 | presenter.attachView(view)
31 | assertNotNull(presenter.getView())
32 | }
33 |
34 | @Test
35 | fun testRepoPrinted() {
36 | presenter.attachView(view)
37 | assertFalse(view.printedRepo)
38 | presenter.getRepos()
39 | assertTrue(view.printedRepo)
40 | }
41 |
42 | @Test
43 | fun testRetrofitError() {
44 | presenter.attachView(view)
45 | assertFalse(view.errorShown)
46 | githubAPI.throwError = true
47 | presenter.getRepos()
48 | assertTrue(view.errorShown)
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/ui/ExampleActivity.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.widget.TextView;
6 | import be.vergauwen.simon.androidqualitycontrol.ExampleApp;
7 | import be.vergauwen.simon.androidqualitycontrol.R;
8 | import be.vergauwen.simon.himurakotlin.MVPDaggerActivity;
9 | import org.jetbrains.annotations.NotNull;
10 | import org.jetbrains.annotations.Nullable;
11 |
12 | public class ExampleActivity
13 | extends MVPDaggerActivity
14 | implements ExampleContract.View {
15 |
16 | private TextView githubRepo;
17 |
18 | @NotNull
19 | @Override
20 | protected ExampleComponent createComponent() {
21 | return DaggerExampleComponent.builder()
22 | .applicationComponent(((ExampleApp) getApplication()).getComponent())
23 | .build();
24 | }
25 |
26 | @Override
27 | protected void onCreate(@Nullable Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.example_activity);
30 | githubRepo = (TextView) findViewById(R.id.github_repos);
31 | githubRepo.setText("Github repo = \n");
32 | }
33 |
34 | @Override
35 | public void printRepo(String repoName) {
36 | Log.e("ExampleActivity", repoName);
37 | githubRepo.setText(githubRepo.getText().toString() + repoName + "\n");
38 | }
39 |
40 | @Override
41 | public void showError() {
42 | githubRepo.setText("error");
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/gradle/findbugs.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'findbugs'
2 |
3 | //adds script to 'check' task
4 | check.dependsOn 'findbugs'
5 |
6 | //Create new gradle task findbugs
7 | task findbugs(type: FindBugs) {
8 |
9 | // group 'Verification tasks' - Already added to app:check by check.dependsOn 'findbugs'
10 | description 'Generate FindBugs reports for this build' //Add description to task
11 |
12 | //if false build will fail when checkstyle warning is detected!! (Ultra strict)
13 | // same as lintOptions { abortOnError false }
14 | ignoreFailures true
15 |
16 | //Higher levels increase precision and find more bugs at the expense of running time and memory consumption.
17 | effort = 'max'
18 | //The priority threshold for reporting bugs. If set to {@code low}, all bugs are reported.
19 | reportLevel = 'low'
20 |
21 | //Define path to classes
22 | classes = fileTree("${project.rootDir}/app/build/intermediates/classes")
23 |
24 | //Add source that should be checked by findbugs
25 | source 'src'
26 | include '**/*.java'
27 | exclude '**/gen/**'
28 |
29 | //Define exclude config file
30 | excludeFilter = file("${rootProject.projectDir}/gradle/config/findbugs/exclude.xml")
31 |
32 |
33 | //IMPORTANT: FINDBUGS CAN ONLY GENERATE 1 REPORT. XML OR HTML!! AND PATH MUST BE DEFINED!!
34 | reports {
35 | xml.enabled = false
36 | html.enabled = true
37 | xml.destination = "$project.buildDir/reports/findbugs/findbugs-output.xml"
38 | html.destination = "$project.buildDir/reports/findbugs/findbugs-output.html"
39 | }
40 |
41 | classpath = files()
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/app/src/test/kotlin/be/vergauwen/simon/androidqualitycontrol/ui/ExampleActivityTest.kt:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui
2 |
3 | import android.widget.TextView
4 | import be.vergauwen.simon.androidqualitycontrol.BuildConfig
5 | import be.vergauwen.simon.androidqualitycontrol.R
6 | import org.junit.Before
7 | import org.junit.Test
8 | import org.junit.runner.RunWith
9 | import org.robolectric.Robolectric
10 | import org.robolectric.RobolectricGradleTestRunner
11 | import org.robolectric.annotation.Config
12 | import kotlin.test.assertNotNull
13 | import kotlin.test.assertTrue
14 |
15 | @RunWith(RobolectricGradleTestRunner::class)
16 | @Config(constants = BuildConfig::class, sdk = intArrayOf(21))
17 | class ExampleActivityTest {
18 |
19 | @Before
20 | fun setUp() {
21 | }
22 |
23 | @Test
24 | fun preConditions() {
25 | val activity = Robolectric.buildActivity(ExampleActivity::class.java).get()
26 | assertNotNull(activity)
27 | }
28 |
29 | @Test
30 | fun testTextView() {
31 | val activity = Robolectric.buildActivity(
32 | ExampleActivity::class.java).create().start().resume().visible().get()
33 | val githubRepos : TextView = activity.findViewById(R.id.github_repos) as TextView
34 | assertNotNull(githubRepos)
35 | }
36 |
37 | @Test
38 | fun testPrintRepos() {
39 | val activity = Robolectric.buildActivity(
40 | ExampleActivity::class.java).create().start().resume().visible().get()
41 | activity.printRepo("text")
42 | val githubRepos : TextView = activity.findViewById(R.id.github_repos) as TextView
43 | assertTrue(githubRepos.text.toString().contains("text"))
44 | }
45 |
46 | @Test
47 | fun testShowError() {
48 | val activity = Robolectric.buildActivity(
49 | ExampleActivity::class.java).create().start().resume().visible().get()
50 | activity.showError()
51 | val githubRepos : TextView = activity.findViewById(R.id.github_repos) as TextView
52 | assertTrue(githubRepos.text.toString().contains("error"))
53 | }
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/be/vergauwen/simon/androidqualitycontrol/ui/ExamplePresenter.java:
--------------------------------------------------------------------------------
1 | package be.vergauwen.simon.androidqualitycontrol.ui;
2 |
3 | import be.vergauwen.simon.androidqualitycontrol.core.model.GitHubRepo;
4 | import be.vergauwen.simon.androidqualitycontrol.core.rx.Transformers;
5 | import be.vergauwen.simon.androidqualitycontrol.core.service.GithubAPI;
6 | import be.vergauwen.simon.himurakotlin.MVPPresenter;
7 | import java.util.List;
8 | import javax.inject.Inject;
9 | import rx.Observable;
10 | import rx.Subscriber;
11 | import rx.functions.Func1;
12 |
13 | public class ExamplePresenter extends MVPPresenter
14 | implements ExampleContract.Presenter {
15 |
16 | private GithubAPI githubAPI;
17 | private Transformers transformers;
18 |
19 | @Inject
20 | public ExamplePresenter(GithubAPI githubAPI, Transformers transformers) {
21 | this.githubAPI = githubAPI;
22 | this.transformers = transformers;
23 | }
24 |
25 | @Override
26 | public void getRepos() {
27 |
28 | githubAPI.getRepos()
29 | .flatMap(new Func1, Observable>() {
30 | @Override
31 | public Observable call(List gitHubRepos) {
32 | return Observable.from(gitHubRepos);
33 | }
34 | })
35 | .compose(transformers.applyIOSchedulers())
36 | .filter(new Func1() {
37 | @Override
38 | public Boolean call(GitHubRepo gitHubRepo) {
39 | return gitHubRepo != null;
40 | }
41 | })
42 | .subscribe(new Subscriber() {
43 | @Override
44 | public void onCompleted() {}
45 |
46 | @Override
47 | public void onError(Throwable e) {
48 | getView().showError();
49 | }
50 |
51 | @Override
52 | public void onNext(GitHubRepo gitHubRepo) {
53 | getView().printRepo(gitHubRepo.getName());
54 | }
55 | });
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | //script plugins
6 | apply from: rootProject.file('gradle/checkstyle.gradle')
7 | apply from: rootProject.file('gradle/pmd.gradle')
8 | apply from: rootProject.file('gradle/findbugs.gradle')
9 |
10 | android {
11 | compileSdkVersion 23
12 | buildToolsVersion "23.0.2"
13 |
14 | defaultConfig {
15 | applicationId "be.vergauwen.simon.be.vergauwen.simon.androidqualitycontrol"
16 | minSdkVersion 9
17 | targetSdkVersion 23
18 | versionCode 1
19 | versionName "1.0"
20 |
21 | buildConfigField "String", "URI", "\"https://api.github.com\""
22 | }
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | testCoverageEnabled true
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | }
29 | debug {
30 | debuggable true
31 | testCoverageEnabled true
32 | }
33 | }
34 | productFlavors{
35 | free{
36 | applicationIdSuffix ".free"
37 | versionName "1.0-free"
38 |
39 | }
40 | paid{
41 | applicationIdSuffix ".paid"
42 | versionName "1.0-paid"
43 | }
44 | }
45 |
46 | lintOptions { abortOnError false }
47 |
48 | sourceSets {
49 | main.java.srcDirs += 'src/main/kotlin'
50 | test.java.srcDirs += 'src/test/kotlin'
51 | free.java.srcDirs += 'src/free/kotlin'
52 | paid.java.srcDirs += 'src/paid/kotlin'
53 | testPaid.java.srcDirs += 'src/testPaid/kotlin'
54 | testFree.java.srcDirs += 'src/testFree/kotlin'
55 | }
56 | }
57 |
58 | kapt { generateStubs = true }
59 |
60 | dependencies {
61 | compile fileTree(dir: 'libs', include: ['*.jar'])
62 | compile project(':himura-kt')
63 |
64 | testCompile('junit:junit:4.12',"org.robolectric:robolectric:3.1-SNAPSHOT",
65 | "org.jetbrains.kotlin:kotlin-test:$kotlin_version")
66 |
67 | compile 'com.android.support:appcompat-v7:23.3.0'
68 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
69 |
70 | compile 'com.google.dagger:dagger:2.0'
71 | kapt 'com.google.dagger:dagger-compiler:2.0'
72 | compile 'javax.annotation:jsr250-api:1.0'
73 |
74 | //Retrofit
75 | compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
76 | compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
77 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
78 | compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
79 |
80 | //Rx dependencies
81 | compile 'io.reactivex:rxandroid:1.1.0'
82 | compile 'io.reactivex:rxjava:1.1.3'
83 | }
84 |
--------------------------------------------------------------------------------
/gradle/config/pmd/pmd.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/gradle/config/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Quality Control
2 |
3 | To increase and track the quality of your code there are serveral tools available. Aside from continuous integration (CI) tools like Jenkins and test coverage with Jacoco shown in Android Jacoco Gradle, there are some static code analysis tools out there like PMD, FindBugs and Checkstyle
4 |
5 | ##### Static code analysis
6 | > Static program analysis is the analysis of computer software that is performed without actually executing programs (analysis performed on executing programs is known as dynamic analysis). In most cases the analysis is performed on some version of the source code, and in the other cases, some form of the object code.
7 |
8 | In other words, it is a tool that is going to analyse our code and point out bugs, mistakes, pitfalls. **This is a tool and so it doens't work miracles!**
9 |
10 | You can expect it to point out unused code, redudant code, unchecked potetional NPE's etc
11 |
12 | ## PMD
13 | * PMD is a source code analyser. That means it analyses your source code to find missing curly braces, redundant null check, long parameter list, unnecessary constructor, missing break in switch, etc. What it should report is configureable, more about this below.
14 | * PMD includes CPD (copy-paste-detector) which detects duplicated code.
15 |
16 | * Setting up PMD is relatively easy. The most important step here is to decide what you want PMD to check, and depending on these decisions you should setup your configuration.
17 | * The documentation can be rather tedious, and unhelpfull to setup the PMD configuration in gradle. This is a list of the possible Ruleset you can specify that PMD should analyse, the files linked here hold some documentation of what they do. More information can be found here PMD Rules. **Don't forget that in Gradle, the rules must be prefixed with the language. So in our case the ruleset resides in the java folde. So prefix with `java-`**
18 |
19 | * Combining these sources you should be able to figure out what configuration suits your project, and your setup might look something like this.
20 |
21 | ```
22 | apply plugin: 'pmd'
23 |
24 | check.dependsOn 'pmd'
25 |
26 | task pmd(type: Pmd) {
27 |
28 | description "Generate PMD reports for this build"
29 |
30 | ignoreFailures true // Ignores failing build on warning. If not set build will fail on warning.
31 |
32 | ruleSets = [
33 | "java-basic",
34 | "java-braces",
35 | "java-naming",
36 | "java-android",
37 | "java-codesize",
38 | "java-design",
39 | "java-finalizers",
40 | "java-junit",
41 | "java-optimizations",
42 | "java-strictexception",
43 | "java-strings",
44 | "java-unusedcode"
45 | ]
46 |
47 | source 'src' // Specify the source code. The script should be applied to
48 | include '**/*.java' // the module build.gradle so the 'src' folder resides at the same level
49 | exclude '**/gen/**' // include / exclude folders and files.
50 |
51 | reports {
52 | xml.enabled = true
53 | html.enabled = true
54 | }
55 | }
56 | ```
57 |
58 |
59 | ## FindBugs
60 | * FindBugs is a bytecode analyser.FindBugs will thus analyse the compiled `.class` files.
61 | * FindBugs will search for common pitfalls in the compiled class files like infinite loops, reference comparison of Boolean values, equals() method fails on subtypes, clone method may return null, (32bit) int shifted by an amount not in the range (of 0-31), a collection which contains itself, equals method always returns true, etc.
62 | * FindBugs like PMD analyses your code and thus can be setup with a very minimal setup. FindBugs can also be configured with custom bugs, this setup is out of the scope of this article. More information on how to do this can be found here.
63 |
64 | * A basic setup might look something like this
65 | ```
66 | apply plugin: 'findbugs'
67 |
68 | check.dependsOn 'findbugs'
69 |
70 | task findbugs(type: FindBugs) {
71 |
72 | description 'Generate FindBugs reports for this build'
73 |
74 | ignoreFailures true
75 |
76 | //Higher levels increase precision and find more bugs at the expense of running time and memory consumption.
77 | effort = 'max'
78 | //The priority threshold for reporting bugs. If set to {@code low}, all bugs are reported.
79 | reportLevel = 'low'
80 |
81 | //Define path to classes
82 | classes = fileTree("${project.rootDir}/app/build/intermediates/classes") //path to compiled class files
83 |
84 | source 'src' // Specify the source code. The script should be applied to
85 | include '**/*.java' // the module build.gradle so the 'src' folder resides at the same level
86 | exclude '**/gen/**' // include / exclude folders and files.
87 |
88 | //Define exclude config file
89 | excludeFilter = file("${rootProject.projectDir}/gradle/config/findbugs/exclude.xml")
90 |
91 | //IMPORTANT: FINDBUGS CAN ONLY GENERATE 1 REPORT. XML OR HTML!! AND PATH MUST BE DEFINED!!
92 | reports {
93 | xml.enabled = false
94 | html.enabled = true
95 | xml.destination = "$project.buildDir/reports/findbugs/findbugs-output.xml"
96 | html.destination = "$project.buildDir/reports/findbugs/findbugs-output.html"
97 | }
98 |
99 | classpath = files()
100 | }
101 | ```
102 |
103 | * A general `exclude.xml` file can be found in this repo. And it consists of a simple pattern to exclude files generated by the most common libraries like dagger, butterknife, kotlin, ... When using a library, you trust the developers code so this should not be included in the analysis
104 |
105 | Since FindBugs analyses compiled class files it can be used with Kotlin (ノ◕ヮ◕)ノ*:・゚✧
106 |
107 | ## Checkstyle
108 | * Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. Eventhough this might seem minor, adhering the same code style throughout a project can drastically increase readability and thus the quality of your code.
109 |
110 | * Checkstyle is something that takes a while to setup. You need to think about the codestyle you and the team you're in want to honor. And when setting deciding on codestyle conventions, it's easily to overlook certain situations. Luckily Checkstyle has a very good documentation, and it's highly configureable. For more information http://checkstyle.sourceforge.net/checks.html, an example of a config file can be found in this repo.
111 |
112 | ```
113 | apply plugin: 'checkstyle'
114 |
115 | check.dependsOn 'checkstyle'
116 |
117 | task checkstyle(type: Checkstyle) {
118 |
119 | description "Generate Checkstyle reports for this build" //Add description to task
120 |
121 | ignoreFailures true
122 |
123 | configFile file("${rootProject.projectDir}/gradle/config/checkstyle/checkstyle.xml")
124 |
125 | source 'src'
126 | include '**/*.java'
127 | exclude '**/gen/**', '**/test/**'
128 |
129 | reports {
130 | xml.enabled = true
131 | html.enabled = true
132 | }
133 |
134 | classpath = files(file("${project.rootDir}/app/build/intermediates/classes"))
135 | }
136 | ```
137 |
138 | ## Source
139 | * https://pmd.github.io/
140 | * http://findbugs.sourceforge.net/
141 | * http://checkstyle.sourceforge.net/
142 | * https://docs.gradle.org/current/userguide/findbugs_plugin.html
143 | * https://docs.gradle.org/current/userguide/pmd_plugin.html
144 | * https://docs.gradle.org/current/userguide/checkstyle_plugin.html
145 | * http://stackoverflow.com/questions/20710704/gradles-pmd-plugin-what-are-acceptable-arguments
146 |
--------------------------------------------------------------------------------