<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import logging <EOL> import os <EOL> import shutil <EOL> from collections import defaultdict <EOL> from pathspec import PathSpec <EOL> from pathspec . gitignore import GitIgnorePattern <EOL> from twitter . common . collections . orderedset import OrderedSet <EOL> from pants . backend . jvm . subsystems . scala_platform import ScalaPlatform <EOL> from pants . backend . jvm . targets . annotation_processor import AnnotationProcessor <EOL> from pants . backend . jvm . targets . scala_library import ScalaLibrary <EOL> from pants . backend . jvm . tasks . classpath_products import ClasspathProducts <EOL> from pants . backend . jvm . tasks . ivy_task_mixin import IvyTaskMixin <EOL> from pants . backend . jvm . tasks . nailgun_task import NailgunTask <EOL> from pants . base . build_environment import get_buildroot <EOL> from pants . base . build_file import BuildFile <EOL> from pants . base . exceptions import TaskError <EOL> from pants . binaries import binary_util <EOL> from pants . build_graph . address import BuildFileAddress <EOL> from pants . build_graph . resources import Resources <EOL> from pants . util . dirutil import safe_mkdir , safe_walk <EOL> logger = logging . getLogger ( __name__ ) <EOL> def is_scala ( target ) : <EOL> return target . has_sources ( '<STR_LIT>' ) or target . is_scala <EOL> def is_java ( target ) : <EOL> return target . has_sources ( '<STR_LIT>' ) or target . is_java <EOL> class IdeGen ( IvyTaskMixin , NailgunTask ) : <EOL> @ classmethod <EOL> def subsystem_dependencies ( cls ) : <EOL> return super ( IdeGen , cls ) . subsystem_dependencies ( ) + ( ScalaPlatform , ) <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( IdeGen , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( cls . options_scope ) ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , default = True , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = int , default = <NUM_LIT:7> , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , default = None , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , default = True , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = int , default = <NUM_LIT> , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , default = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , default = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = list , advanced = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = list , advanced = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = list , advanced = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = list , advanced = True , <EOL> help = '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = list , advanced = True , <EOL> help = '<STR_LIT>' ) <EOL> @ classmethod <EOL> def prepare ( cls , options , round_manager ) : <EOL> super ( IdeGen , cls ) . prepare ( options , round_manager ) <EOL> if options . python : <EOL> round_manager . require ( '<STR_LIT>' ) <EOL> if options . java : <EOL> round_manager . require ( '<STR_LIT>' ) <EOL> if options . scala : <EOL> round_manager . require ( '<STR_LIT>' ) <EOL> class Error ( TaskError ) : <EOL> """<STR_LIT>""" <EOL> class TargetUtil ( object ) : <EOL> def __init__ ( self , context ) : <EOL> self . context = context <EOL> @ property <EOL> def build_graph ( self ) : <EOL> return self . context . build_graph <EOL> def get_all_addresses ( self , buildfile ) : <EOL> return set ( self . context . address_mapper . addresses_in_spec_path ( buildfile . spec_path ) ) <EOL> def get ( self , address ) : <EOL> self . context . build_graph . inject_address_closure ( address ) <EOL> return self . context . build_graph . get_target ( address ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( IdeGen , self ) . __init__ ( * args , ** kwargs ) <EOL> self . project_name = self . get_options ( ) . project_name <EOL> self . python = self . get_options ( ) . python <EOL> self . skip_java = not self . get_options ( ) . java <EOL> self . skip_scala = not self . get_options ( ) . scala <EOL> self . use_source_root = self . get_options ( ) . use_source_root <EOL> self . java_language_level = self . get_options ( ) . java_language_level <EOL> if self . get_options ( ) . java_jdk_name : <EOL> self . java_jdk = self . get_options ( ) . java_jdk_name <EOL> else : <EOL> self . java_jdk = '<STR_LIT>' . format ( self . java_language_level ) <EOL> if self . get_options ( ) . project_dir : <EOL> self . gen_project_workdir = os . path . abspath ( <EOL> os . path . join ( self . get_options ( ) . project_dir , self . project_name ) ) <EOL> else : <EOL> self . gen_project_workdir = os . path . abspath ( <EOL> os . path . join ( self . workdir , self . __class__ . __name__ , self . project_name ) ) <EOL> self . cwd = ( <EOL> os . path . abspath ( self . get_options ( ) . project_cwd ) if <EOL> self . get_options ( ) . project_cwd else self . gen_project_workdir <EOL> ) <EOL> self . intransitive = self . get_options ( ) . intransitive <EOL> self . debug_port = self . get_options ( ) . debug_port <EOL> def resolve_jars ( self , targets ) : <EOL> executor = self . create_java_executor ( ) <EOL> confs = [ '<STR_LIT:default>' ] <EOL> if self . get_options ( ) . source_jars : <EOL> confs . append ( '<STR_LIT>' ) <EOL> if self . get_options ( ) . javadoc_jars : <EOL> confs . append ( '<STR_LIT>' ) <EOL> compile_classpath = ClasspathProducts ( self . get_options ( ) . pants_workdir ) <EOL> self . resolve ( executor = executor , <EOL> targets = targets , <EOL> classpath_products = compile_classpath , <EOL> confs = confs ) <EOL> return compile_classpath <EOL> def _prepare_project ( self ) : <EOL> targets , self . _project = self . configure_project ( <EOL> self . context . targets ( ) , <EOL> self . debug_port ) <EOL> self . configure_compile_context ( targets ) <EOL> def configure_project ( self , targets , debug_port ) : <EOL> jvm_targets = [ t for t in targets if t . has_label ( '<STR_LIT>' ) or t . has_label ( '<STR_LIT>' ) or <EOL> isinstance ( t , Resources ) ] <EOL> if self . intransitive : <EOL> jvm_targets = set ( self . context . target_roots ) . intersection ( jvm_targets ) <EOL> build_ignore_patterns = self . context . options . for_global_scope ( ) . ignore_patterns or [ ] <EOL> project = Project ( self . project_name , <EOL> self . python , <EOL> self . skip_java , <EOL> self . skip_scala , <EOL> self . use_source_root , <EOL> get_buildroot ( ) , <EOL> debug_port , <EOL> self . context , <EOL> jvm_targets , <EOL> not self . intransitive , <EOL> self . TargetUtil ( self . context ) , <EOL> PathSpec . from_lines ( GitIgnorePattern , build_ignore_patterns ) ) <EOL> if self . python : <EOL> python_source_paths = self . get_options ( ) . python_source_paths <EOL> python_test_paths = self . get_options ( ) . python_test_paths <EOL> python_lib_paths = self . get_options ( ) . python_lib_paths <EOL> project . configure_python ( python_source_paths , python_test_paths , python_lib_paths ) <EOL> extra_source_paths = self . get_options ( ) . extra_jvm_source_paths <EOL> extra_test_paths = self . get_options ( ) . extra_jvm_test_paths <EOL> all_targets = project . configure_jvm ( extra_source_paths , extra_test_paths ) <EOL> return all_targets , project <EOL> def configure_compile_context ( self , targets ) : <EOL> """<STR_LIT>""" <EOL> def is_cp ( target ) : <EOL> return ( <EOL> target . is_codegen or <EOL> isinstance ( target , AnnotationProcessor ) or <EOL> ( self . skip_java and is_java ( target ) ) or <EOL> ( self . skip_scala and is_scala ( target ) ) or <EOL> ( self . intransitive and target not in self . context . target_roots ) <EOL> ) <EOL> jars = OrderedSet ( ) <EOL> excludes = OrderedSet ( ) <EOL> compiles = OrderedSet ( ) <EOL> def prune ( target ) : <EOL> if target . is_jvm : <EOL> if target . excludes : <EOL> excludes . update ( target . excludes ) <EOL> jars . update ( jar for jar in target . jar_dependencies ) <EOL> if is_cp ( target ) : <EOL> target . walk ( compiles . add ) <EOL> for target in targets : <EOL> target . walk ( prune ) <EOL> self . context . _replace_targets ( compiles ) <EOL> self . jar_dependencies = jars <EOL> self . context . log . debug ( '<STR_LIT>' . format ( <EOL> '<STR_LIT>' . join ( str ( t ) for t in self . context . targets ( ) ) <EOL> ) ) <EOL> def map_internal_jars ( self , targets ) : <EOL> internal_jar_dir = os . path . join ( self . gen_project_workdir , '<STR_LIT>' ) <EOL> safe_mkdir ( internal_jar_dir , clean = True ) <EOL> internal_source_jar_dir = os . path . join ( self . gen_project_workdir , '<STR_LIT>' ) <EOL> safe_mkdir ( internal_source_jar_dir , clean = True ) <EOL> internal_jars = self . context . products . get ( '<STR_LIT>' ) <EOL> internal_source_jars = self . context . products . get ( '<STR_LIT>' ) <EOL> for target in targets : <EOL> mappings = internal_jars . get ( target ) <EOL> if mappings : <EOL> for base , jars in mappings . items ( ) : <EOL> if len ( jars ) != <NUM_LIT:1> : <EOL> raise IdeGen . Error ( '<STR_LIT>' . format ( target , jars ) ) <EOL> jar = jars [ <NUM_LIT:0> ] <EOL> cp_jar = os . path . join ( internal_jar_dir , jar ) <EOL> shutil . copy ( os . path . join ( base , jar ) , cp_jar ) <EOL> cp_source_jar = None <EOL> mappings = internal_source_jars . get ( target ) <EOL> if mappings : <EOL> for base , jars in mappings . items ( ) : <EOL> if len ( jars ) != <NUM_LIT:1> : <EOL> raise IdeGen . Error ( <EOL> '<STR_LIT>' . format ( target , jars ) <EOL> ) <EOL> jar = jars [ <NUM_LIT:0> ] <EOL> cp_source_jar = os . path . join ( internal_source_jar_dir , jar ) <EOL> shutil . copy ( os . path . join ( base , jar ) , cp_source_jar ) <EOL> self . _project . internal_jars . add ( ClasspathEntry ( cp_jar , source_jar = cp_source_jar ) ) <EOL> def map_external_jars ( self , targets ) : <EOL> external_jar_dir = os . path . join ( self . gen_project_workdir , '<STR_LIT>' ) <EOL> safe_mkdir ( external_jar_dir , clean = True ) <EOL> external_source_jar_dir = os . path . join ( self . gen_project_workdir , '<STR_LIT>' ) <EOL> safe_mkdir ( external_source_jar_dir , clean = True ) <EOL> external_javadoc_jar_dir = os . path . join ( self . gen_project_workdir , '<STR_LIT>' ) <EOL> safe_mkdir ( external_javadoc_jar_dir , clean = True ) <EOL> classpath_products = self . resolve_jars ( targets ) or ClasspathProducts ( self . get_options ( ) . pants_workdir ) <EOL> cp_entry_by_classifier_by_orgname = defaultdict ( lambda : defaultdict ( dict ) ) <EOL> for conf , jar_entry in classpath_products . get_artifact_classpath_entries_for_targets ( targets ) : <EOL> coord = ( jar_entry . coordinate . org , jar_entry . coordinate . name ) <EOL> classifier = jar_entry . coordinate . classifier <EOL> cp_entry_by_classifier_by_orgname [ coord ] [ classifier ] = jar_entry <EOL> def copy_jar ( cp_entry , dest_dir ) : <EOL> if not cp_entry : <EOL> return None <EOL> cp_jar = os . path . join ( dest_dir , os . path . basename ( cp_entry . path ) ) <EOL> shutil . copy ( cp_entry . path , cp_jar ) <EOL> return cp_jar <EOL> for cp_entry_by_classifier in cp_entry_by_classifier_by_orgname . values ( ) : <EOL> primary_jar = copy_jar ( cp_entry_by_classifier . pop ( None , None ) , external_jar_dir ) <EOL> sources_jar = copy_jar ( cp_entry_by_classifier . pop ( '<STR_LIT>' , None ) , external_source_jar_dir ) <EOL> javadoc_jar = copy_jar ( cp_entry_by_classifier . pop ( '<STR_LIT>' , None ) , external_javadoc_jar_dir ) <EOL> if primary_jar : <EOL> self . _project . external_jars . add ( ClasspathEntry ( jar = primary_jar , <EOL> source_jar = sources_jar , <EOL> javadoc_jar = javadoc_jar ) ) <EOL> for jar_entry in cp_entry_by_classifier . values ( ) : <EOL> extra_jar = copy_jar ( jar_entry , external_jar_dir ) <EOL> self . _project . external_jars . add ( ClasspathEntry ( extra_jar ) ) <EOL> def execute ( self ) : <EOL> """<STR_LIT>""" <EOL> targets = self . context . targets ( ) <EOL> self . _prepare_project ( ) <EOL> if self . context . options . is_known_scope ( '<STR_LIT>' ) : <EOL> checkstyle_classpath = self . tool_classpath ( '<STR_LIT>' , scope = '<STR_LIT>' ) <EOL> else : <EOL> checkstyle_classpath = [ ] <EOL> if self . skip_scala : <EOL> scalac_classpath = [ ] <EOL> else : <EOL> scalac_classpath = ScalaPlatform . global_instance ( ) . compiler_classpath ( self . context . products ) <EOL> self . _project . set_tool_classpaths ( checkstyle_classpath , scalac_classpath ) <EOL> self . map_internal_jars ( targets ) <EOL> self . map_external_jars ( targets ) <EOL> idefile = self . generate_project ( self . _project ) <EOL> if idefile : <EOL> binary_util . ui_open ( idefile ) <EOL> def generate_project ( self , project ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> class ClasspathEntry ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , jar , source_jar = None , javadoc_jar = None ) : <EOL> self . jar = jar <EOL> self . source_jar = source_jar <EOL> self . javadoc_jar = javadoc_jar <EOL> class SourceSet ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root_dir , source_base , path , is_test = False , resources_only = False ) : <EOL> """<STR_LIT>""" <EOL> self . root_dir = root_dir <EOL> self . source_base = source_base <EOL> self . path = path <EOL> self . is_test = is_test <EOL> self . resources_only = resources_only <EOL> self . _excludes = [ ] <EOL> @ property <EOL> def excludes ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _excludes <EOL> @ property <EOL> def _key_tuple ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . root_dir , self . source_base , self . path ) <EOL> def __str__ ( self ) : <EOL> return str ( self . _key_tuple ) <EOL> def __eq__ ( self , other ) : <EOL> return self . _key_tuple == other . _key_tuple <EOL> def __cmp__ ( self , other ) : <EOL> return cmp ( self . _key_tuple , other . _key_tuple ) <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _key_tuple ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( <EOL> self . root_dir , <EOL> self . source_base , <EOL> self . path , <EOL> self . is_test , <EOL> self . resources_only , <EOL> self . _excludes ) <EOL> class Project ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def extract_resource_extensions ( resources ) : <EOL> """<STR_LIT>""" <EOL> if resources : <EOL> for resource in resources : <EOL> _ , ext = os . path . splitext ( resource ) <EOL> yield ext <EOL> @ staticmethod <EOL> def _collapse_by_source_root ( source_roots , source_sets ) : <EOL> """<STR_LIT>""" <EOL> collapsed_source_sets = [ ] <EOL> for source in source_sets : <EOL> query = os . path . join ( source . source_base , source . path ) <EOL> source_root = source_roots . find_by_path ( query ) <EOL> if not source_root : <EOL> collapsed_source_sets . append ( source ) <EOL> else : <EOL> collapsed_source_sets . append ( SourceSet ( source . root_dir , source_root . path , "<STR_LIT>" , <EOL> is_test = source . is_test , <EOL> resources_only = source . resources_only ) ) <EOL> return collapsed_source_sets <EOL> def __init__ ( self , name , has_python , skip_java , skip_scala , use_source_root , root_dir , <EOL> debug_port , context , targets , transitive , target_util , build_ignore_patterns = None ) : <EOL> """<STR_LIT>""" <EOL> self . context = context <EOL> self . target_util = target_util <EOL> self . name = name <EOL> self . root_dir = root_dir <EOL> self . targets = OrderedSet ( targets ) <EOL> self . transitive = transitive <EOL> self . sources = [ ] <EOL> self . py_sources = [ ] <EOL> self . py_libs = [ ] <EOL> self . resource_extensions = set ( ) <EOL> self . has_python = has_python <EOL> self . skip_java = skip_java <EOL> self . skip_scala = skip_scala <EOL> self . use_source_root = use_source_root <EOL> self . has_scala = False <EOL> self . has_tests = False <EOL> self . debug_port = debug_port <EOL> self . internal_jars = OrderedSet ( ) <EOL> self . external_jars = OrderedSet ( ) <EOL> self . build_ignore_patterns = build_ignore_patterns <EOL> def configure_python ( self , source_paths , test_paths , lib_paths ) : <EOL> self . py_sources . extend ( SourceSet ( get_buildroot ( ) , root , None ) for root in source_paths ) <EOL> self . py_sources . extend ( SourceSet ( get_buildroot ( ) , root , None , is_test = True ) for root in test_paths ) <EOL> for root in lib_paths : <EOL> for path in os . listdir ( os . path . join ( get_buildroot ( ) , root ) ) : <EOL> if os . path . isdir ( os . path . join ( get_buildroot ( ) , root , path ) ) or path . endswith ( '<STR_LIT>' ) : <EOL> self . py_libs . append ( SourceSet ( get_buildroot ( ) , root , path , is_test = False ) ) <EOL> @ classmethod <EOL> def dedup_sources ( cls , source_set_list ) : <EOL> """<STR_LIT>""" <EOL> deduped_sources = set ( filter ( lambda s : not s . resources_only and s . is_test , <EOL> source_set_list ) ) <EOL> deduped_sources . update ( filter ( lambda s : not s . resources_only , <EOL> source_set_list ) ) <EOL> deduped_sources . update ( filter ( lambda s : s . resources_only and not s . is_test , <EOL> source_set_list ) ) <EOL> deduped_sources . update ( filter ( lambda s : s . resources_only and s . is_test , <EOL> source_set_list ) ) <EOL> return sorted ( list ( deduped_sources ) ) <EOL> def configure_jvm ( self , extra_source_paths , extra_test_paths ) : <EOL> """<STR_LIT>""" <EOL> analyzed_targets = OrderedSet ( ) <EOL> targeted = set ( ) <EOL> def relative_sources ( target ) : <EOL> sources = target . payload . sources . relative_to_buildroot ( ) <EOL> return [ os . path . relpath ( source , target . target_base ) for source in sources ] <EOL> def source_target ( target ) : <EOL> result = ( ( self . transitive or target in self . targets ) and <EOL> target . has_sources ( ) and <EOL> ( not ( self . skip_java and is_java ( target ) ) and <EOL> not ( self . skip_scala and is_scala ( target ) ) ) ) <EOL> return result <EOL> def configure_source_sets ( relative_base , sources , is_test = False , resources_only = False ) : <EOL> absolute_base = os . path . join ( self . root_dir , relative_base ) <EOL> paths = set ( [ os . path . dirname ( source ) for source in sources ] ) <EOL> for path in paths : <EOL> absolute_path = os . path . join ( absolute_base , path ) <EOL> targeted . add ( absolute_path ) <EOL> source_set = SourceSet ( self . root_dir , relative_base , path , <EOL> is_test = is_test , resources_only = resources_only ) <EOL> self . sources . append ( source_set ) <EOL> def find_source_basedirs ( target ) : <EOL> dirs = set ( ) <EOL> if source_target ( target ) : <EOL> absolute_base = os . path . join ( self . root_dir , target . target_base ) <EOL> dirs . update ( [ os . path . join ( absolute_base , os . path . dirname ( source ) ) <EOL> for source in relative_sources ( target ) ] ) <EOL> return dirs <EOL> def configure_target ( target ) : <EOL> if target not in analyzed_targets : <EOL> analyzed_targets . add ( target ) <EOL> self . has_scala = not self . skip_scala and ( self . has_scala or is_scala ( target ) ) <EOL> if isinstance ( target , ScalaLibrary ) : <EOL> for java_source in target . java_sources : <EOL> configure_target ( java_source ) <EOL> if target . has_resources : <EOL> resources_by_basedir = defaultdict ( set ) <EOL> for resources in target . resources : <EOL> analyzed_targets . add ( resources ) <EOL> resources_by_basedir [ resources . target_base ] . update ( relative_sources ( resources ) ) <EOL> for basedir , resources in resources_by_basedir . items ( ) : <EOL> self . resource_extensions . update ( Project . extract_resource_extensions ( resources ) ) <EOL> configure_source_sets ( basedir , resources , is_test = target . is_test , <EOL> resources_only = True ) <EOL> if target . has_sources ( ) : <EOL> test = target . is_test <EOL> self . has_tests = self . has_tests or test <EOL> base = target . target_base <EOL> configure_source_sets ( base , relative_sources ( target ) , is_test = test , <EOL> resources_only = isinstance ( target , Resources ) ) <EOL> target_dirset = find_source_basedirs ( target ) <EOL> if not isinstance ( target . address , BuildFileAddress ) : <EOL> return [ ] <EOL> candidates = OrderedSet ( ) <EOL> build_file = target . address . build_file <EOL> dir_relpath = os . path . dirname ( build_file . relpath ) <EOL> for descendant in BuildFile . scan_build_files ( build_file . project_tree , dir_relpath , <EOL> build_ignore_patterns = self . build_ignore_patterns ) : <EOL> candidates . update ( self . target_util . get_all_addresses ( descendant ) ) <EOL> if not self . _is_root_relpath ( dir_relpath ) : <EOL> ancestors = self . _collect_ancestor_build_files ( build_file . project_tree , os . path . dirname ( dir_relpath ) , <EOL> self . build_ignore_patterns ) <EOL> for ancestor in ancestors : <EOL> candidates . update ( self . target_util . get_all_addresses ( ancestor ) ) <EOL> def is_sibling ( target ) : <EOL> return source_target ( target ) and target_dirset . intersection ( find_source_basedirs ( target ) ) <EOL> return filter ( is_sibling , [ self . target_util . get ( a ) for a in candidates if a != target . address ] ) <EOL> resource_targets = [ ] <EOL> for target in self . targets : <EOL> if isinstance ( target , Resources ) : <EOL> resource_targets . append ( target ) <EOL> else : <EOL> target . walk ( configure_target , predicate = source_target ) <EOL> for target in resource_targets : <EOL> target . walk ( configure_target ) <EOL> def full_path ( source_set ) : <EOL> return os . path . join ( source_set . root_dir , source_set . source_base , source_set . path ) <EOL> overlap_error = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> source_full_paths = { } <EOL> for source_set in sorted ( self . sources , key = full_path ) : <EOL> full = full_path ( source_set ) <EOL> if full in source_full_paths : <EOL> previous_set = source_full_paths [ full ] <EOL> logger . debug ( overlap_error . format ( current = source_set , previous = previous_set ) ) <EOL> source_full_paths [ full ] = source_set <EOL> unexcludable_paths = set ( ) <EOL> for source_set in self . sources : <EOL> parent = os . path . join ( self . root_dir , source_set . source_base , source_set . path ) <EOL> while True : <EOL> unexcludable_paths . add ( parent ) <EOL> parent , _ = os . path . split ( parent ) <EOL> if parent == self . root_dir : <EOL> break <EOL> for source_set in self . sources : <EOL> paths = set ( ) <EOL> source_base = os . path . join ( self . root_dir , source_set . source_base ) <EOL> for root , dirs , _ in safe_walk ( os . path . join ( source_base , source_set . path ) ) : <EOL> if dirs : <EOL> paths . update ( [ os . path . join ( root , directory ) for directory in dirs ] ) <EOL> unused_children = paths - targeted <EOL> if unused_children : <EOL> for child in unused_children : <EOL> if child not in unexcludable_paths : <EOL> source_set . excludes . append ( os . path . relpath ( child , source_base ) ) <EOL> targets = OrderedSet ( ) <EOL> for target in self . targets : <EOL> target . walk ( lambda target : targets . add ( target ) , source_target ) <EOL> targets . update ( analyzed_targets - targets ) <EOL> self . sources . extend ( SourceSet ( get_buildroot ( ) , p , None , is_test = False ) for p in extra_source_paths ) <EOL> self . sources . extend ( SourceSet ( get_buildroot ( ) , p , None , is_test = True ) for p in extra_test_paths ) <EOL> if self . use_source_root : <EOL> self . sources = Project . _collapse_by_source_root ( self . context . source_roots , self . sources ) <EOL> self . sources = self . dedup_sources ( self . sources ) <EOL> return targets <EOL> def set_tool_classpaths ( self , checkstyle_classpath , scalac_classpath ) : <EOL> self . checkstyle_classpath = checkstyle_classpath <EOL> self . scala_compiler_classpath = scalac_classpath <EOL> @ classmethod <EOL> def _collect_ancestor_build_files ( cls , project_tree , dir_relpath , build_ignore_patterns ) : <EOL> for build_file in BuildFile . get_build_files_family ( project_tree , dir_relpath , build_ignore_patterns ) : <EOL> yield build_file <EOL> while not cls . _is_root_relpath ( dir_relpath ) : <EOL> dir_relpath = os . path . dirname ( dir_relpath ) <EOL> for build_file in BuildFile . get_build_files_family ( project_tree , dir_relpath , build_ignore_patterns ) : <EOL> yield build_file <EOL> @ classmethod <EOL> def _is_root_relpath ( cls , relpath ) : <EOL> return relpath == '<STR_LIT:.>' or relpath == '<STR_LIT>' </s>
