Class: PropertyManager
- Inherits:
-
Object
- Object
- PropertyManager
- Defined in:
- lib/mavenReactorService/PropertyManager.rb
Constant Summary collapse
- @@ppp_counter =
1- @@reactorHandler =
ReactorHandler.new
- @@modulePomPaths =
nil
Instance Method Summary collapse
- #isAvailableInParentPomProperties(parent_pom_properties, common_module_pom_property) ⇒ Object
- #removeCommonPropertiesfromModulePOMs(project_directory_path, commonProperties, parent_pom_properties) ⇒ Object
- #removeParentPropertiesfromModulePOMs(project_directory_path, parent_pom_properties) ⇒ Object
- #restructure(project_directory_path, parent_pom_path) ⇒ Object
- #writeToReactor(project_directory_path, commonProperties, reactorProperties, parent_pom_properties) ⇒ Object
Instance Method Details
#isAvailableInParentPomProperties(parent_pom_properties, common_module_pom_property) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mavenReactorService/PropertyManager.rb', line 128 def isAvailableInParentPomProperties (parent_pom_properties, common_module_pom_property) #Looping over parent POM properties and checking if that is present in one of the 'common module POM properties' # puts("Checking availability of common_module_pom_property in parent POM : #{common_module_pom_property}") parent_pom_properties.each do |parent_pom_property| if parent_pom_property == common_module_pom_property # puts("(#{@@ppp_counter}) !!! Matched !!! common_module_pom_property = #{common_module_pom_property}") # puts("parent_pom_property = #{parent_pom_property}") # puts("\n\n") @@ppp_counter += 1 return true end end return false end |
#removeCommonPropertiesfromModulePOMs(project_directory_path, commonProperties, parent_pom_properties) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mavenReactorService/PropertyManager.rb', line 89 def removeCommonPropertiesfromModulePOMs (project_directory_path,commonProperties,parent_pom_properties) @@modulePomPaths.each do |eachModulePath| pom_document = @@reactorHandler.parse_xml_from_file(eachModulePath) if !commonProperties.nil? commonProperties.each do |property| propNameValue = property.split(':_') propName = propNameValue[0] pom_document.css('project/properties').children.each do |eachProperty| if eachProperty.name == propName eachProperty.remove end end end File.write(eachModulePath,pom_document) end end removeParentPropertiesfromModulePOMs(project_directory_path,parent_pom_properties) end |
#removeParentPropertiesfromModulePOMs(project_directory_path, parent_pom_properties) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/mavenReactorService/PropertyManager.rb', line 109 def removeParentPropertiesfromModulePOMs(project_directory_path,parent_pom_properties) @@modulePomPaths.each do |eachModulePath| pom_document = @@reactorHandler.parse_xml_from_file(eachModulePath) if !parent_pom_properties.nil? parent_pom_properties.each do |property| propNameValue = property.split(':_') propName = propNameValue[0] pom_document.css('project/properties').children.each do |eachProperty| if eachProperty.name == propName eachProperty.remove end end end File.write(eachModulePath,pom_document) end end puts "Common properties removed from child modules!!!" end |
#restructure(project_directory_path, parent_pom_path) ⇒ Object
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mavenReactorService/PropertyManager.rb', line 7 def restructure(project_directory_path, parent_pom_path) @@modulePomPaths = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false) allModuleProperties = Array.new commonProperties = Array.new reactorProperties = Array.new @@modulePomPaths.each do |modulePomPath| modulePomDoc = Nokogiri::XML(open(modulePomPath)) amp_counter = 1 modulePomDoc.css("project/properties").children.each do |property| if property.name != 'text' && property.name != 'comment' propertyNameValue = "#{property.name}:_#{property.text}" allModuleProperties.push(propertyNameValue) # puts("(#{amp_counter}) allModuleProperty : #{propertyNameValue}") amp_counter += 1 end end puts("\n\n") end #Parsing Parent POM, pushing all the Properties tag into "parent_pom_properties". parent_pom_properties = Array.new parent_pom_doc = Nokogiri::XML(open(parent_pom_path)) pppnv_counter = 1 parent_pom_doc.css("project/properties").children.each do |parent_pom_property| if parent_pom_property.name != 'text' && parent_pom_property.name != 'comment' parent_pom_property_name_value = "#{parent_pom_property.name}:_#{parent_pom_property.text}" parent_pom_properties.push(parent_pom_property_name_value) # puts("(#{pppnv_counter}) parent_pom_property_name_value : #{parent_pom_property_name_value}") pppnv_counter += 1 end end puts("\n\n") # Assumption is : the Reactor POM will only contain properties, which are common to the Module POMs. # We will find Common properties between "Parent POM" and "Common Module POM" # They(Common Properties) can be excluded before we add them into the Reactor POM by the function isAvailableInParentPomProperties(parent_pom_properties, property). p_counter = 1 u_counter = 1 allModuleProperties.uniq.each do |property| # puts("(#{u_counter}) Unique Module Property : #{property}") u_counter += 1 if allModuleProperties.count(property) == @@modulePomPaths.length # puts("(#{p_counter}) Common Module Property : #{property}") p_counter += 1 commonProperties.push(property) if !isAvailableInParentPomProperties(parent_pom_properties, property) reactorProperties.push(property) end end end puts("\n\n") writeToReactor(project_directory_path,commonProperties,reactorProperties,parent_pom_properties) end |
#writeToReactor(project_directory_path, commonProperties, reactorProperties, parent_pom_properties) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mavenReactorService/PropertyManager.rb', line 67 def writeToReactor(project_directory_path,commonProperties,reactorProperties,parent_pom_properties) reactorPomPath = "#{project_directory_path}/pom.xml" pom_document = @@reactorHandler.parse_xml_from_file(reactorPomPath) nokObj = Nokogiri::XML::Node projectNode = pom_document.at('project') propertiesNode = nokObj.new('properties',projectNode) reactorProperties.each do |property| propNameValue = property.split(':_') propName = propNameValue[0] propValue = propNameValue[1] propNode = nokObj.new(propName,projectNode) propNode.content = propValue propertiesNode.add_child(propNode) end dependencyHandler = DependencyHandler.new pomObj = dependencyHandler.add_node_element('project',propertiesNode,pom_document) File.write(reactorPomPath,pomObj) puts "Moved common properties to reactor pom!!!" removeCommonPropertiesfromModulePOMs(project_directory_path,commonProperties,parent_pom_properties) end |