Class: Fastlane::Actions::SonarAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/sonar.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, output, sh, step_text

Class Method Details

.authorsObject



77
78
79
# File 'lib/fastlane/actions/sonar.rb', line 77

def self.authors
  ["c_gretzki"]
end

.available_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/actions/sonar.rb', line 45

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :project_configuration_path,
                                  env_name: "FL_SONAR_RUNNER_PROPERTIES_PATH",
                                  description: "The path to your sonar project configuration file; defaults to `sonar-project.properties`", # default is enforced by sonar-runner binary
                                  optional: true,
                                  verify_block: proc do |value|
                                    raise "Couldn't find file at path '#{value}'".red unless value.nil? or File.exist?(value)
                                  end),
    FastlaneCore::ConfigItem.new(key: :project_key,
                                 env_name: "FL_SONAR_RUNNER_PROJECT_KEY",
                                 description: "The key sonar uses to identify the project, e.g. `name.gretzki.awesomeApp`. Must either be specified here or inside the sonar project configuration file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :project_name,
                                 env_name: "FL_SONAR_RUNNER_PROJECT_NAME",
                                 description: "The name of the project that gets displayed on the sonar report page. Must either be specified here or inside the sonar project configuration file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :project_version,
                                 env_name: "FL_SONAR_RUNNER_PROJECT_VERSION",
                                 description: "The project's version that gets displayed on the sonar report page. Must either be specified here or inside the sonar project configuration file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :sources_path,
                                 env_name: "FL_SONAR_RUNNER_SOURCES_PATH",
                                 description: "Comma-separated paths to directories containing source files. Must either be specified here or inside the sonar project configuration file",
                                 optional: true)
  ]
end

.descriptionObject



37
38
39
# File 'lib/fastlane/actions/sonar.rb', line 37

def self.description
  "Invokes sonar-runner to programmatically run SonarQube analysis"
end

.detailsObject



41
42
43
# File 'lib/fastlane/actions/sonar.rb', line 41

def self.details
  "See http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner for details."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/fastlane/actions/sonar.rb', line 81

def self.is_supported?(platform)
  true
end

.return_valueObject



73
74
75
# File 'lib/fastlane/actions/sonar.rb', line 73

def self.return_value
  "The exit code of the sonar-runner binary"
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fastlane/actions/sonar.rb', line 4

def self.run(params)
  verify_sonar_runner_binary

  command_prefix = [
    'cd',
    File.expand_path('.').shellescape,
    '&&'
  ].join(' ')

  sonar_runner_args = []
  sonar_runner_args << "-Dproject.settings=\"#{params[:project_configuration_path]}\"" if params[:project_configuration_path]
  sonar_runner_args << "-Dsonar.projectKey=\"#{params[:project_key]}\"" if params[:project_key]
  sonar_runner_args << "-Dsonar.projectName=\"#{params[:project_name]}\"" if params[:project_name]
  sonar_runner_args << "-Dsonar.projectVersion=\"#{params[:project_version]}\"" if params[:project_version]
  sonar_runner_args << "-Dsonar.sources=\"#{params[:sources_path]}\"" if params[:sources_path]

  command = [
    command_prefix,
    'sonar-runner',
    sonar_runner_args
  ].join(' ')

  Action.sh command
end

.verify_sonar_runner_binaryObject



29
30
31
# File 'lib/fastlane/actions/sonar.rb', line 29

def self.verify_sonar_runner_binary
  raise "You have to install sonar-runner using `brew install sonar-runner`".red unless `which sonar-runner`.to_s.length > 0
end