-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathlinks.rb
252 lines (218 loc) · 9.51 KB
/
links.rb
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
require 'logger'
module Awestruct
module Extensions
module Links
def execute(site)
# keep reference to site
@site = site
end
def reference_doc(project, series)
return DocumentRef.from_patterns(project, series, :reference_doc)
end
def javadoc(project, series)
return DocumentRef.from_patterns(project, series, :javadoc)
end
def getting_started_guides(project, series)
return DocumentRef.from_patterns_multi(project, series, :getting_started_guide)
end
def migration_guide(project, series)
return DocumentRef.from_patterns(project, series, :migration_guide)
end
def maven(project, series, release)
return MavenRef.from(@site, project, series, release)
end
def github_issues_url(project)
return "https://github.com/hibernate/#{project.github['project']}/issues?q=is%3Aissue+is%3Aclosed+"
end
def jira_issues_for_series_url(project, series)
versions = series.releases.collect{|r| r.version}
return jira_issues_for_versions_url(project, versions)
end
def jira_issues_for_release_url(project, release)
return jira_issues_for_versions_url(project, [release.version])
end
def jira_issues_for_versions_url(project, versions)
fix_version_translator = _fix_version_translator(project)
comma_separated_fix_versions = versions.collect{|v| fix_version_translator.call(v)}.join( "%2C%20" )
return "https://hibernate.atlassian.net/issues/?jql=project%20%3D%20#{project.jira['key']}%20AND%20fixVersion%20in%20(#{comma_separated_fix_versions})%20ORDER%20BY%20updated"
end
def _fix_version_translator(project)
return project.jira['key'] == 'HHH' ?
lambda {|v| v != '4.2.0.Final' && v != '4.3.0.Final' && v != '5.0.0.Final' && v =~ /^(.*).Final$/ ? $1 : v }
: lambda {|v| v}
end
def dist_sourceforge(project, series, release)
return DistRef.from(project, series, release, :sourceforge)
end
def self._pattern_substitute(pattern, project, series = nil, release = nil)
if pattern.nil?
return nil
end
return pattern.gsub('{series.version}', series&.version || '')
.gsub('{series.latest_scm_ref}', series&.latest_scm_ref || '')
.gsub('{release.version}', release&.version || '')
.gsub('{series.version.dashes}', series&.version&.gsub('.', '-') || '')
end
class MavenRef
@@logger = Logger.new(STDERR)
@@logger.level = Logger::INFO
def self.from(site, project, series, release)
log_prefix = "#{project.name}/#{series.version}/#{release.version}: "
project_maven = project[:maven] || {}
series_maven = series[:maven] || {}
release_maven = release[:maven] || {}
maven_coord = release_maven&.[](:coord) || series_maven&.[](:coord) || project_maven[:coord]
@@logger.debug("#{log_prefix}Coord: #{maven_coord}")
maven_signing = project_maven&.[](:signing)
maven_repo = {}
maven_repo[:releases] = MavenRepoRef.from( site, release_maven&.[](:repo)&.[](:releases) || series_maven&.[](:repo)&.[](:releases) || project_maven&.[](:repo)&.[](:releases) )
maven_repo[:snapshots] = MavenRepoRef.from( site, release_maven&.[](:repo)&.[](:snapshots) || series_maven&.[](:repo)&.[](:snapshots) || project_maven&.[](:repo)&.[](:snapshots) )
@@logger.debug("#{log_prefix}Repo: #{maven_repo}")
maven_artifacts = release_maven&.[](:artifacts) || series_maven&.[](:artifacts) || project_maven[:artifacts]
@@logger.debug("#{log_prefix}Artifacts: #{maven_artifacts}")
return MavenRef.new(maven_coord, maven_signing, maven_artifacts, maven_repo)
end
attr_reader :coord, :signing, :artifacts, :repo
def initialize(coord, signing, artifacts, repo)
@coord = coord
@signing = signing
@artifacts = artifacts
@repo = repo
end
end
class MavenRepoRef
def self.from(site, id)
data = site.maven.repo&.[](id)
return MavenRepoRef.new(id, data)
end
attr_reader :id, :data
def initialize(id, data)
@id = id
@data = data
end
def to_s
@id
end
def web_ui_all_artifacts_url(coord, version)
if @id != 'central'
raise StandardError, "Cannot generate web UI artifact links for repository: #{@id}"
end
if coord.artifact_id_pattern?
# The new Maven Central WebUI doesn't support artifact ID patterns, so we fall back to the old WebUI.
search_string = ERB::Util.url_encode("g:#{coord.group_id} AND a:#{coord.artifact_id_pattern} AND v:#{version}")
return "#{@data.old_web_ui_url}/search?q=#{search_string}"
else
search_string = ERB::Util.url_encode("g:#{coord.group_id} v:#{version}")
return "#{@data.web_ui_url}/search?q=#{search_string}&sort=name"
end
end
def web_ui_artifact_url(group_id, artifact_id, version)
if @id != 'central'
raise StandardError, "Cannot generate web UI artifact links for repository: #{@id}"
end
return "#{@data.web_ui_url}/artifact/#{group_id}/#{artifact_id}/#{version}"
end
def direct_download_url(coord)
group_id_path = coord.group_id.gsub('.', '/')
return "#{@data.repo_url}/#{group_id_path}/"
end
end
class DocumentRef
@@logger = Logger.new(STDERR)
@@logger.level = Logger::INFO
def self.from_patterns(project, series, link_key)
log_prefix = "#{project.name}/#{series.version}/#{link_key}: "
link_root = series&.links&.[](link_key)
link_root ||= project&.links&.[](link_key)
return from_patterns_single(project, series, link_key, link_root)
end
def self.from_patterns_multi(project, series, link_key)
log_prefix = "#{project.name}/#{series.version}/#{link_key}: "
link_root = series&.links&.[](link_key)
link_root ||= project&.links&.[](link_key)
links = []
if link_root.kind_of?(Array)
link_root.each do |link|
links.push(from_patterns_single(project, series, link_key, link))
end
else
links.push(from_patterns_single(project, series, link_key, link_root))
end
return links.compact
end
def self.from_patterns_single(project, series, link_key, link)
log_prefix = "#{project.name}/#{series.version}/#{link_key}: "
if link.nil?
@@logger.debug("#{log_prefix}Link is nil")
return nil
end
displayed = link['displayed']
if not displayed.nil? and not displayed
@@logger.debug("#{log_prefix}Link is not displayed")
return nil
end
latest_stable_only = link['latest_stable_only']
if not latest_stable_only.nil? and latest_stable_only and not series.latest_stable
@@logger.debug("#{log_prefix}Link is for the latest stable series only")
return nil
end
name = link['name']
@@logger.debug("#{log_prefix}Link name: #{name}")
latest_stable = link['latest_stable']
if latest_stable and series.latest_stable
link = latest_stable
@@logger.debug("#{log_prefix}Link overridden for latest stable: #{link}")
end
html_pattern = link['html']
pdf_pattern = link['pdf']
@@logger.debug("#{log_prefix}Link patterns: #{html_pattern} / #{pdf_pattern}")
html_url = Links._pattern_substitute(html_pattern, project, series)
pdf_url = Links._pattern_substitute(pdf_pattern, project, series)
@@logger.debug("#{log_prefix}Link URLs: #{html_url} / #{pdf_url}")
if html_url.nil? and pdf_url.nil?
return nil
end
return DocumentRef.new(name, html_url, pdf_url)
end
attr_reader :name, :html_url, :pdf_url
def initialize(name, html_url, pdf_url)
@name = name
@html_url = html_url
@pdf_url = pdf_url
end
end
class DistRef
@@logger = Logger.new(STDERR)
@@logger.level = Logger::INFO
def self.from(project, series, release, link_key)
log_prefix = "#{project.name}/#{series.version}/#{release&.version}/#{link_key}: "
link = release&.links&.dist&.[](link_key)
link ||= series&.links&.dist&.[](link_key)
link ||= project&.links&.dist&.[](link_key)
if link.nil?
@@logger.debug("#{log_prefix}Link is nil")
return nil
end
@@logger.debug("#{log_prefix}Link is #{link}")
displayed = link['displayed']
if not displayed.nil? and not displayed
@@logger.debug("#{log_prefix}Link is not displayed")
return nil
end
zip_pattern = link['zip']
@@logger.debug("#{log_prefix}Link patterns: #{zip_pattern}")
zip_url = Links._pattern_substitute(zip_pattern, project, series, release)
@@logger.debug("#{log_prefix}Link URLs: #{zip_url}")
if zip_url.nil?
return nil
end
return DistRef.new(zip_url)
end
attr_reader :zip_url
def initialize(zip_url)
@zip_url = zip_url
end
end
end
end
end