Skip to content

Commit

Permalink
chore: Improve gradle log strings handling (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 4, 2024
1 parent a7b8303 commit 7ab3404
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions lib/server-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { updateDependencyLines } from './utils';
const GRADLE_VERSION_KEY = 'gradle';
const GRADLE_URL_PREFIX = 'distributionUrl=';
const GRADLE_URL_TEMPLATE = 'https\\://services.gradle.org/distributions/gradle-VERSION-all.zip';
const GRADLE_MAX_ERROR_LOG_LINES = 15;
const DEPENDENCY_PROP_NAMES = ['additionalAppDependencies', 'additionalAndroidTestDependencies'];

const VERSION_KEYS = [
Expand Down Expand Up @@ -175,31 +174,26 @@ class ServerBuilder {
shell: system.isWindows(),
windowsVerbatimArguments: true
});
let buildLastLines = [];
/** @type {string[]} */
let gradleError = [];

const logMsg = `Output from Gradle ${this.showGradleLog ? 'will' : 'will not'} be logged`;
this.log.debug(`${logMsg}. To change this, use 'showGradleLog' desired capability`);
gradlebuild.on('stream-line', (line) => {
if (this.showGradleLog) {
if (line.startsWith('[STDERR]')) {
this.log.warn(`[Gradle] ${line}`);
} else {
this.log.info(`[Gradle] ${line}`);
}
}
buildLastLines.push(`${EOL}${line}`);
if (buildLastLines.length > GRADLE_MAX_ERROR_LOG_LINES) {
buildLastLines = buildLastLines.slice(-GRADLE_MAX_ERROR_LOG_LINES);
}
gradlebuild.on('line-stderr', (line) => {
this.log.warn(`[Gradle] ${line}`);
gradleError.push(line);
});
gradlebuild.on('line-stdout', (line) => this.log.info(`[Gradle] ${line}`));

try {
await gradlebuild.start();
await gradlebuild.join();
} catch (err) {
let msg = `Unable to build Espresso server - ${err.message}\n` +
`Gradle error message:${EOL}${buildLastLines}`;
const msg = `Unable to build Espresso server - ${err.message}\n` +
`Gradle error message:${EOL}${gradleError.join('\n')}`;
this.log.errorAndThrow(msg);
} finally {
gradlebuild.removeAllListeners();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"lodash": "^4.17.11",
"portscanner": "^2.1.1",
"source-map-support": "^0.x",
"teen_process": "^2.0.0"
"teen_process": "^2.2.0"
},
"scripts": {
"build": "npm run build:node && npm run build:server",
Expand Down

0 comments on commit 7ab3404

Please sign in to comment.