Setup various tools

This commit is contained in:
Benoit Marty
2019-03-13 17:00:30 +01:00
parent 26ae034ba9
commit a199eaa171
18 changed files with 743 additions and 3 deletions

141
tools/check/check_code_quality.sh Executable file
View File

@ -0,0 +1,141 @@
#!/usr/bin/env bash
#
# Copyright 2019 New Vector Ltd
#
# 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.
#
#######################################################################################################################
# Check drawable quantity
#######################################################################################################################
echo "Check drawable quantity"
numberOfFiles1=`ls -1U ./app/src/main/res/drawable-hdpi | wc -l | sed "s/ //g"`
numberOfFiles2=`ls -1U ./app/src/main/res/drawable-mdpi | wc -l | sed "s/ //g"`
numberOfFiles3=`ls -1U ./app/src/main/res/drawable-xhdpi | wc -l | sed "s/ //g"`
numberOfFiles4=`ls -1U ./app/src/main/res/drawable-xxhdpi | wc -l | sed "s/ //g"`
numberOfFiles5=`ls -1U ./app/src/main/res/drawable-xxxhdpi | wc -l | sed "s/ //g"`
if [[ ${numberOfFiles1} -eq ${numberOfFiles5} ]] && [[ ${numberOfFiles2} -eq ${numberOfFiles5} ]] && [[ ${numberOfFiles3} -eq ${numberOfFiles5} ]] && [[ ${numberOfFiles4} -eq ${numberOfFiles5} ]]; then
resultNbOfDrawable=0
echo "OK"
else
resultNbOfDrawable=1
echo "ERROR, missing drawable alternative."
fi
echo
#######################################################################################################################
# Search forbidden pattern
#######################################################################################################################
searchForbiddenStringsScript=./tmp/search_forbidden_strings.pl
if [[ -f ${searchForbiddenStringsScript} ]]; then
echo "${searchForbiddenStringsScript} already there"
else
mkdir tmp
echo "Get the script"
wget https://raw.githubusercontent.com/matrix-org/matrix-dev-tools/develop/bin/search_forbidden_strings.pl -O ${searchForbiddenStringsScript}
fi
if [[ -x ${searchForbiddenStringsScript} ]]; then
echo "${searchForbiddenStringsScript} is already executable"
else
echo "Make the script executable"
chmod u+x ${searchForbiddenStringsScript}
fi
echo
echo "Search for forbidden patterns in code..."
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_code.txt \
./app/src/main/java
resultForbiddenStringInCode=$?
echo
echo "Search for forbidden patterns in resources..."
${searchForbiddenStringsScript} ./tools/check/forbidden_strings_in_resources.txt \
./app/src/main/res/color \
./app/src/main/res/layout \
./app/src/main/res/menu \
./app/src/main/res/values \
./app/src/main/res/values-v21 \
./app/src/main/res/xml
resultForbiddenStringInResource=$?
#######################################################################################################################
# Check files with long lines
#######################################################################################################################
checkLongFilesScript=./tmp/check_long_files.pl
if [[ -f ${checkLongFilesScript} ]]; then
echo "${checkLongFilesScript} already there"
else
mkdir tmp
echo "Get the script"
wget https://raw.githubusercontent.com/matrix-org/matrix-dev-tools/develop/bin/check_long_files.pl -O ${checkLongFilesScript}
fi
if [[ -x ${checkLongFilesScript} ]]; then
echo "${checkLongFilesScript} is already executable"
else
echo "Make the script executable"
chmod u+x ${checkLongFilesScript}
fi
echo
echo "Search for long files..."
${checkLongFilesScript} 1000 \
./app/src/main/java \
./app/src/main/res/layout \
./app/src/main/res/values \
./app/src/main/res/values-v21 \
resultLongFiles=$?
#######################################################################################################################
# search png in drawable folder
#######################################################################################################################
echo
echo "Search for png files in /drawable..."
ls -1U ./app/src/main/res/drawable/*.png
resultTmp=$?
# Inverse the result, cause no file found is an error for ls but this is what we want!
if [[ ${resultTmp} -eq 0 ]]; then
echo "ERROR, png files detected in /drawable"
resultPngInDrawable=1
else
echo "OK"
resultPngInDrawable=0
fi
echo
if [[ ${resultNbOfDrawable} -eq 0 ]] && [[ ${resultForbiddenStringInCode} -eq 0 ]] && [[ ${resultForbiddenStringInResource} -eq 0 ]] && [[ ${resultLongFiles} -eq 0 ]] && [[ ${resultPngInDrawable} -eq 0 ]]; then
echo "MAIN OK"
else
echo "❌ MAIN ERROR"
exit 1
fi

View File

@ -0,0 +1,151 @@
#
# Copyright 2018 New Vector Ltd
#
# 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.
#
# This file list String which are not allowed in source code.
# Use Perl regex to write forbidden strings
# Note: line cannot start with a space. Use \s instead.
# It is possible to specify an authorized number of occurrence with === suffix. Default is 0
# Example:
# AuthorizedStringThreeTimes===3
# Extension:java
# Extension:kt
# Use new SecureLinearLayoutManager
# DISABLED
#new LinearLayoutManager
### No import static: use full class name
import static
### Rubbish from merge. Please delete those lines (sometimes in comment)
<<<<<<<
>>>>>>>
### carry return before "}". Please remove empty lines.
\n\s*\n\s*\}
### typo detected.
formated
abtract
Succes[^s]
succes[^s]
### Please insert line break. ex: .flatMap() not at new line
\}\)\.[\w]
### Use int instead of Integer
protected Integer
### Use the interface declaration. Example: use type "Map" instead of type "HashMap" to declare variable or parameter
(private|public|protected| ) (static )?(final )?(HashMap|HashSet|ArrayList)<
### Use int instead of short
Short\.parseShort
\(short\)
private short
final short
### Line length is limited to 160 chars. Please split long lines
.{161}
### "DO NOT COMMIT" has been committed
DO NOT COMMIT
### invalid formatting
\s{8}/\*\n \*
[^\w]if\(
while\(
for\(
# Add space after //
# DISABLED To re-enable when code will be formatted globally
#^\s*//[^\s]
# Not usable with unitary test. Use StringUtils
# DISABLED
#TextUtils\.isEmpty\(
### invalid formatting (too many space char)
^ /\*
# No ternary operator
# DISABLED
# \?
### unnecessary parenthesis around numbers, example: " (0)"
\(\d+\)
### Malformatted comment
^ \*
### import the package, do not use long class name with package
android\.os\.Build\.
### Tab char is forbidden. Use only spaces
\t
# Empty lines and trailing space
# DISABLED To re-enable when code will be formatted globally
#[ ]$
### Deprecated, use retrofit2.HttpException
import retrofit2\.adapter\.rxjava\.HttpException
### This is generally not necessary, no need to reset the padding if there is no drawable
setCompoundDrawablePadding\(0\)
### Deprecated use class form SDK API 26
ButterKnife\.findById\(
# Change thread with Rx
# DISABLED
#runOnUiThread
### Bad formatting of chain (missing new line)
\w\.flatMap\(
\w\.map\(
### Bad formatting of Realm query chain. Insert new line
\)\.equalTo
\)\.findAll
# Use StandardCharsets.UTF_8.name()
# DISABLED (min API to low)
#\"UTF-
### Directly use getString() in a Fragment
getActivity\(\)\.getString\(
### In Kotlin, Void has to be null safe, i.e. use 'Void?' instead of 'Void'
\: Void\)
### Home menu click is managed in parent Activity, with one exception
android\.R\.id\.home===2
### Kotlin conversion tools introduce this, but is can be replace by trim()
trim \{ it \<\= \' \' \}
### Use AlertDialog form v7 compat lib
android\.app\.AlertDialog
### Put the operator at the beginning of next line
&&$
\|\|$
==$
### Use JsonUtils.getBasicGson()
new Gson\(\)

View File

@ -0,0 +1,84 @@
#
# Copyright 2018 New Vector Ltd
#
# 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.
#
# This file list String which are not allowed in source code.
# Use Perl regex to write forbidden strings
# Note: line cannot start with a space. Use \s instead.
# It is possible to specify an authorized number of occurrence with === suffix. Default is 0
# Example:
# AuthorizedStringThreeTimes===3
# Extension:xml
### Rubbish from merge. Please delete those lines (sometimes in comment)
<<<<<<<
>>>>>>>
### Hardcoded string are forbidden. Please create a string resource
app\:emptyLabelText=\"[^@]
android\:text=\"[^@]
android\:hint=\"[^@]
# (with tolerance for empty string)
android\:title=\"[^@"]
android\:contentDescription=\"[^@]
# (with tolerance for summary="%s")
android\:summary=\"[^@|\%s]
app\:ms_floatingLabelText=\"[^@]
app\:ms_hint=\"[^@]
### "DO NOT COMMIT" has been committed
DO NOT COMMIT
### Tab char is forbidden. Use only spaces
\t
### Remove space in empty lines and trailing space
[ ]$
# Use project color
# DISABLED
#@android\:color\/
# String in multiline
# DISABLED
#<string [^<]*$
### double unbreakable space looks like an issue in translation
\\u00A0\\u00A0
### Empty XML tag. Please use the single tag form (<TagName .../>)
\"><\/
### Bad comment format in XML resources. Use <!-- --> instead of //
^\s*\/\/
### Bad RTL support, use attribute with Start and End
layout_constraintRight_
layout_constraintLeft_
### Use Preference from v7 library (android.support.v7.preference.PreferenceScreen)
<PreferenceScreen
### Use im.vector.preference.VectorSwitchPreference to support multiline of the title
<SwitchPreference
### Use im.vector.preference.VectorPreference to support multiline of the title
<Preference\n
### Will crash on API < 21. Use ?colorAccent instead
\?android:colorAccent
\?android:attr/colorAccent

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
adb shell am broadcast -a im.vector.receiver.DEBUG_ACTION_ALTER_SCALAR_TOKEN

3
tools/debug_dump_filesystem.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
adb shell am broadcast -a im.vector.receiver.DEBUG_ACTION_DUMP_FILESYSTEM

3
tools/debug_dump_prefs.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
adb shell am broadcast -a im.vector.receiver.DEBUG_ACTION_DUMP_PREFERENCES

View File

@ -0,0 +1,3 @@
# Test boot complete broadcast
adb shell am broadcast -a android.intent.action.ACTION_BOOT_COMPLETED -c android.intent.category.HOME -n im.vector.alpha/im.vector.receiver.VectorBootReceiver

8
tools/tests/test_referrer.sh Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER \
-n im.vector.alpha/im.vector.receiver.VectorReferrerReceiver \
--es "referrer" "utm_source=migrator\&utm_medium=web\&utm_content%3Dis%253Dhttps%253A%252F%252Fvector.im%252526hs%253Dhttps%253A%252F%252Ftadhack.vector.im"
# adb shell input text 'https://play.google.com/store/apps/details?id=im.vector.alpha\&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_content%3Dis%253Dhttps%253A%252F%252Fvector.im%252526hs%253Dhttps%253A%252F%252Ftadhack.vector.im%26anid%3Dadmob'

45
tools/travis/check_pr.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# Copyright 2018 New Vector Ltd
#
# 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.
#
branch=${TRAVIS_BRANCH}
# echo ${TRAVIS_BRANCH}
# If not on develop, exit, else we cannot get the list of modified files
# It is ok to check only when on develop branch
if [[ "${branch}" -eq 'develop' ]]; then
echo "Check that the file 'CHANGES.rst' has been modified"
else
echo "Not on develop branch"
exit 0
fi
# git status
listOfModifiedFiles=`git diff --name-only HEAD ${branch}`
# echo "List of modified files by this PR:"
# echo ${listOfModifiedFiles}
if [[ ${listOfModifiedFiles} = *"CHANGES.rst"* ]]; then
echo "CHANGES.rst has been modified!"
else
echo "❌ Please add a line describing your change in CHANGES.rst"
exit 1
fi