copyright-header 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/contrib/syntax.yml CHANGED
@@ -6,6 +6,14 @@ ruby:
6
6
  close: '#\n'
7
7
  prefix: '# '
8
8
 
9
+ perl:
10
+ ext: ['.pl']
11
+ after: ['^#!']
12
+ comment:
13
+ open: '#\n'
14
+ close: '#\n'
15
+ prefix: '# '
16
+
9
17
  python:
10
18
  ext: ['.py']
11
19
  after: ['^#!', '^#.*coding']
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.extra_rdoc_files = ['README.md', 'LICENSE', 'AUTHORS', 'contrib/syntax.yml' ]
21
21
  s.require_paths = ["lib"]
22
+ s.add_dependency('github-linguist', '~> 2.6.7')
22
23
  end
@@ -72,14 +72,19 @@ module CopyrightHeader
72
72
  @options[:word_wrap] = len.to_i
73
73
  end
74
74
 
75
- opts.on( '-a', '--add-path PATH', 'Recursively insert header in all files found in path (allows multiple pathes separated by platform path-separator)' ) do |path|
75
+ opts.on( '-a', '--add-path PATH', 'Recursively insert header in all files found in path (allows multiple paths separated by platform path-separator "' + File::PATH_SEPARATOR + '")' ) do |path|
76
76
  @options[:add_path] = path
77
77
  end
78
78
 
79
- opts.on( '-r', '--remove-path PATH', 'Recursively remove header in all files found in path (allows multiple pathes separated by platform path-separator)' ) do |path|
79
+ opts.on( '-r', '--remove-path PATH', 'Recursively remove header in all files found in path (allows multiple paths separated by platform path-separator "' + File::PATH_SEPARATOR + '")' ) do |path|
80
80
  @options[:remove_path] = path
81
81
  end
82
82
 
83
+ @options[:guess_extension] = false
84
+ opts.on( '-g', '--guess-extension', 'Use the GitHub Linguist gem to guess the extension of the source code when no extension can be determined (experimental).' ) do
85
+ @options[:guess_extension] = true
86
+ end
87
+
83
88
  @options[:syntax] ||= @options[:base_path] + '/contrib/syntax.yml'
84
89
  opts.on( '-c', '--syntax FILE', 'Syntax configuration file' ) do |path|
85
90
  @options[:syntax] = path
@@ -21,6 +21,7 @@ require 'fileutils'
21
21
  require 'yaml'
22
22
  require 'erb'
23
23
  require 'ostruct'
24
+ require 'linguist'
24
25
 
25
26
  module CopyrightHeader
26
27
  class FileNotFoundException < Exception; end
@@ -76,7 +77,7 @@ module CopyrightHeader
76
77
 
77
78
  def add(license)
78
79
  if has_copyright?
79
- raise ExistingLicenseException.new("detected exisiting license")
80
+ raise ExistingLicenseException.new("detected existing license")
80
81
  end
81
82
 
82
83
  copyright = self.format(license)
@@ -131,7 +132,10 @@ module CopyrightHeader
131
132
  end
132
133
 
133
134
  class Syntax
134
- def initialize(config)
135
+ attr_accessor :guess_extension
136
+
137
+ def initialize(config, guess_extension = false)
138
+ @guess_extension = guess_extension
135
139
  @config = {}
136
140
  syntax = YAML.load_file(config)
137
141
  syntax.each_value do |format|
@@ -146,7 +150,11 @@ module CopyrightHeader
146
150
  end
147
151
 
148
152
  def ext(file)
149
- File.extname(file)
153
+ extension = File.extname(file)
154
+ if @guess_extension && (extension.nil? || extension.empty?)
155
+ extension = Linguist::FileBlob.new(file).language.primary_extension
156
+ end
157
+ return extension
150
158
  end
151
159
 
152
160
  def supported?(file)
@@ -171,7 +179,7 @@ module CopyrightHeader
171
179
  :copyright_years => @options[:copyright_years],
172
180
  :copyright_holders => @options[:copyright_holders],
173
181
  :word_wrap => @options[:word_wrap])
174
- @syntax = Syntax.new(@options[:syntax])
182
+ @syntax = Syntax.new(@options[:syntax], @options[:guess_extension])
175
183
  end
176
184
 
177
185
  def execute
@@ -18,5 +18,5 @@
18
18
  # along with Copyright Header. If not, see <http://www.gnu.org/licenses/>.
19
19
  #
20
20
  module CopyrightHeader
21
- VERSION = "1.0.8"
21
+ VERSION = "1.0.9"
22
22
  end
@@ -6,4 +6,4 @@ Redistribution and use in source and binary forms, with or without modification,
6
6
  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
7
  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
8
 
9
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 8
9
- version: 1.0.8
8
+ - 9
9
+ version: 1.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Erik Osterman
@@ -14,10 +14,23 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2013-03-08 00:00:00 -08:00
17
+ date: 2013-04-02 00:00:00 -07:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: github-linguist
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 6
30
+ - 7
31
+ version: 2.6.7
32
+ type: :runtime
33
+ version_requirements: *id001
21
34
  description: A utility which is able to recursively insert and remove copyright headers from source code files based on file extensions.
22
35
  email:
23
36
  - e@osterman.com