text_to_checkstyle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fbd3fb46d72ad00db1674673fed519bd9f35349
4
+ data.tar.gz: 526ed8d8eb4bb60f98aa4b48f7d75af727d47f87
5
+ SHA512:
6
+ metadata.gz: 54d61854f2ef705b771bc8627094cf61135d318c9182474959a20e69a322ee3e4d3b21477a964a48f3b52d4d2c47835f4a223f0210e5a95d81744a4dd7a7a4fc
7
+ data.tar.gz: 8402bae0fd2891f1d80bc3233fea27b84e7cce1ac05487ba42b85c98d845482dc3441157f1806f263105f7c497c6c24f2c73e458f38445cfe989a4423c23674f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /node_modules/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bundle_bin/*'
4
+ - 'vendor/bundle/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Style/FileName:
13
+ Exclude:
14
+ - exe/*
15
+
16
+ Style/RegexpLiteral:
17
+ MaxSlashes: 0
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.1.0 (2015-03-17)
2
+
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in text_to_checkstyle.gemspec
4
+ gemspec
5
+ gem 'byebug' if RUBY_VERSION >= '2.0.0'
6
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sanemat
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
13
+ all 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 NONINFRINGEMENT. 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # TextToCheckstyle
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/text_to_checkstyle.svg?style=flat)](http://badge.fury.io/rb/text_to_checkstyle)
4
+ [![Build Status](http://img.shields.io/travis/packsaddle/ruby-text_to_checkstyle/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-text_to_checkstyle)
5
+
6
+ ## Usage
7
+
8
+ Text message to Checkstyle format.
9
+
10
+ ```bash
11
+ $ echo -n "This line includes a error." | text-to-checkstyle
12
+ <?xml version='1.0'?><checkstyle><file name='path/to/file'><error column='0' line='0' message='This line includes a error.' severity='info' source='TextToCheckstyle'/></file></checkstyle>
13
+ ```
14
+
15
+ ## Command
16
+
17
+ ```text
18
+ Commands:
19
+ text-to-checkstyle convert # Convert text to checkstyle
20
+ text-to-checkstyle help [COMMAND] # Describe available commands or one specific command
21
+ text-to-checkstyle version # Show the TextToCheckstyle version
22
+
23
+ Usage:
24
+ text-to-checkstyle convert
25
+
26
+ Options:
27
+ [--debug], [--no-debug]
28
+ [--verbose], [--no-verbose]
29
+ [--data=DATA]
30
+ [--file=FILE]
31
+ [--name=NAME]
32
+ # Default: path/to/file
33
+ [--line=LINE]
34
+ # Default: 0
35
+ [--column=COLUMN]
36
+ # Default: 0
37
+ [--severity=SEVERITY]
38
+ # Default: info
39
+ [--source=SOURCE]
40
+ # Default: TextToCheckstyle
41
+
42
+ Convert text to checkstyle
43
+ ```
44
+
45
+ ## Installation
46
+
47
+ Add this line to your application's Gemfile:
48
+
49
+ ```ruby
50
+ gem 'text_to_checkstyle'
51
+ ```
52
+
53
+ And then execute:
54
+
55
+ $ bundle
56
+
57
+ Or install it yourself as:
58
+
59
+ $ gem install text_to_checkstyle
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec text_to_checkstyle` to use the code located in this directory, ignoring other installed copies of this gem.
64
+
65
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( https://github.com/packsaddle/ruby-text_to_checkstyle/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'text_to_checkstyle'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ var fs = require('fs');
4
+ var execSync = require('child_process').execSync;
5
+ var conventionalChangelog = require('conventional-changelog');
6
+
7
+ var version = "" + execSync('ruby -e \'require "./lib/text_to_checkstyle/version"; print TextToCheckstyle::VERSION\'');
8
+
9
+ conventionalChangelog({
10
+ repository: 'https://github.com/packsaddle/ruby-text_to_checkstyle',
11
+ version: version,
12
+ file: 'CHANGELOG.md'
13
+ }, function(err, log) {
14
+ fs.writeFile('CHANGELOG.md', log, function(err){
15
+ console.log(err);
16
+ });
17
+ console.log('Here is your changelog!', log);
18
+ });
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'text_to_checkstyle'
4
+ require 'text_to_checkstyle/cli'
5
+ TextToCheckstyle::CLI.start(ARGV)
@@ -0,0 +1,26 @@
1
+ require 'logger'
2
+ require 'rexml/document'
3
+
4
+ require 'text_to_checkstyle/converter'
5
+ require 'text_to_checkstyle/error'
6
+ require 'text_to_checkstyle/version'
7
+
8
+ module TextToCheckstyle
9
+ ISSUE_URL = 'https://github.com/packsaddle/ruby-text_to_checkstyle/issues/new'
10
+
11
+ def self.default_logger
12
+ logger = Logger.new(STDERR)
13
+ logger.progname = "TextToCheckstyle/#{VERSION}"
14
+ logger.level = Logger::WARN
15
+ logger
16
+ end
17
+
18
+ def self.logger
19
+ return @logger if @logger
20
+ @logger = default_logger
21
+ end
22
+
23
+ class << self
24
+ attr_writer :logger
25
+ end
26
+ end
@@ -0,0 +1,80 @@
1
+ require 'thor'
2
+
3
+ module TextToCheckstyle
4
+ class CLI < Thor
5
+ def self.exit_on_failure?
6
+ true
7
+ end
8
+
9
+ desc 'version', 'Show the TextToCheckstyle version'
10
+ map %w(-v --version) => :version
11
+
12
+ def version
13
+ puts "TextToCheckstyle version #{::TextToCheckstyle::VERSION}"
14
+ end
15
+
16
+ desc 'convert', 'Convert text to checkstyle'
17
+ option :debug, type: :boolean, default: false
18
+ option :verbose, type: :boolean, default: false
19
+ option :data
20
+ option :file
21
+ option :name, type: :string, default: Converter::FILE_NAME
22
+ option :line, type: :string, default: Converter::ERROR_LINE
23
+ option :column, type: :string, default: Converter::ERROR_COLUMN
24
+ option :severity, type: :string, default: Converter::ERROR_SEVERITY
25
+ option :source, type: :string, default: Converter::ERROR_SOURCE
26
+ def convert
27
+ setup_logger(options)
28
+ data = \
29
+ if options[:data]
30
+ options[:data]
31
+ elsif options[:file]
32
+ File.read(options[:file])
33
+ elsif !$stdin.tty?
34
+ ARGV.clear
35
+ ARGF.read
36
+ end
37
+
38
+ fail(NoInputError) if !data || data.empty?
39
+ params = {
40
+ name: options[:name],
41
+ line: options[:line],
42
+ column: options[:column],
43
+ severity: options[:severity],
44
+ source: options[:source]
45
+ }
46
+ puts ::TextToCheckstyle::Converter.convert(data, params)
47
+ rescue StandardError => e
48
+ suggest_messages(options)
49
+ raise e
50
+ end
51
+ default_command :convert
52
+
53
+ no_commands do
54
+ def logger
55
+ ::TextToCheckstyle.logger
56
+ end
57
+
58
+ def setup_logger(options)
59
+ if options[:debug]
60
+ logger.level = Logger::DEBUG
61
+ elsif options[:verbose]
62
+ logger.level = Logger::INFO
63
+ end
64
+ logger.debug(options)
65
+ end
66
+
67
+ def suggest_messages(options)
68
+ logger.error 'Have a question? Please ask us:'
69
+ logger.error ISSUE_URL
70
+ logger.error 'options:'
71
+ logger.error options
72
+ end
73
+
74
+ # http://stackoverflow.com/a/23955971/104080
75
+ def method_missing(method, *args)
76
+ self.class.start([self.class.default_command, method.to_s] + args)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,34 @@
1
+ module TextToCheckstyle
2
+ class Converter
3
+ FILE_NAME = 'path/to/file'
4
+ ERROR_LINE = '0'
5
+ ERROR_COLUMN = '0'
6
+ ERROR_SEVERITY = 'info'
7
+ ERROR_SOURCE = 'TextToCheckstyle'
8
+ def self.convert(text, options = {})
9
+ fail NoInputError if !text || text.empty?
10
+ logger.info(text: text)
11
+
12
+ doc = REXML::Document.new
13
+ doc.add REXML::XMLDecl.new
14
+ checkstyle = doc.add_element 'checkstyle'
15
+ name = options[:name] || FILE_NAME
16
+ file = checkstyle.add_element 'file', 'name' => name
17
+ line = options[:line] || ERROR_LINE
18
+ column = options[:column] || ERROR_COLUMN
19
+ severity = options[:severity] || ERROR_SEVERITY
20
+ message = text
21
+ source = options[:source] || ERROR_SOURCE
22
+ file.add_element 'error',
23
+ 'line' => line,
24
+ 'column' => column,
25
+ 'severity' => severity,
26
+ 'message' => message,
27
+ 'source' => source
28
+ doc.to_s
29
+ end
30
+ def self.logger
31
+ ::TextToCheckstyle.logger
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module TextToCheckstyle
2
+ class NoInputError < StandardError; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module TextToCheckstyle
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'text_to_checkstyle/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'text_to_checkstyle'
8
+ spec.version = TextToCheckstyle::VERSION
9
+ spec.authors = ['sanemat']
10
+ spec.email = ['o.gata.ken@gmail.com']
11
+
12
+ spec.summary = 'Transform text format to checkstyle format.'
13
+ spec.description = 'Transform text format to checkstyle format.'
14
+ spec.homepage = 'https://github.com/packsaddle/ruby-text_to_checkstyle'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = \
18
+ `git ls-files -z`
19
+ .split("\x0")
20
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ .reject do |f|
22
+ [
23
+ '.travis.yml',
24
+ 'circle.yml',
25
+ '.tachikoma.yml',
26
+ 'package.json'
27
+ ].include?(f)
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+ spec.add_runtime_dependency 'thor', '>= 0'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.8'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'test-unit', '>= 0'
37
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: text_to_checkstyle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sanemat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-16 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Transform text format to checkstyle format.
70
+ email:
71
+ - o.gata.ken@gmail.com
72
+ executables:
73
+ - text-to-checkstyle
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/conventional-changelog
87
+ - bin/setup
88
+ - exe/text-to-checkstyle
89
+ - lib/text_to_checkstyle.rb
90
+ - lib/text_to_checkstyle/cli.rb
91
+ - lib/text_to_checkstyle/converter.rb
92
+ - lib/text_to_checkstyle/error.rb
93
+ - lib/text_to_checkstyle/version.rb
94
+ - text_to_checkstyle.gemspec
95
+ homepage: https://github.com/packsaddle/ruby-text_to_checkstyle
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Transform text format to checkstyle format.
119
+ test_files: []