Exemplo n.º 1
0
    def classpath(self, cp=None, confs=None):
        classpath = cp or []
        with self.context.state('classpath', []) as cp:
            classpath.extend(path for conf, path in cp
                             if not confs or conf in confs)

        def add_resource_paths(predicate):
            bases = set()
            for target in self.context.targets():
                if predicate(target):
                    if target.target_base not in bases:
                        sibling_resources_base = os.path.join(
                            os.path.dirname(target.target_base), 'resources')
                        classpath.append(
                            os.path.join(get_buildroot(),
                                         sibling_resources_base))
                        bases.add(target.target_base)

        if self.context.config.getbool('jvm',
                                       'parallel_src_paths',
                                       default=False):
            add_resource_paths(lambda t: is_jvm(t) and not is_test(t))

        if self.context.config.getbool('jvm',
                                       'parallel_test_paths',
                                       default=False):
            add_resource_paths(lambda t: is_jvm(t) and is_test(t))

        return classpath
Exemplo n.º 2
0
    def configure_target(target):
      if target not in analyzed:
        analyzed.add(target)

        self.has_scala = self.has_scala or is_scala(target)

        if isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary):
          # TODO(John Sirois): this does not handle test resources, make test resources 1st class
          # in ant build and punch this through to pants model
          resources = set()
          if target.resources:
            resources.update(target.resources)
          if target.binary_resources:
            resources.update(target.binary_resources)
          if resources:
            self.resource_extensions.update(Project.extract_resource_extensions(resources))
            configure_source_sets(ExportableJvmLibrary.RESOURCES_BASE_DIR, 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)

        siblings = Target.get_all_addresses(target.address.buildfile)
        return filter(accept_target, [ Target.get(a) for a in siblings if a != target.address ])
Exemplo n.º 3
0
 def calculate_tests(self, targets):
     tests = OrderedSet()
     for target in targets:
         if is_scala(target) and is_test(target):
             tests.update(
                 os.path.join(target.target_base, test)
                 for test in target.sources)
     return tests
Exemplo n.º 4
0
 def is_transitive():
     if self.ide_transitivity == TRANSITIVITY_TESTS:
         return is_test
     if self.ide_transitivity == TRANSITIVITY_ALL:
         return lambda target: True
     if self.ide_transitivity == TRANSITIVITY_NONE:
         return lambda target: False
     if self.ide_transitivity == TRANSITIVITY_SOURCES:
         return lambda target: not is_test(target)
Exemplo n.º 5
0
 def add_sources_under_test(tgt):
   if is_java(tgt) and not is_test(tgt) and not is_codegen(tgt):
     for source in tgt.sources:
       classes = classes_by_source.get(source)
       if classes:
         for base, classes in classes.items():
           classes_under_test.update(
             JUnitRun.classfile_to_classname(cls) for cls in classes
           )
Exemplo n.º 6
0
 def add_sources_under_test(tgt):
     if is_java(tgt) and not is_test(tgt) and not is_codegen(tgt):
         for source in tgt.sources:
             classes = classes_by_source.get(source)
             if classes:
                 for base, classes in classes.items():
                     classes_under_test.update(
                         JUnitRun.classfile_to_classname(cls)
                         for cls in classes)
Exemplo n.º 7
0
Arquivo: lib.py Projeto: crnt/commons
 def is_transitive():
   if self.ide_transitivity == TRANSITIVITY_TESTS:
     return is_test
   if self.ide_transitivity == TRANSITIVITY_ALL:
     return lambda target: True
   if self.ide_transitivity == TRANSITIVITY_NONE:
     return lambda target: False
   if self.ide_transitivity == TRANSITIVITY_SOURCES:
     return lambda target: not is_test(target)
Exemplo n.º 8
0
    def classpath(self, cp=None, confs=None, exclusives_classpath=None):
        classpath = cp or []

        classpath.extend(path for conf, path in exclusives_classpath if not confs or conf in confs)

        def add_resource_paths(predicate):
            bases = set()
            for target in self.context.targets():
                if predicate(target):
                    if target.target_base not in bases:
                        sibling_resources_base = os.path.join(os.path.dirname(target.target_base), "resources")
                        classpath.append(os.path.join(get_buildroot(), sibling_resources_base))
                        bases.add(target.target_base)

        if self.context.config.getbool("jvm", "parallel_src_paths", default=False):
            add_resource_paths(lambda t: is_jvm(t) and not is_test(t))

        if self.context.config.getbool("jvm", "parallel_test_paths", default=False):
            add_resource_paths(lambda t: is_jvm(t) and is_test(t))

        return classpath
Exemplo n.º 9
0
  def classpath(self, cp=None, confs=None):
    classpath = cp or []
    with self.context.state('classpath', []) as cp:
      classpath.extend(path for conf, path in cp if not confs or conf in confs)

    def add_resource_paths(predicate):
      bases = set()
      for target in self.context.targets():
        if predicate(target):
          if target.target_base not in bases:
            sibling_resources_base = os.path.join(os.path.dirname(target.target_base), 'resources')
            classpath.append(os.path.join(get_buildroot(), sibling_resources_base))
            bases.add(target.target_base)

    if self.context.config.getbool('jvm', 'parallel_src_paths', default=False):
      add_resource_paths(lambda t: is_jvm(t) and not is_test(t))

    if self.context.config.getbool('jvm', 'parallel_test_paths', default=False):
      add_resource_paths(lambda t: is_jvm(t) and is_test(t))

    return classpath
Exemplo n.º 10
0
  def calculate_tests(self, targets):
    def is_test_file(test):
      # TODO(John Sirois): config for a list of include regexes and exclude regexes
      basename = os.path.basename(test)
      return (test.endswith('Test.java') or test.endswith('IT.java')) \
          and not basename.startswith('Base') and not basename.startswith('Abstract')

    tests = set()
    for target in targets:
      if is_java(target) and is_test(target):
        tests.update(self.normalize(test, target.target_base) for test in target.sources
                     if is_test_file(test))
    return tests
Exemplo n.º 11
0
        def configure_target(target):
            if target not in analyzed:
                analyzed.add(target)

                self.has_scala = self.has_scala or is_scala(target)

                if isinstance(target, JavaLibrary) or isinstance(
                        target, ScalaLibrary):
                    # TODO(John Sirois): this does not handle test resources, make test resources 1st class
                    # in ant build and punch this through to pants model
                    resources = set()
                    if target.resources:
                        resources.update(target.resources)
                    if target.binary_resources:
                        resources.update(target.binary_resources)
                    if resources:
                        self.resource_extensions.update(
                            Project.extract_resource_extensions(resources))
                        configure_source_sets(
                            ExportableJvmLibrary.RESOURCES_BASE_DIR,
                            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])
Exemplo n.º 12
0
        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])
Exemplo n.º 13
0
  def classpath(self, cp=None, confs=None):
    classpath = cp or []
    with self.context.state('classpath', []) as cp:
      classpath.extend(jar for conf, jar in cp if not confs or conf in confs)

    # TODO(John Sirois): Fixup jvm test targets to declare their resources and fixup resources to
    # be their own target libraries or tests then depend on:
    # http://jira.local.twitter.com/browse/AWESOME-108
    bases = set()
    for target in self.context.targets():
      if isinstance(target, JvmTarget) and (is_test(target) or hasattr(target, 'resources')):
        if target.target_base not in bases:
          sibling_resources_base = os.path.join(os.path.dirname(target.target_base), 'resources')
          classpath.append(os.path.join(get_buildroot(), sibling_resources_base))
          bases.add(target.target_base)

    return classpath
Exemplo n.º 14
0
Arquivo: ide.py Projeto: crnt/commons
    def configure_target(target):
      if target not in analyzed:
        analyzed.add(target)

        self.has_scala = self.has_scala or is_scala(target)

        if isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary):
          # TODO(John Sirois): this does not handle test resources, make test resources 1st class
          # in ant build and punch this through to pants model
          resources = set()
          if target.resources:
            resources.update(target.resources)
          if target.binary_resources:
            resources.update(target.binary_resources)
          if resources:
            self.resource_extensions.update(Project.extract_resource_extensions(resources))
            configure_source_sets(ExportableJvmLibrary.RESOURCES_BASE_DIR,
                                  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 ])
Exemplo n.º 15
0
    def classpath(self, cp=None, confs=None):
        classpath = cp or []
        with self.context.state('classpath', []) as cp:
            classpath.extend(jar for conf, jar in cp
                             if not confs or conf in confs)

        # TODO(John Sirois): Fixup jvm test targets to declare their resources and fixup resources to
        # be their own target libraries or tests then depend on:
        # http://jira.local.twitter.com/browse/AWESOME-108
        bases = set()
        for target in self.context.targets():
            if isinstance(target, JvmTarget) and (is_test(target) or hasattr(
                    target, 'resources')):
                if target.target_base not in bases:
                    sibling_resources_base = os.path.join(
                        os.path.dirname(target.target_base), 'resources')
                    classpath.append(
                        os.path.join(get_buildroot(), sibling_resources_base))
                    bases.add(target.target_base)

        return classpath
Exemplo n.º 16
0
    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 isinstance(target, JavaLibrary) or isinstance(target, ScalaLibrary):
          resources = set()
          if target.resources:
            resources.update(target.resources)
          if resources:
            self.resource_extensions.update(Project.extract_resource_extensions(resources))
            configure_source_sets(target.sibling_resources_base,
                                  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 ])
Exemplo n.º 17
0
 def calculate_tests(self, targets):
   tests = OrderedSet()
   for target in targets:
     if is_scala(target) and is_test(target):
       tests.update(os.path.join(target.target_base, test) for test in target.sources)
   return tests
Exemplo n.º 18
0
 def is_coverage_target(self, tgt):
     return (is_java(tgt)
             or is_scala(tgt)) and not is_test(tgt) and not is_codegen(tgt)
Exemplo n.º 19
0
 def calculate_tests(self, targets):
     for target in targets:
         if (is_java(target) or is_scala(target)) and is_test(target):
             for test in target.sources:
                 for cls in self.normalize(test, target.target_base):
                     yield cls
Exemplo n.º 20
0
 def is_coverage_target(self, tgt):
   return (is_java(tgt) or is_scala(tgt)) and not is_test(tgt) and not is_codegen(tgt)
Exemplo n.º 21
0
 def calculate_tests(self, targets):
   for target in targets:
     if (is_java(target) or is_scala(target)) and is_test(target):
       for test in target.sources:
         for cls in self.normalize(test, target.target_base):
           yield cls