gn2bp: mark java targets as java_group

According to the docs, java target names are (somewhat) guaranteed to end in
_java. There are some other variations that are allowlisted, though it
is currently unclear if those need to be supported for our purposes.

Test: //net:net
Change-Id: I0647dac6a078790e23509d437628aed0d8d62f77
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 686003c..d706bd8 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -20,6 +20,7 @@
 import errno
 import filecmp
 import json
+import logging as log
 import os
 import re
 import shutil
@@ -185,6 +186,13 @@
 
     return ' '.join(formatted_flags)
 
+  def _is_java_target(self, target):
+    # Per https://chromium.googlesource.com/chromium/src/build/+/HEAD/android/docs/java_toolchain.md
+    # java target names must end in "_java".
+    # TODO: There are some other possible variations we might need to support.
+    return re.match('.*_java$', target.name)
+
+
   def get_target(self, gn_target_name):
     """Returns a Target object from the fully qualified GN target name.
 
@@ -243,6 +251,11 @@
     elif target.type == 'copy':
       # TODO: copy rules are not currently implemented.
       self.actions[gn_target_name] = target
+    elif target.type == 'group' and self._is_java_target(target):
+      # java_group identifies the group target generated by the android_library
+      # or java_library template. A java_group must not be added as a dependency, but sources are collected
+      log.debug('Found java target %s', target.name)
+      target.type = 'java_group'
 
     # Default for 'public' is //* - all headers in 'sources' are public.
     # TODO(primiano): if a 'public' section is specified (even if empty), then