Permalink
Browse files

CB-9971: Suppressed unwanted java stderr output when running gradle w…

…rapper

this closes #388
1 parent 3ff3209 commit 540929c6a0ced3d186ce9b1efea03c32403b89d1 @matrosov-nikita matrosov-nikita committed Jun 26, 2017
Showing with 41 additions and 31 deletions.
  1. +38 −30 bin/templates/cordova/lib/builders/GradleBuilder.js
  2. +3 −1 spec/unit/builders/GradleBuilder.spec.js
@@ -37,7 +37,7 @@ var TEMPLATE =
function GradleBuilder (projectRoot) {
GenericBuilder.call(this, projectRoot);
- this.binDirs = {gradle: this.binDirs.gradle};
+ this.binDirs = { gradle: this.binDirs.gradle };
}
util.inherits(GradleBuilder, GenericBuilder);
@@ -73,9 +73,12 @@ GradleBuilder.prototype.runGradleWrapper = function (gradle_cmd) {
var gradlePath = path.join(this.root, 'gradlew');
var wrapperGradle = path.join(this.root, 'wrapper.gradle');
if (fs.existsSync(gradlePath)) {
- // Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
+ // Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
} else {
- return superspawn.spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'});
+ return superspawn.spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], { stdio: 'pipe' })
+ .progress(function (stdio) {
+ suppressJavaOptionsInfo(stdio);
+ });
}
};
@@ -219,41 +222,27 @@ GradleBuilder.prototype.build = function (opts) {
var wrapper = path.join(this.root, 'gradlew');
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
- return superspawn.spawn(wrapper, args, {stdio: 'pipe'}).progress(function (stdio) {
- if (stdio.stderr) {
- /*
- * Workaround for the issue with Java printing some unwanted information to
- * stderr instead of stdout.
- * This function suppresses 'Picked up _JAVA_OPTIONS' message from being
- * printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
- * explanation.
- */
- var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
- if (suppressThisLine) {
- return;
+ return superspawn.spawn(wrapper, args, { stdio: 'pipe' })
+ .progress(function (stdio) {
+ suppressJavaOptionsInfo(stdio);
+ }).catch(function (error) {
+ if (error.toString().indexOf('failed to find target with hash string') >= 0) {
+ return check_reqs.check_android_target(error).then(function () {
+ // If due to some odd reason - check_android_target succeeds
+ // we should still fail here.
+ return Q.reject(error);
+ });
}
- process.stderr.write(stdio.stderr);
- } else {
- process.stdout.write(stdio.stdout);
- }
- }).catch(function (error) {
- if (error.toString().indexOf('failed to find target with hash string') >= 0) {
- return check_reqs.check_android_target(error).then(function () {
- // If due to some odd reason - check_android_target succeeds
- // we should still fail here.
- return Q.reject(error);
- });
- }
- return Q.reject(error);
- });
+ return Q.reject(error);
+ });
};
GradleBuilder.prototype.clean = function (opts) {
var builder = this;
var wrapper = path.join(this.root, 'gradlew');
var args = builder.getArgs('clean', opts);
return Q().then(function () {
- return superspawn.spawn(wrapper, args, {stdio: 'inherit'});
+ return superspawn.spawn(wrapper, args, { stdio: 'inherit' });
}).then(function () {
shell.rm('-rf', path.join(builder.root, 'out'));
@@ -268,6 +257,25 @@ GradleBuilder.prototype.clean = function (opts) {
module.exports = GradleBuilder;
+function suppressJavaOptionsInfo (stdio) {
+ if (stdio.stderr) {
+ /*
+ * Workaround for the issue with Java printing some unwanted information to
+ * stderr instead of stdout.
+ * This function suppresses 'Picked up _JAVA_OPTIONS' message from being
+ * printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
+ * explanation.
+ */
+ var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
+ if (suppressThisLine) {
+ return;
+ }
+ process.stderr.write(stdio.stderr);
+ } else {
+ process.stdout.write(stdio.stdout);
+ }
+}
+
function isAutoGenerated (file) {
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
}
@@ -1,14 +1,16 @@
var Gradle_builder = require('../../../bin/templates/cordova/lib/builders/GradleBuilder.js');
var fs = require('fs');
+var Q = require('q');
var superspawn = require('cordova-common').superspawn;
var builder;
describe('Gradle Builder', function () {
beforeEach(function () {
spyOn(fs, 'existsSync').and.returnValue(true);
builder = new Gradle_builder('/root');
- spyOn(superspawn, 'spawn');
+ var deferred = Q.defer();
+ spyOn(superspawn, 'spawn').and.returnValue(deferred.promise);
});
describe('runGradleWrapper method', function () {

0 comments on commit 540929c

Please sign in to comment.