11#-*- mode: ruby -*-
2-
32task :default => [ :specs ]
43
54desc 'generate licenses data from internet'
65task :licenses do
76 require 'open-uri'
8- require 'ostruct '
9-
7+ require 'json '
8+
109 File . open ( 'lib/maven/tools/licenses.rb' , 'w' ) do |f |
11- url = 'http://opensource.org'
12- f . puts "require 'ostruct'"
10+ url = 'https://opensource.org'
1311 f . puts 'module Maven'
1412 f . puts ' module Tools'
13+ f . puts ' SpdxLicenseMeta = Struct.new(:short, :name, :url, keyword_init: true)'
1514 f . puts ' LICENSES = {}'
1615
17- open ( url + '/licenses/alphabetical' ) . each_line do |line |
18-
19- if line =~ /.*"\/ licenses\/ / and line =~ /<li>/
20- l = OpenStruct . new
21- line . sub! ( /.*"(\/ licenses\/ ([^"]*))">/ ) do
22- l . url = "http://opensource.org#{ $1} "
23- l . short = $1. sub ( /\/ licenses\/ / , '' )
24- ''
25- end
26- line . sub! ( /\ \( .*$/ , '' )
27- f . puts " LICENSES[ #{ l . short . downcase . inspect } ] = OpenStruct.new :short => #{ l . short . inspect } , :name => #{ line . strip . inspect } , :url => #{ l . url . inspect } "
28- end
29- end
16+ JSON . parse ( URI . open ( url + '/api/licenses' ) . read )
17+ . select { |l | l [ "spdx_id" ] . size > 0 && l [ "name" ] . size > 0 }
18+ . sort_by { |l | l [ "spdx_id" ] . downcase }
19+ . each { |l | f . puts ( " LICENSES[ #{ l [ "spdx_id" ] . downcase . inspect } ] = SpdxLicenseMeta.new( short: #{ l [ "spdx_id" ] . inspect } , name: #{ l [ "name" ] . inspect } , url: #{ l [ "_links" ] [ "html" ] [ "href" ] . inspect } ).freeze" ) }
20+
3021 f . puts ' LICENSES.freeze'
3122 f . puts ' end'
3223 f . puts 'end'
@@ -48,23 +39,4 @@ task :specs do
4839 Dir [ 'spec/**/*_spec.rb' ] . each { |f | require f . sub ( /spec\/ / , '' ) }
4940end
5041
51- task :headers do
52- require 'copyright_header'
53-
54- s = Gem ::Specification . load ( Dir [ "*gemspec" ] . first )
55-
56- args = {
57- :license => s . license ,
58- :copyright_software => s . name ,
59- :copyright_software_description => s . description ,
60- :copyright_holders => s . authors ,
61- :copyright_years => [ Time . now . year ] ,
62- :add_path => "lib:src" ,
63- :output_dir => './'
64- }
65-
66- command_line = CopyrightHeader ::CommandLine . new ( args )
67- command_line . execute
68- end
69-
7042# vim: syntax=Ruby
0 commit comments