2
3
4
5
6
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
37
38
39
40
41
42
43
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
69
|
# File 'lib/mavenReactorService/ValidateProjects.rb', line 2
def checkEligiblityForReactorization (project_directory_path)
puts "Checking Eligibility for Reactorization"
reactorHandler = ReactorHandler.new
basePomCordinate = 'com.cerner.maven:maven-base-pom'
modulePomPaths = reactorHandler.fetchGidArtifactIdAndVersionFromChildModule(project_directory_path,false)
ancestorStrings = Array.new
indexCounter = 0
modulePomPaths.each do |modulePomFile|
eachPomPath = modulePomFile.sub("/pom.xml","")
Dir.chdir(eachPomPath){
`mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:display-ancestors > ancestors.txt`
File.open('ancestors.txt').each do |line|
if line.start_with?("[INFO] Ancestor POMs:")
= line.sub("[INFO] Ancestor POMs: ","")
puts
ancestorStrings.push()
else
if line.start_with?("[FATAL] Non-resolvable parent POM") or line.start_with?("[ERROR]")
raise `mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:display-ancestors`
end
end
end
}
end
ancestorStrings.each do |ancestorString|
if ancestorString.include?(basePomCordinate)
indexCounter = indexCounter + 1
end
end
if ancestorStrings.length == 0
puts "No projects have ancestors POM\. Good to go!!!"
else
if indexCounter == ancestorStrings.length and indexCounter == modulePomPaths.length
mbpHash = Hash.new
nonMbpHash = Hash.new
grandMbpHash = Hash.new
ancestorStrings.each do |ancestorString|
ancestors = ancestorString.split(' <- ')
if ancestors[0].include?(basePomCordinate)
mbpHash[ancestors[0]] = 1
else
nonMbpHash[ancestors[0]] = 1
end
if ancestors.length > 1
ancestors.each_with_index do |ancstor,index|
if index > 0 and ancstor.include?(basePomCordinate)
grandMbpHash[ancstor] = 1
end
end
end
end
if mbpHash.length == 1
puts "All projects have MBP as their immediate ancestors with identical version. Good to go !!!"
else
if nonMbpHash.length == 1 and grandMbpHash.length == 1
puts "All projects have identical non MBP as their immediate ancestors as well as identical MBP as their grand ancestor . Good to go !!!"
else
raise "All projects do not have identical immediate ancestors and MBP as their one of the ancestor. Aborting the reactorization !!!"
end
end
elsif indexCounter == 0
puts "No ancestors are MBP. Good to go!!!"
else
raise "Not all projects have MBP as their ancestors but few of them have\. Not eligible for reactorization. Aborting the reactorization"
end
end
end
|