Class: Licensed::Reporters::NoticesReporter

Inherits:
Reporter
  • Object
show all
Defined in:
lib/licensed/reporters/notices_reporter.rb

Constant Summary collapse

TEXT_SEPARATOR =
"\n\n#{("-" * 5)}\n\n".freeze
LICENSE_SEPARATOR =
"\n#{("*" * 5)}\n".freeze

Instance Method Summary collapse

Methods inherited from Reporter

#initialize, #report_run

Constructor Details

This class inherits a constructor from Licensed::Reporters::Reporter

Instance Method Details

#notices(report) ⇒ Object

Returns notices information for a dependency report



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/licensed/reporters/notices_reporter.rb', line 73

def notices(report)
  return unless report.target.is_a?(Licensed::Dependency)

  cached_record = report["cached_record"]
  return unless cached_record

  texts = cached_record.licenses.map(&:text)
  cached_record.notices.each do |notice|
    case notice
    when Hash
      texts << notice["text"]
    when String
      texts << notice
    else
      shell.warn "* unable to parse notices for #{report.target.name}"
    end
  end

  <<~NOTICE
    #{cached_record["name"]}@#{cached_record["version"]}

    #{texts.map(&:strip).reject(&:empty?).compact.join(TEXT_SEPARATOR)}
  NOTICE
end

#report_app(app) ⇒ Object

Reports on an application configuration in a notices command run

app - An application configuration

Returns the result of the yielded method Note - must be called from inside the ‘report_run` scope



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/licensed/reporters/notices_reporter.rb', line 15

def report_app(app)
  super do |report|
    filename = app["shared_cache"] ? "NOTICE.#{app["name"]}" : "NOTICE"
    path = app.cache_path.join(filename)
    shell.info "Writing notices for #{app["name"]} to #{path}"

    result = yield report

    File.open(path, "w") do |file|
      file << "THIRD PARTY NOTICES\n"
      file << LICENSE_SEPARATOR
      file << report.all_reports
                    .map { |r| notices(r) }
                    .compact
                    .join(LICENSE_SEPARATOR)
    end

    result
  end
end

#report_dependency(dependency) ⇒ Object

Reports on a dependency in a notices command run.

dependency - An application dependency

Returns the result of the yielded method Note - must be called from inside the ‘report_run` scope



62
63
64
65
66
67
68
69
70
# File 'lib/licensed/reporters/notices_reporter.rb', line 62

def report_dependency(dependency)
  super do |report|
    result = yield report
    report.warnings.each do |warning|
      shell.warn "* #{report.name}: #{warning}"
    end
    result
  end
end

#report_source(source) ⇒ Object

Reports on a dependency source enumerator in a notices command run. Shows warnings encountered during the run.

source - A dependency source enumerator

Returns the result of the yielded method Note - must be called from inside the ‘report_run` scope



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/licensed/reporters/notices_reporter.rb', line 44

def report_source(source)
  super do |report|
    result = yield report

    report.warnings.each do |warning|
      shell.warn "* #{report.name}: #{warning}"
    end

    result
  end
end