def test_missing_symlinked_jar_in_candidates(self): empty_symlink_map = {} result = IvyResolveResult(['non-existent-file-location'], empty_symlink_map, 'hash-name', {'default': self.ivy_report_path('ivy_utils_resources/report_with_diamond.xml') }) with self.assertRaises(IvyResolveMappingError): list(result.resolved_jars_for_each_target('default', [self.make_target('t', JarLibrary, jars=[JarDependency('org1', 'name1')]) ]))
def test_missing_hardlinked_jar_in_candidates(self): empty_hardlink_map = {} result = IvyResolveResult(['non-existent-file-location'], empty_hardlink_map, 'hash-name', {'default': self.ivy_report_path('ivy_utils_resources/report_with_diamond.xml') }) with self.assertRaises(IvyResolveMappingError): list(result.resolved_jars_for_each_target('default', [self.make_target('t', JarLibrary, jars=[JarDependency('org1', 'name1')]) ]))
def test_missing_symlinked_jar_in_candidates(self): empty_symlink_map = {} result = IvyResolveResult( ["non-existent-file-location"], empty_symlink_map, "hash-name", {"default": self.ivy_report_path("ivy_utils_resources/report_with_diamond.xml")}, ) with self.assertRaises(IvyResolveMappingError): list( result.resolved_jars_for_each_target( "default", [self.make_target("t", JarLibrary, jars=[JarDependency("org1", "name1")])] ) )
def test_missing_hardlinked_jar_in_candidates(self): empty_hardlink_map = {} result = IvyResolveResult( ["non-existent-file-location"], empty_hardlink_map, "hash-name", {"default": self.ivy_report_path("ivy_utils_resources/report_with_diamond.xml")}, ) with self.assertRaises(IvyResolveMappingError): list( result.resolved_jars_for_each_target( "default", [self.make_target("t", JarLibrary, jars=[JarDependency("org1", "name1")])], ) )
def test_resolve_conflicted(self): # Create jar_libraries with different versions of the same dep: this will cause # a pre-ivy "eviction" in IvyUtils.generate_ivy, but the same case can be triggered # due to an ivy eviction where the declared version loses to a transitive version. losing_dep = JarDependency('com.google.guava', 'guava', '16.0') winning_dep = JarDependency('com.google.guava', 'guava', '16.0.1') losing_lib = self.make_target('//:a', JarLibrary, jars=[losing_dep]) winning_lib = self.make_target('//:b', JarLibrary, jars=[winning_dep]) # Confirm that the same artifact was added to each target. context = self.context(target_roots=[losing_lib, winning_lib]) def artifact_path(name): return os.path.join(self.pants_workdir, 'ivy_artifact', name) def mock_ivy_info_for(conf): ivy_info = IvyInfo(conf) # Guava 16.0 would be evicted by Guava 16.0.1. But in a real # resolve, it's possible that before it was evicted, it would # generate some resolution data. artifact_1 = artifact_path('bogus0') unused_artifact = artifact_path('unused') # Because guava 16.0 was evicted, it has no artifacts. guava_0 = IvyModule( IvyModuleRef('com.google.guava', 'guava', '16.0'), None, []) guava_1 = IvyModule( IvyModuleRef('com.google.guava', 'guava', '16.0.1'), artifact_1, []) ivy_info.add_module(guava_0) ivy_info.add_module(guava_1) artifact_dep_1 = artifact_path('bogus1') # Because fake#dep 16.0 was evicted before it was resolved, # its deps are never examined, so we don't call add_module. guava_dep_0 = IvyModule( IvyModuleRef('com.google.fake', 'dep', '16.0.0'), None, [guava_0.ref]) guava_dep_1 = IvyModule( IvyModuleRef('com.google.fake', 'dep', '16.0.1'), artifact_dep_1, [guava_1.ref]) ivy_info.add_module(guava_dep_0) ivy_info.add_module(guava_dep_1) # Add an unrelated module to ensure that it's not returned. unrelated_parent = IvyModuleRef('com.google.other', 'parent', '1.0') unrelated = IvyModule( IvyModuleRef('com.google.unrelated', 'unrelated', '1.0'), unused_artifact, [unrelated_parent]) ivy_info.add_module(unrelated) return ivy_info symlink_map = { artifact_path('bogus0'): artifact_path('bogus0'), artifact_path('bogus1'): artifact_path('bogus1'), artifact_path('unused'): artifact_path('unused') } result = IvyResolveResult([], symlink_map, 'some-key-for-a-and-b', {}) result._ivy_info_for = mock_ivy_info_for def mock_ivy_resolve(*args, **kwargs): return result task = self.create_task(context, workdir='unused') task._ivy_resolve = mock_ivy_resolve task.execute() compile_classpath = context.products.get_data('compile_classpath', None) losing_cp = compile_classpath.get_for_target(losing_lib) winning_cp = compile_classpath.get_for_target(winning_lib) self.assertEqual(losing_cp, winning_cp) self.assertEqual( OrderedSet([(u'default', artifact_path(u'bogus0')), (u'default', artifact_path(u'bogus1'))]), winning_cp)
def test_resolve_conflicted(self): # Create jar_libraries with different versions of the same dep: this will cause # a pre-ivy "eviction" in IvyUtils.generate_ivy, but the same case can be triggered # due to an ivy eviction where the declared version loses to a transitive version. losing_dep = JarDependency('com.google.guava', 'guava', '16.0') winning_dep = JarDependency('com.google.guava', 'guava', '16.0.1') losing_lib = self.make_target('//:a', JarLibrary, jars=[losing_dep]) winning_lib = self.make_target('//:b', JarLibrary, jars=[winning_dep]) # Confirm that the same artifact was added to each target. context = self.context(target_roots=[losing_lib, winning_lib]) def artifact_path(name): return os.path.join(self.pants_workdir, 'ivy_artifact', name) def mock_ivy_info_for(conf): ivy_info = IvyInfo(conf) # Guava 16.0 would be evicted by Guava 16.0.1. But in a real # resolve, it's possible that before it was evicted, it would # generate some resolution data. artifact_1 = artifact_path('bogus0') unused_artifact = artifact_path('unused') # Because guava 16.0 was evicted, it has no artifacts. guava_0 = IvyModule(IvyModuleRef('com.google.guava', 'guava', '16.0'), None, []) guava_1 = IvyModule(IvyModuleRef('com.google.guava', 'guava', '16.0.1'), artifact_1, []) ivy_info.add_module(guava_0) ivy_info.add_module(guava_1) artifact_dep_1 = artifact_path('bogus1') # Because fake#dep 16.0 was evicted before it was resolved, # its deps are never examined, so we don't call add_module. guava_dep_0 = IvyModule(IvyModuleRef('com.google.fake', 'dep', '16.0.0'), None, [guava_0.ref]) guava_dep_1 = IvyModule(IvyModuleRef('com.google.fake', 'dep', '16.0.1'), artifact_dep_1, [guava_1.ref]) ivy_info.add_module(guava_dep_0) ivy_info.add_module(guava_dep_1) # Add an unrelated module to ensure that it's not returned. unrelated_parent = IvyModuleRef('com.google.other', 'parent', '1.0') unrelated = IvyModule(IvyModuleRef('com.google.unrelated', 'unrelated', '1.0'), unused_artifact, [unrelated_parent]) ivy_info.add_module(unrelated) return ivy_info symlink_map = {artifact_path('bogus0'): artifact_path('bogus0'), artifact_path('bogus1'): artifact_path('bogus1'), artifact_path('unused'): artifact_path('unused')} result = IvyResolveResult([], symlink_map, 'some-key-for-a-and-b', {}) result._ivy_info_for= mock_ivy_info_for def mock_ivy_resolve(*args, **kwargs): return result task = self.create_task(context, workdir='unused') task._ivy_resolve = mock_ivy_resolve task.execute() compile_classpath = context.products.get_data('compile_classpath', None) losing_cp = compile_classpath.get_for_target(losing_lib) winning_cp = compile_classpath.get_for_target(winning_lib) self.assertEquals(losing_cp, winning_cp) self.assertEquals(OrderedSet([(u'default', artifact_path(u'bogus0')), (u'default', artifact_path(u'bogus1'))]), winning_cp)