def imported_jars(self): """:returns: the string specs of JarDependencies referenced by imported_jar_library_specs :rtype: list of JarDependency """ return JarLibrary.to_jar_dependencies(self.address, self.imported_jar_library_specs(payload=self.payload), self._build_graph)
def imports(self): """Returns the set of JarDependency instances to be included when compiling this target.""" if self._imports is None: self._imports = JarLibrary.to_jar_dependencies(self.address, self.payload.raw_imports, self._build_graph) return self._imports
def imported_jars(self): """:returns: the string specs of JarDependencies referenced by imported_jar_library_specs :rtype: list of string """ return JarLibrary.to_jar_dependencies(self.address, self.imported_jar_library_specs, self._build_graph)
def imported_jars(self): """:returns: the string specs of JarDependencies referenced by imported_jar_library_specs :rtype: list of string """ if self._imported_jars is None: self._imported_jars = JarLibrary.to_jar_dependencies( self.address, self.imported_jar_library_specs, self._build_graph ) return self._imported_jars
def imports(self): """Expected by the IvyImports tasks. :returns: the set of JarDependency instances to be included when compiling this target. """ if self._libraries is None: self._libraries = JarLibrary.to_jar_dependencies(self.address, self.payload.raw_libraries, self._build_graph) return self._libraries
def add_payload_fields(cls, build_graph, addresses, payload): # JarLibrary targets have a unique attribute called `managed_dependencies`, which holds a spec of a # `managed_jar_dependency` target. That will not be inserted along with the rest of the jar_library's closure # since at address_mapping time it is not a dependency. We could take care to track them down and insert them # but it looks to me like this handling is already wired into the JarDependency and JarLibrary pipeline. If we # end up seeing misses, we can add the logic to insert them as a special case, but for now I hope to hand that # special casing off. all_jar_deps = JarLibrary.to_jar_dependencies( cls.get_synthetic_address(), [t.spec for t in addresses], build_graph, ) payload.add_fields({ 'jars': JarsField(sorted(all_jar_deps)), }) return payload
def test_to_jar_dependencies(self): def assert_dep(dep, org, name, rev): self.assertTrue(isinstance(dep, JarDependency)) self.assertEquals(org, dep.org) self.assertEquals(name, dep.name) self.assertEquals(rev, dep.rev) self.add_to_build_file( 'BUILD', dedent(''' jar_library(name='lib1', jars=[ jar(org='testOrg1', name='testName1', rev='123'), ], ) jar_library(name='lib2', jars=[ jar(org='testOrg2', name='testName2', rev='456'), jar(org='testOrg3', name='testName3', rev='789'), ], ) ''')) lib1 = self.target('//:lib1') self.assertIsInstance(lib1, JarLibrary) self.assertEquals(1, len(lib1.jar_dependencies)) assert_dep(lib1.jar_dependencies[0], 'testOrg1', 'testName1', '123') lib2 = self.target('//:lib2') self.assertIsInstance(lib2, JarLibrary) self.assertEquals(2, len(lib2.jar_dependencies)) assert_dep(lib2.jar_dependencies[0], 'testOrg2', 'testName2', '456') assert_dep(lib2.jar_dependencies[1], 'testOrg3', 'testName3', '789') jvm_target = JarLibrary(name='dummy', address=SyntheticAddress.parse("//:dummy"), build_graph=self.build_graph) deps = jvm_target.to_jar_dependencies(jvm_target.address, [':lib1', ':lib2'], self.build_graph) self.assertEquals(3, len(deps)) assert_dep(lib1.jar_dependencies[0], 'testOrg1', 'testName1', '123') assert_dep(lib2.jar_dependencies[0], 'testOrg2', 'testName2', '456') assert_dep(lib2.jar_dependencies[1], 'testOrg3', 'testName3', '789')
def create_synthetic_target(cls, options, address_mapper, build_graph, discovered_targets): """Create a synthetic target that depends on the set of jar_library_targets. The created target is injected into the build graph as an unconnected target with a payload of a JarsField populated by the JarDependencies implied by the jar_library_targets. :param `pants.option.options.Option` options: The Task's scoped options. :param `pants.build_graph.AddressMapper` address_mapper: Populated build_graph instance. :param `pants.build_graph.BuildGraph` build_graph: Populated build_graph instance :param collection[`pants.target.Target`] discovered_targets: Targets newly injected into build graph but possibly not in the context of any target_root. :returns synthetic target: :rtype subclass of `pants.target.Target`: """ synthetic_address = cls.get_synthetic_address() # JarLibrary targets have a unique attribute called `managed_dependencies`, which holds a spec of a # `managed_jar_dependency` target. That will not be inserted along with the rest of the jar_library's closure # since at address_mapping time it is not a dependency. We could take care to track them down and insert them # but it looks to me like this handling is already wired into the JarDependency and JarLibrary pipeline. If we # end up seeing misses, we can add the logic to insert them as a special case, but for now I hope to hand that # special casing off. jar_library_targets = [ t for t in discovered_targets if isinstance(t, JarLibrary) ] all_jar_deps = JarLibrary.to_jar_dependencies( synthetic_address, [t.address.spec for t in jar_library_targets], build_graph, ) payload = Payload() payload.add_fields({ 'jars': JarsField(sorted(all_jar_deps)), }) synthetic_target = cls.inject_synthetic_target( build_graph, synthetic_address, payload=payload, dependencies=[j.address for j in jar_library_targets], ) return synthetic_target
def test_to_jar_dependencies(self): def assert_dep(dep, org, name, rev): self.assertTrue(isinstance(dep, JarDependency)) self.assertEquals(org, dep.org) self.assertEquals(name, dep.name) self.assertEquals(rev, dep.rev) self.add_to_build_file( "BUILD", dedent( """ jar_library(name='lib1', jars=[ jar(org='testOrg1', name='testName1', rev='123'), ], ) jar_library(name='lib2', jars=[ jar(org='testOrg2', name='testName2', rev='456'), jar(org='testOrg3', name='testName3', rev='789'), ], ) """ ), ) lib1 = self.target("//:lib1") self.assertIsInstance(lib1, JarLibrary) self.assertEquals(1, len(lib1.jar_dependencies)) assert_dep(lib1.jar_dependencies[0], "testOrg1", "testName1", "123") lib2 = self.target("//:lib2") self.assertIsInstance(lib2, JarLibrary) self.assertEquals(2, len(lib2.jar_dependencies)) assert_dep(lib2.jar_dependencies[0], "testOrg2", "testName2", "456") assert_dep(lib2.jar_dependencies[1], "testOrg3", "testName3", "789") deps = JarLibrary.to_jar_dependencies(lib1.address, [":lib1", ":lib2"], self.build_graph) self.assertEquals(3, len(deps)) assert_dep(lib1.jar_dependencies[0], "testOrg1", "testName1", "123") assert_dep(lib2.jar_dependencies[0], "testOrg2", "testName2", "456") assert_dep(lib2.jar_dependencies[1], "testOrg3", "testName3", "789")
def test_to_jar_dependencies(self): def assert_dep(dep, org, name, rev): self.assertTrue(isinstance(dep, JarDependency)) self.assertEquals(org, dep.org) self.assertEquals(name, dep.name) self.assertEquals(rev, dep.rev) self.add_to_build_file('BUILD', dedent(''' jar_library(name='lib1', jars=[ jar(org='testOrg1', name='testName1', rev='123'), ], ) jar_library(name='lib2', jars=[ jar(org='testOrg2', name='testName2', rev='456'), jar(org='testOrg3', name='testName3', rev='789'), ], ) ''')) lib1 = self.target('//:lib1') self.assertIsInstance(lib1, JarLibrary) self.assertEquals(1, len(lib1.jar_dependencies)) assert_dep(lib1.jar_dependencies[0], 'testOrg1', 'testName1', '123') lib2 = self.target('//:lib2') self.assertIsInstance(lib2, JarLibrary) self.assertEquals(2, len(lib2.jar_dependencies)) assert_dep(lib2.jar_dependencies[0], 'testOrg2', 'testName2', '456') assert_dep(lib2.jar_dependencies[1], 'testOrg3', 'testName3', '789') jvm_target = JarLibrary(name='dummy', address=SyntheticAddress.parse("//:dummy"), build_graph=self.build_graph) deps = jvm_target.to_jar_dependencies(jvm_target.address, [':lib1', ':lib2'], self.build_graph) self.assertEquals(3, len(deps)) assert_dep(lib1.jar_dependencies[0], 'testOrg1', 'testName1', '123') assert_dep(lib2.jar_dependencies[0], 'testOrg2', 'testName2', '456') assert_dep(lib2.jar_dependencies[1], 'testOrg3', 'testName3', '789')