Class: MergeRepository

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

Constant Summary collapse

@@reactorHandler =
ReactorHandler.new
@@dependencyHandler =
DependencyHandler.new
@@mvnReactorization =
MvnReactorization.new

Instance Method Summary collapse

Instance Method Details

#addRepoIntoReactorPom(project_directory_path, rootRepo, tagName) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mavenReactorService/MergeRepository.rb', line 47

def addRepoIntoReactorPom (project_directory_path,rootRepo,tagName)
  fullPomPath = "#{project_directory_path}/pom.xml"
  pom_document = Nokogiri::XML(open(fullPomPath))
  if !(pom_document.at_css("project/#{tagName}").nil?)
    pom_document.at_css("project/#{tagName}").remove
  end
  nokObj = Nokogiri::XML::Node
  projectNode =  pom_document.at("project")
  repositoriesnode =  nokObj.new(tagName,projectNode)
  repositoryStr = rootRepo.to_s
  repoStrBuffer =  StringIO.new
  rootRepo.each do |eachRepo|
    repoStrBuffer << eachRepo
  end
  repositoriesStr =  repoStrBuffer.string
  repositorynode =  nokObj.new(repositoriesStr,projectNode)
  repositoriesnode.add_child(repositorynode)
  repoStr =  repositoriesnode.to_s
  repoStr = repoStr.gsub(">/>",">")
  repoStr = repoStr.gsub("<<","<")
  pom_nokogiri = @@dependencyHandler.add_node_element('project', repoStr, pom_document)
  File.write(fullPomPath, pom_nokogiri)
  @@mvnReactorization.generateFormatedXml(project_directory_path)
end

#deleteRepoFromChildModule(project_directory_path, tagName) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/mavenReactorService/MergeRepository.rb', line 72

def deleteRepoFromChildModule(project_directory_path,tagName)
  childPomPathArr =   @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  childPomPathArr.each do |eachChildPom|
    child_pom_document = Nokogiri::XML(open(eachChildPom))
    child_pom_document.at_css("project/#{tagName}").remove
    File.write(eachChildPom, child_pom_document)
  end
end

#findCommonRepos(project_directory_path, tagName) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mavenReactorService/MergeRepository.rb', line 5

def findCommonRepos(project_directory_path,tagName)
  childPomPathArr =  @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  fullPomPath = "#{project_directory_path}/pom.xml"
  pom_document = Nokogiri::XML(open(fullPomPath))
  repoIdArr = Array.new
  childPomPathArr.each do |eachChildModule|
    child_pom_document = Nokogiri::XML(open(eachChildModule))
    child_pom_document.css("project/#{tagName}").each do |eachChildRepo|
      eachChildId =   eachChildRepo.at("url").text
      lastChar = eachChildId[-1]
      if lastChar=="/"
        eachChildId =  eachChildId.chomp(lastChar)
      end
        if !(repoIdArr.include?eachChildId)
          repoIdArr.push(eachChildId)
        end
    end
  end
  return repoIdArr
end

#makeFullRepoFromCommonRepo(project_directory_path, tagName, commonUrlList) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mavenReactorService/MergeRepository.rb', line 26

def makeFullRepoFromCommonRepo(project_directory_path,tagName,commonUrlList)
  childPomPathArr =  @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  rootRepo =   Array.new
  identifierList = Array.new
  childPomPathArr.each do |eachChildModule|
    child_pom_document = Nokogiri::XML(open(eachChildModule))
    child_pom_document.css("project/#{tagName}").each do |eachChildRepo|
      eachChildId =   eachChildRepo.at("url").text
      lastChar = eachChildId[-1]
      if lastChar=="/"
        eachChildId =  eachChildId.chomp(lastChar)
      end
      if ((commonUrlList.include?eachChildId) and !(identifierList.include?eachChildId))
        rootRepo.push(eachChildRepo)
        identifierList.push(eachChildId)
      end
    end
  end
  return rootRepo
end

#renameDuplicateRepoId(project_directory_path, tagName) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mavenReactorService/MergeRepository.rb', line 80

def renameDuplicateRepoId(project_directory_path,tagName)
  reactorPom = "#{project_directory_path}/pom.xml"
  repoIdList = Array.new
  counter = 1
  reactorPomDoc = Nokogiri::XML(open(reactorPom))
  reactorPomDoc.css("project/#{tagName}").each do |eachChildRepo|
    repoId = eachChildRepo.at("id").text
    if (repoIdList.include?repoId)
      idNode = eachChildRepo.at("id")
      idNode.content = "#{repoId}-#{counter}"
      counter = counter+1
    else
      repoIdList.push(repoId)
    end
  end
  File.write(reactorPom, reactorPomDoc)
end