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 #3300: Add check for accessibility label for activities #3352

Merged
merged 182 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 164 commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
225a4fc
Fix #3290: Add support for generic regex pattern matching
Sparsh1212 Jun 10, 2021
638895f
Apply review suggestions for proto location
Sparsh1212 Jun 11, 2021
e3fd706
Delete main directory
Sparsh1212 Jun 11, 2021
b25e776
Implment script logic and tests
Sparsh1212 Jun 14, 2021
d44e015
CI setup part 1
Sparsh1212 Jun 14, 2021
de1d38f
syntax fix in yaml file
Sparsh1212 Jun 14, 2021
173fe53
import nits in dummy file
Sparsh1212 Jun 15, 2021
618e380
Use regex patterns from script in script test
Sparsh1212 Jun 16, 2021
e3830ac
Make PR suggestions into effect
Sparsh1212 Jun 16, 2021
bb93c0a
Make PR suggestions into effect
Sparsh1212 Jun 16, 2021
f7342c1
Make PR suggestions into effect
Sparsh1212 Jun 16, 2021
51e593b
Improve naming of script_assets variables
Sparsh1212 Jun 16, 2021
0d17657
Make PR suggestions into effect
Sparsh1212 Jun 16, 2021
16bb041
Make PR suggestions
Sparsh1212 Jun 17, 2021
325f28c
Make PR suggestions
Sparsh1212 Jun 17, 2021
a3f8ea6
Revamp testing approach
Sparsh1212 Jun 18, 2021
b1970eb
Merge branch 'develop' into regex-checks
Sparsh1212 Jun 18, 2021
51e64aa
Fix #3291: Add check for XML syntax correctness
Sparsh1212 Jun 18, 2021
f440a33
nit fixes
Sparsh1212 Jun 18, 2021
255773d
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 18, 2021
7b2a178
Introduce XML syntax check in static checks workflow
Sparsh1212 Jun 18, 2021
14c5f6f
Fix #3292: Add check for test files presence for prod files
Sparsh1212 Jun 18, 2021
163310e
Make nit suggestions
Sparsh1212 Jun 20, 2021
6131c1d
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 21, 2021
9cb5fc5
Make nit suggestions
Sparsh1212 Jun 21, 2021
4120775
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 21, 2021
8c98cf2
Make nit suggestions
Sparsh1212 Jun 21, 2021
7f1762c
Fix #3300: Add check for accessibility labels for activities
Sparsh1212 Jun 21, 2021
5229ac9
Add CI check for label presence for activities
Sparsh1212 Jun 21, 2021
7e1d24a
Add ScriptConstants file to exemptions test list
Sparsh1212 Jun 21, 2021
08cf6c3
merge test-file-check
Sparsh1212 Jun 21, 2021
b72e419
Test if: always()
Sparsh1212 Jun 21, 2021
d8472ab
Revert "Test if: always()"
Sparsh1212 Jun 21, 2021
fe42a64
Add if: always()
Sparsh1212 Jun 21, 2021
e12f247
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 21, 2021
9fdb165
Add if: always()
Sparsh1212 Jun 21, 2021
7bf2726
Merge branch 'test-file-check' into accesibilty-label-check
Sparsh1212 Jun 21, 2021
6e3424b
Add if: always()
Sparsh1212 Jun 21, 2021
381853c
Apply review suggestions on PR
Sparsh1212 Jun 22, 2021
c59494f
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 23, 2021
293ab92
Make review suggestions from regex pattern checks
Sparsh1212 Jun 23, 2021
f393e1e
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 23, 2021
56d607e
Implement review suggestions based on #3340
Sparsh1212 Jun 24, 2021
d01a238
Refactor PR as per feedback recieved
Sparsh1212 Jun 24, 2021
b7cb290
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 24, 2021
5a4ac03
Implement feedback suggestions
Sparsh1212 Jun 24, 2021
f6b0715
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 24, 2021
0feacee
Implement review suggestions
Sparsh1212 Jun 24, 2021
28fbc73
Implement review suggestions
Sparsh1212 Jun 24, 2021
96c0bfd
Implement review suggestions
Sparsh1212 Jun 24, 2021
dcbf660
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 24, 2021
56cf6d0
Implement review suggestions
Sparsh1212 Jun 24, 2021
1e3c47d
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 24, 2021
60e64dc
nits
Sparsh1212 Jun 25, 2021
cd2f287
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 25, 2021
36033ef
Nit fixes
Sparsh1212 Jun 25, 2021
161f8ec
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 25, 2021
996694b
Nit fixes
Sparsh1212 Jun 25, 2021
8740a48
Nit fixes
Sparsh1212 Jun 25, 2021
6671857
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 25, 2021
11963c8
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 25, 2021
c8aa5e4
merge test-file-check
Sparsh1212 Jun 26, 2021
3b78452
Implement feedback suggestions as per #3340
Sparsh1212 Jun 26, 2021
fe17ed9
nit fix
Sparsh1212 Jun 27, 2021
6860083
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jun 27, 2021
4083244
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 27, 2021
7c6f3e8
Merge branch 'test-file-check' into accesibilty-label-check
Sparsh1212 Jun 27, 2021
d65efa4
nit fix
Sparsh1212 Jun 27, 2021
3afc018
nit fix
Sparsh1212 Jun 28, 2021
b13e3f3
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jun 28, 2021
6132e5d
Merge branch 'test-file-check' into accesibilty-label-check
Sparsh1212 Jun 28, 2021
4a5b47e
nit fix
Sparsh1212 Jun 28, 2021
60f2482
Review suggestions part 1
Sparsh1212 Jun 29, 2021
9375775
Implement review suggestions part 2
Sparsh1212 Jun 29, 2021
a94cc5e
nit fixes
Sparsh1212 Jun 30, 2021
a811521
resolve merge conflict
Sparsh1212 Jun 30, 2021
aeb20d3
update static_checks
Sparsh1212 Jun 30, 2021
d5a0166
add test to repository file
Sparsh1212 Jun 30, 2021
8ac402d
nit fix
Sparsh1212 Jun 30, 2021
32910ea
nit fix
Sparsh1212 Jun 30, 2021
8b749db
nit fix
Sparsh1212 Jun 30, 2021
6c08868
merge regex-checks
Sparsh1212 Jun 30, 2021
4add1ed
Do review suggestions
Sparsh1212 Jun 30, 2021
be2f808
Implement review suggestions
Sparsh1212 Jul 1, 2021
1002034
Implement review suggestions
Sparsh1212 Jul 1, 2021
11010b1
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 1, 2021
ad4b0ec
nit fix
Sparsh1212 Jul 1, 2021
8eaf8df
merge xml-syntax-check
Sparsh1212 Jul 1, 2021
3042f2e
Implement review suggestions
Sparsh1212 Jul 1, 2021
49745a4
Add Ben as a codeowner for the ScriptExemptions file
Sparsh1212 Jul 1, 2021
05dbe3e
bazel files nit fix
Sparsh1212 Jul 1, 2021
45d73c9
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 1, 2021
5a9c601
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 1, 2021
83d66e0
Introduce a library for the regex assets
Sparsh1212 Jul 1, 2021
8cae1f8
Make directory structure same as that of #3374
Sparsh1212 Jul 2, 2021
e201a3d
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 2, 2021
44d839c
Make directory structure similar to #3374
Sparsh1212 Jul 2, 2021
edd6b4e
Merge branch 'develop' into regex-checks
Sparsh1212 Jul 2, 2021
5e38f79
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 2, 2021
73de958
merge xml-syntax-checks
Sparsh1212 Jul 2, 2021
9e67cab
add new files to test file script exemptions and nit fixes
Sparsh1212 Jul 2, 2021
7a73b1f
merge develop
Sparsh1212 Jul 3, 2021
1637ccd
diable ktlint max-line-length
Sparsh1212 Jul 3, 2021
fba990e
disable ktlint-max-line
Sparsh1212 Jul 3, 2021
262a4ec
disable ktlint max-length
Sparsh1212 Jul 3, 2021
8e5887c
merge regex-checks
Sparsh1212 Jul 3, 2021
fcb0555
remove testonly attribute from tests
Sparsh1212 Jul 3, 2021
de21e33
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 3, 2021
130c0d9
add new files to script exemptions
Sparsh1212 Jul 3, 2021
b56c104
nit fix
Sparsh1212 Jul 4, 2021
cdb88fe
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 4, 2021
98f7d73
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 4, 2021
3459461
nit fix
Sparsh1212 Jul 5, 2021
69c5f96
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 5, 2021
26a8d52
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 5, 2021
2e785d5
merge regex-checks
Sparsh1212 Jul 5, 2021
5e13219
nit fix
Sparsh1212 Jul 5, 2021
21e5197
Apply review suggestions
Sparsh1212 Jul 6, 2021
e557570
ktlint fix
Sparsh1212 Jul 6, 2021
3cb5db3
nit fix
Sparsh1212 Jul 6, 2021
c37cca3
Apply nit fixes
Sparsh1212 Jul 6, 2021
e2186d7
Apply nit fixes
Sparsh1212 Jul 6, 2021
7d7f9fc
Remove script constants
Sparsh1212 Jul 7, 2021
b70c880
nit fix
Sparsh1212 Jul 7, 2021
e70413b
add tests for XML syntax error handler
Sparsh1212 Jul 7, 2021
8e8bcf5
merge xml-syntax-check
Sparsh1212 Jul 7, 2021
31c1df5
add todo
Sparsh1212 Jul 7, 2021
5849bc0
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 7, 2021
e09e837
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 7, 2021
637606c
add todo
Sparsh1212 Jul 7, 2021
5ed9d9a
Merge branch 'develop' into regex-checks
Sparsh1212 Jul 8, 2021
bab0b70
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 8, 2021
c30158c
nit fixes
Sparsh1212 Jul 8, 2021
d57ef42
Merge branch 'develop' into regex-checks
Sparsh1212 Jul 8, 2021
d873ecd
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 8, 2021
de8bf3a
add test
Sparsh1212 Jul 8, 2021
5a1cbd9
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 8, 2021
91e108a
add testOnly
Sparsh1212 Jul 8, 2021
17ddf56
Merge branch 'regex-checks' into xml-syntax-check
Sparsh1212 Jul 8, 2021
594d31a
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 8, 2021
1940980
nit fixes
Sparsh1212 Jul 8, 2021
d34d46b
nit fix
Sparsh1212 Jul 8, 2021
ba0b960
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 8, 2021
50ea8ae
nit fixes
Sparsh1212 Jul 8, 2021
c72e5a9
nit fixes
Sparsh1212 Jul 8, 2021
57d0b42
nit fixes
Sparsh1212 Jul 8, 2021
c32c921
nit fixes
Sparsh1212 Jul 8, 2021
b99a316
fix textproto file
Sparsh1212 Jul 8, 2021
af6a607
merge-regex-checks
Sparsh1212 Jul 8, 2021
6bdea69
Merge branch 'xml-syntax-check' into test-file-check
Sparsh1212 Jul 8, 2021
7f13ff8
merge xml-syntax-check
Sparsh1212 Jul 8, 2021
19fc1e9
add exemptions to textproto
Sparsh1212 Jul 8, 2021
99a1f13
sort failures lexicographically
Sparsh1212 Jul 8, 2021
0dd079c
Merge branch 'develop' into test-file-check
Sparsh1212 Jul 9, 2021
f286c73
add new files to exemption list
Sparsh1212 Jul 9, 2021
0db928c
merge test-file-check
Sparsh1212 Jul 11, 2021
0d2d9dd
merge develop
Sparsh1212 Jul 11, 2021
a331ffa
nit fixes
Sparsh1212 Jul 11, 2021
484891e
nit fixes
Sparsh1212 Jul 11, 2021
5a7495d
add kdocs
Sparsh1212 Jul 13, 2021
9988373
nit fix
Sparsh1212 Jul 13, 2021
0eb4dd6
nit fix
Sparsh1212 Jul 13, 2021
76b8e2c
Trigger CI failure exclusively
Sparsh1212 Jul 14, 2021
e34798e
Revert CI check failure
Sparsh1212 Jul 14, 2021
dcba69f
merge develop
Sparsh1212 Jul 17, 2021
f09d0d4
nit fix
Sparsh1212 Jul 17, 2021
9c94456
nit fix
Sparsh1212 Jul 17, 2021
b042bba
nit fixes
Sparsh1212 Jul 20, 2021
8e9c383
Merge branch 'develop' into accesibilty-label-check
Sparsh1212 Jul 22, 2021
dc2b163
nit fixes
Sparsh1212 Jul 22, 2021
b012d04
nit fixes
Sparsh1212 Jul 22, 2021
eacacba
Add redundant exemptions check
Sparsh1212 Jul 24, 2021
57a4b8d
Merge branch 'develop' into accesibilty-label-check
Sparsh1212 Jul 24, 2021
43cf464
rectify static_checks
Sparsh1212 Jul 24, 2021
3d3b03f
Remove duplicate proto libraries
Sparsh1212 Jul 24, 2021
1aa7ead
nit fixes
Sparsh1212 Jul 28, 2021
9fb4e1c
add activity to exemption
Sparsh1212 Jul 28, 2021
fffef74
nit fixes
Sparsh1212 Jul 28, 2021
6f0f05c
nit fixes
Sparsh1212 Jul 28, 2021
015d717
nit fixes
Sparsh1212 Jul 28, 2021
cb67d44
Merge branch 'develop' into accesibilty-label-check
Sparsh1212 Jul 28, 2021
bb68dcd
update branch
Sparsh1212 Jul 28, 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
5 changes: 5 additions & 0 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,8 @@ jobs:
if: always()
run: |
bazel run //scripts:test_file_check -- $(pwd)

- name: Accessibility label check
if: always()
run: |
bazel run //scripts:accessibility_label_check -- $(pwd) app/src/main/AndroidManifest.xml
23 changes: 23 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Kotlin-based scripts to help developers or perform continuous integration tasks.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_binary", "kt_jvm_library")
load(
"//scripts:script_assets.bzl",
"generate_accessibility_label_assets_list_from_text_protos",
"generate_regex_assets_list_from_text_protos",
"generate_test_file_assets_list_from_text_protos",
)
Expand Down Expand Up @@ -98,3 +99,25 @@ kt_jvm_binary(
main_class = "org.oppia.android.scripts.testfile.TestFileCheckKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/testfile:test_file_check_lib"],
)

ACCESSIBILITY_LABEL_EXEMPTION_ASSETS = generate_accessibility_label_assets_list_from_text_protos(
name = "accessibility_label_exemption_assets",
accessibility_label_exemptions_name = ["accessibility_label_exemptions"],
)

kt_jvm_library(
name = "accessibility_label_check_assets",
testonly = True,
data = ACCESSIBILITY_LABEL_EXEMPTION_ASSETS,
visibility = [":oppia_script_test_visibility"],
)

kt_jvm_binary(
name = "accessibility_label_check",
testonly = True,
data = ACCESSIBILITY_LABEL_EXEMPTION_ASSETS,
main_class = "org.oppia.android.scripts.label.AccessibilityLabelCheckKt",
runtime_deps = [
"//scripts/src/java/org/oppia/android/scripts/label:accessibility_label_check_lib",
],
)
27 changes: 27 additions & 0 deletions scripts/assets/accessibility_label_exemptions.textproto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
exempted_activity: "app/home/HomeActivity"
exempted_activity: "app/home/recentlyplayed/RecentlyPlayedActivity"
exempted_activity: "app/mydownloads/MyDownloadsActivity"
exempted_activity: "app/player/state/testing/StateFragmentTestActivity"
exempted_activity: "app/profileprogress/ProfilePictureActivity"
exempted_activity: "app/settings/profile/ProfileEditActivity"
exempted_activity: "app/splash/SplashActivity"
exempted_activity: "app/testing/AudioFragmentTestActivity"
exempted_activity: "app/testing/BindableAdapterTestActivity"
exempted_activity: "app/testing/ConceptCardFragmentTestActivity"
exempted_activity: "app/testing/DragDropTestActivity"
exempted_activity: "app/testing/ExplorationInjectionActivity"
exempted_activity: "app/testing/ExplorationTestActivity"
exempted_activity: "app/testing/HomeFragmentTestActivity"
exempted_activity: "app/testing/HomeTestActivity"
exempted_activity: "app/testing/HtmlParserTestActivity"
exempted_activity: "app/testing/ImageRegionSelectionTestActivity"
exempted_activity: "app/testing/InputInteractionViewTestActivity"
exempted_activity: "app/testing/LessonThumbnailImageViewTestActivity"
exempted_activity: "app/testing/NavigationDrawerTestActivity"
exempted_activity: "app/testing/ProfileChooserFragmentTestActivity"
exempted_activity: "app/testing/SplashTestActivity"
exempted_activity: "app/testing/TestFontScaleConfigurationUtilActivity"
exempted_activity: "app/testing/TopicRevisionTestActivity"
exempted_activity: "app/testing/TopicTestActivity"
exempted_activity: "app/testing/TopicTestActivityForStory"
exempted_activity: "app/walkthrough/WalkthroughActivity"
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions scripts/script_assets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,28 @@ def generate_test_file_assets_list_from_text_protos(
proto_dep_bazel_target_prefix = "//scripts/src/java/org/oppia/android/scripts/proto",
proto_package = "proto",
)

def generate_accessibility_label_assets_list_from_text_protos(
name,
accessibility_label_exemptions_name):
"""
Converts multiple lists of text proto assets to binary.

Args:
name: str. The name of this generation instance. This will be a prefix for derived targets.
accessibility_label_exemptions_name: list of str. The list of accessibility label exemptions
file names.

Returns:
list of str. The list of new proto binary asset files that were generated.
"""
return generate_proto_binary_assets(
name = name,
names = accessibility_label_exemptions_name,
proto_dep_name = "accessibility_label_exemptions",
proto_type_name = "AccessibilityLabelExemptions",
name_prefix = name,
asset_dir = "assets",
proto_dep_bazel_target_prefix = "//scripts/src/java/org/oppia/android/scripts/proto",
proto_package = "proto",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package org.oppia.android.scripts.label

import org.oppia.android.scripts.proto.AccessibilityLabelExemptions
import org.w3c.dom.Node
import org.w3c.dom.NodeList
import java.io.File
import java.io.FileInputStream
import java.util.stream.Collectors
import java.util.stream.IntStream
import javax.xml.parsers.DocumentBuilderFactory

/**
* Script for ensuring that all the Activities in the codebase are defined with accessibility
* labels.
*
* Usage:
* bazel run //scripts:accessibility_label_check -- <path_to_directory_root> <path_to_app_level
* _manifest_file>
*
* Arguments:
* - path_to_directory_root: directory path to the root of the Oppia Android repository.
* - path_to_app_level_manifest_file: path to the manifest file of app layer.
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* bazel run //scripts:accessibility_label_check -- $(pwd) app/src/main/AndroidManifest.xml
*/
fun main(vararg args: String) {
val repoPath = "${args[0]}/"

val accessibilityLabelExemptiontextProto = "scripts/assets/accessibility_label_exemptions"
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

val accessibilityLabelExemptionList = loadAccessibilityLabelExemptionsProto(
accessibilityLabelExemptiontextProto
).getExemptedActivityList()

val manifesFilePath = args[1]
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

val fullPathToManifestFile = repoPath + manifesFilePath

val builderFactory = DocumentBuilderFactory.newInstance()

val docBuilder = builderFactory.newDocumentBuilder()

val doc = docBuilder.parse(File(fullPathToManifestFile))
doc.getDocumentElement().normalize()

val completeActivityList = convertNodeListToListOfNode(doc.getElementsByTagName("activity"))

val activityListWithoutLabel = completeActivityList.filter { node ->
checkIfActivityHasMissingLabel(node, accessibilityLabelExemptionList)
}

logFailures(activityListWithoutLabel, repoPath, accessibilityLabelExemptiontextProto)

if (activityListWithoutLabel.isNotEmpty()) {
throw Exception("ACCESSIBILITY LABEL CHECK FAILED")
} else {
println("ACCESSIBILITY LABEL CHECK PASSED")
}
}

/**
* Checks whether an activity element has a missing label.
*
* @param activityNode instance of Node
* @param accessibilityLabelExemptionList list of all the exemptions of the label check
* @return whether the label is present or not
*/
private fun checkIfActivityHasMissingLabel(
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
activityNode: Node,
accessibilityLabelExemptionList: List<String>
): Boolean {
val attributesList = activityNode.getAttributes()
val activityPath = attributesList.getNamedItem("android:name").getNodeValue()
if (
activityPath
.removePrefix(".")
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
.replace(".", "/") in accessibilityLabelExemptionList
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
) {
return false
}
return attributesList.getNamedItem("android:label") == null
}

/**
* The [nodeList] is not iterable. This helper
* function converts it to List<Node>.
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
*
* @param nodeList instance of NodeList
* @return a list of nodes
*/
private fun convertNodeListToListOfNode(nodeList: NodeList): List<Node> {
return IntStream.range(0, nodeList.getLength())
.mapToObj(nodeList::item)
.collect(Collectors.toList())
}
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

/**
* Logs the failures for accessibility label check.
*
* @param matchedNodes a list of nodes having missing label
* @param repoPath path of the repo to be analyzed
*/
private fun logFailures(
matchedNodes: List<Node>,
repoPath: String,
accessibilityLabelExemptiontextProto: String
) {
val pathPrefix = "${repoPath}app/src/main/java/org/oppia/android"
if (matchedNodes.isNotEmpty()) {
println("Accessiblity labels missing for Activities:")
matchedNodes.sortedBy {
it.getAttributes()
.getNamedItem("android:name")
.getNodeValue()
}.forEach { node ->
println(
"- $pathPrefix" +
"${
node.getAttributes()
.getNamedItem("android:name")
.getNodeValue()
.replace(".", "/")
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
}"
)
}
println("If this is correct, please update $accessibilityLabelExemptiontextProto.textproto")
println(
"Note that, in general, all Activities should have labels. If you choose to add an" +
" exemption, please specifically call this out in your PR description."
)
println()
}
}

/**
* Loads the test file exemptions list to proto.
*
* @param accessibilityLabelExemptiontextProto the location of the accessibility label exemption
* textproto file.
* @return proto class from the parsed textproto file
*/
private fun loadAccessibilityLabelExemptionsProto(accessibilityLabelExemptiontextProto: String):
AccessibilityLabelExemptions {
val protoBinaryFile = File("$accessibilityLabelExemptiontextProto.pb")
val builder = AccessibilityLabelExemptions.getDefaultInstance().newBuilderForType()

// This cast is type-safe since proto guarantees type consistency from mergeFrom(),
// and this method is bounded by the generic type T.
@Suppress("UNCHECKED_CAST")
val protoObj: AccessibilityLabelExemptions =
FileInputStream(protoBinaryFile).use {
builder.mergeFrom(it)
}.build() as AccessibilityLabelExemptions
return protoObj
}
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions scripts/src/java/org/oppia/android/scripts/label/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Libraries corresponding to accessibility label check that ensures all the activities in the codebase
are defined with labels.
"""

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")

kt_jvm_library(
name = "accessibility_label_check_lib",
testonly = True,
srcs = ["AccessibilityLabelCheck.kt"],
visibility = ["//scripts:oppia_script_binary_visibility"],
deps = [
"//scripts/src/java/org/oppia/android/scripts/common:repository_file",
"//scripts/src/java/org/oppia/android/scripts/proto:accessibility_label_exemptions_java_proto_lite",
],
)
12 changes: 12 additions & 0 deletions scripts/src/java/org/oppia/android/scripts/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ java_lite_proto_library(
visibility = ["//scripts:oppia_script_library_visibility"],
deps = [":test_file_exemptions_proto"],
)

proto_library(
name = "accessibility_label_exemptions_proto",
srcs = ["script_exemptions.proto"],
BenHenning marked this conversation as resolved.
Show resolved Hide resolved
visibility = ["//scripts:oppia_script_binary_visibility"],
)

java_lite_proto_library(
name = "accessibility_label_exemptions_java_proto_lite",
visibility = ["//scripts:oppia_script_library_visibility"],
deps = [":accessibility_label_exemptions_proto"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ message TestFileExemptions {
// at the correct lexicographical position in the textproto file.
repeated string exempted_file_path = 1;
}

// Exemptions for the accessibility label check. Exemptions indicate Activities for which we should
// not check for the presence of an accessibility label.
message AccessibilityLabelExemptions {
// List of all the Activities which should be exempted for the accessibility label check.
// For exempting any Activity, provide its path w.r.t app in
// 'script/assets/accessibility_label_exemptions.textproto'
// Also, note that the exemptions in the textproto file are maintained in lexicographical order.
// While adding any new Activity, please add it only at the correct lexicographical position,
// so that the list remains sorted.
//
// For example if we want to add the 'RecentlyPlayedActivity' to the exemption list, add:
// 'exempted_activity: "app/home/recentlyplayed/RecentlyPlayedActivity"'
// at the correct lexicographical position in the textproto file.
repeated string exempted_activity = 1;
}
Loading