def jar(self, jvm_targets, genmap, add_genjar): for target in jvm_targets: generated = genmap.get(target) if generated or has_resources(target): jar_name = '%s.jar' % jarname(target) add_genjar(target, jar_name) jar_path = os.path.join(self._output_dir, jar_name) with self.create_jar(target, jar_path) as jarfile: if generated: for basedir, classfiles in generated.items(): for classfile in classfiles: jarfile.write(os.path.join(basedir, classfile), classfile) if has_resources(target): resources_genmap = self.context.products.get( 'resources') if resources_genmap: for resources in target.resources: resource_map = resources_genmap.get(resources) if resource_map: for basedir, files in resource_map.items(): for resource in files: jarfile.write( os.path.join( basedir, resource), resource)
def sourcejar(self, jvm_targets, add_genjar): for target in jvm_targets: jar_name = '%s-sources.jar' % jarname(target) add_genjar(target, jar_name) jar_path = os.path.join(self._output_dir, jar_name) with self.create_jar(target, jar_path) as zip: for source in target.sources: zip.write(os.path.join(target.target_base, source), source) if has_resources(target): for resources in target.resources: for resource in resources.sources: zip.write(os.path.join(get_buildroot(), resources.target_base, resource), resource)
def jar(self, jvm_targets, genmap, add_genjar): for target in jvm_targets: generated = genmap.get(target) if generated or has_resources(target): jar_name = '%s.jar' % jarname(target) add_genjar(target, jar_name) jar_path = os.path.join(self._output_dir, jar_name) with self.create_jar(target, jar_path) as zip: if generated: for basedir, classfiles in generated.items(): for classfile in classfiles: zip.write(os.path.join(basedir, classfile), classfile) if has_resources(target): resources_genmap = self.context.products.get('resources') if resources_genmap: for resources in target.resources: resource_map = resources_genmap.get(resources) if resource_map: for basedir, files in resource_map.items(): for resource in files: zip.write(os.path.join(basedir, resource), resource)
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target)) if has_resources(target): resources_by_basedir = defaultdict(set) for resources in target.resources: resources_by_basedir[resources.target_base].update( resources.sources) for basedir, resources in resources_by_basedir.items(): self.resource_extensions.update( Project.extract_resource_extensions(resources)) configure_source_sets(basedir, resources, is_test=False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test=test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target( target) and target_dirset.intersection( find_source_basedirs(target)) return filter( is_sibling, [Target.get(a) for a in candidates if a != target.address])
def configure_target(target): if target not in analyzed: analyzed.add(target) self.has_scala = not self.skip_scala and (self.has_scala or is_scala(target)) if has_resources(target): resources_by_basedir = defaultdict(set) for resources in target.resources: resources_by_basedir[resources.target_base].update(resources.sources) for basedir, resources in resources_by_basedir.items(): self.resource_extensions.update(Project.extract_resource_extensions(resources)) configure_source_sets(basedir, resources, is_test=False) if target.sources: test = is_test(target) self.has_tests = self.has_tests or test configure_source_sets(target.target_base, target.sources, is_test = test) # Other BUILD files may specify sources in the same directory as this target. Those BUILD # files might be in parent directories (globs('a/b/*.java')) or even children directories if # this target globs children as well. Gather all these candidate BUILD files to test for # sources they own that live in the directories this targets sources live in. target_dirset = find_source_basedirs(target) candidates = Target.get_all_addresses(target.address.buildfile) for ancestor in target.address.buildfile.ancestors(): candidates.update(Target.get_all_addresses(ancestor)) for sibling in target.address.buildfile.siblings(): candidates.update(Target.get_all_addresses(sibling)) for descendant in target.address.buildfile.descendants(): candidates.update(Target.get_all_addresses(descendant)) def is_sibling(target): return source_target(target) and target_dirset.intersection(find_source_basedirs(target)) return filter(is_sibling, [ Target.get(a) for a in candidates if a != target.address ])
def extract_resources(target): return target.resources if has_resources(target) else ()