forked from sshaw/ddex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
82 lines (70 loc) · 2.42 KB
/
Rakefile
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
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "tmpdir"
RSpec::Core::RakeTask.new(:spec)
task :default => "spec"
desc "Generate code from the schema given by SCHEMA"
task :generate do
schema = ENV["SCHEMA"]
output = File.join(Dir.tmpdir, "ddex-schema-#{Time.now.to_i}")
abort "code generation requires JRuby" unless RUBY_PLATFORM == "java"
abort "usage: rake generate SCHEMA=schema.xsd" unless schema
sh "jaxb2ruby -o #{output} -I etc -t etc/ddex.erb -n etc/namespaces.yml #{schema}" do |ok, rv|
abort "code generation failed (#{rv.exitstatus})" unless ok
end
puts "Files output to #{output}"
# TODO: Automate this
puts "REMEMBER: you'll need to modify RelatedReleaseOfferSet:", <<-DEAL
# remove this require:
require "ddex/ern/vXX/deal"
# and forward declare Deal
class Deal < Element; include ROXML end
DEAL
end
%w[ern].each do |spec|
root = File.expand_path("../etc/schemas/#{spec}", __FILE__)
Dir.entries(root).each do |dir|
next if dir == "." or dir == ".."
# Ignore patch version
schema = dir[0..2].to_i < 34 ? "ern-main.xsd" : "release-notification.xsd"
schema = File.join(root, dir, schema)
desc "Validate the instance doc given by FILE against #{spec} v#{dir}"
task "validate:#{spec}#{dir}" do
abort "missing FILE argument" unless ENV["FILE"]
# Empty block to silence the stack trace, that aside, we do want verboseness
sh "xmllint --noout --schema #{schema} #{ENV["FILE"]}" do end
end
end
end
desc "List currently generated versions"
task :versions do
# Maybe better to use a method on DDEX...
root = File.expand_path("../lib/ddex", __FILE__)
specs = Dir.glob("#{root}/*").select { |path| File.directory?(path) }
specs.each do |spec|
puts "#{File.basename(spec)}: "
versions = Dir.glob(File.join(spec, "*")).select { |path| File.directory?(path) }
versions.each { |version| puts " #{File.basename(version)}" }
end
end
namespace :generate do
desc "Create a 'main' file to load the given spec and version"
task :main, :name, :version do |t, args|
name = args[:name]
ver = args[:version]
abort "usage: generate:main[name, version]" unless name and ver
puts <<MAIN
#
# Do not edit. Automatically generated by `rake generate:main`.
#
module DDEX
module #{name.upcase}
module V#{ver.upcase.tr(".", "")}
extend DDEX
require_standard("#{name}", "#{ver}")
end
end
end
MAIN
end
end