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_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_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))
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)
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)
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)
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)
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)
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)
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)
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)
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)
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_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)
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)
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)
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)
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)
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)
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)