Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1735: Add Java Linter to the project #2101

Merged
merged 66 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
be81193
added java linter
anandwana001 Nov 10, 2020
aacd296
added exec name
anandwana001 Nov 10, 2020
eff0560
using jar to run command
anandwana001 Nov 10, 2020
9c45bfe
update config file
anandwana001 Nov 10, 2020
09ec7ad
checking on java 10
anandwana001 Nov 10, 2020
6b17885
checking on java 11
anandwana001 Nov 10, 2020
ac0a45c
adding more indentation to check
anandwana001 Nov 10, 2020
7671065
adding property
anandwana001 Nov 10, 2020
cf8c41b
updating property
anandwana001 Nov 10, 2020
96a55f2
fixed path for property
anandwana001 Nov 10, 2020
ae6ceca
update severity to error on custom level
anandwana001 Nov 10, 2020
a1f7c0f
fix java lint errors
anandwana001 Nov 11, 2020
512e234
path reference update
anandwana001 Nov 11, 2020
19bf833
adding all other modules
anandwana001 Nov 11, 2020
ce98803
nit fix
anandwana001 Nov 12, 2020
7d3f0f8
nit fix
anandwana001 Dec 1, 2020
2e9f663
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
anandwana001 Dec 1, 2020
831b258
nit java lint fix
anandwana001 Dec 1, 2020
82fd627
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
anandwana001 Dec 9, 2020
7918330
nit update
anandwana001 Dec 21, 2020
9709143
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
anandwana001 Jan 6, 2021
9e89925
adding pre push
anandwana001 Jan 6, 2021
7a38a17
add license
anandwana001 Jan 6, 2021
221a212
nit fix
anandwana001 Jan 6, 2021
5f7a0a9
comment update
anandwana001 Jan 9, 2021
a349a9d
try without config file
anandwana001 Jan 13, 2021
e6e27e5
separate file for action, non prepush
anandwana001 Jan 13, 2021
c07457c
nit fix
anandwana001 Jan 13, 2021
77b1906
pushing error to see on action
anandwana001 Jan 13, 2021
c11b4cf
fixing script to give error for warn
anandwana001 Jan 13, 2021
29d505b
nit fix
anandwana001 Jan 13, 2021
160e364
fixed putted error
anandwana001 Jan 13, 2021
142f65c
Merge branch 'develop' of https://github.com/oppia/oppia-android into…
anandwana001 Jan 18, 2021
ab86f08
undo changes
anandwana001 Jan 18, 2021
3532b28
shifting main linter to oppia-android-tools
anandwana001 Jan 18, 2021
8f4e0ac
create dir at action
anandwana001 Jan 18, 2021
7ad8a01
checking home path
anandwana001 Jan 18, 2021
6341f28
make actions use scripts
anandwana001 Feb 4, 2021
ec9dcc9
modularize scripts
anandwana001 Feb 5, 2021
e4bb401
trying to get correct path on actions
anandwana001 Feb 5, 2021
a529aca
using $HOME for path
anandwana001 Feb 5, 2021
67e5351
trying giving exe permission to script file
anandwana001 Feb 5, 2021
58816dc
fixing path
anandwana001 Feb 5, 2021
1863036
diff sh/bash
anandwana001 Feb 5, 2021
7ca46b2
diff sh/bash
anandwana001 Feb 5, 2021
992f317
trying sudo
anandwana001 Feb 5, 2021
e714f55
complete path
anandwana001 Feb 5, 2021
16e2dcb
remove header
anandwana001 Feb 5, 2021
d5f5d58
show list
anandwana001 Feb 5, 2021
fb71166
echo list
anandwana001 Feb 5, 2021
151448f
try ls
anandwana001 Feb 5, 2021
2d94da2
try download direct
anandwana001 Feb 5, 2021
77cea50
try sh
anandwana001 Feb 5, 2021
02a7ba9
try github workspace
anandwana001 Feb 5, 2021
3d1f3a7
using complete path
anandwana001 Feb 5, 2021
191fabd
using complete path
anandwana001 Feb 5, 2021
cca2fd4
fix path in lint for actions
anandwana001 Feb 5, 2021
c6c08f4
fix path
anandwana001 Feb 5, 2021
ecd4d06
use home path
anandwana001 Feb 5, 2021
f7a351b
fix for ktlint
anandwana001 Feb 5, 2021
abd4112
nit fix
anandwana001 Feb 5, 2021
854a8b8
removed setup_deps.sh
anandwana001 Feb 9, 2021
65706b6
putting error
anandwana001 Feb 9, 2021
92c12da
fixing script
anandwana001 Feb 9, 2021
9680162
fixing main script
anandwana001 Feb 9, 2021
9599fec
using #!/bin/bash and error removed
anandwana001 Feb 9, 2021
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
69 changes: 43 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ on:
workflow_dispatch:
pull_request:
push:
branches:
branches:
# Push events on develop branch
- develop

# This workflow has the following jobs:
# linters: Kotlin and Protobuf Linting
# linters: Java, Kotlin, Protobuf
# robolectric_tests: Robolectric tests for all modules except the app module
# app_tests: Non-flaky Robolectric tests for the app module
jobs:
Expand All @@ -25,40 +25,58 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Create oppia android tools directory
run: mkdir -p $HOME/oppia-android-tools

# Java 11 is specifically needed for Checkstyle.
- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

- name: Download Checkstyle
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
run: |
cd $HOME/oppia-android-tools
bash /home/runner/work/oppia-android/oppia-android/scripts/checkstyle_download.sh

- name: Download Ktlint
run: |
KTLINT="0.37.1"
echo Using Ktlint $KTLINT
curl -sSLO https://github.com/pinterest/ktlint/releases/download/$KTLINT/ktlint
chmod a+x ktlint

- name: Download buf
run: |
cd $HOME/oppia-android-tools
bash /home/runner/work/oppia-android/oppia-android/scripts/ktlint_download.sh

- name: Download buf
run: |
cd $HOME/oppia-android-tools
BUFVERSION="v0.15.0"
echo Using Bufbuild version $BUFVERSION
curl -sSL https://github.com/bufbuild/buf/releases/download/$BUFVERSION/buf-$(uname -s)-$(uname -m) > buf
chmod a+x buf


- name: Java lint check
run: |
bash /home/runner/work/oppia-android/oppia-android/scripts/checkstyle_lint_check.sh $HOME

- name: Kotlin lint check
run: ./ktlint --android domain/src/**/*.kt utility/src/**/*.kt data/src/**/*.kt app/src/**/*.kt testing/src/**/*.kt && echo "Lint completed successfully"

- name: Protobuf lint check
run: ./buf check lint --input=model/src/main/proto --input-config buf.yaml && echo "Protobuf lint check completed successfully"

run: |
bash /home/runner/work/oppia-android/oppia-android/scripts/ktlint_lint_check.sh $HOME

- name: Protobuf lint check
run: $HOME/oppia-android-tools/buf check lint --input=model/src/main/proto --input-config buf.yaml && echo "Protobuf lint check completed successfully"

robolectric_tests:
name: Robolectric Tests (Non-App Modules)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
id: cache
with:
path: ~/.gradle
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-jars-{{ checksum "build.gradle" }}

- name: Set up JDK 1.9
uses: actions/setup-java@v1
with:
Expand All @@ -67,11 +85,11 @@ jobs:
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: ./gradlew --full-stacktrace androidDependencies

- name: Build App
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace assembleDebug

- name: Utility tests
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :utility:testDebugUnitTest
Expand All @@ -81,7 +99,7 @@ jobs:
with:
name: utility reports
path: utility/build/reports

- name: Domain tests
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: sudo ./gradlew --full-stacktrace :domain:testDebugUnitTest
Expand All @@ -101,26 +119,26 @@ jobs:
with:
name: testing reports
path: testing/build/reports

app_tests:
name: Robolectric Tests - App Module (Non-Flaky)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-jars-{{ checksum "build.gradle" }}

- name: Set up JDK 1.9
uses: actions/setup-java@v1
with:
java-version: 1.9

- name: Robolectric tests - App Module
# We require 'sudo' to avoid an error of the existing android sdk. See https://github.com/actions/starter-workflows/issues/58
run: |
Expand Down Expand Up @@ -169,4 +187,3 @@ jobs:
name: oppia-bazel-apk
path: /home/runner/work/oppia-android/oppia-android/oppia.apk
- uses: actions/checkout@v2

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.oppia.android.app.databinding;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void setBackgroundDrawable(@NonNull View view, @ColorInt int color
background.setColor(0xff000000 | colorRgb);
}

/** Used to set a top rounded-rect background drawable with a data-bound color. */
@BindingAdapter("app:topRoundedRectDrawableWithColor")
public static void setTopBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) {
view.setBackgroundResource(R.drawable.top_rounded_rect_background);
Expand All @@ -29,6 +30,7 @@ public static void setTopBackgroundDrawable(@NonNull View view, @ColorInt int co
background.setColor(0xff000000 | colorRgb);
}

/** Used to set a bottom rounded-rect background drawable with a data-bound color. */
@BindingAdapter("app:bottomRoundedRectDrawableWithColor")
public static void setBottomBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) {
view.setBackgroundResource(R.drawable.bottom_rounded_rect_background);
Expand All @@ -37,6 +39,7 @@ public static void setBottomBackgroundDrawable(@NonNull View view, @ColorInt int
background.setColor(0xff000000 | colorRgb);
}

/** Used to set a rectangular background drawable with a data-bound color. */
@BindingAdapter("app:rectangleDrawableWithColor")
public static void setRectangleBackgroundDrawable(@NonNull View view, @ColorInt int colorRgb) {
view.setBackgroundResource(R.drawable.rectangle_background);
Expand All @@ -45,6 +48,7 @@ public static void setRectangleBackgroundDrawable(@NonNull View view, @ColorInt
background.setColor(0xff000000 | colorRgb);
}

/** Used to set a resource background to a button. */
@BindingAdapter("android:button")
public static void setBackgroundResource(@NonNull Button button, @DrawableRes int resource) {
button.setBackgroundResource(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** Holds all custom binding adapters that bind to [EditText]. */
public final class EditTextBindingAdapters {

/** Binding adapter for setting a [TextWatcher] as a change listener for an [EditText] */
/** Binding adapter for setting a [TextWatcher] as a change listener for an [EditText]. */
@BindingAdapter("app:textChangedListener")
public static void bindTextWatcher(@NonNull EditText editText, TextWatcher textWatcher) {
editText.addTextChangedListener(textWatcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void setImageDrawable(

/**
* Binds the specified [LessonThumbnailGraphic] as the source for the [ImageView].
*
* <p/>
* The view should be specified to have no width/height (when sized in a constraint layout), and
* use centerCrop for the image to appear correctly.
*/
Expand All @@ -58,42 +58,61 @@ public static void setImageDrawable(
switch (thumbnailGraphic) {
case BAKER:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_baker;
break;
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
case CHILD_WITH_BOOK:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_book;
break;
case CHILD_WITH_CUPCAKES:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_cupcakes;
break;
case CHILD_WITH_FRACTIONS_HOMEWORK:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_child_with_fractions_homework;
break;
case DUCK_AND_CHICKEN:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_duck_and_chicken;
break;
case PERSON_WITH_PIE_CHART:
drawableResourceId = R.drawable.lesson_thumbnail_graphic_person_with_pie_chart;
break;
case IDENTIFYING_THE_PARTS_OF_A_FRACTION:
drawableResourceId = R.drawable.topic_fractions_01;
break;
case WRITING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_02;
break;
case EQUIVALENT_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_03;
break;
case MIXED_NUMBERS_AND_IMPROPER_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_04;
break;
case COMPARING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_05;
break;
case ADDING_AND_SUBTRACTING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_06;
break;
case MULTIPLYING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_07;
break;
case DIVIDING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_08;
break;
case DERIVE_A_RATIO:
drawableResourceId = R.drawable.topic_ratios_01;
break;
case WHAT_IS_A_FRACTION:
drawableResourceId = R.drawable.topic_fractions_01;
break;
case FRACTION_OF_A_GROUP:
drawableResourceId = R.drawable.topic_fractions_02;
break;
case ADDING_FRACTIONS:
drawableResourceId = R.drawable.topic_fractions_03;
break;
case MIXED_NUMBERS:
drawableResourceId = R.drawable.topic_fractions_04;
break;
default:
drawableResourceId = R.drawable.topic_fractions_01;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public final class TextInputLayoutBindingAdapters {

/** Binding adapter for setting an error message. */
@BindingAdapter("app:errorMessage")
public static void setErrorMessage(@NonNull TextInputLayout textInputLayout, String errorMessage) {
public static void setErrorMessage(
@NonNull TextInputLayout textInputLayout,
String errorMessage
) {
textInputLayout.setError(errorMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.databinding.BindingAdapter;
import org.oppia.android.R;
import org.oppia.android.util.system.OppiaDateTimeFormatter;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.oppia.android.R;
import org.oppia.android.util.system.OppiaDateTimeFormatter;

/** Holds all custom binding adapters that bind to [TextView]. */
public final class TextViewBindingAdapters {
Expand All @@ -29,6 +29,7 @@ public static void setProfileDataText(@NonNull TextView textView, long timestamp
));
}

/** Binds last used with relative timestamp. */
@BindingAdapter("profile:lastVisited")
public static void setProfileLastVisitedText(@NonNull TextView textView, long timestamp) {
String profileLastUsed = textView.getContext().getString(R.string.profile_last_used);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void setLayoutWidth(@NonNull View view, float width) {
view.setLayoutParams(layoutParams);
}

/** Adapter to animate-rotate a view by the specified angle in the specified direction. */
@BindingAdapter(
value = {
"app:isRotationAnimationClockwise",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.oppia.android.app.recyclerview;

import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableList;
Expand Down
4 changes: 3 additions & 1 deletion app/src/test/java/DataBinderMapperImpl.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package androidx.databinding;

// TODO(#1683): Remove when android_local_test works with data-binding.
/**
* Generated code necessary to run tests with Bazel.
*
* <p/>
* Typically, this code is generated by Bazel and included in the srcs list when running tests.
* However, the `enable_data_binding` flag somehow affects this process. For now, this file must be
* included in the srcs list of any Bazel test in app module.
*/
public final class DataBinderMapperImpl extends MergedDataBinderMapper {

DataBinderMapperImpl() {
addMapper(new org.oppia.android.app.test.DataBinderMapperImpl());
}
Expand Down
8 changes: 8 additions & 0 deletions scripts/checkstyle_download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Download checkstyle
CHECKSTYLE="8.37"
echo Using Checkstyle version $CHECKSTYLE
curl -sSLOC - https://github.com/checkstyle/checkstyle/releases/download/checkstyle-$CHECKSTYLE/checkstyle-$CHECKSTYLE-all.jar
chmod a+x checkstyle-$CHECKSTYLE-all.jar
echo Checkstyle file downloaded
33 changes: 33 additions & 0 deletions scripts/checkstyle_lint_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

echo "********************************"
echo "Checking Java file formatting"
echo "********************************"

github_actions_path=$1

jar_file_path=$?

if [ $# -eq 0 ]; then
jar_file_path="../oppia-android-tools/checkstyle-8.37-all.jar"
else
jar_file_path="$github_actions_path/oppia-android-tools/checkstyle-8.37-all.jar"
fi

lint_results=$(java -jar $jar_file_path -c /google_checks.xml app/src/ data/src/ domain/src/ utility/src/ testing/src/ 2>&1)

lint_command_result=$?

echo $lint_results

if [ "$lint_command_result" -ne 0 ] || [ -z "$lint_results" ] || [[ ${lint_results} == *"[WARN]"* ]]; then
# Assume any lint output or non-zero exit code is a failure.
echo "********************************"
echo "Checkstyle issue found."
echo "Please fix the above issues."
echo "********************************"
exit 1
else
echo "Checkstyle lint check completed successfully"
exit 0
fi
8 changes: 8 additions & 0 deletions scripts/ktlint_download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Download ktlint
KTLINT="0.37.1"
echo Using Ktlint $KTLINT
curl -sSLOC - https://github.com/pinterest/ktlint/releases/download/$KTLINT/ktlint
chmod a+x ktlint
echo Ktlint file downloaded
Loading