Skip to content

Commit

Permalink
fix(android): gradle warning log
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Dec 30, 2022
1 parent 881552f commit a48c173
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions android/cli/lib/gradle-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ class GradleWrapper {
}

// Function which returns a stdout/stderr "data" reading function object and outputs it to given "logFunction".
// The "logFunction" argument is expected to be an appc "logger.info" or "logger.error" object.
const createReadableDataHandlerUsing = (logFunction) => {
// The "logFunction" argument is expected to be a "logger" object that conatins "logger.info" or "logger.error".
// The "logType" is a string "error" or "info" to call the correct logger function
const createReadableDataHandlerUsing = (logFunction, logType) => {
let stringBuffer = '';
return (data) => {
// Append the received string data to existing buffer.
Expand All @@ -190,7 +191,8 @@ class GradleWrapper {
// Log the received messages, split by newline. (Strip out carriage returns on Windows.)
const messageArray = stringBuffer.substr(0, index).split('\n');
for (const nextMessage of messageArray) {
logFunction('[GRADLE] ' + nextMessage.replace(/\r/g, ''));
var logMethod = (logType === 'info') ? 'info' : nextMessage.includes('Warning: ') ? 'warn' : 'error';
logFunction[logMethod]('[GRADLE] ' + nextMessage.replace(/\r/g, ''));
}

// Remove the above logged strings from the buffer.
Expand All @@ -207,8 +209,8 @@ class GradleWrapper {
await new Promise((resolve, reject) => {
const childProcess = exec(commandLineString, { cwd: this._gradlewDirPath });
if (this._logger) {
childProcess.stdout.on('data', createReadableDataHandlerUsing(this._logger.info));
childProcess.stderr.on('data', createReadableDataHandlerUsing(this._logger.error));
childProcess.stdout.on('data', createReadableDataHandlerUsing(this._logger, 'info'));
childProcess.stderr.on('data', createReadableDataHandlerUsing(this._logger, 'error'));
}
childProcess.on('error', reject);
childProcess.on('exit', (exitCode) => {
Expand Down

0 comments on commit a48c173

Please sign in to comment.