-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #517 from 3scale/xml-report
Xml Report
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<licenseSummary> | ||
<dependencies> | ||
<% sorted_dependencies.each do |dependency| -%> | ||
<dependency> | ||
<packageName><%= dependency.name %></packageName> | ||
<version><%= dependency.version %></version> | ||
<licenses> | ||
<% dependency.licenses.each do |license| -%> | ||
<license> | ||
<name><%= license.name %></name> | ||
<url><%= license.url %></url> | ||
</license> | ||
<% end -%> | ||
</licenses> | ||
</dependency> | ||
<% end -%> | ||
</dependencies> | ||
</licenseSummary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'license_finder/reports/erb_report' | ||
|
||
module LicenseFinder | ||
class XmlReport < ErbReport | ||
ROOT_PATH = Pathname.new(__FILE__).dirname | ||
TEMPLATE_PATH = ROOT_PATH.join('templates') | ||
|
||
def to_s(filename = TEMPLATE_PATH.join("#{template_name}.erb")) | ||
template = ERB.new(filename.read, nil, '-') | ||
template.result(binding) | ||
end | ||
|
||
private | ||
|
||
def template_name | ||
'xml_report' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
module LicenseFinder | ||
describe XmlReport do | ||
let(:dep1) do | ||
result = Package.new('dep_1', '1.0') | ||
result.decide_on_license(License.find_by_name('MIT')) | ||
result | ||
end | ||
|
||
let(:dep2) do | ||
result = Package.new('dep_2', '2.0') | ||
result.decide_on_license(License.find_by_name('BSD')) | ||
result | ||
end | ||
|
||
let(:expected_report) do | ||
<<-XML | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<licenseSummary> | ||
<dependencies> | ||
<dependency> | ||
<packageName>dep_1</packageName> | ||
<version>1.0</version> | ||
<licenses> | ||
<license> | ||
<name>MIT</name> | ||
<url>http://opensource.org/licenses/mit-license</url> | ||
</license> | ||
</licenses> | ||
</dependency> | ||
<dependency> | ||
<packageName>dep_2</packageName> | ||
<version>2.0</version> | ||
<licenses> | ||
<license> | ||
<name>BSD</name> | ||
<url>http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29</url> | ||
</license> | ||
</licenses> | ||
</dependency> | ||
</dependencies> | ||
</licenseSummary> | ||
XML | ||
end | ||
|
||
subject { described_class.new([dep1, dep2], {}) } | ||
|
||
it 'should generate the correct xml report with name, version and license' do | ||
expect(subject.to_s.gsub(/\s/, '')).to eq(expected_report.gsub(/\s/, '')) | ||
end | ||
end | ||
end |