#NEWLINE# def add_target( self , target , recursive = False ) : #NEWLINE# #INDENT# "Adds the classes and resources for a target to an open jar.\n\n      :param target: The target to add generated classes and resources for.\n      :param bool recursive: `True` to add classes and resources for the target's transitive\n        internal dependency closure.\n      :returns: `True` if the target contributed any files - manifest entries, classfiles or\n        resource files - to this jar.\n      :rtype: bool\n      " #NEWLINE# products_added = False #NEWLINE# classpath_products = self . _context . products . get_data ( 'runtime_classpath' ) #NEWLINE# if isinstance ( target , JvmBinary ) : #NEWLINE# #INDENT# self . _add_manifest_entries ( target , self . _manifest ) #NEWLINE# products_added = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( target , JavaAgent ) : #NEWLINE# #INDENT# self . _add_agent_manifest ( target , target_classpath . _manifest ) #NEWLINE# products_added = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if recursive : #NEWLINE# #INDENT# agents = [ t for t in target . closure ( ) if isinstance ( t , JavaAgent ) ] #NEWLINE# if ( len ( agents ) > 1 ) : #NEWLINE# #INDENT# raise TaskError ( 'Only 1 agent can be added to a jar, found {} for {}:\n\t{}' . format ( len ( agents ) , target . address . reference ( ) , '\n\t' . join ( ( agent . address . reference ( ) for agent in agents ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if agents : #NEWLINE# #INDENT# self . _add_agent_manifest ( agents [ 0 ] , self . _manifest ) #NEWLINE# products_added = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# targets = ( target . closure ( bfs = True ) if recursive else [ target ] ) #NEWLINE# if ( ( not recursive ) and target . has_resources ) : #NEWLINE# #INDENT# targets += target . resources #NEWLINE# #UNINDENT# target_classpath = ClasspathUtil . internal_classpath ( targets , classpath_products ) #NEWLINE# for entry in target_classpath : #NEWLINE# #INDENT# if ClasspathUtil . is_jar ( entry ) : #NEWLINE# #INDENT# self . _jar . writejar ( entry ) #NEWLINE# products_added = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ClasspathUtil . is_dir ( entry ) : #NEWLINE# #INDENT# for rel_file in ClasspathUtil . classpath_entries_contents ( [ entry ] ) : #NEWLINE# #INDENT# self . _jar . write ( os . path . join ( entry , rel_file ) , rel_file ) #NEWLINE# products_added = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return products_added