Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit dcc1631465db58b3a38fa9080ab3ec6f34bb3b46 @mainej mainej committed Dec 21, 2010
Showing with 108 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 Gemfile
  3. +14 −0 Gemfile.lock
  4. +2 −0 Rakefile
  5. +8 −0 bin/license_finder
  6. +53 −0 lib/license_finder.rb
  7. +3 −0 lib/license_finder/version.rb
  8. +21 −0 license_finder.gemspec
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in license_finder.gemspec
+gemspec
@@ -0,0 +1,14 @@
+PATH
+ remote: .
+ specs:
+ license_finder (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ license_finder!
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+require "rubygems"
+require "bundler"
+Bundler.setup
+
+require "license_finder"
+
+LicenseFinder.from_bundler.each { |lf| puts lf.to_s(ARGV.first == "--with-licenses") }
@@ -0,0 +1,53 @@
+module LicenseFinder
+ def self.from_bundler
+ require 'bundler'
+ Bundler.load.specs.map { |spec| Finder.new(spec) }.sort_by &:sort_order
+ end
+
+ class Finder
+ LICENSE_FILE_NAMES = '*{LICENSE,License,COPYING}*' # follows Dir.glob format
+
+ def initialize(spec)
+ @spec = spec
+ end
+
+ attr_reader :spec
+
+ def install_path
+ spec.full_gem_path
+ end
+
+ def dependency_name
+ spec.name
+ end
+
+ def dependency_version
+ spec.version.to_s
+ end
+
+ def license_files
+ Dir.glob(File.join(install_path, '**', LICENSE_FILE_NAMES))
+ end
+
+ def to_s(include_license_text = true)
+ result = ''
+ result << "#{dependency_name} #{dependency_version}\n"
+ result << "\t(installed at #{install_path})\n"
+ license_files.each do |license_file|
+ result << "\t#{license_file}\n"
+ result << "#{license_text(license_file)}\n\n" if include_license_text
+ end
+ result
+ end
+
+ def sort_order
+ dependency_name.downcase
+ end
+
+ private
+
+ def license_text(license_file)
+ File.read(license_file)
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module LicenseFinder
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "license_finder/version"
+
+Gem::Specification.new do |s|
+ s.name = "license_finder"
+ s.version = LicenseFinder::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Jacob Maine"]
+ s.email = ["jacob.maine@gmail.com"]
+ # s.homepage = "http://rubygems.org/gems/license_finder"
+ s.summary = %q{License finding heaven.}
+ s.description = %q{Find and display licenses of a project's gem dependencies.}
+
+ s.rubyforge_project = "license_finder"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit dcc1631

Please sign in to comment.