extract_party_license.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/env ruby
  2. # Licensed to Elasticsearch under one or more contributor
  3. # license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright
  5. # ownership. Elasticsearch licenses this file to you under
  6. # the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on
  14. # an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  15. # either express or implied. See the License for the specific
  16. # language governing permissions and limitations under the License
  17. #
  18. # The script extract license information out of logstash project
  19. # First it will use license information out of gem object.
  20. # If that is not available, it will try to print out the license file
  21. #
  22. require 'rubygems'
  23. require 'bundler/setup'
  24. require 'yaml'
  25. # get all local installed gems
  26. def all_installed_gems
  27. Gem::Specification.all = nil
  28. all = Gem::Specification
  29. Gem::Specification.reset
  30. all
  31. end
  32. all_installed_gems.select {|y| y.gem_dir.include?('vendor') }.sort {|v, u| v.name <=> u.name }.each do |x|
  33. puts '='*80 #seperator
  34. if(x.license) #ah gem has license information
  35. puts "%s,%s,%s,%s,%s"%[x.name, x.version, x.license, x.homepage, x.email]
  36. else
  37. puts "%s,%s,%s,%s"%[x.name, x.version, x.homepage, x.email]
  38. license_file = Dir.glob(File.join(x.gem_dir,'LICENSE*')).first #see if there is a license file
  39. if(license_file)
  40. file = File.open(license_file, 'r')
  41. data = file.read
  42. file.close
  43. puts data
  44. else
  45. #no license file.. try to print some gem information
  46. puts 'No License File'
  47. puts x.gem_dir
  48. puts x.files.join("\n")
  49. end
  50. end
  51. end