license_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-01-11
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,25 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ features/development.feature
6
+ features/step_definitions/common_steps.rb
7
+ features/support/common.rb
8
+ features/support/env.rb
9
+ features/support/matchers.rb
10
+ lib/license_generator.rb
11
+ license_generator.gemspec
12
+ rubygems_generators/license/USAGE
13
+ rubygems_generators/license/license_generator.rb
14
+ rubygems_generators/license/templates/agpl.txt
15
+ rubygems_generators/license/templates/copyright.erb
16
+ rubygems_generators/license/templates/gpl.txt
17
+ script/console
18
+ script/destroy
19
+ script/generate
20
+ spec/license_generator_spec.rb
21
+ spec/spec.opts
22
+ spec/spec_helper.rb
23
+ tasks/rspec.rake
24
+ test/test_generator_helper.rb
25
+ test/test_license_generator.rb
@@ -0,0 +1,52 @@
1
+ = license_generator
2
+
3
+ * http://projects.tryphon.eu/license_generator
4
+
5
+ == DESCRIPTION:
6
+
7
+ Choose the license and generate required documents
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * install licenses
12
+ * support GPL and AGPL (for the moment)
13
+ * TODO : rake tasks to manage file headers
14
+
15
+ == SYNOPSIS:
16
+
17
+ ./script/generate license --author="John Doe" --years="2007,2009" --license=gpl
18
+ create COPYING
19
+ create COPYRIGHT
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * rubigen
24
+
25
+ == INSTALL:
26
+
27
+ * sudo gem install license_generator
28
+
29
+ == LICENSE:
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2010 Alban Peignier
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/license_generator'
6
+
7
+ Hoe.plugin :newgem
8
+ Hoe.plugin :cucumberfeatures
9
+
10
+ # Generate all the Rake tasks
11
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
12
+ $hoe = Hoe.spec 'license_generator' do
13
+ self.developer 'Alban Peignier', 'alban@tryphon.eu'
14
+ self.rubyforge_name = self.name
15
+ self.extra_deps = [['rubigen','>= 1.5.2']]
16
+ end
17
+
18
+ require 'newgem/tasks'
19
+ Dir['tasks/**/*.rake'].each { |t| load t }
20
+
21
+ # TODO - want other tests/tasks run by default? Add them to the list
22
+ # remove_task :default
23
+ task :default => [:spec, :features]
@@ -0,0 +1,13 @@
1
+ Feature: Development processes of newgem itself (rake tasks)
2
+
3
+ As a Newgem maintainer or contributor
4
+ I want rake tasks to maintain and release the gem
5
+ So that I can spend time on the tests and code, and not excessive time on maintenance processes
6
+
7
+ Scenario: Generate RubyGem
8
+ Given this project is active project folder
9
+ And "pkg" folder is deleted
10
+ When I invoke task "rake gem"
11
+ Then folder "pkg" is created
12
+ And file with name matching "pkg/*.gem" is created else you should run "rake manifest" to fix this
13
+ And gem spec key "rdoc_options" contains /--mainREADME.rdoc/
@@ -0,0 +1,163 @@
1
+ Given /^this project is active project folder/ do
2
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
3
+ end
4
+
5
+ Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
6
+ ENV[env_var] = value
7
+ end
8
+
9
+ Given /"(.*)" folder is deleted/ do |folder|
10
+ in_project_folder { FileUtils.rm_rf folder }
11
+ end
12
+
13
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
14
+ @stdout = StringIO.new
15
+ in_project_folder do
16
+ if Object.const_defined?("APP_ROOT")
17
+ APP_ROOT.replace(FileUtils.pwd)
18
+ else
19
+ APP_ROOT = FileUtils.pwd
20
+ end
21
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
22
+ end
23
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
24
+ @stdout.rewind
25
+ f << @stdout.read
26
+ end
27
+ end
28
+
29
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
30
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
31
+ in_project_folder do
32
+ system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
33
+ end
34
+ end
35
+
36
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
37
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
38
+ in_project_folder do
39
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
40
+ end
41
+ end
42
+
43
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
44
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
45
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
46
+ in_project_folder do
47
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
48
+ end
49
+ end
50
+
51
+ When /^I invoke task "rake (.*)"/ do |task|
52
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
53
+ in_project_folder do
54
+ system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
55
+ end
56
+ end
57
+
58
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
59
+ in_project_folder do
60
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
61
+ end
62
+ end
63
+
64
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
65
+ in_project_folder do
66
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
67
+ end
68
+ end
69
+
70
+ Then /^file with name matching "(.*)" is created/ do |pattern|
71
+ in_project_folder do
72
+ Dir[pattern].should_not be_empty
73
+ end
74
+ end
75
+
76
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
77
+ in_project_folder do
78
+ actual_output = File.read(file)
79
+ (does == 'does') ?
80
+ actual_output.should(match(/#{regex}/)) :
81
+ actual_output.should_not(match(/#{regex}/))
82
+ end
83
+ end
84
+
85
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
86
+ File.exists?(gem_file).should be_true
87
+ File.exists?(project_file).should be_true
88
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
89
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
90
+ project_file_contents.should == gem_file_contents
91
+ end
92
+
93
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
94
+ actual_output = File.read(@stdout)
95
+ does_invoke == "does" ?
96
+ actual_output.should(match(/dependency\s+#{generator}/)) :
97
+ actual_output.should_not(match(/dependency\s+#{generator}/))
98
+ end
99
+
100
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
101
+ actual_output = File.read(@stdout)
102
+ actual_output.should match(/#{opt1}/)
103
+ actual_output.should match(/#{opt2}/)
104
+ end
105
+
106
+ Then /^I should see$/ do |text|
107
+ actual_output = File.read(@stdout)
108
+ actual_output.should contain(text)
109
+ end
110
+
111
+ Then /^I should not see$/ do |text|
112
+ actual_output = File.read(@stdout)
113
+ actual_output.should_not contain(text)
114
+ end
115
+
116
+ Then /^I should see exactly$/ do |text|
117
+ actual_output = File.read(@stdout)
118
+ actual_output.should == text
119
+ end
120
+
121
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
122
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
123
+ actual_output = File.read(@stdout)
124
+ actual_output.should match(expected)
125
+ end
126
+
127
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
128
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
129
+ actual_output = File.read(@stdout)
130
+ actual_output.should match(expected)
131
+ end
132
+
133
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
134
+ in_project_folder do
135
+ yaml = eval yaml
136
+ YAML.load(File.read(file)).should == yaml
137
+ end
138
+ end
139
+
140
+ Then /^Rakefile can display tasks successfully/ do
141
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
142
+ in_project_folder do
143
+ system "rake -T > #{@stdout} 2> #{@stdout}"
144
+ end
145
+ actual_output = File.read(@stdout)
146
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
147
+ end
148
+
149
+ Then /^task "rake (.*)" is executed successfully/ do |task|
150
+ @stdout.should_not be_nil
151
+ actual_output = File.read(@stdout)
152
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
153
+ actual_output.should_not match(/Error/i)
154
+ end
155
+
156
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
157
+ in_project_folder do
158
+ gem_file = Dir["pkg/*.gem"].first
159
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
160
+ spec_value = gem_spec.send(key.to_sym)
161
+ spec_value.to_s.should match(/#{regex}/)
162
+ end
163
+ end
@@ -0,0 +1,29 @@
1
+ module CommonHelpers
2
+ def in_tmp_folder(&block)
3
+ FileUtils.chdir(@tmp_root, &block)
4
+ end
5
+
6
+ def in_project_folder(&block)
7
+ project_folder = @active_project_folder || @tmp_root
8
+ FileUtils.chdir(project_folder, &block)
9
+ end
10
+
11
+ def in_home_folder(&block)
12
+ FileUtils.chdir(@home_path, &block)
13
+ end
14
+
15
+ def force_local_lib_override(project_name = @project_name)
16
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
17
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
18
+ f << "$:.unshift('#{@lib_path}')\n"
19
+ f << rakefile
20
+ end
21
+ end
22
+
23
+ def setup_active_project_folder project_name
24
+ @active_project_folder = File.join(@tmp_root, project_name)
25
+ @project_name = project_name
26
+ end
27
+ end
28
+
29
+ World(CommonHelpers)
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../../lib/license_generator"
2
+
3
+ gem 'cucumber'
4
+ require 'cucumber'
5
+ gem 'rspec'
6
+ require 'spec'
7
+
8
+ Before do
9
+ @tmp_root = File.dirname(__FILE__) + "/../../tmp"
10
+ @home_path = File.expand_path(File.join(@tmp_root, "home"))
11
+ FileUtils.rm_rf @tmp_root
12
+ FileUtils.mkdir_p @home_path
13
+ ENV['HOME'] = @home_path
14
+ end
@@ -0,0 +1,11 @@
1
+ module Matchers
2
+ def contain(expected)
3
+ simple_matcher("contain #{expected.inspect}") do |given, matcher|
4
+ matcher.failure_message = "expected #{given.inspect} to contain #{expected.inspect}"
5
+ matcher.negative_failure_message = "expected #{given.inspect} not to contain #{expected.inspect}"
6
+ given.index expected
7
+ end
8
+ end
9
+ end
10
+
11
+ World(Matchers)
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module LicenseGenerators
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{license_generator}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Alban Peignier"]
9
+ s.date = %q{2010-01-12}
10
+ s.description = %q{Choose the license and generate required documents}
11
+ s.email = ["alban@tryphon.eu"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "rubygems_generators/license/templates/agpl.txt", "rubygems_generators/license/templates/gpl.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "features/development.feature", "features/step_definitions/common_steps.rb", "features/support/common.rb", "features/support/env.rb", "features/support/matchers.rb", "lib/license_generator.rb", "license_generator.gemspec", "rubygems_generators/license/USAGE", "rubygems_generators/license/license_generator.rb", "rubygems_generators/license/templates/agpl.txt", "rubygems_generators/license/templates/copyright.erb", "rubygems_generators/license/templates/gpl.txt", "script/console", "script/destroy", "script/generate", "spec/license_generator_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "test/test_generator_helper.rb", "test/test_license_generator.rb"]
14
+ s.homepage = %q{http://projects.tryphon.eu/license_generator}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{license_generator}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Choose the license and generate required documents}
20
+ s.test_files = ["test/test_license_generator.rb", "test/test_generator_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<rubigen>, [">= 1.5.2"])
28
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.3"])
29
+ s.add_development_dependency(%q<gemcutter>, [">= 0.3.0"])
30
+ s.add_development_dependency(%q<hoe>, [">= 2.5.0"])
31
+ else
32
+ s.add_dependency(%q<rubigen>, [">= 1.5.2"])
33
+ s.add_dependency(%q<rubyforge>, [">= 2.0.3"])
34
+ s.add_dependency(%q<gemcutter>, [">= 0.3.0"])
35
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<rubigen>, [">= 1.5.2"])
39
+ s.add_dependency(%q<rubyforge>, [">= 2.0.3"])
40
+ s.add_dependency(%q<gemcutter>, [">= 0.3.0"])
41
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ Description:
2
+
3
+ Install required resources to place a program under a selected license
4
+
5
+ Support gpl and agpl licenses for the moment. Based on information provided
6
+ by http://www.gnu.org/licenses/gpl-howto.html.
7
+
8
+ Usage:
9
+
10
+ ./script/generate license --author="John Doe" --years="2007,2009" --license=gpl
11
+ create COPYING
12
+ create COPYRIGHT
@@ -0,0 +1,75 @@
1
+ class LicenseGenerator < RubiGen::Base
2
+
3
+ default_options :years => ""
4
+
5
+ attr_reader :name
6
+ attr_accessor :author, :license, :years
7
+
8
+ def initialize(runtime_args, runtime_options = {})
9
+ super
10
+ @name = args.shift
11
+ extract_options
12
+
13
+ usage if [author,license,years].any?(&:blank?)
14
+ end
15
+
16
+ def manifest
17
+ record do |m|
18
+ m.template "gpl.txt", "COPYING"
19
+ m.template "copyright.erb", "COPYRIGHT"
20
+
21
+ # m.directory 'some_folder'
22
+ # m.template "template.rb.erb", "some_file_after_erb.rb"
23
+ # m.template_copy_each ["template.rb", "template2.rb"]
24
+ # m.template_copy_each ["template.rb", "template2.rb"], "some/path"
25
+ # m.file "file", "some_file_copied"
26
+ # m.file_copy_each ["path/to/file", "path/to/file2"]
27
+ # m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
28
+ end
29
+ end
30
+
31
+ def license=(license)
32
+ @license = license.blank? ? nil : license.to_sym
33
+ end
34
+
35
+ def years=(years_definition)
36
+ if String === years_definition
37
+ years_definition = years_definition.split(',').collect(&:to_i).sort
38
+ years_definition << Time.now.year
39
+ end
40
+
41
+ @years = years_definition
42
+ end
43
+
44
+ def license_name
45
+ @@license_names[license]
46
+ end
47
+
48
+ @@license_names = { :gpl => "GNU General public",
49
+ :agpl => "GNU Affero General public" }
50
+
51
+ def self.license_names
52
+ @@license_names
53
+ end
54
+
55
+ protected
56
+ def add_options!(opts)
57
+ # opts.separator ''
58
+ # opts.separator 'Options:'
59
+ # For each option below, place the default
60
+ # at the top of the file next to "default_options"
61
+ opts.on("-a", "--author=\"copyright owner\"", String,
62
+ "The name(s) associated to the copyright") { |o| options[:author] = o }
63
+ opts.on("-l", "--license=gpl|agpl", String,
64
+ "The selected license : gpl, agpl (for the moment)") { |o| options[:license] = o }
65
+ opts.on("-y", "--years=year[,year1,...]", String,
66
+ "The proper year(s) for each release. The current year is added by default", "Default: none") { |o| options[:years] = o }
67
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
68
+ end
69
+
70
+ def extract_options
71
+ self.author = options[:author]
72
+ self.license = options[:license]
73
+ self.years = options[:years]
74
+ end
75
+ end