license_auto 0.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +103 -0
- data/LICENSE +23 -0
- data/README.md +136 -0
- data/Rakefile +20 -0
- data/examples/get_license_files_of_bundler.rb +12 -0
- data/lib/api.rb +60 -0
- data/lib/api/bitbucket.rb +142 -0
- data/lib/api/code_google_com.rb +66 -0
- data/lib/api/excel_export.rb +189 -0
- data/lib/api/gem_data.rb +30 -0
- data/lib/api/git_kernel_org.rb +59 -0
- data/lib/api/github.rb +376 -0
- data/lib/api/go_pkg_in.rb +41 -0
- data/lib/api/golang_org.rb +63 -0
- data/lib/api/google_source_com.rb +68 -0
- data/lib/api/gradle2.rb +41 -0
- data/lib/api/helper.rb +26 -0
- data/lib/api/j_center.rb +23 -0
- data/lib/api/maven_central_repository.rb +192 -0
- data/lib/api/mq.rb +30 -0
- data/lib/api/npm_registry.rb +169 -0
- data/lib/api/pattern.rb +33 -0
- data/lib/api/remote_source_package.rb +319 -0
- data/lib/api/spider.rb +47 -0
- data/lib/cloner.rb +154 -0
- data/lib/db.rb +267 -0
- data/lib/license_auto.rb +20 -0
- data/lib/license_auto/config/config.rb +52 -0
- data/lib/license_auto/errors.rb +0 -0
- data/lib/license_auto/license/frequency.rb +30 -0
- data/lib/license_auto/license/similarity.rb +247 -0
- data/lib/license_auto/license/templates/AFL2.0.txt +43 -0
- data/lib/license_auto/license/templates/AFL2.1.txt +47 -0
- data/lib/license_auto/license/templates/AFL3.0.txt +45 -0
- data/lib/license_auto/license/templates/AGPL3.0.txt +236 -0
- data/lib/license_auto/license/templates/APSL 2.0.txt +100 -0
- data/lib/license_auto/license/templates/Apache1.0.txt +18 -0
- data/lib/license_auto/license/templates/Apache1.1.txt +18 -0
- data/lib/license_auto/license/templates/Apache2.0.txt +201 -0
- data/lib/license_auto/license/templates/Artistic1.0.txt +45 -0
- data/lib/license_auto/license/templates/Artistic2.0.txt +70 -0
- data/lib/license_auto/license/templates/BSD.txt +29 -0
- data/lib/license_auto/license/templates/CDDL1.0.txt +1 -0
- data/lib/license_auto/license/templates/CDDL1.1.txt +209 -0
- data/lib/license_auto/license/templates/CPL1.0.txt +211 -0
- data/lib/license_auto/license/templates/CPOL 1.02.txt +41 -0
- data/lib/license_auto/license/templates/ClarifiedArtistic.txt +140 -0
- data/lib/license_auto/license/templates/Creative Commons1.0.txt +28 -0
- data/lib/license_auto/license/templates/EPL1.0.txt +70 -0
- data/lib/license_auto/license/templates/ERLANG1.1.txt +286 -0
- data/lib/license_auto/license/templates/GFDL1.1.txt +101 -0
- data/lib/license_auto/license/templates/GFDL1.2.txt +108 -0
- data/lib/license_auto/license/templates/GFDL1.3.txt +116 -0
- data/lib/license_auto/license/templates/GPL1.0.txt +105 -0
- data/lib/license_auto/license/templates/GPL2.0.txt +340 -0
- data/lib/license_auto/license/templates/GPL3.0.txt +220 -0
- data/lib/license_auto/license/templates/H2.txt +118 -0
- data/lib/license_auto/license/templates/IBMPublic1.0.txt +58 -0
- data/lib/license_auto/license/templates/LGPL2.0.txt +481 -0
- data/lib/license_auto/license/templates/LGPL2.1.txt +166 -0
- data/lib/license_auto/license/templates/LGPL3.0.txt +56 -0
- data/lib/license_auto/license/templates/Lucent Public License 1.02.txt +244 -0
- data/lib/license_auto/license/templates/MIT.txt +21 -0
- data/lib/license_auto/license/templates/MIT2.0.txt +11 -0
- data/lib/license_auto/license/templates/MPL 2.0.txt +373 -0
- data/lib/license_auto/license/templates/MPL1.1.txt +470 -0
- data/lib/license_auto/license/templates/MS-LPL.txt +22 -0
- data/lib/license_auto/license/templates/MS-PL.txt +20 -0
- data/lib/license_auto/license/templates/MS-RL.txt +19 -0
- data/lib/license_auto/license/templates/NPL1.0.txt +138 -0
- data/lib/license_auto/license/templates/OpenSSL.txt +127 -0
- data/lib/license_auto/license/templates/Oracle license.txt +69 -0
- data/lib/license_auto/license/templates/PublicDomain.txt +7 -0
- data/lib/license_auto/license/templates/Python.txt +15 -0
- data/lib/license_auto/license/templates/QPL1.0.txt +45 -0
- data/lib/license_auto/license/templates/RubyClause-6.txt +56 -0
- data/lib/license_auto/license/templates/SQLite Copyright.txt +33 -0
- data/lib/license_auto/license/templates/Sleepycat.txt +133 -0
- data/lib/license_auto/license/templates/SunPublic1.0.txt +183 -0
- data/lib/license_auto/license/templates/WTFPL license.txt +13 -0
- data/lib/license_auto/license_info.rb +12 -0
- data/lib/license_auto/matcher.rb +100 -0
- data/lib/license_auto/package.rb +73 -0
- data/lib/license_auto/parser/gemfile.rb +0 -0
- data/lib/license_auto/parser/golang.rb +0 -0
- data/lib/license_auto/parser/gradle.rb +0 -0
- data/lib/license_auto/version.rb +20 -0
- data/lib/license_auto/website.rb +11 -0
- data/lib/license_auto/website/github.rb +49 -0
- data/lib/license_auto/website/ruby_gems_org.rb +79 -0
- data/lib/license_auto/website/ruby_gems_org_db.rb +52 -0
- data/lib/license_auto/website/rubydoc_info.rb +12 -0
- data/lib/message.rb +5 -0
- data/lib/misc.rb +131 -0
- data/lib/parser/enums.rb +161 -0
- data/lib/parser/gemfile_parser.rb +221 -0
- data/lib/parser/golang_parser.rb +104 -0
- data/lib/parser/gradle_parser.rb +141 -0
- data/lib/parser/manifest_parser.rb +66 -0
- data/lib/parser/maven_parser.rb +91 -0
- data/lib/parser/npm_parser.rb +82 -0
- data/lib/parser/pip_parser.rb +1 -0
- data/lib/parser/rebar_parser.rb +61 -0
- data/lib/recorder.rb +184 -0
- data/lib/script/apt-get.deps.sh +37 -0
- data/lib/script/debian_dpkg_list.sh +2 -0
- data/lib/script/rubygems.org.importdb.sh +22 -0
- data/license_auto.gemspec +44 -0
- data/remove/license_auto +4 -0
- data/remove/mq_pack.rb +219 -0
- data/remove/mq_repo.rb +106 -0
- metadata +249 -0
data/lib/parser/enums.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
##
|
2
|
+
# Golang(v1.4.2 darwin/amd64) system libraries
|
3
|
+
|
4
|
+
GOLANG_STD_PACKAGES = [
|
5
|
+
'cmd/addr2line',
|
6
|
+
'cmd/cgo',
|
7
|
+
'cmd/fix',
|
8
|
+
'cmd/go',
|
9
|
+
'cmd/gofmt',
|
10
|
+
'cmd/nm',
|
11
|
+
'cmd/objdump',
|
12
|
+
'cmd/pack',
|
13
|
+
'cmd/pprof',
|
14
|
+
'cmd/yacc',
|
15
|
+
'archive/tar',
|
16
|
+
'archive/zip',
|
17
|
+
'bufio',
|
18
|
+
'bytes',
|
19
|
+
'cmd/internal/goobj',
|
20
|
+
'cmd/internal/objfile',
|
21
|
+
'cmd/pprof/internal/commands',
|
22
|
+
'cmd/pprof/internal/driver',
|
23
|
+
'cmd/pprof/internal/fetch',
|
24
|
+
'cmd/pprof/internal/plugin',
|
25
|
+
'cmd/pprof/internal/profile',
|
26
|
+
'cmd/pprof/internal/report',
|
27
|
+
'cmd/pprof/internal/svg',
|
28
|
+
'cmd/pprof/internal/symbolizer',
|
29
|
+
'cmd/pprof/internal/symbolz',
|
30
|
+
'cmd/pprof/internal/tempfile',
|
31
|
+
'compress/bzip2',
|
32
|
+
'compress/flate',
|
33
|
+
'compress/gzip',
|
34
|
+
'compress/lzw',
|
35
|
+
'compress/zlib',
|
36
|
+
'container/heap',
|
37
|
+
'container/list',
|
38
|
+
'container/ring',
|
39
|
+
'crypto',
|
40
|
+
'crypto/aes',
|
41
|
+
'crypto/cipher',
|
42
|
+
'crypto/des',
|
43
|
+
'crypto/dsa',
|
44
|
+
'crypto/ecdsa',
|
45
|
+
'crypto/elliptic',
|
46
|
+
'crypto/hmac',
|
47
|
+
'crypto/md5',
|
48
|
+
'crypto/rand',
|
49
|
+
'crypto/rc4',
|
50
|
+
'crypto/rsa',
|
51
|
+
'crypto/sha1',
|
52
|
+
'crypto/sha256',
|
53
|
+
'crypto/sha512',
|
54
|
+
'crypto/subtle',
|
55
|
+
'crypto/tls',
|
56
|
+
'crypto/x509',
|
57
|
+
'crypto/x509/pkix',
|
58
|
+
'database/sql',
|
59
|
+
'database/sql/driver',
|
60
|
+
'debug/dwarf',
|
61
|
+
'debug/elf',
|
62
|
+
'debug/gosym',
|
63
|
+
'debug/macho',
|
64
|
+
'debug/pe',
|
65
|
+
'debug/plan9obj',
|
66
|
+
'encoding',
|
67
|
+
'encoding/ascii85',
|
68
|
+
'encoding/asn1',
|
69
|
+
'encoding/base32',
|
70
|
+
'encoding/base64',
|
71
|
+
'encoding/binary',
|
72
|
+
'encoding/csv',
|
73
|
+
'encoding/gob',
|
74
|
+
'encoding/hex',
|
75
|
+
'encoding/json',
|
76
|
+
'encoding/pem',
|
77
|
+
'encoding/xml',
|
78
|
+
'errors',
|
79
|
+
'expvar',
|
80
|
+
'flag',
|
81
|
+
'fmt',
|
82
|
+
'go/ast',
|
83
|
+
'go/build',
|
84
|
+
'go/doc',
|
85
|
+
'go/format',
|
86
|
+
'go/parser',
|
87
|
+
'go/printer',
|
88
|
+
'go/scanner',
|
89
|
+
'go/token',
|
90
|
+
'hash',
|
91
|
+
'hash/adler32',
|
92
|
+
'hash/crc32',
|
93
|
+
'hash/crc64',
|
94
|
+
'hash/fnv',
|
95
|
+
'html',
|
96
|
+
'html/template',
|
97
|
+
'image',
|
98
|
+
'image/color',
|
99
|
+
'image/color/palette',
|
100
|
+
'image/draw',
|
101
|
+
'image/gif',
|
102
|
+
'image/jpeg',
|
103
|
+
'image/png',
|
104
|
+
'index/suffixarray',
|
105
|
+
'io',
|
106
|
+
'io/ioutil',
|
107
|
+
'log',
|
108
|
+
'log/syslog',
|
109
|
+
'math',
|
110
|
+
'math/big',
|
111
|
+
'math/cmplx',
|
112
|
+
'math/rand',
|
113
|
+
'mime',
|
114
|
+
'mime/multipart',
|
115
|
+
'net',
|
116
|
+
'net/http',
|
117
|
+
'net/http/cgi',
|
118
|
+
'net/http/cookiejar',
|
119
|
+
'net/http/fcgi',
|
120
|
+
'net/http/httptest',
|
121
|
+
'net/http/httputil',
|
122
|
+
'net/http/internal',
|
123
|
+
'net/http/pprof',
|
124
|
+
'net/mail',
|
125
|
+
'net/rpc',
|
126
|
+
'net/rpc/jsonrpc',
|
127
|
+
'net/smtp',
|
128
|
+
'net/textproto',
|
129
|
+
'net/url',
|
130
|
+
'os',
|
131
|
+
'os/exec',
|
132
|
+
'os/signal',
|
133
|
+
'os/user',
|
134
|
+
'path',
|
135
|
+
'path/filepath',
|
136
|
+
'reflect',
|
137
|
+
'regexp',
|
138
|
+
'regexp/syntax',
|
139
|
+
'runtime',
|
140
|
+
'runtime/cgo',
|
141
|
+
'runtime/debug',
|
142
|
+
'runtime/pprof',
|
143
|
+
'runtime/race',
|
144
|
+
'sort',
|
145
|
+
'strconv',
|
146
|
+
'strings',
|
147
|
+
'sync',
|
148
|
+
'sync/atomic',
|
149
|
+
'syscall',
|
150
|
+
'testing',
|
151
|
+
'testing/iotest',
|
152
|
+
'testing/quick',
|
153
|
+
'text/scanner',
|
154
|
+
'text/tabwriter',
|
155
|
+
'text/template',
|
156
|
+
'text/template/parse',
|
157
|
+
'time',
|
158
|
+
'unicode',
|
159
|
+
'unicode/utf16',
|
160
|
+
'unicode/utf8',
|
161
|
+
'unsafe']
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require 'thread/pool'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
require_relative './Obtain_path'
|
5
|
+
require_relative './Ruby_extractor'
|
6
|
+
require_relative './utils'
|
7
|
+
require_relative '../config/config'
|
8
|
+
require_relative '../lib/api/pattern'
|
9
|
+
#require 'License_recognition'
|
10
|
+
|
11
|
+
include Ruby_extractor
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
module ExtractRuby
|
16
|
+
class Ex
|
17
|
+
include Ruby_extractor,Utils
|
18
|
+
end
|
19
|
+
|
20
|
+
class RubyExtractotr < Ex
|
21
|
+
|
22
|
+
# attr_reader :two_dependencies
|
23
|
+
attr_reader :package_list
|
24
|
+
|
25
|
+
def initialize(repo_path)
|
26
|
+
@repo_path = repo_path
|
27
|
+
|
28
|
+
@package_list = [] # [name, version, status] package list , not exist "\n"
|
29
|
+
@rubygems_not_found = 30 # rubygemsDB not found
|
30
|
+
@status_init = 10
|
31
|
+
# gem server or git uri
|
32
|
+
@status_private_source = 33
|
33
|
+
end
|
34
|
+
|
35
|
+
# https://gist.github.com/flavio/1722530
|
36
|
+
# DOC: https://github.com/bundler/bundler/blob/master/lib/bundler/lockfile_parser.rb
|
37
|
+
# description : use bundler extract ruby package from gemfile.lcok
|
38
|
+
# repo_path : local repo path , type : String
|
39
|
+
# st_true : Correct extraction 10
|
40
|
+
# s.source.options['tag'], ['revision']
|
41
|
+
def get_first_level_specs()
|
42
|
+
all_specs = []
|
43
|
+
lockfiles = Obtain_path.new(@repo_path, "gem", ".lock").get_data
|
44
|
+
if lockfiles.size == 0
|
45
|
+
$plog.info('Gemfile.lock files not found, Ruby packages not found')
|
46
|
+
return all_specs
|
47
|
+
end
|
48
|
+
|
49
|
+
lockfiles.each do |pathname|
|
50
|
+
$plog.debug("Gemfile.lock file pathname: #{pathname}")
|
51
|
+
lockfile_parser = Bundler::LockfileParser.new(Bundler.read_file(pathname))
|
52
|
+
lockfile_parser.specs.each do |s|
|
53
|
+
all_specs.push(s)
|
54
|
+
# The 2nd level dependencies
|
55
|
+
# s.dependencies.each{|rows|
|
56
|
+
# rows.requirement.requirements.each{|row|
|
57
|
+
# tmp.concat [[row[0], row[1].version]]
|
58
|
+
# }
|
59
|
+
# }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
all_specs
|
63
|
+
end
|
64
|
+
|
65
|
+
def start
|
66
|
+
all_packs = []
|
67
|
+
require_relative '../lib/api/gem_data'
|
68
|
+
require_relative '../lib/api'
|
69
|
+
local_gemdb = API::GemData.new
|
70
|
+
rubygems_org = 'https://rubygems.org'
|
71
|
+
rubygems_org_domain = 'rubygems.org'
|
72
|
+
|
73
|
+
first_level_specs = get_first_level_specs
|
74
|
+
first_level_specs.each {|s|
|
75
|
+
# $plog.debug("git_uri: #{s.source.options['uri']}, remotes: #{s.source.options['remotes']}")
|
76
|
+
# gem_server_remotes.join(',').gsub(/http[s]?:\/\//, '')
|
77
|
+
pack = nil
|
78
|
+
pack_name = s.name
|
79
|
+
pack_version = s.version.to_s
|
80
|
+
|
81
|
+
if s.source.class == Bundler::Source::Git
|
82
|
+
source_url = s.source.options['uri']
|
83
|
+
_status = @status_init
|
84
|
+
_lang = source_url
|
85
|
+
_cmt = nil
|
86
|
+
|
87
|
+
if source_url =~ API::SOURCE_URL_PATTERN[:github]
|
88
|
+
g = API::Github.new(source_url)
|
89
|
+
source_url = g.repo_url
|
90
|
+
_lang = 'https://github.com'
|
91
|
+
if g.list_contents('').size == 0
|
92
|
+
_status = @status_private_source
|
93
|
+
_cmt = 'Private git uri, source code not found'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
pack = {
|
97
|
+
pack_name: pack_name,
|
98
|
+
pack_version: pack_version,
|
99
|
+
homepage: nil,
|
100
|
+
source_url: source_url,
|
101
|
+
license: nil,
|
102
|
+
status: _status,
|
103
|
+
language: _lang,
|
104
|
+
# This cmt require local rubygems.org database always up-to-date
|
105
|
+
cmt: _cmt
|
106
|
+
}
|
107
|
+
elsif s.source.class == Bundler::Source::Rubygems
|
108
|
+
gem_server_remotes = s.source.options['remotes']
|
109
|
+
|
110
|
+
formatted_remotes = gem_server_remotes.collect {|r|
|
111
|
+
r.gsub(/\/$/, '').gsub(/http:\/\/rubygems\.org/, rubygems_org)
|
112
|
+
}
|
113
|
+
# TODO: get Gemfile source section
|
114
|
+
db_pack = local_gemdb.get_gem(pack_name, pack_version)
|
115
|
+
if formatted_remotes.index(rubygems_org) and db_pack
|
116
|
+
pack = db_pack.merge({
|
117
|
+
:status => 10,
|
118
|
+
:language => rubygems_org_domain,
|
119
|
+
:cmt => nil
|
120
|
+
})
|
121
|
+
else
|
122
|
+
formatted_remotes.delete(rubygems_org)
|
123
|
+
pack = {
|
124
|
+
pack_name: pack_name,
|
125
|
+
pack_version: pack_version,
|
126
|
+
homepage: nil,
|
127
|
+
source_url: nil,
|
128
|
+
license: 'UNKNOWN',
|
129
|
+
status: @status_private_source,
|
130
|
+
language: formatted_remotes.join(''),
|
131
|
+
# This cmt require local rubygems.org database always up-to-date
|
132
|
+
cmt: 'Private gem server or source code not found'
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
all_packs.push(pack)
|
137
|
+
}
|
138
|
+
all_packs
|
139
|
+
end
|
140
|
+
|
141
|
+
def select_rubygems_db
|
142
|
+
# FIXME: db connection
|
143
|
+
require_relative '../lib/api/gem_data'
|
144
|
+
rubygems_result = []
|
145
|
+
ruby_gems = API::GemData.new
|
146
|
+
@package_list.each do |row|
|
147
|
+
pack_hash = {
|
148
|
+
:pack_name => nil,
|
149
|
+
:pack_version => nil,
|
150
|
+
:homepage => nil,
|
151
|
+
:source_url => nil,
|
152
|
+
:license => nil,
|
153
|
+
:status => 10,
|
154
|
+
:cmt => nil,
|
155
|
+
:language => nil
|
156
|
+
}
|
157
|
+
if row['uri'] != nil
|
158
|
+
pack_hash[:language] = row['uri']
|
159
|
+
pack_hash[:pack_name] = row['name']
|
160
|
+
pack_hash[:pack_version] = row['version']
|
161
|
+
pack_hash[:source_url] = row['uri']
|
162
|
+
rubygems_result << pack_hash
|
163
|
+
next
|
164
|
+
elsif row['remotes'] != nil
|
165
|
+
pack_hash[:language] = row['remotes']
|
166
|
+
end
|
167
|
+
if 10 == row['st']
|
168
|
+
result = ruby_gems.get_gemdata(row['name'],row['version'])
|
169
|
+
if result != nil
|
170
|
+
pack_hash[:pack_name] = result[:name]
|
171
|
+
pack_hash[:pack_version] = result[:version]
|
172
|
+
pack_hash[:homepage] = result[:homepage]
|
173
|
+
pack_hash[:source_url] = result[:source_url]
|
174
|
+
pack_hash[:license] = result[:license]
|
175
|
+
pack_hash[:status] = row['st']
|
176
|
+
elsif nil == result
|
177
|
+
pack_hash[:pack_name] = row['name']
|
178
|
+
if "" == row['version']
|
179
|
+
pack_hash[:pack_version] = nil
|
180
|
+
else
|
181
|
+
pack_hash[:pack_version] = row['version']
|
182
|
+
end
|
183
|
+
pack_hash[:status] = @rubygems_not_found
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
rubygems_result << pack_hash
|
188
|
+
end
|
189
|
+
|
190
|
+
return rubygems_result
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
if __FILE__ == $0
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'open3'
|
6
|
+
require 'set'
|
7
|
+
require_relative '../../lib/cloner'
|
8
|
+
require_relative '../../enums'
|
9
|
+
require_relative '../../config/config'
|
10
|
+
require_relative '../recorder'
|
11
|
+
|
12
|
+
|
13
|
+
class GolangParser
|
14
|
+
|
15
|
+
def self.start(repo_filepath)
|
16
|
+
pack__name_uris = {}
|
17
|
+
|
18
|
+
pack_names = self.find_pack_names(repo_filepath)
|
19
|
+
pack_names.each {|pack_name|
|
20
|
+
pack_uri = ''
|
21
|
+
begin
|
22
|
+
pack_uri = self.golang_extpack_to_repo_uri(pack_name)
|
23
|
+
rescue Exception => e
|
24
|
+
# todo: save bad golang package into DB
|
25
|
+
pack_uri = e
|
26
|
+
end
|
27
|
+
name = pack_uri.gsub(/http(s)?:\/\//,'')
|
28
|
+
if pack_uri != nil
|
29
|
+
pack__name_uris.store(name, pack_uri)
|
30
|
+
end
|
31
|
+
}
|
32
|
+
$plog.debug("GolangParser: pack__name_uris: #{pack__name_uris}")
|
33
|
+
return pack__name_uris
|
34
|
+
end
|
35
|
+
|
36
|
+
# return: pack_names {Set} eg. { 'github.com/some_golang_author/hist_package', ... }
|
37
|
+
def self.find_pack_names(repo_filepath)
|
38
|
+
pack_names = Set.new
|
39
|
+
|
40
|
+
$plog.debug("repo_filepath: #{repo_filepath}")
|
41
|
+
|
42
|
+
Dir.chdir(repo_filepath) do
|
43
|
+
cmd = 'go list -json ./...'
|
44
|
+
Open3.popen3(cmd) {|i,o,e,t|
|
45
|
+
out = o.readlines
|
46
|
+
error = e.readlines
|
47
|
+
if error.length > 0 and error[0] != "warning: \"./...\" matched no packages\n"
|
48
|
+
raise "cmd error: #{error}"
|
49
|
+
elsif out.length > 0
|
50
|
+
out2 = out.join('').gsub(/}\n{/, "}\n\n{").split(/\n\n/)
|
51
|
+
out2.each {|s|
|
52
|
+
j = JSON::parse(s)
|
53
|
+
# $plog.info("json: #{j}")
|
54
|
+
imports = []
|
55
|
+
section_keys = ['Deps', 'Imports', 'TestImports', 'XTestImports']
|
56
|
+
section_keys.each {|s|
|
57
|
+
if j[s]
|
58
|
+
imports += j[s]
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
if imports.size == 0
|
63
|
+
next
|
64
|
+
else
|
65
|
+
imports.each {|d|
|
66
|
+
unless GOLANG_STD_PACKAGES.include?(d)
|
67
|
+
unless d.index('.').nil?
|
68
|
+
pack_names.add(d)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
}
|
72
|
+
end
|
73
|
+
}
|
74
|
+
else
|
75
|
+
$plog.error "!!!Opps'"
|
76
|
+
end
|
77
|
+
exit_status = t.value
|
78
|
+
pack_names
|
79
|
+
p pack_names
|
80
|
+
}
|
81
|
+
end
|
82
|
+
return pack_names
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.golang_extpack_to_repo_uri(extpack)
|
86
|
+
pack_repo = nil
|
87
|
+
# todo: Case lower convert
|
88
|
+
uri = no_protocol_uri = extpack.split('/')
|
89
|
+
host, owner, pack_name = uri[0], uri[1], uri[2]
|
90
|
+
# todo: In china, you have to setup a proxy for Google Code
|
91
|
+
# sites = {
|
92
|
+
# # 'code.google.com',
|
93
|
+
# https: ['github.com', 'bitbucket.org', 'git.oschina.net'],
|
94
|
+
# http: [],
|
95
|
+
# git: []
|
96
|
+
# }
|
97
|
+
if extpack.index('.')
|
98
|
+
pack_repo = "https://#{host}/#{owner}/#{pack_name}"
|
99
|
+
else
|
100
|
+
$plog.error("不是外部Golang包: #{extpack}")
|
101
|
+
end
|
102
|
+
return pack_repo
|
103
|
+
end
|
104
|
+
end
|