Skip to content
Open
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
62 changes: 31 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var fs = require('fs'),
path = require('path'),
through = require('through2'),
gutil = require('gulp-util'),
PluginError = gutil.PluginError,
exec = require('child_process').exec,
os = require('os'),
format = require('util').format;
var fs = require("fs"),
path = require("path"),
through = require("through2"),
log = require("fancy-log"),
PluginError = require("plugin-error"),
exec = require("child_process").exec,
os = require("os"),
format = require("util").format;

module.exports = function (options) {
var SONAR_VERSION,
Expand All @@ -16,10 +16,10 @@ module.exports = function (options) {
flush;

SONAR_VERSION = "2.8";
SONAR_SCANNER_HOME = path.join(__dirname, format('/sonar-scanner-%s', SONAR_VERSION));
SONAR_SCANNER_PROPERTIES = path.join(__dirname, format('/sonar-scanner-%s', SONAR_VERSION), 'conf', 'sonar-scanner.properties');
SONAR_SCANNER_JAR = format('/lib/sonar-scanner-cli-%s.jar', SONAR_VERSION);
SONAR_SCANNER_COMMAND = 'java -jar "' + path.join(SONAR_SCANNER_HOME, SONAR_SCANNER_JAR) + '" -X -Drunner.home="' + SONAR_SCANNER_HOME + '" -Dproject.settings="' + SONAR_SCANNER_PROPERTIES + '"';
SONAR_SCANNER_HOME = path.join(__dirname, format("/sonar-scanner-%s", SONAR_VERSION));
SONAR_SCANNER_PROPERTIES = path.join(__dirname, format("/sonar-scanner-%s", SONAR_VERSION), "conf", "sonar-scanner.properties");
SONAR_SCANNER_JAR = format("/lib/sonar-scanner-cli-%s.jar", SONAR_VERSION);
SONAR_SCANNER_COMMAND = "java -jar \"" + path.join(SONAR_SCANNER_HOME, SONAR_SCANNER_JAR) + "\" -X -Drunner.home=\"" + SONAR_SCANNER_HOME + "\" -Dproject.settings=\"" + SONAR_SCANNER_PROPERTIES + "\"";

write = function (file, enc, cb) {
// do nothing with source ... not needed
Expand All @@ -30,24 +30,24 @@ module.exports = function (options) {
var props,
process;

options = (typeof options === 'object') ? options : { sonar: {} };
options = (typeof options === "object") ? options : { sonar: {} };
options.sonar.language = options.sonar.language;
options.sonar.sourceEncoding = options.sonar.sourceEncoding || 'UTF-8';
options.sonar.host = options.sonar.host || { url: 'http://localhost:9000' };
options.sonar.sourceEncoding = options.sonar.sourceEncoding || "UTF-8";
options.sonar.host = options.sonar.host || { url: "http://localhost:9000" };
options_exec = options.sonar.exec;
// This property is not for the sonar runner, but for the nodejs exec method, so we remove it after copied it
delete options.sonar.exec;

function objectToProps(obj, result, prefix, o, prop) {
obj = (typeof obj === 'object') ? obj : {};
result = (typeof result === 'object' && typeof result.length === 'number') ? result : [];
prefix = (typeof prefix === 'string' && prefix.length) ? prefix + '.' : '';
obj = (typeof obj === "object") ? obj : {};
result = (typeof result === "object" && typeof result.length === "number") ? result : [];
prefix = (typeof prefix === "string" && prefix.length) ? prefix + "." : "";
for (o in obj) {
if (obj.hasOwnProperty(o)) {
prop = prefix + o;
if (typeof obj[o] === 'string') {
result.push(prop + '=' + obj[o]);
} else if (typeof obj[o] === 'object') {
if (typeof obj[o] === "string") {
result.push(prop + "=" + obj[o]);
} else if (typeof obj[o] === "object") {
result = objectToProps(obj[o], result, prop);
}
}
Expand All @@ -57,23 +57,23 @@ module.exports = function (options) {

props = objectToProps(options);

fs.writeFile(path.join(SONAR_SCANNER_HOME, '/conf/sonar-scanner.properties'), props.join(os.EOL), function (err) {
fs.writeFile(path.join(SONAR_SCANNER_HOME, "/conf/sonar-scanner.properties"), props.join(os.EOL), function (err) {
if (err) {
throw new PluginError('gulp-sonar', format('Error writing properties file: %d.', err));
throw new PluginError("gulp-sonar", format("Error writing properties file: %d.", err));
} else {
process = exec(SONAR_SCANNER_COMMAND, options_exec, function () {});
process.stdout.on('data', function (c) {
gutil.log(c);
process.stdout.on("data", function (c) {
log(c);
});
process.stderr.on('data', function (c) {
gutil.log(c);
process.stderr.on("data", function (c) {
log(c);
});
process.on('exit', function (code) {
process.on("exit", function (code) {
if (code !== 0) {
gutil.log(format('Return code: %d.', code));
throw new PluginError('gulp-sonar', format('Return code: %d.', code));
log(format("Return code: %d.", code));
throw new PluginError("gulp-sonar", format("Return code: %d.", code));
}
gutil.log(format('Return code: %d.', code));
log(format("Return code: %d.", code));
cb();
});
}
Expand Down
155 changes: 155 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
{
"name": "gulp-sonar",
"description": "Sonar runner for gulp.",
"version": "3.0.1",
"version": "3.0.2",
"homepage": "https://github.com/carsdotcom/gulp-sonar",
"author": {
"name": "Mac Heller-Ogden",
"email": "mac@machellerogden.com"
"name": "Felix Willnecker (Mac Heller-Ogden)",
"email": "felix.willnecker@web.de"
},
"repository": {
"type": "git",
"url": "git@github.com/carsdotcom/gulp-sonar.git"
"url": "git@github.com/Floix/gulp-sonar.git"
},
"bugs": {
"url": "https://github.com/carsdotcom/gulp-sonar/issues"
"url": "https://github.com/Floix/gulp-sonar/issues"
},
"licenses": [
{
"type": "Apache 2.0",
"url": "https://github.com/carsdotcom/gulp-sonar/blob/master/LICENSE.txt"
}
],
"license": "Apache-2.0",
"engines": {
"node": ">= 0.10"
},
"devDependencies": {
"gulp": "^3.9.0"
},
"devDependencies": {},
"peerDependencies": {},
"keywords": [
"gulpplugin",
"sonar",
"sonar-runner"
],
"dependencies": {
"gulp-util": "3.0.1",
"fancy-log": "1.3.2",
"plugin-error": "1.0.1",
"through2": "0.6.3",
"properties": "1.2.1"
}
Expand Down