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

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_html_reports, #build_report_diff, #compute_project_diffs, #parse_pmd_report

Methods included from PmdTester

#logger, logger

Constructor Details

#initialize(project) ⇒ Project

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



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

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 || 'master'

  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
end

Instance Attribute Details

#auxclasspathObject

stores the auxclasspath calculated after cloning/preparing the project



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

def auxclasspath
  @auxclasspath
end

#auxclasspath_commandObject (readonly)

Returns the value of attribute auxclasspath_command.



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

def auxclasspath_command
  @auxclasspath_command
end

#build_commandObject (readonly)

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



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

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

#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



111
112
113
# File 'lib/pmdtester/project.rb', line 111

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

#compute_report_diff(base_branch, patch_branch, filter_set) ⇒ Object



122
123
124
125
126
127
128
129
130
131
# File 'lib/pmdtester/project.rb', line 122

def compute_report_diff(base_branch, patch_branch, filter_set)
  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)

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

#default_webview_urlObject

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



52
53
54
55
56
57
58
# File 'lib/pmdtester/project.rb', line 52

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



94
95
96
97
98
99
100
# File 'lib/pmdtester/project.rb', line 94

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

#get_local_path(file_path) ⇒ Object

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



74
75
76
# File 'lib/pmdtester/project.rb', line 74

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’



68
69
70
# File 'lib/pmdtester/project.rb', line 68

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

#get_pmd_report_path(branch_name) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/pmdtester/project.rb', line 78

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



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

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



86
87
88
89
90
91
92
# File 'lib/pmdtester/project.rb', line 86

def get_report_info_path(branch_name)
  if branch_name.nil?
    nil
  else
    "#{get_project_target_dir(branch_name)}/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’



62
63
64
# File 'lib/pmdtester/project.rb', line 62

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)



104
105
106
107
# File 'lib/pmdtester/project.rb', line 104

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