예제 #1
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))
예제 #2
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),
        )
예제 #3
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.assertEquals(OrderedDict([(a, [ClasspathEntry(path1)]),
                                   (b, [ClasspathEntry(path2)])]),
                      ClasspathUtil.classpath_by_targets(a.closure(bfs=True),
                                                         classpath_products))
예제 #4
0
  def test_excluded_classpath_element(self):
    a = self.make_target('a', JvmTarget, excludes=[Exclude('com.example', 'lib')])

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

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
예제 #5
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()
    classpath_product.add_for_target(b, [('default', self._example_jar_path())])
    classpath_product.add_excludes_for_targets([a])

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
예제 #6
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()
    classpath_product.add_for_target(b, [('default', self._example_jar_path())])
    classpath_product.add_excludes_for_targets([a])

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([], classpath)
  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)
예제 #8
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)
예제 #9
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')])

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

    classpath = classpath_product.get_for_target(b)

    self.assertEqual([('default', example_jar_path)], classpath)
예제 #10
0
  def test_jar_provided_exclude_with_similar_org(self):
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example.lib', '', Repository()))
    root = self.make_target('root', JvmTarget, dependencies=[provider])

    classpath_product = ClasspathProducts()
    classpath_product.add_for_target(root, [('default', self._example_jar_path())])
    classpath_product.add_excludes_for_targets([root, provider])

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([('default', self._example_jar_path())], classpath)
예제 #11
0
  def test_jar_provided_exclude_with_similar_name(self):
    # note exclude 'jars/com.example/l' should not match jars/com.example/lib/jars/123.4.jar
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example', 'li', Repository()))
    root = self.make_target('root', JvmTarget, dependencies=[provider])

    classpath_product = ClasspathProducts()
    classpath_product.add_for_target(root, [('default', self._example_jar_path())])
    classpath_product.add_excludes_for_targets([root, provider])

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([('default', self._example_jar_path())], classpath)
예제 #12
0
    def test_excluded_classpath_element(self):
        a = self.make_target('a',
                             JvmTarget,
                             excludes=[Exclude('com.example', 'lib')])

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

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([], classpath)
예제 #13
0
  def test_jar_provided_by_transitive_target_excluded(self):
    provider = self.make_target('provider', ExportableJvmLibrary,
                         provides=Artifact('com.example', 'lib', Repository()))
    consumer = self.make_target('consumer', JvmTarget)
    root = self.make_target('root', JvmTarget, dependencies=[provider, consumer])

    classpath_product = ClasspathProducts()
    classpath_product.add_for_target(consumer, [('default', self._example_jar_path())])
    classpath_product.add_excludes_for_targets([root, provider, consumer])

    classpath = classpath_product.get_for_target(root)

    self.assertEqual([], classpath)
예제 #14
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()
        classpath_product.add_for_target(
            b, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([a])

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([], classpath)
예제 #15
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()
    com_example_jar_path = self._example_jar_path()
    org_example_jar_path = os.path.join(self.build_root, 'ivy/jars/org.example/lib/123.4.jar')
    classpath_product.add_for_target(a, [('default', com_example_jar_path),
                                         ('default', org_example_jar_path)])
    classpath_product.add_excludes_for_targets([b])

    classpath = classpath_product.get_for_target(a)

    self.assertEqual([('default', org_example_jar_path)], classpath)
예제 #16
0
    def test_jar_provided_exclude_with_similar_org(self):
        provider = self.make_target('provider',
                                    ExportableJvmLibrary,
                                    provides=Artifact('com.example.lib', '',
                                                      Repository()))
        root = self.make_target('root', JvmTarget, dependencies=[provider])

        classpath_product = ClasspathProducts()
        classpath_product.add_for_target(
            root, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([root, provider])

        classpath = classpath_product.get_for_target(root)

        self.assertEqual([('default', self._example_jar_path())], classpath)
예제 #17
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()
        example_jar_path = self._example_jar_path()
        classpath_product.add_for_target(b, [('default', example_jar_path)])
        classpath_product.add_excludes_for_targets([a, b])

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([], classpath)
예제 #18
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()
        classpath_product.add_for_target(
            b, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([a])

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([], classpath)
예제 #19
0
    def test_jar_provided_exclude_with_similar_name(self):
        # note exclude 'jars/com.example/l' should not match jars/com.example/lib/jars/123.4.jar
        provider = self.make_target('provider',
                                    ExportableJvmLibrary,
                                    provides=Artifact('com.example', 'li',
                                                      Repository()))
        root = self.make_target('root', JvmTarget, dependencies=[provider])

        classpath_product = ClasspathProducts()
        classpath_product.add_for_target(
            root, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([root, provider])

        classpath = classpath_product.get_for_target(root)

        self.assertEqual([('default', self._example_jar_path())], classpath)
예제 #20
0
    def test_jar_provided_by_transitive_target_excluded(self):
        provider = self.make_target('provider',
                                    ExportableJvmLibrary,
                                    provides=Artifact('com.example', 'lib',
                                                      Repository()))
        consumer = self.make_target('consumer', JvmTarget)
        root = self.make_target('root',
                                JvmTarget,
                                dependencies=[provider, consumer])

        classpath_product = ClasspathProducts()
        classpath_product.add_for_target(
            consumer, [('default', self._example_jar_path())])
        classpath_product.add_excludes_for_targets([root, provider, consumer])

        classpath = classpath_product.get_for_target(root)

        self.assertEqual([], classpath)
예제 #21
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()
        com_example_jar_path = self._example_jar_path()
        org_example_jar_path = os.path.join(
            self.build_root, 'ivy/jars/org.example/lib/123.4.jar')
        classpath_product.add_for_target(a,
                                         [('default', com_example_jar_path),
                                          ('default', org_example_jar_path)])
        classpath_product.add_excludes_for_targets([b])

        classpath = classpath_product.get_for_target(a)

        self.assertEqual([('default', org_example_jar_path)], classpath)