diff --git a/.github/workflows/HTMLTidy.yml b/.github/workflows/HTMLTidy.yml deleted file mode 100644 index 615d7fb458..0000000000 --- a/.github/workflows/HTMLTidy.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Verify rule files with HTML Tidy - -name: Verify rule files - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '2.7' - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - name: Install HTML Tidy - run: | - wget https://github.com/htacg/tidy-html5/releases/download/5.8.0/tidy-5.8.0-Linux-64bit.deb - sudo dpkg -i tidy-5.8.0-Linux-64bit.deb - # - name: Verify rule files - # run: bash ./cxx-sensors/src/tools/check_rules.sh - diff --git a/.github/workflows/cxx-ci.yml b/.github/workflows/cxx-ci.yml new file mode 100644 index 0000000000..cd77bfd8e4 --- /dev/null +++ b/.github/workflows/cxx-ci.yml @@ -0,0 +1,517 @@ +# +# This workflow contains all necessary steps to build, test and release the cxx plugin +# + +name: cxx plugin CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +defaults: + run: + # use bash only, makes it easier to write steps for Windows & Linux + shell: bash + +jobs: + + + # ----------------------------------------------------------------------------------------------------------- + # Verify SonarQube rule definition files with HTML Tidy + # - Do they contain valid HTML? + # ----------------------------------------------------------------------------------------------------------- + verify-rules: + + strategy: + matrix: + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + + steps: + + # checkout code + # + - name: Checkout repository + uses: actions/checkout@v2 + + # setup Python + # + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '2.7' + + # setup Tidy + # + - name: Install xmllint + run: sudo apt-get install libxml2-utils + + - name: Install HTML Tidy + run: | + wget https://github.com/htacg/tidy-html5/releases/download/5.8.0/tidy-5.8.0-Linux-64bit.deb + sudo dpkg -i tidy-5.8.0-Linux-64bit.deb + + # verify SonarQube rule definition files with HTML Tidy + # + - name: Verify rule files + run: bash ./cxx-sensors/src/tools/check_rules.sh + + + # ----------------------------------------------------------------------------------------------------------- + # Going through the Maven cycles 'validate', 'compile', 'test', 'package' in all combinations to be supported + # The result of 'package' is uploaded as artifact for Ubuntu Linux Java 11 Temurin + # ----------------------------------------------------------------------------------------------------------- + build-linux: + + strategy: + matrix: + os: [ubuntu-latest] + java: [ '11' ] + distribution: [ 'temurin' ] + + runs-on: ${{ matrix.os }} + + steps: + + # context information + # + - name: Dump GitHub context + run: echo '${{ toJSON(github) }}' + - name: Dump Matrix context + run: echo '${{ toJSON(matrix) }}' + + # checkout code + # + - name: Checkout repository + uses: actions/checkout@v2 + + # setup Java + # + - name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: ${{ matrix.distribution }} + cache: maven + + - name: Dump environment variables + run: env + + # set version number of plugin JAR + # - GitHub milestone 'major.minor.patch level' and 'build number from actions run number + # + - name: Sets the current project's version + run: mvn versions:set -DartifactId='cxx' -DnewVersion='${{ github.event.pull_request.milestone.title }}.${{ github.run_number }}' + + # Build and test with with Maven + # + - name: Build and test with with Maven + run: mvn -B package --file pom.xml + + # Update SonarCloud results + # - Secrets are not passed to the runner when a workflow is triggered from a forked repository! + # + - name: Update SonarCloud results + if: github.event_name == 'push' + run: mvn sonar:sonar -B -e -V -Dsonar.organization=sonaropencommunity -Dsonar.host.url=https://sonarcloud.io -Dsonar.login="$SONARCLOUDTOKEN" + env: + SONARCLOUDTOKEN: ${{ secrets.SONAR_TOKEN }} + + # create artifacts from Linux, Java 11 Temurin + # + - name: Collect JAR files + if: matrix.os == 'ubuntu-latest' && matrix.java == '11' && matrix.distribution == 'temurin' + run: | + mkdir staging + cp sonar-cxx-plugin/target/*.jar staging + cp cxx-sslr-toolkit/target/*.jar staging + rm -f staging/original-*.jar + rm -f staging/*-sources.jar + + # upload JARs as artifact + # + - name: Packaging workflow data as artifacts + if: hashFiles('staging') != '' + uses: actions/upload-artifact@v2 + with: + name: JAR_Files + path: staging + + + # ----------------------------------------------------------------------------------------------------------- + # Going through the Maven cycles 'validate', 'compile', 'test', 'package' in all combinations to be supported + # The result of 'package' is uploaded as artifact for Ubuntu Linux Java 11 Temurin + # ----------------------------------------------------------------------------------------------------------- + build-windows: + + strategy: + matrix: + os: [windows-latest] + java: [ '11' ] + distribution: [ 'temurin' ] + + runs-on: ${{ matrix.os }} + + steps: + + # context information + # + - name: Dump GitHub context + run: echo '${{ toJSON(github) }}' + - name: Dump Matrix context + run: echo '${{ toJSON(matrix) }}' + + # checkout code + # + - name: Checkout repository + uses: actions/checkout@v2 + + # setup Java + # + - name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: ${{ matrix.distribution }} + cache: maven + + # for tests on Windows we need a valid TMP folder + # - necessary for org.junit.rules.TemporaryFolder + # + - name: Adapt TMP folder on Windows OS + run: | + echo "TMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV + echo "TEMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV + + - name: Dump environment variables + run: env + + # Build and test with with Maven + # + - name: Build and test with with Maven + run: mvn -B package --file pom.xml + + + # ----------------------------------------------------------------------------------------------------------- + # test cxx plugin with SonarQube (Linux) + # ----------------------------------------------------------------------------------------------------------- + integration-linux: + + strategy: + matrix: + os: [ubuntu-latest] + java: [ '11' ] + distribution: [ 'temurin' ] + sonarqube: [ '7.9.6', '8.9.7.52159' ] + sonarscanner: [ '4.6.2.2472' ] + + runs-on: ${{ matrix.os }} + needs: [build-linux, verify-rules] + + steps: + + # context information + # + - name: Dump Matrix context + run: echo '${{ toJSON(matrix) }}' + + # checkout code + # + - name: Checkout repository + uses: actions/checkout@v2 + + # setup Java + # + - name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: ${{ matrix.distribution }} + cache: maven + + # setup Python + # + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '2.7' + # cache not working with 2.7? + #cache: 'pip' + - run: pip install -r "$GITHUB_WORKSPACE/integration-tests/requirements.txt" + + # target folder + # + - name: Create root folder + run: mkdir test + + # Download & install SonarQube + # + - name: Set up SonarQube (Cache) + id: sonar-qube + uses: actions/cache@v2 + with: + path: test/sonarqube-${{ matrix.sonarqube }} + key: install-sonarqube-${{ matrix.sonarqube }}-${{ runner.os }} + + - name: Set up SonarQube (Download) + if: steps.sonar-qube.outputs.cache-hit != 'true' + run: | + pushd test + wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${{ matrix.sonarqube }}.zip + unzip -qq sonarqube-${{ matrix.sonarqube }}.zip + popd + + # Download & install SonarScanner + # + - name: Set up SonarScanner (Cache) + id: sonar-scanner + uses: actions/cache@v2 + with: + path: test/sonar-scanner-${{ matrix.sonarscanner }} + key: install-sonar-scanner-cli-${{ matrix.sonarscanner }}-${{ runner.os }} + + - name: Set up SonarScanner (Download) + if: steps.sonar-scanner.outputs.cache-hit != 'true' + run: | + pushd test + wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ matrix.sonarscanner }}.zip + unzip -qq sonar-scanner-cli-${{ matrix.sonarscanner }}.zip + popd + + # download & install cxx plugin + # - copy it to target folder, behave script expect it there + # + - name: Download cxx plugin + uses: actions/download-artifact@v2 + with: + name: JAR_Files + + - name: restore cxx plugin + run: | + mkdir -p $GITHUB_WORKSPACE/sonar-cxx-plugin/target + cp sonar-cxx-plugin*.jar $GITHUB_WORKSPACE/sonar-cxx-plugin/target + + # setup test environment + # - for the tests it is important that path seperator are correct for the OS + # + - name: Set test environment (Linux) + run: | + echo "SONARHOME=$GITHUB_WORKSPACE/test/sonarqube-${{ matrix.sonarqube }}" >> $GITHUB_ENV + echo "SONARLOG=$GITHUB_WORKSPACE/test/sonarqube-${{ matrix.sonarqube }}/logs" >> $GITHUB_ENV + echo "$GITHUB_WORKSPACE/test/sonar-scanner-${{ matrix.sonarscanner }}/bin" >> $GITHUB_PATH + echo "TestDataFolder=$GITHUB_WORKSPACE/integration-tests/testdata" >> $GITHUB_ENV + + - name: Dump environment variables + run: env + + # prepare test data + # - tests with absolute paths must be aligend with CI workspace + # + - name: Prepare test data (Linux) + run: | + find "$TestDataFolder" -name '*.xml' -exec sed -i "s|/home/travis/build/SonarOpenCommunity/sonar-cxx|$GITHUB_WORKSPACE|g" '{}' \; + + # run integration tests + # - use OS specific shell to start behave + # + - name: Run integration tests (Linux) + shell: bash + run: behave --no-capture --tags=SqApi79 + + # collect and upload LOG files + # + - name: Collect LOG files + if: always() + run: cp -v *.log "$SONARLOG" + + - name: Upload LOG files as artifact + if: always() + uses: actions/upload-artifact@v2 + with: + name: "LOG_sonarqube_${{ matrix.sonarqube }}_${{ matrix.os }}" + path: "${{ env.SONARLOG }}" + + + # ----------------------------------------------------------------------------------------------------------- + # test cxx plugin with SonarQube (Windows) + # ----------------------------------------------------------------------------------------------------------- + integration-windows: + + strategy: + matrix: + os: [windows-latest] + java: [ '11' ] + distribution: [ 'temurin' ] + sonarqube: [ '7.9.6', '8.9.7.52159' ] + sonarscanner: [ '4.6.2.2472' ] + + runs-on: ${{ matrix.os }} + # needs build-linux because of JAR artifacts + needs: [build-linux, build-windows, verify-rules] + + steps: + + # context information + # + - name: Dump Matrix context + run: echo '${{ toJSON(matrix) }}' + + # checkout code + # + - name: Checkout repository + uses: actions/checkout@v2 + + # setup Java + # + - name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: ${{ matrix.distribution }} + cache: maven + + # setup Python + # + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '2.7' + # cache not working with 2.7? + #cache: 'pip' + - run: pip install -r "$GITHUB_WORKSPACE/integration-tests/requirements.txt" + + # target folder + # + - name: Create root folder + run: mkdir test + + # Download & install SonarQube + # + - name: Set up SonarQube (Cache) + id: sonar-qube + uses: actions/cache@v2 + with: + path: test/sonarqube-${{ matrix.sonarqube }} + key: install-sonarqube-${{ matrix.sonarqube }}-${{ runner.os }} + + - name: Set up SonarQube (Download) + if: steps.sonar-qube.outputs.cache-hit != 'true' + shell: cmd + run: | + pushd test + C:\msys64\usr\bin\wget.exe -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${{ matrix.sonarqube }}.zip + unzip -qq sonarqube-${{ matrix.sonarqube }}.zip + popd + + # Download & install SonarScanner + # + - name: Set up SonarScanner (Cache) + id: sonar-scanner + uses: actions/cache@v2 + with: + path: test/sonar-scanner-${{ matrix.sonarscanner }} + key: install-sonar-scanner-cli-${{ matrix.sonarscanner }}-${{ runner.os }} + + - name: Set up SonarScanner for Windows (Download) + if: steps.sonar-scanner.outputs.cache-hit != 'true' + shell: cmd + run: | + pushd test + C:\msys64\usr\bin\wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ matrix.sonarscanner }}.zip + unzip -qq sonar-scanner-cli-${{ matrix.sonarscanner }}.zip + popd + + # download & install cxx plugin + # - copy it to target folder, behave script expect it there + # + - name: Download cxx plugin + uses: actions/download-artifact@v2 + with: + name: JAR_Files + + - name: restore cxx plugin + run: | + mkdir -p $GITHUB_WORKSPACE/sonar-cxx-plugin/target + cp sonar-cxx-plugin*.jar $GITHUB_WORKSPACE/sonar-cxx-plugin/target + + # setup test environment + # - for the tests it is important that path seperator are correct for the OS + # + - name: Set Up SonarQube environment (Windows) + run: | + echo "SONARHOME=$GITHUB_WORKSPACE\test\sonarqube-${{ matrix.sonarqube }}" >> $GITHUB_ENV + echo "SONARLOG=$GITHUB_WORKSPACE\test\sonarqube-${{ matrix.sonarqube }}\logs" >> $GITHUB_ENV + echo "$GITHUB_WORKSPACE\test\sonar-scanner-${{ matrix.sonarscanner }}\bin" >> $GITHUB_PATH + echo "TestDataFolder=$GITHUB_WORKSPACE\integration-tests\testdata" >> $GITHUB_ENV + echo "TMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV + echo "TEMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV + + - name: Dump environment variables + run: env + + # prepare test data + # - tests with absolute paths must be aligend with CI workspace + # + - name: Prepare test data (Windows) + shell: pwsh + run: | + Get-ChildItem "$env:TestDataFolder\*.log" -Recurse | ForEach { (Get-Content $_).Replace('C:\projects\sonar-cxx', "$env:GITHUB_WORKSPACE") | Set-Content $_ } + + # run integration tests + # - use OS specific shell to start behave + # + - name: Run integration tests (Windows) + shell: cmd + run: behave --no-capture --tags=SqApi79 + + # collect and upload LOG files + # + - name: Collect LOG files + if: always() + run: cp -v *.log "$SONARLOG" + + - name: Upload LOG files as artifact + if: always() + uses: actions/upload-artifact@v2 + with: + name: "LOG_sonarqube_${{ matrix.sonarqube }}_${{ matrix.os }}" + path: "${{ env.SONARLOG }}" + + + # ----------------------------------------------------------------------------------------------------------- + # success + # ----------------------------------------------------------------------------------------------------------- + successfully-finished: + + strategy: + matrix: + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + needs: [integration-windows, integration-linux] + + steps: + + # download JAR files + # + - name: Download JAR files + uses: actions/download-artifact@v2 + with: + name: JAR_Files + + # create pre-release + # + - uses: "marvinpinto/action-automatic-releases@latest" + if: github.event_name == 'push' + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest-snapshot" + prerelease: true + title: "Latest Snapshot" + files: | + ./*.jar + + - run: echo SUCCESS diff --git a/README.md b/README.md index 1e7b8d3573..f99a5af6a6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ | | | | | --- | --- | --- | | **SonarCloud** / SonarSource SA
(Technical Debt analysis) | [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.sonarqube-plugins.cxx%3Acxx&metric=alert_status)](https://sonarcloud.io/dashboard?id=org.sonarsource.sonarqube-plugins.cxx%3Acxx) | ![Coverage](https://sonarcloud.io/api/project_badges/measure?project=org.sonarsource.sonarqube-plugins.cxx%3Acxx&metric=coverage) | -| **DeepCode** / DeepCode AG
(real-time AI powered semantic code analysis) | [![deepcode](https://www.deepcode.ai/api/gh/badge?key=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwbGF0Zm9ybTEiOiJnaCIsIm93bmVyMSI6IlNvbmFyT3BlbkNvbW11bml0eSIsInJlcG8xIjoic29uYXItY3h4IiwiaW5jbHVkZUxpbnQiOmZhbHNlLCJhdXRob3JJZCI6MTU1ODMsImlhdCI6MTYwMTI4MjcwOH0.Wz0G-HIoHfLfP1SjzxUnbyA598JfjKkQTsBqGG4Kleo)](https://www.deepcode.ai/app/gh/SonarOpenCommunity/sonar-cxx/_/dashboard?utm_content=gh%2FSonarOpenCommunity%2Fsonar-cxx) | | **JProfiler** / ej-technologies GmbH
(when it comes to profiling: [Java profiler](https://www.ej-technologies.com/products/jprofiler/overview.html) tool) | [![JProfiler](https://www.ej-technologies.com/images/product_banners/jprofiler_small.png)](https://www.ej-technologies.com/products/jprofiler/overview.html)| +| **GitHub Actions**
(Windows & Linux CI/CD) | [![Build Status](https://github.com/SonarOpenCommunity/sonar-cxx/actions/workflows/cxx-ci.yml/badge.svg?branch=master&event=push)](https://github.com/SonarOpenCommunity/sonar-cxx/actions/workflows/cxx-ci.yml) | [You can download latest snapshot from here.](https://github.com/SonarOpenCommunity/sonar-cxx/releases/tag/latest-snapshot) | # SonarQube C++ Community plugin (_cxx plugin_) @@ -59,7 +59,7 @@ Sensors for **static and dynamic code analysis**: * **Boost.Test** file format (https://www.boost.org/doc/libs/release/libs/test/) - [sonar.cxx.xunit.reportPaths](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xunit.reportPaths) with [sonar.cxx.xslt](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xslt) * **CppTest** file format (https://cpptest.sourceforge.io/) - - [sonar.cxx.xunit.reportPaths](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xunit.reportPaths) with [sonar.cxx.xslt](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xslt) + - [sonar.cxx.xunit.reportPaths](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xunit.reportPaths) with [sonar.cxx.xslt](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xslt) * **CppUnit** file format (https://sourceforge.net/projects/cppunit/) - [sonar.cxx.xunit.reportPaths](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xunit.reportPaths) with [sonar.cxx.xslt](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.xslt) * **VSTest** file format (https://github.com/microsoft/vstest) @@ -99,7 +99,7 @@ Simple to **customize** ## Resources - [Latest release](https://github.com/SonarOpenCommunity/sonar-cxx/releases) -- [Download latest snapshot](https://ci.appveyor.com/project/SonarOpenCommunity/sonar-cxx/branch/master/artifacts) +- [Download latest snapshot](https://github.com/SonarOpenCommunity/sonar-cxx/releases/tag/latest-snapshot) - [Documentation](https://github.com/SonarOpenCommunity/sonar-cxx/wiki) - [Issue Tracker](https://github.com/SonarOpenCommunity/sonar-cxx/issues) @@ -110,7 +110,7 @@ You are welcome to contribute. [Help is needed](https://github.com/SonarOpenComm That's not the only choice when you are looking for C++ support in SonarQube there is also * the commercial [SonarCFamily plugin from SonarSource](https://www.sonarsource.com/cpp) * the commercial [C/C++ plugin from CppDepend](http://www.cppdepend.com/sonarplugin) -* the [Coverity plugin](https://github.com/coverity/coverity-sonar-plugin) * the commercial [PVS-Studio plugin](https://www.viva64.com/en/pvs-studio-download) +* the [Coverity plugin](https://github.com/coverity/coverity-sonar-plugin) Choose whatever fits your needs. diff --git a/cxx-sensors/src/tools/utils_createrules.py b/cxx-sensors/src/tools/utils_createrules.py index 497c57ce2c..284b66e4d4 100644 --- a/cxx-sensors/src/tools/utils_createrules.py +++ b/cxx-sensors/src/tools/utils_createrules.py @@ -150,7 +150,7 @@ def call_tidy(file_path): p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() - if p.returncode != 0: + if p.returncode < 0 or p.returncode > 1: # error: not ok, not warning print("### TIDY ", file_path) with open(file_path, 'r') as f: print(f.read()) diff --git a/integration-tests/features/cppcheck.feature b/integration-tests/features/cppcheck.feature index e91a442aa3..f7d126c177 100644 --- a/integration-tests/features/cppcheck.feature +++ b/integration-tests/features/cppcheck.feature @@ -16,7 +16,7 @@ Feature: Importing Cppcheck reports And the server log (if locatable) contains no error/warning messages But the analysis log contains a line matching """ - .*WARN: The 'Cppcheck V2' report is empty.*skipping + WARN: The 'Cppcheck V2' report is empty.*skipping """ And the number of violations fed is 0 @@ -35,7 +35,7 @@ Feature: Importing Cppcheck reports And the server log (if locatable) contains no error/warning messages But the analysis log contains a line matching """ - .*WARN: Cannot find the file.*skipping + WARN: Cannot find the file.*skipping """ And the number of violations fed is 0 @@ -70,7 +70,7 @@ Feature: Importing Cppcheck reports And the server log (if locatable) contains no error/warning messages But the analysis log contains a line matching """ - .*WARN: The 'Cppcheck V2' report is invalid.*skipping + WARN: The 'Cppcheck V2' report is invalid.*skipping """ And the number of violations fed is Examples: diff --git a/integration-tests/features/environment.py b/integration-tests/features/environment.py index 478ce1ed03..8b17029cea 100644 --- a/integration-tests/features/environment.py +++ b/integration-tests/features/environment.py @@ -26,11 +26,11 @@ import time import platform import requests +import subprocess from glob import glob from shutil import copyfile from shutil import move -from subprocess import Popen, PIPE, check_call from common import analyse_log, get_sonar_log_file, cleanup_logs, print_logs from tempfile import mkstemp from requests.auth import HTTPBasicAuth @@ -163,7 +163,7 @@ def install_plugin(sonarhome): os.remove(path) jpath = jar_cxx_path() if not jpath: - sys.stderr.write(RED + "FAILED: the jar file cannot be found. Make sure you build it.\n" + RESET) + sys.stderr.write(RED + "FAILED: the jar file cannot be found. Make sure you build it '" + jpath + "'.\n" + RESET) sys.stderr.flush() return False @@ -203,8 +203,12 @@ def start_sonar(sonarhome): def stop_sonar(sonarhome): - rc = check_call(stop_script(sonarhome)) - if rc != 0 or not wait_for_sonar(300, is_webui_down): + try: + subprocess.check_call(stop_script(sonarhome)) + except subprocess.CalledProcessError as error: + sys.stdout.write(RED + "FAILED, %s\n" % (error) + RESET) + + if not wait_for_sonar(300, is_webui_down): sys.stdout.write(RED + "FAILED\n" + RESET) sys.stdout.flush() return False @@ -244,7 +248,7 @@ def start_script(sonarhome): script = linux_script(sonarhome) if script: command = [script, "start"] - Popen(command, stdout=PIPE, shell=os.name == "nt") + subprocess.Popen(command, stdout=subprocess.PIPE, shell=os.name == "nt") elif platform.system() == "Windows": @@ -253,12 +257,12 @@ def start_script(sonarhome): replace(os.path.join(sonarhome, "conf", "wrapper.conf"), "wrapper.java.additional.1=-Djava.awt.headless=true", "wrapper.java.additional.1=-Djava.awt.headless=true -Djava.io.tmpdir=" + os.path.join(sonarhome,"temp").replace("\\","/")) command = ["cmd", "/c", os.path.join(sonarhome, "bin/windows-x86-64/StartSonar.bat")] - sq_process = Popen(command, stdout=PIPE, shell=os.name == "nt") + sq_process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=os.name == "nt") elif platform.system() == "Darwin": command = [os.path.join(sonarhome, "bin/macosx-universal-64/sonar.sh"), "start"] - Popen(command, stdout=PIPE, shell=os.name == "nt") + subprocess.Popen(command, stdout=subprocess.PIPE, shell=os.name == "nt") if command is None: diff --git a/integration-tests/features/googletest.feature b/integration-tests/features/googletest.feature index aeb1cf1682..2042c99aee 100644 --- a/integration-tests/features/googletest.feature +++ b/integration-tests/features/googletest.feature @@ -55,7 +55,7 @@ Feature: Providing test execution measures Then the analysis breaks And the analysis log contains a line matching: """ - .*ERROR: Invalid xUnit report.*stop analysis + ERROR: Invalid xUnit report.*stop analysis """ diff --git a/integration-tests/features/steps/test_execution_statistics.py b/integration-tests/features/steps/test_execution_statistics.py index 5b7322b9a2..ee8f56ac07 100644 --- a/integration-tests/features/steps/test_execution_statistics.py +++ b/integration-tests/features/steps/test_execution_statistics.py @@ -21,6 +21,7 @@ import os import re +import io import json import requests import platform @@ -355,11 +356,12 @@ def _diff_measures(expected, measured): return "\n".join(difflist) def _contains_line_matching(filepath, pattern): - pat = re.compile(pattern) - with open(filepath) as logfo: + pat = re.compile(pattern.strip()) + with io.open(filepath, mode='rt', encoding='utf-8') as logfo: for line in logfo: - if pat.match(line): + if pat.search(line.rstrip('\r\n')): return True + return False def _assert_measures(project, measures): diff --git a/integration-tests/requirements.txt b/integration-tests/requirements.txt new file mode 100644 index 0000000000..3d21b099f6 --- /dev/null +++ b/integration-tests/requirements.txt @@ -0,0 +1,3 @@ +requests +behave +colorama