Beispiel #1
0
    def test_fingerprinted_field(self):
        class TestValue(FingerprintedMixin):
            def __init__(self, test_value):
                self.test_value = test_value

            def fingerprint(self):
                hasher = sha1()
                hasher.update(self.test_value)
                return hasher.hexdigest()

        field1 = TestValue('field1')
        field1_same = TestValue('field1')
        field2 = TestValue('field2')
        self.assertEquals(field1.fingerprint(), field1_same.fingerprint())
        self.assertNotEquals(field1.fingerprint(), field2.fingerprint())

        fingerprinted_field1 = FingerprintedField(field1)
        fingerprinted_field1_same = FingerprintedField(field1_same)
        fingerprinted_field2 = FingerprintedField(field2)
        self.assertEquals(fingerprinted_field1.fingerprint(),
                          fingerprinted_field1_same.fingerprint())
        self.assertNotEquals(fingerprinted_field1.fingerprint(),
                             fingerprinted_field2.fingerprint())
Beispiel #2
0
    def test_fingerprinted_field(self):
        class TestValue(FingerprintedMixin):
            def __init__(self, test_value):
                self.test_value = test_value

            def fingerprint(self):
                hasher = sha1()
                hasher.update(self.test_value)
                return hasher.hexdigest()

        field1 = TestValue("field1")
        field1_same = TestValue("field1")
        field2 = TestValue("field2")
        self.assertEquals(field1.fingerprint(), field1_same.fingerprint())
        self.assertNotEquals(field1.fingerprint(), field2.fingerprint())

        fingerprinted_field1 = FingerprintedField(field1)
        fingerprinted_field1_same = FingerprintedField(field1_same)
        fingerprinted_field2 = FingerprintedField(field2)
        self.assertEquals(fingerprinted_field1.fingerprint(), fingerprinted_field1_same.fingerprint())
        self.assertNotEquals(fingerprinted_field1.fingerprint(), fingerprinted_field2.fingerprint())
Beispiel #3
0
    def test_unimplemented_fingerprinted_field(self):
        class TestUnimplementedValue(FingerprintedMixin):
            pass

        with self.assertRaises(NotImplementedError):
            FingerprintedField(TestUnimplementedValue()).fingerprint()
Beispiel #4
0
    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)
Beispiel #5
0
    def test_jar_rules_field(self):
        field1 = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.SKIP)]))
        field1_same = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.SKIP)]))
        field2 = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.CONCAT)]))
        field3 = FingerprintedField(
            JarRules(rules=[Duplicate('bar', Duplicate.SKIP)]))
        field4 = FingerprintedField(
            JarRules(rules=[
                Duplicate('foo', Duplicate.SKIP),
                Duplicate('bar', Duplicate.SKIP)
            ]))
        field5 = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.SKIP),
                            Skip('foo')]))
        field6 = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.SKIP)],
                     default_dup_action=Duplicate.FAIL))
        field6_same = FingerprintedField(
            JarRules(rules=[Duplicate('foo', Duplicate.SKIP)],
                     default_dup_action=Duplicate.FAIL))
        field7 = FingerprintedField(JarRules(rules=[Skip('foo')]))
        field8 = FingerprintedField(JarRules(rules=[Skip('bar')]))
        field8_same = FingerprintedField(JarRules(rules=[Skip('bar')]))

        self.assertEquals(field1.fingerprint(), field1_same.fingerprint())
        self.assertEquals(field6.fingerprint(), field6_same.fingerprint())
        self.assertEquals(field8.fingerprint(), field8_same.fingerprint())
        self._assert_fingerprints_not_equal(
            [field1, field2, field3, field4, field5, field6, field7])
Beispiel #6
0
  def test_jar_rules_field(self):
    field1 = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP)]))
    field1_same = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP)]))
    field2 = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.CONCAT)]))
    field3 = FingerprintedField(JarRules(rules=[Duplicate('bar', Duplicate.SKIP)]))
    field4 = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP),
                                                Duplicate('bar', Duplicate.SKIP)]))
    field5 = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP), Skip('foo')]))
    field6 = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP)],
                                         default_dup_action=Duplicate.FAIL))
    field6_same = FingerprintedField(JarRules(rules=[Duplicate('foo', Duplicate.SKIP)],
                                              default_dup_action=Duplicate.FAIL))
    field7 = FingerprintedField(JarRules(rules=[Skip('foo')]))
    field8 = FingerprintedField(JarRules(rules=[Skip('bar')]))
    field8_same = FingerprintedField(JarRules(rules=[Skip('bar')]))

    self.assertEquals(field1.fingerprint(), field1_same.fingerprint())
    self.assertEquals(field6.fingerprint(), field6_same.fingerprint())
    self.assertEquals(field8.fingerprint(), field8_same.fingerprint())
    self._assert_fingerprints_not_equal([field1, field2, field3, field4, field5, field6, field7])
Beispiel #7
0
  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)