Class: PluginHandler
- Inherits:
-
Object
- Object
- PluginHandler
- Defined in:
- lib/mavenReactorService/PluginHandler.rb
Constant Summary collapse
- @@basicInfoHandler =
BasicInfoHandler.new
- @@dependencyHandler =
DependencyHandler.new
- @@reactorHandler =
ReactorHandler.new
- @@xpathOfPlugin =
nil
Instance Method Summary collapse
- #addBuildTag ⇒ Object
- #addReportingTag ⇒ Object
-
#compareWithGrandParentPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in grand parent.
-
#compareWithOriginalPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in original pom.
-
#compareWithParentPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in parent.
-
#createXpathOfTag(eachTag) ⇒ Object
create xpath of placeholder tag.
-
#getGrpAndArtifactIdOfPlugins(tagName = nil) ⇒ Object
make a list of plugins from effective pom.
-
#handlePlaceholder(eachPlugin, fullPlugin, pluginNode) ⇒ Object
handle placeholder operation.
- #removeExtraTag(tagName) ⇒ Object
-
#removePluginManagementTag ⇒ Object
remove pluginmanagement section.
-
#replaceTagValInTemp(fullPlugin, tagName, tagVal, pluginNode) ⇒ Object
introduce place holder if found in original, parent or grand parent.
Instance Method Details
#addBuildTag ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 97 def addBuildTag() efftive_pom_document = @@basicInfoHandler.copyTagsFromEffectivePom(Dir.getwd) allplugins = efftive_pom_document.at("project/build") if !allplugins.nil? tempXml = "temp.xml" File.write(tempXml, allplugins, File.size(tempXml), mode: 'a') puts "Plugins are added" end end |
#addReportingTag ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 108 def addReportingTag() efftive_pom_document = @@basicInfoHandler.copyTagsFromEffectivePom(Dir.getwd) allplugins = efftive_pom_document.at("project/reporting") if !allplugins.nil? tempXml = "temp.xml" File.write(tempXml, allplugins, File.size(tempXml), mode: 'a') puts "Reporting Plugins are added" end end |
#compareWithGrandParentPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in grand parent
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 218 def compareWithGrandParentPomPlugin(pluginList,tagName=nil) pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd) parent = pom_document.at("project/parent") if !parent.nil? parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(pom_document) grandParent = parent_pom_document.at("project/parent") if !grandParent.nil? grand_parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(parent_pom_document) temp_pom_document = @@reactorHandler.parse_xml_from_file("temp.xml") pluginNode = nil pomFilePluginNode = nil toAddPath=nil if tagName == "reporting" pluginNode = temp_pom_document.at("project/reporting/plugins") pomFilePluginNode = grand_parent_pom_document.css("project/reporting/plugins/plugin") toAddPath = "project/reporting" else pluginNode = temp_pom_document.at("project/build/plugins") pomFilePluginNode = grand_parent_pom_document.css("project/build/plugins/plugin") toAddPath = "project/build" end pomFilePluginNode.each do |eachPlugin| # issue-117 #grpId = eachPlugin.at("groupId").text if (!eachPlugin.at("groupId").nil? and eachPlugin.at("groupId").parent.name == "plugin") grpId = eachPlugin.at("groupId").text else grpId = "org.apache.maven.plugins" end artifactId = eachPlugin.at("artifactId").text fullPlugin = "#{grpId}:#{artifactId}" if pluginList.include?fullPlugin handlePlaceholder(eachPlugin,fullPlugin,pluginNode) end end formated_pom_doc = @@dependencyHandler.add_node_element(toAddPath,pluginNode,temp_pom_document) File.write("temp.xml", formated_pom_doc.to_xml) end end end |
#compareWithOriginalPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in original pom
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 145 def compareWithOriginalPomPlugin(pluginList,tagName=nil) pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd) temp_pom_document = @@reactorHandler.parse_xml_from_file("temp.xml") pluginNode = nil pomFilePluginNode = nil toAddPath=nil if tagName == "reporting" pluginNode = temp_pom_document.at("project/reporting/plugins") pomFilePluginNode = pom_document.css("project/reporting/plugins/plugin") toAddPath = "project/reporting" else pluginNode = temp_pom_document.at("project/build/plugins") pomFilePluginNode = pom_document.css("project/build/plugins/plugin") toAddPath = "project/build" end pomFilePluginNode.each do |eachPlugin| #grpId = eachPlugin.at("groupId").text grpId=nil if (!eachPlugin.at("groupId").nil? and eachPlugin.at("groupId").parent.name == "plugin") grpId = eachPlugin.at("groupId").text else grpId = "org.apache.maven.plugins" end artifactId = eachPlugin.at("artifactId").text fullPlugin = "#{grpId}:#{artifactId}" if pluginList.include?fullPlugin handlePlaceholder(eachPlugin,fullPlugin,pluginNode) end end formated_pom_doc = @@dependencyHandler.add_node_element(toAddPath,pluginNode,temp_pom_document) File.write("temp.xml", formated_pom_doc.to_xml) end |
#compareWithParentPomPlugin(pluginList, tagName = nil) ⇒ Object
findout the common plugin in parent
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 179 def compareWithParentPomPlugin(pluginList,tagName=nil) puts "Parent plugin placeholder replacement is started" pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd) parent = pom_document.at("project/parent") if !parent.nil? parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(pom_document) temp_pom_document = @@reactorHandler.parse_xml_from_file("temp.xml") pluginNode = nil pomFilePluginNode = nil toAddPath=nil if tagName == "reporting" pluginNode = temp_pom_document.at("project/reporting/plugins") pomFilePluginNode = parent_pom_document.css("project/reporting/plugins/plugin") toAddPath = "project/reporting" else pluginNode = temp_pom_document.at("project/build/plugins") pomFilePluginNode = parent_pom_document.css("project/build/plugins/plugin") toAddPath = "project/build" end pomFilePluginNode.each do |eachPlugin| #grpId = eachPlugin.at("groupId").text grpId=nil if (!eachPlugin.at("groupId").nil? and eachPlugin.at("groupId").parent.name == "plugin") grpId = eachPlugin.at("groupId").text else grpId = "org.apache.maven.plugins" end artifactId = eachPlugin.at("artifactId").text fullPlugin = "#{grpId}:#{artifactId}" if pluginList.include?fullPlugin handlePlaceholder(eachPlugin,fullPlugin,pluginNode) end end formated_pom_doc = @@dependencyHandler.add_node_element(toAddPath,pluginNode,temp_pom_document) File.write("temp.xml", formated_pom_doc.to_xml) end end |
#createXpathOfTag(eachTag) ⇒ Object
create xpath of placeholder tag
277 278 279 280 281 282 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 277 def createXpathOfTag(eachTag) if (eachTag.parent.name != "plugin") @@xpathOfPlugin = "#{eachTag.parent.name}/#{@@xpathOfPlugin}" createXpathOfTag(eachTag.parent) end end |
#getGrpAndArtifactIdOfPlugins(tagName = nil) ⇒ Object
make a list of plugins from effective pom
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 119 def getGrpAndArtifactIdOfPlugins(tagName=nil) temp_pom_document = Nokogiri::XML(open("temp.xml")) pluginList = Array.new buildPluginPath = "project/build/plugins/plugin" reportingPluginPath = "project/reporting/plugins/plugin" pluginNode = nil if (tagName == "reporting") pluginNode = temp_pom_document.css(reportingPluginPath) else pluginNode = temp_pom_document.css(buildPluginPath) end pluginNode.each do |eachPlugin| grpId=nil if (!eachPlugin.at("groupId").nil? and eachPlugin.at("groupId").parent.name == "plugin") grpId = eachPlugin.at("groupId").text else grpId = "org.apache.maven.plugins" end artifactId = eachPlugin.at("artifactId").text fullPlugin = "#{grpId}:#{artifactId}" pluginList.push(fullPlugin) end return pluginList end |
#handlePlaceholder(eachPlugin, fullPlugin, pluginNode) ⇒ Object
handle placeholder operation
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 260 def handlePlaceholder(eachPlugin,fullPlugin,pluginNode) eachPlugin.children.each do |eachTag| if (eachTag.children.length>1) handlePlaceholder(eachTag,fullPlugin,pluginNode) else pluginVal = eachTag.text plugintag = eachTag.name if (pluginVal.include?"${" and plugintag!="#cdata-section") @@xpathOfPlugin=nil createXpathOfTag(eachTag) replaceTagValInTemp(fullPlugin,plugintag,pluginVal,pluginNode) end end end end |
#removeExtraTag(tagName) ⇒ Object
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 20 def removeExtraTag(tagName) temp_pom_document = Nokogiri::XML(open("temp.xml")) buildNode = temp_pom_document.at("project/#{tagName}") if !buildNode.nil? srcDirectoryNode = buildNode.css("sourceDirectory") scriptSourceDirectoryNode = buildNode.css("scriptSourceDirectory") testSourceDirectoryNode = buildNode.css("testSourceDirectory") outputDirectoryNode = buildNode.css("outputDirectory") testOutputDirectoryNode = buildNode.css("testOutputDirectory") resourcesNode = buildNode.css("resources") testResourcesNode = buildNode.css("testResources") directoryNode = buildNode.css("directory") finalNameNode = buildNode.css("finalName") additionalClasspathElementsNode = buildNode.css("additionalClasspathElements") sortOrderFile = buildNode.css("sortOrderFile") if !srcDirectoryNode.nil? srcDirectoryNode.each do |eachSrcDirectory| eachSrcDirectory.remove end end if !scriptSourceDirectoryNode.nil? scriptSourceDirectoryNode.each do |eachScriptSourceDirectory| eachScriptSourceDirectory.remove end end if !testSourceDirectoryNode.nil? testSourceDirectoryNode.each do |eachTestSourceDirectory| eachTestSourceDirectory.remove end end if !outputDirectoryNode.nil? outputDirectoryNode.each do |eachOutputDirectory| eachOutputDirectory.remove end end if !testOutputDirectoryNode.nil? testOutputDirectoryNode.each do |eachTestOutputDirectory| eachTestOutputDirectory.remove end end if !resourcesNode.nil? resourcesNode.each do |eachResources| eachResources.remove end end if !testResourcesNode.nil? testResourcesNode.each do |eachTestResources| eachTestResources.remove end end if !directoryNode.nil? directoryNode.each do |eachDirectory| eachDirectory.remove end end if !finalNameNode.nil? finalNameNode.each do |eachFinalName| eachFinalName.remove end end if !additionalClasspathElementsNode.nil? additionalClasspathElementsNode.each do |eachAdditionalClasspathElements| eachAdditionalClasspathElements.remove end end if !sortOrderFile.nil? sortOrderFile.each do |eachSortOrderFile| eachSortOrderFile.remove end end formated_pom_doc = @@dependencyHandler.add_node_element("project",buildNode,temp_pom_document) File.write("temp.xml", formated_pom_doc) end end |
#removePluginManagementTag ⇒ Object
remove pluginmanagement section
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 7 def removePluginManagementTag() efftive_pom_document = @@basicInfoHandler.copyTagsFromEffectivePom(Dir.getwd) temp_pom_document = Nokogiri::XML(open("temp.xml")) buildNode = temp_pom_document.at("project/build") if !buildNode.nil? #If condition will come buildNode.at("pluginManagement").remove formated_pom_doc = @@dependencyHandler.add_node_element("project",buildNode,temp_pom_document) File.write("temp.xml", formated_pom_doc) puts "Plugins management is removed" end end |
#replaceTagValInTemp(fullPlugin, tagName, tagVal, pluginNode) ⇒ Object
introduce place holder if found in original, parent or grand parent
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/mavenReactorService/PluginHandler.rb', line 285 def replaceTagValInTemp(fullPlugin,tagName,tagVal,pluginNode) temp_pom_document = @@reactorHandler.parse_xml_from_file("temp.xml") pluginNode.css("plugin").each do |eachPlugin| grpId=nil if (!eachPlugin.at("groupId").nil? and eachPlugin.at("groupId").parent.name == "plugin") grpId = eachPlugin.at("groupId").text else grpId = "org.apache.maven.plugins" end artifactId = eachPlugin.at("artifactId").text tempFullPlugin = "#{grpId}:#{artifactId}" if (fullPlugin == tempFullPlugin) fullXpath = "#{@@xpathOfPlugin}#{tagName}" deleteNode = eachPlugin.at(fullXpath) deleteParent = deleteNode.parent deleteNode.remove nokObj = Nokogiri::XML::Node projectNode = temp_pom_document.at("project") tagNode = nokObj.new(tagName,projectNode) tagNode.content=tagVal deleteParent.add_child(tagNode) # eachPlugin.css("configuration").each do |eachConfig| # parentName = eachConfig.parent.name # if (parentName == "plugin") # eachConfig.remove # end # end pluginNode.add_child(eachPlugin) end end end |