Skip to content
Navigation Menu
{{ message }}
forked from javaee-samples/javaee-samples.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaeesamples.rb
More file actions
418 lines (389 loc) · 16.3 KB
/
Copy pathjavaeesamples.rb
File metadata and controls
418 lines (389 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# encoding: utf-8
require 'git'
require 'fileutils'
require 'rexml/document'
require_relative 'repository'
module Awestruct::Extensions::Repository::Visitors
module Clone
include Base
def visit(repository, site)
repos_dir = nil
if site.repos_dir
repos_dir = site.repos_dir
else
repos_dir = File.join(site.tmp_dir, 'repos')
end
if !File.directory? repos_dir
FileUtils.mkdir_p(repos_dir)
end
clone_dir = File.join(repos_dir, repository.path)
rc = nil
if !File.directory? clone_dir
puts "Cloning repository #{repository.clone_url} -> #{clone_dir}"
rc = Git.clone(repository.clone_url, clone_dir)
if repository.master_branch.nil?
rc.checkout(repository.master_branch)
else
repository.master_branch = rc.current_branch
end
else
puts "Using cloned repository #{clone_dir}"
rc = Git.open(clone_dir)
master_branch = repository.master_branch
if master_branch.nil?
master_branch = rc.branches.find{|b| !b.remote and !(b.name.include? 'detached' or b.name.include? 'no branch')}.name
repository.master_branch = master_branch
end
rc.checkout(master_branch)
begin
# attempt a light pull
rc.pull('origin')
rescue
# do hard reset to master branch, some forced change might have occured upstream
rc.fetch('origin')
rc.reset_hard("origin/#{master_branch}")
end
end
repository.clone_dir = clone_dir
repository.client = rc
end
end
module RepositoryHelpers
# Retrieves the contributors between the two commits, filtering
# by the relative path, if present
def self.resolve_contributors_between(site, repository, sha1, sha2, update_index = true)
range_author_index = {}
RepositoryHelpers.resolve_commits_between(repository, sha1, sha2).map {|c|
# we'll use email as the key to finding their identity; the sha we just need temporarily
# clear out bogus characters from email and downcase
OpenStruct.new({:name => c.author.name, :email => c.author.email.downcase.gsub(/[^\w@\.\(\)]/, ''), :commits => 0, :sha => c.sha})
}.each {|e|
# This loop both grabs unique authors by email and counts their commits
if !range_author_index.has_key? e.email
range_author_index[e.email] = e
end
range_author_index[e.email].commits += 1
}
range_author_index.values.each {|e|
# this loop registers author in global index if not present
if repository.host.eql? 'github.com' and update_index
site.git_author_index[e.email] ||= OpenStruct.new({
:email => e.email,
:name => e.name,
:sample_commit_sha => e.sha,
:sample_commit_url => RepositoryHelpers.build_commit_url(repository, e.sha, 'json'),
:commits => 0,
:repositories => []
})
site.git_author_index[e.email].commits += e.commits
site.git_author_index[e.email].repositories |= [repository.html_url]
end
e.delete_field('sha')
}.sort {|a, b| a.name <=> b.name}
end
# Retrieves the commits in the range, filtered on the relative
# path in the repository, if present
def self.resolve_commits_between(repository, sha1, sha2)
rc = repository.client
log = rc.log(10000).path(repository.relative_path)
if sha1.nil?
log = log.object(sha2)
else
log = log.between(sha1, sha2)
end
end
def self.build_commit_url(repository, sha, ext)
if !repository.commits_url.nil?
url = repository.commits_url.gsub(/\{.*/, "/#{sha}")
else
url = repository.html_url + '/commit/' + sha + '.' + ext
end
return url
end
end
module MavenHelpers
# Traverse all modules recursivly in a repository from a given rev:root
def self.traverse_modules(rev, repository)
pomrev = repository.client.revparse("#{rev}pom.xml")
pom = REXML::Document.new(repository.client.cat_file(pomrev))
yield rev, pom
unique_modules = Set.new
pom.each_element('/project/modules/module') do |mod|
unique_modules << mod.text()
end
pom.each_element('/project/profiles/profile/modules/module') do |mod|
unique_modules << mod.text()
end
unique_modules.each do |submodule|
MavenHelpers.traverse_modules("#{rev}#{submodule}/", repository) { |y, x| yield(y, x)}
end
end
def self.to_relative_sub_path(rev, relative_repository_path)
rev.gsub(/.*:/, '').gsub(relative_repository_path, '')
end
end
# SEMI-HACK think about how best to curate & display info about these special repos
# FIXME at least try to make GenericMavenComponent build on this one; perhaps a website component?
module GenericComponent
include Base
def handles(repository)
!File.exist? File.join(repository.clone_dir, repository.relative_path, 'pom.xml')
end
def visit(repository, site)
rc = repository.client
c = OpenStruct.new({
:repository => repository,
:basepath => repository.path.eql?(repository.owner) ? repository.path : repository.path.sub(/^#{repository.owner}-/, ''),
:owner => repository.owner,
:name => repository.name,
:desc => repository.desc,
:contributors => []
})
# FIXME not dry (from below)!
RepositoryHelpers.resolve_contributors_between(site, repository, nil, rc.revparse('HEAD')).each do |contrib|
i = c.contributors.index {|n| n.email == contrib.email}
if i.nil?
c.contributors << contrib
else
c.contributors[i].commits += contrib.commits
end
end
end
end
module GenericMavenComponent
include Base
def initialize
@root_head_pom = nil
end
def handles(repository)
repository.path != 'arquillian-showcase' and
repository.path != 'arquillian-container-reloaded' and
File.exist? File.join(repository.clone_dir, repository.relative_path, 'pom.xml')
#repository.path =~ /^arquillian-(core$|(testrunner|container|extension)-.+$)/ and
# repository.path != 'arquillian-testrunner-jbehave'
end
def visit(repository, site)
@root_head_pom = nil
rc = repository.client
c = OpenStruct.new({
:repository => repository,
:basepath => repository.path.eql?(repository.owner) ? repository.path : repository.path.sub(/^#{repository.owner}-/, ''),
:key => repository.path.split('-').last, # this is how components are matched in jira
:owner => repository.owner,
:html_url => repository.relative_path.empty? ? repository.html_url : "#{repository.html_url}/tree/#{repository.master_branch}/#{repository.relative_path.chomp('/')}",
:external => !repository.owner.eql?('arquillian'),
:name => resolve_name(repository),
:desc => repository.desc,
:groupId => resolve_group_id(repository),
:parent => true,
:lead => resolve_current_lead(repository, site.component_leads),
# we should not assume the license for external modules (hardcoding is not ideal either)
:license => ['jbossas', 'wildfly' 'jsfunit'].include?(repository.owner) ? 'LGPL-2.1' : 'Apache-2.0',
:releases => [],
:contributors => []
})
prev_sha = nil
rc.tags.select {|t|
# supports formats: 1.0.0.Alpha1
#t.name =~ /^[1-9]\d*\.\d+\.\d+\.((Alpha|Beta|CR)[1-9]\d*|Final)$/
# supports formats: 1.0.0.Alpha1 or 1.0.0-alpha-1 or with prefix- or 1.0.0 or 0.1
t.name =~ /^([a-z]+-?)?[0-9]\d*\.\d+(\.\d+)?([\.-]((alpha|beta|cr)-?[1-9]\d*|final))?$/i
}.sort_by{|t| rc.gcommit(t).author_date}.each do |t|
# skip tag if arquillian has nothing to do with it
next if repository.relative_path and rc.log(1).object(t.name).path(repository.relative_path).size.zero?
# for some reason, we have to use ^0 to get to the actual commit, can't use t.sha
sha = rc.revparse(t.name + '^0')
commit = rc.gcommit(sha)
committer = commit.committer
release = OpenStruct.new({
:tag => t.name,
:version => t.name.gsub(/^([a-z]+-?)/, ''),
:key => (c.key.eql?('core') ? '' : c.key + '_') + t.name, # jira release version key, should we add owner?
#:license => 'track?',
:sha => sha,
:html_url => RepositoryHelpers.build_commit_url(repository, sha, 'html'),
:json_url => RepositoryHelpers.build_commit_url(repository, sha, 'json'),
:date => commit.author_date,
:released_by => OpenStruct.new({
:name => committer.name,
:email => committer.email.downcase
}),
:contributors => RepositoryHelpers.resolve_contributors_between(site, repository, prev_sha, sha),
:published_artifacts => []
})
if site.resolve_published_artifacts and repository.owner.eql? 'arquillian'
resolve_published_artifacts(site.dir, repository, release)
end
# not assigning to release for now since it can be very space intensive
#if site.release_notes_by_version.has_key? release.key
# release.issues = site.release_notes_by_version[release.key]
#end
depversions = resolve_dep_versions(repository, release.tag)
release.compiledeps = []
{
'arquillian' => 'Arquillian Core',
'arquillian_core' => 'Arquillian Core',
'jboss_arquillian_core' => 'Arquillian Core',
'org_jboss_arquillian' => 'Arquillian Core',
'org_jboss_arquillian_core' => 'Arquillian Core',
'arquillian_drone' => 'Arquillian Drone',
'arquillian_warp' => 'Arquillian Warp',
'arquillian_transaction' => 'Arquillian Transaction',
'org_jboss_arquillian_graphene' => 'Arquillian Graphene',
'shrinkwrap_shrinkwrap' => 'ShrinkWrap Core',
'jboss_shrinkwrap' => 'ShrinkWrap Core',
'shrinkwrap' => 'ShrinkWrap Core',
'shrinkwrap_descriptors' => 'ShrinkWrap Descriptors',
'shrinkwrap_descriptor' => 'ShrinkWrap Descriptors',
'shrinkwrap_resolver' => 'ShrinkWrap Resolvers',
'selenium' => 'Selenium',
'junit_junit' => 'JUnit',
'testng_testng' => 'TestNG',
'spock' => 'Spock'
}.each do |key, name|
if depversions.has_key? key
release.compiledeps << OpenStruct.new({:name => name, :key => key, :version => depversions[key]})
end
end
c.releases << release
prev_sha = sha
end
c.latest_version = (!c.releases.empty? ? c.releases.last.version : resolve_head_version(repository))
c.latest_tag = (!c.releases.empty? ? c.releases.last.tag : 'HEAD')
c.releases.each do |r|
# FIXME not dry!
r.contributors.each do |contrib|
i = c.contributors.index {|n| n.email == contrib.email}
if i.nil?
c.contributors << contrib
else
c.contributors[i].commits += contrib.commits
end
end
end
# FIXME not dry!
RepositoryHelpers.resolve_contributors_between(site, repository, prev_sha, rc.revparse('HEAD')).each do |contrib|
i = c.contributors.index {|n| n.email == contrib.email}
if i.nil?
c.contributors << contrib
else
c.contributors[i].commits += contrib.commits
end
end
# we can be pretty sure we'll have at least one commit, otherwise why the repository ;)
last = rc.log(1).path(repository.relative_path).first
c.last_commit = OpenStruct.new({
:author => last.author,
:date => last.date,
:message => last.message,
:sha => last.sha,
:html_url => RepositoryHelpers.build_commit_url(repository, last.sha, 'html'),
:json_url => RepositoryHelpers.build_commit_url(repository, last.sha, 'json')
})
c.unreleased_commits = RepositoryHelpers.resolve_commits_between(repository, prev_sha, rc.revparse('HEAD')).size
c.modules = []
site.components[repository.path] = c
end
def resolve_name(repository)
pom = load_root_head_pom(repository)
name = pom.root.text('name')
# FIXME note misspelling of Aggregator in Drone extension
name.nil? ? repository.path : name.gsub(/[ :]*(Aggregator|Agreggator|Parent|module)+/, '')
end
def resolve_group_id(repository)
pom = load_root_head_pom(repository)
pom.root.text('groupId') || pom.root.elements['parent'].text('groupId')
end
def resolve_head_version(repository)
pom = load_root_head_pom(repository)
pom.root.text('version')
end
# QUESTION should we track lead by release version? (for historical reasons)
def resolve_current_lead(repository, component_leads)
if !component_leads.nil? and component_leads.has_key? repository.path
lead = component_leads[repository.path]
else
lead = nil
pom = load_root_head_pom(repository)
pom.each_element('/project/developers/developer') do |dev|
# capture first developer as fallback lead
if lead.nil? and !dev.text('email').nil?
lead = OpenStruct.new({:name => dev.text('name'), :email => dev.text('email').downcase})
end
if !dev.elements['roles'].nil?
if !dev.elements['roles'].elements.find { |role| role.name.eql? 'role' and role.text =~ / Lead/ }.nil?
lead = OpenStruct.new({:name => dev.text('name'), :email => dev.text('email').downcase})
break
end
end
end
if lead.nil?
# FIXME parameterize (keep in mind the JIRA extension hits most of the leads)
if repository.path.eql? 'jboss-as' or repository.path.eql? 'wildfly'
lead = OpenStruct.new({
:name => 'Jason T. Greene',
:jboss_username => 'jason.greene'
})
elsif repository.path.eql? 'plugin-arquillian'
lead = OpenStruct.new({
:name => 'Paul Bakker',
:jboss_username => 'pbakker'
})
elsif repository.path.eql? 'arquillian-graphene'
lead = OpenStruct.new({
:name => 'Lukáš Fryč',
:jboss_username => 'lfryc'
})
elsif repository.owner.eql? 'arquillian'
lead = OpenStruct.new({
:name => 'Aslak Knutsen',
:jboss_username => 'aslak'
})
elsif repository.path.eql? 'tomee'
lead = OpenStruct.new({
:name => 'David Blevins',
:jboss_username => 'dblevins'
})
end
end
# update the global index (why not?)
if !lead.nil?
component_leads[repository.path] = lead
end
end
lead
end
def resolve_dep_versions(repository, rev)
rc = repository.client
versions = {}
# FIXME Android extension defines versions in android-bom/pom.xml
['pom.xml', 'build/pom.xml', 'android-bom/pom.xml', "#{repository.relative_path}pom.xml"].each do |path|
# skip if path is not present in this revision
next if rc.log(1).object(rev).path(path).size.zero?
pom = REXML::Document.new(rc.cat_file(rc.revparse("#{rev}:#{path}")))
pom.each_element('/project/properties/*') do |prop|
if (prop.name.start_with? 'version.' or prop.name.end_with? '.version') and
not prop.name =~ /[\._]plugin$/ and
not prop.name =~ /\.maven[\._]/
versions[prop.name.sub(/\.?version\.?/, '').gsub('.', '_')] = prop.text
end
end
end
versions
end
def resolve_published_artifacts(sitedir, repository, release)
rc = repository.client
rc.checkout(release.sha)
if File.exist? File.join(repository.clone_dir, 'pom.xml')
artifacts = `cd #{repository.clone_dir} && #{sitedir}/_bin/list-reactor-artifacts`.split("\n")
release.published_artifacts = artifacts.map{|a| Artifact::Coordinates.parse a}.sort_by{|a| a.artifactId}
end
rc.checkout(repository.master_branch)
end
def load_root_head_pom(repository)
@root_head_pom ||= REXML::Document.new(
repository.client.cat_file(repository.client.revparse("HEAD:#{repository.relative_path}pom.xml"))
)
end
end
end
You can’t perform that action at this time.
