Skip to content

Commit

Permalink
enable its in windows
Browse files Browse the repository at this point in the history
package artifacts

Conflicts:
	.travis.yml

provide some error information to help debugging coverage import issues

implement ci strategy for 5.3

deprecate measures

(cherry picked from commit 1cdb774)

implement ci strategy for 5.3

disable multi module test, since the abssolute lookup does not work in this case

more logging

seems in some places its like this

fix its windows

disable test success density

disable some metrics to comply with 5.3

clean
  • Loading branch information
Jorge Costa authored and Costa, Jorge committed Feb 7, 2016
1 parent 4d06742 commit 5936106
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target
**/.sonarqube/*
**/Debug/**
**/Release/**
*.log.server
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ before_script:
script:
- mvn install -DskipTests=true
- mvn test
- RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin TestDataFolder=~/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata behave
- RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin TestDataFolder=~/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata behave --no-capture

after_failure:
- cat $SONARHOME/logs/sonar.log
Expand Down
33 changes: 32 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ install:
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
if (!(Test-Path -Path "C:\sonar-runner" )) {
(new-object System.Net.WebClient).DownloadFile(
'http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip',
'C:\sonar-runner-dist.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonar-runner-dist.zip", "C:\sonar-runner")
}
if (!(Test-Path -Path "C:\sonarqube-4.5.6" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-4.5.6.zip',
'C:\sonarqube-4.5.6.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube-4.5.6.zip", "C:\sonarqube-4.5.6")
}
- ps: |
If ($env:Platform -Match "x86") {
$env:PCRE_PLATFORM="Win32"
Expand All @@ -24,19 +38,36 @@ install:
$env:VCVARS_PLATFORM="amd64"
$env:LANG_PLATFORM="-x64"
}
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;C:\sonar-runner\sonar-runner-2.4\bin;%PATH%
- cmd: SET SONARHOME=C:\sonarqube-4.5.6\sonarqube-4.5.6
- cmd: SET TestDataFolder=C:\projects\sonar-cxx\integration-tests\testdata
- cmd: SET

build_script:
- dir
# SONAR-7154 : workaround
- mkdir C:\WINDOWS\system32\config\systemprofile\AppData\Local\Temp
- cd C:\WINDOWS\system32\config\systemprofile\AppData\Local\
- dir
- cd C:\projects\sonar-cxx
- dir
- C:\Python27\Scripts\pip.exe install requests
- C:\Python27\Scripts\pip.exe install behave
- C:\Python27\Scripts\pip.exe install colorama
- mvn clean install
- C:\Python27\Scripts\behave.exe --no-capture
cache:
- C:\maven\
- C:\Users\appveyor\.m2
artifacts:
- path: 'sonar-cxx-plugin\target\sonar-cxx-plugin-0.9.5-SNAPSHOT.jar'
- path: 'sslr-cxx-toolkit\target\sslr-cxx-toolkit-0.9.5-SNAPSHOT.jar'
- path: '*_project_.log'
- path: 'C:\sonarqube-4.5.6\sonarqube-4.5.6\logs\*'
on_failure:
- ps: Get-ChildItem cxx-squid\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem cxx-checks\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem sonar-cxx-plugin\target\surefire-reports\*.txt | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem *_project_.log | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- ps: Get-ChildItem C:\sonarqube-4.5.6\sonarqube-4.5.6\logs\* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

78 changes: 75 additions & 3 deletions integration-tests/features/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,74 @@

import re
import os
import sys
import requests
from requests.auth import HTTPBasicAuth
import json
import time

SONAR_ERROR_RE = re.compile(".* ERROR .*")
SONAR_WARN_RE = re.compile(".* WARN .*")
SONAR_WARN_TO_IGNORE_RE = re.compile(".*H2 database should.*|.*Starting search|.*Starting web")
RELPATH_LOG = "logs/sonar.log"

RED = ""
YELLOW = ""
GREEN = ""
RESET = ""
RESET_ALL = ""
BRIGHT = ""

SONAR_URL = "http://localhost:9000"

def sonarlog(sonarhome):
return os.path.join(sonarhome, RELPATH_LOG)

def ensureComputeEngineHasFinishedOk(logpath):
urlForChecking = ""

print(BRIGHT + " Read Log : " + logpath + RESET_ALL)

try:
with open(logpath, "r") as log:
lines = log.readlines()
urlForChecking = getUrlForChecking(lines)
except IOError, e:
badlines.append(str(e) + "\n")


print(BRIGHT + " Get Analysis In Background : " + urlForChecking + RESET_ALL)

if urlForChecking == "":
return ""

status = ""
while True:
time.sleep(1)
response = requests.get(urlForChecking)
task = json.loads(response.text).get("task", None)
print(BRIGHT + " CURRENT STATUS : " + task["status"] + RESET_ALL)
if task["status"] == "IN_PROGRESS" or task["status"] == "PENDING":
continue

if task["status"] == "SUCCESS":
break

if task["status"] == "FAILED":
status = "BACKGROUND TASK AS FAILED. CHECK SERVER : " + logpath + ".server"
break

serverlogurl = urlForChecking.replace("task?id", "logs?taskId")
r = requests.get(serverlogurl, auth=HTTPBasicAuth('admin', 'admin'),timeout=10)

writepath = logpath + ".server"
f = open(writepath, 'w')
f.write(r.text)
f.close()

# print(BRIGHT + " LOG SERVER : " + r.text + RESET_ALL)
return status

def analyselog(logpath, toignore=None):
badlines = []
errors = warnings = 0
Expand All @@ -43,7 +102,17 @@ def analyselog(logpath, toignore=None):

return badlines, errors, warnings


def getUrlForChecking(lines):
urlForChecking = ""
for line in lines:
if "INFO: More about the report processing at" in line:
urlForChecking = line.split("INFO: More about the report processing at")[1].strip()

if "INFO - More about the report processing at" in line:
urlForChecking = line.split("INFO - More about the report processing at")[1].strip()

return urlForChecking

def analyseloglines(lines, toignore=None):
badlines = []
errors = warnings = 0
Expand All @@ -53,8 +122,11 @@ def analyseloglines(lines, toignore=None):
badlines.append(line)
errors += 1
elif isSonarWarning(line, toingore_re):
badlines.append(line)
warnings += 1
if "JOURNAL_FLUSHER" not in line:
sys.stdout.write("found warning '%s'" % line)
badlines.append(line)
warnings += 1

return badlines, errors, warnings


Expand Down
76 changes: 67 additions & 9 deletions integration-tests/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
from subprocess import Popen, PIPE, check_call
from common import analyselog, sonarlog

from tempfile import mkstemp
from shutil import move
from os import remove, close

SONAR_URL = "http://localhost:9000"
INDENT = " "
BASEDIR = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -155,7 +159,7 @@ def start_sonar(sonarhome):
sys.stdout.write(INDENT + "starting SonarQube ... ")
sys.stdout.flush()
now = time.time()
Popen(start_script(sonarhome), stdout=PIPE, shell=os.name == "nt")
start_script(sonarhome)
if not wait_for_sonar(50, is_webui_up):
sys.stdout.write(RED + "FAILED\n" + RESET)
return False
Expand All @@ -167,8 +171,19 @@ def start_sonar(sonarhome):

def stop_sonar(sonarhome):
if platform.system() == "Windows":
sys.stdout.write(YELLOW + "Cannot stop SonarQube automaticly on Windows. Please do it manually.\n" + RESET)
return
if platform.machine() == "x86_64":
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "UninstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")
elif platform.machine() == "i686":
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-32", "UninstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")
elif platform.machine() == "AMD64":
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "UninstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")

if not wait_for_sonar(30, is_webui_down):
sys.stdout.write(RED + "FAILED\n" + RESET)
return False

sys.stdout.write(INDENT + "stopping SonarQube ... ")
sys.stdout.flush()
Expand All @@ -185,24 +200,65 @@ class UnsupportedPlatform(Exception):
def __init__(self, msg):
super(UnsupportedPlatform, self).__init__(msg)


def replace(file_path, pattern, subst):
#Create temp file
fh, abs_path = mkstemp()
with open(abs_path,'w') as new_file:
with open(file_path) as old_file:
for line in old_file:
new_file.write(line.replace(pattern, subst))
close(fh)
#Remove original file
remove(file_path)
#Move new file
move(abs_path, file_path)

def start_script(sonarhome):
command = None

if platform.system() == "Linux":
script = linux_script(sonarhome)
if script:
command = [script, "start"]

Popen(command, stdout=PIPE, shell=os.name == "nt")
elif platform.system() == "Windows":
replace(os.path.join(sonarhome, "conf", "sonar.properties"), "#sonar.path.data=data", "sonar.path.data=" + os.path.join(sonarhome,"data").replace("\\","/"))
replace(os.path.join(sonarhome, "conf", "sonar.properties"), "#sonar.path.temp=temp", "sonar.path.temp=" + os.path.join(sonarhome,"temp").replace("\\","/"))
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("\\","/"))

if platform.machine() == "x86_64":
command = ["start", "cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "StartSonar.bat")]
sys.stdout.write(GREEN + "Install Service...\n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "InstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Install Service... Ok\n" + RESET)
sys.stdout.write(GREEN + "Start Service... \n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "StartNTService.bat")]
Popen(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Start Service... Ok \n")
elif platform.machine() == "i686":
command = ["start", "cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-32", "StartSonar.bat")]
sys.stdout.write(GREEN + "Install Service...\n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-32", "InstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Install Service... Ok\n" + RESET)
sys.stdout.write(GREEN + "Start Service... \n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-32", "StartNTService.bat")]
Popen(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Start Service... Ok \n" + RESET)
elif platform.machine() == "AMD64":
command = ["start", "cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "StartSonar.bat")]
sys.stdout.write(GREEN + "Install Service...\n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "InstallNTService.bat")]
check_call(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Install Service... Ok\n" + RESET)
sys.stdout.write(GREEN + "Start Service... \n")
command = ["cmd", "/c", os.path.join(sonarhome, "bin", "windows-x86-64", "StartNTService.bat")]
Popen(command, stdout=PIPE, shell=os.name == "nt")
sys.stdout.write(GREEN + "Start Service... Ok \n" + RESET)

sys.stdout.write(GREEN + "Start on windows done... Ok \n" + RESET)
elif platform.system() == "Darwin":
command = [os.path.join(sonarhome, "bin/macosx-universal-64/sonar.sh"), "start"]

Popen(command, stdout=PIPE, shell=os.name == "nt")
if command is None:
msg = "Dont know how to find the start script for the platform %s-%s" % (platform.system(), platform.machine())
raise UnsupportedPlatform(msg)
Expand All @@ -213,13 +269,15 @@ def start_script(sonarhome):
def stop_script(sonarhome):
command = None


if platform.system() == "Linux":
script = linux_script(sonarhome)
if script:
command = [script, "stop"]
elif platform.system() == "Darwin":
command = [os.path.join(sonarhome, "bin/macosx-universal-64/sonar.sh"), "stop"]

elif platform.system() == "Windows":
command = ["cmd", "/c", "dir"]
if command is None:
msg = "Dont know how to find the stop script for the platform %s-%s" % (platform.system(), platform.machine())
raise UnsupportedPlatform(msg)
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/features/importing_coverage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Feature: Importing coverage data
"""

THEN the analysis finishes successfully
AND the analysis in server has completed
AND the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
Expand Down Expand Up @@ -47,6 +48,7 @@ Feature: Importing coverage data
"""

THEN the analysis finishes successfully
AND the analysis in server has completed
AND the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
Expand Down Expand Up @@ -84,6 +86,7 @@ Feature: Importing coverage data
"""

THEN the analysis finishes successfully
AND the analysis in server has completed
AND the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
Expand Down
8 changes: 8 additions & 0 deletions integration-tests/features/importing_cppcheck_reports.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Importing Cppcheck reports
GIVEN the project "cppcheck_project"
WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=<reportpath>"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
AND the analysis log contains no error/warning messages except those matching:
"""
Expand All @@ -27,6 +28,7 @@ Feature: Importing Cppcheck reports
GIVEN the project "cppcheck_project"
WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=empty.xml"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
BUT the analysis log contains a line matching
"""
Expand All @@ -39,6 +41,7 @@ Feature: Importing Cppcheck reports
GIVEN the project "cppcheck_project"
WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=rule_unknown.xml"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
BUT the analysis log contains a line matching
"""
Expand All @@ -51,6 +54,7 @@ Feature: Importing Cppcheck reports
GIVEN the project "cppcheck_project"
WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=<reportpath>"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
BUT the analysis log contains a line matching
"""
Expand All @@ -68,6 +72,7 @@ Feature: Importing Cppcheck reports
GIVEN the project "cppcheck_project"
WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=relative-to-src.xml"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
BUT the analysis log contains a line matching
"""
Expand All @@ -77,8 +82,10 @@ Feature: Importing Cppcheck reports

Scenario: The reports and issues in the reports have absolute paths
GIVEN the project "cppcheck_with_absolute_paths_project"
and platform is not "Windows"
WHEN I run "sonar-runner -X"
THEN the analysis finishes successfully
AND the analysis in server has completed
AND the server log (if locatable) contains no error/warning messages
AND the number of violations fed is 6

Expand All @@ -90,6 +97,7 @@ Feature: Importing Cppcheck reports
# AND a report outside the projects directory, e.g. "/tmp/cppcheck-v1.xml"
# WHEN I run "sonar-runner -X -Dsonar.cxx.cppcheck.reportPath=/tmp/cppcheck-v1.xml"
# THEN the analysis finishes successfully
# AND the analysis in server has completed
# AND the server log (if locatable) contains no error/warning messages
# AND the analysis log contains no error/warning messages
# AND the number of violations fed is 7
Expand Down
Loading

0 comments on commit 5936106

Please sign in to comment.