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 #3972: Added TextViewStyleCheck script #5599

Merged
merged 58 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e243e20
adding text view style check script
manas-yu Dec 16, 2024
00f7367
formatting
manas-yu Dec 16, 2024
25e31c0
error print fix
manas-yu Dec 16, 2024
0e7240c
Merge branch 'develop' into text-view-script
manas-yu Dec 17, 2024
8afffd9
Merge branch 'develop' into text-view-script
manas-yu Dec 20, 2024
0cda3ff
Merge branch 'develop' into text-view-script
manas-yu Dec 23, 2024
ecb097e
Merge branch 'develop' into text-view-script
manas-yu Dec 27, 2024
b3247dd
Merge branch 'develop' into text-view-script
manas-yu Dec 29, 2024
284759b
Merge branch 'develop' into text-view-script
manas-yu Dec 30, 2024
50155ab
edge cases
manas-yu Jan 8, 2025
781d682
formatting
manas-yu Jan 8, 2025
d66f9aa
Merge branch 'text-view-script' of https://github.com/manas-yu/oppia-…
manas-yu Jan 8, 2025
8b1f90f
class fix
manas-yu Jan 8, 2025
b5155bd
removing redundant checks
manas-yu Jan 8, 2025
0631ec7
checking style
manas-yu Jan 8, 2025
f104b96
kdoc fix
manas-yu Jan 8, 2025
8bd90bf
logging line no. and CI integration
manas-yu Jan 10, 2025
9e530aa
formatting
manas-yu Jan 10, 2025
051ab79
Merge branch 'develop' into text-view-script
manas-yu Jan 10, 2025
0510d7d
test file
manas-yu Jan 10, 2025
f24b7f6
Merge branch 'text-view-script' of https://github.com/manas-yu/oppia-…
manas-yu Jan 10, 2025
ec4c12d
bazel setup
manas-yu Jan 10, 2025
67ab290
revert
manas-yu Jan 10, 2025
afcb708
avoid redundant RTL/LTR settings checks
manas-yu Jan 10, 2025
b5d50a8
Merge branch 'develop' into text-view-script
manas-yu Jan 15, 2025
6caa1a9
Merge branch 'oppia:develop' into text-view-script
manas-yu Jan 15, 2025
992e644
revert
manas-yu Jan 15, 2025
73c90aa
adding ids
manas-yu Jan 15, 2025
7670404
updating tests
manas-yu Jan 15, 2025
5f7c85d
formatting
manas-yu Jan 15, 2025
ca14146
adding style
manas-yu Jan 16, 2025
8602e7e
kdoc and todo exemp
manas-yu Jan 16, 2025
e8ad25c
line number
manas-yu Jan 17, 2025
2fb3eff
formatting
manas-yu Jan 17, 2025
6e76303
attri list
manas-yu Jan 17, 2025
c80cfe9
kdoc
manas-yu Jan 17, 2025
4bdbe27
Deque and line no
manas-yu Jan 19, 2025
72e30eb
formatting
manas-yu Jan 19, 2025
1e0a43f
Merge branch 'develop' into text-view-script
manas-yu Jan 21, 2025
9917fad
Merge branch 'develop' into text-view-script
manas-yu Jan 22, 2025
250a24a
Merge branch 'develop' into text-view-script
manas-yu Jan 22, 2025
c26d301
TODO and idInformation
manas-yu Jan 22, 2025
8a77278
formatting
manas-yu Jan 22, 2025
cf97591
foramtting
manas-yu Jan 22, 2025
1a7eb37
idinfo logging
manas-yu Jan 22, 2025
0a02b75
renaming
manas-yu Jan 22, 2025
e727eab
Merge branch 'develop' into text-view-script
manas-yu Jan 22, 2025
4ccf308
formatting
manas-yu Jan 22, 2025
62ac584
formatting
manas-yu Jan 22, 2025
e82e479
Merge branch 'text-view-script' of github.com:manas-yu/oppia-android …
manas-yu Jan 22, 2025
a82826d
Merge branch 'develop' into text-view-script
manas-yu Jan 22, 2025
c9af6ad
exception handling
manas-yu Jan 22, 2025
e32a8d3
Merge branch 'text-view-script' of github.com:manas-yu/oppia-android …
manas-yu Jan 22, 2025
7e7b863
adding id attributes
manas-yu Jan 23, 2025
eb202c7
Merge branch 'develop' into text-view-script
manas-yu Jan 27, 2025
aa8e4c3
Merge branch 'develop' into text-view-script
manas-yu Jan 27, 2025
ca80dc7
Merge branch 'develop' into text-view-script
manas-yu Jan 28, 2025
ee445b1
edits
manas-yu Jan 28, 2025
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
7 changes: 7 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,10 @@ java_binary(
main_class = "org.oppia.android.scripts.telemetry.DecodeUserStudyEventStringKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/telemetry:decode_user_study_event_string_lib"],
)

kt_jvm_binary(
name = "check_textview_styles",
testonly = True,
main_class = "org.oppia.android.scripts.xml.TextViewStyleCheckKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/xml:check_textview_styles"],
)
11 changes: 11 additions & 0 deletions scripts/src/java/org/oppia/android/scripts/xml/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ kt_jvm_library(
"//scripts/src/java/org/oppia/android/scripts/common:repository_file",
],
)

kt_jvm_library(
name = "check_textview_styles",
testonly = True,
srcs = ["TextViewStyleCheck.kt"],
visibility = ["//scripts:oppia_script_binary_visibility"],
deps = [
":xml_syntax_error_handler",
"//scripts/src/java/org/oppia/android/scripts/common:repository_file",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.oppia.android.scripts.xml

import java.io.File
import javax.xml.parsers.DocumentBuilderFactory

/**
* Script to ensure all TextView elements in layout XML files use centrally managed styles.
*
* Usage:
* bazel run //scripts:check_textview_styles -- <path_to_repository_root>
*
* Arguments:
* - path_to_repository_root: The root path of the repository.
*
* Example:
* bazel run //scripts:check_textview_styles -- $(pwd)
Rd4dev marked this conversation as resolved.
Show resolved Hide resolved
*/
fun main(vararg args: String) {
require(args.isNotEmpty()) {
"Usage: bazel run" +
" //scripts:check_textview_styles -- <path_to_repository_root>"
}

val repoRoot = File(args[0])
require(repoRoot.exists()) { "Repository root path does not exist: ${args[0]}" }

val resDir = File(repoRoot, "app/src/main/res")
require(resDir.exists()) { "Resource directory does not exist: ${resDir.path}" }

val layoutDirs = resDir.listFiles { file -> file.isDirectory && file.name.startsWith("layout") }
?: emptyArray()
val xmlFiles = layoutDirs.flatMap { dir ->
dir.walkTopDown().filter { file -> file.extension == "xml" }.toList()
}

val builderFactory = DocumentBuilderFactory.newInstance()
val errors = mutableListOf<String>()

for (file in xmlFiles) {
val document = builderFactory.newDocumentBuilder().parse(file)
val textViewNodes = document.getElementsByTagName("TextView")

for (i in 0 until textViewNodes.length) {
val node = textViewNodes.item(i)
val attributes = node.attributes
val styleAttribute = attributes?.getNamedItem("style")?.nodeValue

if (styleAttribute == null || !styleAttribute.startsWith("@style/")) {
errors.add("${file.path}: TextView element is missing a centrally managed style.")
break
}
}
}

if (errors.isNotEmpty()) {
println("TextView Style Check FAILED:")
errors.forEach { println(it) }
throw Exception("Some TextView elements do not have centrally managed styles.")
} else {
println("TextView Style Check PASSED.")
}
}
Loading