Beispiel #1
0
 def test_deploy_jar_excludes(self):
     target = self.make_target(
         ':foo',
         JvmBinary,
         main='com.example.Foo',
         deploy_excludes=[Exclude(org='example.com', name='foo-lib')])
     self.assertEquals([Exclude(org='example.com', name='foo-lib')],
                       target.deploy_excludes)
Beispiel #2
0
 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)
Beispiel #3
0
    def test_get_product_target_mappings_for_targets_intransitive(self):
        b = self.make_target('b',
                             JvmTarget,
                             excludes=[Exclude('com.example', 'lib')])
        a = self.make_target('a', JvmTarget, dependencies=[b])

        classpath_product = ClasspathProducts(self.pants_workdir)
        example_jar_path = self._example_jar_path()
        resolved_jar = self.add_jar_classpath_element_for_path(
            classpath_product, a, example_jar_path)

        classpath_product.add_for_target(
            b, [('default', self.path('b/loose/classes/dir'))])
        classpath_product.add_for_target(
            a, [('default', self.path('a/loose/classes/dir')),
                ('default', self.path('an/internally/generated.jar'))])

        classpath_target_tuples = classpath_product.get_product_target_mappings_for_targets(
            [a])
        self.assertEqual([
            (('default',
              ArtifactClasspathEntry(example_jar_path, resolved_jar.coordinate,
                                     resolved_jar.cache_path)), a),
            (('default', ClasspathEntry(self.path('a/loose/classes/dir'))), a),
            (('default',
              ClasspathEntry(self.path('an/internally/generated.jar'))), a)
        ], classpath_target_tuples)
Beispiel #4
0
 def _add_excludes_for_target(self, target):
     if isinstance(target, ExportableJvmLibrary) and target.provides:
         self._excludes.add_for_target(
             target, [Exclude(target.provides.org, target.provides.name)]
         )
     if isinstance(target, JvmTarget) and target.excludes:
         self._excludes.add_for_target(target, target.excludes)
    def test_classpath_by_targets(self):
        b = self.make_target('b', JvmTarget)
        a = self.make_target('a',
                             JvmTarget,
                             dependencies=[b],
                             excludes=[Exclude('com.example', 'lib')])

        classpath_products = ClasspathProducts(self.pants_workdir)

        path1 = self._path('jar/path1')
        path2 = self._path('jar/path2')
        path3 = os.path.join(self.pants_workdir, 'jar/path3')
        resolved_jar = ResolvedJar(M2Coordinate(org='com.example',
                                                name='lib',
                                                rev='1.0'),
                                   cache_path='somewhere',
                                   pants_path=path3)
        classpath_products.add_for_target(a, [('default', path1)])
        classpath_products.add_for_target(a, [('non-default', path2)])
        classpath_products.add_for_target(b, [('default', path2)])
        classpath_products.add_jars_for_targets([b], 'default', [resolved_jar])
        classpath_products.add_excludes_for_targets([a])

        # (a, path2) filtered because of conf
        # (b, path3) filtered because of excludes
        self.assertEqual(
            OrderedDict([(a, [ClasspathEntry(path1)]),
                         (b, [ClasspathEntry(path2)])]),
            ClasspathUtil.classpath_by_targets(a.closure(bfs=True),
                                               classpath_products))
Beispiel #6
0
    def test_get_artifact_classpath_entries_for_targets(self):
        b = self.make_target("b",
                             JvmTarget,
                             excludes=[Exclude("com.example", "lib")])
        a = self.make_target("a", JvmTarget, dependencies=[b])

        classpath_product = ClasspathProducts(self.pants_workdir)
        example_jar_path = self._example_jar_path()
        resolved_jar = self.add_jar_classpath_element_for_path(
            classpath_product, a, example_jar_path)

        # These non-artifact classpath entries should be ignored.
        classpath_product.add_for_target(
            b, [("default", self.path("b/loose/classes/dir"))])
        classpath_product.add_for_target(
            a,
            [
                ("default", self.path("a/loose/classes/dir")),
                ("default", self.path("an/internally/generated.jar")),
            ],
        )

        classpath = classpath_product.get_artifact_classpath_entries_for_targets(
            [a])
        self.assertEqual(
            [(
                "default",
                ArtifactClasspathEntry(example_jar_path,
                                       resolved_jar.coordinate,
                                       resolved_jar.cache_path),
            )],
            classpath,
        )
Beispiel #7
0
  def test_excludes_in_java_lib_excludes_all_from_jar_lib(self):
    junit_jar_lib = self._make_junit_target()

    excluding_target = self.make_target('//:b', JavaLibrary, sources=[],
                                        excludes=[Exclude('junit', 'junit')])
    compile_classpath = self.resolve([junit_jar_lib, excluding_target])

    junit_jar_cp = compile_classpath.get_for_target(junit_jar_lib)
    excluding_cp = compile_classpath.get_for_target(excluding_target)

    self.assertEqual(2, len(junit_jar_cp))
    self.assertEqual(0, len(excluding_cp))

    def get_coord_in_classpath(cp, targets):
      """
      Get the simple coords that are going to be on the classpath
      """
      conf_art_tuples_ex = cp.get_classpath_entries_for_targets(targets)
      simple_coords = {x[1].coordinate.simple_coord for x in conf_art_tuples_ex}
      return simple_coords

    # If we grab the transitive closure of the coordinates just for junit, then
    # both junit and hamcrest should be in it.
    simple_coords = get_coord_in_classpath(compile_classpath, [junit_jar_lib])
    self.assertIn('junit:junit:4.12', simple_coords)
    self.assertIn('org.hamcrest:hamcrest-core:1.3', simple_coords)

    # If we grab transitive closure of the coordinates for junit along with a JavaLibrary
    # target that excludes junit, then junit should not be on the classpath.
    simple_coords = get_coord_in_classpath(compile_classpath, [excluding_target, junit_jar_lib])
    self.assertNotIn('junit:junit:4.12', simple_coords)
    self.assertIn('org.hamcrest:hamcrest-core:1.3', simple_coords)
Beispiel #8
0
    def test_classpath_by_targets(self):
        b = self.make_target("b", JvmTarget)
        a = self.make_target("a",
                             JvmTarget,
                             dependencies=[b],
                             excludes=[Exclude("com.example", "lib")])

        classpath_products = ClasspathProducts(self.pants_workdir)

        path1 = self._path("jar/path1")
        path2 = self._path("jar/path2")
        path3 = os.path.join(self.pants_workdir, "jar/path3")
        resolved_jar = ResolvedJar(
            M2Coordinate(org="com.example", name="lib", rev="1.0"),
            cache_path="somewhere",
            pants_path=path3,
        )
        classpath_products.add_for_target(a, [("default", path1)])
        classpath_products.add_for_target(a, [("non-default", path2)])
        classpath_products.add_for_target(b, [("default", path2)])
        classpath_products.add_jars_for_targets([b], "default", [resolved_jar])
        classpath_products.add_excludes_for_targets([a])

        # (a, path2) filtered because of conf
        # (b, path3) filtered because of excludes
        self.assertEqual(
            OrderedDict([(a, [ClasspathEntry(path1)]),
                         (b, [ClasspathEntry(path2)])]),
            ClasspathUtil.classpath_by_targets(a.closure(bfs=True),
                                               classpath_products),
        )
  def test_copy(self):
    b = self.make_target('b', JvmTarget, excludes=[Exclude('com.example', 'lib')])
    a = self.make_target('a', JvmTarget, dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    resolved_jar = self.add_jar_classpath_element_for_path(classpath_product,
                                                           a,
                                                           self._example_jar_path())
    classpath_product.add_for_target(a, [('default', self.path('a/path'))])

    copied = classpath_product.copy()

    a_closure = a.closure(bfs=True)

    self.assertEqual([('default', resolved_jar.pants_path), ('default', self.path('a/path'))],
                     classpath_product.get_for_targets(a_closure))
    self.assertEqual([('default', resolved_jar.pants_path), ('default', self.path('a/path'))],
                     copied.get_for_targets(a_closure))

    self.add_excludes_for_targets(copied, b, a)
    self.assertEqual([('default', resolved_jar.pants_path), ('default', self.path('a/path'))],
                     classpath_product.get_for_targets(a_closure))
    self.assertEqual([('default', self.path('a/path'))],
                     copied.get_for_targets(a_closure))

    copied.add_for_target(b, [('default', self.path('b/path'))])
    self.assertEqual([('default', resolved_jar.pants_path), ('default', self.path('a/path'))],
                     classpath_product.get_for_targets(a_closure))
    self.assertEqual([('default', self.path('a/path')), ('default', self.path('b/path'))],
                     copied.get_for_targets(a_closure))
Beispiel #10
0
 def _mkjardep(self,
               org='foo',
               name='foo',
               excludes=(Exclude(org='example.com', name='foo-lib'), ),
               tpe=JarDependency,
               **kwargs):
     return tpe(org=org, name=name, excludes=excludes, **kwargs)
Beispiel #11
0
  def test_jvm_target_with_excludes_is_hashed(self):
    confs = ()
    strategy = CoursierResolveFingerprintStrategy(confs)

    target_with_excludes = self.make_target(':jvm-target', target_type=JvmTarget,
                                               excludes=[Exclude('org.some')])

    self.assertIsNotNone(strategy.compute_fingerprint(target_with_excludes))
Beispiel #12
0
 def collect_provide_excludes(tgt):
     if not (isinstance(tgt, ExportableJvmLibrary) and tgt.provides):
         return
     logger.debug(
         "Automatically excluding jar {}.{}, which is provided by {}".
         format(tgt.provides.org, tgt.provides.name, tgt))
     provide_excludes.add(
         Exclude(org=tgt.provides.org, name=tgt.provides.name))
Beispiel #13
0
 def _test_copy(self, original):
     # A no-op clone results in an equal object.
     self.assertEqual(original, original.copy())
     # Excludes included in equality.
     excludes_added = original.copy(excludes=[Exclude(org="com.blah", name="blah")])
     self.assertNotEqual(original, excludes_added)
     # Clones are equal with equal content.
     self.assertEqual(original.copy(rev="1.2.3"), original.copy(rev="1.2.3"))
Beispiel #14
0
 def _mkjardep(
     self,
     org="foo",
     name="foo",
     excludes=(Exclude(org="example.com", name="foo-lib"),),
     tpe=JarDependency,
     **kwargs,
 ):
     return tpe(org=org, name=name, excludes=excludes, **kwargs)
Beispiel #15
0
  def test_transitive_dependencies_excluded_classpath_element(self):
    b = self.make_target('b', JvmTarget, excludes=[Exclude('com.example', 'lib')])
    a = self.make_target('a', JvmTarget, dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_jar_classpath_element_for_path(classpath_product, a, self._example_jar_path())
    self.add_excludes_for_targets(classpath_product, b, a)

    classpath = classpath_product.get_for_target(a)
    self.assertEqual([], classpath)
Beispiel #16
0
    def test_deploy_jar_excludes(self):
        self.add_to_build_file(
            '', '''jvm_binary(
  name = "foo",
  main = "com.example.Foo",
  deploy_excludes=[exclude(org = "example.com", name = "foo-lib")],
)''')
        target = self.target(':foo')
        self.assertEqual([Exclude(org='example.com', name='foo-lib')],
                         target.deploy_excludes)
Beispiel #17
0
  def test_excludes_org_name(self):
    b = self.make_target('b', JvmTarget)
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example')], dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, b)
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
Beispiel #18
0
  def test_excludes_similar_org_name(self):
    b = self.make_target('b', JvmTarget)
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.exam')], dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, b)
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_targets(a.closure(bfs=True))

    self.assertEqual([('default', self._example_jar_path())], classpath)
Beispiel #19
0
  def test_excludes_used_across_targets(self):
    b = self.make_target('b', JvmTarget)
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example', 'lib')])

    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_example_jar_classpath_element_for(classpath_product, b)
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
Beispiel #20
0
  def test_intransitive_dependencies_excluded_classpath_element(self):
    b = self.make_target('b', JvmTarget, excludes=[Exclude('com.example', 'lib')])
    a = self.make_target('a', JvmTarget, dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    example_jar_path = self._example_jar_path()
    classpath_product.add_for_target(a, [('default', example_jar_path)])
    classpath_product.add_excludes_for_targets([a, b])

    intransitive_classpath = classpath_product.get_for_target(a)
    self.assertEqual([('default', example_jar_path)], intransitive_classpath)
Beispiel #21
0
  def test_excluded_classpath_element(self):
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example', 'lib')])

    classpath_product = ClasspathProducts(self.pants_workdir)
    example_jar_path = self._example_jar_path()
    self.add_jar_classpath_element_for_path(classpath_product, a, example_jar_path)
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
Beispiel #22
0
 def test_deploy_jar_excludes(self):
     self.add_to_build_file(
         "",
         """jvm_binary(
         name = "foo",
         main = "com.example.Foo",
         deploy_excludes=[exclude(org = "example.com", name = "foo-lib")],
         )""",
     )
     target = self.target(":foo")
     self.assertEqual([Exclude(org="example.com", name="foo-lib")], target.deploy_excludes)
Beispiel #23
0
  def test_excludes_in_java_lib_excludes_all_from_jar_lib(self):
    junit_jar_lib = self._make_junit_target()

    excluding_target = self.make_target('//:b', JavaLibrary, sources=[],
                                        excludes=[Exclude('junit', 'junit')])
    compile_classpath = self.resolve([junit_jar_lib, excluding_target])

    junit_jar_cp = compile_classpath.get_for_target(junit_jar_lib)
    excluding_cp = compile_classpath.get_for_target(excluding_target)

    self.assertEquals(0, len(junit_jar_cp))
    self.assertEquals(0, len(excluding_cp))
Beispiel #24
0
  def test_parent_excludes_ignored_for_resolving_child_target(self):
    b = self.make_target('b', JvmTarget)
    a = self.make_target('a', JvmTarget, dependencies=[b], excludes=[Exclude('com.example', 'lib')])

    example_jar_path = self._example_jar_path()
    classpath_product = ClasspathProducts(self.pants_workdir)
    self.add_jar_classpath_element_for_path(classpath_product, b, example_jar_path)
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_target(b)

    self.assertEqual([('default', example_jar_path)], classpath)
Beispiel #25
0
    def test_create_canonical_classpath(self):
        a = self.make_target('a/b', JvmTarget)

        jar_path = 'ivy/jars/org.x/lib/x-1.0.jar'
        classpath_products = ClasspathProducts(self.pants_workdir)

        resolved_jar = ResolvedJar(M2Coordinate(org='org', name='x',
                                                rev='1.0'),
                                   cache_path='somewhere',
                                   pants_path=self._create_file(jar_path))

        classpath_products.add_for_target(
            a, [('default', self._create_file('a.jar')),
                ('default', self._create_file('resources'))])
        classpath_products.add_jars_for_targets([a], 'default', [resolved_jar])

        with temporary_dir() as base_dir:
            self._test_canonical_classpath_helper(
                classpath_products, [a],
                base_dir, [
                    'a.b.b-0.jar',
                    'a.b.b-1',
                    'a.b.b-2.jar',
                ], {
                    'a.b.b-classpath.txt':
                    '{}/a.jar:{}/resources:{}/{}\n'.format(
                        self.pants_workdir, self.pants_workdir,
                        self.pants_workdir, jar_path)
                },
                excludes={Exclude(org='org', name='y')})

        # incrementally delete the resource dendendency
        classpath_products = ClasspathProducts(self.pants_workdir)
        classpath_products.add_for_target(
            a, [('default', self._create_file('a.jar'))])
        self._test_canonical_classpath_helper(
            classpath_products, [a], base_dir, [
                'a.b.b-0.jar',
            ],
            {'a.b.b-classpath.txt': '{}/a.jar\n'.format(self.pants_workdir)})

        # incrementally add another jar dependency
        classpath_products = ClasspathProducts(self.pants_workdir)
        classpath_products.add_for_target(
            a, [('default', self._create_file('a.jar')),
                ('default', self._create_file('b.jar'))])
        self._test_canonical_classpath_helper(
            classpath_products, [a], base_dir, ['a.b.b-0.jar', 'a.b.b-1.jar'],
            {
                'a.b.b-classpath.txt':
                '{}/a.jar:{}/b.jar\n'.format(self.pants_workdir,
                                             self.pants_workdir)
            })
Beispiel #26
0
  def test_jar_in_classpath_not_a_resolved_jar_ignored_by_excludes(self):
    b = self.make_target('b', JvmTarget)
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example')], dependencies=[b])

    example_jar_path = self._example_jar_path()

    classpath_product = ClasspathProducts(self.pants_workdir)
    classpath_product.add_for_target(b, [('default', example_jar_path)])
    self.add_excludes_for_targets(classpath_product, a)

    classpath = classpath_product.get_for_targets(a.closure(bfs=True))

    self.assertEqual([('default', example_jar_path)], classpath)
Beispiel #27
0
    def test_get_product_target_mappings_for_targets_respect_excludes(self):
        a = self.make_target("a",
                             JvmTarget,
                             excludes=[Exclude("com.example", "lib")])

        classpath_product = ClasspathProducts(self.pants_workdir)
        example_jar_path = self._example_jar_path()
        self.add_jar_classpath_element_for_path(classpath_product, a,
                                                example_jar_path)
        self.add_excludes_for_targets(classpath_product, a)

        classpath_by_product = classpath_product.get_product_target_mappings_for_targets(
            [a])

        self.assertEqual([], classpath_by_product)
Beispiel #28
0
  def test_get_product_target_mappings_for_targets_ignore_excludes(self):
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example', 'lib')])

    classpath_product = ClasspathProducts(self.pants_workdir)
    example_jar_path = self._example_jar_path()
    resolved_jar = self.add_jar_classpath_element_for_path(classpath_product, a, example_jar_path,
                                                           conf='fred-conf')
    self.add_excludes_for_targets(classpath_product, a)

    classpath_target_tuples = classpath_product.get_product_target_mappings_for_targets([a], respect_excludes=False)

    expected_entry = ArtifactClasspathEntry(example_jar_path,
                                            resolved_jar.coordinate,
                                            resolved_jar.cache_path)
    self.assertEqual([(('fred-conf', expected_entry), a)], classpath_target_tuples)
Beispiel #29
0
  def test_exclude_leaves_other_jars_unaffected(self):
    b = self.make_target('b', JvmTarget, excludes=[Exclude('com.example', 'lib')])
    a = self.make_target('a', JvmTarget, dependencies=[b])

    classpath_product = ClasspathProducts(self.pants_workdir)
    com_example_jar_path = self._example_jar_path()
    org_example_jar_path = self.path('ivy/jars/org.example/lib/123.4.jar')
    classpath_product.add_jars_for_targets([a], 'default',
                                          [resolved_example_jar_at(com_example_jar_path),
                                           resolved_example_jar_at(org_example_jar_path,
                                                                   org='org.example')])
    self.add_excludes_for_targets(classpath_product, b)

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([('default', org_example_jar_path)], classpath)
Beispiel #30
0
    def test_parent_exclude_excludes_dependency_jar(self):
        b = self.make_target("b", JvmTarget)
        a = self.make_target("a",
                             JvmTarget,
                             dependencies=[b],
                             excludes=[Exclude("com.example", "lib")])

        classpath_product = ClasspathProducts(self.pants_workdir)
        example_jar_path = self._example_jar_path()
        self.add_jar_classpath_element_for_path(classpath_product, b,
                                                example_jar_path)
        self.add_excludes_for_targets(classpath_product, b, a)

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([], classpath)