class PmdTester::Project

This class represents all the information about the project

Constants

REPOSITORIES_PATH

Attributes

auxclasspath[RW]

stores the auxclasspath calculated after cloning/preparing the project

auxclasspath_command[R]
build_command[R]

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

connection[R]
exclude_patterns[R]
name[R]
report_diff[RW]
src_subpath[R]
tag[R]
type[R]
webview_url[R]

Public Class Methods

new(project) click to toggle source
# 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

Public Instance Methods

clone_root_path() click to toggle source

Path to the clone directory

# File lib/pmdtester/project.rb, line 109
def clone_root_path
  "#{REPOSITORIES_PATH}/#{@name}"
end
compute_report_diff(base_branch, patch_branch, filter_set) click to toggle source
# File lib/pmdtester/project.rb, line 120
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)
end
default_webview_url() click to toggle source

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

# 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) click to toggle source
# File lib/pmdtester/project.rb, line 92
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) click to toggle source
# File lib/pmdtester/project.rb, line 72
def get_local_path(file_path)
  file_path.sub(%r{/#{clone_root_path}/}, '')
end
get_path_inside_project(file_path) click to toggle source

Change the file path from 'LOCAL_DIR/SOURCE_CODE_PATH' to 'PROJECT_NAME/SOURCE_CODE_PATH'

# 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) click to toggle source
# File lib/pmdtester/project.rb, line 76
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) click to toggle source
# File lib/pmdtester/project.rb, line 113
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) click to toggle source
# File lib/pmdtester/project.rb, line 84
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) click to toggle source

Change the file path from 'LOCAL_DIR/SOURCE_CODE_PATH' to 'WEB_VIEW_URL/SOURCE_CODE_PATH'

# 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_path() click to toggle source

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

# File lib/pmdtester/project.rb, line 102
def local_source_path
  # normalize path
  Pathname.new("#{clone_root_path}/#{src_subpath}").cleanpath
end