pmdtester 1.0.0.pre.beta3 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/build.sh +67 -0
- data/.ci/files/env.gpg +1 -0
- data/.ci/inc/install-openjdk.inc +26 -0
- data/.ci/manual-integration-tests.sh +20 -0
- data/.github/workflows/build.yml +39 -0
- data/.github/workflows/manual-integration-tests.yml +32 -0
- data/.gitignore +9 -0
- data/.hoerc +1 -1
- data/.rubocop.yml +13 -2
- data/.rubocop_todo.yml +7 -8
- data/.ruby-version +1 -0
- data/Gemfile +1 -12
- data/History.md +104 -0
- data/Manifest.txt +30 -6
- data/README.rdoc +110 -60
- data/Rakefile +27 -15
- data/config/all-java.xml +1 -1
- data/config/design.xml +1 -1
- data/config/projectlist_1_0_0.xsd +2 -1
- data/config/projectlist_1_1_0.xsd +31 -0
- data/lib/pmdtester.rb +12 -4
- data/lib/pmdtester/builders/liquid_renderer.rb +73 -0
- data/lib/pmdtester/builders/pmd_report_builder.rb +134 -60
- data/lib/pmdtester/builders/project_builder.rb +100 -0
- data/lib/pmdtester/builders/project_hasher.rb +126 -0
- data/lib/pmdtester/builders/rule_set_builder.rb +94 -48
- data/lib/pmdtester/builders/simple_progress_logger.rb +27 -0
- data/lib/pmdtester/builders/summary_report_builder.rb +62 -117
- data/lib/pmdtester/cmd.rb +15 -1
- data/lib/pmdtester/collection_by_file.rb +55 -0
- data/lib/pmdtester/parsers/options.rb +25 -2
- data/lib/pmdtester/parsers/pmd_report_document.rb +79 -27
- data/lib/pmdtester/parsers/projects_parser.rb +2 -4
- data/lib/pmdtester/pmd_branch_detail.rb +36 -12
- data/lib/pmdtester/pmd_configerror.rb +62 -0
- data/lib/pmdtester/pmd_error.rb +34 -34
- data/lib/pmdtester/pmd_report_detail.rb +10 -13
- data/lib/pmdtester/pmd_tester_utils.rb +57 -0
- data/lib/pmdtester/pmd_violation.rb +66 -26
- data/lib/pmdtester/project.rb +28 -23
- data/lib/pmdtester/report_diff.rb +194 -70
- data/lib/pmdtester/resource_locator.rb +4 -0
- data/lib/pmdtester/runner.rb +81 -54
- data/pmdtester.gemspec +64 -0
- data/resources/_includes/diff_pill_row.html +6 -0
- data/resources/css/bootstrap.min.css +7 -0
- data/resources/css/datatables.min.css +36 -0
- data/resources/css/pmd-tester.css +132 -0
- data/resources/js/bootstrap.min.js +7 -0
- data/resources/js/code-snippets.js +73 -0
- data/resources/js/datatables.min.js +726 -0
- data/resources/js/jquery-3.2.1.slim.min.js +4 -0
- data/resources/js/jquery.min.js +2 -0
- data/resources/js/popper.min.js +5 -0
- data/resources/js/project-report.js +136 -0
- data/resources/project_diff_report.html +205 -0
- data/resources/project_index.html +102 -0
- metadata +122 -38
- data/.travis.yml +0 -22
- data/lib/pmdtester/builders/diff_builder.rb +0 -30
- data/lib/pmdtester/builders/diff_report_builder.rb +0 -225
- data/lib/pmdtester/builders/html_report_builder.rb +0 -33
- data/resources/css/maven-base.css +0 -155
- data/resources/css/maven-theme.css +0 -171
data/README.rdoc
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
= pmdtester
|
2
2
|
|
3
|
+
home :: https://pmd.github.io
|
3
4
|
code :: https://github.com/pmd/pmd-regression-tester
|
4
5
|
bugs :: https://github.com/pmd/pmd-regression-tester/issues
|
5
6
|
|
6
|
-
build-status :: {<img src="https://
|
7
|
+
build-status :: {<img src="https://github.com/pmd/pmd-regression-tester/workflows/build/badge.svg?branch=master" alt="Build Status" />}[https://github.com/pmd/pmd-regression-tester/actions?query=workflow%3Abuild]
|
8
|
+
|
9
|
+
gem-version :: {<img src="https://badge.fury.io/rb/pmdtester.svg" alt="Gem Version" />}[https://rubygems.org/gems/pmdtester]
|
7
10
|
|
8
11
|
== DESCRIPTION:
|
9
12
|
|
@@ -15,82 +18,110 @@ The diff report can be generated according to the base and patch branch of PMD
|
|
15
18
|
on a list of standard projects(Spring Framework, Hibernate, Solr, etc.)
|
16
19
|
|
17
20
|
== SYNOPSIS:
|
18
|
-
|
19
|
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
21
|
+
|
22
|
+
=== Options:
|
23
|
+
-r, --local-git-repo path to the local PMD repository
|
24
|
+
-b, --base-branch name of the base branch in local PMD repository
|
25
|
+
-p, --patch-branch name of the patch branch in local PMD repository
|
26
|
+
-bc, --base-config path to the base PMD configuration file default:PMDTESTER_INSTALLED_DIR/config/all-java.xml
|
27
|
+
-pc, --patch-config path to the patch PMD configuration file default:PMDTESTER_INSTALLED_DIR/config/all-java.xml
|
28
|
+
-c, --config path to the base and patch PMD configuration file
|
29
|
+
-l, --list-of-project path to the file which contains the list of standard projects default:PMDTESTER_INSTALLED_DIR/config/project-list.xml
|
30
|
+
-m, --mode the mode of the tool: 'local', 'online' or 'single'
|
27
31
|
single: Set this option to 'single' if your patch branch contains changes
|
28
32
|
for any option that can't work on master/base branch
|
29
33
|
online: Set this option to 'online' if you want to download
|
30
34
|
the PMD report of master/base branch rather than generating it locally
|
31
35
|
local: Default option is 'local', PMD reports for the base and patch branches are generated locally.
|
32
36
|
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
37
|
+
-t, --threads Sets the number of threads used by PMD. Set threads to 0 to disable multi-threading processing. default:1
|
38
|
+
-f, --html-flag whether to not generate the html diff report in single mode
|
39
|
+
-a, --auto-gen-config whether to generate configurations automatically based on branch differences,this option only works in online and local mode
|
40
|
+
--keep-reports whether to keep old reports and skip running PMD again if possible
|
41
|
+
-d, --debug whether change log level to DEBUG to see more information
|
42
|
+
--error-recovery enable error recovery mode when executing PMD. Might help to analyze errors.
|
43
|
+
--baseline-download-url download url prefix from where to download the baseline in online mode default:https://sourceforge.net/projects/pmd/files/pmd-regression-tester/
|
44
|
+
-v, --version
|
45
|
+
-h, --help
|
46
|
+
|
38
47
|
=== Quick start
|
48
|
+
|
39
49
|
==== Run local mode
|
40
|
-
|
50
|
+
|
51
|
+
pmdtester -b master -p YOUR_DEVELOPMENT_BRANCH -r PATH_TO_LOCAL_PMD_REPO -a
|
52
|
+
|
41
53
|
==== Run single mode
|
54
|
+
|
42
55
|
pmdtester -p YOUR_DEVELOPMENT_BRANCH -pc CONFIG_ONLY_CONTAINS_NEW_PMD_JAVA_RULE -m single
|
56
|
+
|
43
57
|
==== Run online mode
|
44
|
-
|
58
|
+
|
59
|
+
pmdtester -b master -p YOUR_DEVELOPMENT_BRANCH -r PATH_TO_LOCAL_PMD_REPO -m online -a
|
60
|
+
|
45
61
|
=== Output
|
46
62
|
The tool creates the following folders:
|
47
|
-
target
|
48
|
-
├── repositories <- the analyzed projects are cloned here
|
49
|
-
│ ├── PROJECT_NAME_1
|
50
|
-
│ ├── ......
|
51
|
-
│ └── PROJECT_NAME_n
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
├──
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
target
|
64
|
+
├── repositories <- the analyzed projects are cloned here
|
65
|
+
│ ├── PROJECT_NAME_1
|
66
|
+
│ ├── ......
|
67
|
+
│ └── PROJECT_NAME_n
|
68
|
+
├── reports
|
69
|
+
│ ├── BASE_BRANCH_NAME <- the base baseline is placed here
|
70
|
+
│ ├── PATCH_BRANCH_NAME <- the patch baseline is placed here
|
71
|
+
│ └── diff
|
72
|
+
│ ├── index.html <- the summary report of diff reports
|
73
|
+
│ ├── base_config.xml <- pmd config from the base branch
|
74
|
+
│ ├── patch_config.xml <- pmd config from the patch branch
|
75
|
+
│ ├── css <- css resources are placed here
|
76
|
+
│ ├── js <- js resources
|
77
|
+
│ ├── PROJECT_NAME_1
|
78
|
+
│ │ ├── project_data.js <- contains the violations as js/json
|
79
|
+
│ │ └── index.html <- the diff report of PROJECT_1
|
80
|
+
│ ├── .......
|
81
|
+
│ └── PROJECT_NAME_n
|
82
|
+
│ ├── project_data.js <- contains the violations as js/json
|
83
|
+
│ └── index.xml <- the diff report of PROJECT_N
|
84
|
+
├── pmd-bin-<version>-<branch_name>-<sha1> <- cached pmd builds that are reused
|
85
|
+
└── pmd-bin-....
|
86
|
+
|
87
|
+
==== The baseline format
|
88
|
+
branch_name
|
89
|
+
├── branch_info.json
|
90
|
+
├── config.xml
|
91
|
+
├── STANDARD_PROJECT_NAME_1
|
92
|
+
│ ├── report_info.json
|
93
|
+
│ └── pmd_report.xml
|
94
|
+
├── ......................
|
95
|
+
│ ├── report_info.json
|
96
|
+
│ └── pmd_report.xml
|
97
|
+
└── STANDARD_PROJECT_NAME_n
|
76
98
|
├── report_info.info
|
77
|
-
└── pmd_report.xml
|
99
|
+
└── pmd_report.xml
|
78
100
|
|
79
101
|
== REQUIREMENTS:
|
80
|
-
|
102
|
+
|
103
|
+
* Ruby 2.7 or higher
|
104
|
+
|
81
105
|
=== Runtime dependency
|
82
|
-
|
83
|
-
|
106
|
+
|
107
|
+
nokogiri >= 1.11.0.rc4
|
108
|
+
slop ~> 4.6
|
109
|
+
differ ~> 0.1
|
110
|
+
rufus-scheduler ~> 3.5
|
111
|
+
logger-colors ~> 1.0
|
112
|
+
liquid >= 4.0
|
113
|
+
|
84
114
|
=== Development dependency
|
85
|
-
|
86
|
-
hoe
|
115
|
+
|
116
|
+
hoe ~> 3.22
|
117
|
+
hoe-bundler ~> 1.5
|
87
118
|
hoe-git ~> 1.6
|
88
|
-
minitest ~> 5.10
|
89
|
-
mocha ~> 1.5
|
90
|
-
rdoc <
|
91
|
-
rubocop ~> 0.
|
92
|
-
test-unit ~> 3.2
|
93
|
-
|
119
|
+
minitest ~> 5.10
|
120
|
+
mocha ~> 1.5
|
121
|
+
rdoc < 7, >= 4.0
|
122
|
+
rubocop ~> 0.81
|
123
|
+
test-unit ~> 3.2
|
124
|
+
|
94
125
|
== INSTALL:
|
95
126
|
|
96
127
|
gem install pmdtester --pre
|
@@ -99,8 +130,27 @@ The tool creates the following folders:
|
|
99
130
|
git clone https://github.com/pmd/pmd-regression-tester.git
|
100
131
|
cd pmd-regression-tester
|
101
132
|
gem install bundler
|
102
|
-
bundle
|
103
|
-
|
133
|
+
bundle config set path "vendor/cache"
|
134
|
+
bundle install # once
|
135
|
+
bundle exec rake verify # run this command before commit your changes
|
136
|
+
bundle exec pmdtester ... # run this to directly execute pmdtester from source
|
137
|
+
|
138
|
+
Run a single test class, e.g.:
|
139
|
+
bundle exec ruby -I test test/test_diff_report_builder.rb
|
104
140
|
|
141
|
+
Run a single test, e.g.:
|
142
|
+
bundle exec ruby -I test test/test_diff_report_builder.rb -n test_diff_report_builder
|
105
143
|
|
144
|
+
=== Releasing
|
106
145
|
|
146
|
+
* Update +History.md+ (version and date)
|
147
|
+
* Update +lib/pmdtester.rb+ (version)
|
148
|
+
* Run "bundle exec rake verify" and add new +pmdtester.gemspec+ (new version)
|
149
|
+
* Commit ("Prepare release x.y.z").
|
150
|
+
* Tag this commit ("git tag vx.y.z").
|
151
|
+
* Update History.md and lib/pmdtester.rb for the next development version,
|
152
|
+
run again "bundle exec rake verify"
|
153
|
+
* Commit ("Prepare next development version x.y.z-SNAPSHOT").
|
154
|
+
* Push to master.
|
155
|
+
* Push the tag. Github Actions will build and publish the new gem
|
156
|
+
* Update the release notes on https://github.com/pmd/pmd-regression-tester/releases
|
data/Rakefile
CHANGED
@@ -14,29 +14,32 @@ Hoe.plugin :git
|
|
14
14
|
hoe = Hoe.spec 'pmdtester' do
|
15
15
|
self.version = PmdTester::VERSION
|
16
16
|
|
17
|
-
developer 'Andreas Dangel', 'andreas.dangel@
|
17
|
+
developer 'Andreas Dangel', 'andreas.dangel@pmd-code.org'
|
18
18
|
developer 'Binguo Bao', 'djydewang@gmail.com'
|
19
|
+
developer 'Clément Fournier', 'clement.fournier76@gmail.com'
|
19
20
|
|
20
|
-
self.clean_globs = %w[target/reports/**/* target/test/**/* Gemfile.lock]
|
21
|
-
self.extra_deps += [['nokogiri', '
|
22
|
-
|
23
|
-
|
21
|
+
self.clean_globs = %w[target/reports/**/* target/test/**/* target/dynamic-config.xml Gemfile.lock]
|
22
|
+
self.extra_deps += [['nokogiri', '>= 1.11.0.rc4'], ['slop', '~> 4.6'], ['differ', '~> 0.1'],
|
23
|
+
['rufus-scheduler', '~> 3.5'], ['logger-colors', '~> 1.0'],
|
24
|
+
['liquid', '>= 4.0']]
|
25
|
+
self.extra_dev_deps += [
|
26
|
+
['hoe-bundler', '~> 1.5'],
|
24
27
|
['hoe-git', '~> 1.6'],
|
25
|
-
['minitest', '~> 5.10
|
26
|
-
['mocha', '~> 1.5
|
27
|
-
|
28
|
-
['
|
28
|
+
['minitest', '~> 5.10'],
|
29
|
+
['mocha', '~> 1.5'],
|
30
|
+
# use the same version of rubocop as codacy
|
31
|
+
['rubocop', '~> 0.81'],
|
32
|
+
['test-unit', '~> 3.2'],
|
33
|
+
['rdoc', ['>= 4.0', '< 7']]
|
29
34
|
]
|
30
|
-
|
35
|
+
spec_extras[:required_ruby_version] = '>= 2.7'
|
31
36
|
|
32
37
|
license 'BSD-2-Clause'
|
33
38
|
end
|
34
39
|
|
35
40
|
# Refers to
|
36
41
|
# http://rubocop.readthedocs.io/en/latest/integration_with_other_tools/#rake-integration
|
37
|
-
RuboCop::RakeTask.new(:rubocop)
|
38
|
-
task.patterns = %w[lib/**/*.rb test/**/*.rb]
|
39
|
-
end
|
42
|
+
RuboCop::RakeTask.new(:rubocop)
|
40
43
|
|
41
44
|
# Run integration test cases
|
42
45
|
Rake::TestTask.new('integration-test') do |task|
|
@@ -48,9 +51,18 @@ end
|
|
48
51
|
|
49
52
|
desc 'generate the pmdtester.gemspec file'
|
50
53
|
task 'hoe:spec' do
|
51
|
-
|
54
|
+
attention_message = '# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake hoe:spec`.'
|
55
|
+
File.open("#{hoe.name}.gemspec", 'w') do |f|
|
56
|
+
f.puts attention_message
|
57
|
+
f.puts
|
58
|
+
f.write hoe.spec.to_ruby
|
59
|
+
f.puts
|
60
|
+
f.puts attention_message
|
61
|
+
end
|
52
62
|
end
|
53
63
|
|
54
64
|
desc 'verify code quality before committing changes'
|
55
|
-
task 'verify' => ['clean', 'test', 'rubocop', '
|
65
|
+
task 'verify' => ['clean', 'test', 'rubocop', 'git:manifest', 'hoe:spec', 'check_manifest'] do
|
66
|
+
Rake.application.invoke_task('bundler:gemfile[,true]')
|
67
|
+
end
|
56
68
|
# vim: syntax=ruby
|
data/config/all-java.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<ruleset name="All Java Rules"
|
4
4
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
5
5
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
6
|
-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
|
6
|
+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
7
7
|
<description>Every Java Rule in PMD</description>
|
8
8
|
|
9
9
|
<rule ref="category/java/bestpractices.xml" />
|
data/config/design.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<ruleset name="Design"
|
4
4
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
5
5
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
6
|
-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
|
6
|
+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
7
7
|
|
8
8
|
<description>
|
9
9
|
The Design ruleset contains rules that flag suboptimal code implementations. Alternate approaches
|
@@ -1,4 +1,5 @@
|
|
1
1
|
<?xml version="1.0" ?>
|
2
|
+
<!-- version 1.0.0 -->
|
2
3
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
3
4
|
<xs:element name="projectlist">
|
4
5
|
<xs:complexType>
|
@@ -25,4 +26,4 @@
|
|
25
26
|
<xs:element name="exclude-pattern" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
|
26
27
|
</xs:sequence>
|
27
28
|
</xs:complexType>
|
28
|
-
</xs:schema>
|
29
|
+
</xs:schema>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!-- version 1.1.0 -->
|
3
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
4
|
+
<xs:element name="projectlist">
|
5
|
+
<xs:complexType>
|
6
|
+
<xs:sequence>
|
7
|
+
<xs:element name="description" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
8
|
+
<xs:element name="project" type="project" minOccurs="1" maxOccurs="unbounded"/>
|
9
|
+
</xs:sequence>
|
10
|
+
</xs:complexType>
|
11
|
+
</xs:element>
|
12
|
+
<xs:complexType name="project">
|
13
|
+
<xs:sequence>
|
14
|
+
<xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
15
|
+
<xs:element name="type" minOccurs="1" maxOccurs="1">
|
16
|
+
<xs:simpleType>
|
17
|
+
<xs:restriction base="xs:string">
|
18
|
+
<xs:enumeration value="git"/>
|
19
|
+
<xs:enumeration value="hg"/>
|
20
|
+
</xs:restriction>
|
21
|
+
</xs:simpleType>
|
22
|
+
</xs:element>
|
23
|
+
<xs:element name="connection" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
24
|
+
<xs:element name="webview-url" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
25
|
+
<xs:element name="tag" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
26
|
+
<xs:element name="exclude-pattern" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
|
27
|
+
<xs:element name="build-command" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
28
|
+
<xs:element name="auxclasspath-command" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
29
|
+
</xs:sequence>
|
30
|
+
</xs:complexType>
|
31
|
+
</xs:schema>
|
data/lib/pmdtester.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'logger'
|
4
|
+
require 'logger/colors'
|
4
5
|
|
5
6
|
require_relative 'pmdtester/cmd'
|
7
|
+
require_relative 'pmdtester/collection_by_file'
|
6
8
|
require_relative 'pmdtester/pmd_branch_detail'
|
9
|
+
require_relative 'pmdtester/pmd_configerror'
|
7
10
|
require_relative 'pmdtester/pmd_error'
|
8
11
|
require_relative 'pmdtester/pmd_report_detail'
|
12
|
+
require_relative 'pmdtester/pmd_tester_utils'
|
9
13
|
require_relative 'pmdtester/pmd_violation'
|
10
14
|
require_relative 'pmdtester/project'
|
11
15
|
require_relative 'pmdtester/report_diff'
|
12
16
|
require_relative 'pmdtester/resource_locator'
|
13
17
|
require_relative 'pmdtester/runner'
|
14
18
|
|
15
|
-
require_relative 'pmdtester/builders/
|
16
|
-
require_relative 'pmdtester/builders/
|
17
|
-
require_relative 'pmdtester/builders/
|
19
|
+
require_relative 'pmdtester/builders/simple_progress_logger'
|
20
|
+
require_relative 'pmdtester/builders/project_builder'
|
21
|
+
require_relative 'pmdtester/builders/project_hasher'
|
18
22
|
require_relative 'pmdtester/builders/pmd_report_builder'
|
23
|
+
require_relative 'pmdtester/builders/liquid_renderer'
|
19
24
|
require_relative 'pmdtester/builders/rule_set_builder'
|
20
25
|
require_relative 'pmdtester/builders/summary_report_builder'
|
21
26
|
|
@@ -27,7 +32,10 @@ require_relative 'pmdtester/parsers/projects_parser'
|
|
27
32
|
# and unexpected behaviors will not be introduced to PMD project
|
28
33
|
# after fixing an issue and new rules can work as expected.
|
29
34
|
module PmdTester
|
30
|
-
VERSION = '1.
|
35
|
+
VERSION = '1.1.2'
|
36
|
+
BASE = 'base'
|
37
|
+
PATCH = 'patch'
|
38
|
+
PR_NUM_ENV_VAR = 'PMD_CI_PULL_REQUEST_NUMBER' # see PmdBranchDetail
|
31
39
|
|
32
40
|
def logger
|
33
41
|
PmdTester.logger
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'liquid'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module PmdTester
|
7
|
+
# A module to include in classes that use a Liquid template
|
8
|
+
# to generate content.
|
9
|
+
module LiquidRenderer
|
10
|
+
include PmdTester
|
11
|
+
|
12
|
+
def render_liquid(template_path, env)
|
13
|
+
to_render = File.read(ResourceLocator.resource(template_path))
|
14
|
+
includes = Liquid::LocalFileSystem.new(ResourceLocator.resource('_includes'), '%s.html')
|
15
|
+
Liquid::Template.file_system = includes
|
16
|
+
template = Liquid::Template.parse(to_render, error_mode: :strict)
|
17
|
+
template.render!(env, { strict_variables: true })
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_and_write(template_path, target_file, env)
|
21
|
+
write_file(target_file, render_liquid(template_path, env))
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_file(target_file, contents)
|
25
|
+
dir = File.dirname(target_file)
|
26
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
27
|
+
|
28
|
+
index = File.new(target_file, 'w')
|
29
|
+
index&.puts contents # may be nil when stubbing
|
30
|
+
logger&.info "Written #{target_file}"
|
31
|
+
ensure
|
32
|
+
index&.close
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_resource(dir, to_root)
|
36
|
+
src = ResourceLocator.resource(dir)
|
37
|
+
dest = "#{to_root}/#{dir}"
|
38
|
+
FileUtils.copy_entry(src, dest)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Renders the index of a project diff report.
|
43
|
+
class LiquidProjectRenderer
|
44
|
+
include PmdTester
|
45
|
+
include ProjectHasher
|
46
|
+
include LiquidRenderer
|
47
|
+
|
48
|
+
def write_project_index(project, root)
|
49
|
+
liquid_env = {
|
50
|
+
'diff' => report_diff_to_h(project.report_diff),
|
51
|
+
'error_diffs' => errors_to_h(project),
|
52
|
+
'configerror_diffs' => configerrors_to_h(project),
|
53
|
+
'project_name' => project.name
|
54
|
+
}
|
55
|
+
|
56
|
+
# Renders index.html using liquid
|
57
|
+
write_file("#{root}/index.html", render_liquid('project_diff_report.html', liquid_env))
|
58
|
+
# generate array of violations in json
|
59
|
+
write_file("#{root}/project_data.js", dump_violations_json(project))
|
60
|
+
end
|
61
|
+
|
62
|
+
def dump_violations_json(project)
|
63
|
+
h = {
|
64
|
+
'source_link_base' => project.webview_url,
|
65
|
+
'source_link_template' => link_template(project),
|
66
|
+
**violations_to_hash(project)
|
67
|
+
}
|
68
|
+
|
69
|
+
project_data = JSON.fast_generate(h)
|
70
|
+
"let project = #{project_data}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|