license_auto 0.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +47 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +17 -0
  5. data/Gemfile +27 -0
  6. data/Gemfile.lock +103 -0
  7. data/LICENSE +23 -0
  8. data/README.md +136 -0
  9. data/Rakefile +20 -0
  10. data/examples/get_license_files_of_bundler.rb +12 -0
  11. data/lib/api.rb +60 -0
  12. data/lib/api/bitbucket.rb +142 -0
  13. data/lib/api/code_google_com.rb +66 -0
  14. data/lib/api/excel_export.rb +189 -0
  15. data/lib/api/gem_data.rb +30 -0
  16. data/lib/api/git_kernel_org.rb +59 -0
  17. data/lib/api/github.rb +376 -0
  18. data/lib/api/go_pkg_in.rb +41 -0
  19. data/lib/api/golang_org.rb +63 -0
  20. data/lib/api/google_source_com.rb +68 -0
  21. data/lib/api/gradle2.rb +41 -0
  22. data/lib/api/helper.rb +26 -0
  23. data/lib/api/j_center.rb +23 -0
  24. data/lib/api/maven_central_repository.rb +192 -0
  25. data/lib/api/mq.rb +30 -0
  26. data/lib/api/npm_registry.rb +169 -0
  27. data/lib/api/pattern.rb +33 -0
  28. data/lib/api/remote_source_package.rb +319 -0
  29. data/lib/api/spider.rb +47 -0
  30. data/lib/cloner.rb +154 -0
  31. data/lib/db.rb +267 -0
  32. data/lib/license_auto.rb +20 -0
  33. data/lib/license_auto/config/config.rb +52 -0
  34. data/lib/license_auto/errors.rb +0 -0
  35. data/lib/license_auto/license/frequency.rb +30 -0
  36. data/lib/license_auto/license/similarity.rb +247 -0
  37. data/lib/license_auto/license/templates/AFL2.0.txt +43 -0
  38. data/lib/license_auto/license/templates/AFL2.1.txt +47 -0
  39. data/lib/license_auto/license/templates/AFL3.0.txt +45 -0
  40. data/lib/license_auto/license/templates/AGPL3.0.txt +236 -0
  41. data/lib/license_auto/license/templates/APSL 2.0.txt +100 -0
  42. data/lib/license_auto/license/templates/Apache1.0.txt +18 -0
  43. data/lib/license_auto/license/templates/Apache1.1.txt +18 -0
  44. data/lib/license_auto/license/templates/Apache2.0.txt +201 -0
  45. data/lib/license_auto/license/templates/Artistic1.0.txt +45 -0
  46. data/lib/license_auto/license/templates/Artistic2.0.txt +70 -0
  47. data/lib/license_auto/license/templates/BSD.txt +29 -0
  48. data/lib/license_auto/license/templates/CDDL1.0.txt +1 -0
  49. data/lib/license_auto/license/templates/CDDL1.1.txt +209 -0
  50. data/lib/license_auto/license/templates/CPL1.0.txt +211 -0
  51. data/lib/license_auto/license/templates/CPOL 1.02.txt +41 -0
  52. data/lib/license_auto/license/templates/ClarifiedArtistic.txt +140 -0
  53. data/lib/license_auto/license/templates/Creative Commons1.0.txt +28 -0
  54. data/lib/license_auto/license/templates/EPL1.0.txt +70 -0
  55. data/lib/license_auto/license/templates/ERLANG1.1.txt +286 -0
  56. data/lib/license_auto/license/templates/GFDL1.1.txt +101 -0
  57. data/lib/license_auto/license/templates/GFDL1.2.txt +108 -0
  58. data/lib/license_auto/license/templates/GFDL1.3.txt +116 -0
  59. data/lib/license_auto/license/templates/GPL1.0.txt +105 -0
  60. data/lib/license_auto/license/templates/GPL2.0.txt +340 -0
  61. data/lib/license_auto/license/templates/GPL3.0.txt +220 -0
  62. data/lib/license_auto/license/templates/H2.txt +118 -0
  63. data/lib/license_auto/license/templates/IBMPublic1.0.txt +58 -0
  64. data/lib/license_auto/license/templates/LGPL2.0.txt +481 -0
  65. data/lib/license_auto/license/templates/LGPL2.1.txt +166 -0
  66. data/lib/license_auto/license/templates/LGPL3.0.txt +56 -0
  67. data/lib/license_auto/license/templates/Lucent Public License 1.02.txt +244 -0
  68. data/lib/license_auto/license/templates/MIT.txt +21 -0
  69. data/lib/license_auto/license/templates/MIT2.0.txt +11 -0
  70. data/lib/license_auto/license/templates/MPL 2.0.txt +373 -0
  71. data/lib/license_auto/license/templates/MPL1.1.txt +470 -0
  72. data/lib/license_auto/license/templates/MS-LPL.txt +22 -0
  73. data/lib/license_auto/license/templates/MS-PL.txt +20 -0
  74. data/lib/license_auto/license/templates/MS-RL.txt +19 -0
  75. data/lib/license_auto/license/templates/NPL1.0.txt +138 -0
  76. data/lib/license_auto/license/templates/OpenSSL.txt +127 -0
  77. data/lib/license_auto/license/templates/Oracle license.txt +69 -0
  78. data/lib/license_auto/license/templates/PublicDomain.txt +7 -0
  79. data/lib/license_auto/license/templates/Python.txt +15 -0
  80. data/lib/license_auto/license/templates/QPL1.0.txt +45 -0
  81. data/lib/license_auto/license/templates/RubyClause-6.txt +56 -0
  82. data/lib/license_auto/license/templates/SQLite Copyright.txt +33 -0
  83. data/lib/license_auto/license/templates/Sleepycat.txt +133 -0
  84. data/lib/license_auto/license/templates/SunPublic1.0.txt +183 -0
  85. data/lib/license_auto/license/templates/WTFPL license.txt +13 -0
  86. data/lib/license_auto/license_info.rb +12 -0
  87. data/lib/license_auto/matcher.rb +100 -0
  88. data/lib/license_auto/package.rb +73 -0
  89. data/lib/license_auto/parser/gemfile.rb +0 -0
  90. data/lib/license_auto/parser/golang.rb +0 -0
  91. data/lib/license_auto/parser/gradle.rb +0 -0
  92. data/lib/license_auto/version.rb +20 -0
  93. data/lib/license_auto/website.rb +11 -0
  94. data/lib/license_auto/website/github.rb +49 -0
  95. data/lib/license_auto/website/ruby_gems_org.rb +79 -0
  96. data/lib/license_auto/website/ruby_gems_org_db.rb +52 -0
  97. data/lib/license_auto/website/rubydoc_info.rb +12 -0
  98. data/lib/message.rb +5 -0
  99. data/lib/misc.rb +131 -0
  100. data/lib/parser/enums.rb +161 -0
  101. data/lib/parser/gemfile_parser.rb +221 -0
  102. data/lib/parser/golang_parser.rb +104 -0
  103. data/lib/parser/gradle_parser.rb +141 -0
  104. data/lib/parser/manifest_parser.rb +66 -0
  105. data/lib/parser/maven_parser.rb +91 -0
  106. data/lib/parser/npm_parser.rb +82 -0
  107. data/lib/parser/pip_parser.rb +1 -0
  108. data/lib/parser/rebar_parser.rb +61 -0
  109. data/lib/recorder.rb +184 -0
  110. data/lib/script/apt-get.deps.sh +37 -0
  111. data/lib/script/debian_dpkg_list.sh +2 -0
  112. data/lib/script/rubygems.org.importdb.sh +22 -0
  113. data/license_auto.gemspec +44 -0
  114. data/remove/license_auto +4 -0
  115. data/remove/mq_pack.rb +219 -0
  116. data/remove/mq_repo.rb +106 -0
  117. metadata +249 -0
@@ -0,0 +1,73 @@
1
+ require 'hashie/mash'
2
+
3
+ require 'license_auto/website/ruby_gems_org'
4
+
5
+ module LicenseAuto
6
+
7
+ ##
8
+ # Package: {
9
+ # language: 'Ruby', # Ruby|Golang|Java|NodeJS|Erlang|Python|
10
+ # name: 'bundler',
11
+ # group: 'com.google.http-client', # Optional: Assign nil if your package is not a Java
12
+ # version: '1.11.2', # Optional: Assign nil if check the latest
13
+ # project_server: 'rubygems.org' # Optional: github.com|rubygems.org|pypi.python.org/pypi|registry.npmjs.org
14
+ # }
15
+
16
+ class Package < Hashie::Mash
17
+ extend LicenseAuto
18
+
19
+ ##
20
+ # Default project website server of all kinds of languages.
21
+ #
22
+ # Key: language name
23
+ #
24
+ # Value: default project server
25
+
26
+ LANGUAGES_PROJECT_SERVER = {
27
+ Ruby: RubyGemsOrg
28
+ }
29
+
30
+ def initialize(hash)
31
+ super(hash)
32
+ @server = nil
33
+ end
34
+
35
+ ##
36
+ # Class Entry
37
+
38
+ def get_license_info(**args)
39
+
40
+ # args = {
41
+ # fetch_license_text: true
42
+ # }.merge(args)
43
+
44
+ @server.get_license_info if chose_project_server
45
+
46
+ # TODO: uncomment these line, add Google or Yahoo!
47
+ # if @server.nil?
48
+ # @server.get_license_info if chose_search_engine
49
+ # end
50
+
51
+ end
52
+
53
+ private
54
+
55
+ def chose_project_server()
56
+ begin
57
+ @server = LANGUAGES_PROJECT_SERVER.fetch(self.language.to_sym).new(self)
58
+ rescue KeyError => e
59
+ return nil
60
+ end
61
+ end
62
+
63
+ def chose_search_engine()
64
+ # TODO: Website::Google
65
+ # logger.info("#{self.language} has no adapter. I will google it...")
66
+ # @search_engine = LicenseAuto::SearchEngine::Google
67
+ # TODO: Website::Github
68
+ end
69
+
70
+ end
71
+
72
+
73
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,20 @@
1
+ module LicenseAuto
2
+ # Returns the version of the currently loaded Rails as a <tt>Gem::Version</tt>
3
+ def self.gem_version
4
+ Gem::Version.new VERSION::STRING
5
+ end
6
+
7
+ module VERSION
8
+ MAJOR = 0
9
+ MINOR = 1
10
+ TINY = 1
11
+ PRE = '1'
12
+
13
+ STRING =
14
+ if PRE.empty?
15
+ [MAJOR, MINOR, TINY].compact.join(".")
16
+ else
17
+ [MAJOR, MINOR, TINY, PRE].compact.join(".")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ class Website
2
+
3
+ def initialize(package)
4
+ @package = package
5
+ end
6
+
7
+ def to_s
8
+ @package
9
+ end
10
+
11
+ end
@@ -0,0 +1,49 @@
1
+ require 'github_api'
2
+
3
+ module LicenseAuto
4
+
5
+ ##
6
+ #
7
+ # @owner: string
8
+ # @repo: string
9
+ # @pack_version: string
10
+ #
11
+ # @return LicenseInfo
12
+ GIT_HASH_LENGTH = 40
13
+
14
+ def self.github_get_license_info(owner, repo, package_version=nil)
15
+ github = Github.new(user: owner, repo: repo)
16
+
17
+ possible_ref = nil
18
+ # If provided a Git SHA, use it directly
19
+ if package_version.size >= GIT_HASH_LENGTH
20
+ possible_ref = package_version
21
+ else
22
+ matcher = LicenseAuto::Matcher::FilepathName.new(package_version)
23
+ github.repos.tags do |tag|
24
+ matched = matcher.match_the_ref(tag.name)
25
+ if matched
26
+ possible_ref = tag.name
27
+ break
28
+ end
29
+ end
30
+ end
31
+
32
+ # If possible_ref is nil, the Github API server will return the default branch contents
33
+ contents = github.repos.contents.get(path: '/', ref: possible_ref)
34
+
35
+ license_files = []
36
+ readme_files = []
37
+ notice_files = []
38
+ contents.each {|obj|
39
+ if obj.type == 'file'
40
+ filename_matcher = LicenseAuto::Matcher::FilepathName.new(obj.name)
41
+ license_files.push(obj) if filename_matcher.match_license_file
42
+ readme_files.push(obj) if filename_matcher.match_readme_file
43
+ notice_files.push(obj) if filename_matcher.match_notice_file
44
+ end
45
+ }
46
+
47
+ LicenseAuto::LicenseInfo.new(licenses: license_files, readmes: readme_files, notices: notice_files)
48
+ end
49
+ end
@@ -0,0 +1,79 @@
1
+ require 'gems'
2
+ require 'hashie'
3
+
4
+ require 'license_auto/website/github'
5
+
6
+
7
+ class RubyGemsOrg < Website
8
+
9
+
10
+ GEM_NOT_FOUND = "This rubygem could not be found."
11
+
12
+ def initialize(package)
13
+ super(package)
14
+ end
15
+
16
+ # (Defaults to the latest version if no version is specified.)
17
+
18
+ def get_license_info()
19
+ if @package.version.nil?
20
+ begin
21
+ @package.version = get_latest_version['number']
22
+ rescue Exception => e
23
+ # TODO: what returned value is better?
24
+ return nil
25
+ end
26
+ end
27
+
28
+ gem_info = get_gem_info
29
+ gem_info = Hashie::Mash.new(gem_info)
30
+
31
+ source_code_matcher = LicenseAuto::Matcher::SourceURL.new(gem_info.source_code_uri)
32
+
33
+ github_matched = source_code_matcher.match_github_resource
34
+ if github_matched
35
+ license_info = LicenseAuto::github_get_license_info(github_matched[:owner], github_matched[:repo], @package.version)
36
+ end
37
+
38
+ # bitbucket_matched = source_code_matcher.match_bitbucket_resource()
39
+ # if github_matched
40
+ # # TODO: bitbucket_matched
41
+ # end
42
+ end
43
+
44
+ def get_gem_info()
45
+ # TODO: Gems.info(@package.name, @package.version)
46
+ Gems.info(@package.name)
47
+ end
48
+
49
+ # TODO: switch to https://github.com/rubygems/gems/issues/32#issuecomment-195180422
50
+ # @return {
51
+ # "authors" => "David Heinemeier Hansson",
52
+ # "built_at" => "2016-03-07T00:00:00.000Z",
53
+ # "created_at" => "2016-03-07T22:33:22.563Z",
54
+ # "description" => "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.",
55
+ # "downloads_count" => 28113,
56
+ # "metadata" => {},
57
+ # "number" => "4.2.6",
58
+ # "summary" => "Full-stack web application framework.",
59
+ # "platform" => "ruby",
60
+ # "ruby_version" => ">= 1.9.3",
61
+ # "prerelease" => false,
62
+ # "licenses" => [
63
+ # [0] "MIT"
64
+ # ],
65
+ # "requirements" => [],
66
+ # "sha" => "a199258c0d2bae09993a6932c49df254fd66428899d1823b8c5285de02e5bc33"
67
+ # }
68
+ def get_latest_version()
69
+ versions = Gems.versions(@package.name).reject { |v| v['prerelease'] }.first
70
+ if versions == GEM_NOT_FOUND
71
+ raise(GEM_NOT_FOUND)
72
+ end
73
+
74
+ versions.reject { |v| v['prerelease'] }.first
75
+ end
76
+
77
+ def download_gem()
78
+ end
79
+ end
@@ -0,0 +1,52 @@
1
+ ##
2
+ # This file can get PostgreSQL DB dumped data of https://rubygems.org
3
+ # But it's easier to get JSON data from the website API than from the local created database.
4
+
5
+ require './lib/misc'
6
+
7
+
8
+ class RubyGemsOrgDB
9
+ def initialize
10
+ @download_prefix = 'https://s3-us-west-2.amazonaws.com/rubygems-dumps/'
11
+
12
+ @http_option = {}
13
+ # TODO: LicenseAuto::Base.config({http_proxy})
14
+ http_proxy = Misc.get_http_proxy
15
+ if http_proxy
16
+ @http_option[:http_proxyaddr] = http_proxy[:addr]
17
+ @http_option[:http_proxyport] = http_proxy[:port]
18
+ end
19
+ end
20
+
21
+ def find_archive_download_url()
22
+ api_url = 'https://s3-us-west-2.amazonaws.com/rubygems-dumps/?prefix=production/public_postgresql'
23
+ download_url = nil
24
+
25
+ response = HTTParty.get(api_url, options=@http_option)
26
+ if response.code == 200
27
+ # DOC: http://www.nokogiri.org/tutorials/searching_a_xml_html_document.html#but_i_m_lazy_and_don_t_want_to_deal_with_namespaces_
28
+ doc = Nokogiri::XML(response.licenses).remove_namespaces!
29
+
30
+ xpath = "//Contents[last()]/Key/text()"
31
+ xpath = "//Contents[last()]/Key/text()"
32
+ text_node = doc.xpath(xpath)
33
+ relative_url = text_node.text
34
+
35
+ download_url = "#{@download_prefix}#{relative_url}"
36
+ else
37
+ raise Exception("http_status: #{response.status}")
38
+ end
39
+ download_url
40
+ end
41
+
42
+ # TODO: download function move into misc.rb or others, like launchpad.rb has the same function
43
+ def download(url)
44
+ file_pathname = nil
45
+ return file_pathname
46
+ end
47
+
48
+ end
49
+
50
+ if __FILE__ == $0
51
+ p RubygemsOrgDB.new.find_archive_download_url
52
+ end
@@ -0,0 +1,12 @@
1
+ ##
2
+ # http://www.rubydoc.info/
3
+ # * If https://rubygems.org/gems/foo don't provide a source_code link, and you don't want download a gem by link as
4
+ # https://rubygems.org/downloads/foo-0.0.2.gem and scan its source code, then you can get [YARD](http://yardoc.org)
5
+ # Ruby documents by this website service.
6
+ #
7
+ # * For safe, download gem package and scan file `license*` is the best way.
8
+
9
+ class RubyDocInfo
10
+ # TODO: get Ajax request
11
+
12
+ end
data/lib/message.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Message
2
+ def self.send(message)
3
+ # TODO: http api post to website
4
+ end
5
+ end
data/lib/misc.rb ADDED
@@ -0,0 +1,131 @@
1
+ require 'find'
2
+ require 'json'
3
+ require 'httparty'
4
+
5
+ require 'license_auto/config/config'
6
+
7
+ module Misc
8
+
9
+ def Misc.check_private_repo(where)
10
+ pg_result = $conn.exec("select * from repo #{where}")
11
+
12
+ pg_result.each {|r|
13
+ source_url = r['source_url']
14
+ $plog.debug("source_url: #{source_url}")
15
+ response = HTTParty.get(source_url)
16
+
17
+ priv = -1
18
+ if response.code == 404
19
+ require_relative './api'
20
+ g = API::Github.new(source_url)
21
+ commits = g.list_commits
22
+ if commits != nil
23
+ priv = 0
24
+ end
25
+ elsif response.code == 200
26
+ priv = 1
27
+ end
28
+ $plog.debug("priv: #{priv}")
29
+
30
+ update = $conn.exec_params("update repo set priv = $1 where source_url = $2", [priv, source_url])
31
+ }
32
+ end
33
+
34
+ # TODO:
35
+ def Misc.check_git_submodules(where)
36
+ require_relative './api'
37
+ # third_party = []
38
+ # pg_result = $conn.exec("select * from repo #{where}")
39
+ #
40
+ # pg_result.each {|r|
41
+ source_url = 'https://github.com/cloudfoundry-incubator/rep'
42
+ $plog.debug("source_url: #{source_url}")
43
+
44
+ g = API::Github.new(source_url)
45
+
46
+ modules = g.get_gitmodules
47
+ if modules
48
+ # third_party.push(modules)
49
+ $plog.debug("modules: #{mmodules}")
50
+ end
51
+ # update = $conn.exec_params("update repo set priv = $1 where source_url = $2", [priv, source_url])
52
+ # }
53
+ end
54
+
55
+ def Misc.enqueue_packs(where)
56
+ pg_result = $conn.exec("select * from pack #{where}")
57
+ queue_name = 'license_auto.pack'
58
+ $plog.debug("enqueue packs no: #{pg_result.ntuples}")
59
+ pg_result.each {|p|
60
+ pack_id = p['id'].to_i
61
+ $rmq.publish(queue_name, {:pack_id => pack_id}.to_json, check_exist=true)
62
+ }
63
+ end
64
+
65
+ def Misc.enqueue_repos(where, release_id)
66
+ pg_result = $conn.exec("select * from repo #{where}")
67
+ queue_name = 'license_auto.repo'
68
+ $plog.debug("enqueue repos no: #{pg_result.ntuples}")
69
+ pg_result.each {|repo|
70
+ repo_id = repo['id'].to_i
71
+ message = {
72
+ :repo_id => repo_id,
73
+ :release_id => release_id
74
+ }
75
+ $rmq.publish(queue_name, message.to_json, check_exist=true)
76
+ }
77
+ end
78
+
79
+ def Misc.get_http_proxy
80
+ http_proxy = ENV['license_auto_proxy']
81
+ if http_proxy
82
+ http_proxy = http_proxy.split(':')
83
+ return {
84
+ :addr => http_proxy[0],
85
+ :port => http_proxy[1]
86
+ }
87
+ else
88
+ return nil
89
+ end
90
+ end
91
+
92
+ class DirUtils
93
+ attr_reader :path, :filenames
94
+ def initialize(path)
95
+ @path = path
96
+ @filenames = []
97
+
98
+ if File.exists?(path) and File.directory?(path)
99
+ Find.find(path) do |filename|
100
+ if File.file?(filename)
101
+ @filenames.push(filename)
102
+ end
103
+ end
104
+ else
105
+ raise "Parameter Error: #{path}"
106
+ end
107
+ end
108
+
109
+ def filter_filename(filename_pattern)
110
+ result = []
111
+ @filenames.each {|f|
112
+ if f =~ filename_pattern
113
+ result.push(f)
114
+ end
115
+ }
116
+ result
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ if __FILE__ == $0
123
+ # where = ' where 1=1 '
124
+ # Misc.check_private_repo(where)
125
+
126
+ where = ' where status < 30 '
127
+ Misc.enqueue_packs(where)
128
+ # Misc.check_private_repo(where)
129
+ # third_party = Misc.check_git_submodules(where)
130
+
131
+ end