Permalink
Browse files

link license names to license urls in html report

  • Loading branch information...
1 parent 24cf148 commit 12597db9ec0b3049d1bccaa79d49578eda1159bb Matthew Kane Parker committed Sep 13, 2012
@@ -40,6 +40,7 @@ Feature: rake license:action_items
And I should see the "mit_licensed_gem" in the html with the following details:
| license | summary | description | name |
| MIT | mit is cool | seriously | mit_licensed_gem v0.0.1 |
+ And the text "MIT" should link to "http://opensource.org/licenses/mit-license"
And I should see the "gpl_licensed_gem" in the html with the following details:
| license | summary | description | name |
| GPL | gpl :-( | seriously | gpl_licensed_gem v0.0.2 |
@@ -49,7 +49,7 @@ Feature: rake license:generate_dependencies
When I run "rake license:generate_dependencies"
Then license finder should generate a file "dependencies.txt" containing:
"""
- mit_gem 0.0.0, MIT, production
+ mit_gem 0.0.0, MIT, http://opensource.org/licenses/mit-license, production
"""
Scenario: I have specified multiple groups for my gem
@@ -58,5 +58,5 @@ Feature: rake license:generate_dependencies
When I run "rake license:generate_dependencies"
Then license finder should generate a file "dependencies.txt" containing:
"""
- mit_gem 0.0.0, MIT, production, demo, staging
+ mit_gem 0.0.0, MIT, http://opensource.org/licenses/mit-license, production, demo, staging
"""
@@ -9,7 +9,7 @@ Feature: Catch Regressions!
And I run "<command>"
Then license finder should generate a file "dependencies.txt" containing:
"""
- descriptive_gem 0.0.0, MIT, summary, description, default
+ descriptive_gem 0.0.0, MIT, http://opensource.org/licenses/mit-license, summary, description, default
"""
Examples:
@@ -274,3 +274,8 @@ def root_path
end
end
end
+
+When /^the text "([^"]*)" should link to "([^"]*)"$/ do |text, link|
+ html = Capybara.string File.read(@user.dependencies_html_path)
+ html.find(:xpath, "//a[@href='#{link}']").text.should == text
+end
View
@@ -55,3 +55,4 @@ def self.load_rake_tasks
require 'license_finder/dependency'
require 'license_finder/dependency_list'
require 'license_finder/cli'
+require 'license_finder/license_url'
@@ -21,7 +21,6 @@ def initialize(attributes = {})
@version = attributes['version']
@license = attributes['license']
@approved = attributes['approved'] || LicenseFinder.config.whitelist.include?(attributes['license'])
- @license_url = attributes['license_url'] || ''
@notes = attributes['notes'] || ''
@license_files = attributes['license_files'] || []
@readme_files = attributes['readme_files'] || []
@@ -30,6 +29,10 @@ def initialize(attributes = {})
@description = attributes['description']
end
+ def license_url
+ LicenseFinder::LicenseUrl.find_by_name license
+ end
+
def merge(other)
raise "Cannot merge dependencies with different names. Expected #{name}, was #{other.name}." unless other.name == name
@@ -93,7 +96,7 @@ def to_yaml
def to_html
css_class = approved ? "approved" : "unapproved"
- template = ERB.new <<-HTML
+ template = ERB.new <<-ERB
<div id="<%=name%>" class="<%=css_class%>">
<h2><%=name%> v<%=version%></h2>
<table class="table table-striped table-bordered">
@@ -108,13 +111,19 @@ def to_html
<tr>
<td><%= summary %></td>
<td><%= description %></td>
- <td><%= license %></td>
+ <td>
+ <% if license_url && !license_url.empty? %>
+ <a href="<%= license_url %>"><%= license %></a>
+ <% else %>
+ <%= license %>
+ <% end %>
+ </td>
</td>
</tr>
</tbody>
</table>
</div>
- HTML
+ ERB
template.result binding
end
@@ -132,12 +141,25 @@ def to_s
<%= readme_files.join("\n ") %>
<% end %>
<% end%>
-TEMPLATE
+ TEMPLATE
- attributes = ["#{name} #{version}".strip, license, license_url, summary, description, bundler_groups].flatten.compact.reject {|a| a == ""}
+ attributes = ["#{name} #{version}".strip, license, license_url, summary, description, bundler_groups].flatten.compact.reject { |a| a == "" }
template.result(binding).gsub(/(^|\n)\s*(\n|$)/, '\1')
end
+
+ private
+
+ def constantize(string)
+ names = string.split('::')
+ names.shift if names.empty? || names.first.empty?
+
+ constant = Object
+ names.each do |name|
+ constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
+ end
+ constant
+ end
end
end
@@ -23,10 +23,20 @@ def normalized(text)
class Base
class << self
+ attr_accessor :license_url, :alternative_names
+
def inherited(descendant)
LicenseFinder::License.all << descendant
end
+ def names
+ [demodulized_name] + self.alternative_names
+ end
+
+ def alternative_names
+ @alternative_names ||= []
+ end
+
def demodulized_name
name.gsub(/^.*::/, '')
end
@@ -1,4 +1,7 @@
class LicenseFinder::License::Apache < LicenseFinder::License::Base
+ self.alternative_names = ["Apache 2.0", "Apache2"]
+ self.license_url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
+
def self.pretty_name
'Apache 2.0'
end
@@ -1,2 +1,4 @@
class LicenseFinder::License::BSD < LicenseFinder::License::Base
+ self.alternative_names = ["BSD4", "bsd-old", "4-clause BSD"]
+ self.license_url = "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29"
end
@@ -1,2 +1,4 @@
class LicenseFinder::License::GPLv2 < LicenseFinder::License::Base
+ self.license_url = 'http://www.gnu.org/licenses/gpl-2.0.txt'
+ self.alternative_names = ["GPL V2", "gpl-v2", "GNU GENERAL PUBLIC LICENSE Version 2"]
end
@@ -1,2 +1,3 @@
class LicenseFinder::License::ISC < LicenseFinder::License::Base
+ self.license_url = "http://en.wikipedia.org/wiki/ISC_license"
end
@@ -1,2 +1,3 @@
class LicenseFinder::License::LGPL < LicenseFinder::License::Base
+ self.license_url = "http://www.gnu.org/licenses/lgpl.txt"
end
@@ -1,7 +1,10 @@
class LicenseFinder::License::MIT < LicenseFinder::License::Base
+ self.license_url = "http://opensource.org/licenses/mit-license"
+ self.alternative_names = ["Expat"]
+
HEADER_REGEX = /The MIT Licen[sc]e/
ONE_LINER_REGEX = /is released under the MIT licen[sc]e/
- URL_REGEX = %r{MIT Licen[sc]e.*http://www.opensource.org/licenses/mit-license}
+ URL_REGEX = %r{MIT Licen[sc]e.*http://(?:www.)?opensource.org/licenses/mit-license}
def matches?
super || matches_url? || matches_header?
@@ -1,4 +1,7 @@
class LicenseFinder::License::NewBSD < LicenseFinder::License::Base
+ self.license_url = "http://opensource.org/licenses/BSD-3-Clause"
+ self.alternative_names = ["Modified BSD", "BSD3", "BSD-3", "3-clause BSD"]
+
def self.pretty_name
'New BSD'
end
@@ -1,11 +1,11 @@
class LicenseFinder::License::Ruby < LicenseFinder::License::Base
- URL_REGEX = %r{http://www.ruby-lang.org/en/LICENSE.txt}
+ self.license_url = "http://www.ruby-lang.org/en/LICENSE.txt"
def self.pretty_name
'ruby'
end
def matches?
- super || !!(text =~ URL_REGEX)
+ super || !!(text =~ /#{self.class.license_url}/)
end
end
@@ -1,4 +1,7 @@
class LicenseFinder::License::SimplifiedBSD < LicenseFinder::License::Base
+ self.license_url = "http://opensource.org/licenses/bsd-license"
+ self.alternative_names = ["Simplified BSD", "FreeBSD", "2-clause BSD"]
+
def self.pretty_name
'Simplified BSD'
end
@@ -0,0 +1,10 @@
+module LicenseFinder::LicenseUrl
+ extend self
+
+ def find_by_name(name)
+ return unless name.respond_to?(:downcase)
+
+ license = LicenseFinder::License.all.detect {|l| l.names.map(&:downcase).include? name.downcase }
+ license.license_url if license
+ end
+end
@@ -74,7 +74,7 @@ def build_gemspec(name, version)
'license' => 'MIT',
'approved' => false,
'source' => nil,
- 'license_url' => '',
+ 'license_url' => LicenseFinder::License::MIT.license_url,
'notes' => '',
'license_files' => nil,
'readme_files' => nil
@@ -85,7 +85,7 @@ def build_gemspec(name, version)
'license' => 'MIT',
'approved' => false,
'source' => 'bundle',
- 'license_url' => '',
+ 'license_url' => LicenseFinder::License::MIT.license_url,
'notes' => '',
'license_files' => nil,
'readme_files' => nil
@@ -5,9 +5,8 @@
{
'name' => "spec_name",
'version' => "2.1.3",
- 'license' => "GPL",
+ 'license' => "GPLv2",
'approved' => false,
- 'license_url' => 'http://www.apache.org/licenses/LICENSE-2.0.html',
'notes' => 'some notes',
'license_files' => [{'path' => '/Users/pivotal/foo/lic1'}, {'path' => '/Users/pivotal/bar/lic2'}],
'readme_files' => [{'path' => '/Users/pivotal/foo/Readme1'}, {'path' => '/Users/pivotal/bar/Readme2'}],
@@ -42,9 +41,8 @@
its(:name) { should == 'spec_name' }
its(:version) { should == '2.1.3' }
- its(:license) { should == 'GPL' }
+ its(:license) { should == 'GPLv2' }
its(:approved) { should == false }
- its(:license_url) { should == "http://www.apache.org/licenses/LICENSE-2.0.html" }
its(:notes) { should == "some notes" }
its(:license_files) { should == %w(/Users/pivotal/foo/lic1 /Users/pivotal/bar/lic2) }
its(:readme_files) { should == %w(/Users/pivotal/foo/Readme1 /Users/pivotal/bar/Readme2) }
@@ -55,10 +53,10 @@
should == {
'name' => 'spec_name',
'version' => '2.1.3',
- 'license' => 'GPL',
+ 'license' => 'GPLv2',
'approved' => false,
'source' => 'bundle',
- 'license_url' => 'http://www.apache.org/licenses/LICENSE-2.0.html',
+ 'license_url' => LicenseFinder::License::GPLv2.license_url,
'notes' => 'some notes',
'license_files' => [
{'path' => '/Users/pivotal/foo/lic1'},
@@ -77,6 +75,24 @@
end
end
+ describe '#license_url' do
+ context "class exists for license type" do
+ it "should return the license url configured in the class" do
+ LicenseFinder::Dependency.new('license' => "GPLv2").license_url.should == LicenseFinder::License::GPLv2.license_url
+ end
+
+ it "should handle differences in case" do
+ LicenseFinder::Dependency.new('license' => "gplv2").license_url.should == LicenseFinder::License::GPLv2.license_url
+ end
+ end
+
+ context "class does not exist for license type" do
+ it "should return nil" do
+ LicenseFinder::Dependency.new('license' => "FakeLicense").license_url.should be_nil
+ end
+ end
+ end
+
describe '#to_s' do
let(:gem) do
LicenseFinder::Dependency.new(
@@ -100,7 +116,7 @@
subject { gem.to_s.strip }
it 'should generate text with all the gem attributes' do
- should == "test_gem 1.0, MIT, summary foo, description bar"
+ should == "test_gem 1.0, MIT, http://opensource.org/licenses/mit-license, summary foo, description bar"
end
context "when license is 'other'" do
@@ -121,19 +137,11 @@
end
end
- context "when the gem has a license url" do
- let(:license_url) { "www.foobar.com"}
-
- it "should include the license_url" do
- should == "test_gem 1.0, MIT, www.foobar.com, summary foo, description bar"
- end
- end
-
context "when the gem has any bundler groups" do
let(:bundler_groups) { %w(staging production) }
it "should include the bundler groups" do
- should == "test_gem 1.0, MIT, summary foo, description bar, staging, production"
+ should == "test_gem 1.0, MIT, http://opensource.org/licenses/mit-license, summary foo, description bar, staging, production"
end
end
end
@@ -173,7 +181,6 @@
'name' => 'foo',
'license' => 'MIT',
'version' => '0.0.1',
- 'license_url' => 'http://www.example.com/license1.htm',
'license_files' => "old license files",
'readme_files' => "old readme files",
)
@@ -184,7 +191,6 @@
'name' => 'foo',
'license' => 'MIT',
'version' => '0.0.2',
- 'license_url' => 'http://www.example.com/license2.htm',
'license_files' => "new license files",
'readme_files' => "new readme files",
'summary' => 'foo summary',
@@ -201,11 +207,10 @@
}.to raise_error
end
- it 'should return the new version, license url, license files, readme files, and source' do
+ it 'should return the new version, license files, readme files, and source' do
merged = subject.merge(new_dep)
merged.version.should == '0.0.2'
- merged.license_url.should == 'http://www.example.com/license2.htm'
merged.license_files.should == new_dep.license_files
merged.readme_files.should == new_dep.readme_files
merged.source.should == new_dep.source
@@ -7,7 +7,7 @@
describe "#matches?" do
it "should return true if the text contains the MIT url" do
- subject.text = "MIT License is awesome http://www.opensource.org/licenses/mit-license"
+ subject.text = "MIT License is awesome http://opensource.org/licenses/mit-license"
should be_matches
subject.text = "MIT Licence is awesome http://www.opensource.org/licenses/mit-license"
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe LicenseFinder::License::Base do
+ describe ".names" do
+ subject do
+ Class.new(LicenseFinder::License::Base) do
+ def self.demodulized_name; "FooLicense"; end
+ self.alternative_names = ["foo license"]
+ end.names
+ end
+
+ it { should =~ ["FooLicense", "foo license"] }
+ end
+end
Oops, something went wrong.

0 comments on commit 12597db

Please sign in to comment.