Class: LicenseFinder::Maven

Inherits:
PackageManager show all
Defined in:
lib/license_finder/package_managers/maven.rb

Instance Method Summary collapse

Methods inherited from PackageManager

#active?, #command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #prepare, #prepare_command, takes_priority_over

Constructor Details

#initialize(options = {}) ⇒ Maven

Returns a new instance of Maven.



8
9
10
11
12
13
# File 'lib/license_finder/package_managers/maven.rb', line 8

def initialize(options = {})
  super
  @ignored_groups = options[:ignored_groups]
  @include_groups = options[:maven_include_groups]
  @maven_options = options[:maven_options]
end

Instance Method Details

#current_packagesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/license_finder/package_managers/maven.rb', line 15

def current_packages
  # Generate a file "target/generated-resources/licenses.xml" that contains a list of
  # dependencies including their groupId, artifactId, version and license (name, file, url).
  # The license file downloaded this way, however, is a generic one without author information.
  # This file also does not contain further information about the package like its name,
  # description or website URL.
  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, maven_repository_path).dependencies
  packages = dependencies.map do |dep|
    MavenPackage.new(dep, logger: logger, include_groups: @include_groups)
  end
  packages.uniq
end

#package_management_commandObject



34
35
36
37
38
39
# File 'lib/license_finder/package_managers/maven.rb', line 34

def package_management_command
  wrapper = File.join(project_path, Platform.windows? ? 'mvnw.cmd' : 'mvnw')
  maven = 'mvn'

  File.exist?(wrapper) ? wrapper : maven
end

#possible_package_pathsObject



41
42
43
# File 'lib/license_finder/package_managers/maven.rb', line 41

def possible_package_paths
  [project_path.join('pom.xml')]
end

#project_root?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/license_finder/package_managers/maven.rb', line 45

def project_root?
  active? && root_module?
end