Module: Dependabot::Maven::NativeHelpers

Extended by:
T::Sig
Defined in:
lib/dependabot/maven/native_helpers.rb

Constant Summary collapse

DEPENDENCY_PLUGIN_VERSION =
T.let(version, T.nilable(String))

Class Method Summary collapse

Class Method Details

.handle_tool_error(output) ⇒ Object

Raises:

  • (DependabotError)


40
41
42
43
44
45
46
47
48
# File 'lib/dependabot/maven/native_helpers.rb', line 40

def self.handle_tool_error(output)
  if (match = output.match(
    %r{Could not transfer artifact (?<artifact>[^ ]+) from/to (?<repository_name>[^ ]+) \((?<repository_url>[^ ]+)\): status code: (?<status_code>[0-9]+)} # rubocop:disable Layout/LineLength
  )) && (match[:status_code] == "403" || match[:status_code] == "401")
    raise Dependabot::PrivateSourceAuthenticationFailure, match[:repository_url]
  end

  raise DependabotError, "mvn CLI failed with an unhandled error"
end

.run_mvn_dependency_tree_plugin(file_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dependabot/maven/native_helpers.rb', line 25

def self.run_mvn_dependency_tree_plugin(file_name)
  proxy_url = URI.parse(ENV.fetch("HTTPS_PROXY"))
  stdout, _, status = Open3.capture3(
    { "PROXY_HOST" => proxy_url.host },
    "mvn",
    "dependency:#{DEPENDENCY_PLUGIN_VERSION}:tree",
    "-DoutputFile=#{file_name}",
    "-DoutputType=json",
    "-e"
  )
  Dependabot.logger.info("mvn dependency:tree output: STDOUT:#{stdout}")
  handle_tool_error(stdout) unless status.success?
end