Skip to content

Commit

Permalink
Enable code quality tools (#17)
Browse files Browse the repository at this point in the history
Enable CheckStyle, FindBugs and PMD with the same configurations as https://github.com/realm/realm-java. Also adds the same GitHub template.
  • Loading branch information
cmelchior committed May 9, 2016
1 parent 435c1f9 commit 01ea81c
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 13 deletions.
43 changes: 43 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,43 @@
> We LOVE to help with any issues or bug you have!
> **Questions**: If you have questions about how to use Realm, please ask on [SO](http://stackoverflow.com/questions/ask?tags=realm) - we monitor the Realm tag.
> **Feature Request**: Just fill in the first two sections below.
> **Bugs**: To help you as fast as possible with an issue or bug please describe your issue and the steps you have taken to reproduce it in as many details as possible.
>
> Thanks for helping us help you :-)
>
> Remove this and above before submitting.
#### Goal

> What do you want to achieve?
#### Expected Results

> ?
#### Actual Results

> E.g. full stack trace with exception
#### Steps & Code to Reproduce

> Describe your current debugging efforts.
#### Code Sample

```java

> Your code here. Bigger samples should ideally be as separate Android Studio project,
> in gists/repositories or privately at help@realm.io)

```

#### Version of Realm and tooling
Realm version(s): ?

Android Studio version: ?

Which Android version and device: ?
57 changes: 57 additions & 0 deletions adapters/build.gradle
Expand Up @@ -3,6 +3,9 @@ apply plugin: 'maven-publish'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
apply plugin: 'realm-android'

android {
Expand Down Expand Up @@ -33,6 +36,60 @@ dependencies {
javadoc "io.realm:realm-annotations:${rootProject.realmVersion}"
}

task findbugs(type: FindBugs) {
dependsOn assembleDebug
group = 'Verification'

ignoreFailures = false
effort = "default"
reportLevel = "medium"
excludeFilter = file("${projectDir}/../config/findbugs/findbugs-filter.xml")
classes = files("${projectDir}/build/intermediates/classes")
source = fileTree('src/main/java/')
classpath = files()
reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/findbugs/findbugs-output.xml"
}
html {
destination "$project.buildDir/findbugs/findbugs-output.html"
}
}
}

task pmd(type: Pmd) {
group = 'Verification'
print "${projectDir}"
source = fileTree('src/main/java')
ruleSetFiles = files("${projectDir}/../config/pmd/ruleset.xml")
ruleSets = [] // This needs to be here to remove the default checks

reports {
xml.enabled = false
html.enabled = true
}
}

task checkstyle(type: Checkstyle) {
group = 'Test'

source 'src'
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'

def configProps = ['proj.module.dir': projectDir.absolutePath]
configProperties configProps

configFile = file("${projectDir}/../config/checkstyle/checkstyle.xml")

// empty classpath
classpath = files()
}

task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += configurations.javadoc
Expand Down
Expand Up @@ -35,6 +35,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -222,4 +223,5 @@ public void testNullToNonNullResults() {

assertEquals(TEST_DATA_SIZE, realmAdapter.getCount());
}

}
26 changes: 13 additions & 13 deletions adapters/src/androidTest/java/io/realm/entity/AllJavaTypes.java
Expand Up @@ -27,19 +27,19 @@
public class AllJavaTypes extends RealmObject {

public static final String CLASS_NAME = "AllJavaTypes";
public static String FIELD_IGNORED = "fieldIgnored";
public static String FIELD_STRING = "fieldString";
public static String FIELD_SHORT = "fieldShort";
public static String FIELD_INT = "fieldInt";
public static String FIELD_LONG = "fieldLong";
public static String FIELD_BYTE = "fieldByte";
public static String FIELD_FLOAT = "fieldFloat";
public static String FIELD_DOUBLE = "fieldDouble";
public static String FIELD_BOOLEAN = "fieldBoolean";
public static String FIELD_DATE = "fieldDate";
public static String FIELD_BINARY = "fieldBinary";
public static String FIELD_OBJECT = "fieldObject";
public static String FIELD_LIST = "fieldList";
public static final String FIELD_IGNORED = "fieldIgnored";
public static final String FIELD_STRING = "fieldString";
public static final String FIELD_SHORT = "fieldShort";
public static final String FIELD_INT = "fieldInt";
public static final String FIELD_LONG = "fieldLong";
public static final String FIELD_BYTE = "fieldByte";
public static final String FIELD_FLOAT = "fieldFloat";
public static final String FIELD_DOUBLE = "fieldDouble";
public static final String FIELD_BOOLEAN = "fieldBoolean";
public static final String FIELD_DATE = "fieldDate";
public static final String FIELD_BINARY = "fieldBinary";
public static final String FIELD_OBJECT = "fieldObject";
public static final String FIELD_LIST = "fieldList";

@Ignore private String fieldIgnored;
@Index private String fieldString;
Expand Down
11 changes: 11 additions & 0 deletions config/checkstyle/checkstyle-suppressions.xml
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="[a-zA-Z0-9]*" files="R\.java" />
<suppress checks="." files="BuildConfig.java" />
<suppress checks="." files=".*\.properties" />
<suppress checks="FileLength" files="RealmTests.java" />
<suppress checks="FileLengthCheck" files="Realm.java|RealmAsyncQueryTests.java|RealmQuery.java|RealmQueryTests.java"/>
</suppressions>
154 changes: 154 additions & 0 deletions config/checkstyle/checkstyle.xml
@@ -0,0 +1,154 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">
<!-- There are non-ascii test cases -->
<property name="charset" value="UTF-8"/>
<!-- Files to ignore -->
<module name="SuppressionFilter">
<property name="file" value="${proj.module.dir}/../config/checkstyle/checkstyle-suppressions.xml"/>
</module>

<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
</module>
<module name="FileLength"/>
<module name="FileTabCharacter"/>

<!-- Trailing spaces -->
<!-- TODO: UNCOMMENT
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module> -->

<!-- Space after 'for', 'if', 'while', 'try' -->
<module name="RegexpSingleline">
<property name="format" value="^\s*(for|if|while|try)[^ ]"/>
<property name="message" value="Space needed before opening parenthesis."/>
</module>

<!-- For each spacing -->
<module name="RegexpSingleline">
<property name="format" value="^\s*for \(.*?([^ ]:|:[^ ])"/>
<property name="message" value="Space needed around ':' character."/>
</module>

<module name="TreeWalker">
<property name="cacheFile" value="bin/cachefile"/>

<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<!--module name="JavadocMethod"/-->
<!--module name="JavadocType"/-->
<!--module name="JavadocVariable"/-->
<!-- TODO: UNCOMMENT
<module name="JavadocStyle"/> -->


<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<!-- TODO: UNCOMMENT
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/> -->


<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<!--<module name="AvoidStarImport"/>-->
<!--<module name="IllegalImport"/>--> <!-- defaults to sun.* packages -->
<!--<module name="RedundantImport"/>-->
<!--<module name="UnusedImports"/>-->


<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<!-- TODO: UNCOMMENT
<module name="LineLength">
<property name="max" value="120"/>
<property name="severity" value="warning"/>
</module> -->
<!--<module name="MethodLength"/>-->
<!--<module name="ParameterNumber"/>-->


<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<!-- TODO: UNCOMMENT
<module name="GenericWhitespace"/>
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/> -->
<module name="WhitespaceAround">
<property name="tokens" value="LITERAL_DO"/>
</module>


<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<!-- TODO: UNCOMMENT
<module name="ModifierOrder"/>
<module name="RedundantModifier"/> -->


<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<!-- <module name="AvoidNestedBlocks"/> -->
<!--module name="EmptyBlock"/-->
<!-- <module name="LeftCurly"/> -->
<!--module name="NeedBraces"/-->
<!-- <module name="RightCurly"/> -->


<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<!--module name="AvoidInlineConditionals"/-->
<!-- TODO: UNCOMMENT
<module name="CovariantEquals"/>
<module name="EmptyStatement"/>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber">
<property name="severity" value="warning"/>
</module>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/> -->

<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<!--module name="DesignForExtension"/-->
<!-- TODO: UNCOMMENT
<module name="FinalClass">
<property name="severity" value="warning"/>
</module>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/> -->
<!--module name="VisibilityModifier"/-->


<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<!-- TODO: UNCOMMENT <module name="ArrayTypeStyle"/> -->
<!--module name="FinalParameters"/-->
<!--module name="TodoComment"/-->
<!-- TODO: UNCOMMENT <module name="UpperEll"/> -->
</module>
</module>
27 changes: 27 additions & 0 deletions config/findbugs/findbugs-filter.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<!-- ignore all issues in resource generation -->
<Class name="~.*\.R\$.*"/>
</Match>
<Match>
<Class name="~.*\.Manifest\$.*"/>
</Match>
<Match>
<Class name="io.realm.RealmBaseAdapter" />
<Field name="context" />
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>
<Match>
<Class name="io.realm.RealmBaseAdapter" />
<Field name="inflater" />
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>

<!-- Unit tests -->
<Match>
<Class name="~.*Tests?$"/>
<Bug pattern="DM_GC"/>
</Match>

</FindBugsFilter>
17 changes: 17 additions & 0 deletions config/pmd/ruleset.xml
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="RealmRuleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

<description>
Realm PMD ruleset
</description>

<rule ref="rulesets/java/basic.xml">
<exclude name="UselessParentheses"/>
</rule>

<rule ref="rulesets/java/android.xml"/>

</ruleset>

0 comments on commit 01ea81c

Please sign in to comment.