Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
58 changes: 29 additions & 29 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"),
gutil = require("fancy-log"),
Copy link

@DullReferenceException DullReferenceException Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. From the docs on fancy-log, there is no log method attached; rather, the main export is the log function:

https://github.com/gulpjs/fancy-log/blob/master/index.js#L88-L92

So maybe you could make this:

log = require("fancy-log")

...and replace all the gutil.log(...) calls with log(...).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this with bf34a1d. Thank you for the suggestion

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) {
process.stdout.on("data", function (c) {
gutil.log(c);
});
process.stderr.on('data', function (c) {
process.stderr.on("data", function (c) {
gutil.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));
gutil.log(format("Return code: %d.", code));
throw new PluginError("gulp-sonar", format("Return code: %d.", code));
}
gutil.log(format('Return code: %d.', code));
gutil.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.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"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",
Expand All @@ -23,17 +23,16 @@
"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