-
Notifications
You must be signed in to change notification settings - Fork 339
/
maven.rb
65 lines (54 loc) · 2.13 KB
/
maven.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
require 'xmlsimple'
require 'license_finder/package_utils/maven_dependency_finder'
module LicenseFinder
class Maven < PackageManager
def initialize(options = {})
super
@ignored_groups = options[:ignored_groups]
@include_groups = options[:maven_include_groups]
@maven_options = options[:maven_options]
end
def current_packages
command = "#{package_management_command} org.codehaus.mojo:license-maven-plugin:download-licenses"
command += " -Dlicense.excludedScopes=#{@ignored_groups.to_a.join(',')}" if @ignored_groups && !@ignored_groups.empty?
command += " #{@maven_options}" unless @maven_options.nil?
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
dependencies = MavenDependencyFinder.new(project_path).dependencies
packages = dependencies.flat_map do |xml|
options = {
'GroupTags' => { 'licenses' => 'license', 'dependencies' => 'dependency' },
'ForceArray' => %w[license dependency]
}
contents = XmlSimple.xml_in(xml, options)['dependencies']
contents.map do |dep|
MavenPackage.new(dep, logger: logger, include_groups: @include_groups)
end
end
packages.uniq
end
def package_management_command
wrapper = if Platform.windows?
'mvnw.cmd'
else
'./mvnw'
end
maven = 'mvn'
File.exist?(File.join(project_path, wrapper)) ? wrapper : maven
end
def possible_package_paths
[project_path.join('pom.xml')]
end
def project_root?
active? && root_module?
end
private
def root_module?
command = "#{package_management_command} help:evaluate -Dexpression=project.parent -q -DforceStdout"
stdout, _stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
raise "Command '#{command}' failed to execute in #{project_path}: #{stdout}" unless status.success?
stdout.include?('null object or invalid expression')
end
end
end