Class: PluginConfigurationHandler

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

Constant Summary collapse

@@reactorHandler =
ReactorHandler.new
@@xPathOfLeafNode =
nil
@@leafNodesXpathMasterList =
nil
@@mvnReactorization =
MvnReactorization.new

Instance Method Summary collapse

Instance Method Details

#AppendLeafNodesToOuterConfig(plugin, xPathsLeafNode) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/mavenReactorService/PluginConfigurationHandler.rb', line 80

def AppendLeafNodesToOuterConfig (plugin,xPathsLeafNode)
  plugin.css('configuration').each do |configuration|
    if configuration.parent.name == "plugin"

      puts configuration
      puts "*********************************************************************"
      puts xPathsLeafNode

      leafNodeXpathArray = xPathsLeafNode.split('>')
      #nodeToCheckAndCreate = leafNodeXpathArray [leafNodeXpathArray.length - ]

    end
  end

  #    puts plugin
  #    puts "*********************************************"
  #    puts xPathsLeafNode

  #    pluginConfigMap.each do |plugin,nodes|
  #      if !nodes.empty?
  #        puts "#{plugin} => #{nodes}"
  #
  #      end
  #    end

end

#findConfigurationLeafNode(configuration) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mavenReactorService/PluginConfigurationHandler.rb', line 56

def findConfigurationLeafNode (configuration)
  configuration.children.each do |leafNode|
    if leafNode.children.length>1
      findConfigurationLeafNode(leafNode)
    else
      if leafNode.name != 'text'
        findXpathOfLeafNode (leafNode)
        @@xPathOfLeafNode = "#{@@xPathOfLeafNode}#{leafNode.name}>#{leafNode.text}"
      end
      if !@@xPathOfLeafNode.nil?
        @@leafNodesXpathMasterList.push(@@xPathOfLeafNode)
      end
      @@xPathOfLeafNode = nil
    end
  end
end

#findXpathOfLeafNode(leafNode) ⇒ Object



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

def findXpathOfLeafNode (leafNode)
  if (leafNode.parent.name != 'plugin' && leafNode.parent.name != 'text' && leafNode.parent.name != 'execution')
    @@xPathOfLeafNode = "#{leafNode.parent.name}>#{@@xPathOfLeafNode}"
    findXpathOfLeafNode(leafNode.parent)
  end
end

#mergePluginConfiguration(project_directory_path, projectsWithExternalConfiguration) ⇒ Object



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

def mergePluginConfiguration (project_directory_path,projectsWithExternalConfiguration)
  projectsWithExternalConfiguration.each do |projectPath|
    fullPomPath = "#{projectPath}/pom.xml"
    modulePomDoc = Nokogiri::XML(open(fullPomPath))
    if(!modulePomDoc.nil?)
      modulePomDoc.css('project/build/plugins/plugin').each do|plugin|
        @@leafNodesXpathMasterList = Array.new
        configNode = plugin.at('configuration')
        executionsNode = plugin.at('executions')
        if (!configNode.nil? and configNode.parent.name == "plugin")
          findConfigurationLeafNode(configNode)
          xpathConfigList =  @@leafNodesXpathMasterList
          @@leafNodesXpathMasterList = Array.new
          if (!executionsNode.nil? and executionsNode.parent.name == "plugin")
            executionsNode.css("execution").each do |eachExecution|
              exeConfig = eachExecution.at("configuration")
              if (!exeConfig.nil?)
                findConfigurationLeafNode(exeConfig)
              end
            end
          end
          commonList = xpathConfigList & @@leafNodesXpathMasterList.uniq
          removeTagFromExecutions(commonList,plugin)
        end
      end
       @@mvnReactorization.write_nokogiri_to_xml(fullPomPath, modulePomDoc)
      puts "Plugin Configuration is done"
    end
  end
end

#removeTagFromExecutions(commonList, plugin) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mavenReactorService/PluginConfigurationHandler.rb', line 38

def removeTagFromExecutions(commonList,plugin)
  if (!commonList.nil? and !commonList.empty?)
    commonList.each do |eachEntry|
      lastValArr = eachEntry.split(">")
      lastVal = lastValArr.last
      finalEntry = "executions>execution>#{eachEntry}"
      finalEntry = finalEntry.chomp(">#{lastVal}")
      plugin.css(finalEntry).each do |eachEntry|
        textVal = eachEntry.text
        if (!textVal.nil? and !textVal.empty? and textVal == lastVal)
          eachEntry.remove
        end
      end

    end
  end
end