iwarapter / sonar-puppet

SonarQube plugin for Puppet code.
Other
26 stars 10 forks source link

WIP: [HELP needed] first attempt based on sonar-puppet module to parse generic-test-data #277

Open witjoh opened 6 years ago

witjoh commented 6 years ago

Just trying to make this plugin parse generic-test-date. Just copied the relevant files from sonar-puppet, but since I'm a noob with java/groovy I'm stcuk .... I guessed building is done executing ./gradlew build ... But always get error which I dont find a way to solve them

 /vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/xunit/PuppetXUnitSensor.java:36: error: cannot find symbol
import org.sonar.api.config.Configuration;
                           ^
  symbol:   class Configuration
  location: package org.sonar.api.config
/vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/PuppetReportSensor.java:31: error: cannot find symbol
import org.sonar.api.config.Configuration;
                           ^
  symbol:   class Configuration
  location: package org.sonar.api.config
/vagrant/playground/workflow/sonar-puppet/sonar-puppet-plugin/src/main/java/com/iadams/sonarqube/puppet/xunit/PuppetXUnitSensor.java:50: error: cannot find symbol
  public PuppetXUnitSensor(Configuration conf, FileSystem fileSystem) {

Maybe I'm just messing everything up ..... so any guidance is very welcome.

iwarapter commented 6 years ago

I thought most people were using the generic test coverage plugin for this?

witjoh commented 6 years ago

that plugin is removed in the 6.7.1LTS version .... Sonar is parsing the xml file, but just ignores its content ...

iwarapter commented 6 years ago

Yeah I seen the plugin was removed as is now part of core: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data (i haven't tested it however) so are you saying when you pass in test reports sonar.testExecutionReportPaths it's not picked up?

witjoh commented 6 years ago

from the logs ...

14:02:02.078 DEBUG: Sensors : Generic Test Executions Report -> Puppet Squid Sensor -> SonarJavaXmlFileSensor -> Analyzer for "php.ini" files -> Zero Coverage Sensor -> CPD Block Indexer
14:02:02.078 INFO: Sensor Generic Test Executions Report
14:02:02.079 WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
14:02:02.079 INFO: Parsing /opt/jenkins-slave/workspace/PMT_Demo/puppet_modules/vdab_ntp_demo/junit/reports_sonar.xml
14:02:02.159 INFO: Imported test execution data for 0 files
14:02:02.159 INFO: Test execution data ignored for 4 unknown files, including:
./spec/classes/chrony_spec.rb
./spec/classes/monitoring_spec.rb
./spec/classes/ntp_spec.rb
./spec/classes/vdab_ntp_spec.rb
14:02:02.159 INFO: Sensor Generic Test Executions Report (done) | time=81ms
14:02:02.159 INFO: Sensor Puppet Squid Sensor [puppet]
iwarapter commented 6 years ago

Can you share the demo project so I can reproduce the issue please?

witjoh commented 6 years ago

Have to remove company specific dependencies first .. I used the most crapy module to introduce puppet testing :) Will setup a quick demo .... In short .. I think one just need the following to add to your module .... in your Gemfile :

gem "rspec_sonar_formatter", :git => "https://github.com/witjoh/rspec_sonar_formatter.git", :branch => "master"
    #gem "rspec_sonar_formatter", :path => "../rspec_sonar_formatter"

(custom rspec formatter i wrote that generates the generic-test-data format) and then in tour spec/spec_helper.rb c.add_formatter('RSpec::RspecSonarFormatter::Formatter', 'junit/reports_sonar.xml') and start jenkins with following options (in a Jenkinsfile) ...

          /opt/sonar-scanner/bin/sonar-scanner -X \
            --define "sonar.projectKey=puppet:${gitlabSourceRepoName}" \
            --define "sonar.projectName=${gitlabSourceRepoName}" \
            --define "sonar.projectVersion=${BUILD_ID}-${gitlabMergeRequestIid}" \
            --define "sonar.exclusions=Jenkinsfile*,junit/**/*,spec/**/*" \
            --define "sonar.testExecutionReportPaths=junit/reports_sonar.xml" \
            --define "sonar.import_unknown_files=true" \
            --define "sonar.sources=."

As soon as I get a demo project i will come back

witjoh commented 6 years ago

@iwarapter demo project : https://github.com/witjoh/puppetlabs-ntp.git branch sonarqube

witjoh commented 6 years ago

posted in the sonarqube mailing list : https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/sonarqube/hON5Z4dfWIA/Cf7yT_zuAwAJ

witjoh commented 6 years ago

One of the reasons coverage is not parsed is due to the different languages puppet uses to wirite tests, namely _spec.rb files. Sonar is not able to map the tests files against the corresponding pp file.
I looked at the sonar-ruby-plugin, but this gives no solution out of the box. At least we do have coverage overview in jenkins using the junit coverage reporting. https://github.com/hersonalfaro/ruby-sonar-plugin seems the most up-to-date.