def format_jar_library(cls, target_name, jar_deps, pom_file=None):
    """Given a list of jar dependencies, format a jar_library target.

    Exposed for testing.
    :param target_name: the target name for the jar_library.
    :param jar_deps: - <jar> dependency names to add to the jar_library.
    :returns: A jar_library declaration.
    :rtype: string
    """
    if not jar_deps:
      return ''

    # There is a bug in Target.jar_library.format(). See test_target_template.py
    #return Target.jar_library.format(
    #  name=target_name,
    #  jars=sorted(set(jar_deps)),
    #  symbols=pom_file.properties if pom_file else None,
    #  file_name=pom_file.path if pom_file else None,
    #)
    jar_library = dedent('''
        jar_library(name='{name}',
          jars=[{jars}
          ],
        )
      ''').format(name=target_name,
                  jars=','.join('\n{}{}'.format(' '*4, jar) for jar in sorted(set(jar_deps))))
    if pom_file:
      jar_library = GenerationUtils.symbol_substitution(pom_file.properties, jar_library)
    return GenerationUtils.autoindent(jar_library)
        def format_body(self):
            """The body of the target (ie jar_library(...)) for inclusion in a build file.

      If this library has no body, this returns the emptystring.
      """
            if not self.has_body:
                return ""
            management = ""
            if self.managed_dependencies:
                management = "\n  managed_dependencies=':{}',".format(self.managed_dependencies.name)
            return GenerationUtils.autoindent(
                ThirdPartyBuildGenerator._substitute_symbols(
                    dedent(
                        """
        jar_library(name='{name}',
          jars=[
            {jars},
          ],{management}
        )
      """
                    ).format(
                        name=self.name,
                        jars=",\n    ".join(jar.format() for jar in self.artifacts),
                        management=management,
                    )
                )
            )
        def format_body(self):
            """The body of the target (ie jar_library(...)) for inclusion in a build file.

      If this library has no body, this returns the emptystring.
      """
            if not self.has_body:
                return ''
            management = ''
            if self.managed_dependencies:
                management = "\n  managed_dependencies=':{}',".format(
                    self.managed_dependencies.name)
            return GenerationUtils.autoindent(
                ThirdPartyBuildGenerator._substitute_symbols(
                    dedent('''
        jar_library(name='{name}',
          jars=[
            {jars},
          ],{management}
        )
      ''').format(
                        name=self.name,
                        jars=',\n    '.join(jar.format()
                                            for jar in self.artifacts),
                        management=management,
                    )))
   def format(self):
       """Generates a formatted string for inclusion in a BUILD file."""
       references = sorted(self._formatted_jars())
       return GenerationUtils.autoindent(
           ThirdPartyBuildGenerator._substitute_symbols(
               dedent('''
   # {type_explanation}
   managed_jar_{type_}(name='{name}',
     artifacts=[{artifacts}
     ],{parent}
   )
 ''').format(
                   name=self.name,
                   artifacts=''.join('\n    {},'.format(s)
                                     for s in references),
                   parent='' if not self.parent else
                   "\n  dependencies=[':{}'],".format(self.parent),
                   type_='libraries'
                   if self.generate_libraries else 'dependencies',
                   type_explanation=self._type_explanation,
               )))
   def format(self):
       """Generates a formatted string for inclusion in a BUILD file."""
       references = sorted(self._formatted_jars())
       return GenerationUtils.autoindent(
           ThirdPartyBuildGenerator._substitute_symbols(
               dedent(
                   """
   # {type_explanation}
   managed_jar_{type_}(name='{name}',
     artifacts=[{artifacts}
     ],{parent}
   )
 """
               ).format(
                   name=self.name,
                   artifacts="".join("\n    {},".format(s) for s in references),
                   parent="" if not self.parent else "\n  dependencies=[':{}'],".format(self.parent),
                   type_="libraries" if self.generate_libraries else "dependencies",
                   type_explanation=self._type_explanation,
               )
           )
       )