def test_relocate_package(self): self.assertEqual(('com.foo.bar.**', '{}com.foo.bar.@1'.format(Shading.SHADE_PREFIX)), Shading.create_relocate_package('com.foo.bar')) self.assertEqual(('com.foo.bar.*', '{}com.foo.bar.@1'.format(Shading.SHADE_PREFIX)), Shading.create_relocate_package('com.foo.bar', recursive=False)) self.assertEqual(('com.foo.bar.**', '__p__.com.foo.bar.@1'), Shading.create_relocate_package('com.foo.bar', shade_prefix='__p__.'))
def test_relocate(self): self.assertEqual(('com.foo.bar.**', '{}com.foo.bar.@1'.format(Shading.SHADE_PREFIX)), Shading.create_relocate(from_pattern='com.foo.bar.**')) self.assertEqual(('com.foo.bar.**', '{}com.foo.bar.@1'.format('__my_prefix__.')), Shading.create_relocate(from_pattern='com.foo.bar.**', shade_prefix='__my_prefix__.')) self.assertEqual(('com.foo.bar.**', 'org.biz.baz.@1'.format('__my_prefix__.')), Shading.create_relocate(from_pattern='com.foo.bar.**', shade_prefix='__my_prefix__.', shade_pattern='org.biz.baz.@1'))
def test_relocate_package(self): self.assertEqual( ("com.foo.bar.**", "{}com.foo.bar.@1".format(Shading.SHADE_PREFIX)), Shading.create_relocate_package("com.foo.bar"), ) self.assertEqual( ("com.foo.bar.*", "{}com.foo.bar.@1".format(Shading.SHADE_PREFIX)), Shading.create_relocate_package("com.foo.bar", recursive=False), ) self.assertEqual( ("com.foo.bar.**", "__p__.com.foo.bar.@1"), Shading.create_relocate_package("com.foo.bar", shade_prefix="__p__."), )
def test_relocate(self): self.assertEqual( ('com.foo.bar.**', '{}com.foo.bar.@1'.format( Shading.SHADE_PREFIX)), Shading.create_relocate(from_pattern='com.foo.bar.**')) self.assertEqual( ('com.foo.bar.**', '{}com.foo.bar.@1'.format('__my_prefix__.')), Shading.create_relocate(from_pattern='com.foo.bar.**', shade_prefix='__my_prefix__.')) self.assertEqual( ('com.foo.bar.**', 'org.biz.baz.@1'.format('__my_prefix__.')), Shading.create_relocate(from_pattern='com.foo.bar.**', shade_prefix='__my_prefix__.', shade_pattern='org.biz.baz.@1'))
def register_options(cls, register): super(ErrorProne, cls).register_options(register) register('--skip', type=bool, help='Skip Error Prone.') register('--transitive', default=False, type=bool, help='Run Error Prone against transitive dependencies of targets ' 'specified on the command line.') register('--command-line-options', type=list, default=[], fingerprint=True, help='Command line options passed to Error Prone') register('--exclude-patterns', type=list, default=[], fingerprint=True, help='Patterns for targets to be excluded from analysis.') cls.register_jvm_tool(register, 'errorprone', classpath=[ JarDependency(org='com.google.errorprone', name='error_prone_core', rev='2.0.17'), ], main=cls._ERRORPRONE_MAIN, custom_rules=[ Shader.exclude_package('com.google.errorprone', recursive=True), Shading.create_exclude('*'), # https://github.com/pantsbuild/pants/issues/4288 ] )
def test_relocate(self): self.assertEqual( ("com.foo.bar.**", "{}com.foo.bar.@1".format(Shading.SHADE_PREFIX)), Shading.create_relocate(from_pattern="com.foo.bar.**"), ) self.assertEqual( ("com.foo.bar.**", "{}com.foo.bar.@1".format("__my_prefix__.")), Shading.create_relocate(from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__."), ) self.assertEqual( ("com.foo.bar.**", "org.biz.baz.@1".format("__my_prefix__.")), Shading.create_relocate( from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__.", shade_pattern="org.biz.baz.@1" ), )
def test_assemble_classes_in_meta_inf(self): input_jar = self.populate_input_jar('org/pantsbuild/tools/fake/Main.class', 'META-INF/versions/9/javax/xml/bind/ModuleInfo.class') rules = self.shader.assemble_binary_rules('org.pantsbuild.tools.fake.Main', input_jar) self.assertEqual(Shader.exclude_package('org.pantsbuild.tools.fake'), rules[0]) self.assertIn(Shader.exclude_package('javax', recursive=True), rules[1:]) self.assertNotIn(Shading.create_relocate('META-INF.versions.9.javax.xml.bind.*'), rules[1:])
def test_relocate(self): self.assertEqual( ("com.foo.bar.**", f"{Shading.SHADE_PREFIX}com.foo.bar.@1"), Shading.create_relocate(from_pattern="com.foo.bar.**"), ) self.assertEqual( ("com.foo.bar.**", "__my_prefix__.com.foo.bar.@1"), Shading.create_relocate(from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__."), ) self.assertEqual( ("com.foo.bar.**", "org.biz.baz.@1"), Shading.create_relocate( from_pattern="com.foo.bar.**", shade_prefix="__my_prefix__.", shade_pattern="org.biz.baz.@1", ), )
def register_options(cls, register): super(ErrorProne, cls).register_options(register) register('--skip', type=bool, help='Skip Error Prone.') register( '--transitive', default=False, type=bool, help='Run Error Prone against transitive dependencies of targets ' 'specified on the command line.') register('--command-line-options', type=list, default=[], fingerprint=True, help='Command line options passed to Error Prone') register('--exclude-patterns', type=list, default=[], fingerprint=True, help='Patterns for targets to be excluded from analysis.') cls.register_jvm_tool( register, 'errorprone', classpath=[ JarDependency(org='com.google.errorprone', name='error_prone_core', rev='2.0.17'), ], main=cls._ERRORPRONE_MAIN, custom_rules=[ Shader.exclude_package('com.google.errorprone', recursive=True), Shading.create_exclude( '*'), # https://github.com/pantsbuild/pants/issues/4288 ])
def test_rules_file(self): expected = [ "rule a.b.c.** d.e.f.@1\n", "rule a.*.b [email protected]\n", "rule x.y.z.** shaded.x.y.z.@1\n", "zap com.foo.bar.Main\n", "zap com.baz.*\n", "keep org.foobar.vegetable.Potato\n", "keep org.foobar.fruit.**\n", ] rules = [ Shading.create_relocate("a.b.c.**", "d.e.f.@1"), Shading.create_relocate("a.*.b", shade_prefix="shaded."), Shading.create_relocate_package("x.y.z", shade_prefix="shaded."), Shading.create_zap("com.foo.bar.Main"), Shading.create_zap_package("com.baz", recursive=False), Shading.create_keep("org.foobar.vegetable.Potato"), Shading.create_keep_package("org.foobar.fruit"), ] with self.shader.temporary_rules_file(rules) as fname: with open(fname, "r") as f: received = f.readlines() self.assertEqual(received, expected)
def test_rules_file(self): expected = [ 'rule a.b.c.** d.e.f.@1\n', 'rule a.*.b [email protected]\n', 'rule x.y.z.** shaded.x.y.z.@1\n', 'zap com.foo.bar.Main\n', 'zap com.baz.*\n', 'keep org.foobar.vegetable.Potato\n', 'keep org.foobar.fruit.**\n', ] rules = [ Shading.create_relocate('a.b.c.**', 'd.e.f.@1'), Shading.create_relocate('a.*.b', shade_prefix='shaded.'), Shading.create_relocate_package('x.y.z', shade_prefix='shaded.'), Shading.create_zap('com.foo.bar.Main'), Shading.create_zap_package('com.baz', recursive=False), Shading.create_keep('org.foobar.vegetable.Potato'), Shading.create_keep_package('org.foobar.fruit'), ] with self.shader.temporary_rules_file(rules) as fname: with open(fname, 'r') as f: received = f.readlines() self.assertEqual(received, expected)
def assert_exclude(from_pattern, to_pattern): self.assertEqual((from_pattern, to_pattern), Shading.create_exclude(from_pattern))
def test_keep_package(self): self.assertEqual(("keep", "com.foo.bar.**"), Shading.create_keep_package("com.foo.bar", True)) self.assertEqual(("keep", "com.foo.bar.*"), Shading.create_keep_package("com.foo.bar", False))
def test_shading_exclude_package(self): self.assertEqual(('com.foo.bar.**', 'com.foo.bar.@1'), Shading.create_exclude_package('com.foo.bar')) self.assertEqual(('com.foo.bar.*', 'com.foo.bar.@1'), Shading.create_exclude_package('com.foo.bar', recursive=False))
def test_keep_package(self): self.assertEqual(('keep', 'com.foo.bar.**'), Shading.create_keep_package('com.foo.bar', True)) self.assertEqual(('keep', 'com.foo.bar.*'), Shading.create_keep_package('com.foo.bar', False))
def test_shading_exclude_package(self): self.assertEqual(("com.foo.bar.**", "com.foo.bar.@1"), Shading.create_exclude_package("com.foo.bar")) self.assertEqual( ("com.foo.bar.*", "com.foo.bar.@1"), Shading.create_exclude_package("com.foo.bar", recursive=False) )