Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/it app veyour #682

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 32 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand All @@ -10,6 +9,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-5.3" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.3.zip',
'C:\sonarqube-5.3.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sonarqube-5.3.zip", "C:\sonarqube-5.3")
}
- ps: |
If ($env:Platform -Match "x86") {
$env:PCRE_PLATFORM="Win32"
Expand All @@ -24,19 +37,34 @@ 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-5.3\sonarqube-5.3
- 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: 'sonar-cxx-plugin\target\*.jar'
- path: 'sslr-cxx-toolkit\target\*.jar'
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-5.3\sonarqube-5.3\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
Loading