rubygems-generate_index 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e89ec0ba401376957ef5cd59bfaecd5e77bc043775fa0f4414332dffab489aa
4
+ data.tar.gz: 9032f6fe7bb94da4d1b9c11bfd29bbbd0f6bb4bc74d054c2825c833121ea84c0
5
+ SHA512:
6
+ metadata.gz: ad0f57dd0f7a01f1b6702848190c5623af4787ffde8817ee090fb334b1c575f47f112f21aee01d047dbe12df1409635a40abb55ae9617bd3c29dd913de91c458
7
+ data.tar.gz: ee119a9d5bad9b7045d22868eaf08e4c2efbc9097eb03ed1f9cd2f3b858da00fbedc596fc839d22aa2db7f6a51ea41cef7ae3ce3fd4fc7f8d94ce1130bf24b75
@@ -0,0 +1,81 @@
1
+ # RubyGems and Bundler Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or advances of any kind
22
+ * Trolling, insulting or derogatory comments, and personal or political attacks
23
+ * Public or private harassment
24
+ * Publishing others' private information, such as a physical or email address, without their explicit permission
25
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
26
+
27
+ ## Enforcement Responsibilities
28
+
29
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32
+
33
+ ## Scope
34
+
35
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36
+
37
+ ## Enforcement
38
+
39
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at team@bundler.io, or directly contacting project team members via email or Slack. All complaints will be reviewed and investigated promptly and fairly.
40
+
41
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42
+
43
+ ## Enforcement Guidelines
44
+
45
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46
+
47
+ ### 1. Correction
48
+
49
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50
+
51
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52
+
53
+ ### 2. Warning
54
+
55
+ **Community Impact**: A violation through a single incident or series of actions.
56
+
57
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58
+
59
+ ### 3. Temporary Ban
60
+
61
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62
+
63
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64
+
65
+ ### 4. Permanent Ban
66
+
67
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68
+
69
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
70
+
71
+ ## Attribution
72
+
73
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
74
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
75
+
76
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
77
+
78
+ [homepage]: https://www.contributor-covenant.org
79
+
80
+ For answers to common questions about this code of conduct, see the FAQ at
81
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rubygems-generate_index.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "test-unit", "~> 3.0"
10
+ install_if -> { RUBY_VERSION >= "2.7" } do
11
+ gem "rubocop", "~> 1.21"
12
+ gem "rubocop-performance", "~> 1.19"
13
+ end
14
+ install_if -> { Gem::VERSION < "3.2.0" } do
15
+ gem "builder", "~> 3.2"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubygems-generate_index (1.0.0)
5
+ compact_index (~> 0.14.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ base64 (0.1.1)
12
+ builder (3.2.4)
13
+ compact_index (0.14.0)
14
+ json (2.6.3)
15
+ json (2.6.3-java)
16
+ language_server-protocol (3.17.0.3)
17
+ parallel (1.23.0)
18
+ parser (3.2.2.3)
19
+ ast (~> 2.4.1)
20
+ racc
21
+ power_assert (2.0.3)
22
+ racc (1.7.1)
23
+ racc (1.7.1-java)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.8.1)
27
+ rexml (3.2.6)
28
+ rubocop (1.56.3)
29
+ base64 (~> 0.1.1)
30
+ json (~> 2.3)
31
+ language_server-protocol (>= 3.17.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.2.2.3)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml (>= 3.2.5, < 4.0)
37
+ rubocop-ast (>= 1.28.1, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 2.4.0, < 3.0)
40
+ rubocop-ast (1.29.0)
41
+ parser (>= 3.2.1.0)
42
+ rubocop-performance (1.19.1)
43
+ rubocop (>= 1.7.0, < 2.0)
44
+ rubocop-ast (>= 0.4.0)
45
+ ruby-progressbar (1.13.0)
46
+ test-unit (3.6.1)
47
+ power_assert
48
+ unicode-display_width (2.4.2)
49
+
50
+ PLATFORMS
51
+ arm64-darwin
52
+ arm64-linux
53
+ java
54
+ ruby
55
+ x64-linux
56
+
57
+ DEPENDENCIES
58
+ builder (~> 3.2)
59
+ rake (~> 13.0)
60
+ rubocop (~> 1.21)
61
+ rubocop-performance (~> 1.19)
62
+ rubygems-generate_index!
63
+ test-unit (~> 3.0)
64
+
65
+ BUNDLED WITH
66
+ 2.4.19
data/LICENSE.txt ADDED
@@ -0,0 +1,54 @@
1
+ RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim
2
+ Weirich and others. You can redistribute it and/or modify it under
3
+ either the terms of the MIT license (see the file MIT.txt), or the
4
+ conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a. place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b. use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c. give non-standard executables non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d. make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a. distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b. accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c. give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d. make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial).
43
+
44
+ 5. The scripts and library files supplied as input to or produced as
45
+ output from the software do not automatically fall under the
46
+ copyright of the software, but belong to whomever generated them,
47
+ and may be sold commercially, and may be aggregated with this
48
+ software.
49
+
50
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
51
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
52
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53
+ PURPOSE.
54
+
data/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Chad Fowler, Rich Kilmer, Jim Weirich and others.
2
+ Portions copyright (c) Engine Yard and Andre Arko
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ 'Software'), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ CODE_OF_CONDUCT.md
2
+ Gemfile
3
+ Gemfile.lock
4
+ LICENSE.txt
5
+ MIT.txt
6
+ Manifest.txt
7
+ README.md
8
+ lib/rubygems/commands/generate_index_command.rb
9
+ lib/rubygems/indexer.rb
10
+ lib/rubygems_plugin.rb
11
+ rubygems-generate_index.gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # rubygems-generate_index
2
+
3
+ rubygems-generate_index generates the index files for a `gem server` directory.
4
+
5
+ The generate_index command creates a set of indexes for serving gems
6
+ statically. The command expects a 'gems' directory under the path given to
7
+ the --directory option. The given directory will be the directory you serve
8
+ as the gem repository.
9
+
10
+ For `gem generate_index --directory /path/to/repo`, expose /path/to/repo via
11
+ your HTTP server configuration (not /path/to/repo/gems).
12
+
13
+ When done, it will generate a set of files like this:
14
+
15
+ ```
16
+ gems/*.gem # .gem files you want to
17
+ # index
18
+
19
+ specs.<version>.gz # specs index
20
+ latest_specs.<version>.gz # latest specs index
21
+ prerelease_specs.<version>.gz # prerelease specs index
22
+ quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
23
+ ```
24
+
25
+ The .rz extension files are compressed with the inflate algorithm.
26
+ The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
27
+ Marshal::MINOR_VERSION constants. It is used to ensure compatibility.
28
+
29
+ This gem is a replacement for the `gem generate_index` command that was removed in RubyGems 3.5.0.
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'rubygems-generate_index'
37
+ ```
38
+
39
+ And then execute:
40
+
41
+ $ bundle install
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install rubygems-generate_index
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubygems/rubygems-generate_index.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems/command"
4
+ require_relative "../indexer"
5
+
6
+ ##
7
+ # Generates a index files for use as a gem server.
8
+ #
9
+ # See `gem help generate_index`
10
+
11
+ class Gem::Commands::GenerateIndexCommand < Gem::Command
12
+ def initialize
13
+ super "generate_index",
14
+ "Generates the index files for a gem server directory",
15
+ :directory => ".", :build_modern => true
16
+
17
+ @deprecated_options = { "generate_index" => {} } unless defined?(@deprecated_options)
18
+
19
+ add_option "-d", "--directory=DIRNAME",
20
+ "repository base dir containing gems subdir" do |dir, options|
21
+ options[:directory] = File.expand_path dir
22
+ end
23
+
24
+ add_option "--[no-]modern",
25
+ "Generate indexes for RubyGems",
26
+ "(always true)" do |value, options|
27
+ options[:build_modern] = value
28
+ end
29
+
30
+ deprecate_option("--modern", version: "4.0", extra_msg: "Modern indexes (specs, latest_specs, and prerelease_specs) are always generated, so this option is not needed.")
31
+ deprecate_option("--no-modern", version: "4.0", extra_msg: "The `--no-modern` option is currently ignored. Modern indexes (specs, latest_specs, and prerelease_specs) are always generated.")
32
+
33
+ add_option "--update",
34
+ "Update modern indexes with gems added",
35
+ "since the last update" do |value, options|
36
+ options[:update] = value
37
+ end
38
+ end
39
+
40
+ def defaults_str # :nodoc:
41
+ "--directory . --modern"
42
+ end
43
+
44
+ def description # :nodoc:
45
+ <<-EOF
46
+ The generate_index command creates a set of indexes for serving gems
47
+ statically. The command expects a 'gems' directory under the path given to
48
+ the --directory option. The given directory will be the directory you serve
49
+ as the gem repository.
50
+
51
+ For `gem generate_index --directory /path/to/repo`, expose /path/to/repo via
52
+ your HTTP server configuration (not /path/to/repo/gems).
53
+
54
+ When done, it will generate a set of files like this:
55
+
56
+ gems/*.gem # .gem files you want to
57
+ # index
58
+
59
+ specs.<version>.gz # specs index
60
+ latest_specs.<version>.gz # latest specs index
61
+ prerelease_specs.<version>.gz # prerelease specs index
62
+ quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
63
+
64
+ The .rz extension files are compressed with the inflate algorithm.
65
+ The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
66
+ Marshal::MINOR_VERSION constants. It is used to ensure compatibility.
67
+ EOF
68
+ end
69
+
70
+ def execute
71
+ # This is always true because it's the only way now.
72
+ options[:build_modern] = true
73
+
74
+ if !File.exist?(options[:directory]) ||
75
+ !File.directory?(options[:directory])
76
+ alert_error "unknown directory name #{options[:directory]}."
77
+ terminate_interaction 1
78
+ else
79
+ indexer = Gem::Indexer.new options.delete(:directory), options
80
+
81
+ if options[:update]
82
+ indexer.update_index
83
+ else
84
+ indexer.generate_index
85
+ end
86
+ end
87
+ end
88
+
89
+ unless allocate.respond_to?(:deprecate_option)
90
+ def deprecate_option(name, version: nil, extra_msg: nil)
91
+ @deprecated_options[command].merge!({ name => { "rg_version_to_expire" => version, "extra_msg" => extra_msg } })
92
+ end
93
+
94
+ def check_deprecated_options(options)
95
+ options.each do |option|
96
+ next unless option_is_deprecated?(option)
97
+ deprecation = @deprecated_options[command][option]
98
+ version_to_expire = deprecation["rg_version_to_expire"]
99
+
100
+ deprecate_option_msg = if version_to_expire
101
+ "The \"#{option}\" option has been deprecated and will be removed in Rubygems #{version_to_expire}."
102
+ else
103
+ "The \"#{option}\" option has been deprecated and will be removed in future versions of Rubygems."
104
+ end
105
+
106
+ extra_msg = deprecation["extra_msg"]
107
+
108
+ deprecate_option_msg += " #{extra_msg}" if extra_msg
109
+
110
+ alert_warning(deprecate_option_msg)
111
+ end
112
+ end
113
+
114
+ def handle_options(args)
115
+ super
116
+ check_deprecated_options(args)
117
+ end
118
+
119
+ private
120
+
121
+ def option_is_deprecated?(option)
122
+ @deprecated_options[command].key?(option)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,452 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "rubygems/package"
5
+ require "tmpdir"
6
+
7
+ if Gem::VERSION < "3.2.0"
8
+ begin
9
+ gem "builder"
10
+ require "builder/xchar"
11
+ rescue *rescue_exceptions
12
+ end
13
+ end
14
+
15
+ ##
16
+ # Top level class for building the gem repository index.
17
+
18
+ class Gem::Indexer
19
+ include Gem::UserInteraction
20
+
21
+ ##
22
+ # Build indexes for RubyGems 1.2.0 and newer when true
23
+
24
+ attr_accessor :build_modern
25
+
26
+ ##
27
+ # Index install location
28
+
29
+ attr_reader :dest_directory
30
+
31
+ ##
32
+ # Specs index install location
33
+
34
+ attr_reader :dest_specs_index
35
+
36
+ ##
37
+ # Latest specs index install location
38
+
39
+ attr_reader :dest_latest_specs_index
40
+
41
+ ##
42
+ # Prerelease specs index install location
43
+
44
+ attr_reader :dest_prerelease_specs_index
45
+
46
+ ##
47
+ # Index build directory
48
+
49
+ attr_reader :directory
50
+
51
+ ##
52
+ # Create an indexer that will index the gems in +directory+.
53
+
54
+ def initialize(directory, options = {})
55
+ require "fileutils"
56
+ require "tmpdir"
57
+ require "zlib"
58
+
59
+ if Gem::VERSION < "3.2.0" && !defined?(Builder::XChar)
60
+ raise "Gem::Indexer requires that the XML Builder library be installed:" \
61
+ "\n\tgem install builder"
62
+ end
63
+
64
+ options = { :build_modern => true }.merge options
65
+
66
+ @build_modern = options[:build_modern]
67
+
68
+ @dest_directory = directory
69
+ @directory = Dir.mktmpdir "gem_generate_index"
70
+
71
+ marshal_name = "Marshal.#{Gem.marshal_version}"
72
+
73
+ @master_index = File.join @directory, "yaml"
74
+ @marshal_index = File.join @directory, marshal_name
75
+
76
+ @quick_dir = File.join @directory, "quick"
77
+ @quick_marshal_dir = File.join @quick_dir, marshal_name
78
+ @quick_marshal_dir_base = File.join "quick", marshal_name # FIX: UGH
79
+
80
+ @quick_index = File.join @quick_dir, "index"
81
+ @latest_index = File.join @quick_dir, "latest_index"
82
+
83
+ @specs_index = File.join @directory, "specs.#{Gem.marshal_version}"
84
+ @latest_specs_index =
85
+ File.join(@directory, "latest_specs.#{Gem.marshal_version}")
86
+ @prerelease_specs_index =
87
+ File.join(@directory, "prerelease_specs.#{Gem.marshal_version}")
88
+ @dest_specs_index =
89
+ File.join(@dest_directory, "specs.#{Gem.marshal_version}")
90
+ @dest_latest_specs_index =
91
+ File.join(@dest_directory, "latest_specs.#{Gem.marshal_version}")
92
+ @dest_prerelease_specs_index =
93
+ File.join(@dest_directory, "prerelease_specs.#{Gem.marshal_version}")
94
+
95
+ @files = []
96
+ end
97
+
98
+ ##
99
+ # Build various indices
100
+
101
+ def build_indices
102
+ specs = map_gems_to_specs gem_file_list
103
+ Gem::Specification._resort! specs
104
+ build_marshal_gemspecs specs
105
+ build_modern_indices specs if @build_modern
106
+
107
+ compress_indices
108
+ end
109
+
110
+ ##
111
+ # Builds Marshal quick index gemspecs.
112
+
113
+ def build_marshal_gemspecs(specs)
114
+ count = specs.count
115
+ progress = ui.progress_reporter count,
116
+ "Generating Marshal quick index gemspecs for #{count} gems",
117
+ "Complete"
118
+
119
+ files = []
120
+
121
+ Gem.time "Generated Marshal quick index gemspecs" do
122
+ specs.each do |spec|
123
+ next if spec.default_gem?
124
+ spec_file_name = "#{spec.original_name}.gemspec.rz"
125
+ marshal_name = File.join @quick_marshal_dir, spec_file_name
126
+
127
+ marshal_zipped = Gem.deflate Marshal.dump(spec)
128
+
129
+ File.open marshal_name, "wb" do |io|
130
+ io.write marshal_zipped
131
+ end
132
+
133
+ files << marshal_name
134
+
135
+ progress.updated spec.original_name
136
+ end
137
+
138
+ progress.done
139
+ end
140
+
141
+ @files << @quick_marshal_dir
142
+
143
+ files
144
+ end
145
+
146
+ ##
147
+ # Build a single index for RubyGems 1.2 and newer
148
+
149
+ def build_modern_index(index, file, name)
150
+ say "Generating #{name} index"
151
+
152
+ Gem.time "Generated #{name} index" do
153
+ File.open(file, "wb") do |io|
154
+ specs = index.map do |*spec|
155
+ # We have to splat here because latest_specs is an array, while the
156
+ # others are hashes.
157
+ spec = spec.flatten.last
158
+ platform = spec.original_platform
159
+
160
+ # win32-api-1.0.4-x86-mswin32-60
161
+ unless String === platform
162
+ alert_warning "Skipping invalid platform in gem: #{spec.full_name}"
163
+ next
164
+ end
165
+
166
+ platform = Gem::Platform::RUBY if platform.nil? || platform.empty?
167
+ [spec.name, spec.version, platform]
168
+ end
169
+
170
+ specs = compact_specs(specs)
171
+ Marshal.dump(specs, io)
172
+ end
173
+ end
174
+ end
175
+
176
+ ##
177
+ # Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease
178
+
179
+ def build_modern_indices(specs)
180
+ prerelease, released = specs.partition do |s|
181
+ s.version.prerelease?
182
+ end
183
+ latest_specs =
184
+ Gem::Specification._latest_specs specs
185
+
186
+ build_modern_index(released.sort, @specs_index, "specs")
187
+ build_modern_index(latest_specs.sort, @latest_specs_index, "latest specs")
188
+ build_modern_index(prerelease.sort, @prerelease_specs_index,
189
+ "prerelease specs")
190
+
191
+ @files += [@specs_index,
192
+ "#{@specs_index}.gz",
193
+ @latest_specs_index,
194
+ "#{@latest_specs_index}.gz",
195
+ @prerelease_specs_index,
196
+ "#{@prerelease_specs_index}.gz"]
197
+ end
198
+
199
+ def map_gems_to_specs(gems)
200
+ gems.map do |gemfile|
201
+ if File.size(gemfile) == 0
202
+ alert_warning "Skipping zero-length gem: #{gemfile}"
203
+ next
204
+ end
205
+
206
+ begin
207
+ spec = Gem::Package.new(gemfile).spec
208
+ spec.loaded_from = gemfile
209
+
210
+ spec.abbreviate
211
+ spec.sanitize
212
+
213
+ spec
214
+ rescue SignalException
215
+ alert_error "Received signal, exiting"
216
+ raise
217
+ rescue StandardError => e
218
+ msg = ["Unable to process #{gemfile}",
219
+ "#{e.message} (#{e.class})",
220
+ "\t#{e.backtrace.join "\n\t"}"].join("\n")
221
+ alert_error msg
222
+ end
223
+ end.compact
224
+ end
225
+
226
+ ##
227
+ # Compresses indices on disk
228
+ #--
229
+ # All future files should be compressed using gzip, not deflate
230
+
231
+ def compress_indices
232
+ say "Compressing indices"
233
+
234
+ Gem.time "Compressed indices" do
235
+ if @build_modern
236
+ gzip @specs_index
237
+ gzip @latest_specs_index
238
+ gzip @prerelease_specs_index
239
+ end
240
+ end
241
+ end
242
+
243
+ ##
244
+ # Compacts Marshal output for the specs index data source by using identical
245
+ # objects as much as possible.
246
+
247
+ def compact_specs(specs)
248
+ names = {}
249
+ versions = {}
250
+ platforms = {}
251
+
252
+ specs.map do |(name, version, platform)|
253
+ names[name] = name unless names.include? name
254
+ versions[version] = version unless versions.include? version
255
+ platforms[platform] = platform unless platforms.include? platform
256
+
257
+ [names[name], versions[version], platforms[platform]]
258
+ end
259
+ end
260
+
261
+ ##
262
+ # Compress +filename+ with +extension+.
263
+
264
+ def compress(filename, extension)
265
+ data = Gem.read_binary filename
266
+
267
+ zipped = Gem.deflate data
268
+
269
+ File.open "#{filename}.#{extension}", "wb" do |io|
270
+ io.write zipped
271
+ end
272
+ end
273
+
274
+ ##
275
+ # List of gem file names to index.
276
+
277
+ def gem_file_list
278
+ Gem::Util.glob_files_in_dir("*.gem", File.join(@dest_directory, "gems"))
279
+ end
280
+
281
+ ##
282
+ # Builds and installs indices.
283
+
284
+ def generate_index
285
+ make_temp_directories
286
+ build_indices
287
+ install_indices
288
+ rescue SignalException
289
+ ensure
290
+ FileUtils.rm_rf @directory
291
+ end
292
+
293
+ ##
294
+ # Zlib::GzipWriter wrapper that gzips +filename+ on disk.
295
+
296
+ def gzip(filename)
297
+ Zlib::GzipWriter.open "#{filename}.gz" do |io|
298
+ io.write Gem.read_binary(filename)
299
+ end
300
+ end
301
+
302
+ ##
303
+ # Install generated indices into the destination directory.
304
+
305
+ def install_indices
306
+ verbose = Gem.configuration.really_verbose
307
+
308
+ say "Moving index into production dir #{@dest_directory}" if verbose
309
+
310
+ files = @files
311
+ files.delete @quick_marshal_dir if files.include? @quick_dir
312
+
313
+ if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir)
314
+ files.delete @quick_marshal_dir
315
+
316
+ dst_name = File.join(@dest_directory, @quick_marshal_dir_base)
317
+
318
+ FileUtils.mkdir_p File.dirname(dst_name), :verbose => verbose
319
+ FileUtils.rm_rf dst_name, :verbose => verbose
320
+ FileUtils.mv(@quick_marshal_dir, dst_name,
321
+ :verbose => verbose, :force => true)
322
+ end
323
+
324
+ files = files.map do |path|
325
+ path.sub(%r{^#{Regexp.escape @directory}/?}, "") # HACK?
326
+ end
327
+
328
+ files.each do |file|
329
+ src_name = File.join @directory, file
330
+ dst_name = File.join @dest_directory, file
331
+
332
+ FileUtils.rm_rf dst_name, :verbose => verbose
333
+ FileUtils.mv(src_name, @dest_directory,
334
+ :verbose => verbose, :force => true)
335
+ end
336
+ end
337
+
338
+ ##
339
+ # Make directories for index generation
340
+
341
+ def make_temp_directories
342
+ FileUtils.rm_rf @directory
343
+ FileUtils.mkdir_p @directory, :mode => 0o700
344
+ FileUtils.mkdir_p @quick_marshal_dir
345
+ end
346
+
347
+ ##
348
+ # Ensure +path+ and path with +extension+ are identical.
349
+
350
+ def paranoid(path, extension)
351
+ data = Gem.read_binary path
352
+ compressed_data = Gem.read_binary "#{path}.#{extension}"
353
+
354
+ unless data == Gem::Util.inflate(compressed_data)
355
+ raise "Compressed file #{compressed_path} does not match uncompressed file #{path}"
356
+ end
357
+ end
358
+
359
+ ##
360
+ # Perform an in-place update of the repository from newly added gems.
361
+
362
+ def update_index
363
+ make_temp_directories
364
+
365
+ specs_mtime = File.stat(@dest_specs_index).mtime
366
+ newest_mtime = Time.at 0
367
+
368
+ updated_gems = gem_file_list.select do |gem|
369
+ gem_mtime = File.stat(gem).mtime
370
+ newest_mtime = gem_mtime if gem_mtime > newest_mtime
371
+ gem_mtime >= specs_mtime
372
+ end
373
+
374
+ if updated_gems.empty?
375
+ say "No new gems"
376
+ terminate_interaction 0
377
+ end
378
+
379
+ specs = map_gems_to_specs updated_gems
380
+ prerelease, released = specs.partition {|s| s.version.prerelease? }
381
+
382
+ files = build_marshal_gemspecs specs
383
+
384
+ Gem.time "Updated indexes" do
385
+ update_specs_index released, @dest_specs_index, @specs_index
386
+ update_specs_index released, @dest_latest_specs_index, @latest_specs_index
387
+ update_specs_index(prerelease,
388
+ @dest_prerelease_specs_index,
389
+ @prerelease_specs_index)
390
+ end
391
+
392
+ compress_indices
393
+
394
+ verbose = Gem.configuration.really_verbose
395
+
396
+ say "Updating production dir #{@dest_directory}" if verbose
397
+
398
+ files << @specs_index
399
+ files << "#{@specs_index}.gz"
400
+ files << @latest_specs_index
401
+ files << "#{@latest_specs_index}.gz"
402
+ files << @prerelease_specs_index
403
+ files << "#{@prerelease_specs_index}.gz"
404
+
405
+ files = files.map do |path|
406
+ path.sub(%r{^#{Regexp.escape @directory}/?}, "") # HACK?
407
+ end
408
+
409
+ files.each do |file|
410
+ src_name = File.join @directory, file
411
+ dst_name = File.join @dest_directory, file # REFACTOR: duped above
412
+
413
+ FileUtils.mv src_name, dst_name, :verbose => verbose,
414
+ :force => true
415
+
416
+ File.utime newest_mtime, newest_mtime, dst_name
417
+ end
418
+ ensure
419
+ FileUtils.rm_rf @directory
420
+ end
421
+
422
+ ##
423
+ # Combines specs in +index+ and +source+ then writes out a new copy to
424
+ # +dest+. For a latest index, does not ensure the new file is minimal.
425
+
426
+ def update_specs_index(index, source, dest)
427
+ specs_index = marshal_load Gem.read_binary(source)
428
+
429
+ index.each do |spec|
430
+ platform = spec.original_platform
431
+ platform = Gem::Platform::RUBY if platform.nil? || platform.empty?
432
+ specs_index << [spec.name, spec.version, platform]
433
+ end
434
+
435
+ specs_index = compact_specs specs_index.uniq.sort
436
+
437
+ File.open dest, "wb" do |io|
438
+ Marshal.dump specs_index, io
439
+ end
440
+ end
441
+
442
+ private
443
+
444
+ def marshal_load(string)
445
+ if Gem.respond_to?(:load_safe_marshal)
446
+ Gem.load_safe_marshal
447
+ Gem::SafeMarshal.safe_load string
448
+ else
449
+ Marshal.load string
450
+ end
451
+ end
452
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems/command_manager"
4
+ require_relative "rubygems/commands/generate_index_command"
5
+
6
+ Gem::CommandManager.instance.register_command :generate_index
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rubygems-generate_index"
5
+ s.version = "1.0.0"
6
+ s.authors = ["Jim Weirich", "Chad Fowler", "Eric Hodel", "Luis Lavena", "Aaron Patterson", "Samuel Giddins", "André Arko", "Evan Phoenix", "Hiroshi SHIBATA"]
7
+ s.email = ["", "", "drbrain@segment7.net", "luislavena@gmail.com", "aaron@tenderlovemaking.com", "segiddins@segiddins.me", "andre@arko.net", "evan@phx.io", "hsbt@ruby-lang.org"]
8
+
9
+ s.summary = "Generates the index files for a gem server directory"
10
+ s.homepage = "https://github.com/rubygems/rubygems-generate_index"
11
+
12
+ s.metadata["homepage_uri"] = s.homepage
13
+ s.metadata["source_code_uri"] = "https://github.com/rubygems/rubygems-generate_index"
14
+ s.metadata["changelog_uri"] = "https://github.com/rubygems/rubygems-generate_index"
15
+
16
+ s.licenses = ["Ruby", "MIT"]
17
+
18
+ s.files = File.read("Manifest.txt").split
19
+ s.bindir = "exe"
20
+ s.executables = s.files.grep(%r{\Aexe/}) {|f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ s.rdoc_options = ["--main", "README.md", "--title=RubyGems Generate Index Documentation"]
23
+ s.extra_rdoc_files = [
24
+ "LICENSE.txt",
25
+ "MIT.txt", "Manifest.txt", "README.md",
26
+ "CODE_OF_CONDUCT.md"
27
+ ]
28
+
29
+ s.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
30
+ s.required_rubygems_version = Gem::Requirement.new(">= 0")
31
+
32
+ s.add_dependency "compact_index", "~> 0.14.0"
33
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-generate_index
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jim Weirich
8
+ - Chad Fowler
9
+ - Eric Hodel
10
+ - Luis Lavena
11
+ - Aaron Patterson
12
+ - Samuel Giddins
13
+ - André Arko
14
+ - Evan Phoenix
15
+ - Hiroshi SHIBATA
16
+ autorequire:
17
+ bindir: exe
18
+ cert_chain: []
19
+ date: 2023-11-26 00:00:00.000000000 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: compact_index
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.14.0
28
+ type: :runtime
29
+ prerelease: false
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.14.0
35
+ description:
36
+ email:
37
+ - ''
38
+ - ''
39
+ - drbrain@segment7.net
40
+ - luislavena@gmail.com
41
+ - aaron@tenderlovemaking.com
42
+ - segiddins@segiddins.me
43
+ - andre@arko.net
44
+ - evan@phx.io
45
+ - hsbt@ruby-lang.org
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files:
49
+ - LICENSE.txt
50
+ - MIT.txt
51
+ - Manifest.txt
52
+ - README.md
53
+ - CODE_OF_CONDUCT.md
54
+ files:
55
+ - CODE_OF_CONDUCT.md
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE.txt
59
+ - MIT.txt
60
+ - Manifest.txt
61
+ - README.md
62
+ - lib/rubygems/commands/generate_index_command.rb
63
+ - lib/rubygems/indexer.rb
64
+ - lib/rubygems_plugin.rb
65
+ - rubygems-generate_index.gemspec
66
+ homepage: https://github.com/rubygems/rubygems-generate_index
67
+ licenses:
68
+ - Ruby
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/rubygems/rubygems-generate_index
72
+ source_code_uri: https://github.com/rubygems/rubygems-generate_index
73
+ changelog_uri: https://github.com/rubygems/rubygems-generate_index
74
+ post_install_message:
75
+ rdoc_options:
76
+ - "--main"
77
+ - README.md
78
+ - "--title=RubyGems Generate Index Documentation"
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.4.10
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Generates the index files for a gem server directory
96
+ test_files: []