예제 #1
0
    def test_managed_resolve(self):
        """A managed resolve should consume a ManagedResolve and ManagedJars to produce Jars."""
        build_request = BuildRequest(
            goals=['compile'],
            addressable_roots=[self.consumes_managed_thirdparty])
        walk = self.build_and_walk(build_request)

        # Validate the root.
        self.assertEqual(
            (SelectNode(self.consumes_managed_thirdparty, Classpath, None,
                        None), Return(Classpath(creator='javac'))), walk[0][0])

        # Confirm that we produced classpaths for the managed jars.
        managed_jars = [self.managed_guava, self.managed_hadoop]
        self.assert_select_for_subjects(walk, Classpath,
                                        [self.consumes_managed_thirdparty])
        self.assert_select_for_subjects(walk,
                                        Classpath,
                                        managed_jars,
                                        variants={'resolve': 'latest-hadoop'})

        # Confirm that the produced jars had the appropriate versions.
        self.assertEquals(
            {
                Jar('org.apache.hadoop', 'hadoop-common', '2.7.0'),
                Jar('com.google.guava', 'guava', '18.0')
            }, {
                ret.value
                for (node, ret), _ in walk
                if node.product == Jar and isinstance(node, SelectNode)
            })
예제 #2
0
 def assert_engine(self, engine):
     build_request = BuildRequest(goals=['compile'],
                                  addressable_roots=[self.java.address])
     result = engine.execute(build_request)
     self.assertEqual(
         {
             SelectNode(self.java, Classpath, None):
             Return(Classpath(creator='javac'))
         }, result.root_products)
     self.assertIsNone(result.error)
예제 #3
0
  def test_gen(self):
    build_request = BuildRequest(goals=['gen'], addressable_roots=[self.thrift.address])
    walk = self.build_and_walk(build_request)

    # Root: expect JavaSources.
    root_entry = walk[0][0]
    self.assertEqual(SelectNode(self.thrift, JavaSources, None), root_entry[0])
    self.assertIsInstance(root_entry[1], Return)

    # Expect an ApacheThriftJavaConfiguration to have been used.
    product = ApacheThriftJavaConfiguration
    self.assertEqual({NativeNode(self.thrift, product, None)},
                     {node for (node, _), _ in walk
                      if node.product == product and isinstance(node, NativeNode)})
예제 #4
0
    def test_dependency_inference(self):
        """Scala dependency inference introduces dependencies that do not exist in BUILD files."""
        build_request = BuildRequest(goals=['compile'],
                                     addressable_roots=[self.inferred_deps])
        walk = self.build_and_walk(build_request)

        # Validate the root.
        self.assertEqual(
            (SelectNode(self.inferred_deps, Classpath, None, None),
             Return(Classpath(creator='scalac'))), walk[0][0])

        # Confirm that we requested a classpath for the root and inferred targets.
        self.assert_select_for_subjects(walk, Classpath,
                                        [self.inferred_deps, self.java_simple])
예제 #5
0
    def test_consumes_resources(self):
        build_request = BuildRequest(
            goals=['compile'], addressable_roots=[self.consumes_resources])
        walk = self.build_and_walk(build_request)

        # Validate the root.
        self.assertEqual(
            (SelectNode(self.consumes_resources, Classpath, None,
                        None), Return(Classpath(creator='javac'))), walk[0][0])

        # Confirm a classpath for the resources target and other subjects. We know that they are
        # reachable from the root (since it was involved in this walk).
        subjects = [self.resources, self.consumes_resources, self.guava]
        self.assert_select_for_subjects(walk, Classpath, subjects)
예제 #6
0
  def test_codegen_simple(self):
    build_request = BuildRequest(goals=['compile'], addressable_roots=[self.java.address])
    walk = self.build_and_walk(build_request)

    subjects = [self.guava,
                Jar(org='org.apache.thrift', name='libthrift', rev='0.9.2'),
                Jar(org='commons-lang', name='commons-lang', rev='2.5'),
                self.graph.resolve(Address.parse('src/thrift:slf4j-api')),
                self.java,
                self.thrift]

    # Root: expect compilation via javac.
    self.assertEqual((SelectNode(self.java, Classpath, None), Return(Classpath(creator='javac'))),
                     walk[0][0])

    # Confirm that exactly the expected subjects got Classpaths.
    self.assert_product_for_subjects(walk, Classpath, subjects)
예제 #7
0
    def test_gen(self):
        build_request = BuildRequest(goals=['gen'],
                                     addressable_roots=[self.thrift])
        walk = self.build_and_walk(build_request)

        # Root: expect JavaSources.
        root_entry = walk[0][0]
        self.assertEqual(SelectNode(self.thrift, JavaSources, None, None),
                         root_entry[0])
        self.assertIsInstance(root_entry[1], Return)

        # Expect an ApacheThriftJavaConfiguration to have been used via the default Variants.
        self.assert_select_for_subjects(walk,
                                        ApacheThriftJavaConfiguration,
                                        [self.thrift],
                                        variants={'thrift': 'apache_java'},
                                        variant_key='thrift')
예제 #8
0
    def test_codegen_simple(self):
        build_request = BuildRequest(goals=['compile'],
                                     addressable_roots=[self.java])
        walk = self.build_and_walk(build_request)

        # The subgraph below 'src/thrift/codegen/simple' will be affected by its default variants.
        subjects = [self.guava, self.java, self.thrift]
        variant_subjects = [
            Jar(org='org.apache.thrift', name='libthrift', rev='0.9.2'),
            Jar(org='commons-lang', name='commons-lang', rev='2.5'),
            Address.parse('src/thrift:slf4j-api')
        ]

        # Root: expect compilation via javac.
        self.assertEqual(
            (SelectNode(self.java, Classpath, None,
                        None), Return(Classpath(creator='javac'))), walk[0][0])

        # Confirm that exactly the expected subjects got Classpaths.
        self.assert_select_for_subjects(walk, Classpath, subjects)
        self.assert_select_for_subjects(walk,
                                        Classpath,
                                        variant_subjects,
                                        variants={'thrift': 'apache_java'})
예제 #9
0
 def assert_product_for_subjects(self, walk, product, subjects, variants=None):
   variants = tuple(variants.items()) if variants else None
   self.assertEqual({SelectNode(subject, product, variants) for subject in subjects},
                    {node for (node, _), _ in walk
                     if node.product == product and isinstance(node, SelectNode) and node.variants == variants})
예제 #10
0
 def _select(self, address):
     return SelectNode(address, self._product, None, None)