xolti 0.0.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +2 -0
- data/.xoltignore +6 -0
- data/Gemfile +5 -0
- data/Rakefile +5 -0
- data/exe/xolti +23 -0
- data/lib/comment.rb +33 -0
- data/lib/config.rb +45 -0
- data/lib/core.rb +101 -0
- data/lib/file_finder.rb +55 -0
- data/lib/header_detection.rb +86 -0
- data/lib/xolti.rb +101 -0
- data/readme.md +6 -0
- data/test/tc_comment.rb +37 -0
- data/test/tc_header_detection.rb +58 -0
- data/test/ts_xolti.rb +21 -0
- data/xolti.gemspec +14 -0
- data/xolti.yml +23 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef14fd250bc397bffdcca4f6b0d49117b4d758a8
|
4
|
+
data.tar.gz: 75849122d896705b7ee74fbcdf8ce03fcb0b046a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c89f930b36b0879432aafcd4b3ee61c10d3c2b9b67aadc02c8a5ebdd7ea84f8791f5d8d5f343e7a7701aaf73b92de3bc04d817d30ce9db1f2dc6fb429e135f00
|
7
|
+
data.tar.gz: fc096e1eff003508d7bbfa6257520748ad48ea397366236ee0ba463a57891d18ab8b672921c680b41e528b5af29d04d8d87458fd32b77f1233bcc1eb83a07d4f
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/exe/xolti
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/user/bin/env ruby
|
2
|
+
|
3
|
+
# xolti
|
4
|
+
# Copyright (C) Rémi Even 2016
|
5
|
+
#
|
6
|
+
# This file is part of Xolti.
|
7
|
+
#
|
8
|
+
# Xolti 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
|
+
# Xolti 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 Xolti. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
require "xolti"
|
22
|
+
|
23
|
+
XoltiCLI.start(ARGV)
|
data/lib/comment.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# comment.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
def simple_comment(text, comment_token)
|
19
|
+
text.lines.map{|line| "#{comment_token}#{line}".rstrip + "\n"}.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def complex_comment(text, comment_tokens)
|
23
|
+
result = "#{comment_tokens[0]}\n"
|
24
|
+
result << simple_comment(text, comment_tokens[1])
|
25
|
+
result << "#{comment_tokens[2]}\n"
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
module Comment
|
30
|
+
def Comment.comment(text, comment_tokens)
|
31
|
+
comment_tokens.is_a?(String) ? simple_comment(text, comment_tokens) : complex_comment(text, comment_tokens)
|
32
|
+
end
|
33
|
+
end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# config.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
require "yaml"
|
19
|
+
require "pathname"
|
20
|
+
|
21
|
+
def extract_project_info(raw_project_info)
|
22
|
+
{
|
23
|
+
author: raw_project_info["author"],
|
24
|
+
project_name: raw_project_info["project_name"],
|
25
|
+
year: raw_project_info["year"] || Date.today().year
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
module XoltiConfig
|
30
|
+
def XoltiConfig.find_config_file(path = Pathname.getwd)
|
31
|
+
return nil if path.root?
|
32
|
+
potential_config_file = (path + "xolti.yml")
|
33
|
+
potential_config_file.file? ? potential_config_file.to_s : find_config_file(path.parent)
|
34
|
+
end
|
35
|
+
|
36
|
+
def XoltiConfig.load_config()
|
37
|
+
raw_config = YAML.load(IO.binread(find_config_file()))
|
38
|
+
{
|
39
|
+
project_info: extract_project_info(raw_config["project_info"]),
|
40
|
+
comment: raw_config["comment"] || ["/*", " * ", " */"],
|
41
|
+
template: raw_config["template"] || "header.txt",
|
42
|
+
offset: raw_config["offset"] || 0
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
data/lib/core.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# core.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
require "tempfile"
|
19
|
+
|
20
|
+
require_relative "header_detection"
|
21
|
+
require_relative "comment"
|
22
|
+
|
23
|
+
def complete_template(path, info, template)
|
24
|
+
template %= info.merge({:file_name => File.basename(path)})
|
25
|
+
template
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_header_for(path, config)
|
29
|
+
bare_header = complete_template(path, config[:project_info], config[:template])
|
30
|
+
Comment.comment(bare_header, config[:comment])
|
31
|
+
end
|
32
|
+
|
33
|
+
def insert_with_offset(path, text, offset)
|
34
|
+
file = Tempfile.new("xolti")
|
35
|
+
begin
|
36
|
+
File.open(path, "r") do |source_file|
|
37
|
+
i = 0
|
38
|
+
source_file.each_line do |line|
|
39
|
+
file.write(text) if i == offset
|
40
|
+
i += 1
|
41
|
+
file.write(line)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
file.close()
|
45
|
+
FileUtils.cp(file, path)
|
46
|
+
ensure
|
47
|
+
file.close()
|
48
|
+
file.unlink()
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_lines_from_file(path, start, length)
|
53
|
+
file = Tempfile.new("xolti")
|
54
|
+
begin
|
55
|
+
File.open(path, "r").each_with_index do |line, index|
|
56
|
+
file.write(line) if index < start || index >= start + length
|
57
|
+
end
|
58
|
+
file.close()
|
59
|
+
FileUtils.cp(file, path)
|
60
|
+
ensure
|
61
|
+
file.close()
|
62
|
+
file.unlink()
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def detect_header_position(path, template, comment_tokens)
|
67
|
+
template_lines = Comment.comment(template, comment_tokens).lines("\n")
|
68
|
+
template_regexp_lines = template_lines.map do |line|
|
69
|
+
HeaderDetection.create_detection_regexp_for_line(line)
|
70
|
+
end
|
71
|
+
potential_header_start = 0
|
72
|
+
i = 0
|
73
|
+
File.open(path, "r").each do |line|
|
74
|
+
if template_regexp_lines[i].match(line)
|
75
|
+
i += 1
|
76
|
+
return potential_header_start if i == template_regexp_lines.length
|
77
|
+
else
|
78
|
+
potential_header_start += i + 1
|
79
|
+
i = 0
|
80
|
+
end
|
81
|
+
end
|
82
|
+
-1
|
83
|
+
end
|
84
|
+
|
85
|
+
module Core
|
86
|
+
def Core.licensify(path, config)
|
87
|
+
header = create_header_for(path, config)
|
88
|
+
insert_with_offset(path, header, config[:offset])
|
89
|
+
end
|
90
|
+
|
91
|
+
def Core.delete_header(path, config)
|
92
|
+
template = config[:template]
|
93
|
+
start = detect_header_position(path, template, config[:comment])
|
94
|
+
delete_lines_from_file(path, start, Comment.comment(template, config[:comment]).lines.length) if start >= 0
|
95
|
+
end
|
96
|
+
|
97
|
+
def Core.has_header(path, config)
|
98
|
+
template = config[:template]
|
99
|
+
detect_header_position(path, template, config[:comment]) >= 0
|
100
|
+
end
|
101
|
+
end
|
data/lib/file_finder.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# file_finder.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
# TODO : handle "folder/file" patterns
|
19
|
+
def parse_xoltignore(path)
|
20
|
+
xoltignorePath = "#{path}/.xoltignore"
|
21
|
+
return [] if !File.file?(xoltignorePath)
|
22
|
+
File.readlines(xoltignorePath).reject {|line| line == "" || line[0] == "#"}.map {|line| line.chomp}
|
23
|
+
end
|
24
|
+
|
25
|
+
module FileFinder
|
26
|
+
def FileFinder.explore_folder(folder, ignoreRules=[])
|
27
|
+
fileAcc = []
|
28
|
+
ignoredPaths = [".", "..", ".git", ".xoltignore", "xolti.yml", "header.txt"]
|
29
|
+
ignoreRules += parse_xoltignore(folder)
|
30
|
+
|
31
|
+
Dir.glob("#{folder}/{*,.*}")
|
32
|
+
.delete_if {|x| ignoredPaths.include?(File.basename(x))}
|
33
|
+
.delete_if do |x|
|
34
|
+
basename = File.basename(x)
|
35
|
+
toIgnore = false
|
36
|
+
ignoreRules.each do |rule|
|
37
|
+
if (rule[0] == "!" && File.fnmatch(rule[1..-1], basename))
|
38
|
+
toIgnore = false
|
39
|
+
elsif (File.fnmatch(rule, basename))
|
40
|
+
toIgnore = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
toIgnore
|
44
|
+
end
|
45
|
+
.each do |path|
|
46
|
+
if File.directory?(path)
|
47
|
+
fileAcc += explore_folder(path, ignoreRules)
|
48
|
+
else
|
49
|
+
fileAcc << path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
fileAcc
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# header_detection.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
module HeaderDetection
|
19
|
+
|
20
|
+
# Return the positions of every (alternating) % and } in template_line
|
21
|
+
def HeaderDetection.find_template_tokens_indexes(template_line)
|
22
|
+
indexes = []
|
23
|
+
searchedChar = "%"
|
24
|
+
for i in 0..template_line.length - 1
|
25
|
+
if template_line[i].chr == searchedChar
|
26
|
+
indexes.push(i)
|
27
|
+
searchedChar = searchedChar == "%" ? "}" : "%"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
indexes
|
31
|
+
end
|
32
|
+
|
33
|
+
def HeaderDetection.split_template_tokens_from_line(template_line)
|
34
|
+
tokens = []
|
35
|
+
currentTokenStart = 0
|
36
|
+
currentTokenEnd = 0
|
37
|
+
inTag = false
|
38
|
+
while currentTokenEnd < template_line.length do
|
39
|
+
if !inTag && template_line[currentTokenEnd].chr == "%"
|
40
|
+
if (currentTokenEnd != currentTokenStart)
|
41
|
+
tokens.push(template_line[currentTokenStart..(currentTokenEnd - 1)])
|
42
|
+
end
|
43
|
+
currentTokenStart = currentTokenEnd
|
44
|
+
inTag = true
|
45
|
+
elsif inTag && template_line[currentTokenEnd].chr == "}"
|
46
|
+
tokens.push(template_line[currentTokenStart..currentTokenEnd])
|
47
|
+
currentTokenStart = currentTokenEnd + 1
|
48
|
+
inTag = false
|
49
|
+
end
|
50
|
+
currentTokenEnd += 1
|
51
|
+
end
|
52
|
+
tokens.push(template_line[currentTokenStart..-1]) unless currentTokenStart == template_line.length
|
53
|
+
tokens
|
54
|
+
end
|
55
|
+
|
56
|
+
def HeaderDetection.create_detection_regexp_for_line(template_line)
|
57
|
+
tokens = split_template_tokens_from_line(template_line)
|
58
|
+
regexpTokens = tokens.map do |token|
|
59
|
+
if tag?(token) then create_regexp_for_tag(token) else Regexp.escape(token) end
|
60
|
+
end
|
61
|
+
Regexp.new("(" + regexpTokens.join(")(") + ")")
|
62
|
+
end
|
63
|
+
|
64
|
+
def HeaderDetection.tag?(token)
|
65
|
+
token[0] == "%"
|
66
|
+
end
|
67
|
+
|
68
|
+
def HeaderDetection.extract_tag_type(tag)
|
69
|
+
tag[2..-2]
|
70
|
+
end
|
71
|
+
|
72
|
+
def HeaderDetection.create_regexp_for_tag(tag)
|
73
|
+
case extract_tag_type(tag)
|
74
|
+
when "year"
|
75
|
+
"?<year>[[:digit:]]{4}"
|
76
|
+
when "author"
|
77
|
+
"?<author>.*"
|
78
|
+
when "project_name"
|
79
|
+
"?<project_name>.*"
|
80
|
+
when "file_name"
|
81
|
+
"?<file_name>.*"
|
82
|
+
else
|
83
|
+
".*"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/xolti.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# xolti.rb
|
4
|
+
# Copyright (C) Rémi Even 2016
|
5
|
+
#
|
6
|
+
# This file is part of Xolti.
|
7
|
+
#
|
8
|
+
# Xolti 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
|
+
# Xolti 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 Xolti. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
require "thor"
|
22
|
+
require "pathname"
|
23
|
+
require "yaml"
|
24
|
+
|
25
|
+
require_relative "core"
|
26
|
+
require_relative "config"
|
27
|
+
require_relative "file_finder"
|
28
|
+
|
29
|
+
Signal.trap("INT") do
|
30
|
+
puts "\nCancelling..."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
class XoltiCLI < Thor
|
35
|
+
|
36
|
+
desc "add [FILE|FOLDER]", "Add a header to FILE or to all files in FOLDER"
|
37
|
+
def add(file)
|
38
|
+
if File.file?(file)
|
39
|
+
puts "Adding header to #{file}"
|
40
|
+
config = XoltiConfig.load_config
|
41
|
+
Core.licensify(file, config) if !Core.has_header(file, config)
|
42
|
+
else
|
43
|
+
config = XoltiConfig.load_config
|
44
|
+
FileFinder.explore_folder(file)
|
45
|
+
.reject{|source_file| Core.has_header(source_file, config)}
|
46
|
+
.each do |source_file|
|
47
|
+
puts "Adding header to #{source_file}"
|
48
|
+
Core.licensify(source_file, config)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "check FILE", "Check the header of FILE"
|
54
|
+
def check(file)
|
55
|
+
config = XoltiConfig.load_config
|
56
|
+
puts Core.has_header(file, config) ? "\"#{file}\" : OK" : "\"#{file}\": not OK"
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "list-missing", "Print a list of files missing (proper) header"
|
60
|
+
def list_missing()
|
61
|
+
dir = Dir.pwd
|
62
|
+
config = XoltiConfig.load_config
|
63
|
+
missing_headers = FileFinder.explore_folder(dir)
|
64
|
+
.reject{|file| Core.has_header(file, config)}
|
65
|
+
return puts "All files OK" if missing_headers.empty?
|
66
|
+
puts "Files missing (proper) header:"
|
67
|
+
missing_headers.each{|file| puts file[dir.length + 1..-1]}
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "delete FILE", "Delete the header in FILE"
|
71
|
+
def delete(file)
|
72
|
+
puts "Deleting header in #{file}"
|
73
|
+
config = XoltiConfig.load_config
|
74
|
+
Core.delete_header(file, config)
|
75
|
+
end
|
76
|
+
|
77
|
+
no_commands {
|
78
|
+
def ask_for_name(config)
|
79
|
+
default_name = Pathname.getwd.basename.to_s
|
80
|
+
print "name (#{default_name}): "
|
81
|
+
typed_name = STDIN.gets.chomp
|
82
|
+
config["project_info"]["project_name"] = (typed_name == "") ? default_name : typed_name
|
83
|
+
end
|
84
|
+
|
85
|
+
def ask_for_author(config)
|
86
|
+
print "author: "
|
87
|
+
typed_author = STDIN.gets.chomp
|
88
|
+
config["project_info"]["author"] = typed_author
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
desc "init", "Create xolti.yml"
|
93
|
+
def init()
|
94
|
+
return puts "Xolti is already initialiazed" if XoltiConfig.find_config_file != nil
|
95
|
+
puts "Initiating xolti project"
|
96
|
+
config = {"project_info" => {}}
|
97
|
+
self.ask_for_name(config)
|
98
|
+
self.ask_for_author(config)
|
99
|
+
File.write("xolti.yml", config.to_yaml)
|
100
|
+
end
|
101
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# Xolti
|
2
|
+
|
3
|
+
> Tool assisting developers to manage license headers in source files, written in Ruby.
|
4
|
+
|
5
|
+
[](http://travis-ci.org/RemiEven/xolti)
|
6
|
+
[](http://www.gnu.org/licenses/gpl-3.0.en.html)
|
data/test/tc_comment.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# tc_comment.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
require "test/unit"
|
19
|
+
|
20
|
+
require_relative "../lib/comment"
|
21
|
+
|
22
|
+
class TestComment < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def test_simple_comment
|
25
|
+
assert_equal("", Comment.comment("", "# "))
|
26
|
+
assert_equal("# A\n", Comment.comment("A\n", "# "))
|
27
|
+
assert_equal("# A\n# B\n", Comment.comment("A\nB\n", "# "))
|
28
|
+
assert_equal("#\n", Comment.comment("\n", "# "))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_complex_comment
|
32
|
+
assert_equal("/*\n */\n", Comment.comment("", ["/*", " * ", " */"]))
|
33
|
+
assert_equal("/*\n * A\n */\n", Comment.comment("A\n", ["/*", " * ", " */"]))
|
34
|
+
assert_equal("/*\n * A\n * B\n */\n", Comment.comment("A\nB\n", ["/*", " * ", " */"]))
|
35
|
+
assert_equal("/*\n * A\n *\n */\n", Comment.comment("A\n\n", ["/*", " * ", " */"]))
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# tc_header_detection.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
require "test/unit"
|
19
|
+
|
20
|
+
require_relative "../lib/header_detection"
|
21
|
+
|
22
|
+
class TestHeaderDetection < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def test_find_template_tokens_indexes
|
25
|
+
assert_equal([], HeaderDetection.find_template_tokens_indexes(""))
|
26
|
+
assert_equal([], HeaderDetection.find_template_tokens_indexes("ee"))
|
27
|
+
assert_equal([2, 5], HeaderDetection.find_template_tokens_indexes("ee%{r}"))
|
28
|
+
assert_equal([2, 5, 7, 12], HeaderDetection.find_template_tokens_indexes("ee%{r} %{abc}fe"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_split_template_tokens_from_line
|
32
|
+
assert_equal(["ee"], HeaderDetection.split_template_tokens_from_line("ee"))
|
33
|
+
assert_equal(["ee", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}"))
|
34
|
+
assert_equal(["%{coucou}"], HeaderDetection.split_template_tokens_from_line("%{coucou}"))
|
35
|
+
assert_equal(["ee", "%{coucou}", "ee"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}ee"))
|
36
|
+
assert_equal(["ee", "%{coucou}", "ee", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}ee%{coucou}"))
|
37
|
+
assert_equal(["ee", "%{coucou}", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}%{coucou}"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_create_detection_regexp_for_line
|
41
|
+
assert_match(HeaderDetection.create_detection_regexp_for_line("e"), "e")
|
42
|
+
assert_match(HeaderDetection.create_detection_regexp_for_line("."), ".")
|
43
|
+
assert_no_match(HeaderDetection.create_detection_regexp_for_line("."), "a")
|
44
|
+
assert_match(HeaderDetection.create_detection_regexp_for_line("%{r}"), "azer")
|
45
|
+
assert_match(HeaderDetection.create_detection_regexp_for_line(""), "")
|
46
|
+
assert_match(HeaderDetection.create_detection_regexp_for_line("a%{r}r"), "azer")
|
47
|
+
assert_no_match(HeaderDetection.create_detection_regexp_for_line("z%{r}f"), "azer")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_extract_tag_type
|
51
|
+
assert_equal(HeaderDetection.extract_tag_type("%{coucou}"), "coucou")
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_tag?
|
55
|
+
assert(HeaderDetection.tag?("%{coucou}"))
|
56
|
+
refute(HeaderDetection.tag?("blabla"))
|
57
|
+
end
|
58
|
+
end
|
data/test/ts_xolti.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# ts_xolti.rb
|
2
|
+
# Copyright (C) Rémi Even 2016
|
3
|
+
#
|
4
|
+
# This file is part of Xolti.
|
5
|
+
#
|
6
|
+
# Xolti is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Xolti is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Xolti. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
require "test/unit"
|
19
|
+
|
20
|
+
require_relative "tc_header_detection"
|
21
|
+
require_relative "tc_comment"
|
data/xolti.gemspec
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "xolti"
|
3
|
+
spec.version = "0.0.0"
|
4
|
+
spec.summary = "A gem to manage license headers"
|
5
|
+
spec.description = "A gem to manage license headers"
|
6
|
+
spec.authors = ["Rémi Even"]
|
7
|
+
spec.homepage = "https://github.com/RemiEven/xolti"
|
8
|
+
spec.license = "GPL-3.0"
|
9
|
+
spec.files = `git ls-files -z`.split("\x0")
|
10
|
+
spec.bindir = "exe"
|
11
|
+
spec.executables << "xolti"
|
12
|
+
|
13
|
+
spec.add_runtime_dependency("thor", ["~>0.19.1", ">=0.19.1"])
|
14
|
+
end
|
data/xolti.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
project_info:
|
3
|
+
project_name: Xolti
|
4
|
+
author: "Rémi Even"
|
5
|
+
comment: "# "
|
6
|
+
template: |
|
7
|
+
%{file_name}
|
8
|
+
Copyright (C) %{author} %{year}
|
9
|
+
|
10
|
+
This file is part of %{project_name}.
|
11
|
+
|
12
|
+
%{project_name} is free software: you can redistribute it and/or modify
|
13
|
+
it under the terms of the GNU General Public License as published by
|
14
|
+
the Free Software Foundation, either version 3 of the License, or
|
15
|
+
(at your option) any later version.
|
16
|
+
|
17
|
+
%{project_name} is distributed in the hope that it will be useful,
|
18
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
+
GNU General Public License for more details.
|
21
|
+
|
22
|
+
You should have received a copy of the GNU General Public License
|
23
|
+
along with %{project_name}. If not, see <http://www.gnu.org/licenses/>.
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xolti
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rémi Even
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.19.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.19.1
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.19.1
|
33
|
+
description: A gem to manage license headers
|
34
|
+
email:
|
35
|
+
executables:
|
36
|
+
- xolti
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".travis.yml"
|
41
|
+
- ".xoltignore"
|
42
|
+
- Gemfile
|
43
|
+
- Rakefile
|
44
|
+
- exe/xolti
|
45
|
+
- lib/comment.rb
|
46
|
+
- lib/config.rb
|
47
|
+
- lib/core.rb
|
48
|
+
- lib/file_finder.rb
|
49
|
+
- lib/header_detection.rb
|
50
|
+
- lib/xolti.rb
|
51
|
+
- readme.md
|
52
|
+
- test/tc_comment.rb
|
53
|
+
- test/tc_header_detection.rb
|
54
|
+
- test/ts_xolti.rb
|
55
|
+
- xolti.gemspec
|
56
|
+
- xolti.yml
|
57
|
+
homepage: https://github.com/RemiEven/xolti
|
58
|
+
licenses:
|
59
|
+
- GPL-3.0
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: A gem to manage license headers
|
81
|
+
test_files: []
|