Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Add sample application #100

Merged
merged 22 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ staticAnalysis {
This will enable all the tools with their default settings. For more advanced configurations, please refer to the
[advanced usage](docs/advanced-usage.md) and to the [supported tools](docs/supported-tools.md) pages.

## Sample app
There's a sample Android project available [here](https://github.com/novoda/gradle-static-analysis-plugin/tree/master/sample). This sample showcases a simple setup featuring Checkstyle, FindBugs, PMD, Lint and Detekt.

## Roadmap
The plugin is under active development and to be considered in **beta stage**. It is routinely used by many Novoda projects and
by other external projects with no known critical issues. The API is supposed to be relatively stable, but there still may be
Expand Down
79 changes: 79 additions & 0 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
id 'io.gitlab.arturbosch.detekt' version '1.0.0.RC6-3'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: com.novoda.staticanalysis.StaticAnalysisPlugin

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId 'com.novoda.staticanalysis.sample'
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName '1.0'
}

buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}

dependencies {
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
}

staticAnalysis {

penalty none

checkstyle {
toolVersion '8.8'
exclude project.fileTree('src/test/java')
exclude '**/*.kt'
configFile rootProject.file('team-props/checkstyle-modules.xml')
includeVariants { variant -> variant.name.contains('debug') }
}

pmd {
toolVersion '6.1.0'
exclude project.fileTree('src/test/java')
ruleSetFiles = rootProject.files('team-props/pmd-rules.xml')
ruleSets = [] // https://stackoverflow.com/questions/32247190/pmd-exclude-pattern-with-gradle
includeVariants { variant -> variant.name.contains('debug') }
}

findbugs {
toolVersion '3.0.1'
excludeFilter rootProject.file('team-props/findbugs-excludes.xml')
includeVariants { variant -> variant.name.contains('debug') }
}

lintOptions {
lintConfig rootProject.file('team-props/lint-config.xml')
checkReleaseBuilds false
warningsAsErrors true
}

detekt {
profile('main') {
input = "$projectDir/src/main/java"
config = rootProject.file('team-props/detekt-config.yml')
filters = '.*test.*,.*/resources/.*,.*/tmp/.*'
output = "$projectDir/build/reports/detekt"
}
}

}
24 changes: 24 additions & 0 deletions sample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.novoda.buildpropertiesplugin.sample">

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name="com.novoda.staticanalysisplugin.sample.MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name="com.novoda.staticanalysisplugin.sample.SomeOtherActivity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.novoda.staticanalysisplugin.sample

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.novoda.buildpropertiesplugin.sample.R
import kotlinx.android.synthetic.main.activity_my.*

class MyActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_my)

button.setOnClickListener({
LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(1)
startActivity(Intent(this, SomeOtherActivity::class.java))
})
}

private fun LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()

private fun A_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun B_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun C_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun D_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun E_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun F_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun G_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun H_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun I_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun J_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
private fun K_LOOK_ANOTHER_CRAZY_LONG_LONG_LONG_METHOD_NAME_FOR_NO_APPARENT_REASON_WHY_IS_THIS_METHOD_NAMED_LIKE_THIS_WHY_IT_LITERALLY_MAKES_NO_SENSE_WHATSOEVER(duration: Int) = Toast.makeText(this, "some useless message", duration).show()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.novoda.staticanalysisplugin.sample;

public class MyClass {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.novoda.staticanalysisplugin.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.novoda.buildpropertiesplugin.sample.R;

public class SomeOtherActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_some_other);

THIS_IS_A_VERY_VERY_VERY_LONG_NAME_FOR_A_METHOD_IT_IS_IN_FACT_VERY_LONG_INDEED_NO_NEED_TO_COUNT_THE_NUMBER_OF_CHARACTERS_YOU_CAN_CLEARLY_SEE_THIS_IS_WAY_LONGER_THAN_IT_SHOULD(0);

String extra = getIntent().getStringExtra("nope");
if (extra != null) {
Log.d(SomeOtherActivity.class.getSimpleName(), extra);
}
int boom = extra.length();
}

private void THIS_IS_A_VERY_VERY_VERY_LONG_NAME_FOR_A_METHOD_IT_IS_IN_FACT_VERY_LONG_INDEED_NO_NEED_TO_COUNT_THE_NUMBER_OF_CHARACTERS_YOU_CAN_CLEARLY_SEE_THIS_IS_WAY_LONGER_THAN_IT_SHOULD(int duration) {
Toast.makeText(this, "i have no idea what to write here", duration).show();
}
}
13 changes: 13 additions & 0 deletions sample/app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name" />

</LinearLayout>
7 changes: 7 additions & 0 deletions sample/app/src/main/res/layout/activity_some_other.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions sample/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
3 changes: 3 additions & 0 deletions sample/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Static Analysis Plugin Sample</string>
</resources>
11 changes: 11 additions & 0 deletions sample/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.novoda.buildpropertiesplugin.sample;

import org.junit.Test;

public class MyClassTest {

@Test
public void testNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestNametestName() {

}
}
20 changes: 20 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
buildscript {
ext.kotlin_version = '1.2.30'

repositories {
google()
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

subprojects {
repositories {
google()
mavenCentral()
}
}
15 changes: 15 additions & 0 deletions sample/buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repositories {
jcenter()
}

apply plugin: 'groovy'

dependencies {
compile gradleApi()
}

sourceSets {
main {
groovy { srcDir '../../plugin/src/main/groovy' }
}
}
Binary file added sample/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Mar 12 18:00:46 GMT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
Loading