cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nim...@apache.org
Subject android commit: CB-9971: Suppressed unwanted java stderr output when running gradle wrapper
Date Mon, 26 Jun 2017 18:42:01 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 3ff32092a -> 540929c6a


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

this closes #388


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/540929c6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/540929c6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/540929c6

Branch: refs/heads/master
Commit: 540929c6a0ced3d186ce9b1efea03c32403b89d1
Parents: 3ff3209
Author: Nikita Matrosov <v-nimatr@microsoft.com>
Authored: Mon Jun 26 20:55:14 2017 +0300
Committer: Nikita Matrosov <v-nimatr@microsoft.com>
Committed: Mon Jun 26 21:17:58 2017 +0300

----------------------------------------------------------------------
 .../cordova/lib/builders/GradleBuilder.js       | 68 +++++++++++---------
 spec/unit/builders/GradleBuilder.spec.js        |  4 +-
 2 files changed, 41 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/540929c6/bin/templates/cordova/lib/builders/GradleBuilder.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/builders/GradleBuilder.js b/bin/templates/cordova/lib/builders/GradleBuilder.js
index c006c65..a0fb2a6 100644
--- a/bin/templates/cordova/lib/builders/GradleBuilder.js
+++ b/bin/templates/cordova/lib/builders/GradleBuilder.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,33 +222,19 @@ 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) {
@@ -253,7 +242,7 @@ GradleBuilder.prototype.clean = function (opts) {
     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;
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/540929c6/spec/unit/builders/GradleBuilder.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/builders/GradleBuilder.spec.js b/spec/unit/builders/GradleBuilder.spec.js
index bae5a79..f8ad1a4 100644
--- a/spec/unit/builders/GradleBuilder.spec.js
+++ b/spec/unit/builders/GradleBuilder.spec.js
@@ -1,6 +1,7 @@
 
 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;
 
@@ -8,7 +9,8 @@ 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 () {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message