Skip to content

Commit

Permalink
Add checkstyle and fix Codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfav committed Nov 22, 2017
1 parent 80e9cf2 commit 801b1bc
Show file tree
Hide file tree
Showing 29 changed files with 295 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -41,7 +41,7 @@ before_install:

script:
- ./gradlew clean assemble --stacktrace
- ./gradlew lint --stacktrace
- ./gradlew checkstyle lint --stacktrace
- ./gradlew testReleaseUnitTest --info
# - ./gradlew connectedDebugAndroidTest

Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'

Properties localProps = getSigningProperties()

android {
Expand Down
Expand Up @@ -48,5 +48,4 @@ public void drawerActivityTest() {
appCompatButton3.perform(scrollTo(), click());

}

}
Expand Up @@ -60,5 +60,4 @@ public void multiTapActivityTEst() {

pressBack();
}

}
Expand Up @@ -88,7 +88,9 @@ public String getValue() {
}
}));

firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));
firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. " +
"\nI need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do" +
"\nthat? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));

firstPage.add(Hood.get().createHeaderEntry("Misc Action"));
PageUtil.addAction(firstPage, new ButtonDefinition("Test Loading", new OnClickAction() {
Expand Down
Expand Up @@ -64,7 +64,9 @@ public Pages getPageData(@NonNull Pages pages) {
firstPage.add(DefaultProperties.createSectionBasicDeviceInfo());
firstPage.add(DefaultProperties.createDetailedDeviceInfo(this));

firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));
firstPage.add(Hood.get().createPropertyEntry("MultiLine Test", "I am displaying text in a textview that appears to\nbe too long to fit into one screen. \n" +
"I need to make my TextView scrollable. How can i do\nthat? Here is the code\nbe too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\n" +
"that? Here is the code\ne too long to fit into one screen. \nI need to make my TextView scrollable. How can i do\nthat? Here is the code", true));

firstPage.add(Hood.get().createHeaderEntry("Misc Action"));
PageUtil.addAction(firstPage, new ButtonDefinition("Test Loading", new OnClickAction() {
Expand Down
139 changes: 139 additions & 0 deletions config/checkstyle/checkstyle.xml
@@ -0,0 +1,139 @@
<?xml version="1.0" ?><!--
~ Copyright 2016 Patrick Favre-Bulle
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<!--This it the config for the main source code with more strict rules than e.g. testing -->

<module name="Checker">
<module name="NewlineAtEndOfFile" /> <!-- force newline, important for git merge and POSIX compatibility: http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile -->
<module name="FileTabCharacter" /> <!-- e.g. disallow tab character outside of strings -->
<module name="UniqueProperties"><!-- must not have duplicate properties in .properties files: http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->
<property name="fileExtensions" value="properties" />
</module>

<module name="FileLength"><!-- max line length for single file: http://checkstyle.sourceforge.net/config_sizes.html#FileLength -->
<property name="max" value="1500" />
</module>

<module name="TreeWalker">
<module name="SuppressionCommentFilter" /> <!-- use //CHECKSTYLE:OFF (...) //CHECKSTYLE:ON to disable checkstyle: http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter -->

<!-- Annotations -->
<module name="MissingDeprecated"> <!-- if @deprecated and javadoc is there, must be explained in javadoc: http://checkstyle.sourceforge.net/config_annotation.html#MissingDeprecated -->
<property name="skipNoJavadoc" value="true" />
</module>
<module name="MissingOverride" /> <!-- if has @inheritDoc in javadoc must have @Override http://checkstyle.sourceforge.net/config_annotation.html#MissingOverride -->
<module name="PackageAnnotation" /> <!-- must only be in package-info: http://checkstyle.sourceforge.net/config_annotation.html#PackageAnnotation -->

<!-- Blocks -->
<module name="AvoidNestedBlocks" /> <!-- fails for useless {...} blocks: http://checkstyle.sourceforge.net/config_blocks.html#AvoidNestedBlocks -->
<module name="EmptyCatchBlock"> <!-- empty catch blocks exception var name must be 'ignored' or must not be empty: http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock -->
<property name="exceptionVariableName" value="expected|ignore" />
</module>

<!-- Misc -->
<module name="ArrayTypeStyle" /> <!-- e.g. int[] array is ok int array[] not: http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle -->
<module name="MutableException" /> <!-- e.g. int[] array is ok int array[] not: http://checkstyle.sourceforge.net/config_misc.html#ArrayTypeStyle -->
<module name="UpperEll" /> <!-- long values must be postfixed with 'L' not 'l': http://checkstyle.sourceforge.net/config_misc.html#UpperEll -->
<module name="Indentation"> <!-- Checks correct indentation of Java code: http://checkstyle.sourceforge.net/config_misc.html#Indentation -->
<property name="basicOffset" value="4" />
<property name="arrayInitIndent" value="8" />
<property name="braceAdjustment" value="0" />
<property name="caseIndent" value="4" />
<property name="throwsIndent" value="4" />
<property name="lineWrappingIndentation" value="4" />
<property name="forceStrictCondition" value="false" />
</module>

<!-- Modifier -->
<module name="ModifierOrder" /> <!-- Checks that the order of modifiers conforms to the suggestions in the Java Language specification: http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder -->
<module name="RedundantModifier"> <!-- Checks for redundant modifiers: http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier -->
<property name="tokens" value="METHOD_DEF, VARIABLE_DEF, INTERFACE_DEF, ANNOTATION_FIELD_DEF, ENUM_DEF, CLASS_DEF" />
</module>

<!-- Classes -->
<module name="FinalClass" /> <!-- class with only private constructor must be final: http://checkstyle.sourceforge.net/config_design.html#FinalClass -->
<module name="OneStatementPerLine" /> <!-- you cant write int i=1;int j=2; http://checkstyle.sourceforge.net/config_design.html#OneStatementPerLine -->
<module name="SimplifyBooleanReturn" /> <!-- directly return boolean doe not check and return http://checkstyle.sourceforge.net/config_design.html#SimplifyBooleanReturn -->
<module name="StringLiteralEquality" /> <!-- you cant write myString == "this" http://checkstyle.sourceforge.net/config_design.html#StringLiteralEquality -->
<module name="OneTopLevelClass" /> <!-- only one root class per file http://checkstyle.sourceforge.net/config_design.html#OneTopLevelClass -->
<module name="ThrowsCount"> <!-- max 5 throws definitions per method: http://checkstyle.sourceforge.net/config_design.html#ThrowsCount -->
<property name="max" value="5" />
</module>
<module name="InterfaceIsType" /> <!-- interface must contain methods, should not be used for const only: http://checkstyle.sourceforge.net/config_design.html#InterfaceIsType -->
<module name="OuterTypeFilename" /> <!-- class Foo must be in Foo.java: http://checkstyle.sourceforge.net/config_misc.html#OuterTypeFilename -->

<module name="HideUtilityClassConstructor" /> <!-- utility class constructor must be private: http://checkstyle.sourceforge.net/config_design.html#HideUtilityClassConstructor -->
<module name="VisibilityModifier"> <!-- most members must be private http://checkstyle.sourceforge.net/config_design.html#VisibilityModifier -->
<property name="protectedAllowed" value="true" />
<property name="packageAllowed" value="true" />
<property name="allowPublicImmutableFields" value="true" />
<property name="allowPublicFinalFields" value="true" />
<property name="publicMemberPattern" value="^TAG$|^CREATOR$" />
</module>

<!-- Coding -->
<module name="CovariantEquals" /> <!-- if you override equals with different type you must provide equals with same type: http://checkstyle.sourceforge.net/config_coding.html#CovariantEquals -->
<module name="DefaultComesLast" /> <!-- in switch case default must be the last elem: http://checkstyle.sourceforge.net/config_coding.html#DefaultComesLast -->
<module name="EmptyStatement" /> <!-- basically an empty semicolon: http://checkstyle.sourceforge.net/config_coding.html#EmptyStatement -->
<module name="EqualsHashCode" /> <!-- if you implement equals, you must implement hashcode and vice versa: http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode -->
<module name="NoFinalizer" /> <!-- Verifies there are no finalize() methods defined in a class: http://checkstyle.sourceforge.net/config_coding.html#NoFinalizer -->
<module name="FallThrough" /> <!-- switch fallthrough with statement not allowed http://checkstyle.sourceforge.net/config_coding.html#FallThrough -->
<module name="IllegalInstantiation" /> <!-- Must not use const of certain types (Activity, Fragment): http://checkstyle.sourceforge.net/config_coding.html#IllegalInstantiation -->

<!-- Size Limitiations -->
<module name="LineLength"><!-- max char length per line http://checkstyle.sourceforge.net/config_sizes.html#LineLength -->
<property name="max" value="300" />
</module>
<module name="MethodLength"><!-- max line length for single method http://checkstyle.sourceforge.net/config_sizes.html#MethodLength -->
<property name="max" value="150" />
</module>
<module name="AnonInnerLength"><!-- max line length for anon class http://checkstyle.sourceforge.net/config_sizes.html#AnonInnerLength -->
<property name="max" value="85" />
</module>
<module name="ParameterNumber"><!-- max params for method http://checkstyle.sourceforge.net/config_sizes.html#ParameterNumber -->
<property name="max" value="10" />
<property name="ignoreOverriddenMethods" value="true" />
<property name="tokens" value="METHOD_DEF" />
</module>

<!-- Naming Conventions -->
<!--<module name="ConstantName" /> for possible futer use-->

<!-- Whitespaces -->
<module name="EmptyLineSeparator"> <!-- Checks for correct empty line placements, omit VAR token: http://checkstyle.sourceforge.net/config_whitespace.html#EmptyLineSeparator -->
<property name="allowMultipleEmptyLines" value="false" />
<property name="tokens" value="PACKAGE_DEF, IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF" />
</module>
<module name="SingleSpaceSeparator" /> <!-- Checks if a token is surrounded by whitespace: http://checkstyle.sourceforge.net/config_whitespace.html#SingleSpaceSeparator -->
<module name="GenericWhitespace" /> <!-- Checks whitespaces with Java Generics <>: http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace -->
<module name="WhitespaceAround"> <!-- Checks if a token is surrounded by whitespace: http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround -->
<property name="allowEmptyConstructors" value="true" />
<property name="allowEmptyMethods" value="true" />
<property name="allowEmptyTypes" value="true" />
<property name="allowEmptyLambdas" value="true" />
<property name="allowEmptyCatches" value="true" />
</module>

<!-- Imports -->
<module name="RedundantImport" /> <!-- e.g. double import statements: http://checkstyle.sourceforge.net/config_imports.html#RedundantImport -->
<module name="UnusedImports" /> <!-- http://checkstyle.sourceforge.net/config_imports.html#UnusedImports -->
<module name="IllegalImport" /> <!-- checks if import sun.* is used http://checkstyle.sourceforge.net/config_imports.html#IllegalImport -->
</module>
</module>
24 changes: 24 additions & 0 deletions config/checkstyle/suppressions.xml
@@ -0,0 +1,24 @@
<?xml version="1.0"?><!--
~ Copyright 2016 Patrick Favre-Bulle
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://checkstyle.sourceforge.net/dtds/suppressions_1_1.dtd">

<!-- Add global checkstyle suppression here, see: http://checkstyle.sourceforge.net/config_filters.html -->
<suppressions>

</suppressions>
68 changes: 68 additions & 0 deletions gradle/checkstyle.gradle
@@ -0,0 +1,68 @@
/*
* Copyright 2016 Patrick Favre-Bulle
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Checkstyle tasks
* Usage:
* - place this file under root dir of your project at /gradle directory
* - apply script from your gradle file:
* apply from : "{rootDir}/gradle/checkstyle.gradle"
*
* To configure checkstyle use configs at:
* "{rootDir}/config/checkstyle/checkstyle.xml" - for main projects
* "{rootDir}/config/checkstyle/checkstyle-test.xml" - for tests
* "{rootDir}/config/checkstyle/suppresions.xml" - for style suppressions
*
* Xml and HTML reports are stored:
* "{project.buildDir}/reports/checkstyle/"
* HTML styling is done by XSLT stylesheet:
* "{rootDir}/config/checkstyle/checkstyle-noframes-sorted.xsl"
*/

apply plugin: 'checkstyle'

checkstyle {
toolVersion = "8.4"
}

task checkstyleMain(type: Checkstyle) {
ignoreFailures = false
showViolations = false
source fileTree(dir: 'src', exclude: ['**/*test*/**', '**/*Test*/**'])
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
classpath = files()
configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
}

task checkstyleTest(type: Checkstyle) {
ignoreFailures = false
showViolations = false
source fileTree(dir: 'src', include: ['**/*test*/**', '**/*Test*/**'])
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
classpath = files()
configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
}

task checkstyle(dependsOn: ['checkstyleMain', 'checkstyleTest']) {
description 'Runs Checkstyle inspection against Android sourcesets.'
group = 'Code Quality'
}
2 changes: 1 addition & 1 deletion hood-core/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'de.mobilej.unmock'
apply plugin: 'jacoco-android'
apply plugin: "com.github.kt3k.coveralls"

apply from: "$rootDir/gradle/checkstyle.gradle"
Properties localProps = rootProject.getSigningProperties()

android {
Expand Down
Expand Up @@ -29,4 +29,4 @@ public class HoodDebugPageViewTest {
// view.refresh();
// assertEquals(pages.getAll().size(), view.getPages().getAll().size());
// }
}
}
Expand Up @@ -41,7 +41,7 @@ public static Builder newBuilder() {
return new Builder();
}

public static class Builder {
public static final class Builder {
private boolean showZebra = true;
private boolean showHighlightContent = false;
private boolean autoLog = true;
Expand Down
Expand Up @@ -21,6 +21,9 @@
*/
public final class ViewTypes {

private ViewTypes() {
}

public static final int VIEWTYPE_HEADER = 1 << 16;
public static final int VIEWTYPE_KEYVALUE = 1 << 16 + 1;
public static final int VIEWTYPE_ACTION = 1 << 16 + 2;
Expand All @@ -30,5 +33,4 @@ public final class ViewTypes {
public static final int VIEWTYPE_KEYVALUE_MULTILINE = 1 << 16 + 6;
public static final int VIEWTYPE_MESSAGE = 1 << 16 + 7;
public static final int VIEWTYPE_SPACER = 1 << 16 + 8;

}
Expand Up @@ -31,7 +31,7 @@
/**
* Reads and abstracts Android OS device states (wifi, bt, etc.)
*/
public class DeviceStatusUtil {
public final class DeviceStatusUtil {
public enum Status {
UNSUPPORTED, NEEDS_PERMISSION, ENABLED, DISABLED
}
Expand All @@ -40,6 +40,9 @@ public enum ConnectionState {
PERMISSION_NEEDED, DISCONNECTED, CONNECTED_WIFI, CONNECTED_MOBILE, CONNECTED_ETHERNET, CONNECTED_BT, CONNECTED_VPN, CONNECTED_OTHER
}

private DeviceStatusUtil() {
}

/**
* The current network (ie. internet) connectivity state. Needs correct permission to work.
*
Expand Down
5 changes: 4 additions & 1 deletion hood-core/src/main/java/at/favre/lib/hood/util/HoodUtil.java
Expand Up @@ -25,9 +25,12 @@
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class HoodUtil {
public final class HoodUtil {
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();

private HoodUtil() {
}

public static String byteToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
Expand Down
Expand Up @@ -29,7 +29,7 @@
/**
* Gets current runtime permission status
*/
public class PermissionTranslator {
public final class PermissionTranslator {
@Retention(RetentionPolicy.SOURCE)
@IntDef({GRANTED, GRANTED_ON_INSTALL, DENIED, BLOCKED})
public @interface PermissionState {
Expand All @@ -40,6 +40,9 @@ public class PermissionTranslator {
public static final int DENIED = 2;
public static final int BLOCKED = 3;

private PermissionTranslator() {
}

/**
* Gets the current status. Caveat: returns {@link #BLOCKED} the first time before the user accepts or denies a permission
*
Expand Down

0 comments on commit 801b1bc

Please sign in to comment.