def test_type_test_jar(self): with temporary_dir() as tmpdir: with open(os.path.join(tmpdir, 'pom.xml') , 'w') as pomfile: pomfile.write(dedent('''<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <groupId>com.example</groupId> <artifactId>base</artifactId> <description>A generic Square module.</description> <version>HEAD-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>dep1</artifactId> <type>foo</type> <version>1.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>dep2</artifactId> <type>test-jar</type> <version>1.2.3</version> </dependency> </dependencies> </project> ''')) # TODO(Eric Ayers): Right now, our builds expect a file in <rootdir>/parents/base/pom.xml os.makedirs(os.path.join(tmpdir, 'parents', 'base')) with open(os.path.join(tmpdir, 'parents', 'base', 'pom.xml'), 'w') as dep_mgmt_pom: dep_mgmt_pom.write(DEPENDENCY_MANAGEMENT_POM) df = squarepants.pom_handlers.DependencyInfo('pom.xml', rootdir=tmpdir) self.assertEquals({u'groupId' : 'com.example', u'artifactId' : 'dep1', u'type' : 'foo', u'exclusions' : [], u'version' : '1.0' }, df.dependencies[0]) self.assertEquals({u'groupId' : 'com.example', u'artifactId' : 'dep2', u'type' : 'test-jar', u'exclusions' : [], u'version' : '1.2.3' }, df.dependencies[1]) self.assertEquals(2, len(df.dependencies)) deps_from_pom = squarepants.pom_handlers.DepsFromPom(PomUtils.pom_provides_target(), rootdir=tmpdir) refs = deps_from_pom.build_pants_refs(df.dependencies) self.assertEquals("sjar(org='com.example', name='dep1', rev='1.0', ext='foo',)", refs[0]) # type test-jar gets transformed into a 'tests' classifier self.assertEquals("sjar(org='com.example', name='dep2', rev='1.2.3', classifier='tests',)", refs[1]) self.assertEquals(2, len(refs))
def test_is_third_party_dep(self): self.assertFalse(PomUtils.is_third_party_dep('bogus-dep'))
def test_parse_common_args(self): unprocessed = PomUtils.parse_common_args(['-ldebug', 'unused']) self.assertEquals(['unused'], unprocessed) self.assertTrue(logging.DEBUG, logging.getLogger().getEffectiveLevel())
def test_get_modules(self): top_modules = PomUtils.top_pom_content_handler() self.assertIsNotNone(top_modules)
def test_top_pom_content_handler(self): tpch = PomUtils.top_pom_content_handler() self.assertIsNotNone(tpch) self.assertIs(tpch, PomUtils.top_pom_content_handler())
def test_local_dep_targets(self): ldt = PomUtils.local_dep_targets() self.assertIsNotNone(ldt) self.assertIs(ldt, PomUtils.local_dep_targets()) # should be a singleton
def test_dependency_management_Finder(self): dmf = PomUtils.dependency_management_finder() self.assertIsNotNone(dmf) self.assertIs(dmf, PomUtils.dependency_management_finder()) # should be a singleton
def test_pom_provides_target(self): ppt = PomUtils.pom_provides_target() self.assertIsNotNone(ppt) self.assertIs(ppt, PomUtils.pom_provides_target()) # should be a singleton
def test_common_usage(self): # nothing really to test here, it just prints a message to sdout. PomUtils.common_usage()
def test_external_protos_content_handler(self): epch = PomUtils.external_protos_content_handler() self.assertIsNotNone(epch) self.assertIs(epch, PomUtils.external_protos_content_handler())
def test_third_party_dep_targets(self): tpdt = PomUtils.third_party_dep_targets() self.assertIsNotNone(tpdt) self.assertIs(tpdt, PomUtils.third_party_dep_targets())
def reset_caches(): """Reset the internal caches in some of the libraries used for BUILD file generation.""" PomUtils.reset_caches() squarepants.pom_handlers.reset_caches()
def setUp(self): self.maxDiff = None self._wd = os.getcwd() PomUtils.reset_caches()
def test_type_test_jar(self): with temporary_dir() as tmpdir: with open(os.path.join(tmpdir, 'pom.xml'), 'w') as pomfile: pomfile.write( dedent('''<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <groupId>com.example</groupId> <artifactId>base</artifactId> <description>A generic Square module.</description> <version>HEAD-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>dep1</artifactId> <type>foo</type> <version>1.0</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>dep2</artifactId> <type>test-jar</type> <version>1.2.3</version> </dependency> </dependencies> </project> ''')) # TODO(Eric Ayers): Right now, our builds expect a file in <rootdir>/parents/base/pom.xml os.makedirs(os.path.join(tmpdir, 'parents', 'base')) with open(os.path.join(tmpdir, 'parents', 'base', 'pom.xml'), 'w') as dep_mgmt_pom: dep_mgmt_pom.write(DEPENDENCY_MANAGEMENT_POM) df = squarepants.pom_handlers.DependencyInfo('pom.xml', rootdir=tmpdir) self.assertEquals( { u'groupId': 'com.example', u'artifactId': 'dep1', u'type': 'foo', u'exclusions': [], u'version': '1.0' }, df.dependencies[0]) self.assertEquals( { u'groupId': 'com.example', u'artifactId': 'dep2', u'type': 'test-jar', u'exclusions': [], u'version': '1.2.3' }, df.dependencies[1]) self.assertEquals(2, len(df.dependencies)) deps_from_pom = squarepants.pom_handlers.DepsFromPom( PomUtils.pom_provides_target(), rootdir=tmpdir) refs = deps_from_pom.build_pants_refs(df.dependencies) self.assertEquals( "sjar(org='com.example', name='dep1', rev='1.0', ext='foo',)", refs[0]) # type test-jar gets transformed into a 'tests' classifier self.assertEquals( "sjar(org='com.example', name='dep2', rev='1.2.3', classifier='tests',)", refs[1]) self.assertEquals(2, len(refs))
def test_is_local_dep(self): self.assertFalse(PomUtils.is_local_dep('bogus-dep'))
def test_is_external_dep(self): self.assertTrue(PomUtils.is_external_dep('bogus-dep'))
def setUp(self): self._orig_wd = os.getcwd() os.chdir(self.REPO_ROOT) PomUtils.reset_caches()
def setUp(self): PomUtils.reset_caches() logging.basicConfig()
def setUp(self): PomUtils.reset_caches()
def test_dependency_management_Finder(self): dmf = PomUtils.dependency_management_finder() self.assertIsNotNone(dmf) self.assertIs( dmf, PomUtils.dependency_management_finder()) # should be a singleton