class ValidateProjects 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:") ancestorsString = line.sub("[INFO] Ancestor POMs: ","") puts ancestorsString ancestorStrings.push(ancestorsString) 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 !!!" return mbpHash 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 !!!" return nonMbpHash 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 end