-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathrelease_file_parser.rb
312 lines (265 loc) · 10.3 KB
/
release_file_parser.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
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
require 'fileutils'
module Awestruct
module Extensions
# Awestrcut extension which traverses the given directory to find release information,
# making it available in a hash.
#
# The assumption is that the parent directory is named after the project,
# and release files are YAML files in a direct subdirectory called 'releases'.
#
# The release information for a given release can then be accessed, starting from the
# top level site hash via:
# site['projects'].['<project-name>'].['releases'].['<release-version>'], eg site['projects'].['validator'].['releases'].['5.0.0.Final'].
#
# The release data itself is stored in the hash using at the moment the following keys:
# version, version_family, date, announcement_url, summary and displayed
class ReleaseFileParser
def initialize(data_dir="_data")
@data_dir = data_dir
end
def watch(watched_dirs)
watched_dirs << @data_dir
end
def execute(site)
# keep reference to site
@site = site
# register the parent hash for all releases with the site
@projects_hash = site[:projects]
if @projects_hash == nil
@projects_hash = Hash.new
site[:projects] = @projects_hash
end
# traverse the file system to find the release information
findReleaseFiles( site, "#{site.dir}/#{@data_dir}" )
end
def findReleaseFiles(site, dir)
Dir[ "#{dir}/*" ].each do |entry|
if ( File.directory?( entry ) )
if ( entry =~ /releases/ )
project = getProject( entry )
releases_hash = project[:releases]
if ( releases_hash == nil )
releases_hash = Hash.new
project[:releases] = releases_hash
end
release_series_hash = project[:release_series]
if ( release_series_hash == nil )
release_series_hash = Hash.new
project[:release_series] = release_series_hash
end
populateReleaseHashes( project, entry )
sortReleaseHashes( project )
else
findReleaseFiles( site, entry )
end
end
end
end
def getProject(sub_dir)
parent_dir = File.dirname( sub_dir )
project_id = File.basename( parent_dir )
project = @projects_hash[project_id]
if project == nil
project = Hash.new
@projects_hash[project_id] = project
end
if (project[:id] == nil)
project[:id] = project_id
end
return project
end
def populateReleaseHashes(project, releases_dir)
release_hash = project[:releases]
release_series_hash = project[:release_series]
Dir.foreach(releases_dir) do |file_name|
file = File.expand_path( file_name, releases_dir )
# skip '.' and '..'
if ( file_name.start_with?( "." ) )
next
else
# This directory represents a release series
series = createSeries( project, file )
release_series_hash[series.version] = series
# Populate this series' releases
Dir.foreach(file) do |sub_file_name|
sub_file = File.expand_path( sub_file_name, file )
# skip '.' and '..' and 'series.yml'
if ( File.directory?( sub_file ) || File.basename( sub_file ) == "series.yml" )
next
else
release = createRelease( project, series, sub_file )
series.releases.push( release )
release_hash[release.version] = release
end
end
end
end
end
def createSeries(project, series_dir)
series_file = File.expand_path( "./series.yml", series_dir )
series = @site.engine.load_yaml( series_file )
series[:project] = project
if ( series[:version] == nil )
series[:version] = File.basename( series_dir )
end
if ( series[:license] == nil )
series[:license] = project.license
end
series[:releases] = Array.new
return series
end
def createRelease(project, series, release_file)
unless ( release_file =~ /.*\.yml$/ )
abort( "The release file #{release_file} does not have the YAML (.yml) extension!" )
end
release = @site.engine.load_yaml( release_file )
release[:project] = project
release[:series] = series
if ( release[:version] == nil )
File.basename( release_file ) =~ /^(.*)\.\w*$/
release[:version] = $1
end
if ( series != nil )
release[:version_family] = series.version
end
if release.version =~ /.*\.(Alpha[0-9]+|Beta[0-9]+|CR[0-9]+)$/
release.stable = false
elsif release.version =~ /.*\.(Final|SP[0-9]+)/
release.stable = true
else
raise StandardError, "Unsupported version scheme for #{release_file}: #{release.version}"
end
if release[:scm_tag] == nil
if project.github['final_suffix_in_tags']
release[:scm_tag] = release.version
else
release[:scm_tag] = release.version =~ /^(.*).Final$/ ? $1 : release.version
end
end
if ( release[:license] == nil )
release[:license] = series.license
end
return release
end
def sortReleaseHashes(project)
releases = project[:releases]
unless releases == nil
releases = Hash[releases.sort_by { |key, value| Version.new(key) }.reverse]
project[:releases] = releases
# Also add useful, but redundant information to the objects
found_release = false
found_stable_release = false
releases.values.each do |release|
release.latest = false
release.latest_stable = false
if !found_release
found_release = true
release.latest = true
project[:latest_release] = release
end
if !found_stable_release && release.stable
found_stable_release = true
release.latest_stable = true
project[:latest_stable_release] = release
end
end
end
series = project[:release_series]
unless series == nil
series = Hash[series.sort_by { |key, value| Version.new(key) }.reverse]
project[:release_series] = series
# Also add useful, but redundant information to the objects
found_series = false
found_stable_series = false
series.each do |series_version, series|
releases = series.releases
releases = releases.sort_by { |release| Version.new(release.version) }.reverse
series.releases = releases
series.stable = releases.first.stable
if !found_series
found_series = true
series.latest = true
project[:latest_series] = series
else
series.latest = false
end
if !found_stable_series && series.stable
found_stable_series = true
series.latest_stable = true
project[:latest_stable_series] = series
if series[:status] == nil
series[:status] = 'latest-stable'
end
else
series.latest_stable = false
if series[:status] == nil
if !series.stable
series[:status] = 'development'
project[:next_dev_series] = series
else
# By default, stable series that are not the latest are considered end-of-life'd.
# This can be overridden in yaml.
series[:status] = 'end-of-life'
end
end
end
series[:endoflife] = series[:status] == 'end-of-life'
# The latest series might have its own branch, or might still be on main.
# We don't know so we won't try to guess.
if series[:scm_branch] == nil && !series.latest
series[:scm_branch] = series.version
end
series.latest_scm_ref = series[:scm_branch] || series.releases&.first&.scm_tag
end
end
project[:active_release_series] = project[:release_series].nil? ? nil
: project[:release_series].values.select{|s| !s[:displayed].nil? ? s.displayed : s[:status] != 'end-of-life'}
project[:older_release_series] = project[:release_series].nil? ? nil
: project[:release_series].values.select{|s| !s[:displayed].nil? ? !s.displayed : s[:status] == 'end-of-life'}
end
end
# Custom version class able to understand and compare the project versions of Hibernate projects
class Version
include Comparable
attr_reader :major, :feature_group, :feature, :bugfix
def initialize(version="")
v = version.to_s.split(".")
@major = v[0].to_i
@feature_group = v[1].to_i
@feature = v[2].to_i
@bugfix = v[3] == nil ? nil : VersionBugfix.new(v[3])
end
def <=>(other)
return @major <=> other.major if ((@major <=> other.major) != 0)
return @feature_group <=> other.feature_group if ((@feature_group <=> other.feature_group) != 0)
return @feature <=> other.feature if ((@feature <=> other.feature) != 0)
return @bugfix <=> other.bugfix
end
def self.sort
self.sort!{|a,b| a <=> b}
end
def to_s
@major.to_s + "." + @feature_group.to_s + "." + @feature.to_s + "." + @bugfix.to_s
end
end
class VersionBugfix
include Comparable
attr_reader :prefix, :number
def initialize(bugfix="")
split = bugfix.scan(/^([A-Za-z\-_]+)([0-9]+)?$/)
@prefix = split.first[0]
@number = split.first[1]&.to_i
end
def <=>(other)
return @prefix <=> other.prefix if ((@prefix <=> other.prefix) != 0)
return @number <=> other.number
end
def self.sort
self.sort!{|a,b| a <=> b}
end
def to_s
@bugfix + @number&.to_s
end
end
end
end