Skip to content

Commit e5e3f98

Browse files
committed
Merge pull request #79 from adangel/pmd-regression-tester:download-url
Add new configuration option "--baseline-download-url" #79
2 parents 9a9069b + 5406362 commit e5e3f98

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Typeresolution is now supported by two new tags in the project-list.xml file:
1717
* [#74](https://github.com/pmd/pmd-regression-tester/pull/74): Merge violations that have just changed messages
1818
* [#75](https://github.com/pmd/pmd-regression-tester/pull/75): Add new option "--error-recovery"
1919
* [#76](https://github.com/pmd/pmd-regression-tester/pull/76): Speedup XML parsing
20+
* [#79](https://github.com/pmd/pmd-regression-tester/pull/79): Add new configuration option "--baseline-download-url"
2021

2122
## External Contributions
2223

README.rdoc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ on a list of standard projects(Spring Framework, Hibernate, Solr, etc.)
2020
== SYNOPSIS:
2121

2222
=== 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'
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'
3131
single: Set this option to 'single' if your patch branch contains changes
3232
for any option that can't work on master/base branch
3333
online: Set this option to 'online' if you want to download
3434
the PMD report of master/base branch rather than generating it locally
3535
local: Default option is 'local', PMD reports for the base and patch branches are generated locally.
3636

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.
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/
4344
-v, --version
4445
-h, --help
4546

lib/pmdtester/parsers/options.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Options
1616
SINGLE = 'single'
1717
DEFAULT_CONFIG_PATH = ResourceLocator.locate('config/all-java.xml')
1818
DEFAULT_LIST_PATH = ResourceLocator.locate('config/project-list.xml')
19+
DEFAULT_BASELINE_URL_PREFIX = 'https://sourceforge.net/projects/pmd/files/pmd-regression-tester/'
1920

2021
attr_reader :local_git_repo
2122
attr_reader :base_branch
@@ -32,6 +33,7 @@ class Options
3233
attr_accessor :filter_set
3334
attr_reader :keep_reports
3435
attr_reader :error_recovery
36+
attr_reader :baseline_download_url_prefix
3537

3638
def initialize(argv)
3739
options = parse(argv)
@@ -50,6 +52,12 @@ def initialize(argv)
5052
@filter_set = nil
5153
@keep_reports = options.keep_reports?
5254
@error_recovery = options.error_recovery?
55+
url = options[:baseline_download_url]
56+
@baseline_download_url_prefix = if url[-1] == '/'
57+
url
58+
else
59+
"#{url}/"
60+
end
5361

5462
# if the 'config' option is selected then `config` overrides `base_config` and `patch_config`
5563
@base_config = @config if !@config.nil? && @mode == 'local'
@@ -98,6 +106,9 @@ def parse(argv)
98106
'whether change log level to DEBUG to see more information'
99107
o.bool '--error-recovery',
100108
'enable error recovery mode when executing PMD. Might help to analyze errors.'
109+
o.string '--baseline-download-url',
110+
'download url prefix from where to download the baseline in online mode',
111+
default: DEFAULT_BASELINE_URL_PREFIX
101112
o.on '-v', '--version' do
102113
puts VERSION
103114
exit

lib/pmdtester/runner.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run_local_mode
4747
def run_online_mode
4848
logger.info "Mode: #{@options.mode}"
4949

50-
baseline_path = download_baseline(@options.base_branch)
50+
baseline_path = download_baseline(@options.baseline_download_url_prefix, @options.base_branch)
5151

5252
project_list = determine_project_list_for_online_mode(baseline_path)
5353
get_projects(project_list)
@@ -83,13 +83,13 @@ def determine_project_list_for_online_mode(baseline_path)
8383
project_list
8484
end
8585

86-
def download_baseline(branch_name)
86+
def download_baseline(url_prefix, branch_name)
8787
branch_filename = PmdBranchDetail.branch_filename(branch_name)
8888
zip_filename = "#{branch_filename}-baseline.zip"
8989
target_path = 'target/reports'
9090
FileUtils.mkdir_p(target_path) unless File.directory?(target_path)
9191

92-
url = get_baseline_url(zip_filename)
92+
url = get_baseline_url(url_prefix, zip_filename)
9393
wget_cmd = "wget --timestamping #{url}"
9494
unzip_cmd = "unzip -qo #{zip_filename}"
9595

@@ -101,8 +101,8 @@ def download_baseline(branch_name)
101101
"#{target_path}/#{branch_filename}"
102102
end
103103

104-
def get_baseline_url(zip_filename)
105-
"https://sourceforge.net/projects/pmd/files/pmd-regression-tester/#{zip_filename}"
104+
def get_baseline_url(url_prefix, zip_filename)
105+
"#{url_prefix}#{zip_filename}"
106106
end
107107

108108
def run_single_mode

test/test_options.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@ def test_default_value
3838
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.base_config)
3939
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.patch_config)
4040
assert_equal(Options::DEFAULT_LIST_PATH, opts.project_list)
41+
assert_equal(Options::DEFAULT_BASELINE_URL_PREFIX, opts.baseline_download_url_prefix)
4142
assert_false(opts.error_recovery)
4243
end
4344

45+
def test_download_url_with_trailing_slash
46+
command_line = %w[-r /path/to/repo -b pmd_releases/6.2.0 -p master --baseline-download-url https://example.com/]
47+
opts = Options.new(command_line)
48+
assert_equal('https://example.com/', opts.baseline_download_url_prefix)
49+
end
50+
51+
def test_download_url_without_trailing_slash
52+
command_line = %w[-r /path/to/repo -b pmd_releases/6.2.0 -p master --baseline-download-url https://example.com]
53+
opts = Options.new(command_line)
54+
assert_equal('https://example.com/', opts.baseline_download_url_prefix)
55+
end
56+
4457
def test_enable_error_recovery
4558
command_line = %w[-r /path/to/repo -b pmd_releases/6.2.0 -p master --error-recovery]
4659
opts = Options.new(command_line)

0 commit comments

Comments
 (0)