Class: ReactorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/mavenReactorService/ReactorHandler.rb

Overview

This class will handle all the reactor-operation #

Constant Summary collapse

@@flag =
false
@@projectsWithExternalConfiguration =
Array.new

Instance Method Summary collapse

Instance Method Details

#clean(node) ⇒ Object



217
218
219
220
221
222
# File 'lib/mavenReactorService/ReactorHandler.rb', line 217

def clean(node)
 node.children.each do |child|
   clean(child)
   child.remove if child.content.gsub(/\s+/, '').empty?
 end
end

#closeFileObjObject



304
305
306
307
# File 'lib/mavenReactorService/ReactorHandler.rb', line 304

def closeFileObj()
  @@xml_file.close
  @@xml_file.closed?
end

#createDistributionManagmentInReactorPom(project_directory_path, externalPomUrl) ⇒ Object



203
204
205
206
# File 'lib/mavenReactorService/ReactorHandler.rb', line 203

def createDistributionManagmentInReactorPom (project_directory_path,externalPomUrl)
  moveDistributionManagement = MoveDistributionManagement.new
  moveDistributionManagement.moveDistributionManagementFromFirstModule(project_directory_path,externalPomUrl)
end

#createEffectivePom(project_directory_path, externalPomUrl) ⇒ Object

This api will generate effective-pom and implements flatten out process # If parent tag is not prersent then effective-pom will not be generated #



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
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
# File 'lib/mavenReactorService/ReactorHandler.rb', line 9

def createEffectivePom(project_directory_path,externalPomUrl)
  eachModuleArr = fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  eachModuleArr.each do |eachPom|
 isIdentical=false
    pom_document = parse_xml_from_file(eachPom)
    if tag_exists?('parent', pom_document)
 parentPomHandler = ParentPomHandler.new
  @@cordinateArr =  parentPomHandler.makeMbpCordinateFromOriginalPom(pom_document)
  if ((@@cordinateArr.length == 0) and ((!externalPomUrl.nil?) and (externalPomUrl.include? "https://" or externalPomUrl.include? "http://")))
        cordinatesArr =  parentPomHandler.makeCordinateFromUrl(externalPomUrl)
        orginalCordinateArr = parentPomHandler.makeOriginalPomUrl(pom_document)
        isIdentical =  parentPomHandler.compareTwoCordinatesArr(cordinatesArr,orginalCordinateArr)
   elsif (@@cordinateArr.length > 0)
		isIdentical=true
      end
  if !isIdentical
      eachPomPath = eachPom.sub("/pom.xml","")
      Dir.chdir(eachPomPath) {
        result = `mvn help:effective-pom -Doutput=effective_pom.xml`
        puts result # Maven out-put
        generate_temp_xml()
  @@projectsWithExternalConfiguration.push(eachPomPath)
        basicInfoHandler = BasicInfoHandler.new
        basicInfoHandler.handleGrpAndArtifact(eachPomPath)
        basicInfoHandler.handleModelVersion(eachPomPath)
        basicInfoHandler.handleInceptionYearDescAndOrganization(eachPomPath)
        basicInfoHandler.handleProjectUrl(eachPomPath)
        basicInfoHandler.handleDevelopersContributorsMailingLists(eachPomPath)
        basicInfoHandler.handleScmIssueManagementCiManagement(eachPomPath)
        basicInfoHandler.handleDistributionManagement(eachPomPath)
        basicInfoHandler.handleRepositories(eachPomPath)
        basicInfoHandler.handlePluginRepositories(eachPomPath)
        pluginHandler =  PluginHandler.new
        pluginHandler.addBuildTag()
        pluginHandler.addReportingTag()
        propertyHandler = PropertyHandler.new
        propertyHandler.handleProperties(eachPomPath)
        dependencyHandler = DependencyHandler.new
        dependencyHandler.projectPomDependencyHandler()
        tempDependencyList = dependencyHandler.getTempDependencyList()
        childDependencyMap = dependencyHandler.getOriginalDependencyMap()
        parentDependencyMap = dependencyHandler.getImmediateParentDependencyMap()
        grandParentDependencyMap = dependencyHandler.getgrandParentDependencyMap()
        dependencyHandler.findPlaceHolderWithinPoms(tempDependencyList,childDependencyMap,parentDependencyMap,grandParentDependencyMap)
        project_end()
        tempPropertyMap = propertyHandler.getTempPropertyMap()
        childPropertyMap = propertyHandler.getOriginalPropertyMap()
        parentPropertyMap = propertyHandler.getImidiateParentPropertyMap()
        grandparentPropertyMap = propertyHandler.getgrandParentPropertyMap()
        propertyHandler.findPlaceHolderWithinProperties(tempPropertyMap,childPropertyMap,parentPropertyMap,grandparentPropertyMap)
        pluginHandler.removePluginManagementTag()
        pluginList =  pluginHandler.getGrpAndArtifactIdOfPlugins()
        pluginHandler.compareWithOriginalPomPlugin(pluginList)
        pluginHandler.compareWithParentPomPlugin(pluginList)
        pluginHandler.compareWithGrandParentPomPlugin(pluginList)
        pluginHandler.removeExtraTag("build")
        #Reporting plugin
        reportSwitch = "reporting"
        pluginList =  pluginHandler.getGrpAndArtifactIdOfPlugins(reportSwitch)
        pluginHandler.compareWithOriginalPomPlugin(pluginList,reportSwitch)
        pluginHandler.compareWithParentPomPlugin(pluginList,reportSwitch)
        pluginHandler.compareWithGrandParentPomPlugin(pluginList,reportSwitch)
        pluginHandler.removeExtraTag("reporting")
        #Site and eclipse plugin
        handleSiteAndEclipsePlugin(eachPomPath)
        closeFileObj()
        basicInfoHandler.renamePom(eachPomPath)
        basicInfoHandler.renameTemp(eachPomPath)
  puts "Original pom is reanamed to pom_back.xml"
      }
 else
        puts "Provided parent URL and external configuration are same"
       end
    else
      eachPomPath = eachPom.sub("/pom.xml","")
      index = eachPomPath.rindex("/")
      projectName = eachPomPath[index+1,eachPomPath.length-1]
      puts "No parent found for #{projectName} project"
    end
  end
  puts "Effective pom generation is completed"
end

#dmpmForexternalConfiguration(project_directory_path, externalPomUrl) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/mavenReactorService/ReactorHandler.rb', line 224

def dmpmForexternalConfiguration(project_directory_path,externalPomUrl)
  if @@flag
   dmAndPMManagementForExternalConfiguration =  DMAndPMManagementForExternalConfiguration.new
    cordinateArr =  dmAndPMManagementForExternalConfiguration.getParentCordinates(externalPomUrl,"dependency")
    dmAndPMManagementForExternalConfiguration.comparetheVersionWithParent(project_directory_path,cordinateArr,"dependencies/dependency")
    dmAndPMManagementForExternalConfiguration.comparetheVersionWithParent(project_directory_path,cordinateArr,"dependencyManagement/dependencies/dependency")
    cordinateArr =  dmAndPMManagementForExternalConfiguration.getParentCordinates(externalPomUrl,"plugins")
    dmAndPMManagementForExternalConfiguration.comparethePluginVersionWithParent(project_directory_path,cordinateArr,"project/build/plugins/plugin")
    dmAndPMManagementForExternalConfiguration.comaprePluginVersionWihReactorPom(project_directory_path,cordinateArr,"project/build/pluginManagement/plugins/plugin")
  end
end

#fetchGidArtifactIdAndVersionFromChildModule(project_directory_path, retDecision) ⇒ Object

This api will return the list of projects path of individual projects #



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/mavenReactorService/ReactorHandler.rb', line 169

def fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,retDecision)
  alldir = Dir.entries(project_directory_path)
  pomFilePath=Array.new
  alldir.each do |fileLtst|
    if File.directory? fileLtst
      if !(File.basename(fileLtst) == "." || File.basename(fileLtst) == "..")
        innerFileLtst =  Dir.entries(fileLtst)
        innerFileLtst.each do |eachInner|
          fileName = File.basename(eachInner)
          if fileName == "pom.xml"
            pomFilePath.push("#{File.expand_path(fileLtst)}/#{fileName}")
          end
        end
      end
    end
  end
  if (retDecision)
    mvnReactorization =  MvnReactorization.new
    finalSnapShot =  mvnReactorization.findHighestVersionOfPom(pomFilePath)
    fullDetails =  mvnReactorization.getDetails(pomFilePath[0])
    fullDetails[2]=finalSnapShot
    return fullDetails
  else
    return pomFilePath
  end
end

#generate_temp_xmlObject

This api generate blank temp.xml inside the individual projects #



277
278
279
280
# File 'lib/mavenReactorService/ReactorHandler.rb', line 277

def generate_temp_xml()
  dest = "temp.xml"
  File.write("temp.xml","<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>")
end

#handleDeveloperAndContributors(project_directory_path) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mavenReactorService/ReactorHandler.rb', line 142

def handleDeveloperAndContributors(project_directory_path)
  developerAndContributors = DeveloperAndContributors.new
  commonDevelopers = developerAndContributors.findCommonDevelopers(project_directory_path,"developers/developer")
  developersAndContributorsList =  developerAndContributors.mergeDeveloperAndContributors(project_directory_path,commonDevelopers,"developers/developer")
  developerAndContributors.addDeveloperAndContributersInReator(project_directory_path,developersAndContributorsList,"developers")
  developerAndContributors.removeCommonDevelopersAndContributorsFromChild(project_directory_path,commonDevelopers,"developers/developer")
  #developerAndContributors.removeEmptyTags(project_directory_path,"developers")
  #Contributors
  commonDevelopers = developerAndContributors.findCommonDevelopers(project_directory_path,"contributors/contributor")
  developersAndContributorsList =  developerAndContributors.mergeDeveloperAndContributors(project_directory_path,commonDevelopers,"contributors/contributor")
  developerAndContributors.addDeveloperAndContributersInReator(project_directory_path,developersAndContributorsList,"contributors")
  developerAndContributors.removeCommonDevelopersAndContributorsFromChild(project_directory_path,commonDevelopers,"contributors/contributor")
  #developerAndContributors.removeEmptyTags(project_directory_path,"contributors")
end

#handleInterDependency(project_directory_path) ⇒ Object



137
138
139
140
# File 'lib/mavenReactorService/ReactorHandler.rb', line 137

def handleInterDependency(project_directory_path)
  interDependencyHandler = InterDependencyHandler.new
  interDependencyHandler.handleInterDependecy(project_directory_path)
end

#handleSiteAndEclipsePlugin(project_directory_path) ⇒ Object



92
93
94
95
96
# File 'lib/mavenReactorService/ReactorHandler.rb', line 92

def handleSiteAndEclipsePlugin(project_directory_path)
  siteAndEclipsePluginHandler = SiteAndEclipsePluginHandler.new
  siteAndEclipsePluginHandler.managePlugins(project_directory_path,"org.apache.maven.plugins:maven-site-plugin")
  siteAndEclipsePluginHandler.managePlugins(project_directory_path,"org.apache.maven.plugins:maven-eclipse-plugin")
end

#handleTeamSpecificParent(project_directory_path, externalConfigUrl) ⇒ Object



162
163
164
165
166
167
# File 'lib/mavenReactorService/ReactorHandler.rb', line 162

def handleTeamSpecificParent(project_directory_path,externalPomUrl)
  if ((!externalPomUrl.nil?) and (externalPomUrl.include? "https://" or externalPomUrl.include? "http://"))
    parentPomHandler = ParentPomHandler.new
    parentPomHandler.setParentInreactor(project_directory_path,externalPomUrl)
  end
end

#makeReator(project_directory_path) ⇒ Object



98
99
100
101
# File 'lib/mavenReactorService/ReactorHandler.rb', line 98

def makeReator(project_directory_path)
  mvnReactorization =  MvnReactorization.new
  mvnReactorization.makeReactor(project_directory_path)
end

#manageDepedency(project_directory_path) ⇒ Object



103
104
105
106
# File 'lib/mavenReactorService/ReactorHandler.rb', line 103

def manageDepedency(project_directory_path)
  dependencyManagementHandler = DependencyManagementHandler.new
  dependencyManagementHandler.handleDependencyManagement(project_directory_path)
end

#managePlugins(project_directory_path) ⇒ Object



108
109
110
111
112
113
# File 'lib/mavenReactorService/ReactorHandler.rb', line 108

def managePlugins(project_directory_path)
  pluginManagementHandler = PluginManagementHandler.new
  pluginManagementHandler.comparePluginManagementFromChildModule(project_directory_path)
  pluginManagementHandler.handlePluginManagement(project_directory_path)
  pluginManagementHandler.findCommonPluginFromPluginManagement(project_directory_path)
end

#mergeRepository(project_directory_path) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/mavenReactorService/ReactorHandler.rb', line 120

def mergeRepository(project_directory_path)
  mergeRepository =MergeRepository.new
  #Repositories
  commonUrlList =  mergeRepository.findCommonRepos(project_directory_path,"repositories/repository")
  rootRepo = mergeRepository.makeFullRepoFromCommonRepo(project_directory_path,"repositories/repository",commonUrlList)
  mergeRepository.addRepoIntoReactorPom(project_directory_path,rootRepo,"repositories")
  mergeRepository.deleteRepoFromChildModule(project_directory_path,"repositories")
  mergeRepository.renameDuplicateRepoId(project_directory_path,"repositories/repository")
  #PluginRepositories
  commonUrlList =  mergeRepository.findCommonRepos(project_directory_path,"pluginRepositories/pluginRepository")
  rootRepo = mergeRepository.makeFullRepoFromCommonRepo(project_directory_path,"pluginRepositories/pluginRepository",commonUrlList)
  mergeRepository.addRepoIntoReactorPom(project_directory_path,rootRepo,"pluginRepositories")
  mergeRepository.deleteRepoFromChildModule(project_directory_path,"pluginRepositories")
  mergeRepository.renameDuplicateRepoId(project_directory_path,"pluginRepositories/pluginRepository")
puts "Renamed repo is done"
end

#moveCommonProperties(project_directory_path) ⇒ Object



196
197
198
199
200
201
# File 'lib/mavenReactorService/ReactorHandler.rb', line 196

def moveCommonProperties (project_directory_path)
  moveCommonPropertiesToRootPom = MoveCommonPropertiesToRootPom.new
  commonProperties = moveCommonPropertiesToRootPom.findCommonProperties(project_directory_path)
  moveCommonPropertiesToRootPom.writeCommonPropertiesToReactorPom(project_directory_path,commonProperties)
  moveCommonPropertiesToRootPom.removeCommonPropertiesfromModules(project_directory_path,commonProperties)
end

#parse_xml_from_file(file_path) ⇒ Object

This api is used to create dom object of pom #



292
293
294
295
296
297
298
299
300
301
302
# File 'lib/mavenReactorService/ReactorHandler.rb', line 292

def parse_xml_from_file(file_path)
  @@xml_file = File.open(file_path)
  Nokogiri::XML(@@xml_file, &:strict)
rescue Errno::ENOENT
  raise Errno::ENOENT,
  "Couldn't locate a file at that path, please check the path!"
rescue Nokogiri::XML::SyntaxError => e
  raise Nokogiri::XML::SyntaxError,
  "The following errors occurred while parsing your XML file: \n" +
  e.message
end

#plugiConfigHandler(project_directory_path) ⇒ Object



115
116
117
118
# File 'lib/mavenReactorService/ReactorHandler.rb', line 115

def plugiConfigHandler(project_directory_path)
  pluginConfigurationHandler=  PluginConfigurationHandler.new
  pluginConfigurationHandler.mergePluginConfiguration(project_directory_path,@@projectsWithExternalConfiguration)
end

#project_endObject



282
283
284
285
286
287
288
289
# File 'lib/mavenReactorService/ReactorHandler.rb', line 282

def project_end()
  tempXml = "temp.xml"
  file = File.open(tempXml)
  contents = file.read
  if !contents.include? "</project>"
    File.write(tempXml, "</project>", File.size(tempXml), mode: 'a')
  end
end

#removeEmptyTags(project_directory_path) ⇒ Object



208
209
210
211
212
213
214
215
216
# File 'lib/mavenReactorService/ReactorHandler.rb', line 208

def removeEmptyTags(project_directory_path)
 pomPathArr =  fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
 mvnReactorization = MvnReactorization.new
 pomPathArr.each do |eachPomPath|
   pom_document = parse_xml_from_file(eachPomPath)
   clean(pom_document.at("project"))
   mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
 end
end

#sortPomExecutorObject



157
158
159
160
# File 'lib/mavenReactorService/ReactorHandler.rb', line 157

def sortPomExecutor()
  pluginManagementHandler = PluginManagementHandler.new
  pluginManagementHandler.executeShortPom()
end

#tag_exists?(tag, pom_nokogiri, data = nil) ⇒ Boolean

This api checks a particular tag present or not and return boolean value #

Returns:

  • (Boolean)


255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/mavenReactorService/ReactorHandler.rb', line 255

def tag_exists?(tag, pom_nokogiri, data = nil)
  temp = pom_nokogiri.dup
  temp.remove_namespaces!
  if data.nil?
    # Searching only for tag when data is not supplied
    !temp.xpath("//#{tag}").empty?
  else
    # Searching for entire the node with given tag and data
    at_parameter = "#{tag}:contains('#{data}')"
    found_match = temp.at(at_parameter)
    # Confirming that whole string matches as contains can
    # report success if even a part of string matches
    !found_match.nil? && found_match.text.strip == data
  end
rescue Nokogiri::XML::XPath::SyntaxError, RuntimeError, NoMethodError, TypeError
  # Rescue is hit only when
  # Supplied tag is either empty or nil or
  # Supplied pom_nokogiri is nil
  raise 'Either tag or pom object supplied is empty or nil'
end

#validateProjectsEligiblity(project_directory_path) ⇒ Object



249
250
251
252
# File 'lib/mavenReactorService/ReactorHandler.rb', line 249

def validateProjectsEligiblity (project_directory_path)
  validateProjects = ValidateProjects.new
  validateProjects.checkEligiblityForReactorization(project_directory_path)
end