2424class GradleFile :
2525 def __init__ (self , content : str ) -> None :
2626 self .content = content
27+ self .configuration_used : str | None = None
28+ self .added_dependencies : list [str ] = []
2729
2830 def find_block (self , name : str ) -> tuple [int , int ] | None :
2931 pattern = re .compile (rf"(^\s*{ re .escape (name )} \s*\{{)" , re .MULTILINE )
@@ -88,6 +90,7 @@ def ensure_dependencies(self) -> None:
8890 raise SystemExit ("Unable to locate dependencies block in Gradle file" )
8991 existing_block = self .content [block [0 ]:block [1 ]]
9092 configuration = self ._select_configuration (existing_block , self .content )
93+ self .configuration_used = configuration
9194 insertion_point = block [1 ] - 1
9295 for coordinate in ANDROID_TEST_DEPENDENCIES :
9396 if self ._has_dependency (existing_block , coordinate ):
@@ -100,6 +103,7 @@ def ensure_dependencies(self) -> None:
100103 )
101104 insertion_point += len (combined )
102105 existing_block += combined
106+ self .added_dependencies .append (coordinate )
103107
104108 @staticmethod
105109 def _has_dependency (block : str , coordinate : str ) -> bool :
@@ -119,18 +123,38 @@ def _select_configuration(block: str, content: str) -> str:
119123 return "androidTestImplementation"
120124 if re .search (r"^\s*androidTestCompile\b" , content , re .MULTILINE ):
121125 return "androidTestCompile"
122- return "androidTestCompile"
126+ if re .search (r"^\s*implementation\b" , block , re .MULTILINE ) or re .search (
127+ r"^\s*implementation\b" , content , re .MULTILINE
128+ ):
129+ return "androidTestImplementation"
130+ if re .search (r"^\s*compile\b" , block , re .MULTILINE ) or re .search (
131+ r"^\s*compile\b" , content , re .MULTILINE
132+ ):
133+ return "androidTestCompile"
134+ return "androidTestImplementation"
123135
124136 def apply (self ) -> None :
125137 self .ensure_test_options ()
126138 self .ensure_instrumentation_runner ()
127139 self .ensure_dependencies ()
128140
141+ def summary (self ) -> str :
142+ configuration = self .configuration_used or "<unknown>"
143+ if self .added_dependencies :
144+ deps = ", " .join (self .added_dependencies )
145+ else :
146+ deps = "none (already present)"
147+ return (
148+ "Instrumentation dependency configuration: "
149+ f"{ configuration } ; added dependencies: { deps } "
150+ )
151+
129152
130153def process (path : pathlib .Path ) -> None :
131154 editor = GradleFile (path .read_text (encoding = "utf-8" ))
132155 editor .apply ()
133156 path .write_text (editor .content , encoding = "utf-8" )
157+ print (editor .summary ())
134158
135159
136160def main (argv : list [str ] | None = None ) -> int :
0 commit comments