Class: DMAndPMManagementForExternalConfiguration

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

Constant Summary collapse

@@reactorHandler =
ReactorHandler.new
@@mvnReactorization =
MvnReactorization.new
@@cordinateArr =
Array.new

Instance Method Summary collapse

Instance Method Details

#comaprePluginVersionWihReactorPom(project_directory_path, cordinateArr, tag) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 145

def comaprePluginVersionWihReactorPom(project_directory_path,cordinateArr,tag)
  pomPath = "#{project_directory_path}/pom.xml"
  pom_document =  @@reactorHandler.parse_xml_from_file(pomPath)
  pom_document.css(tag).each do |eachPlugin|
    grpId=nil
    if (eachPlugin.at("groupId").nil?)
      grpId="org.apache.maven.plugins"
    else
      grpId = eachPlugin.at("groupId").text
    end
    artifactId =  eachPlugin.at("artifactId").text
    version=nil
    fullArtifactId=nil
    isParentGreater=false
    if ((!eachPlugin.at("version").nil?) and (eachPlugin.at("version").parent.name=="plugin"))
      version = eachPlugin.at("version").text
      fullArtifactId = "#{grpId}:#{artifactId}:#{version}"
      isParentGreater =  findHigherVersionOfPlugin(fullArtifactId,cordinateArr)
    end
    if (!fullArtifactId.nil? and isParentGreater)
      eachPlugin.remove
    end
  end
 pluginNode =  pom_document.at("project/build/pluginManagement/plugins/plugin")
 buildNode = pom_document.at("project/build")
 if (pluginNode.nil? and !buildNode.nil?)
   buildNode.remove
 end
  @@mvnReactorization.write_nokogiri_to_xml(pomPath, pom_document)
  puts "remove version of plugin is successfull"
end

#comparethePluginVersionWithParent(project_directory_path, cordinateArr, tag) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 111

def comparethePluginVersionWithParent(project_directory_path,cordinateArr,tag)
  pomPathArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  pomPathArr.each do |eachPomPath|
    pom_document =  @@reactorHandler.parse_xml_from_file(eachPomPath)
    pom_document.css(tag).each do |eachPlugin|
      grpId=nil
      if (eachPlugin.at("groupId").nil?)
        grpId="org.apache.maven.plugins"
      else
        grpId = eachPlugin.at("groupId").text
      end
      artifactId =  eachPlugin.at("artifactId").text
      version=nil
      fullArtifactId=nil
      isParentGreater=false
      if ((!eachPlugin.at("version").nil?) and (eachPlugin.at("version").parent.name=="plugin"))
        version = eachPlugin.at("version").text
        if version.include?"${"
          version = version.gsub("${","")
          version = version.gsub("}","")
          version =  findPropVal(pom_document,version)
        end
        fullArtifactId = "#{grpId}:#{artifactId}:#{version}"
        isParentGreater =  findHigherVersionOfPlugin(fullArtifactId,cordinateArr)
      end
      if (!fullArtifactId.nil? and isParentGreater)
        eachPlugin.at("version").remove
      end
    end
    @@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
    puts "remove version of plugin is successfull"
  end
end

#comparetheVersionWithParent(project_directory_path, cordinateArr, tag) ⇒ 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
106
107
108
109
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 80

def comparetheVersionWithParent(project_directory_path,cordinateArr,tag)
  pomPathArr = @@reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
  reactorPomPath = "#{project_directory_path}/pom.xml"
  pomPathArr.push(reactorPomPath)
  pomPathArr.each do |eachPomPath|
    pom_document =  @@reactorHandler.parse_xml_from_file(eachPomPath)
    pom_document.css(tag).each do |eachDependency|
      grpId=nil
      if (eachDependency.at("groupId").nil?)
        grpId="org.apache.maven.plugins"
      else
        grpId = eachDependency.at("groupId").text
      end
      artifactId =  eachDependency.at("artifactId").text
      version=nil
      fullArtifactId=nil
      if ((!eachDependency.at("version").nil?) and (eachDependency.at("version").parent.name=="dependency"))
        version = eachDependency.at("version").text
        fullArtifactId = "#{grpId}:#{artifactId}:#{version}"
      end
      if (!fullArtifactId.nil? and cordinateArr.include?fullArtifactId and !tag.include?"dependencyManagement/" and eachDependency.parent.parent.name=="project")
        eachDependency.at("version").remove
      elsif (cordinateArr.include?fullArtifactId and eachDependency.at("exclusions").nil? and tag.include?"dependencyManagement/")
        eachDependency.remove
      end
    end
    @@mvnReactorization.write_nokogiri_to_xml(eachPomPath, pom_document)
    puts "Dm is done"
  end
end

#compareVersion(childPluginVersion, parentVersion) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 197

def compareVersion(childPluginVersion,parentVersion)
  if (!childPluginVersion.nil? and !parentVersion.nil? and parentVersion>=childPluginVersion)
    return true
  else
    return false
  end
end

#findHigherVersionOfPlugin(fullArtifactId, cordinateArr) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 177

def findHigherVersionOfPlugin(fullArtifactId,cordinateArr)
  isParentGreater = false
  cordinateArrWithoutVersion = Hash.new
  cordinateArr.each do |eachCordinate|
    eachValArr = eachCordinate.split(":")
    grpId = eachValArr[0]
    artifactId = eachValArr[1]
    fullArtfactId = "#{grpId}:#{artifactId}"
    cordinateArrWithoutVersion[fullArtfactId] = eachValArr[2]
  end
  childCordinateArr = fullArtifactId.split(":")
  childCordinate = "#{childCordinateArr[0]}:#{childCordinateArr[1]}"
  childPluginVersion = childCordinateArr[2]
  if(!cordinateArrWithoutVersion[childCordinate].nil?)
    parentVersion = cordinateArrWithoutVersion[childCordinate]
    isParentGreater = compareVersion(childPluginVersion,parentVersion)
  end
  return isParentGreater
end

#findParent(pom_document, tag) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 29

def findParent(pom_document,tag)
  if @@reactorHandler.tag_exists?('project/parent', pom_document)
    dependencyHandler = DependencyHandler.new
    parentPom = dependencyHandler.getParentPomDomObjFromUrl(pom_document)
    if tag == "dependency"
      getCordinatesListFromEffectivepom(parentPom)
    else
      getCordinatesFromParentPlugin(parentPom,"project/build/pluginManagement/plugins/plugin")
      getCordinatesFromParentPlugin(parentPom,"project/build/plugins/plugin")
    end
  else
    puts ":::::::::::End of Searching::::::"
  end
end

#findPropVal(pom_document, proTag) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 70

def findPropVal(pom_document,proTag)
  propVal=nil
  pom_document.at("project/properties").children.each do |eachProp|
    if eachProp.name == proTag
      propVal =  eachProp.text
    end
  end
  return propVal
end

#getCordinatesFromParentPlugin(pom_document, tag) ⇒ Object



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

def getCordinatesFromParentPlugin(pom_document,tag)
  pom_document.css(tag).each do |eachPlugin|
    grpId=nil
    if (eachPlugin.at("groupId").nil?)
      grpId="org.apache.maven.plugins"
    else
      grpId = eachPlugin.at("groupId").text
    end
    artifactId =  eachPlugin.at("artifactId").text
    version=nil
    if (!eachPlugin.at("version").nil? and eachPlugin.at("version").parent.name=="plugin")
      version =  eachPlugin.at("version").text
    end
    if !version.nil?
      if version.include?"${"
        version = version.gsub("${","")
        version = version.gsub("}","")
        version =  findPropVal(pom_document,version)
      end
      fullCordinate = "#{grpId}:#{artifactId}:#{version}"
      @@cordinateArr.push(fullCordinate)
    end
  end
  findParent(pom_document,"plugins")
end

#getCordinatesListFromEffectivepom(pom_document) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 18

def getCordinatesListFromEffectivepom(pom_document)
  pom_document.css("project/dependencyManagement/dependencies/dependency").each do |eachDependency|
    grpId =  eachDependency.at("groupId").text
    artId = eachDependency.at("artifactId").text
    version = eachDependency.at("version").text
    fullDependency = "#{grpId}:#{artId}:#{version}"
    @@cordinateArr.push(fullDependency)
  end
  findParent(pom_document,"dependency")
end

#getParentCordinates(externalPomUrl, tag) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mavenReactorService/DMAndPMManagementForExternalConfiguration.rb', line 6

def getParentCordinates(externalPomUrl,tag)
  pom_document = Nokogiri::XML(open(externalPomUrl))
  if tag == "dependency"
    getCordinatesListFromEffectivepom(pom_document)
  else
    @@cordinateArr=Array.new
    getCordinatesFromParentPlugin(pom_document,"project/build/pluginManagement/plugins/plugin")
    getCordinatesFromParentPlugin(pom_document,"project/build/plugins/plugin")
  end
  return @@cordinateArr.uniq
end