

@memoized_property
def targets_by_file(self):
    'Returns a map from abs path of source, class or jar file to an OrderedSet of targets.\n\n    The value is usually a singleton, because a source or class file belongs to a single target.\n    However a single jar may be provided (transitively or intransitively) by multiple JarLibrary\n    targets. But if there is a JarLibrary target that depends on a jar directly, then that\n    "canonical" target will be the first one in the list of targets.\n    '
    targets_by_file = defaultdict(OrderedSet)
    runtime_classpath = self.context.products.get_data('runtime_classpath')
    self.context.log.debug('Mapping sources...')
    buildroot = get_buildroot()
    for target in self.context.targets():
        if isinstance(target, JvmTarget):
            for src in target.sources_relative_to_buildroot():
                targets_by_file[os.path.join(buildroot, src)].add(target)
        if isinstance(target, ScalaLibrary):
            for java_source in target.java_sources:
                for src in java_source.sources_relative_to_buildroot():
                    targets_by_file[os.path.join(buildroot, src)].add(target)
    self.context.log.debug('Mapping classpath...')
    for target in self.context.targets():
        files = ClasspathUtil.classpath_contents((target,), runtime_classpath)
        cp_entries = ClasspathUtil.classpath((target,), runtime_classpath)
        jars = [cpe for cpe in cp_entries if ClasspathUtil.is_jar(cpe)]
        for coll in [files, jars]:
            for f in coll:
                targets_by_file[f].add(target)
    return targets_by_file

dataset/ETHPy150Open pantsbuild/pants/src/python/pants/backend/jvm/tasks/jvm_dependency_analyzer.py JvmDependencyAnalyzer.targets_by_file/original