Skip to content

Commit 079efd1

Browse files
committed
first commit
0 parents  commit 079efd1

12 files changed

+315
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.sonar
2+
node_modules
3+
reports

.jshintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"predef": ["describe", "it", "before", "beforeEach", "after", "afterEach", "module"],
3+
"node":true
4+
}

Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MOCHA=node_modules/.bin/mocha
2+
JSCOVER=node_modules/.bin/jscover
3+
JSHINT=node_modules/.bin/jshint
4+
5+
TESTS=$(shell find test/ -name "*.test.js")
6+
7+
test:
8+
$(MOCHA) -R spec $(TESTS)
9+
10+
coverage:
11+
$(JSCOVER) src/ src-cov/
12+
TEST_COV=1 $(MOCHA) -R mocha-lcov-reporter $(TESTS) > reports/coverage.lcov
13+
rm -rf src-cov/
14+
15+
jshint:
16+
$(JSHINT) src test --reporter=checkstyle > reports/checkstyle.xml
17+
18+
sonar:
19+
PATH="$$PWD/tools/sonar-runner-2.1/bin:$$PATH"; \
20+
sonar-runner
21+
22+
.PHONY: test coverage jshint sonar

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "sonar-js",
3+
"version": "0.0.1",
4+
"description": "Simple demo of Sonar analysis with node.js projects",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": "",
10+
"author": "Xavier Seignard <[email protected]>",
11+
"license": "MIT"
12+
}

sonar-project.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
sonar.projectKey=sonar-js
2+
sonar.projectName=sonar-js
3+
sonar.projectVersion=0.0.1
4+
5+
sonar.sources=src
6+
sonar.language=js
7+
8+
sonar.dynamicAnalysis=reuseReports
9+
10+
sonar.javascript.lcov.reportPath=reports/coverage.lcov

src/app.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var Calculator = require('./core/calculator'),
2+
calc = new Calculator();
3+
4+
console.log(calc.add(2,3));

src/core/calculator.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
var Calculator = function() {
3+
4+
/**
5+
* Add two numbers
6+
* @param {Number} a - first number to add
7+
* @param {Number} b - second number to add
8+
* @return {Number} the result of the addition
9+
*/
10+
var _add = function(a, b) {
11+
return a + b;
12+
};
13+
14+
return {
15+
add : _add
16+
};
17+
};
18+
19+
// module exports
20+
module.exports = Calculator;

test/core/calculator.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
var libpath = process.env.TEST_COV ? 'src-cov' : 'src',
3+
assert = require('assert'),
4+
Calculator = require('../../'+ libpath +'/core/calculator');
5+
6+
describe('Calculator', function() {
7+
8+
describe('#add()', function() {
9+
it('should make an addition', function() {
10+
var calculator = new Calculator(),
11+
result = calculator.add(2,3);
12+
assert.equal(result, 5);
13+
});
14+
});
15+
});
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/sh
2+
#
3+
# Sonar Runner Startup Script for Unix
4+
#
5+
# Optional ENV vars:
6+
# SONAR_RUNNER_HOME - location of runner's installed home dir
7+
# SONAR_RUNNER_OPTS - parameters passed to the Java VM when running Sonar
8+
9+
# The following notice only apply to real_path function copied from
10+
# https://sites.google.com/site/jdisnard/realpath
11+
# Copyright 2010 Jon Disnard. All rights reserved.
12+
#
13+
# Redistribution and use in source and binary forms, with or without modification, are
14+
# permitted provided that the following conditions are met:
15+
#
16+
# 1. Redistributions of source code must retain the above copyright notice, this list of
17+
# conditions and the following disclaimer.
18+
#
19+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
20+
# of conditions and the following disclaimer in the documentation and/or other materials
21+
# provided with the distribution.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY Jon Disnard ``AS IS'' AND ANY EXPRESS OR IMPLIED
24+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
25+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
26+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
#
33+
# The views and conclusions contained in the software and documentation are those of the
34+
# authors and should not be interpreted as representing official policies, either expressed
35+
# or implied, of Jon Disnard.
36+
real_path () {
37+
OIFS=$IFS
38+
IFS='/'
39+
for I in $1
40+
do
41+
# Resolve relative path punctuation.
42+
if [ "$I" = "." ] || [ -z "$I" ]
43+
then continue
44+
elif [ "$I" = ".." ]
45+
then FOO="${FOO%%/${FOO##*/}}"
46+
continue
47+
else FOO="${FOO}/${I}"
48+
fi
49+
50+
# Dereference symbolic links.
51+
if [ -h "$FOO" ] && [ -x "/bin/ls" ]
52+
then IFS=$OIFS
53+
set `/bin/ls -l "$FOO"`
54+
while shift ;
55+
do
56+
if [ "$1" = "->" ]
57+
then FOO=$2
58+
shift $#
59+
break
60+
fi
61+
done
62+
fi
63+
done
64+
IFS=$OIFS
65+
echo "$FOO"
66+
}
67+
68+
if [ -z "$SONAR_RUNNER_HOME" ] ; then
69+
PRG="$0"
70+
71+
# resolve symlinks
72+
PRG=`real_path "$PRG"`
73+
74+
SONAR_RUNNER_HOME=`dirname "$PRG"`/..
75+
76+
# make it fully qualified
77+
SONAR_RUNNER_HOME=`cd "$SONAR_RUNNER_HOME" && pwd`
78+
fi
79+
80+
# check that the SONAR_RUNNER_HOME has been correctly set
81+
if [ ! -e "$SONAR_RUNNER_HOME/lib/sonar-runner-impl-2.1.jar" ] ; then
82+
echo '$SONAR_RUNNER_HOME' does not point to a valid installation directory: $SONAR_RUNNER_HOME
83+
exit 1
84+
fi
85+
86+
JAVA_CMD="`which java`"
87+
JAVA_CLASSPATH="${SONAR_RUNNER_HOME}"/lib/sonar-runner-impl-2.1.jar
88+
PROJECT_HOME=`pwd`
89+
90+
#echo "Info: Using sonar-runner at $SONAR_RUNNER_HOME"
91+
#echo "Info: Using java at $JAVA_CMD"
92+
#echo "Info: Using classpath $JAVA_CLASSPATH"
93+
#echo "Info: Using project $PROJECT_HOME"
94+
95+
exec "$JAVA_CMD" \
96+
$SONAR_RUNNER_OPTS \
97+
-classpath $JAVA_CLASSPATH \
98+
"-Drunner.home=${SONAR_RUNNER_HOME}" \
99+
"-Dproject.home=${PROJECT_HOME}" \
100+
org.sonar.runner.Main "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
@REM Sonar Runner Startup Script for Windows
2+
@REM
3+
@REM Required ENV vars:
4+
@REM JAVA_HOME - location of a JDK home dir
5+
@REM
6+
@REM Optional ENV vars:
7+
@REM SONAR_RUNNER_HOME - location of runner's installed home dir
8+
@REM SONAR_RUNNER_OPTS - parameters passed to the Java VM when running Sonar
9+
10+
@echo off
11+
12+
set ERROR_CODE=0
13+
14+
@REM set local scope for the variables with windows NT shell
15+
@setlocal
16+
17+
@REM ==== START VALIDATION ====
18+
@REM *** JAVA EXEC VALIDATION ***
19+
if not "%JAVA_HOME%" == "" goto foundJavaHome
20+
21+
for %%i in (java.exe) do set JAVA_EXEC=%%~$PATH:i
22+
23+
if not "%JAVA_EXEC%" == "" (
24+
set JAVA_EXEC="%JAVA_EXEC%"
25+
goto OkJava
26+
)
27+
28+
if not "%JAVA_EXEC%" == "" goto OkJava
29+
30+
echo.
31+
echo ERROR: JAVA_HOME not found in your environment, and no Java
32+
echo executable present in the PATH.
33+
echo Please set the JAVA_HOME variable in your environment to match the
34+
echo location of your Java installation, or add "java.exe" to the PATH
35+
echo.
36+
goto error
37+
38+
:foundJavaHome
39+
if EXIST "%JAVA_HOME%\bin\java.exe" goto foundJavaExeFromJavaHome
40+
41+
echo.
42+
echo ERROR: JAVA_HOME exists but does not point to a valid Java home
43+
echo folder. No "\bin\java.exe" file can be found there.
44+
echo.
45+
goto error
46+
47+
:foundJavaExeFromJavaHome
48+
set JAVA_EXEC="%JAVA_HOME%\bin\java.exe"
49+
50+
@REM *** SONAR RUNNER HOME VALIDATION ***
51+
:OkJava
52+
if NOT "%SONAR_RUNNER_HOME%"=="" goto cleanSonarRunnerHome
53+
set SONAR_RUNNER_HOME=%~dp0..
54+
goto run
55+
56+
:cleanSonarRunnerHome
57+
@REM If the property has a trailing backslash, remove it
58+
if %SONAR_RUNNER_HOME:~-1%==\ set SONAR_RUNNER_HOME=%SONAR_RUNNER_HOME:~0,-1%
59+
60+
@REM Check if the provided SONAR_RUNNER_HOME is a valid install dir
61+
IF EXIST "%SONAR_RUNNER_HOME%\lib\sonar-runner-impl-2.1.jar" goto run
62+
63+
echo.
64+
echo ERROR: SONAR_RUNNER_HOME exists but does not point to a valid install
65+
echo directory: %SONAR_RUNNER_HOME%
66+
echo.
67+
goto error
68+
69+
70+
71+
@REM ==== START RUN ====
72+
:run
73+
echo %SONAR_RUNNER_HOME%
74+
75+
set PROJECT_HOME=%CD%
76+
77+
%JAVA_EXEC% %SONAR_RUNNER_OPTS% -classpath "%SONAR_RUNNER_HOME%\lib\sonar-runner-impl-2.1.jar" "-Drunner.home=%SONAR_RUNNER_HOME%" "-Dproject.home=%PROJECT_HOME%" org.sonar.runner.Main %*
78+
if ERRORLEVEL 1 goto error
79+
goto end
80+
81+
:error
82+
set ERROR_CODE=1
83+
84+
@REM ==== END EXECUTION ====
85+
86+
:end
87+
@REM set local scope for the variables with windows NT shell
88+
@endlocal & set ERROR_CODE=%ERROR_CODE%
89+
90+
@REM see http://code-bear.com/bearlog/2007/06/01/getting-the-exit-code-from-a-batch-file-that-is-run-from-a-python-program/
91+
goto exit
92+
93+
:returncode
94+
exit /B %1
95+
96+
:exit
97+
call :returncode %ERROR_CODE%
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#Configure here general information about the environment, such as Sonar DB details for example
2+
#No information about specific project should appear here
3+
4+
#----- Default Sonar server
5+
#sonar.host.url=http://localhost:9000
6+
7+
#----- PostgreSQL
8+
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
9+
10+
#----- MySQL
11+
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
12+
13+
#----- Oracle
14+
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
15+
16+
#----- Microsoft SQLServer
17+
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
18+
19+
#----- Global database settings
20+
#sonar.jdbc.username=sonar
21+
#sonar.jdbc.password=sonar
22+
23+
#----- Default source code encoding
24+
#sonar.sourceEncoding=UTF-8
25+
26+
#----- Security (when 'sonar.forceAuthentication' is set to 'true')
27+
#sonar.login=admin
28+
#sonar.password=admin
Binary file not shown.

0 commit comments

Comments
 (0)