pmd_translate_checkstyle_format 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45e5162ca9378cfe0aa9425673ae92f0475d7741
4
- data.tar.gz: d651dd7de4451f2a54362b58fec4f953590540b0
3
+ metadata.gz: f7b7e33a27ea02ad0cb0b0fd4f83471a71fd54bb
4
+ data.tar.gz: be86421a1930d313cfbbe1d67e68655c019539c9
5
5
  SHA512:
6
- metadata.gz: 5f928658ca7e3ac003631cddc2c5105de0bb6da390b76a403e7e7665fd21fa459193f8f4af06ea8e8a6cc09855dd46684d773b3f53bc5b09c426315b7d28311c
7
- data.tar.gz: 2317afa4b0c922722d25f346f283a641e9435a4e3499d4a35443ae35d67d3c86374b674c75ebd3c8f522c973d6d7130207981de7b8dec3e0253b3b5424462dd7
6
+ metadata.gz: a582f20785435aa9223c87f5f47e652941e3d9dc64de9ecbf0c44b296e9364a446c41c43fa8696693480266326dc36f7d6111c45cc10f31352cf82e6e79a2503
7
+ data.tar.gz: dc9c419fdcbbcc13f14375d0abb21c8265c202b79b82d506bb0bc6d68f456f5af3e791d2b86713c52ff74d04a60d47cbb4515587371636d9904ae8904df8bb2e
data/README.md CHANGED
@@ -29,12 +29,14 @@ Or install it yourself as:
29
29
 
30
30
  ```
31
31
  cat pmd.xml | pmd_translate_checkstyle_format translate
32
+ cat cpd.xml | pmd_translate_checkstyle_format translate --cpd-translate # cpd translate
32
33
  ```
33
34
 
34
35
  ### Use command-line option
35
36
 
36
37
  ```
37
38
  pmd_translate_checkstyle_format translate --file="pmd.xml"
39
+ pmd_translate_checkstyle_format translate --file="cpd.xml" --cpd-translate # cpd translate
38
40
  ```
39
41
 
40
42
  ## Development
@@ -6,10 +6,15 @@ module PmdTranslateCheckstyleFormat
6
6
  desc 'translate', 'Exec Translate'
7
7
  option :data
8
8
  option :file
9
+ option 'cpd-translate', type: :boolean
9
10
  def translate
10
11
  data = fetch_data(options)
11
12
  xml = parse(data)
12
- checkstyle = trans(xml)
13
+ if options['cpd-translate']
14
+ checkstyle = trans_cpd(xml)
15
+ elsif
16
+ checkstyle = trans(xml)
17
+ end
13
18
  checkstyle.write(STDOUT, 2)
14
19
  end
15
20
 
@@ -15,7 +15,6 @@ module PmdTranslateCheckstyleFormat
15
15
 
16
16
  checkstyle = doc.add_element("checkstyle")
17
17
  if xml['pmd'].blank? || xml['pmd']['file'].blank?
18
- # set_dummy(xml, checkstyle)
19
18
  return doc
20
19
  end
21
20
 
@@ -25,7 +24,6 @@ module PmdTranslateCheckstyleFormat
25
24
  violations = file['violation']
26
25
  violations = [violations] unless violations.is_a?(Array)
27
26
  violations.each do |violation|
28
- puts violation.attributes
29
27
  file_element = checkstyle.add_element("file", {
30
28
  'name' => file['@name']
31
29
  })
@@ -40,6 +38,36 @@ module PmdTranslateCheckstyleFormat
40
38
  doc
41
39
  end
42
40
 
41
+ def trans_cpd(xml)
42
+ require 'rexml/document'
43
+ doc = REXML::Document.new
44
+ doc << REXML::XMLDecl.new('1.0', 'UTF-8')
45
+
46
+ checkstyle = doc.add_element("checkstyle")
47
+ if xml['pmd_cpd'].blank? || xml['pmd_cpd']['duplication'].blank?
48
+ return doc
49
+ end
50
+
51
+ duplications = xml['pmd_cpd']['duplication']
52
+ duplications = [duplications] if duplications.is_a?(Hash)
53
+ duplications.each do |duplication|
54
+ files = duplication['file']
55
+ files = [files] unless files.is_a?(Array)
56
+ files.each do |file|
57
+ file_element = checkstyle.add_element("file", {
58
+ 'name' => file['@path']
59
+ })
60
+ file_element.add_element("error", {
61
+ 'line' => file['@line'],
62
+ 'severity' => 'error',
63
+ 'message' => create_cpd_message(duplication, file)
64
+ })
65
+ end
66
+ end
67
+
68
+ doc
69
+ end
70
+
43
71
  def get_severity(priority)
44
72
  case priority
45
73
  when 1, 2
@@ -50,5 +78,13 @@ module PmdTranslateCheckstyleFormat
50
78
  'info'
51
79
  end
52
80
  end
81
+
82
+ def create_cpd_message(duplication, file)
83
+ files = duplication['file'].reject { |item| item == file }
84
+ file_names = files.map { |item|
85
+ Pathname.new(item['@path']).relative_path_from(Pathname.new(Dir.pwd)).to_s
86
+ }
87
+ "[PMD-CPD] #{duplication['@lines']} lines duplicated.\n#{file_names.join("\n")}"
88
+ end
53
89
  end
54
90
  end
@@ -1,3 +1,3 @@
1
1
  module PmdTranslateCheckstyleFormat
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pmd_translate_checkstyle_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - noboru-i