コード例 #1
0
def _DictForPath(path, use_proxy_hash=False):
    with open(path) as f:
        contents = jni_generator.RemoveComments(f.read())
        if '@JniIgnoreNatives' in contents:
            return None

    fully_qualified_class = jni_generator.ExtractFullyQualifiedJavaClassName(
        path, contents)
    natives = jni_generator.ExtractNatives(contents, 'long')

    natives += jni_generator.ProxyHelpers.ExtractStaticProxyNatives(
        fully_qualified_class=fully_qualified_class,
        contents=contents,
        ptr_type='long',
        use_hash=use_proxy_hash)
    if len(natives) == 0:
        return None
    namespace = jni_generator.ExtractJNINamespace(contents)
    jni_params = jni_generator.JniParams(fully_qualified_class)
    jni_params.ExtractImportsAndInnerClasses(contents)
    is_main_dex = jni_generator.IsMainDexJavaClass(contents)
    header_generator = HeaderGenerator(namespace, fully_qualified_class,
                                       natives, jni_params, is_main_dex,
                                       use_proxy_hash)
    return header_generator.Generate()
コード例 #2
0
def _DictForPath(path):
    with open(path) as f:
        contents = jni_generator.RemoveComments(f.read())
    natives = jni_generator.ExtractNatives(contents, 'long')
    if len(natives) == 0:
        return None
    namespace = jni_generator.ExtractJNINamespace(contents)
    fully_qualified_class = jni_generator.ExtractFullyQualifiedJavaClassName(
        path, contents)
    jni_params = jni_generator.JniParams(fully_qualified_class)
    jni_params.ExtractImportsAndInnerClasses(contents)
    main_dex = jni_generator.IsMainDexJavaClass(contents)
    header_generator = HeaderGenerator(namespace, fully_qualified_class,
                                       natives, jni_params, main_dex)
    return header_generator.Generate()
コード例 #3
0
def GenerateJNIHeader(java_file_paths, output_file, args):
    """Generate a header file including two registration functions.

  Forward declares all JNI registration functions created by jni_generator.py.
  Calls the functions in RegisterMainDexNatives() if they are main dex. And
  calls them in RegisterNonMainDexNatives() if they are non-main dex.

  Args:
      java_file_paths: A list of java file paths.
      output_file: A relative path to output file.
      args: All input arguments.
  """
    registration_dict = {}
    # Sort the file list to make sure the order is deterministic.
    java_file_paths.sort()
    for path in java_file_paths:
        if path in args.no_register_java:
            continue
        with open(path) as f:
            contents = jni_generator.RemoveComments(f.read())
        natives = jni_generator.ExtractNatives(contents, 'long')
        if len(natives) == 0:
            continue
        namespace = jni_generator.ExtractJNINamespace(contents)
        fully_qualified_class = jni_generator.ExtractFullyQualifiedJavaClassName(
            path, contents)
        jni_params = jni_generator.JniParams(fully_qualified_class)
        jni_params.ExtractImportsAndInnerClasses(contents)
        main_dex = jni_generator.IsMainDexJavaClass(contents)
        header_generator = HeaderGenerator(namespace, fully_qualified_class,
                                           natives, jni_params,
                                           registration_dict, main_dex)
        header_generator.AddContent()

    header_content = CreateFromDict(registration_dict)
    if output_file:
        jni_generator.WriteOutput(output_file, header_content)
    else:
        print header_content
コード例 #4
0
def GenerateJNIHeader(java_file_paths, output_file, args):
  """Generate a header file including two registration functions.

  Forward declares all JNI registration functions created by jni_generator.py.
  Calls the functions in RegisterMainDexNatives() if they are main dex. And
  calls them in RegisterNonMainDexNatives() if they are non-main dex.

  Args:
      java_file_paths: A list of java file paths.
      output_file: A relative path to output file.
      args: All input arguments.
  """
  registration_dict = {
      'FORWARD_DECLARATIONS': '',
      'REGISTER_MAIN_DEX_NATIVES': '',
      'REGISTER_NON_MAIN_DEX_NATIVES': ''
  }
  # Sort the file list to make sure the order is deterministic.
  java_file_paths.sort()
  for path in java_file_paths:
    if path in args.no_register_java:
      continue
    with open(path) as f:
      contents = f.read()
    natives = jni_generator.ExtractNatives(contents, 'long')
    if len(natives) == 0:
      continue
    fully_qualified_class = jni_generator.ExtractFullyQualifiedJavaClassName(
        path, contents)
    main_dex = jni_generator.IsMainDexJavaClass(contents)
    header_generator = HeaderGenerator(
        fully_qualified_class, registration_dict, main_dex)
    registration_dict = header_generator.GetContent()

  header_content = CreateFromDict(registration_dict)
  if output_file:
    jni_generator.WriteOutput(output_file, header_content)
  else:
    print header_content