header-inserter 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ == 1.0.1 2009-03-25
2
+
3
+ * New version
4
+ * Correcting path bugs and tweaking for release
5
+
6
+ == 0.4.1 2009-03-21
7
+
8
+ * 1 major enhancement:
9
+ * Adding support to modifications and svn
10
+
11
+ == 0.0.1 2009-03-21
12
+
13
+ * 1 major enhancement:
14
+ * Initial commit to github
@@ -0,0 +1,25 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile.rb
6
+ features/get_subversion_modifications.feature
7
+ features/retrieve_files_for_project.feature
8
+ features/step_definitions/common_steps.rb
9
+ features/step_definitions/get_subversion_modifications_steps.rb
10
+ features/step_definitions/retrieve_files_for_project_steps.rb
11
+ features/support/env.rb
12
+ lib/header-inserter.rb
13
+ lib/header-inserter/modification.rb
14
+ lib/header-inserter/nil_version_control.rb
15
+ lib/header-inserter/project.rb
16
+ lib/header-inserter/project_file.rb
17
+ lib/header-inserter/svn_version_control.rb
18
+ spec/modification_spec.rb
19
+ spec/nil_version_control_spec.rb
20
+ spec/project-file_spec.rb
21
+ spec/project_spec.rb
22
+ spec/spec.opts
23
+ spec/spec_helper.rb
24
+ spec/svn_version_control_spec.rb
25
+ tasks/rspec.rake
@@ -0,0 +1,58 @@
1
+ Create a ruby script, let's say add-header.rb:
2
+
3
+ require 'rubygems'
4
+ require 'header-inserter'
5
+ require 'header-inserter/project'
6
+
7
+ header_format = """
8
+ # Copyright (c) REPLACE_CREATE_AND_CURRENT_YEAR Hugo Corbucci
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining
11
+ # a copy of this software and associated documentation files (the
12
+ # 'Software'), to deal in the Software without restriction, including
13
+ # without limitation the rights to use, copy, modify, merge, publish,
14
+ # distribute, sublicense, and/or sell copies of the Software, and to
15
+ # permit persons to whom the Software is furnished to do so, subject to
16
+ # the following conditions:
17
+ #
18
+ # The above copyright notice and this permission notice shall be
19
+ # included in all copies or substantial portions of the Software.
20
+ #
21
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
22
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ #
29
+ # This file received the following contributions:
30
+ # REPLACE_CREATOR - Initial API and implementation
31
+ # REPLACE_CONTRIBUTORS - Improvements
32
+ #
33
+ # It was created on REPLACE_DATE, REPLACE_TIME.
34
+ # REPLACE_REST
35
+ """
36
+
37
+ project = Project.new "/my/project"
38
+ files = project.list :rb
39
+ hooks = { "REPLACE_CREATE_AND_CURRENT_YEAR" => lambda { |file|
40
+ created_year = file.created_on.year;
41
+ year = Date.today.year
42
+ if created_year = Date.today.year
43
+ "#{year}"
44
+ else
45
+ "#{created_year}, #{year}"
46
+ end
47
+ },
48
+ "REPLACE_CREATOR" => lambda { |file| file.contributors()[0] },
49
+ "REPLACE_CONTRIBUTORS" => lambda { |file| contributors = file.contributors();contributors[1..contributors.size].join(", ") },
50
+ "REPLACE_DATE" => lambda {|file| file.created_on.strftime("%Y/%m/%d") },
51
+ "REPLACE_TIME" => lambda {|file| file.created_on.strftime("%H:%M") },
52
+ "REPLACE_REST" => lambda {|file| file.original_header }
53
+ }
54
+ files.each do |file|
55
+ new_header = file.generate_header(header_format, hooks)
56
+ old_header = file.original_header
57
+ file.add_header new_header, old_header
58
+ end
@@ -0,0 +1,54 @@
1
+ = header-inserter
2
+
3
+ https://github.com/night/header-inserter/tree
4
+
5
+ == DESCRIPTION:
6
+
7
+ This project was created to help me insert the EPLv1.0 license into all Archimedes source code files.
8
+
9
+ It should recover data from the subversion repository if needed and generated a header with the license, the years in which the copyright apply and the list of contributors for each file.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ Feature:
14
+ - Lists all files of a certain extension within a directory
15
+
16
+ == SYNOPSIS:
17
+
18
+ Create a new project:
19
+ project = Project.new "/tmp/my/project/"
20
+ List "rb" files in it:
21
+ files = project.list "rb"
22
+
23
+ == REQUIREMENTS:
24
+
25
+ All you need is ruby 1.8 which you probably have since you are installing a gem.
26
+
27
+ == INSTALL:
28
+
29
+ sudo gem install header-inserter
30
+
31
+ == LICENSE:
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2009 Hugo Corbucci
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/header-inserter'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('header-inserter', HeaderInserter::VERSION) do |p|
7
+ p.developer('FIXME full name', 'FIXME email')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ task :default => [:spec, :features]
@@ -0,0 +1,26 @@
1
+ Feature: Retrieve the history of a file from subversion
2
+ In order to present the full data of a file
3
+ Files should allow to
4
+ retrieve modifications made to them over time through the subversion repository
5
+
6
+ Scenario: History of a non shared file
7
+ Given a file not version controlled
8
+ When I retrieve its history
9
+ Then I should receive an empty history
10
+
11
+ Scenario: History of a one version shared file
12
+ Given a file recently under version control
13
+ When I retrieve its history
14
+ Then I should receive a history with modifications:
15
+ | revision | author | date | log |
16
+ | 1458 | hugo.corbucci | 2009-03-23 12:00:00 | Test file for the header-insert project. |
17
+
18
+ Scenario: History of an old multi-version shared file
19
+ Given a file under version control for some time
20
+ When I retrieve its history
21
+ Then I should receive a history with modifications:
22
+ | revision | author | date | log |
23
+ | 1458 | hugo.corbucci | 2009-03-23 12:00:00 | Test file for the header-insert project. |
24
+ | 1459 | hugo.corbucci | 2009-03-23 13:00:00 | Changing it. |
25
+ | 1460 | hugo.corbucci | 2009-03-23 14:00:00 | Changing it again. |
26
+ | 1461 | hugo.corbucci | 2009-03-23 15:00:00 | Last change. |
@@ -0,0 +1,24 @@
1
+ Feature: List all source files of a project
2
+ In order to control my source code
3
+ Maintainers should be able to
4
+ easily find out each source file in their project
5
+
6
+ Scenario: Source files of a non-existing project
7
+ Given a non-existing project
8
+ When I list "java" files
9
+ Then I should get nothing
10
+
11
+ Scenario: Source files of an empty project
12
+ Given an empty project
13
+ When I list "java" files
14
+ Then I should get nothing
15
+
16
+ Scenario: Source files on root of a project
17
+ Given a non-structured project
18
+ When I list "java" files
19
+ Then I should get ["Main.java", "MainTest.java"]
20
+
21
+ Scenario: Source files nested in a structured project
22
+ Given a structured project
23
+ When I list "java" files
24
+ Then I should get ["src/my/project/Main.java", "src/my/project/internal/Logic.java", "test/my/project/internal/LogicTest.java"]
@@ -0,0 +1,194 @@
1
+ def in_project_folder(&block)
2
+ project_folder = @active_project_folder || @tmp_root
3
+ FileUtils.chdir(project_folder, &block)
4
+ end
5
+
6
+ def in_home_folder(&block)
7
+ FileUtils.chdir(@home_path, &block)
8
+ end
9
+
10
+ Given %r{^a safe folder} do
11
+ FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp"
12
+ FileUtils.mkdir_p @tmp_root
13
+ FileUtils.mkdir_p @home_path = File.expand_path(File.join(@tmp_root, "home"))
14
+ @lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib')
15
+ Given "env variable $HOME set to '#{@home_path}'"
16
+ end
17
+
18
+ Given %r{^this project is active project folder} do
19
+ Given "a safe folder"
20
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
21
+ end
22
+
23
+ Given %r{^env variable \$([\w_]+) set to '(.*)'} do |env_var, value|
24
+ ENV[env_var] = value
25
+ end
26
+
27
+ def force_local_lib_override(project_name = @project_name)
28
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
29
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
30
+ f << "$:.unshift('#{@lib_path}')\n"
31
+ f << rakefile
32
+ end
33
+ end
34
+
35
+ def setup_active_project_folder project_name
36
+ @active_project_folder = File.join(@tmp_root, project_name)
37
+ @project_name = project_name
38
+ end
39
+
40
+ Given %r{'(.*)' folder is deleted} do |folder|
41
+ in_project_folder do
42
+ FileUtils.rm_rf folder
43
+ end
44
+ end
45
+
46
+ When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments|
47
+ @stdout = StringIO.new
48
+ FileUtils.chdir(@active_project_folder) do
49
+ if Object.const_defined?("APP_ROOT")
50
+ APP_ROOT.replace(FileUtils.pwd)
51
+ else
52
+ APP_ROOT = FileUtils.pwd
53
+ end
54
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
55
+ end
56
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
57
+ @stdout.rewind
58
+ f << @stdout.read
59
+ end
60
+ end
61
+
62
+ When %r{run executable '(.*)' with arguments '(.*)'} do |executable, arguments|
63
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
64
+ in_project_folder do
65
+ system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
66
+ end
67
+ end
68
+
69
+ When %r{run project executable '(.*)' with arguments '(.*)'} do |executable, arguments|
70
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
71
+ in_project_folder do
72
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
73
+ end
74
+ end
75
+
76
+ When %r{run local executable '(.*)' with arguments '(.*)'} do |executable, arguments|
77
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
78
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
79
+ in_project_folder do
80
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
81
+ end
82
+ end
83
+
84
+ When %r{^task 'rake (.*)' is invoked$} do |task|
85
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
86
+ FileUtils.chdir(@active_project_folder) do
87
+ system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
88
+ end
89
+ end
90
+
91
+ Then %r{^folder '(.*)' (is|is not) created} do |folder, is|
92
+ in_project_folder do
93
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
94
+ end
95
+ end
96
+
97
+ Then %r{^file '(.*)' (is|is not) created} do |file, is|
98
+ in_project_folder do
99
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
100
+ end
101
+ end
102
+
103
+ Then %r{^file with name matching '(.*)' is created} do |pattern|
104
+ in_project_folder do
105
+ Dir[pattern].should_not be_empty
106
+ end
107
+ end
108
+
109
+ Then %r{gem file '(.*)' and generated file '(.*)' should be the same} do |gem_file, project_file|
110
+ File.exists?(gem_file).should be_true
111
+ File.exists?(project_file).should be_true
112
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
113
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
114
+ project_file_contents.should == gem_file_contents
115
+ end
116
+
117
+ Then %r{^output same as contents of '(.*)'$} do |file|
118
+ expected_output = File.read(File.join(File.dirname(__FILE__) + "/../expected_outputs", file))
119
+ actual_output = File.read(@stdout)
120
+ actual_output.should == expected_output
121
+ end
122
+
123
+ Then %r{^(does|does not) invoke generator '(.*)'$} do |does_invoke, generator|
124
+ actual_output = File.read(@stdout)
125
+ does_invoke == "does" ?
126
+ actual_output.should(match(/dependency\s+#{generator}/)) :
127
+ actual_output.should_not(match(/dependency\s+#{generator}/))
128
+ end
129
+
130
+ Then %r{help options '(.*)' and '(.*)' are displayed} do |opt1, opt2|
131
+ actual_output = File.read(@stdout)
132
+ actual_output.should match(/#{opt1}/)
133
+ actual_output.should match(/#{opt2}/)
134
+ end
135
+
136
+ Then %r{^output (does|does not) match \/(.*)\/} do |does, regex|
137
+ actual_output = File.read(@stdout)
138
+ (does == 'does') ?
139
+ actual_output.should(match(/#{regex}/)) :
140
+ actual_output.should_not(match(/#{regex}/))
141
+ end
142
+
143
+ Then %r{^contents of file '(.*)' (does|does not) match \/(.*)\/} do |file, does, regex|
144
+ in_project_folder do
145
+ actual_output = File.read(file)
146
+ (does == 'does') ?
147
+ actual_output.should(match(/#{regex}/)) :
148
+ actual_output.should_not(match(/#{regex}/))
149
+ end
150
+ end
151
+
152
+ Then %r{^all (\d+) tests pass} do |expected_test_count|
153
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
154
+ actual_output = File.read(@stdout)
155
+ actual_output.should match(expected)
156
+ end
157
+
158
+ Then %r{^all (\d+) examples pass} do |expected_test_count|
159
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
160
+ actual_output = File.read(@stdout)
161
+ actual_output.should match(expected)
162
+ end
163
+
164
+ Then %r{^yaml file '(.*)' contains (\{.*\})} do |file, yaml|
165
+ in_project_folder do
166
+ yaml = eval yaml
167
+ YAML.load(File.read(file)).should == yaml
168
+ end
169
+ end
170
+
171
+ Then %r{^Rakefile can display tasks successfully} do
172
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
173
+ FileUtils.chdir(@active_project_folder) do
174
+ system "rake -T > #{@stdout} 2> #{@stdout}"
175
+ end
176
+ actual_output = File.read(@stdout)
177
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
178
+ end
179
+
180
+ Then %r{^task 'rake (.*)' is executed successfully} do |task|
181
+ @stdout.should_not be_nil
182
+ actual_output = File.read(@stdout)
183
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
184
+ actual_output.should_not match(/Error/i)
185
+ end
186
+
187
+ Then %r{^gem spec key '(.*)' contains \/(.*)\/} do |key, regex|
188
+ in_project_folder do
189
+ gem_file = Dir["pkg/*.gem"].first
190
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
191
+ spec_value = gem_spec.send(key.to_sym)
192
+ spec_value.to_s.should match(/#{regex}/)
193
+ end
194
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../lib/header-inserter/project'
2
+ require File.dirname(__FILE__) + '/../../lib/header-inserter/project_file'
3
+ require File.dirname(__FILE__) + '/../../lib/header-inserter/modification'
4
+ require 'ftools'
5
+
6
+ project = Project.new("/tmp/version_controlled_project")
7
+
8
+ def create_file path, content
9
+ FileUtils.makedirs File.dirname(path)
10
+ file = File.new path, "w"
11
+ file.puts content
12
+ file.close
13
+ end
14
+
15
+ def obtain_file file
16
+ # system("svn co http://svn.archimedes.org.br/public/header-insert/#{file.path}")
17
+ create_file file.absolute_path, "a test"
18
+ end
19
+
20
+ Given /a file not version controlled/ do
21
+ @file = ProjectFile.new project, "my.file"
22
+ create_file @file.absolute_path, "Just a new file"
23
+ end
24
+
25
+ Given /a file recently under version control/ do
26
+ path = "single_mod.file"
27
+ @file = ProjectFile.new project, path
28
+ obtain_file @file
29
+ end
30
+
31
+ Given /a file under version control for some time/ do
32
+ path = "multiple_mods.file"
33
+ @file = ProjectFile.new project, path
34
+ obtain_file @file
35
+ end
36
+
37
+ When /I retrieve its history/ do
38
+ vcs = @file.version_control
39
+ @history = vcs.history @file
40
+ end
41
+
42
+ Then /I should receive an empty history/ do
43
+ @history.should == []
44
+ end
45
+
46
+ Then /I should receive a history with modifications:/ do |modifications|
47
+ mods = []
48
+ modifications.hashes.each do |hash|
49
+ mods << Modification.new(hash["revision"], hash["author"], hash["date"], hash["log"])
50
+ end
51
+ @history.should == mods
52
+ end
53
+
54
+ at_exit do
55
+ FileUtils.rm_rf project.path
56
+ end