Class: PmdTester::Project

Inherits:
Object
  • Object
show all
Includes:
PmdTesterUtils
Defined in:
lib/pmdtester/project.rb

Overview

This class represents all the information about the project

Defined Under Namespace

Classes: CpdOptions

Constant Summary collapse

REPOSITORIES_PATH =
'target/repositories'

Constants included from PmdTester

BASE, PATCH, PR_NUM_ENV_VAR, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PmdTesterUtils

#build_cpd_report_diff, #build_html_reports, #build_report_diff, #compute_project_diffs, #parse_cpd_report, #parse_pmd_report

Methods included from PmdTester

#logger, logger

Constructor Details

#initialize(project) ⇒ Project

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pmdtester/project.rb', line 28

def initialize(project) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  @name = project.at_xpath('name').text
  @type = project.at_xpath('type').text
  @connection = project.at_xpath('connection').text

  @tag = project.at_xpath('tag')&.text || 'main'

  webview_url_element = project.at_xpath('webview-url')
  @webview_url = default_webview_url
  @webview_url = webview_url_element.text unless webview_url_element.nil?

  @src_subpath = project.at_xpath('src-subpath')&.text || '.'
  @exclude_patterns = []
  project.xpath('exclude-pattern').each do |ep|
    @exclude_patterns.push(ep.text)
  end

  @build_command = project.at_xpath('build-command')&.text
  @auxclasspath_command = project.at_xpath('auxclasspath-command')&.text

  @report_diff = nil
  @cpd_options = CpdOptions.new(project.at_xpath('cpd-options'))
end

Instance Attribute Details

#auxclasspathObject

stores the auxclasspath calculated after cloning/preparing the project



25
26
27
# File 'lib/pmdtester/project.rb', line 25

def auxclasspath
  @auxclasspath
end

#auxclasspath_commandObject (readonly)

Returns the value of attribute auxclasspath_command.



23
24
25
# File 'lib/pmdtester/project.rb', line 23

def auxclasspath_command
  @auxclasspath_command
end

#build_commandObject (readonly)

key: pmd branch name as String => value: local path of pmd report



22
23
24
# File 'lib/pmdtester/project.rb', line 22

def build_command
  @build_command
end

#connectionObject (readonly)

Returns the value of attribute connection.



14
15
16
# File 'lib/pmdtester/project.rb', line 14

def connection
  @connection
end

#cpd_optionsObject (readonly)

Returns the value of attribute cpd_options.



26
27
28
# File 'lib/pmdtester/project.rb', line 26

def cpd_options
  @cpd_options
end

#cpd_report_diffObject

Returns the value of attribute cpd_report_diff.



20
21
22
# File 'lib/pmdtester/project.rb', line 20

def cpd_report_diff
  @cpd_report_diff
end

#exclude_patternsObject (readonly)

Returns the value of attribute exclude_patterns.



17
18
19
# File 'lib/pmdtester/project.rb', line 17

def exclude_patterns
  @exclude_patterns
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/pmdtester/project.rb', line 12

def name
  @name
end

#report_diffObject

Returns the value of attribute report_diff.



19
20
21
# File 'lib/pmdtester/project.rb', line 19

def report_diff
  @report_diff
end

#src_subpathObject (readonly)

Returns the value of attribute src_subpath.



18
19
20
# File 'lib/pmdtester/project.rb', line 18

def src_subpath
  @src_subpath
end

#tagObject (readonly)

Returns the value of attribute tag.



16
17
18
# File 'lib/pmdtester/project.rb', line 16

def tag
  @tag
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/pmdtester/project.rb', line 13

def type
  @type
end

#webview_urlObject (readonly)

Returns the value of attribute webview_url.



15
16
17
# File 'lib/pmdtester/project.rb', line 15

def webview_url
  @webview_url
end

Instance Method Details

#clone_root_pathObject

Path to the clone directory



130
131
132
# File 'lib/pmdtester/project.rb', line 130

def clone_root_path
  "#{REPOSITORIES_PATH}/#{@name}"
end

#compute_report_diff(base_branch, patch_branch, filter_set, rules_changed:, impl_changed:) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/pmdtester/project.rb', line 141

def compute_report_diff(base_branch, patch_branch, filter_set, rules_changed:, impl_changed:)
  self.report_diff = build_report_diff(get_pmd_report_path(base_branch),
                                       get_pmd_report_path(patch_branch),
                                       get_report_info_path(base_branch),
                                       get_report_info_path(patch_branch),
                                       filter_set, rules_changed: rules_changed)

  report_diff.base_report.report_folder = get_project_target_dir(base_branch)
  report_diff.patch_report.report_folder = get_project_target_dir(patch_branch)

  self.cpd_report_diff = build_cpd_report_diff(get_cpd_report_path(base_branch),
                                               get_cpd_report_path(patch_branch),
                                               get_cpd_report_info_path(base_branch),
                                               get_cpd_report_info_path(patch_branch),
                                               impl_changed: impl_changed)
end

#default_webview_urlObject

Generate the default webview url for the projects stored on github. For other projects return value is ‘connection`.



55
56
57
58
59
60
61
# File 'lib/pmdtester/project.rb', line 55

def default_webview_url
  if @type.eql?('git') && @connection.include?('github.com')
    "#{@connection}/tree/#{@tag}"
  else
    @connection
  end
end

#get_config_path(branch_name) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/pmdtester/project.rb', line 113

def get_config_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/config.xml"
  end
end

#get_cpd_report_info_path(branch_name) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/pmdtester/project.rb', line 105

def get_cpd_report_info_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/cpd_report_info.json"
  end
end

#get_cpd_report_path(branch_name) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/pmdtester/project.rb', line 89

def get_cpd_report_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/cpd_report.xml"
  end
end

#get_local_path(file_path) ⇒ Object

Change the file path from ‘LOCAL_DIR/SOURCE_CODE_PATH’ to ‘SOURCE_CODE_PATH’



77
78
79
# File 'lib/pmdtester/project.rb', line 77

def get_local_path(file_path)
  file_path.sub(%r{^#{clone_root_path}/}, '')
end

#get_path_inside_project(file_path) ⇒ Object

Change the file path from ‘LOCAL_DIR/SOURCE_CODE_PATH’ to ‘PROJECT_NAME/SOURCE_CODE_PATH’



71
72
73
# File 'lib/pmdtester/project.rb', line 71

def get_path_inside_project(file_path)
  file_path.gsub(%r{^#{clone_root_path}/}, "#{@name}/")
end

#get_pmd_report_path(branch_name) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/pmdtester/project.rb', line 81

def get_pmd_report_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/pmd_report.xml"
  end
end

#get_project_target_dir(branch_name) ⇒ Object



134
135
136
137
138
139
# File 'lib/pmdtester/project.rb', line 134

def get_project_target_dir(branch_name)
  branch_filename = PmdBranchDetail.branch_filename(branch_name)
  dir = "target/reports/#{branch_filename}/#{@name}"
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
  dir
end

#get_report_info_path(branch_name) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/pmdtester/project.rb', line 97

def get_report_info_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/pmd_report_info.json"
  end
end

#get_webview_url(file_path) ⇒ Object

Change the file path from ‘LOCAL_DIR/SOURCE_CODE_PATH’ to ‘WEB_VIEW_URL/SOURCE_CODE_PATH’



65
66
67
# File 'lib/pmdtester/project.rb', line 65

def get_webview_url(file_path)
  file_path.gsub(%r{^#{clone_root_path}/}, "#{@webview_url}/")
end

#local_source_pathObject

Path to the sources to analyze (below or equal to clone_root_path)



123
124
125
126
# File 'lib/pmdtester/project.rb', line 123

def local_source_path
  # normalize path
  Pathname.new("#{clone_root_path}/#{src_subpath}").cleanpath
end