Class: MoveCommonPropertiesToRootPom

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

Constant Summary collapse

@@reactorHandler =
ReactorHandler.new
@@modulePomPaths =
nil

Instance Method Summary collapse

Instance Method Details

#findCommonProperties(project_directory_path) ⇒ Object



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

def findCommonProperties (project_directory_path)
  @@modulePomPaths =  @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  allModuleProperties = Array.new
  commonProperties = Array.new
  @@modulePomPaths.each do |modulePomPath|
    modulePomDoc = Nokogiri::XML(open(modulePomPath))
    modulePomDoc.css("project/properties").children.each do |property|
      if property.name != 'text' && property.name != 'comment'
        propertyNameValue = "#{property.name}:#{property.text}"
        allModuleProperties.push(propertyNameValue)
      end
    end
  end
  allModuleProperties.uniq.each do |property|
    if allModuleProperties.count(property) == @@modulePomPaths.length
      commonProperties.push(property)
    end
  end
  return commonProperties
end

#removeCommonPropertiesfromModules(project_directory_path, commonProperties) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mavenReactorService/MoveCommonPropertiesToRootPom.rb', line 45

def removeCommonPropertiesfromModules (project_directory_path,commonProperties)
  
  @@modulePomPaths.each do |eachModulePath|
    pom_document = @@reactorHandler.parse_xml_from_file(eachModulePath)
    commonProperties.each do |property|
      propNameValue = property.split(':')
      propName = propNameValue[0]
      pom_document.css('project/properties').children.each do |eachProperty|
        if eachProperty.name == propName
          eachProperty.remove
        end
      end        
    end
  File.write(eachModulePath,pom_document)
  end
  puts "Common properties removed from child modules!!!"
end

#writeCommonPropertiesToReactorPom(project_directory_path, commonProperties) ⇒ Object



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

def writeCommonPropertiesToReactorPom (project_directory_path,commonProperties)
  reactorPomPath = "#{project_directory_path}/pom.xml"
  pom_document = @@reactorHandler.parse_xml_from_file(reactorPomPath)
  nokObj = Nokogiri::XML::Node
  projectNode =  pom_document.at('project')
  propertiesNode =  nokObj.new('properties',projectNode)
  commonProperties.each do |property|
    propNameValue = property.split(':')
    propName = propNameValue[0]
    propValue = propNameValue[1]
    propNode = nokObj.new(propName,projectNode)
    propNode.content = propValue
    propertiesNode.add_child(propNode)
  end
  dependencyHandler = DependencyHandler.new
  pomObj = dependencyHandler.add_node_element('project',propertiesNode,pom_document)
  File.write(reactorPomPath,pomObj)
  puts "Moved common properties to reactor pom!!!"
end