pmd_translate_checkstyle_format 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7b7e33a27ea02ad0cb0b0fd4f83471a71fd54bb
|
4
|
+
data.tar.gz: be86421a1930d313cfbbe1d67e68655c019539c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|