def test_jars_field_artifacts(self): jar1 = JarDependency('com', 'foo', '1.0.0').with_artifact('com', 'baz') jar2 = JarDependency('com', 'foo', '1.0.0') self.assertNotEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def test_jars_field_order(self): jar1 = JarDependency('com', 'foo', '1.0.0') jar2 = JarDependency('org', 'baz') self.assertNotEqual( JarsField([jar1, jar2]).fingerprint(), JarsField([jar2, jar1]).fingerprint(), )
def test_jars_field_order(self): jar1 = JarDependency("com", "foo", "1.0.0") jar2 = JarDependency("org", "baz") self.assertNotEqual( JarsField([jar1, jar2]).fingerprint(), JarsField([jar2, jar1]).fingerprint(), )
def test_jars_field_artifacts_arg_vs_method(self): jar1 = JarDependency('com', 'foo', '1.0.0', artifacts=[IvyArtifact('com', 'baz')]) jar2 = JarDependency('com', 'foo', '1.0.0').with_artifact('com', 'baz') self.assertEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def test_deprecated_jars_field_methods(self): """with_sources() and with_docs() are now no-ops. This test shows they don't affect fingerprinting. """ jar1 = (JarDependency('com', 'foo', '1.0.0')) jar2 = (JarDependency('com', 'foo', '1.0.0').with_sources().with_docs()) self.assertEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def test_jars_field_apidocs(self): """apidocs are not properly rolled into the cache key right now. Is this intentional?""" jar1 = JarDependency('com', 'foo', '1.0.0', apidocs='pantsbuild.github.io') jar2 = JarDependency('com', 'foo', '1.0.0', apidocs='someother.pantsbuild.github.io') self.assertEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def __init__(self, payload=None, jars=None, managed_dependencies=None, **kwargs): """ :param jars: List of `jar <#jar>`_\s to depend upon. :param managed_dependencies: Address of a managed_jar_dependencies() target to use. If omitted, uses the default managed_jar_dependencies() target set by --jar-dependency-management-default-target. """ jars = self.assert_list(jars, expected_type=JarDependency, key_arg='jars') payload = payload or Payload() payload.add_fields({ 'jars': JarsField(jars), 'excludes': ExcludesField([]), 'managed_dependencies': PrimitiveField(managed_dependencies), }) super(JarLibrary, self).__init__(payload=payload, **kwargs) # NB: Waiting to validate until superclasses are initialized. if not jars: raise TargetDefinitionException( self, 'Must have a non-empty list of jars.') self.add_labels('jars', 'jvm')
def test_jars_field_apidocs(self): """apidocs are not properly rolled into the cache key right now; is this intentional?""" jar1 = JarDependency("com", "foo", "1.0.0", apidocs="pantsbuild.github.io") jar2 = JarDependency("com", "foo", "1.0.0", apidocs="someother.pantsbuild.github.io") self.assertEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def test_jars_field_artifacts_ordering(self): """JarDependencies throw away ordering information about their artifacts in the cache key. But they do not throw it away in their internal representation! In the future, this should be fixed: either they should sort them as they are added and keep a canonical representation, or the order information should be preserved. """ jar1 = (JarDependency('com', 'foo', '1.0.0').with_artifact( 'com', 'baz').with_artifact('org', 'bat')) jar2 = (JarDependency('com', 'foo', '1.0.0').with_artifact( 'org', 'bat').with_artifact('com', 'baz')) self.assertEqual( JarsField([jar1]).fingerprint(), JarsField([jar2]).fingerprint(), )
def __init__(self, payload=None, jars=None, **kwargs): """ :param jars: List of `jar <#jar>`_\s to depend upon. """ payload = payload or Payload() payload.add_fields({ 'jars': JarsField(self.assert_list(jars, expected_type=JarDependency)), 'excludes': ExcludesField([]), }) super(JarLibrary, self).__init__(payload=payload, **kwargs) self.add_labels('jars', 'jvm')
def __init__(self, payload=None, artifacts=None, **kwargs): """ :param artifacts: List of `jar <#jar>`_\\s or specs to jar_library targets with pinned versions. Versions are pinned per (org, name, classifier, ext) artifact coordinate (excludes, etc are ignored for the purposes of pinning). """ jar_objects, library_specs = self._split_jars_and_specs(artifacts or ()) payload = payload or Payload() payload.add_fields( {"artifacts": JarsField(jar_objects), "library_specs": PrimitiveField(library_specs)} ) super().__init__(payload=payload, **kwargs)
def __init__(self, payload=None, jars=None, **kwargs): """ :param jars: List of `jar <#jar>`_\s to depend upon. """ jars = self.assert_list(jars, expected_type=JarDependency, key_arg='jars') payload = payload or Payload() payload.add_fields({ 'jars': JarsField(jars), 'excludes': ExcludesField([]), }) super(JarLibrary, self).__init__(payload=payload, **kwargs) # NB: Waiting to validate until superclasses are initialized. if not jars: raise TargetDefinitionException(self, 'Must have a non-empty list of jars.') self.add_labels('jars', 'jvm')
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 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