bibliothecary 8.2.4 → 8.3.0

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: 631a4574650b4e69a1aec283acf4c0d1fb8338a1c4b767500b3b613c51357d7c
4
- data.tar.gz: 1f280d94aacce63d88302f767561d9e9f05e8d3381cd4a618cff5f04cc73511f
3
+ metadata.gz: c551b8910bf1a2244fddcde8a12ab29d88816b61237b10c992a53d049b2ad661
4
+ data.tar.gz: 55254294ffec08398bc658b117673ea2697d31ddc8ad9592d24225313b9803bb
5
5
  SHA512:
6
- metadata.gz: d5e68b0a9fe18880ce752f45e66ba68a31834ce35356e025f892eadb409c613c3d3d57b19fedb65362e0977393757c8a0d7fa521f5e8c3ebbe90dd1aa96b1f86
7
- data.tar.gz: 0ce08bdc863f9e82ed831d99b6132c043d6da012c297f81f5a0a801e847143b5a60a4545d2ce177a1deeaa7e62ed3a50010268b396d34c3f9794d04dccfbd365
6
+ metadata.gz: 52966b0a1fa300c8115f413ebdc991b3856bb77f8098e5b19ed996b1f9bf3c46b54cc41ed2998f0a157f3544c54296b99437596b2666e8345c6285208f0bd46c
7
+ data.tar.gz: e0c980d9065bfbc3c98100c0ebd92f7c0e16ab93f5e0a3f4a8178d8fb4a89ff032225737951486bf704d337d2bf9f2d18d60074e545ee6852297293c5e952b5b
@@ -22,6 +22,12 @@ module Bibliothecary
22
22
  first_matching_mapping_details(info)
23
23
  .fetch(:can_have_lockfile, true)
24
24
  end
25
+
26
+ def groupable?(info)
27
+ # More package managers are groupable than ungroupable, but the methods
28
+ # to get this information should be positive.
29
+ !first_matching_mapping_details(info).fetch(:ungroupable, false)
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -5,7 +5,6 @@ module Bibliothecary
5
5
  attr_accessor :carthage_parser_host
6
6
  attr_accessor :clojars_parser_host
7
7
  attr_accessor :mix_parser_host
8
- attr_accessor :gradle_parser_host
9
8
  attr_accessor :yarn_parser_host
10
9
  attr_accessor :conda_parser_host
11
10
  attr_accessor :swift_parser_host
@@ -17,7 +16,6 @@ module Bibliothecary
17
16
  @carthage_parser_host = 'https://carthage.libraries.io'
18
17
  @clojars_parser_host = 'https://clojars.libraries.io'
19
18
  @mix_parser_host = 'https://mix.libraries.io'
20
- @gradle_parser_host = 'https://gradle-parser.libraries.io'
21
19
  @yarn_parser_host = 'https://yarn-parser.libraries.io'
22
20
  @conda_parser_host = 'https://conda-parser.libraries.io'
23
21
  @swift_parser_host = 'http://swift.libraries.io'
@@ -49,5 +49,9 @@ module Bibliothecary
49
49
 
50
50
  @package_manager = nil
51
51
  end
52
+
53
+ def groupable?
54
+ @package_manager&.groupable?(self)
55
+ end
52
56
  end
53
57
  end
@@ -98,11 +98,13 @@ module Bibliothecary
98
98
  {
99
99
  match_filename('cyclonedx.json') => {
100
100
  kind: 'lockfile',
101
- parser: :parse_cyclonedx_json
101
+ parser: :parse_cyclonedx_json,
102
+ ungroupable: true
102
103
  },
103
104
  match_filename('cyclonedx.xml') => {
104
105
  kind: 'lockfile',
105
- parser: :parse_cyclonedx_xml
106
+ parser: :parse_cyclonedx_xml,
107
+ ungroupable: true
106
108
  }
107
109
  }
108
110
  end
@@ -10,6 +10,7 @@ module Bibliothecary
10
10
  {
11
11
  match_filename('dependencies.csv') => {
12
12
  kind: 'lockfile',
13
+ ungroupable: true,
13
14
  parser: :parse_dependencies_csv
14
15
  }
15
16
  }
@@ -13,16 +13,19 @@ module Bibliothecary
13
13
  GRADLE_DEP_REGEX = /(\+---|\\---){1}/
14
14
 
15
15
  # Builtin methods: https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
16
- GRADLE_KTS_DEPENDENCY_METHODS = %w(api compile compileOnlyApi implementation runtimeOnly testCompileOnly testImplementation testRuntimeOnly)
17
-
18
- # An intentionally overly-simplified regex to scrape deps from build.gradle.kts files.
19
- # To be truly useful bibliothecary would need a full Kotlin parser that speaks Gradle,
20
- # because the Kotlin DSL has many dynamic ways of declaring dependencies.
21
-
22
- GRADLE_KTS_VERSION_REGEX = /[\w.-]+/ # e.g. '1.2.3'
23
- GRADLE_KTS_INTERPOLATED_VERSION_REGEX = /\$\{.*\}/ # e.g. '${my-project-settings["version"]}'
24
- GRADLE_KTS_GAV_REGEX = /([\w.-]+)\:([\w.-]+)(?:\:(#{GRADLE_KTS_VERSION_REGEX}|#{GRADLE_KTS_INTERPOLATED_VERSION_REGEX}))?/
25
- GRADLE_KTS_SIMPLE_REGEX = /(#{GRADLE_KTS_DEPENDENCY_METHODS.join('|')})\s*\(\s*"#{GRADLE_KTS_GAV_REGEX}"\s*\)\s*$/m # e.g. "group:artifactId:1.2.3"
16
+ # Deprecated methods: https://docs.gradle.org/current/userguide/upgrading_version_6.html#sec:configuration_removal
17
+ GRADLE_DEPENDENCY_METHODS = %w(api compile compileClasspath compileOnly compileOnlyApi implementation runtime runtimeClasspath runtimeOnly testCompile testCompileOnly testImplementation testRuntime testRuntimeOnly)
18
+
19
+ # Intentionally overly-simplified regexes to scrape deps from build.gradle (Groovy) and build.gradle.kts (Kotlin) files.
20
+ # To be truly useful bibliothecary would need full Groovy / Kotlin parsers that speaks Gradle,
21
+ # because the Groovy and Kotlin DSLs have many dynamic ways of declaring dependencies.
22
+ GRADLE_VERSION_REGEX = /[\w.-]+/ # e.g. '1.2.3'
23
+ GRADLE_VAR_INTERPOLATION_REGEX = /\$\w+/ # e.g. '$myVersion'
24
+ GRADLE_CODE_INTERPOLATION_REGEX = /\$\{.*\}/ # e.g. '${my-project-settings["version"]}'
25
+ GRADLE_GAV_REGEX = /([\w.-]+)\:([\w.-]+)(?:\:(#{GRADLE_VERSION_REGEX}|#{GRADLE_VAR_INTERPOLATION_REGEX}|#{GRADLE_CODE_INTERPOLATION_REGEX}))?/ # e.g. "group:artifactId:1.2.3"
26
+ GRADLE_COMMENT_REGEX = /\/\/.*|\/\*.*\*\// # '// hello' or '/* hello */'
27
+ GRADLE_GROOVY_SIMPLE_REGEX = /(#{GRADLE_DEPENDENCY_METHODS.join('|')})\s+['"]#{GRADLE_GAV_REGEX}['"]\s*(?:#{GRADLE_COMMENT_REGEX})*$/m
28
+ GRADLE_KOTLIN_SIMPLE_REGEX = /(#{GRADLE_DEPENDENCY_METHODS.join('|')})\s*\(\s*"#{GRADLE_GAV_REGEX}"\s*\)\s*(?:#{GRADLE_COMMENT_REGEX})*$/m
26
29
 
27
30
  MAVEN_PROPERTY_REGEX = /\$\{(.+?)\}/
28
31
  MAX_DEPTH = 5
@@ -233,24 +236,21 @@ module Bibliothecary
233
236
  end
234
237
 
235
238
  def self.parse_gradle(file_contents, options: {})
236
- response = Typhoeus.post("#{Bibliothecary.configuration.gradle_parser_host}/parse", body: file_contents)
237
- raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.gradle_parser_host}/parse", response.response_code) unless response.success?
238
- json = JSON.parse(response.body)
239
- return [] unless json['dependencies']
240
- json['dependencies'].map do |dependency|
241
- name = gradle_dependency_name(dependency["group"], dependency["name"])
242
- next unless name =~ /[\w-]+\.[\w_-]+(\.[\w-])?\:[\w-]/
239
+ file_contents
240
+ .scan(GRADLE_GROOVY_SIMPLE_REGEX) # match 'implementation "group:artifactId:version"'
241
+ .reject { |(_type, group, artifactId, _version)| group.nil? || artifactId.nil? } # remove any matches with missing group/artifactId
242
+ .map { |(type, group, artifactId, version)|
243
243
  {
244
- name: name,
245
- requirement: dependency["version"],
246
- type: dependency["type"]
244
+ name: [group, artifactId].join(":"),
245
+ requirement: version || "*",
246
+ type: type
247
247
  }
248
- end.compact
248
+ }
249
249
  end
250
250
 
251
251
  def self.parse_gradle_kts(file_contents, options: {})
252
252
  file_contents
253
- .scan(GRADLE_KTS_SIMPLE_REGEX) # match 'implementation("group:artifactId:version")'
253
+ .scan(GRADLE_KOTLIN_SIMPLE_REGEX) # match 'implementation("group:artifactId:version")'
254
254
  .reject { |(_type, group, artifactId, _version)| group.nil? || artifactId.nil? } # remove any matches with missing group/artifactId
255
255
  .map { |(type, group, artifactId, version)|
256
256
  {
@@ -84,7 +84,7 @@ module Bibliothecary
84
84
  end
85
85
 
86
86
  def self.parse_poetry(file_contents, options: {})
87
- manifest = Tomlrb.parse(file_contents)['tool']['poetry']
87
+ manifest = Tomlrb.parse(file_contents).fetch('tool', {}).fetch('poetry', {})
88
88
  map_dependencies(manifest['dependencies'], 'runtime') + map_dependencies(manifest['dev-dependencies'], 'develop')
89
89
  end
90
90
 
@@ -12,7 +12,14 @@ module Bibliothecary
12
12
 
13
13
  file_infos_by_directory = file_infos.group_by { |info| File.dirname(info.relative_path) }
14
14
  file_infos_by_directory.values.each do |file_infos_for_path|
15
- file_infos_by_directory_by_package_manager = file_infos_for_path.group_by { |info| info.package_manager}
15
+ groupable, ungroupable = file_infos_for_path.partition(&:groupable?)
16
+
17
+ # add ungroupable ones as separate RFIs
18
+ ungroupable.each do |file_info|
19
+ returns.append(RelatedFilesInfo.new([file_info]))
20
+ end
21
+
22
+ file_infos_by_directory_by_package_manager = groupable.group_by { |info| info.package_manager}
16
23
 
17
24
  file_infos_by_directory_by_package_manager.values.each do |file_infos_in_directory_for_package_manager|
18
25
  returns.append(RelatedFilesInfo.new(file_infos_in_directory_for_package_manager))
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "8.2.4"
2
+ VERSION = "8.3.0"
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: 8.2.4
4
+ version: 8.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-06 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb