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 __init__(self, address=None, payload=None, sources_rel_path=None, sources=None, provides=None, excludes=None, resources=None, configurations=None, no_cache=False, services=None, platform=None, **kwargs): """ :param configurations: One or more ivy configurations to resolve for this target. This parameter is not intended for general use. :type configurations: tuple of strings :param excludes: List of `exclude <#exclude>`_\s to filter this target's transitive dependencies against. :param sources: Source code files to build. Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` (from globs or rglobs) or list of strings :param no_cache: If True, this should not be stored in the artifact cache :param services: A dict mapping service interface names to the classes owned by this target that implement them. Keys are fully qualified service class names, values are lists of strings, each string the fully qualified class name of a class owned by this target that implements the service interface and should be discoverable by the jvm service provider discovery mechanism described here: https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html :param str platform: The name of the platform (defined under the jvm-platform subsystem) to use for compilation (that is, a key into the --jvm-platform-platforms dictionary). If unspecified, the platform will default to the first one of these that exist: (1) the default_platform specified for jvm-platform, (2) a platform constructed from whatever java version is returned by Distribution.cached().version. """ self.address = address # Set in case a TargetDefinitionException is thrown early if sources_rel_path is None: sources_rel_path = address.spec_path payload = payload or Payload() payload.add_fields({ 'sources': self.create_sources_field(sources, sources_rel_path, address, key_arg='sources'), 'provides': provides, 'excludes': ExcludesField(self.assert_list(excludes, expected_type=Exclude, key_arg='excludes')), 'configurations': ConfigurationsField(self.assert_list(configurations, key_arg='configurations')), 'platform': PrimitiveField(platform), }) self._resource_specs = self.assert_list(resources, key_arg='resources') super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs) # Service info is only used when generating resources, it should not affect, for example, a # compile fingerprint or javadoc fingerprint. As such, its not a payload field. self._services = services or {} self.add_labels('jvm') if no_cache: self.add_labels('no_cache')
def test_excludes_field(self): empty = ExcludesField() empty_fp = empty.fingerprint() self.assertEqual(empty_fp, empty.fingerprint()) normal = ExcludesField([Exclude('com', 'foozle'), Exclude('org')]) normal_fp = normal.fingerprint() self.assertEqual(normal_fp, normal.fingerprint()) normal_dup = ExcludesField([Exclude('com', 'foozle'), Exclude('org')]) self.assertEqual(normal_fp, normal_dup.fingerprint()) self.assertNotEqual(empty_fp, normal_fp)
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, 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 test_excludes_field_again(self): self.assertEqual( ExcludesField([Exclude('com', 'foo')]).fingerprint(), ExcludesField([Exclude('com', 'foo')]).fingerprint(), ) self.assertEqual( ExcludesField([]).fingerprint(), ExcludesField().fingerprint(), ) self.assertNotEqual( ExcludesField([Exclude('com', 'foo')]).fingerprint(), ExcludesField([Exclude('com')]).fingerprint(), ) self.assertNotEqual( ExcludesField([Exclude('com', 'foo'), Exclude('org', 'bar')]).fingerprint(), ExcludesField([Exclude('org', 'bar'), Exclude('com', 'foo')]).fingerprint(), )
def test_excludes_field_again(self): self.assertEqual( ExcludesField([Exclude("com", "foo")]).fingerprint(), ExcludesField([Exclude("com", "foo")]).fingerprint(), ) self.assertEqual( ExcludesField([]).fingerprint(), ExcludesField().fingerprint(), ) self.assertNotEqual( ExcludesField([Exclude("com", "foo")]).fingerprint(), ExcludesField([Exclude("com")]).fingerprint(), ) self.assertNotEqual( ExcludesField([Exclude("com", "foo"), Exclude("org", "bar")]).fingerprint(), ExcludesField([Exclude("org", "bar"), Exclude("com", "foo")]).fingerprint(), )
def __init__(self, address=None, payload=None, sources_rel_path=None, sources=None, provides=None, excludes=None, resources=None, configurations=None, no_cache=False, **kwargs): """ :param configurations: One or more ivy configurations to resolve for this target. This parameter is not intended for general use. :type configurations: tuple of strings :param excludes: List of `exclude <#exclude>`_\s to filter this target's transitive dependencies against. :param sources: Source code files to build. Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` (from globs or rglobs) or list of strings :param no_cache: If True, this should not be stored in the artifact cache """ if sources_rel_path is None: sources_rel_path = address.spec_path payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(sources=self.assert_list(sources), sources_rel_path=sources_rel_path), 'provides': provides, 'excludes': ExcludesField(self.assert_list(excludes, expected_type=Exclude)), 'configurations': ConfigurationsField(self.assert_list(configurations)), }) self._resource_specs = self.assert_list(resources) super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs) self.add_labels('jvm') if no_cache: self.add_labels('no_cache')
def __init__(self, name=None, address=None, payload=None, main=None, basename=None, source=None, deploy_excludes=None, deploy_jar_rules=None, manifest_entries=None, **kwargs): """ :param string main: The name of the ``main`` class, e.g., ``'org.pantsbuild.example.hello.main.HelloMain'``. This class may be present as the source of this target or depended-upon library. :param string basename: Base name for the generated ``.jar`` file, e.g., ``'hello'``. (By default, uses ``name`` param) :param string source: Name of one ``.java`` or ``.scala`` file (a good place for a ``main``). :param sources: Overridden by source. If you want more than one source file, use a library and have the jvm_binary depend on that library. :param resources: List of ``resource``\s to include in bundle. :param dependencies: Targets (probably ``java_library`` and ``scala_library`` targets) to "link" in. :type dependencies: list of target specs :param deploy_excludes: List of `exclude <#exclude>`_\s to apply at deploy time. If you, for example, deploy a java servlet that has one version of ``servlet.jar`` onto a Tomcat environment that provides another version, they might conflict. ``deploy_excludes`` gives you a way to build your code but exclude the conflicting ``jar`` when deploying. :param deploy_jar_rules: `Jar rules <#jar_rules>`_ for packaging this binary in a deploy jar. :param manifest_entries: dict that specifies entries for `ManifestEntries <#manifest_entries>`_ for adding to MANIFEST.MF when packaging this binary. :param configurations: Ivy configurations to resolve for this target. This parameter is not intended for general use. :type configurations: tuple of strings """ self.address = address # Set in case a TargetDefinitionException is thrown early if main and not isinstance(main, string_types): raise TargetDefinitionException( self, 'main must be a fully qualified classname') if source and not isinstance(source, string_types): raise TargetDefinitionException( self, 'source must be a single relative file path') if deploy_jar_rules and not isinstance(deploy_jar_rules, JarRules): raise TargetDefinitionException( self, 'deploy_jar_rules must be a JarRules specification. got {}'. format(type(deploy_jar_rules).__name__)) if manifest_entries and not isinstance(manifest_entries, dict): raise TargetDefinitionException( self, 'manifest_entries must be a dict. got {}'.format( type(manifest_entries).__name__)) sources = [source] if source else None if 'sources' in kwargs: raise self.IllegalArgument( address.spec, 'jvm_binary only supports a single "source" argument, typically used to specify a main ' 'class source file. Other sources should instead be placed in a java_library, which ' 'should be referenced in the jvm_binary\'s dependencies.') payload = payload or Payload() payload.add_fields({ 'basename': PrimitiveField(basename or name), 'deploy_excludes': ExcludesField( self.assert_list(deploy_excludes, expected_type=Exclude, key_arg='deploy_excludes')), 'deploy_jar_rules': FingerprintedField(deploy_jar_rules or JarRules.default()), 'manifest_entries': FingerprintedField(ManifestEntries(manifest_entries)), 'main': PrimitiveField(main), }) super(JvmBinary, self).__init__(name=name, address=address, payload=payload, sources=self.assert_list(sources, key_arg='sources'), **kwargs)
def __init__(self, address=None, payload=None, sources=None, provides=None, excludes=None, services=None, platform=None, strict_deps=None, exports=None, compiler_option_sets=None, zinc_file_manager=None, # Some subclasses can have both .java and .scala sources # (e.g., JUnitTests, JvmBinary, even ScalaLibrary), so it's convenient # to have both plugins settings here, even though for other subclasses # (e.g., JavaLibrary) only one will be relevant. javac_plugins=None, javac_plugin_args=None, scalac_plugins=None, scalac_plugin_args=None, **kwargs): """ :API: public :param excludes: List of `exclude <#exclude>`_\\s to filter this target's transitive dependencies against. :param sources: Source code files to build. Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` (from globs or rglobs) or list of strings :param services: A dict mapping service interface names to the classes owned by this target that implement them. Keys are fully qualified service class names, values are lists of strings, each string the fully qualified class name of a class owned by this target that implements the service interface and should be discoverable by the jvm service provider discovery mechanism described here: https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html :param str platform: The name of the platform (defined under the jvm-platform subsystem) to use for compilation (that is, a key into the --jvm-platform-platforms dictionary). If unspecified, the platform will default to the first one of these that exist: (1) the default_platform specified for jvm-platform, (2) a platform constructed from whatever java version is returned by DistributionLocator.cached().version. :param bool strict_deps: When True, only the directly declared deps of the target will be used at compilation time. This enforces that all direct deps of the target are declared, and can improve compilation speed due to smaller classpaths. Transitive deps are always provided at runtime. :param list exports: A list of exported targets, which will be accessible to dependents even with strict_deps turned on. A common use case is for library targets to to export dependencies that it knows its dependents will need. Then any dependents of that library target will have access to those dependencies even when strict_deps is True. Note: exports is transitive, which means dependents have access to the closure of exports. An example will be that if A exports B, and B exports C, then any targets that depends on A will have access to both B and C. :param list compiler_option_sets: A list of compiler_option_sets keys for the target. Platform dependent. :param bool zinc_file_manager: Whether to use zinc provided file manager that allows transactional rollbacks, but in certain cases may conflict with user libraries. :param javac_plugins: names of compiler plugins to use when compiling this target with javac. :param dict javac_plugin_args: Map from javac plugin name to list of arguments for that plugin. :param scalac_plugins: names of compiler plugins to use when compiling this target with scalac. :param dict scalac_plugin_args: Map from scalac plugin name to list of arguments for that plugin. """ self.address = address # Set in case a TargetDefinitionException is thrown early payload = payload or Payload() excludes = ExcludesField(self.assert_list(excludes, expected_type=Exclude, key_arg='excludes')) payload.add_fields({ 'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'), 'provides': provides, 'excludes': excludes, 'platform': PrimitiveField(platform), 'strict_deps': PrimitiveField(strict_deps), 'exports': PrimitivesSetField(exports or []), 'compiler_option_sets': PrimitivesSetField(compiler_option_sets), 'zinc_file_manager': PrimitiveField(zinc_file_manager), 'javac_plugins': PrimitivesSetField(javac_plugins or []), 'javac_plugin_args': PrimitiveField(javac_plugin_args), 'scalac_plugins': PrimitivesSetField(scalac_plugins or []), 'scalac_plugin_args': PrimitiveField(scalac_plugin_args), }) super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs) # Service info is only used when generating resources, it should not affect, for example, a # compile fingerprint or javadoc fingerprint. As such, its not a payload field. self._services = services or {}
def __init__(self, name=None, address=None, payload=None, main=None, basename=None, sources=None, deploy_excludes=None, deploy_jar_rules=None, manifest_entries=None, shading_rules=None, extra_jvm_options=None, **kwargs): """ :API: public :param string main: The name of the ``main`` class, e.g., ``'org.pantsbuild.example.hello.main.HelloMain'``. This class may be present as the source of this target or depended-upon library. :param string basename: Base name for the generated ``.jar`` file, e.g., ``'hello'``. (By default, uses ``name`` param) Note this is unsafe because of the possible conflict when multiple binaries are built. :param EagerFilesetWithSpec sources: Zero or one source files. If more than one source is required, they should be put in a library target which should be added to dependencies. :param dependencies: Targets (probably ``java_library`` and ``scala_library`` targets) to "link" in. :type dependencies: list of target specs :param deploy_excludes: List of `exclude <#exclude>`_\\s to apply at deploy time. If you, for example, deploy a java servlet that has one version of ``servlet.jar`` onto a Tomcat environment that provides another version, they might conflict. ``deploy_excludes`` gives you a way to build your code but exclude the conflicting ``jar`` when deploying. :param deploy_jar_rules: `Jar rules <#jar_rules>`_ for packaging this binary in a deploy jar. :param manifest_entries: dict that specifies entries for `ManifestEntries <#manifest_entries>`_ for adding to MANIFEST.MF when packaging this binary. :param list shading_rules: Optional list of shading rules to apply when building a shaded (aka monolithic aka fat) binary jar. The order of the rules matters: the first rule which matches a fully-qualified class name is used to shade it. See shading_relocate(), shading_exclude(), shading_relocate_package(), and shading_exclude_package(). :param list extra_jvm_options: A list of options to be passed to the jvm when running the binary. Example: ['-Dexample.property=1', '-DMyFlag', '-Xmx4G'] If unspecified, no extra jvm options will be added. """ self.address = address # Set in case a TargetDefinitionException is thrown early if main and not isinstance(main, str): raise TargetDefinitionException(self, 'main must be a fully qualified classname') if deploy_jar_rules and not isinstance(deploy_jar_rules, JarRules): raise TargetDefinitionException(self, 'deploy_jar_rules must be a JarRules specification. got {}' .format(type(deploy_jar_rules).__name__)) if manifest_entries and not isinstance(manifest_entries, dict): raise TargetDefinitionException(self, 'manifest_entries must be a dict. got {}' .format(type(manifest_entries).__name__)) payload = payload or Payload() payload.add_fields({ 'basename': PrimitiveField(basename or name), 'deploy_excludes': ExcludesField(self.assert_list(deploy_excludes, expected_type=Exclude, key_arg='deploy_excludes')), 'deploy_jar_rules': FingerprintedField(deploy_jar_rules or JarRules.default()), 'manifest_entries': FingerprintedField(ManifestEntries(manifest_entries)), 'main': PrimitiveField(main), 'shading_rules': PrimitiveField(shading_rules or ()), 'extra_jvm_options': PrimitiveField(list(extra_jvm_options or ())), }) super().__init__(name=name, address=address, payload=payload, sources=sources, **kwargs)
def __init__(self, address=None, payload=None, sources=None, provides=None, excludes=None, resources=None, services=None, platform=None, strict_deps=None, fatal_warnings=None, **kwargs): """ :param excludes: List of `exclude <#exclude>`_\s to filter this target's transitive dependencies against. :param sources: Source code files to build. Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` (from globs or rglobs) or list of strings :param services: A dict mapping service interface names to the classes owned by this target that implement them. Keys are fully qualified service class names, values are lists of strings, each string the fully qualified class name of a class owned by this target that implements the service interface and should be discoverable by the jvm service provider discovery mechanism described here: https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html :param platform: The name of the platform (defined under the jvm-platform subsystem) to use for compilation (that is, a key into the --jvm-platform-platforms dictionary). If unspecified, the platform will default to the first one of these that exist: (1) the default_platform specified for jvm-platform, (2) a platform constructed from whatever java version is returned by DistributionLocator.cached().version. :type platform: str :param strict_deps: When True, only the directly declared deps of the target will be used at compilation time. This enforces that all direct deps of the target are declared, and can improve compilation speed due to smaller classpaths. Transitive deps are always provided at runtime. :type strict_deps: bool :param fatal_warnings: Whether to turn warnings into errors for this target. If present, takes priority over the language's fatal-warnings option. :type fatal_warnings: bool """ self.address = address # Set in case a TargetDefinitionException is thrown early payload = payload or Payload() excludes = ExcludesField( self.assert_list(excludes, expected_type=Exclude, key_arg='excludes')) payload.add_fields({ 'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'), 'provides': provides, 'excludes': excludes, 'platform': PrimitiveField(platform), 'strict_deps': PrimitiveField(strict_deps), 'fatal_warnings': PrimitiveField(fatal_warnings), }) self._resource_specs = self.assert_list(resources, key_arg='resources') super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs) # Service info is only used when generating resources, it should not affect, for example, a # compile fingerprint or javadoc fingerprint. As such, its not a payload field. self._services = services or {} self.add_labels('jvm')