Class: MoveDistributionManagement
- Inherits:
-
Object
- Object
- MoveDistributionManagement
- Defined in:
- lib/mavenReactorService/MoveDistributionManagement.rb
Constant Summary collapse
- @@reactorHandler =
ReactorHandler.new
- @@modulePomPaths =
nil
Instance Method Summary collapse
- #moveDistributionManagementFromFirstModule(project_directory_path, externalPomUrl) ⇒ Object
- #removeDistributionManagementFromModules ⇒ Object
- #writeDistributionManagementInReactorPom(project_directory_path, distMgmtTag) ⇒ Object
Instance Method Details
#moveDistributionManagementFromFirstModule(project_directory_path, externalPomUrl) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mavenReactorService/MoveDistributionManagement.rb', line 4 def moveDistributionManagementFromFirstModule (project_directory_path,externalPomUrl) distMgmtFlag = true @@modulePomPaths = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false) if (!externalPomUrl.nil?) begin Nokogiri::HTML(open(externalPomUrl)) #This is to validate the url rescue raise "Parent POM URL is not valid !!!" end pomDoc = Nokogiri::XML(open("#{externalPomUrl}")) if !pomDoc.at("project/distributionManagement").nil? distMgmtFlag = false removeDistributionManagementFromModules() else firstModulePomDoc = Nokogiri::XML(open("#{@@modulePomPaths[0]}")) distMgmtTag = firstModulePomDoc.at("project/distributionManagement") writeDistributionManagementInReactorPom(project_directory_path,distMgmtTag) removeDistributionManagementFromModules() end else firstModulePomDoc = Nokogiri::XML(open("#{@@modulePomPaths[0]}")) distMgmtTag = firstModulePomDoc.at("project/distributionManagement") writeDistributionManagementInReactorPom(project_directory_path,distMgmtTag) removeDistributionManagementFromModules() end pom_document = @@reactorHandler.parse_xml_from_file("#{project_directory_path}/pom.xml") if distMgmtFlag and pom_document.at("project/distributionManagement").nil? comment = " TODO: There is no <distributionManagement> defined for this reactor project. Please add this section before taking into production." modulesNode = pom_document.at("project/modules") commentNode = Nokogiri::XML::Comment.new(pom_document,comment) modulesNode.add_next_sibling(commentNode) dependencyHandler = DependencyHandler.new pomObj = dependencyHandler.add_node_element('project',modulesNode,pom_document) File.write("#{project_directory_path}/pom.xml",pomObj) mvnReactorization = MvnReactorization.new mvnReactorization.generateFormatedXml(project_directory_path) end end |
#removeDistributionManagementFromModules ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/mavenReactorService/MoveDistributionManagement.rb', line 59 def removeDistributionManagementFromModules() @@modulePomPaths.each do |modulePom| pom_document = @@reactorHandler.parse_xml_from_file(modulePom) distMgmtNode = pom_document.at('project/distributionManagement') distMgmtNode.remove if !distMgmtNode.nil? File.write(modulePom,pom_document) end puts "distributionManagement removed from child modules!!!" end |
#writeDistributionManagementInReactorPom(project_directory_path, distMgmtTag) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mavenReactorService/MoveDistributionManagement.rb', line 43 def writeDistributionManagementInReactorPom (project_directory_path,distMgmtTag) if !distMgmtTag.nil? reactorPomPath = "#{project_directory_path}/pom.xml" pom_document = @@reactorHandler.parse_xml_from_file(reactorPomPath) comment = " TODO: The reactor service had moved the <distributionManagement> section of first project to reactor\'s POM and removed from all the child modules. Please review this section before deploying these artifacts" commentNode = Nokogiri::XML::Comment.new(pom_document,comment) distMgmtTag.first_element_child.before(commentNode) dependencyHandler = DependencyHandler.new pomObj = dependencyHandler.add_node_element('project',distMgmtTag,pom_document) File.write(reactorPomPath,pomObj) mvnReactorization = MvnReactorization.new mvnReactorization.generateFormatedXml(project_directory_path) puts "Moved distributionManagement to reactor pom!!!" end end |