<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import six <EOL> from twitter . common . collections import OrderedSet <EOL> from pants . backend . jvm . targets . jar_dependency import JarDependency <EOL> from pants . base . exceptions import TargetDefinitionException <EOL> from pants . base . payload import Payload <EOL> from pants . base . payload_field import ExcludesField , JarsField , PrimitiveField <EOL> from pants . build_graph . address import Address <EOL> from pants . build_graph . target import Target <EOL> class JarLibrary ( Target ) : <EOL> """<STR_LIT>""" <EOL> class WrongTargetTypeError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ExpectedAddressError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def __init__ ( self , payload = None , jars = None , managed_dependencies = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> jars = self . assert_list ( jars , expected_type = JarDependency , key_arg = '<STR_LIT>' ) <EOL> payload = payload or Payload ( ) <EOL> payload . add_fields ( { <EOL> '<STR_LIT>' : JarsField ( jars ) , <EOL> '<STR_LIT>' : ExcludesField ( [ ] ) , <EOL> '<STR_LIT>' : PrimitiveField ( managed_dependencies ) , <EOL> } ) <EOL> super ( JarLibrary , self ) . __init__ ( payload = payload , ** kwargs ) <EOL> if not jars : <EOL> raise TargetDefinitionException ( self , '<STR_LIT>' ) <EOL> self . add_labels ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ property <EOL> def managed_dependencies ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . payload . managed_dependencies : <EOL> address = Address . parse ( self . payload . managed_dependencies , <EOL> relative_to = self . address . spec_path ) <EOL> self . _build_graph . inject_address_closure ( address ) <EOL> return self . _build_graph . get_target ( address ) <EOL> return None <EOL> @ property <EOL> def jar_dependencies ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . payload . jars <EOL> @ property <EOL> def excludes ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . payload . excludes <EOL> @ staticmethod <EOL> def to_jar_dependencies ( relative_to , jar_library_specs , build_graph ) : <EOL> """<STR_LIT>""" <EOL> jar_deps = OrderedSet ( ) <EOL> for spec in jar_library_specs : <EOL> if not isinstance ( spec , six . string_types ) : <EOL> raise JarLibrary . ExpectedAddressError ( <EOL> "<STR_LIT>" <EOL> . format ( address = relative_to . spec , <EOL> found_class = type ( spec ) . __name__ ) ) <EOL> lookup = Address . parse ( spec , relative_to = relative_to . spec_path ) <EOL> target = build_graph . get_target ( lookup ) <EOL> if not isinstance ( target , JarLibrary ) : <EOL> raise JarLibrary . WrongTargetTypeError ( <EOL> "<STR_LIT>" <EOL> . format ( address = relative_to . spec , <EOL> spec = spec , <EOL> found_class = type ( target ) . __name__ ) ) <EOL> jar_deps . update ( target . jar_dependencies ) <EOL> return list ( jar_deps ) </s>
