Class: InterDependencyHandler

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#getGidAndArtifactIdOfProject(pomArr) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mavenReactorService/InterDependencyHandler.rb', line 14

def getGidAndArtifactIdOfProject(pomArr)
  fullSignatureArr = Array.new
  if (!pomArr.nil? and !pomArr.empty?)
    pomArr.each do |eachPomPath|
      pom_document =  @@reactorHandler.parse_xml_from_file(eachPomPath)
      grpId =  pom_document.at("project/groupId").text
      artifactId =  pom_document.at("project/artifactId").text
      fullSignature = "#{grpId}:#{artifactId}"
      fullSignatureArr.push(fullSignature)
    end
  end
  return fullSignatureArr
end

#handleInterDependecy(project_directory_path) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/mavenReactorService/InterDependencyHandler.rb', line 6

def handleInterDependecy(project_directory_path)
  pomArr =  @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  fullSignatureArr =  getGidAndArtifactIdOfProject(pomArr)
  putCommentForinterDepedency(pomArr,fullSignatureArr)
  putCommentForinterDepedencyManagement(pomArr,fullSignatureArr)
  @@pluginManagementHandler.executeShortPom()
end

#putCommentForinterDepedency(pomArr, fullSignatureArr) ⇒ Object



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

def putCommentForinterDepedency(pomArr,fullSignatureArr)
  pomArr.each do |eachPomPath|
    pom_document =  @@reactorHandler.parse_xml_from_file(eachPomPath)
    nokObj = Nokogiri::XML::Node
    commentObj = Nokogiri::XML::Comment
    dependenciesNode = pom_document.at("project/dependencies")
    pom_document.css("project/dependencies/dependency").each do |eachDepedency|
      grpId = eachDepedency.at("groupId").text
      artifactId = eachDepedency.at("artifactId").text
      fullSignature = "#{grpId}:#{artifactId}"
      if (fullSignatureArr.include?fullSignature and !eachDepedency.at("version").nil?)
        version = eachDepedency.at("version").text
        eachDepedency.at("version").remove
        versionNode = nokObj.new("version",eachDepedency)
        versionNode.content=version
        commentNode  = commentObj.new(versionNode, " TODO: Version should be removed and managed by reactor pom version")
        versionNode.add_previous_sibling(commentNode)
        eachDepedency.add_child(commentNode)
        eachDepedency.add_child(versionNode)
        dependenciesNode.add_child(eachDepedency)
      end
    end
    @@dependencyHandler.add_node_element('//project', dependenciesNode, pom_document)
    @@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
  end
  puts "Comments added for sibling module dependency"
end

#putCommentForinterDepedencyManagement(pomArr, fullSignatureArr) ⇒ Object



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

def putCommentForinterDepedencyManagement(pomArr,fullSignatureArr)
  pomArr.each do |eachPomPath|
    pom_document =  @@reactorHandler.parse_xml_from_file(eachPomPath)
    nokObj = Nokogiri::XML::Node
    commentObj = Nokogiri::XML::Comment
    dependencyManagementNode = pom_document.at("project/dependencyManagement")
    dependenciesNode = pom_document.at("project/dependencyManagement/dependencies")
    pom_document.css("project/dependencyManagement/dependencies/dependency").each do |eachDepedency|
      grpId = eachDepedency.at("groupId").text
      artifactId = eachDepedency.at("artifactId").text
      fullSignature = "#{grpId}:#{artifactId}"
      if (fullSignatureArr.include?fullSignature and !eachDepedency.at("version").nil?)
        version = eachDepedency.at("version").text
        eachDepedency.at("version").remove
        versionNode = nokObj.new("version",eachDepedency)
        versionNode.content=version
        commentNode  = commentObj.new(versionNode, " TODO: Version should be removed and managed by reactor pom version")
        versionNode.add_previous_sibling(commentNode)
        eachDepedency.add_child(commentNode)
        eachDepedency.add_child(versionNode)
        dependenciesNode.add_child(eachDepedency)
      end
    end
    if !dependencyManagementNode.nil?
    dependencyManagementNode.add_child(dependenciesNode)
    @@dependencyHandler.add_node_element('//project', dependencyManagementNode, pom_document)
    @@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
    end
  end
  puts "Comments added for sibling module dependency"
end