Skip to content

Commit c45dcdb

Browse files
committed
Merge branch 'pr-24'
2 parents d2be763 + d749db4 commit c45dcdb

20 files changed

+221
-133
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2018-07-04 23:39:08 +0800 using RuboCop version 0.56.0.
3+
# on 2018-07-12 16:57:46 +0800 using RuboCop version 0.56.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 18
9+
# Offense count: 22
1010
Metrics/AbcSize:
1111
Max: 47
1212

1313
# Offense count: 3
1414
# Configuration parameters: CountComments.
1515
Metrics/ClassLength:
16-
Max: 173
16+
Max: 174
1717

1818
# Offense count: 33
1919
# Configuration parameters: CountComments.
2020
Metrics/MethodLength:
21-
Max: 32
21+
Max: 35
2222

2323
# Offense count: 5
2424
Naming/AccessorMethodName:
2525
Exclude:
2626
- 'lib/pmdtester/builders/pmd_report_builder.rb'
2727
- 'lib/pmdtester/parsers/projects_parser.rb'
28-
29-
# Offense count: 1
30-
Style/MixinUsage:
31-
Exclude:
32-
- 'lib/pmdtester/builders/pmd_report_builder.rb'

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
* [#21](https://github.com/pmd/pmd-regression-tester/pull/21): Add auto-gen-config option for PmdTester - [BBG](https://github.com/djydewang)
2929
* [#22](https://github.com/pmd/pmd-regression-tester/pull/22): Add 'introduce new errors' table head for html summary report - [BBG](https://github.com/djydewang)
3030
* [#23](https://github.com/pmd/pmd-regression-tester/pull/23): Preparing for the release of PmdTester - [BBG](https://github.com/djydewang)
31+
* [#24](https://github.com/pmd/pmd-regression-tester/pull/24): Adding a logging framework for PmdTester - [BBG](https://github.com/djydewang)

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config/design.xml
1313
config/project-list.xml
1414
config/project_list.txt
1515
config/projectlist_1_0_0.xsd
16+
lib/pmdtester/pmdtester.rb
1617
lib/pmdtester/builders/diff_builder.rb
1718
lib/pmdtester/builders/diff_report_builder.rb
1819
lib/pmdtester/builders/html_report_builder.rb

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# -*- ruby -*-
24
require 'rake/testtask'
35
require 'rubocop/rake_task'

bin/pmdtester

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
require_relative '../lib/pmdtester/runner'
35

46
runner = PmdTester::Runner.new(ARGV)

lib/pmdtester/builders/diff_report_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module PmdTester
77
# Building diff report for a single project
88
class DiffReportBuilder < HtmlReportBuilder
9+
include PmdTester
910
NO_DIFFERENCES_MESSAGE = 'No differences found!'
1011

1112
def build(project)
@@ -20,7 +21,7 @@ def build(project)
2021
index.puts html_report
2122
index.close
2223

23-
puts "Built difference report of #{project.name} successfully!"
24+
logger.info "Built difference report of #{project.name} successfully!"
2425
end
2526

2627
def build_body(doc)

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
require_relative '../pmd_branch_detail'
77
require_relative '../pmd_report_detail'
88

9-
include PmdTester
109
module PmdTester
1110
# Building pmd xml reports according to a list of standard
1211
# projects and branch of pmd source code
1312
class PmdReportBuilder
13+
include PmdTester
1414
def initialize(branch_config, projects, local_git_repo, pmd_branch_name)
1515
@branch_config = branch_config
1616
@projects = projects
@@ -27,32 +27,33 @@ def execute_reset_cmd(type, tag)
2727
reset_cmd = "git reset --hard #{tag}"
2828
when 'hg'
2929
reset_cmd = "hg up #{tag}"
30-
else
31-
raise Exception, "Unknown #{type} repository"
3230
end
3331

3432
Cmd.execute(reset_cmd)
3533
end
3634

3735
def get_projects
38-
puts 'Cloning projects started'
36+
logger.info 'Cloning projects started'
3937

4038
@projects.each do |project|
39+
logger.info "Start cloning #{project.name} repository"
4140
path = project.local_source_path
4241
clone_cmd = "#{project.type} clone #{project.connection} #{path}"
4342
if File.exist?(path)
44-
puts "Skipping clone, project path #{path} already exists"
43+
logger.warn "Skipping clone, project path #{path} already exists"
4544
else
4645
Cmd.execute(clone_cmd)
4746
end
4847

4948
Dir.chdir(path) do
5049
execute_reset_cmd(project.type, project.tag)
5150
end
51+
logger.info "Cloning #{project.name} completed"
5252
end
5353
end
5454

5555
def get_pmd_binary_file
56+
logger.info 'Start packaging PMD'
5657
Dir.chdir(@local_git_repo) do
5758
checkout_cmd = "git checkout #{@pmd_branch_name}"
5859
Cmd.execute(checkout_cmd)
@@ -71,6 +72,7 @@ def get_pmd_binary_file
7172
unzip_cmd = "unzip -qo pmd-dist/target/pmd-bin-#{@pmd_version}.zip -d #{@pwd}/target"
7273
Cmd.execute(unzip_cmd)
7374
end
75+
logger.info 'Packaging PMD completed'
7476
end
7577

7678
def get_last_commit_sha
@@ -94,11 +96,12 @@ def generate_pmd_report(src_root_dir, report_file)
9496
end
9597

9698
def generate_pmd_reports
97-
puts "Generating pmd Report started -- branch #{@pmd_branch_name}"
99+
logger.info "Generating PMD report started -- branch #{@pmd_branch_name}"
98100
get_pmd_binary_file
99101

100102
sum_time = 0
101103
@projects.each do |project|
104+
logger.info "Generating #{project.name}'s PMD report'"
102105
execution_time, end_time =
103106
generate_pmd_report(project.local_source_path,
104107
project.get_pmd_report_path(@pmd_branch_name))
@@ -108,6 +111,7 @@ def generate_pmd_reports
108111
report_details.execution_time = execution_time
109112
report_details.timestamp = end_time
110113
report_details.save(project.get_report_info_path(@pmd_branch_name))
114+
logger.info "#{project.name}'s PMD report was generated successfully"
111115
end
112116

113117
@pmd_branch_details.execution_time = sum_time

lib/pmdtester/builders/rule_set_builder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
require 'set'
55
require_relative '../cmd'
66
require_relative '../resource_locator'
7+
78
module PmdTester
89
# This class is responsible for generation dynamic configuration
910
# according to the difference between base and patch branch of Pmd.
1011
# Attention: we only consider java rulesets now.
1112
class RuleSetBuilder
13+
include PmdTester
1214
ALL_RULE_SETS = Set['bestpractices', 'codestyle', 'design', 'documentation',
1315
'errorprone', 'multithreading', 'performance', 'security'].freeze
1416
PATH_TO_PMD_JAVA_BASED_RULES =
@@ -28,6 +30,7 @@ def build
2830
rule_sets = get_rule_sets(filenames)
2931
output_filter_set(rule_sets)
3032
build_config_file(rule_sets)
33+
logger.debug "Dynamic configuration: #{[rule_sets]}"
3134
end
3235

3336
def output_filter_set(rule_sets)

lib/pmdtester/builders/summary_report_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
module PmdTester
77
# Building summary report to show the details about projects and pmd branchs
88
class SummaryReportBuilder < HtmlReportBuilder
9+
include PmdTester
910
REPORT_DIR = 'target/reports/diff'
1011
BASE_CONFIG_PATH = 'target/reports/diff/base_config.xml'
1112
PATCH_CONFIG_PATH = 'target/reports/diff/patch_config.xml'
@@ -25,7 +26,7 @@ def build(projects, base_name, patch_name)
2526
index.puts html_report
2627
index.close
2728

28-
puts 'Built summary report successfully!'
29+
logger.info 'Built summary report successfully!'
2930
end
3031

3132
def get_branch_details(branch_name)

lib/pmdtester/cmd.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,36 @@
55
module PmdTester
66
# Containing the common method for executing shell command
77
class Cmd
8+
extend PmdTester
89
def self.execute(cmd)
9-
puts cmd
10+
logger.debug "execute command '#{cmd}'"
1011

1112
stdout, stderr, status = Open3.capture3("#{cmd};")
1213

14+
logger.debug stdout
1315
unless status.success?
14-
puts stdout
15-
puts stderr
16-
exit(status.exitstatus)
16+
logger.error stderr
17+
raise CmdException.new(cmd, stderr)
1718
end
1819

1920
stdout&.chomp!
2021

2122
stdout
2223
end
2324
end
25+
26+
# The exception should be raised when the shell command failed.
27+
class CmdException < StandardError
28+
attr_reader :cmd
29+
attr_reader :error
30+
attr_reader :message
31+
32+
COMMON_MSG = 'An error occurred while executing the shell command'
33+
34+
def initialize(cmd, error)
35+
@cmd = cmd
36+
@error = error
37+
@message = "#{COMMON_MSG} '#{cmd}'"
38+
end
39+
end
2440
end

0 commit comments

Comments
 (0)