gn2bp: Prevent collection of source files for testing modules

Test: none
Change-Id: I72a2a23021b01bbf7a78fd458405340349503ea5
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index e5e714e..9fcbcf7 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -323,7 +323,7 @@
 
     return self.all_targets[label_without_toolchain(gn_target_name)]
 
-  def parse_gn_desc(self, gn_desc, gn_target_name, java_group_name=None):
+  def parse_gn_desc(self, gn_desc, gn_target_name, java_group_name=None, is_test_target=False):
     """Parses a gn desc tree and resolves all target dependencies.
 
         It bubbles up variables from source_set dependencies as described in the
@@ -416,7 +416,7 @@
 
     # Recurse in dependencies.
     for gn_dep_name in desc.get('deps', []):
-      dep = self.parse_gn_desc(gn_desc, gn_dep_name, java_group_name)
+      dep = self.parse_gn_desc(gn_desc, gn_dep_name, java_group_name, is_test_target)
       if dep.type == 'proto_library':
         target.proto_deps.add(dep.name)
         target.transitive_proto_deps.add(dep.name)
@@ -466,7 +466,11 @@
         if dep.name.endswith('__compile_java'):
           log.debug('Adding java sources for %s', dep.name)
           java_srcs = [src for src in dep.inputs if _is_java_source(src)]
-          self.java_sources[java_group_name].update(java_srcs)
+          if not is_test_target:
+            # TODO(aymanm): Fix collecting sources for testing modules for java.
+            # Don't collect java source files for test targets.
+            # We only need a specific set of java sources which are hardcoded in gen_android_bp
+            self.java_sources[java_group_name].update(java_srcs)
       if dep.type in ["action"] and target.type == "java_group":
         # GN uses an action to compile aidl files. However, this is not needed in soong
         # as soong can directly have .aidl files in srcs. So adding .aidl files to the java_sources.
@@ -475,7 +479,10 @@
           self.java_sources[java_group_name].update(dep.arch[arch].sources)
           self.aidl_local_include_dirs.update(_extract_includes_from_aidl_args(dep.arch[arch].args))
         else:
-          self.java_actions[java_group_name].add(dep.name)
+          if not is_test_target:
+            # TODO(aymanm): Fix collecting actions for testing modules for java.
+            # Don't collect java actions for test targets.
+            self.java_actions[java_group_name].add(dep.name)
     return target
 
   def get_proto_exports(self, proto_desc):