bibliothecary 11.0.0 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed25de135032f95b602569a3ad5c1476f36be42599c0cd1b29032ecf7de8a47b
4
- data.tar.gz: 6401e84f7ce40b499b4da8274f775813fe1dcfa41843e7cbcc761293ff287c0d
3
+ metadata.gz: 78844f8813583a84df76e0ad0c72f9b8136b47d82aec8194e3e6766049ba721b
4
+ data.tar.gz: bb84e383f0bbded7361d7efbf4550f100d08281a294def960c95ddb1dca4f97c
5
5
  SHA512:
6
- metadata.gz: 8f0cedd4ebe9e4248ac0151b4073fa2671466cb4c4e04b2b1dc7e9a8daecbfca34126fa870cab97d3e95e231dcc8f1e01295a7c3b9b907bf64db1443dfa2ff7e
7
- data.tar.gz: c44115bb427765889d363e59685dfe3bd7fff63b27bca352f453b74da2ddf269d75a526453eb0bdfcfdb219d073cea5172fbfdc4731f38a1d86d8748a7c030b9
6
+ metadata.gz: f537a3fd368046789baf28c758b8f60d8832b7601f2ae78211a78d4d583ee7ddc4d4729f1ca3387e92958756586a6c1608099a4849db70c9e0a2a3b7405ff564
7
+ data.tar.gz: 8b9d7e93affe8df9d4e898bf4c128f912f16dd2e1c61ba7dfde0163690df91c173ed0a75c48717a702ddb45dfff2053527b5730c3d76738e7bf51b2344d09cff
data/CHANGELOG.md CHANGED
@@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ### Removed
15
15
 
16
+
17
+ ## [11.0.1] - 2024-12-20
18
+
19
+ ### Changed
20
+
21
+ - Alow retrieving maven versions from parent poms
22
+
16
23
  ## [11.0.0] - 2024-11-22
17
24
 
18
25
  ### Changed
@@ -294,48 +294,74 @@ module Bibliothecary
294
294
  parse_pom_manifest(file_contents, {}, options: options)
295
295
  end
296
296
 
297
- # parent_properties is used by Libraries:
298
- # https://github.com/librariesio/libraries.io/blob/e970925aade2596a03268b6e1be785eba8502c62/app/models/package_manager/maven.rb#L129
299
297
  def self.parse_pom_manifest(file_contents, parent_properties = {}, options: {}) # rubocop:disable Lint/UnusedMethodArgument
300
- manifest = Ox.parse file_contents
301
- xml = manifest.respond_to?("project") ? manifest.project : manifest
302
- [].tap do |deps|
303
- # <dependencyManagement> is a namespace to specify artifact configuration (e.g. version), but it doesn't
304
- # actually add dependencies to your project. Grab these and keep them for reference while parsing <dependencies>
305
- # Ref: https://maven.apache.org/pom.html#Dependency_Management
306
- # Ref: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#transitive-dependencies
307
- dependencyManagement = xml.locate("dependencyManagement/dependencies/dependency").map do |dep|
308
- {
309
- groupId: extract_pom_dep_info(xml, dep, "groupId", parent_properties),
310
- artifactId: extract_pom_dep_info(xml, dep, "artifactId", parent_properties),
311
- version: extract_pom_dep_info(xml, dep, "version", parent_properties),
312
- scope: extract_pom_dep_info(xml, dep, "scope", parent_properties),
313
- }
314
- end
315
- # <dependencies> is the namespace that will add dependencies to your project.
316
- xml.locate("dependencies/dependency").each do |dep|
317
- groupId = extract_pom_dep_info(xml, dep, "groupId", parent_properties)
318
- artifactId = extract_pom_dep_info(xml, dep, "artifactId", parent_properties)
319
- version = extract_pom_dep_info(xml, dep, "version", parent_properties)
320
- scope = extract_pom_dep_info(xml, dep, "scope", parent_properties)
321
-
322
- # Use any dep configurations from <dependencyManagement> as fallbacks
323
- if (depConfig = dependencyManagement.find { |d| d[:groupId] == groupId && d[:artifactId] == artifactId })
324
- version ||= depConfig[:version]
325
- scope ||= depConfig[:scope]
298
+ parse_pom_manifests([file_contents], parent_properties)
299
+ end
300
+
301
+ # @param files [Array<String>] Ordered array of strings containing the
302
+ # pom.xml bodies. The first element should be the child file.
303
+ # @param merged_properties [Hash]
304
+ def self.parse_pom_manifests(files, merged_properties)
305
+ documents = files.map do |file|
306
+ doc = Ox.parse(file)
307
+ doc.respond_to?("project") ? doc.project : doc
308
+ end
309
+
310
+ mergedDependencyManagements = {}
311
+ documents.each do |document|
312
+ document.locate("dependencyManagement/dependencies/dependency").each do |dep|
313
+ groupId = extract_pom_dep_info(document, dep, "groupId", merged_properties)
314
+ artifactId = extract_pom_dep_info(document, dep, "artifactId", merged_properties)
315
+ key = "#{groupId}:#{artifactId}"
316
+ mergedDependencyManagements[key] ||=
317
+ {
318
+ groupId: groupId,
319
+ artifactId: artifactId,
320
+ version: extract_pom_dep_info(document, dep, "version", merged_properties),
321
+ scope: extract_pom_dep_info(document, dep, "scope", merged_properties),
322
+ }
323
+ end
324
+ end
325
+
326
+ dep_hashes = {}
327
+ documents.each do |document|
328
+ document.locate("dependencies/dependency").each do |dep|
329
+ groupId = extract_pom_dep_info(document, dep, "groupId", merged_properties)
330
+ artifactId = extract_pom_dep_info(document, dep, "artifactId", merged_properties)
331
+ key = "#{groupId}:#{artifactId}"
332
+ unless dep_hashes.key?(key)
333
+ dep_hashes[key] = {
334
+ name: key,
335
+ requirement: nil,
336
+ type: nil,
337
+ optional: nil,
338
+ }
326
339
  end
340
+ dep_hash = dep_hashes[key]
341
+
342
+ dep_hash[:requirement] ||= extract_pom_dep_info(document, dep, "version", merged_properties)
343
+ dep_hash[:type] ||= extract_pom_dep_info(document, dep, "scope", merged_properties)
327
344
 
328
- dep_hash = {
329
- name: "#{groupId}:#{artifactId}",
330
- requirement: version,
331
- type: scope || "runtime",
332
- }
333
345
  # optional field is, itself, optional, and will be either "true" or "false"
334
- optional = extract_pom_dep_info(xml, dep, "optional", parent_properties)
335
- dep_hash[:optional] = optional == "true" unless optional.nil?
336
- deps.push(Dependency.new(**dep_hash))
346
+ optional = extract_pom_dep_info(document, dep, "optional", merged_properties)
347
+ if dep_hash[:optional].nil? && !optional.nil?
348
+ dep_hash[:optional] = optional == "true"
349
+ end
350
+ end
351
+ end
352
+
353
+ # Anything that wasn't covered by a dependency version, get from the
354
+ # dependencyManagements
355
+ dep_hashes.each do |key, dep_hash|
356
+ if (dependencyManagement = mergedDependencyManagements[key])
357
+ dep_hash[:requirement] ||= dependencyManagement[:version]
358
+ dep_hash[:type] ||= dependencyManagement[:scope]
337
359
  end
360
+
361
+ dep_hash[:type] ||= "runtime"
338
362
  end
363
+
364
+ dep_hashes.map{|key, dep_hash| Dependency.new(**dep_hash)}
339
365
  end
340
366
 
341
367
  def self.parse_gradle(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "11.0.0"
2
+ VERSION = "11.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.0.0
4
+ version: 11.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-25 00:00:00.000000000 Z
11
+ date: 2024-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb