示例#1
0
  def write(self, target, path, confs=None, synth=False):
    def as_jar(internal_target, is_tgt=False):
      jar, _, _, _ = self.get_db(internal_target).as_jar_with_version(internal_target)
      if synth and is_tgt:
        jar.name = jar.name + '-only'
      return jar

    # TODO(John Sirois): a dict is used here to de-dup codegen targets which have both the original
    # codegen target - say java_thrift_library - and the synthetic generated target (java_library)
    # Consider reworking codegen tasks to add removal of the original codegen targets when rewriting
    # the graph
    dependencies = OrderedDict()
    internal_codegen = {}
    for dep in target.internal_dependencies:
      jar = as_jar(dep)
      dependencies[(jar.org, jar.name)] = self.internaldep(jar, dep, synth)
      if is_codegen(dep):
        internal_codegen[jar.name] = jar.name
    for jar in target.jar_dependencies:
      if jar.rev:
        dependencies[(jar.org, jar.name)] = self.jardep(jar)
    target_jar = self.internaldep(as_jar(target, is_tgt=True)).extend(
      dependencies=dependencies.values()
    )

    template_kwargs = self.templateargs(target_jar, confs, synth)
    with safe_open(path, 'w') as output:
      template = pkgutil.get_data(__name__, self.template_relpath)
      Generator(template, **template_kwargs).write(output)
示例#2
0
  def write(self, target, path, confs=None, synth=False):
    def as_jar(internal_target, is_tgt=False):
      jar, _, _, _ = self.get_db(internal_target).as_jar_with_version(internal_target)
      if synth and is_tgt:
        jar.name = jar.name + '-only'
      return jar

    # TODO(John Sirois): a dict is used here to de-dup codegen targets which have both the original
    # codegen target - say java_thrift_library - and the synthetic generated target (java_library)
    # Consider reworking codegen tasks to add removal of the original codegen targets when rewriting
    # the graph
    dependencies = OrderedDict()
    internal_codegen = {}
    for dep in target.internal_dependencies:
      jar = as_jar(dep)
      dependencies[(jar.org, jar.name)] = self.internaldep(jar, dep, synth)
      if is_codegen(dep):
        internal_codegen[jar.name] = jar.name
    for jar in target.jar_dependencies:
      if jar.rev:
        dependencies[(jar.org, jar.name)] = self.jardep(jar)
    target_jar = self.internaldep(as_jar(target, is_tgt=True)).extend(
      dependencies=dependencies.values()
    )

    template_kwargs = self.templateargs(target_jar, confs, synth)
    with safe_open(path, 'w') as output:
      template = pkgutil.get_data(__name__, self.template_relpath)
      Generator(template, **template_kwargs).write(output)
示例#3
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
           )
示例#4
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)
示例#5
0
文件: ide_gen.py 项目: xianxu/pants
        def is_cp(target):
            return (
                is_codegen(target)

                # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and
                # proceed in 2 compile rounds
                or is_apt(target) or (self.skip_java and is_java(target)) or
                (self.skip_scala and is_scala(target)) or
                (self.intransitive
                 and target not in self.context.target_roots))
示例#6
0
    def is_cp(target):
      return (
        is_codegen(target)

        # Some IDEs need annotation processors pre-compiled, others are smart enough to detect and
        # proceed in 2 compile rounds
        or is_apt(target)

        or (self.skip_java and is_java(target))
        or (self.skip_scala and is_scala(target))
        or (self.intransitive and target not in self.context.target_roots)
      )
示例#7
0
 def internaldep(self, jar_dependency, dep=None, synth=False):
   classifier = 'idl' if dep and is_codegen(dep) and synth else None
   return self._jardep(jar_dependency, classifier=classifier)
示例#8
0
 def internaldep(self, jar_dependency, dep=None, synth=False):
   classifier = 'idl' if dep and is_codegen(dep) and synth else None
   return self._jardep(jar_dependency, classifier=classifier)
示例#9
0
文件: ide.py 项目: JoeEnnever/commons
 def source_target(target):
   return has_sources(target) \
       and (not is_codegen(target)
            and not (self.skip_java and is_java(target))
            and not (self.skip_scala and is_scala(target)))
示例#10
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)
示例#11
0
 def _is_checked(target):
   return is_java(target) and not is_codegen(target)
示例#12
0
文件: ide.py 项目: JoeEnnever/commons
 def is_cp(target):
   return is_codegen(target) \
          or is_apt(target) \
          or (skip_java and is_java(target)) \
          or (skip_scala and is_scala(target))
示例#13
0
    def test_extract_target(self):
        jar1 = MockTarget('jar1', rev=1)
        jar2 = MockTarget('jar2', rev=1)
        jar3 = MockTarget('jar3', rev=1)
        jar4 = MockTarget('jar4', rev=1)
        jar5 = MockTarget('jar5', rev=1)
        jar6 = MockTarget('jar6', rev=1)

        f = MockTarget('f', is_codegen=True)
        b = MockTarget('b', is_codegen=True, internal_dependencies=[f])
        d = MockTarget('d', internal_dependencies=[f], jar_dependencies=[jar1])

        g = MockTarget('g', is_apt=True)
        i = MockTarget('i', internal_dependencies=[g])
        h = MockTarget('h',
                       is_apt=True,
                       internal_dependencies=[i],
                       jar_dependencies=[jar5])
        j = MockTarget('j', jar_dependencies=[jar1, jar6])

        e = MockTarget('e',
                       internal_dependencies=[g, h],
                       jar_dependencies=[jar2])

        c = MockTarget('c',
                       is_codegen=True,
                       internal_dependencies=[d, e],
                       jar_dependencies=[jar3])

        a = MockTarget('a',
                       internal_dependencies=[c, b, e, j],
                       jar_dependencies=[jar4])

        # We want to compile only:
        #   codegen <- ide classpath needs these
        #   apt + any internal deps <- ide compiler needs these
        #
        # a -> *c -> d --> *f
        #              --> jar1
        #         -> e
        #         -> jar3
        #   -> *b -> (*f)
        #   --> e -> #g
        #         -> #h -> i -> (#g)
        #               -> jar5
        #         -> jar2
        #   --> j -> jar1
        #         -> jar6
        #   --> jar4

        internal_deps, jar_deps = _extract_target(
            [a, e, j], lambda target: target.is_apt or is_codegen(target))

        self.assertEquals(
            OrderedSet([c, b]), internal_deps,
            'Expected depth first walk to roll up e to 1st visited dependee (c)'
        )

        self.assertEquals(OrderedSet([d, e]), c.internal_dependencies)
        self.assertEquals(OrderedSet([f]), d.internal_dependencies)
        self.assertEquals(OrderedSet([g, h]), e.internal_dependencies)
        self.assertEquals(OrderedSet([i]), h.internal_dependencies)
        self.assertEquals(
            OrderedSet(), b.internal_dependencies,
            'Expected depth first walk to roll up f to 1st visited dependee (d)'
        )

        self.assertEquals(
            set([jar1, jar4, jar6]), set(jar_deps),
            'Only jar dependencies from rolled up targets should be collected since '
            'those not rolled up will include their jar deps in their own ivy.xmls'
        )
示例#14
0
# recognize flags to narrow the gen set
goal(name='thrift', action=ThriftGen).install('gen').with_description('Generate code.')
goal(name='protoc', action=ProtobufGen).install('gen')


goal(
  name='checkstyle',
  action=Checkstyle,
  dependencies=['gen', 'resolve']
).install().with_description('Run checkstyle against java source code.')


# Support straight up checkstyle runs in addition to checkstyle as last phase of compile below
goal(name='javac',
     action=JavaCompile,
     group=group('gen', lambda target: is_codegen(target)),
     dependencies=['gen', 'resolve']).install('checkstyle')


def is_java(target):
 return isinstance(target, JavaLibrary) or \
        isinstance(target, JavaTests)

goal(name='scalac',
     action=ScalaCompile,
     group=group('jvm', is_scala),
     dependencies=['gen', 'resolve']).install('compile').with_description(
       'Compile both generated and checked in code.'
     )
goal(name='apt',
     action=JavaCompile,
示例#15
0
 def is_cp(target):
     return is_codegen(target) \
            or is_apt(target) \
            or (skip_java and is_java(target)) \
            or (skip_scala and is_scala(target))
示例#16
0
文件: goal.py 项目: ugodiggi/commons
# recognize flags to narrow the gen set
goal(name='thrift', action=ThriftGen).install('gen').with_description('Generate code.')
goal(name='protoc', action=ProtobufGen).install('gen')


goal(
  name='checkstyle',
  action=Checkstyle,
  dependencies=['gen', 'resolve']
).install().with_description('Run checkstyle against java source code.')


# Support straight up checkstyle runs in addition to checkstyle as last phase of compile below
goal(name='javac',
     action=JavaCompile,
     group=group('gen', lambda target: is_codegen(target)),
     dependencies=['gen', 'resolve']).install('checkstyle')


def is_java(target):
 return isinstance(target, JavaLibrary) or \
        isinstance(target, JavaTests)

goal(name='scalac',
     action=ScalaCompile,
     group=group('jvm', is_scala),
     dependencies=['gen', 'resolve']).install('compile').with_description(
       'Compile both generated and checked in code.'
     )
goal(name='apt',
     action=JavaCompile,
示例#17
0
 def source_target(target):
     return has_sources(target) \
         and (not is_codegen(target)
              and not (self.skip_java and is_java(target))
              and not (self.skip_scala and is_scala(target)))
示例#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)
示例#19
0
 def _is_checked(target):
     return is_java(target) and not is_codegen(target)
示例#20
0
 def source_target(target):
   return (self.transitive or target in self.targets) and has_sources(target) \
       and (not is_codegen(target)
            and not (self.skip_java and is_java(target))
            and not (self.skip_scala and is_scala(target)))
示例#21
0
文件: ide_gen.py 项目: xianxu/pants
 def source_target(target):
     return (self.transitive or target in self.targets) and has_sources(target) \
         and (not is_codegen(target)
              and not (self.skip_java and is_java(target))
              and not (self.skip_scala and is_scala(target)))
示例#22
0
  def test_extract_target(self):
    jar1 = MockTarget('jar1', rev = 1)
    jar2 = MockTarget('jar2', rev = 1)
    jar3 = MockTarget('jar3', rev = 1)
    jar4 = MockTarget('jar4', rev = 1)
    jar5 = MockTarget('jar5', rev = 1)
    jar6 = MockTarget('jar6', rev = 1)

    f = MockTarget('f', is_codegen = True)
    b = MockTarget('b', is_codegen = True, internal_dependencies = [f])
    d = MockTarget('d', internal_dependencies = [f], jar_dependencies = [jar1])

    g = MockTarget('g', is_apt = True)
    i = MockTarget('i', internal_dependencies = [g])
    h = MockTarget('h', is_apt = True, internal_dependencies = [i], jar_dependencies = [jar5])
    j = MockTarget('j', jar_dependencies = [jar1, jar6])

    e = MockTarget('e', internal_dependencies = [g, h], jar_dependencies = [jar2])


    c = MockTarget('c',
                   is_codegen = True,
                   internal_dependencies = [d, e],
                   jar_dependencies = [jar3])

    a = MockTarget('a', internal_dependencies = [c, b, e, j], jar_dependencies = [jar4])

    # We want to compile only:
    #   codegen <- ide classpath needs these
    #   apt + any internal deps <- ide compiler needs these
    #
    # a -> *c -> d --> *f
    #              --> jar1
    #         -> e
    #         -> jar3
    #   -> *b -> (*f)
    #   --> e -> #g
    #         -> #h -> i -> (#g)
    #               -> jar5
    #         -> jar2
    #   --> j -> jar1
    #         -> jar6
    #   --> jar4

    internal_deps, jar_deps = _extract_target(
      [a, e, j],
      lambda target: target.is_apt or is_codegen(target)
    )

    self.assertEquals(OrderedSet([c, b]), internal_deps,
                      'Expected depth first walk to roll up e to 1st visited dependee (c)')

    self.assertEquals(OrderedSet([d, e]), c.internal_dependencies)
    self.assertEquals(OrderedSet([f]), d.internal_dependencies)
    self.assertEquals(OrderedSet([g, h]), e.internal_dependencies)
    self.assertEquals(OrderedSet([i]), h.internal_dependencies)
    self.assertEquals(OrderedSet(), b.internal_dependencies,
                      'Expected depth first walk to roll up f to 1st visited dependee (d)')

    self.assertEquals(set([jar1, jar4, jar6]), set(jar_deps),
                      'Only jar dependencies from rolled up targets should be collected since '
                      'those not rolled up will include their jar deps in their own ivy.xmls')
示例#23
0
文件: goal.py 项目: nsanch/commons
# TODO(John Sirois): gen attempted as the sole Goal should gen for all known gen types but
# recognize flags to narrow the gen set
goal(name="thrift", action=ThriftGen).install("gen").with_description("Generate code.")
goal(name="protoc", action=ProtobufGen).install("gen")


goal(name="checkstyle", action=Checkstyle, dependencies=["gen", "resolve"]).install().with_description(
    "Run checkstyle against java source code."
)


# Support straight up checkstyle runs in addition to checkstyle as last phase of compile below
goal(
    name="javac",
    action=JavaCompile,
    group=group("gen", lambda target: is_codegen(target)),
    dependencies=["gen", "resolve"],
).install("checkstyle")


def is_java(target):
    return isinstance(target, JavaLibrary) or isinstance(target, JavaTests)


goal(name="scalac", action=ScalaCompile, group=group("jvm", is_scala), dependencies=["gen", "resolve"]).install(
    "compile"
).with_description("Compile both generated and checked in code.")
goal(name="apt", action=JavaCompile, group=group("jvm", is_apt), dependencies=["gen", "resolve"]).install("compile")
goal(name="javac", action=JavaCompile, group=group("jvm", is_java), dependencies=["gen", "resolve"]).install("compile")