def modularize(pomPath, newModuleName): #create new directory os.mkdir(pomPath+'/'+newModuleName) #copy everything but the pom for f in os.listdir(pomPath) : if f != 'pom.xml' and f != newModuleName: shutil.copytree(pomPath + '/' + f, pomPath + '/' + newModuleName + '/' + f) #create the new pom #merge plugins and dependencies pm = Pom() pmOrig = Pom(pomPath+'/pom.xml') head = pmOrig.getHead() pm.provideHead(head['groupId'] + '.' + head['artifactId'],newModuleName, head['version'], head['name'], head['packaging'], head['url']) pm.addPlugins(pmOrig.getPlugins()) pm.addDependencies(pmOrig.getDependencies()) pm.writeOut(pomPath + '/' + newModuleName + '/pom.xml') #change header of supoerpom and add modules pmOrig.provideHead(head['groupId'], head['artifactId'], head['version'], head['name'], 'pom', head['url']) newModule = pmOrig.buildModule(newModuleName) pmOrig.addModules([newModule]) pmOrig.writeOut() pass
print newP2.toxml() def testMerge(): newP3 = Pom('pom.xml') newModule = newP3.buildModule('myModule') newP3.addModules([newModule]) newP3.writeOut() if __name__ == '__main__': newP = Pom() st = newP.toxml() assert (st.count(expected) == 1) #set the header newP.provideHead('org.twitterNotifier', 'twitterNotifier', '0.1-SNAPSHOT','','','') st = newP.toxml() assert(st.count('org.twitterNotifier') > 0) assert(st.count('0.1-SNAPSHOT') > 0) assert(st.count('4.0.0') > 0) #reset the header newP.provideHead('org.whateverelse', 'whateverelse', '1.0','','','') st = newP.toxml() #print(st) assert(st.count('org.whateverelse') > 0) assert(st.count('whateverelse') > 0) assert(st.count('1.0') > 0)