xcop 0.2 → 0.3
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 +4 -4
- data/.simplecov +3 -3
- data/README.md +17 -3
- data/bin/xcop +5 -18
- data/features/gem_package.feature +1 -1
- data/features/rake.feature +21 -0
- data/features/step_definitions/steps.rb +7 -1
- data/lib/xcop.rb +28 -0
- data/lib/xcop/rake_task.rb +67 -0
- data/lib/xcop/version.rb +1 -1
- data/test/test_rake_task.rb +56 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5aa1f93ebccfdcec5e65a77c4d9a563ccbedb824
|
4
|
+
data.tar.gz: bfee771919d61c8fc4ca3adaf1c1031a992344c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6cb86b7d2a422f86d71c2729d20d179dac70e8e17a9e9eb577842bdfb416396293013ba49d1ec17bc92b4efe458e8e45c8e7cb3be57f32fe161a8207d0b4a94
|
7
|
+
data.tar.gz: 2d2b8245efe0a331ee2daf9e18fb454af68fb554d8497a5c2ca32d1e2deeb80a9ebdb288e72ae675bff52f8e76d5f8bfd78ed6247b97959bb713ca7251d5b3eb
|
data/.simplecov
CHANGED
@@ -29,9 +29,9 @@ if Gem.win_platform? then
|
|
29
29
|
add_filter "/features/"
|
30
30
|
end
|
31
31
|
else
|
32
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter
|
33
|
-
SimpleCov::Formatter::HTMLFormatter
|
34
|
-
|
32
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
33
|
+
[SimpleCov::Formatter::HTMLFormatter]
|
34
|
+
)
|
35
35
|
SimpleCov.start do
|
36
36
|
add_filter "/test/"
|
37
37
|
add_filter "/features/"
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[](https://codeclimate.com/github/yegor256/xcop)
|
11
11
|
[](https://codecov.io/github/yegor256/xcop?branch=master)
|
12
12
|
|
13
|
-
## What
|
13
|
+
## What this is for?
|
14
14
|
|
15
15
|
This command line tool validates your XML files for proper formatting.
|
16
16
|
If they are not formatted correctly, it prints the difference and
|
@@ -18,7 +18,7 @@ returns with an error. You can use it two ways: 1) to fail your build
|
|
18
18
|
if any X-like files (XML, XSD, XSL, XHTML) are not formatted correctly,
|
19
19
|
and 2) to format them correctly.
|
20
20
|
|
21
|
-
## How to
|
21
|
+
## How to install?
|
22
22
|
|
23
23
|
Install it first:
|
24
24
|
|
@@ -26,7 +26,7 @@ Install it first:
|
|
26
26
|
$ gem install xcop
|
27
27
|
```
|
28
28
|
|
29
|
-
## How to
|
29
|
+
## How to run?
|
30
30
|
|
31
31
|
Run it locally and read its output:
|
32
32
|
|
@@ -34,6 +34,20 @@ Run it locally and read its output:
|
|
34
34
|
$ xcop --help
|
35
35
|
```
|
36
36
|
|
37
|
+
## How to use in Rakefile?
|
38
|
+
|
39
|
+
This is what you need there:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'xcop/rake_task'
|
43
|
+
desc 'Run XCop on all XML/XSL files in all directories'
|
44
|
+
Xcop::RakeTask.new(:xcop) do |task|
|
45
|
+
task.license = 'LICENSE.txt'
|
46
|
+
task.includes = ['**/*.xml', '**/*.xsl']
|
47
|
+
task.excludes = ['target/**/*']
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
37
51
|
## How to contribute?
|
38
52
|
|
39
53
|
Just submit a pull request. Make sure `rake` passes.
|
data/bin/xcop
CHANGED
@@ -50,22 +50,9 @@ Encoding.default_internal = Encoding::UTF_8
|
|
50
50
|
|
51
51
|
license = opts.license? ? File.read(opts[:license]) : ''
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
print "Error\n"
|
59
|
-
puts diff
|
60
|
-
exit -1
|
61
|
-
end
|
62
|
-
unless license.empty?
|
63
|
-
ldiff = doc.ldiff(license)
|
64
|
-
unless ldiff.empty?
|
65
|
-
print "Broken license\n"
|
66
|
-
puts ldiff
|
67
|
-
exit -1
|
68
|
-
end
|
69
|
-
end
|
70
|
-
print "OK\n"
|
53
|
+
begin
|
54
|
+
Xcop::CLI.new(opts.arguments, license).run
|
55
|
+
rescue StandardError => e
|
56
|
+
puts e.message
|
57
|
+
exit -1
|
71
58
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Rake tasks
|
2
|
+
As a source code writer I want to be able to
|
3
|
+
run Xcop from Rakefile
|
4
|
+
|
5
|
+
Scenario: Xcop can be used in Rakefile
|
6
|
+
Given It is Unix
|
7
|
+
And I have a "Rakefile" file with content:
|
8
|
+
"""
|
9
|
+
require 'xcop/rake_task'
|
10
|
+
Xcop::RakeTask.new(:xcop) do |task|
|
11
|
+
task.includes = ['**/*.xml']
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
And I have a "good.xml" file with content:
|
15
|
+
"""
|
16
|
+
<?xml version="1.0"?>
|
17
|
+
<hello>Hello, world!</hello>
|
18
|
+
|
19
|
+
"""
|
20
|
+
When I run bash with "rake xcop"
|
21
|
+
Then Exit code is zero
|
@@ -73,7 +73,13 @@ Then(/^Exit code is not zero$/) do
|
|
73
73
|
raise 'Zero exit code' if @exitstatus == 0
|
74
74
|
end
|
75
75
|
|
76
|
-
When(/^I run bash with$/) do |text|
|
76
|
+
When(/^I run bash with "([^"]*)"$/) do |text|
|
77
|
+
FileUtils.copy_entry(@cwd, File.join(@dir, 'xcop'))
|
78
|
+
@stdout = `#{text}`
|
79
|
+
@exitstatus = $CHILD_STATUS.exitstatus
|
80
|
+
end
|
81
|
+
|
82
|
+
When(/^I run bash with:$/) do |text|
|
77
83
|
FileUtils.copy_entry(@cwd, File.join(@dir, 'xcop'))
|
78
84
|
@stdout = `#{text}`
|
79
85
|
@exitstatus = $CHILD_STATUS.exitstatus
|
data/lib/xcop.rb
CHANGED
@@ -29,6 +29,34 @@ require_relative 'xcop/version'
|
|
29
29
|
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
30
30
|
# License:: MIT
|
31
31
|
module Xcop
|
32
|
+
# Command line interface.
|
33
|
+
class CLI
|
34
|
+
def initialize(files, license)
|
35
|
+
@files = files
|
36
|
+
@license = license
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
@files.each do |f|
|
41
|
+
print "Validating #{f}... "
|
42
|
+
doc = Document.new(f)
|
43
|
+
diff = doc.diff
|
44
|
+
unless diff.empty?
|
45
|
+
puts diff
|
46
|
+
raise "Invalid XML formatting in #{f}"
|
47
|
+
end
|
48
|
+
unless @license.empty?
|
49
|
+
ldiff = doc.ldiff(@license)
|
50
|
+
unless ldiff.empty?
|
51
|
+
puts ldiff
|
52
|
+
raise "Broken license in #{f}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
print "OK\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
32
60
|
# One document.
|
33
61
|
class Document
|
34
62
|
# Ctor.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2017 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'rake'
|
24
|
+
require 'rake/tasklib'
|
25
|
+
require_relative '../xcop'
|
26
|
+
|
27
|
+
# Xcop rake task.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
module Xcop
|
32
|
+
# Rake task.
|
33
|
+
class RakeTask < Rake::TaskLib
|
34
|
+
attr_accessor :name
|
35
|
+
attr_accessor :fail_on_error
|
36
|
+
attr_accessor :excludes
|
37
|
+
attr_accessor :includes
|
38
|
+
attr_accessor :license
|
39
|
+
|
40
|
+
def initialize(*args, &task_block)
|
41
|
+
@name = args.shift || :xcop
|
42
|
+
@includes = %w(xml xsd xhtml xsl html).map { |e| "**/*.#{e}" }
|
43
|
+
@excludes = []
|
44
|
+
@license = nil
|
45
|
+
desc 'Run Xcop' unless ::Rake.application.last_description
|
46
|
+
task(name, *args) do |_, task_args|
|
47
|
+
RakeFileUtils.send(:verbose, true) do
|
48
|
+
yield(*[self, task_args].slice(0, task_block.arity)) if block_given?
|
49
|
+
run
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def run
|
57
|
+
require 'xcop'
|
58
|
+
bad = Dir.glob(@excludes)
|
59
|
+
good = Dir.glob(@includes).reject { |f| bad.include?(f) }
|
60
|
+
begin
|
61
|
+
Xcop::CLI.new(good, @license.nil? ? '' : File.read(@license)).run
|
62
|
+
rescue StandardError => e
|
63
|
+
abort(e.message)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/xcop/version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2017 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
require 'minitest/autorun'
|
24
|
+
require 'tmpdir'
|
25
|
+
require 'rake'
|
26
|
+
require_relative '../lib/xcop/rake_task'
|
27
|
+
|
28
|
+
# Xcop rake task.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class TestRakeTask < Minitest::Test
|
33
|
+
def test_basic
|
34
|
+
Dir.mktmpdir 'test' do |dir|
|
35
|
+
Dir.chdir(dir)
|
36
|
+
File.write('a.xml', "<?xml version=\"1.0\"?>\n<x/>\n")
|
37
|
+
Xcop::RakeTask.new(:xcop1) do |task|
|
38
|
+
# task.license = 'LICENSE.txt'
|
39
|
+
end
|
40
|
+
Rake::Task['xcop1'].invoke
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_with_broken_xml
|
45
|
+
Dir.mktmpdir 'test' do |dir|
|
46
|
+
Dir.chdir(dir)
|
47
|
+
File.write('broken.xml', "<z><a><b></b></a>\n\n</z>")
|
48
|
+
Xcop::RakeTask.new(:xcop2) do |task|
|
49
|
+
task.excludes = ['test/**/*']
|
50
|
+
end
|
51
|
+
assert_raises SystemExit do
|
52
|
+
Rake::Task['xcop2'].invoke
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -190,11 +190,14 @@ files:
|
|
190
190
|
- cucumber.yml
|
191
191
|
- features/cli.feature
|
192
192
|
- features/gem_package.feature
|
193
|
+
- features/rake.feature
|
193
194
|
- features/step_definitions/steps.rb
|
194
195
|
- features/support/env.rb
|
195
196
|
- lib/xcop.rb
|
197
|
+
- lib/xcop/rake_task.rb
|
196
198
|
- lib/xcop/version.rb
|
197
199
|
- test/test__helper.rb
|
200
|
+
- test/test_rake_task.rb
|
198
201
|
- test/test_xcop.rb
|
199
202
|
- xcop.gemspec
|
200
203
|
homepage: http://github.com/yegor256/xcop
|
@@ -225,7 +228,9 @@ summary: XML Formatting Static Validator
|
|
225
228
|
test_files:
|
226
229
|
- features/cli.feature
|
227
230
|
- features/gem_package.feature
|
231
|
+
- features/rake.feature
|
228
232
|
- features/step_definitions/steps.rb
|
229
233
|
- features/support/env.rb
|
230
234
|
- test/test__helper.rb
|
235
|
+
- test/test_rake_task.rb
|
231
236
|
- test/test_xcop.rb
|