mavenReactorService 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/mavenReactorization +7 -0
- data/bin/setup +8 -0
- data/lib/mavenReactorService.rb +5 -0
- data/lib/mavenReactorService/BasicInfoHandler.rb +173 -0
- data/lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb +205 -0
- data/lib/mavenReactorService/DependencyHandler.rb +264 -0
- data/lib/mavenReactorService/DependencyManagementHandler.rb +183 -0
- data/lib/mavenReactorService/DeveloperAndContributors.rb +130 -0
- data/lib/mavenReactorService/InterDependencyHandler.rb +87 -0
- data/lib/mavenReactorService/MergeRepository.rb +98 -0
- data/lib/mavenReactorService/MoveCommonPropertiesToRootPom.rb +83 -0
- data/lib/mavenReactorService/MoveDistributionManagement.rb +68 -0
- data/lib/mavenReactorService/MvnReactorization.rb +209 -0
- data/lib/mavenReactorService/ParentPomHandler.rb +71 -0
- data/lib/mavenReactorService/PluginConfigurationHandler.rb +106 -0
- data/lib/mavenReactorService/PluginHandler.rb +292 -0
- data/lib/mavenReactorService/PluginManagementHandler.rb +391 -0
- data/lib/mavenReactorService/PropertyHandler.rb +129 -0
- data/lib/mavenReactorService/ReactorCommands.rb +49 -0
- data/lib/mavenReactorService/ReactorHandler.rb +309 -0
- data/lib/mavenReactorService/SiteAndEclipsePluginHandler.rb +105 -0
- data/lib/mavenReactorService/ValidateProjects.rb +70 -0
- data/lib/mavenReactorService/version.rb +3 -0
- data/mavenReactorService.gemspec +39 -0
- metadata +146 -0
@@ -0,0 +1,391 @@
|
|
1
|
+
class PluginManagementHandler
|
2
|
+
@@reactorHandler = ReactorHandler.new
|
3
|
+
@@dependencyHandler = DependencyHandler.new
|
4
|
+
@@mvnReactorization = MvnReactorization.new
|
5
|
+
def handlePluginManagement(project_dir)
|
6
|
+
commonPluginList = findCommonPlugins(project_dir)
|
7
|
+
putCommonPluginInReactorPom(project_dir,commonPluginList)
|
8
|
+
removePluginversionFromChildModule(project_dir,commonPluginList,"/plugins")
|
9
|
+
removePluginversionFromChildModule(project_dir,commonPluginList,"/pluginManagement/")
|
10
|
+
end
|
11
|
+
|
12
|
+
def findCommonPlugins(project_dir)
|
13
|
+
pomArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_dir,false)
|
14
|
+
if !(pomArr.nil? || pomArr.empty?)
|
15
|
+
allPluginList = Array.new
|
16
|
+
allPluginManagementList = Array.new
|
17
|
+
masterList = Array.new
|
18
|
+
pomArr.each do |eachPomPath|
|
19
|
+
pom_document = @@reactorHandler.parse_xml_from_file(eachPomPath)
|
20
|
+
pluginList = findAllPluginsOfAProject(pom_document,"project/build/plugins/plugin")
|
21
|
+
allPluginList.push(pluginList.uniq)
|
22
|
+
pluginManagementList = findAllPluginsOfAProject(pom_document,"project/build/pluginManagement/plugins/plugin")
|
23
|
+
allPluginManagementList.push(pluginManagementList.uniq)
|
24
|
+
mergedList = mergePlugins(pluginList,pluginManagementList)
|
25
|
+
filterList = addVersionOfMergedList(pom_document,mergedList)
|
26
|
+
masterList.push(filterList.uniq)
|
27
|
+
end
|
28
|
+
commonDependencyList = findCommonPluginsFromMasterList(masterList)
|
29
|
+
return commonDependencyList
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def findCommonPluginsFromMasterList(masterList)
|
34
|
+
commonDependencyList = Array.new
|
35
|
+
masterList.each_with_index do |eachPomDependencyList,index|
|
36
|
+
if index==0
|
37
|
+
commonDependencyList = eachPomDependencyList
|
38
|
+
else
|
39
|
+
commonDependencyList = commonDependencyList & eachPomDependencyList
|
40
|
+
end
|
41
|
+
end
|
42
|
+
return commonDependencyList
|
43
|
+
end
|
44
|
+
|
45
|
+
def findAllPluginsOfAProject(pom_document,tag)
|
46
|
+
commonPluginArr = Array.new
|
47
|
+
pom_document.css(tag).each do |eachPlugin|
|
48
|
+
grpId=nil
|
49
|
+
if (eachPlugin.at("groupId").nil?)
|
50
|
+
grpId="org.apache.maven.plugins"
|
51
|
+
else
|
52
|
+
grpId = eachPlugin.at("groupId").text
|
53
|
+
end
|
54
|
+
artifactId = eachPlugin.at("artifactId").text
|
55
|
+
version=nil
|
56
|
+
if (!eachPlugin.at("version").nil? and eachPlugin.at("version").parent.name=="plugin")
|
57
|
+
version = eachPlugin.at("version").text
|
58
|
+
end
|
59
|
+
fullArtifactId = "#{grpId}:#{artifactId}:#{version}"
|
60
|
+
if !(commonPluginArr.include?fullArtifactId)
|
61
|
+
commonPluginArr.push(fullArtifactId)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return commonPluginArr
|
65
|
+
end
|
66
|
+
|
67
|
+
def mergePlugins(allPluginList,allPluginManagementList)
|
68
|
+
pluginListWithoutVersion = Array.new
|
69
|
+
pluginManagementListWithoutVersion = Array.new
|
70
|
+
allPluginList.each do |eachPlugin|
|
71
|
+
eachPluginArr = eachPlugin.split(":")
|
72
|
+
cordinatePlugin = "#{eachPluginArr[0]}:#{eachPluginArr[1]}"
|
73
|
+
pluginListWithoutVersion.push(cordinatePlugin)
|
74
|
+
end
|
75
|
+
allPluginManagementList.each do |eachPlugin|
|
76
|
+
eachPluginArr = eachPlugin.split(":")
|
77
|
+
cordinatePlugin = "#{eachPluginArr[0]}:#{eachPluginArr[1]}"
|
78
|
+
pluginManagementListWithoutVersion.push(cordinatePlugin)
|
79
|
+
end
|
80
|
+
commonPluginList = pluginListWithoutVersion & pluginManagementListWithoutVersion
|
81
|
+
uncommonPluginList = (pluginListWithoutVersion+pluginManagementListWithoutVersion) - (pluginListWithoutVersion&pluginManagementListWithoutVersion)
|
82
|
+
mergedList = commonPluginList + uncommonPluginList
|
83
|
+
return mergedList
|
84
|
+
end
|
85
|
+
|
86
|
+
def addVersionOfMergedList(pom_document,mergedList)
|
87
|
+
filterMergedList = Array.new
|
88
|
+
mergedList.each do |eachEntry|
|
89
|
+
pluginNode = pom_document.css ("project/build/plugins/plugin")
|
90
|
+
pluginManagementNode = pom_document.css ("project/build/pluginManagement/plugins/plugin")
|
91
|
+
plugins = findVersionFromPlugin(eachEntry,pluginNode,pom_document)
|
92
|
+
if plugins.nil?
|
93
|
+
plugins = findVersionFromPlugin(eachEntry,pluginManagementNode,pom_document)
|
94
|
+
end
|
95
|
+
filterMergedList.push(plugins)
|
96
|
+
end
|
97
|
+
return filterMergedList
|
98
|
+
end
|
99
|
+
|
100
|
+
def findVersionFromPlugin(eachEntry,nodeObj,pom_document)
|
101
|
+
cordinatedependency = nil
|
102
|
+
nodeObj.each do |eachNode|
|
103
|
+
grpId=nil
|
104
|
+
if (eachNode.at("groupId").nil?)
|
105
|
+
grpId="org.apache.maven.plugins"
|
106
|
+
else
|
107
|
+
grpId = eachNode.at("groupId").text
|
108
|
+
end
|
109
|
+
artifactId = eachNode.at("artifactId").text
|
110
|
+
fullDependency = "#{grpId}:#{artifactId}"
|
111
|
+
if fullDependency == eachEntry
|
112
|
+
if (eachNode.at("version") and eachNode.at("version").parent.name == "plugin")
|
113
|
+
version = eachNode.at("version").text
|
114
|
+
if version.include?"${"
|
115
|
+
version = findPropValue(version,pom_document)
|
116
|
+
end
|
117
|
+
cordinatedependency = "#{fullDependency}:#{version}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
return cordinatedependency
|
122
|
+
end
|
123
|
+
|
124
|
+
def findPropValue(propertyVal,pom_document)
|
125
|
+
pom_document.css("project/properties").children.each do |prop|
|
126
|
+
propTag = "${#{prop.name}}"
|
127
|
+
if propertyVal == propTag
|
128
|
+
return prop.text
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def putCommonPluginInReactorPom(project_directory,commonList)
|
134
|
+
pomPath = "#{project_directory}/pom.xml"
|
135
|
+
pom_document = @@reactorHandler.parse_xml_from_file(pomPath)
|
136
|
+
nokObj = Nokogiri::XML::Node
|
137
|
+
projectNode = pom_document.at("project")
|
138
|
+
buildNode=nil
|
139
|
+
pluginManagementNode = nil
|
140
|
+
pluginsNode=nil
|
141
|
+
if (@@reactorHandler.tag_exists?("build/pluginManagement",pom_document) and commonList.length>0)
|
142
|
+
buildNode = pom_document.at("project/build")
|
143
|
+
pluginManagementNode = pom_document.at("project/build/pluginManagement")
|
144
|
+
pluginsNode = pom_document.at("project/build/pluginManagement/plugins")
|
145
|
+
elsif (!commonList.nil? and commonList.length>0)
|
146
|
+
buildNode = nokObj.new("build",projectNode)
|
147
|
+
pluginManagementNode = nokObj.new("pluginManagement",projectNode)
|
148
|
+
pluginsNode = nokObj.new("plugins",projectNode)
|
149
|
+
end
|
150
|
+
if (!commonList.nil? and commonList.length>0)
|
151
|
+
commonList.each do |eachplugin|
|
152
|
+
pluginArr = eachplugin.split(":")
|
153
|
+
gid = pluginArr[0]
|
154
|
+
artifactId = pluginArr[1]
|
155
|
+
version = pluginArr[2]
|
156
|
+
pluginNode = nokObj.new("plugin",projectNode)
|
157
|
+
grpNode = nokObj.new("groupId",projectNode)
|
158
|
+
grpNode.content=gid
|
159
|
+
artifactNode = nokObj.new("artifactId",projectNode)
|
160
|
+
artifactNode.content=artifactId
|
161
|
+
versionNode = nokObj.new("version",projectNode)
|
162
|
+
versionNode.content=version
|
163
|
+
pluginNode.add_child(grpNode)
|
164
|
+
pluginNode.add_child(artifactNode)
|
165
|
+
pluginNode.add_child(versionNode)
|
166
|
+
pluginsNode.add_child(pluginNode)
|
167
|
+
end
|
168
|
+
if !buildNode.nil?
|
169
|
+
pluginManagementNode.add_child(pluginsNode)
|
170
|
+
buildNode.add_child(pluginManagementNode)
|
171
|
+
@@dependencyHandler.add_node_element('//project', buildNode, pom_document)
|
172
|
+
@@mvnReactorization.write_nokogiri_to_xml(pomPath, pom_document)
|
173
|
+
puts "Plugin management is added in reactor pom"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def removePluginversionFromChildModule(project_directory_path,commonArr,tag)
|
179
|
+
commonPlugArr = Array.new
|
180
|
+
commonArr.each do |eachPlug|
|
181
|
+
plugArr = eachPlug.split(":")
|
182
|
+
cordinatePlug = "#{plugArr[0]}:#{plugArr[1]}"
|
183
|
+
commonPlugArr.push(cordinatePlug)
|
184
|
+
end
|
185
|
+
pomArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
|
186
|
+
if !(pomArr.nil? || pomArr.empty?)
|
187
|
+
pomArr.each do |eachPomPath|
|
188
|
+
pom_document = @@reactorHandler.parse_xml_from_file(eachPomPath)
|
189
|
+
pluginsNode=nil
|
190
|
+
if tag.include?"/pluginManagement/"
|
191
|
+
pluginsNode = pom_document.at("build/pluginManagement/plugins")
|
192
|
+
else
|
193
|
+
pluginsNode = pom_document.at("build/plugins")
|
194
|
+
end
|
195
|
+
if !pluginsNode.nil?
|
196
|
+
pluginsNode.css("plugin").each do |eachplugin|
|
197
|
+
grpId=nil
|
198
|
+
if (eachplugin.at("groupId").nil?)
|
199
|
+
grpId="org.apache.maven.plugins"
|
200
|
+
else
|
201
|
+
grpId = eachplugin.at("groupId").text
|
202
|
+
end
|
203
|
+
artifactId = eachplugin.at("artifactId").text
|
204
|
+
versionNode = eachplugin.at("version")
|
205
|
+
if (!versionNode.nil? and versionNode.parent.name == "plugin")
|
206
|
+
version = versionNode.text
|
207
|
+
fullPlugin = "#{grpId}:#{artifactId}"
|
208
|
+
if (commonPlugArr.include?fullPlugin)
|
209
|
+
versionNode.remove
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def comparePluginManagementFromChildModule(project_directory_path)
|
220
|
+
pomArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
|
221
|
+
if !(pomArr.nil? || pomArr.empty?)
|
222
|
+
pomArr.each do |eachPomPath|
|
223
|
+
pom_document = @@reactorHandler.parse_xml_from_file(eachPomPath)
|
224
|
+
pom_document.css("project/build/pluginManagement/plugins/plugin").each do |eachPlugin|
|
225
|
+
eachPlugin.children.each do |eachNode|
|
226
|
+
if !(eachNode.name == "groupId" or eachNode.name == "artifactId" or eachNode.name == "version" or eachNode.name == "text")
|
227
|
+
grpId=nil
|
228
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
229
|
+
grpId="org.apache.maven.plugins"
|
230
|
+
else
|
231
|
+
grpId = eachPlugin.at("groupId").text
|
232
|
+
end
|
233
|
+
artifactId = eachPlugin.at("artifactId").text
|
234
|
+
versionNode = eachPlugin.at("version")
|
235
|
+
cordinate = "#{grpId}:#{artifactId}"
|
236
|
+
searchCommonPluginInPlugins(eachPomPath,pom_document,cordinate,eachNode,versionNode)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def searchCommonPluginInPlugins(eachPomPath,pom_document,cordinate,eachNode,versionNode)
|
245
|
+
pom_document.css("project/build/plugins/plugin").each do |eachPlugin|
|
246
|
+
grpId=nil
|
247
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
248
|
+
grpId="org.apache.maven.plugins"
|
249
|
+
else
|
250
|
+
grpId = eachPlugin.at("groupId").text
|
251
|
+
end
|
252
|
+
artifactId = eachPlugin.at("artifactId").text
|
253
|
+
pluginCordinate = "#{grpId}:#{artifactId}"
|
254
|
+
if (cordinate == pluginCordinate)
|
255
|
+
nodeName = eachNode.name
|
256
|
+
if (eachPlugin.at(nodeName).nil? or eachPlugin.at(nodeName).parent.name != "plugin")
|
257
|
+
eachPlugin.add_child(eachNode)
|
258
|
+
if (eachPlugin.at("version").nil? or eachPlugin.at("version").parent.name != "plugin")
|
259
|
+
version = versionNode.text
|
260
|
+
nokObj = Nokogiri::XML::Node
|
261
|
+
newVersionNode = nokObj.new("version",eachPlugin)
|
262
|
+
newVersionNode.content = version
|
263
|
+
eachPlugin.add_child(newVersionNode)
|
264
|
+
end
|
265
|
+
@@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def copyPluginFromPluginManagement(pom_document,eachPlugin)
|
272
|
+
grpId=nil
|
273
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
274
|
+
grpId="org.apache.maven.plugins"
|
275
|
+
else
|
276
|
+
grpId = eachPlugin.at("groupId").text
|
277
|
+
end
|
278
|
+
artifactId = eachPlugin.at("artifactId").text
|
279
|
+
cordinate = "#{grpId}:#{artifactId}"
|
280
|
+
searchPluginInPlugins(pom_document,cordinate)
|
281
|
+
end
|
282
|
+
|
283
|
+
def searchPluginInPlugins(pom_document,cordinate)
|
284
|
+
isPluginRequired = true
|
285
|
+
pom_document.css("project/build/plugins/plugin").each do |eachPlugin|
|
286
|
+
grpId=nil
|
287
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
288
|
+
grpId="org.apache.maven.plugins"
|
289
|
+
else
|
290
|
+
grpId = eachPlugin.at("groupId").text
|
291
|
+
end
|
292
|
+
artifactId = eachPlugin.at("artifactId").text
|
293
|
+
pluginCordinate = "#{grpId}:#{artifactId}"
|
294
|
+
if (pluginCordinate == cordinate)
|
295
|
+
puts "Working:::::::::::::::::"
|
296
|
+
puts pluginCordinate
|
297
|
+
isPluginRequired=false
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def findCommonPluginFromPluginManagement(project_directory_path)
|
303
|
+
pomArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
|
304
|
+
if !(pomArr.nil? || pomArr.empty?)
|
305
|
+
pomArr.each do |eachPomPath|
|
306
|
+
pluginList = Hash.new
|
307
|
+
pom_document = @@reactorHandler.parse_xml_from_file(eachPomPath)
|
308
|
+
pom_document.css("project/build/pluginManagement/plugins/plugin").each do |eachPlugin|
|
309
|
+
grpId=nil
|
310
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
311
|
+
grpId="org.apache.maven.plugins"
|
312
|
+
else
|
313
|
+
grpId = eachPlugin.at("groupId").text
|
314
|
+
end
|
315
|
+
artifactId = eachPlugin.at("artifactId").text
|
316
|
+
pluginCordinate = "#{grpId}:#{artifactId}"
|
317
|
+
pluginList[pluginCordinate] = eachPlugin
|
318
|
+
end
|
319
|
+
pluginsList = findCommonPluginFromPlugins(pom_document,pluginList)
|
320
|
+
putPluginVersionIfNotFoundInPlugins(eachPomPath,pom_document,pluginList,"project/build/plugins/plugin")
|
321
|
+
putPluginVersionIfNotFoundInPlugins(eachPomPath,pom_document,pluginList,"project/reporting/plugins/plugin")
|
322
|
+
putUncommonPlugin(eachPomPath,pom_document,pluginList,pluginsList,"project/build/plugins")
|
323
|
+
removePluginManagementTag(pom_document)
|
324
|
+
@@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def putPluginVersionIfNotFoundInPlugins(eachPomPath,pom_document,pluginList,tag)
|
330
|
+
pluginList.each do |key,val|
|
331
|
+
versionNode = val.at("version")
|
332
|
+
pom_document.css(tag).each do |eachPlugin|
|
333
|
+
grpId=nil
|
334
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
335
|
+
grpId="org.apache.maven.plugins"
|
336
|
+
else
|
337
|
+
grpId = eachPlugin.at("groupId").text
|
338
|
+
end
|
339
|
+
artifactId = eachPlugin.at("artifactId").text
|
340
|
+
pluginCordinate = "#{grpId}:#{artifactId}"
|
341
|
+
if ((!versionNode.nil?) and (key==pluginCordinate) and (eachPlugin.at("version").nil? or eachPlugin.at("version").parent.name !="plugin"))
|
342
|
+
version = versionNode.text
|
343
|
+
nokObj = Nokogiri::XML::Node
|
344
|
+
newVersionNode = nokObj.new("version",eachPlugin)
|
345
|
+
newVersionNode.content = version
|
346
|
+
eachPlugin.add_child(newVersionNode)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
def findCommonPluginFromPlugins(pom_document,pluginList)
|
353
|
+
pluginsList = Array.new
|
354
|
+
pom_document.css("project/build/plugins/plugin").each do |eachPlugin|
|
355
|
+
grpId=nil
|
356
|
+
if (eachPlugin.at("groupId").nil? or eachPlugin.at("groupId").parent.name != "plugin")
|
357
|
+
grpId="org.apache.maven.plugins"
|
358
|
+
else
|
359
|
+
grpId = eachPlugin.at("groupId").text
|
360
|
+
end
|
361
|
+
artifactId = eachPlugin.at("artifactId").text
|
362
|
+
pluginCordinate = "#{grpId}:#{artifactId}"
|
363
|
+
pluginsList.push(pluginCordinate)
|
364
|
+
end
|
365
|
+
return pluginsList
|
366
|
+
end
|
367
|
+
|
368
|
+
def putUncommonPlugin(eachPomPath,pom_document,pluginList,pluginsList,tag)
|
369
|
+
pluginsNode = pom_document.at(tag)
|
370
|
+
pluginList.each do |key,val|
|
371
|
+
if (!pluginsList.include?key)
|
372
|
+
puts "Mismatch plugin found in #{eachPomPath}"
|
373
|
+
pluginsNode.add_child(val)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def removePluginManagementTag(pom_document)
|
379
|
+
pluginManagementNode = pom_document.at("project/build/pluginManagement")
|
380
|
+
if !pluginManagementNode.nil?
|
381
|
+
pluginManagementNode.remove
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def executeShortPom()
|
386
|
+
result = `mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort`
|
387
|
+
puts result
|
388
|
+
puts "All poms are sorted by sort-pom plugin"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
class PropertyHandler
|
2
|
+
@@basicInfoHandler = BasicInfoHandler.new
|
3
|
+
@@tempPath = nil
|
4
|
+
@@dependencyHandler = DependencyHandler.new
|
5
|
+
# This api will handle properties #
|
6
|
+
def handleProperties(project_directory_path)
|
7
|
+
@@tempPath = "#{project_directory_path}/temp.xml"
|
8
|
+
effective_pom_doc = @@basicInfoHandler.copyTagsFromEffectivePom(project_directory_path)
|
9
|
+
properties = effective_pom_doc.at("project/properties")
|
10
|
+
if (!properties.nil?)
|
11
|
+
File.write(@@tempPath, properties, File.size(@@tempPath), mode: 'a')
|
12
|
+
puts "::Prfoperties is added successfully::"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# return the property map of effetive-pom
|
17
|
+
def getTempPropertyMap()
|
18
|
+
temp_pom_document = Nokogiri::XML(open("temp.xml"))
|
19
|
+
propertyMap = Hash.new
|
20
|
+
temp_pom_document.css("project/properties").children.each do |eachproperty|
|
21
|
+
tagName = eachproperty.name
|
22
|
+
tagValue = eachproperty.text
|
23
|
+
if tagName!='text'
|
24
|
+
propertyMap[tagName] = tagValue
|
25
|
+
end
|
26
|
+
end
|
27
|
+
return propertyMap
|
28
|
+
end
|
29
|
+
|
30
|
+
# return the property map of child-pom
|
31
|
+
def getOriginalPropertyMap()
|
32
|
+
pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd)
|
33
|
+
propertyMap = Hash.new
|
34
|
+
pom_document.css("project/properties").children.each do |eachproperty|
|
35
|
+
tagName = eachproperty.name
|
36
|
+
tagValue = eachproperty.text
|
37
|
+
if tagName!='text'
|
38
|
+
propertyMap[tagName] = tagValue
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return propertyMap
|
42
|
+
end
|
43
|
+
|
44
|
+
# return the property map of parent-pom
|
45
|
+
def getImidiateParentPropertyMap()
|
46
|
+
pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd)
|
47
|
+
parent = pom_document.at("project/parent")
|
48
|
+
propertyMap = Hash.new
|
49
|
+
if !parent.nil?
|
50
|
+
parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(pom_document)
|
51
|
+
parent_pom_document.css("project/properties").children.each do |eachproperty|
|
52
|
+
tagName = eachproperty.name
|
53
|
+
tagValue = eachproperty.text
|
54
|
+
if tagName!='text'
|
55
|
+
propertyMap[tagName] = tagValue
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
return propertyMap
|
60
|
+
end
|
61
|
+
|
62
|
+
# return the property map of parent-pom
|
63
|
+
def getgrandParentPropertyMap()
|
64
|
+
pom_document = @@basicInfoHandler.copyTagsFromOriginalPom(Dir.getwd)
|
65
|
+
parent = pom_document.at("project/parent")
|
66
|
+
propertyMap = Hash.new
|
67
|
+
if !parent.nil?
|
68
|
+
parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(pom_document)
|
69
|
+
grandParent = parent_pom_document.at("project/parent")
|
70
|
+
if !grandParent.nil?
|
71
|
+
grand_parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(parent_pom_document)
|
72
|
+
grand_parent_pom_document.css("project/properties").children.each do |eachproperty|
|
73
|
+
tagName = eachproperty.name
|
74
|
+
tagValue = eachproperty.text
|
75
|
+
if tagName!='text'
|
76
|
+
propertyMap[tagName] = tagValue
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
return propertyMap
|
82
|
+
end
|
83
|
+
|
84
|
+
# This api takes decision to indentify the dependency where the place holder found. #
|
85
|
+
def findPlaceHolderWithinProperties(tempPropertyMap,originalPropertyMap,parentPropertyMap,grandparentPropertyMap)
|
86
|
+
if (!tempPropertyMap.empty?)
|
87
|
+
tempPropertyMap.each do |propKey,propVal|
|
88
|
+
originalPropVal = nil
|
89
|
+
parentPropVal = nil
|
90
|
+
grandParentPropVal = nil
|
91
|
+
if (!originalPropertyMap.empty?)
|
92
|
+
originalPropVal = originalPropertyMap[propKey]
|
93
|
+
end
|
94
|
+
if (!parentPropertyMap.empty?)
|
95
|
+
parentPropVal = parentPropertyMap[propKey]
|
96
|
+
end
|
97
|
+
if (!grandparentPropertyMap.empty?)
|
98
|
+
grandParentPropVal = grandparentPropertyMap[propKey]
|
99
|
+
end
|
100
|
+
if (!originalPropVal.nil? and originalPropVal.include? "${")
|
101
|
+
replaceVersionIntempFile(propKey,originalPropVal)
|
102
|
+
elsif (!parentPropVal.nil? and parentPropVal.include? "${")
|
103
|
+
replaceVersionIntempFile(propKey,parentPropVal)
|
104
|
+
elsif (!grandParentPropVal.nil? and grandParentPropVal.include? "${")
|
105
|
+
replaceVersionIntempFile(propKey,grandParentPropVal)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# This api replace version by place-holder #
|
112
|
+
def replaceVersionIntempFile(propKey,propVal)
|
113
|
+
temp_pom_document = Nokogiri::XML(open("temp.xml"))
|
114
|
+
nokObj = Nokogiri::XML::Node
|
115
|
+
propertiesNode = temp_pom_document.at("project/properties")
|
116
|
+
temp_pom_document.css("project/properties").children.each do |eachProperty|
|
117
|
+
tagName = eachProperty.name
|
118
|
+
if (tagName==propKey)
|
119
|
+
eachProperty.remove
|
120
|
+
propertyNode = nokObj.new(tagName,propertiesNode)
|
121
|
+
propertyNode.content=propVal
|
122
|
+
propertiesNode.add_child(propertyNode)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
formated_pom_doc = @@dependencyHandler.add_node_element("project",propertiesNode,temp_pom_document)
|
126
|
+
File.write("temp.xml", formated_pom_doc.to_xml)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|