copyright-header 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/copyright-header CHANGED
@@ -1,4 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # Copyright Header - A utility to manipulate copyright headers on source code files
4
+ # Copyright (C) 2012 Erik Osterman <e@osterman.com>
5
+ #
6
+ # This file is part of Copyright Header.
7
+ #
8
+ # Copyright Header is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Foobar is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
2
22
  $:.unshift(File.expand_path('.')) # Ruby 1.9 doesn't have . in the load path...
3
23
  $:.push(File.expand_path('lib/'))
4
24
 
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = CopyrightHeader::VERSION
9
9
  s.authors = ["Erik Osterman"]
10
10
  s.email = ["e@osterman.com"]
11
+ s.license = ['GPL-3']
11
12
  s.homepage = "https://github.com/osterman/copyright-header"
12
13
  s.summary = %q{A utility to insert copyright headers into various types of source code files}
13
14
  s.description = %q{A utility which is able to recursively insert and remove copyright headers from source code files based on file extensions.}
@@ -1,7 +1,25 @@
1
+ #
2
+ # Copyright Header - A utility to manipulate copyright headers on source code files
3
+ # Copyright (C) 2012 Erik Osterman <e@osterman.com>
4
+ #
5
+ # This file is part of Copyright Header.
6
+ #
7
+ # Copyright Header is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Foobar is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
19
+ #
1
20
  require 'copyright_header/version'
2
21
  require 'copyright_header/command_line'
3
22
  require 'copyright_header/parser'
4
23
 
5
24
  module CopyrightHeader
6
25
  end
7
-
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright Header - A utility to manipulate copyright headers on source code files
3
+ # Copyright (C) 2012 Erik Osterman <e@osterman.com>
4
+ #
5
+ # This file is part of Copyright Header.
6
+ #
7
+ # Copyright Header is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Foobar is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
19
+ #
1
20
  require 'optparse'
2
21
 
3
22
  module CopyrightHeader
@@ -108,5 +127,4 @@ module CopyrightHeader
108
127
  @parser.execute
109
128
  end
110
129
  end
111
- end
112
-
130
+ end
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright Header - A utility to manipulate copyright headers on source code files
3
+ # Copyright (C) 2012 Erik Osterman <e@osterman.com>
4
+ #
5
+ # This file is part of Copyright Header.
6
+ #
7
+ # Copyright Header is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Foobar is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
19
+ #
1
20
  require 'fileutils'
2
21
  require 'yaml'
3
22
  require 'erb'
@@ -5,12 +24,13 @@ require 'ostruct'
5
24
 
6
25
  module CopyrightHeader
7
26
  class FileNotFoundException < Exception; end
27
+ class ExistingLicenseException < Exception; end
8
28
 
9
29
  class License
10
30
  @lines = []
11
31
  def initialize(options)
12
32
  @options = options
13
- @lines = load_template.split(/(\n)/)
33
+ @lines = load_template.split(/\n/).map { |line| line += "\n" }
14
34
  end
15
35
 
16
36
  def word_wrap(text, max_width = nil)
@@ -20,10 +40,10 @@ module CopyrightHeader
20
40
 
21
41
  def load_template
22
42
  if File.exists?(@options[:license_file])
23
- template = ::ERB.new File.new(@options[:license_file]).read, 0, '%<'
43
+ template = ::ERB.new File.new(@options[:license_file]).read, 0, '%'
24
44
  license = template.result(OpenStruct.new(@options).instance_eval { binding })
25
- license += "\n" if license !~ /\n$/s
26
- word_wrap(license)
45
+ license = word_wrap(license)
46
+ license
27
47
  else
28
48
  raise FileNotFoundException.new("Unable to open #{file}")
29
49
  end
@@ -56,8 +76,7 @@ module CopyrightHeader
56
76
 
57
77
  def add(license)
58
78
  if has_copyright?
59
- puts "SKIP #{@file}; detected exisiting license"
60
- return nil
79
+ raise ExistingLicenseException.new("detected exisiting license")
61
80
  end
62
81
 
63
82
  copyright = self.format(license)
@@ -107,7 +126,7 @@ module CopyrightHeader
107
126
  end
108
127
 
109
128
  def has_copyright?(lines = 10)
110
- @contents.split(/\n/)[0..lines].select { |line| line =~ /[Cc]opyright|[Ll]icense/ }.length > 0
129
+ @contents.split(/\n/)[0..lines].select { |line| line =~ /(?!class\s+)([Cc]opyright|[Ll]icense)\s/ }.length > 0
111
130
  end
112
131
  end
113
132
 
@@ -173,28 +192,33 @@ module CopyrightHeader
173
192
  paths << Dir.glob("#{path}/**/*")
174
193
  end
175
194
 
176
- puts paths.inspect
177
-
178
195
  paths.flatten!
179
196
 
180
197
  paths.each do |path|
181
- if File.file?(path)
182
- if @exclude.include? File.basename(path)
183
- puts "SKIP #{path}; excluded"
198
+ begin
199
+ if File.file?(path)
200
+ if @exclude.include? File.basename(path)
201
+ puts "SKIP #{path}; excluded"
202
+ next
203
+ end
204
+ else
205
+ puts "SKIP #{path}; not file"
184
206
  next
185
207
  end
186
208
 
187
- if @syntax.supported?(path)
188
- header = @syntax.header(path)
209
+ if @syntax.supported?(path)
210
+ header = @syntax.header(path)
189
211
  contents = header.send(method, @license)
190
212
  if contents.nil?
191
213
  puts "SKIP #{path}; failed to generate license"
192
214
  else
193
215
  write(path, contents)
194
216
  end
217
+ else
218
+ puts "SKIP #{path}; unsupported"
195
219
  end
196
- else
197
- puts "SKIP #{path}; unsupported"
220
+ rescue Exception => e
221
+ puts "SKIP #{path}; #{e.message}"
198
222
  end
199
223
  end
200
224
  end
@@ -223,5 +247,4 @@ module CopyrightHeader
223
247
  end
224
248
  end
225
249
  end
226
- end
227
-
250
+ end
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright Header - A utility to manipulate copyright headers on source code files
3
+ # Copyright (C) 2012 Erik Osterman <e@osterman.com>
4
+ #
5
+ # This file is part of Copyright Header.
6
+ #
7
+ # Copyright Header is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Foobar is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
19
+ #
1
20
  module CopyrightHeader
2
- VERSION = "1.0.0"
21
+ VERSION = "1.0.1"
3
22
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Erik Osterman
@@ -51,8 +51,8 @@ files:
51
51
  - licenses/MIT.erb
52
52
  has_rdoc: true
53
53
  homepage: https://github.com/osterman/copyright-header
54
- licenses: []
55
-
54
+ licenses:
55
+ - - GPL-3
56
56
  post_install_message:
57
57
  rdoc_options: []
58
58