def test_format_jar_deps_symbols(self): with temporary_dir() as temp_path: parent_pom_contents = """<?xml version="1.0" encoding="UTF-8"?> <project> <groupId>com.example</groupId> <artifactId>mock-parent</artifactId> <version>HEAD-SNAPSHOT</version> <properties> <foo>1.2.3</foo> </properties> </project> """ mock_parent_pom_filename = os.path.join(temp_path, 'pom.xml') with open(mock_parent_pom_filename, 'w') as f: f.write(parent_pom_contents) mock_path = os.path.join(temp_path, 'mock-project') os.mkdir(mock_path) mock_pom_filename = os.path.join(mock_path, 'pom.xml') pom_contents = """<?xml version="1.0" encoding="UTF-8"?> <project> <groupId>com.example</groupId> <artifactId>mock</artifactId> <version>HEAD-SNAPSHOT</version> <parent> <groupId>com.example</groupId> <artifactId>mock-project</artifactId> <version>HEAD-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> </project> """ with open(mock_pom_filename, 'w') as f: f.write(pom_contents) mock_pom_file = PomFile(mock_pom_filename) formatted_library = JarFilesMixin.format_jar_library( 'jar_files', ["jar(org='square', name='foobar', rev='${foo}')"], pom_file=mock_pom_file) self.assertEquals( dedent(''' jar_library(name='jar_files', jars=[ jar(org='square', name='foobar', rev='1.2.3') ], ) '''), formatted_library)
def XXXtest_simple_pom_file(self): with temporary_dir() as temp_path: parent_pom_contents = """<?xml version="1.0" encoding="UTF-8"?> <project> <groupId>com.example</groupId> <artifactId>mock-parent</artifactId> <version>HEAD-SNAPSHOT</version> <properties> <foo>1.2.3</foo> </properties> </project> """ mock_parent_pom_filename = os.path.join(temp_path, 'pom.xml') with open(mock_parent_pom_filename, 'w') as f: f.write(parent_pom_contents) mock_path = os.path.join(temp_path, 'mock-project') os.mkdir(mock_path) mock_pom_filename = os.path.join(mock_path, 'pom.xml') pom_contents = """<?xml version="1.0" encoding="UTF-8"?> <project> <groupId>com.example</groupId> <artifactId>mock</artifactId> <version>HEAD-SNAPSHOT</version> <parent> <groupId>com.example</groupId> <artifactId>mock-project</artifactId> <version>HEAD-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> </project> """ with open(mock_pom_filename, 'w') as f: f.write(pom_contents) mock_pom_file = PomFile(mock_pom_filename) self.assertEquals(mock_path, mock_pom_file.properties['project.basedir']) self.assertEquals('1.2.3', mock_pom_file.properties['foo']) parent_pom_file = mock_pom_file.parent self.assertEquals(temp_path, parent_pom_file.properties['project.basedir'])
def test_resolve_properties(self): substitute = GenerationUtils.symbol_substitution with temporary_dir() as tmpdir: with open(os.path.join(tmpdir, 'pom.xml'), 'w') as root_pom_file: root_pom_file.write(self.ROOT_POM) pom_file = PomFile('pom.xml', root_directory=tmpdir) self.assertEquals( 'FOOBAR', substitute(pom_file.properties, '${prop.foo}${prop.bar}')) self.assertEquals('FOO-BAZ', substitute(pom_file.properties, '${prop.baz}')) deps = [{'key1': 'key1-${prop.foo}'}, {'key2': 'key2-${prop.bar}'}] deps = GenerationUtils.symbol_substitution_on_dicts( pom_file.properties, deps) self.assertEquals([{ 'key1': 'key1-FOO' }, { 'key2': 'key2-BAR' }], deps)
def test_no_parent(self): # make sure properties are substituted with temporary_file() as mock_pom_filename: pom_contents = """<?xml version="1.0" encoding="UTF-8"?> <project> <groupId>com.example</groupId> <artifactId>mock</artifactId> <version>HEAD-SNAPSHOT</version> <properties> <foo>1.2.3</foo> </properties> </project> """ with open(mock_pom_filename, 'w') as f: f.write(pom_contents) mock_pom_file = PomFile(mock_pom_filename) self.assertEquals(None, mock_pom_file.parent) self.assertEquals('1.2.3', mock_pom_file.properties['foo'])