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,49 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'mavenReactorService/ReactorHandler'
|
4
|
+
require 'mavenReactorService/DependencyHandler'
|
5
|
+
require 'mavenReactorService/BasicInfoHandler'
|
6
|
+
require 'mavenReactorService/PropertyHandler'
|
7
|
+
require 'mavenReactorService/PluginHandler'
|
8
|
+
require 'mavenReactorService/MvnReactorization'
|
9
|
+
require 'mavenReactorService/MergeRepository'
|
10
|
+
require 'mavenReactorService/DeveloperAndContributors'
|
11
|
+
require 'mavenReactorService/DependencyManagementHandler'
|
12
|
+
require 'mavenReactorService/PluginManagementHandler'
|
13
|
+
require 'mavenReactorService/InterDependencyHandler'
|
14
|
+
require 'mavenReactorService/MoveCommonPropertiesToRootPom'
|
15
|
+
require 'mavenReactorService/SiteAndEclipsePluginHandler'
|
16
|
+
require 'mavenReactorService/MoveDistributionManagement'
|
17
|
+
require 'mavenReactorService/DMAndPMManagementForExternalConfiguration'
|
18
|
+
require 'mavenReactorService/ParentPomHandler'
|
19
|
+
require 'mavenReactorService/ValidateProjects'
|
20
|
+
require 'mavenReactorService/PluginConfigurationHandler'
|
21
|
+
require 'open-uri'
|
22
|
+
|
23
|
+
# This is controller class for reactor service #
|
24
|
+
class ReactorCommands < Thor
|
25
|
+
desc 'all [PROJECT_DIRECTORY_PATH]', 'Run Method For parent pom'
|
26
|
+
def reactorHandler(externalPomUrl=nil,project_directory_path = Dir.getwd)
|
27
|
+
reactorHandler = ReactorHandler.new
|
28
|
+
reactorHandler.createEffectivePom(project_directory_path,externalPomUrl)
|
29
|
+
reactorHandler.makeReator(project_directory_path)
|
30
|
+
reactorHandler.managePlugins(project_directory_path)
|
31
|
+
reactorHandler.plugiConfigHandler(project_directory_path)
|
32
|
+
reactorHandler.moveCommonProperties(project_directory_path)
|
33
|
+
reactorHandler.createDistributionManagmentInReactorPom(project_directory_path,externalPomUrl)
|
34
|
+
reactorHandler.handleDeveloperAndContributors(project_directory_path)
|
35
|
+
reactorHandler.mergeRepository(project_directory_path)
|
36
|
+
reactorHandler.manageDepedency(project_directory_path)
|
37
|
+
reactorHandler.handleInterDependency(project_directory_path)
|
38
|
+
reactorHandler.handleTeamSpecificParent(project_directory_path,externalPomUrl)
|
39
|
+
reactorHandler.dmpmForexternalConfiguration(project_directory_path,externalPomUrl)
|
40
|
+
reactorHandler.removeEmptyTags(project_directory_path)
|
41
|
+
reactorHandler.sortPomExecutor()
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'all [PROJECT_DIRECTORY_PATH]', 'Run Method For parent pom'
|
45
|
+
def projectValidator(project_directory_path = Dir.getwd )
|
46
|
+
reactorHandler = ReactorHandler.new
|
47
|
+
reactorHandler.validateProjectsEligiblity(project_directory_path)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,309 @@
|
|
1
|
+
# This class will handle all the reactor-operation #
|
2
|
+
class ReactorHandler
|
3
|
+
@@xml_file
|
4
|
+
@@cordinateArr
|
5
|
+
@@flag=false
|
6
|
+
@@projectsWithExternalConfiguration = Array.new
|
7
|
+
# This api will generate effective-pom and implements flatten out process #
|
8
|
+
# If parent tag is not prersent then effective-pom will not be generated #
|
9
|
+
def createEffectivePom(project_directory_path,externalPomUrl)
|
10
|
+
eachModuleArr = fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
|
11
|
+
eachModuleArr.each do |eachPom|
|
12
|
+
isIdentical=false
|
13
|
+
pom_document = parse_xml_from_file(eachPom)
|
14
|
+
if tag_exists?('parent', pom_document)
|
15
|
+
parentPomHandler = ParentPomHandler.new
|
16
|
+
@@cordinateArr = parentPomHandler.makeMbpCordinateFromOriginalPom(pom_document)
|
17
|
+
if ((@@cordinateArr.length == 0) and ((!externalPomUrl.nil?) and (externalPomUrl.include? "https://" or externalPomUrl.include? "http://")))
|
18
|
+
cordinatesArr = parentPomHandler.makeCordinateFromUrl(externalPomUrl)
|
19
|
+
orginalCordinateArr = parentPomHandler.makeOriginalPomUrl(pom_document)
|
20
|
+
isIdentical = parentPomHandler.compareTwoCordinatesArr(cordinatesArr,orginalCordinateArr)
|
21
|
+
elsif (@@cordinateArr.length > 0)
|
22
|
+
isIdentical=true
|
23
|
+
end
|
24
|
+
if !isIdentical
|
25
|
+
eachPomPath = eachPom.sub("/pom.xml","")
|
26
|
+
Dir.chdir(eachPomPath) {
|
27
|
+
result = `mvn help:effective-pom -Doutput=effective_pom.xml`
|
28
|
+
puts result # Maven out-put
|
29
|
+
generate_temp_xml()
|
30
|
+
@@projectsWithExternalConfiguration.push(eachPomPath)
|
31
|
+
basicInfoHandler = BasicInfoHandler.new
|
32
|
+
basicInfoHandler.handleGrpAndArtifact(eachPomPath)
|
33
|
+
basicInfoHandler.handleModelVersion(eachPomPath)
|
34
|
+
basicInfoHandler.handleInceptionYearDescAndOrganization(eachPomPath)
|
35
|
+
basicInfoHandler.handleProjectUrl(eachPomPath)
|
36
|
+
basicInfoHandler.handleDevelopersContributorsMailingLists(eachPomPath)
|
37
|
+
basicInfoHandler.handleScmIssueManagementCiManagement(eachPomPath)
|
38
|
+
basicInfoHandler.handleDistributionManagement(eachPomPath)
|
39
|
+
basicInfoHandler.handleRepositories(eachPomPath)
|
40
|
+
basicInfoHandler.handlePluginRepositories(eachPomPath)
|
41
|
+
pluginHandler = PluginHandler.new
|
42
|
+
pluginHandler.addBuildTag()
|
43
|
+
pluginHandler.addReportingTag()
|
44
|
+
propertyHandler = PropertyHandler.new
|
45
|
+
propertyHandler.handleProperties(eachPomPath)
|
46
|
+
dependencyHandler = DependencyHandler.new
|
47
|
+
dependencyHandler.projectPomDependencyHandler()
|
48
|
+
tempDependencyList = dependencyHandler.getTempDependencyList()
|
49
|
+
childDependencyMap = dependencyHandler.getOriginalDependencyMap()
|
50
|
+
parentDependencyMap = dependencyHandler.getImmediateParentDependencyMap()
|
51
|
+
grandParentDependencyMap = dependencyHandler.getgrandParentDependencyMap()
|
52
|
+
dependencyHandler.findPlaceHolderWithinPoms(tempDependencyList,childDependencyMap,parentDependencyMap,grandParentDependencyMap)
|
53
|
+
project_end()
|
54
|
+
tempPropertyMap = propertyHandler.getTempPropertyMap()
|
55
|
+
childPropertyMap = propertyHandler.getOriginalPropertyMap()
|
56
|
+
parentPropertyMap = propertyHandler.getImidiateParentPropertyMap()
|
57
|
+
grandparentPropertyMap = propertyHandler.getgrandParentPropertyMap()
|
58
|
+
propertyHandler.findPlaceHolderWithinProperties(tempPropertyMap,childPropertyMap,parentPropertyMap,grandparentPropertyMap)
|
59
|
+
pluginHandler.removePluginManagementTag()
|
60
|
+
pluginList = pluginHandler.getGrpAndArtifactIdOfPlugins()
|
61
|
+
pluginHandler.compareWithOriginalPomPlugin(pluginList)
|
62
|
+
pluginHandler.compareWithParentPomPlugin(pluginList)
|
63
|
+
pluginHandler.compareWithGrandParentPomPlugin(pluginList)
|
64
|
+
pluginHandler.removeExtraTag("build")
|
65
|
+
#Reporting plugin
|
66
|
+
reportSwitch = "reporting"
|
67
|
+
pluginList = pluginHandler.getGrpAndArtifactIdOfPlugins(reportSwitch)
|
68
|
+
pluginHandler.compareWithOriginalPomPlugin(pluginList,reportSwitch)
|
69
|
+
pluginHandler.compareWithParentPomPlugin(pluginList,reportSwitch)
|
70
|
+
pluginHandler.compareWithGrandParentPomPlugin(pluginList,reportSwitch)
|
71
|
+
pluginHandler.removeExtraTag("reporting")
|
72
|
+
#Site and eclipse plugin
|
73
|
+
handleSiteAndEclipsePlugin(eachPomPath)
|
74
|
+
closeFileObj()
|
75
|
+
basicInfoHandler.renamePom(eachPomPath)
|
76
|
+
basicInfoHandler.renameTemp(eachPomPath)
|
77
|
+
puts "Original pom is reanamed to pom_back.xml"
|
78
|
+
}
|
79
|
+
else
|
80
|
+
puts "Provided parent URL and external configuration are same"
|
81
|
+
end
|
82
|
+
else
|
83
|
+
eachPomPath = eachPom.sub("/pom.xml","")
|
84
|
+
index = eachPomPath.rindex("/")
|
85
|
+
projectName = eachPomPath[index+1,eachPomPath.length-1]
|
86
|
+
puts "No parent found for #{projectName} project"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
puts "Effective pom generation is completed"
|
90
|
+
end
|
91
|
+
|
92
|
+
def handleSiteAndEclipsePlugin(project_directory_path)
|
93
|
+
siteAndEclipsePluginHandler = SiteAndEclipsePluginHandler.new
|
94
|
+
siteAndEclipsePluginHandler.managePlugins(project_directory_path,"org.apache.maven.plugins:maven-site-plugin")
|
95
|
+
siteAndEclipsePluginHandler.managePlugins(project_directory_path,"org.apache.maven.plugins:maven-eclipse-plugin")
|
96
|
+
end
|
97
|
+
|
98
|
+
def makeReator(project_directory_path)
|
99
|
+
mvnReactorization = MvnReactorization.new
|
100
|
+
mvnReactorization.makeReactor(project_directory_path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def manageDepedency(project_directory_path)
|
104
|
+
dependencyManagementHandler = DependencyManagementHandler.new
|
105
|
+
dependencyManagementHandler.handleDependencyManagement(project_directory_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
def managePlugins(project_directory_path)
|
109
|
+
pluginManagementHandler = PluginManagementHandler.new
|
110
|
+
pluginManagementHandler.comparePluginManagementFromChildModule(project_directory_path)
|
111
|
+
pluginManagementHandler.handlePluginManagement(project_directory_path)
|
112
|
+
pluginManagementHandler.findCommonPluginFromPluginManagement(project_directory_path)
|
113
|
+
end
|
114
|
+
|
115
|
+
def plugiConfigHandler(project_directory_path)
|
116
|
+
pluginConfigurationHandler= PluginConfigurationHandler.new
|
117
|
+
pluginConfigurationHandler.mergePluginConfiguration(project_directory_path,@@projectsWithExternalConfiguration)
|
118
|
+
end
|
119
|
+
|
120
|
+
def mergeRepository(project_directory_path)
|
121
|
+
mergeRepository =MergeRepository.new
|
122
|
+
#Repositories
|
123
|
+
commonUrlList = mergeRepository.findCommonRepos(project_directory_path,"repositories/repository")
|
124
|
+
rootRepo = mergeRepository.makeFullRepoFromCommonRepo(project_directory_path,"repositories/repository",commonUrlList)
|
125
|
+
mergeRepository.addRepoIntoReactorPom(project_directory_path,rootRepo,"repositories")
|
126
|
+
mergeRepository.deleteRepoFromChildModule(project_directory_path,"repositories")
|
127
|
+
mergeRepository.renameDuplicateRepoId(project_directory_path,"repositories/repository")
|
128
|
+
#PluginRepositories
|
129
|
+
commonUrlList = mergeRepository.findCommonRepos(project_directory_path,"pluginRepositories/pluginRepository")
|
130
|
+
rootRepo = mergeRepository.makeFullRepoFromCommonRepo(project_directory_path,"pluginRepositories/pluginRepository",commonUrlList)
|
131
|
+
mergeRepository.addRepoIntoReactorPom(project_directory_path,rootRepo,"pluginRepositories")
|
132
|
+
mergeRepository.deleteRepoFromChildModule(project_directory_path,"pluginRepositories")
|
133
|
+
mergeRepository.renameDuplicateRepoId(project_directory_path,"pluginRepositories/pluginRepository")
|
134
|
+
puts "Renamed repo is done"
|
135
|
+
end
|
136
|
+
|
137
|
+
def handleInterDependency(project_directory_path)
|
138
|
+
interDependencyHandler = InterDependencyHandler.new
|
139
|
+
interDependencyHandler.handleInterDependecy(project_directory_path)
|
140
|
+
end
|
141
|
+
|
142
|
+
def handleDeveloperAndContributors(project_directory_path)
|
143
|
+
developerAndContributors = DeveloperAndContributors.new
|
144
|
+
commonDevelopers = developerAndContributors.findCommonDevelopers(project_directory_path,"developers/developer")
|
145
|
+
developersAndContributorsList = developerAndContributors.mergeDeveloperAndContributors(project_directory_path,commonDevelopers,"developers/developer")
|
146
|
+
developerAndContributors.addDeveloperAndContributersInReator(project_directory_path,developersAndContributorsList,"developers")
|
147
|
+
developerAndContributors.removeCommonDevelopersAndContributorsFromChild(project_directory_path,commonDevelopers,"developers/developer")
|
148
|
+
#developerAndContributors.removeEmptyTags(project_directory_path,"developers")
|
149
|
+
#Contributors
|
150
|
+
commonDevelopers = developerAndContributors.findCommonDevelopers(project_directory_path,"contributors/contributor")
|
151
|
+
developersAndContributorsList = developerAndContributors.mergeDeveloperAndContributors(project_directory_path,commonDevelopers,"contributors/contributor")
|
152
|
+
developerAndContributors.addDeveloperAndContributersInReator(project_directory_path,developersAndContributorsList,"contributors")
|
153
|
+
developerAndContributors.removeCommonDevelopersAndContributorsFromChild(project_directory_path,commonDevelopers,"contributors/contributor")
|
154
|
+
#developerAndContributors.removeEmptyTags(project_directory_path,"contributors")
|
155
|
+
end
|
156
|
+
|
157
|
+
def sortPomExecutor()
|
158
|
+
pluginManagementHandler = PluginManagementHandler.new
|
159
|
+
pluginManagementHandler.executeShortPom()
|
160
|
+
end
|
161
|
+
|
162
|
+
def handleTeamSpecificParent(project_directory_path,externalPomUrl)
|
163
|
+
if ((!externalPomUrl.nil?) and (externalPomUrl.include? "https://" or externalPomUrl.include? "http://"))
|
164
|
+
parentPomHandler = ParentPomHandler.new
|
165
|
+
parentPomHandler.setParentInreactor(project_directory_path,externalPomUrl)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
# This api will return the list of projects path of individual projects #
|
169
|
+
def fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,retDecision)
|
170
|
+
alldir = Dir.entries(project_directory_path)
|
171
|
+
pomFilePath=Array.new
|
172
|
+
alldir.each do |fileLtst|
|
173
|
+
if File.directory? fileLtst
|
174
|
+
if !(File.basename(fileLtst) == "." || File.basename(fileLtst) == "..")
|
175
|
+
innerFileLtst = Dir.entries(fileLtst)
|
176
|
+
innerFileLtst.each do |eachInner|
|
177
|
+
fileName = File.basename(eachInner)
|
178
|
+
if fileName == "pom.xml"
|
179
|
+
pomFilePath.push("#{File.expand_path(fileLtst)}/#{fileName}")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
if (retDecision)
|
186
|
+
mvnReactorization = MvnReactorization.new
|
187
|
+
finalSnapShot = mvnReactorization.findHighestVersionOfPom(pomFilePath)
|
188
|
+
fullDetails = mvnReactorization.getDetails(pomFilePath[0])
|
189
|
+
fullDetails[2]=finalSnapShot
|
190
|
+
return fullDetails
|
191
|
+
else
|
192
|
+
return pomFilePath
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def moveCommonProperties (project_directory_path)
|
197
|
+
moveCommonPropertiesToRootPom = MoveCommonPropertiesToRootPom.new
|
198
|
+
commonProperties = moveCommonPropertiesToRootPom.findCommonProperties(project_directory_path)
|
199
|
+
moveCommonPropertiesToRootPom.writeCommonPropertiesToReactorPom(project_directory_path,commonProperties)
|
200
|
+
moveCommonPropertiesToRootPom.removeCommonPropertiesfromModules(project_directory_path,commonProperties)
|
201
|
+
end
|
202
|
+
|
203
|
+
def createDistributionManagmentInReactorPom (project_directory_path,externalPomUrl)
|
204
|
+
moveDistributionManagement = MoveDistributionManagement.new
|
205
|
+
moveDistributionManagement.moveDistributionManagementFromFirstModule(project_directory_path,externalPomUrl)
|
206
|
+
end
|
207
|
+
|
208
|
+
def removeEmptyTags(project_directory_path)
|
209
|
+
pomPathArr = fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
|
210
|
+
mvnReactorization = MvnReactorization.new
|
211
|
+
pomPathArr.each do |eachPomPath|
|
212
|
+
pom_document = parse_xml_from_file(eachPomPath)
|
213
|
+
clean(pom_document.at("project"))
|
214
|
+
mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
def clean(node)
|
218
|
+
node.children.each do |child|
|
219
|
+
clean(child)
|
220
|
+
child.remove if child.content.gsub(/\s+/, '').empty?
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def dmpmForexternalConfiguration(project_directory_path,externalPomUrl)
|
225
|
+
if @@flag
|
226
|
+
dmAndPMManagementForExternalConfiguration = DMAndPMManagementForExternalConfiguration.new
|
227
|
+
cordinateArr = dmAndPMManagementForExternalConfiguration.getParentCordinates(externalPomUrl,"dependency")
|
228
|
+
dmAndPMManagementForExternalConfiguration.comparetheVersionWithParent(project_directory_path,cordinateArr,"dependencies/dependency")
|
229
|
+
dmAndPMManagementForExternalConfiguration.comparetheVersionWithParent(project_directory_path,cordinateArr,"dependencyManagement/dependencies/dependency")
|
230
|
+
cordinateArr = dmAndPMManagementForExternalConfiguration.getParentCordinates(externalPomUrl,"plugins")
|
231
|
+
dmAndPMManagementForExternalConfiguration.comparethePluginVersionWithParent(project_directory_path,cordinateArr,"project/build/plugins/plugin")
|
232
|
+
dmAndPMManagementForExternalConfiguration.comaprePluginVersionWihReactorPom(project_directory_path,cordinateArr,"project/build/pluginManagement/plugins/plugin")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def handleTeamSpecificParent(project_directory_path,externalConfigUrl)
|
237
|
+
parentPomHandler = ParentPomHandler.new
|
238
|
+
if (!externalConfigUrl.nil?)
|
239
|
+
begin
|
240
|
+
Nokogiri::HTML(open(externalConfigUrl)) #This is to validate the url
|
241
|
+
rescue
|
242
|
+
raise "Parent POM URL is not valid !!!"
|
243
|
+
end
|
244
|
+
cordinatesArr = parentPomHandler.makeCordinateFromUrl(externalConfigUrl)
|
245
|
+
@@flag = parentPomHandler.putParentInReactorPom(cordinatesArr,project_directory_path)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def validateProjectsEligiblity (project_directory_path)
|
250
|
+
validateProjects = ValidateProjects.new
|
251
|
+
validateProjects.checkEligiblityForReactorization(project_directory_path)
|
252
|
+
end
|
253
|
+
|
254
|
+
# This api checks a particular tag present or not and return boolean value #
|
255
|
+
def tag_exists?(tag, pom_nokogiri, data = nil)
|
256
|
+
temp = pom_nokogiri.dup
|
257
|
+
temp.remove_namespaces!
|
258
|
+
if data.nil?
|
259
|
+
# Searching only for tag when data is not supplied
|
260
|
+
!temp.xpath("//#{tag}").empty?
|
261
|
+
else
|
262
|
+
# Searching for entire the node with given tag and data
|
263
|
+
at_parameter = "#{tag}:contains('#{data}')"
|
264
|
+
found_match = temp.at(at_parameter)
|
265
|
+
# Confirming that whole string matches as contains can
|
266
|
+
# report success if even a part of string matches
|
267
|
+
!found_match.nil? && found_match.text.strip == data
|
268
|
+
end
|
269
|
+
rescue Nokogiri::XML::XPath::SyntaxError, RuntimeError, NoMethodError, TypeError
|
270
|
+
# Rescue is hit only when
|
271
|
+
# Supplied tag is either empty or nil or
|
272
|
+
# Supplied pom_nokogiri is nil
|
273
|
+
raise 'Either tag or pom object supplied is empty or nil'
|
274
|
+
end
|
275
|
+
|
276
|
+
# This api generate blank temp.xml inside the individual projects #
|
277
|
+
def generate_temp_xml()
|
278
|
+
dest = "temp.xml"
|
279
|
+
File.write("temp.xml","<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>")
|
280
|
+
end
|
281
|
+
|
282
|
+
def project_end()
|
283
|
+
tempXml = "temp.xml"
|
284
|
+
file = File.open(tempXml)
|
285
|
+
contents = file.read
|
286
|
+
if !contents.include? "</project>"
|
287
|
+
File.write(tempXml, "</project>", File.size(tempXml), mode: 'a')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
# This api is used to create dom object of pom #
|
292
|
+
def parse_xml_from_file(file_path)
|
293
|
+
@@xml_file = File.open(file_path)
|
294
|
+
Nokogiri::XML(@@xml_file, &:strict)
|
295
|
+
rescue Errno::ENOENT
|
296
|
+
raise Errno::ENOENT,
|
297
|
+
"Couldn't locate a file at that path, please check the path!"
|
298
|
+
rescue Nokogiri::XML::SyntaxError => e
|
299
|
+
raise Nokogiri::XML::SyntaxError,
|
300
|
+
"The following errors occurred while parsing your XML file: \n" +
|
301
|
+
e.message
|
302
|
+
end
|
303
|
+
|
304
|
+
def closeFileObj()
|
305
|
+
@@xml_file.close
|
306
|
+
@@xml_file.closed?
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class SiteAndEclipsePluginHandler
|
2
|
+
@@reactorHandler = ReactorHandler.new
|
3
|
+
@@mvnReactorization = MvnReactorization.new
|
4
|
+
@@dependencyHandler = DependencyHandler.new
|
5
|
+
def managePlugins(project_directory,pluginName)
|
6
|
+
temp_document = @@reactorHandler.parse_xml_from_file("temp.xml")
|
7
|
+
pom_document = @@reactorHandler.parse_xml_from_file("pom.xml")
|
8
|
+
temp_document.css("project/build/plugins/plugin").each do |eachplugin|
|
9
|
+
gid=nil
|
10
|
+
if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
|
11
|
+
gid = eachplugin.at("groupId").text
|
12
|
+
else
|
13
|
+
gid = "org.apache.maven.plugins"
|
14
|
+
end
|
15
|
+
artifactId = eachplugin.at("artifactId").text
|
16
|
+
pluginCordinate = "#{gid}:#{artifactId}"
|
17
|
+
if (pluginName == pluginCordinate)
|
18
|
+
eachplugin.remove
|
19
|
+
@@mvnReactorization.write_nokogiri_to_xml("temp.xml", temp_document)
|
20
|
+
isPluginFound = findPluginfromOriginalPom(pluginName,pom_document)
|
21
|
+
if !isPluginFound
|
22
|
+
findPluginfromParentPom(pluginName,pom_document)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def findPluginfromOriginalPom(pluginName,pom_document)
|
29
|
+
flag=false
|
30
|
+
pom_document.css("project/build/plugins/plugin").each do |eachplugin|
|
31
|
+
gid=nil
|
32
|
+
if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
|
33
|
+
gid = eachplugin.at("groupId").text
|
34
|
+
else
|
35
|
+
gid = "org.apache.maven.plugins"
|
36
|
+
end
|
37
|
+
artifactId = eachplugin.at("artifactId").text
|
38
|
+
pluginCordinate = "#{gid}:#{artifactId}"
|
39
|
+
if (pluginName == pluginCordinate)
|
40
|
+
if (eachplugin.at("version").nil? or eachplugin.at("version").parent.name != "plugin")
|
41
|
+
version = searchVersionInPom(pluginName,pom_document,"project/build/pluginManagement/plugins/plugin")
|
42
|
+
if version.nil?
|
43
|
+
version = searchVersionInPom(pluginName,pom_document,"project/build/plugins/plugin")
|
44
|
+
end
|
45
|
+
if version.nil?
|
46
|
+
effective_pom_document = @@reactorHandler.parse_xml_from_file("effective_pom.xml")
|
47
|
+
version = searchVersionInPom(pluginName,effective_pom_document,"project/build/pluginManagement/plugins/plugin")
|
48
|
+
if version.nil?
|
49
|
+
version = searchVersionInPom(pluginName,effective_pom_document,"project/build/plugins/plugin")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
insertVersioninPlugin(eachplugin,version)
|
54
|
+
end
|
55
|
+
writePluginInTemp(eachplugin)
|
56
|
+
flag=true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
return flag
|
60
|
+
end
|
61
|
+
|
62
|
+
def findPluginfromParentPom(pluginName,pom_document)
|
63
|
+
parent = pom_document.at("project/parent")
|
64
|
+
if !parent.nil?
|
65
|
+
parent_pom_document = @@dependencyHandler.getParentPomDomObjFromUrl(pom_document)
|
66
|
+
findPluginfromOriginalPom(pluginName,parent_pom_document)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def insertVersioninPlugin(pluginNode,version)
|
71
|
+
nokObj = Nokogiri::XML::Node
|
72
|
+
versionNode = nokObj.new("version",pluginNode)
|
73
|
+
versionNode.content=version
|
74
|
+
pluginNode.add_child(versionNode)
|
75
|
+
end
|
76
|
+
|
77
|
+
def searchVersionInPom(pluginName,pom_document,tag)
|
78
|
+
version = nil
|
79
|
+
pom_document.css(tag).each do |eachplugin|
|
80
|
+
gid=nil
|
81
|
+
if (!eachplugin.at("groupId").nil? and eachplugin.at("groupId").parent.name == "plugin")
|
82
|
+
gid = eachplugin.at("groupId").text
|
83
|
+
else
|
84
|
+
gid = "org.apache.maven.plugins"
|
85
|
+
end
|
86
|
+
artifactId = eachplugin.at("artifactId").text
|
87
|
+
pluginCordinate = "#{gid}:#{artifactId}"
|
88
|
+
if (pluginName == pluginCordinate)
|
89
|
+
if (!eachplugin.at("version").nil? and eachplugin.at("version").parent.name == "plugin")
|
90
|
+
version = eachplugin.at("version").text
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
return version
|
95
|
+
end
|
96
|
+
|
97
|
+
def writePluginInTemp(pluginNode)
|
98
|
+
temp_document = @@reactorHandler.parse_xml_from_file("temp.xml")
|
99
|
+
@@dependencyHandler.add_node_element("project/build/plugins",pluginNode,temp_document)
|
100
|
+
toalPom = temp_document.to_s
|
101
|
+
toalPom = toalPom.sub("<plugin xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns=\"http://maven.apache.org/POM/4.0.0\">","<plugin>")
|
102
|
+
File.write("temp.xml", toalPom)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|