lib/pom_license_check.rb
def check_pom pom_path
        xmlFile = File.new(pom_path)
        
        xmlDoc = Document.new(xmlFile)
        
        root = xmlDoc.root

        # check for studio property
        is_studio_sample = false
        root.elements.each("properties/com.tibco.ep.sb.studio.sample") do |property|
            is_studio_sample = property.get_text.to_s.downcase == "true"
        end
        
        # will return only the first license encountered
        root.elements.each("licenses/license") do |license|
            # <license>
            #     <name>BSD 3-Clause License</name>
            #     <url>https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE</url>
            #     <distribution>repo</distribution>
            # </license>
            lic_name = lic_url = lic_distrib = nil
            license.elements.each("name") { |name| lic_name = name.get_text }
            license.elements.each("url") { |url| lic_url = url.get_text }
            license.elements.each("distribution") { |distribution| lic_distrib = distribution.get_text }

            if lic_name != "BSD 3-Clause License" || lic_url != "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE" || lic_distrib != "repo"
                raise "Error: A BSD-3-clause license is required for #{pom_path} (found #{stringunify lic_name, lic_url, lic_distrib}, expected #{stringunify "BSD 3-Clause License", "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE", "repo"}"
            end
            return true
        end

        # studio samples MUST include the right license in the pom
        if is_studio_sample
            raise "Error: A license must be declared in #{pom_path}"
        end
        return true
    end
# checks for valid license group in pom.xml
checks for valid license group in pom.xml
checks for valid license group in pom . xml
def check_pom pom_path
        xmlFile = File.new(pom_path)
        xmlDoc = Document.new(xmlFile)
        root = xmlDoc.root
        is_studio_sample = false
        root.elements.each("properties/com.tibco.ep.sb.studio.sample") do |property|
            is_studio_sample = property.get_text.to_s.downcase == "true"
        end
        root.elements.each("licenses/license") do |license|
            lic_name = lic_url = lic_distrib = nil
            license.elements.each("name") { |name| lic_name = name.get_text }
            license.elements.each("url") { |url| lic_url = url.get_text }
            license.elements.each("distribution") { |distribution| lic_distrib = distribution.get_text }
            if lic_name != "BSD 3-Clause License" || lic_url != "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE" || lic_distrib != "repo"
                raise "Error: A BSD-3-clause license is required for #{pom_path} (found #{stringunify lic_name, lic_url, lic_distrib}, expected #{stringunify "BSD 3-Clause License", "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE", "repo"}"
            end
            return true
        end
        if is_studio_sample
            raise "Error: A license must be declared in #{pom_path}"
        end
        return true
    end
def check_pom pom_path xmlFile = File . new ( pom_path ) xmlDoc = Document . new ( xmlFile ) root = xmlDoc . root is_studio_sample = false root . elements . each ( "properties/com.tibco.ep.sb.studio.sample" ) do | property | is_studio_sample = property . get_text . to_s . downcase == "true" end root . elements . each ( "licenses/license" ) do | license | lic_name = lic_url = lic_distrib = nil license . elements . each ( "name" ) { | name | lic_name = name . get_text } license . elements . each ( "url" ) { | url | lic_url = url . get_text } license . elements . each ( "distribution" ) { | distribution | lic_distrib = distribution . get_text } if lic_name != "BSD 3-Clause License" || lic_url != "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE" || lic_distrib != "repo" raise "Error: A BSD-3-clause license is required for #{pom_path} (found #{stringunify lic_name, lic_url, lic_distrib}, expected #{stringunify "BSD 3-Clause License", "https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE", "repo"}" end return true end if is_studio_sample raise "Error: A license must be declared in #{pom_path}" end return true end
checks for valid license group in pom.xml
checks for valid license group in pom . xml
# check for studio property # will return only the first license encountered # <license> #     <name>BSD 3-Clause License</name> #     <url>https://raw.githubusercontent.com/TIBCOSoftware/tibco-streaming-community/master/docs/Components-LICENSE</url> #     <distribution>repo</distribution> # </license> # studio samples MUST include the right license in the pom
pom_path