From 723b6acc97f8089e45e2a84e7675b7a143e498f5 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 14 Nov 2023 15:06:34 -0600 Subject: [PATCH] fix(bundletool): support spaces in path. (#1494) --- .../shorebird_cli_integration_test.dart | 6 +- .../lib/src/executables/bundletool.dart | 38 +++++++++--- .../test/src/executables/bundletool_test.dart | 58 ++++++++++++++----- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart b/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart index eba71343c..2d2ca4dc8 100644 --- a/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart +++ b/packages/shorebird_cli/integration_test/shorebird_cli_integration_test.dart @@ -88,7 +88,7 @@ void main() { // Initialize Shorebird final initShorebirdResult = runCommand( - 'shorebird init', + 'shorebird init --verbose', workingDirectory: cwd, ); expect(initShorebirdResult.stderr, isEmpty); @@ -128,7 +128,7 @@ void main() { // Create an Android release. final shorebirdReleaseResult = runCommand( - 'shorebird release android --force', + 'shorebird release android --force --verbose', workingDirectory: cwd, ); expect(shorebirdReleaseResult.stderr, isEmpty); @@ -174,7 +174,7 @@ void main() { // Create an Android patch. final shorebirdPatchResult = runCommand( - 'shorebird patch android --force', + 'shorebird patch android --force --verbose', workingDirectory: cwd, ); expect(shorebirdPatchResult.stderr, isEmpty); diff --git a/packages/shorebird_cli/lib/src/executables/bundletool.dart b/packages/shorebird_cli/lib/src/executables/bundletool.dart index db871ed60..3aa1e2fd5 100644 --- a/packages/shorebird_cli/lib/src/executables/bundletool.dart +++ b/packages/shorebird_cli/lib/src/executables/bundletool.dart @@ -13,7 +13,7 @@ Bundletool get bundletool => read(bundletoolRef); class Bundletool { static const jar = 'bundletool.jar'; - Future _exec(String command) async { + Future _exec(List command) async { await cache.updateAll(); final bundletool = p.join(cache.getArtifactDirectory(jar).path, jar); final javaHome = java.home; @@ -21,7 +21,7 @@ class Bundletool { return process.run( javaExecutable, - ['-jar', bundletool, ...command.split(' ')], + ['-jar', bundletool, ...command], environment: { if (javaHome != null) 'JAVA_HOME': javaHome, }, @@ -39,7 +39,13 @@ class Bundletool { required String output, }) async { final result = await _exec( - '''build-apks --overwrite --bundle=$bundle --output=$output --mode=universal''', + [ + 'build-apks', + '--overwrite', + '--bundle=$bundle', + '--output=$output', + '--mode=universal', + ], ); if (result.exitCode != 0) { throw Exception('Failed to build apks: ${result.stderr}'); @@ -61,7 +67,7 @@ class Bundletool { '--allow-downgrade', if (deviceId != null) '--device-id=$deviceId', ]; - final result = await _exec(args.join(' ')); + final result = await _exec(args); if (result.exitCode != 0) { throw Exception('Failed to install apks: ${result.stderr}'); } @@ -70,7 +76,13 @@ class Bundletool { /// Extract the package name from an app bundle. Future getPackageName(String appBundlePath) async { final result = await _exec( - 'dump manifest --bundle=$appBundlePath --xpath /manifest/@package', + [ + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@package', + ], ); if (result.exitCode != 0) { @@ -85,7 +97,13 @@ class Bundletool { /// Extract the version name from an app bundle. Future getVersionName(String appBundlePath) async { final result = await _exec( - 'dump manifest --bundle=$appBundlePath --xpath /manifest/@android:versionName', + [ + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@android:versionName', + ], ); if (result.exitCode != 0) { @@ -100,7 +118,13 @@ class Bundletool { /// Extract the version code from an app bundle. Future getVersionCode(String appBundlePath) async { final result = await _exec( - 'dump manifest --bundle=$appBundlePath --xpath /manifest/@android:versionCode', + [ + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@android:versionCode', + ], ); if (result.exitCode != 0) { diff --git a/packages/shorebird_cli/test/src/executables/bundletool_test.dart b/packages/shorebird_cli/test/src/executables/bundletool_test.dart index b3c116190..7fca0d268 100644 --- a/packages/shorebird_cli/test/src/executables/bundletool_test.dart +++ b/packages/shorebird_cli/test/src/executables/bundletool_test.dart @@ -33,7 +33,7 @@ void main() { } setUp(() { - workingDirectory = Directory.systemTemp.createTempSync(); + workingDirectory = Directory.systemTemp.createTempSync('bundletool test'); cache = MockCache(); java = MockJava(); process = MockShorebirdProcess(); @@ -106,8 +106,15 @@ void main() { verify( () => process.run( 'java', - '''-jar ${p.join(workingDirectory.path, 'bundletool.jar')} build-apks --overwrite --bundle=$appBundlePath --output=$output --mode=universal''' - .split(' '), + [ + '-jar', + p.join(workingDirectory.path, 'bundletool.jar'), + 'build-apks', + '--overwrite', + '--bundle=$appBundlePath', + '--output=$output', + '--mode=universal', + ], environment: { 'JAVA_HOME': javaHome, }, @@ -169,16 +176,20 @@ void main() { verify( () => process.run( 'java', - '''-jar ${p.join(workingDirectory.path, 'bundletool.jar')} install-apks --apks=$apks --allow-downgrade --device-id=$deviceId''' - .split(' '), + [ + '-jar', + p.join(workingDirectory.path, 'bundletool.jar'), + 'install-apks', + '--apks=$apks', + '--allow-downgrade', + '--device-id=$deviceId', + ], environment: { 'JAVA_HOME': javaHome, }, ), ).called(1); }); - - test('forwards deviceId if provided', () async {}); }); group('getPackageName', () { @@ -232,8 +243,15 @@ void main() { verify( () => process.run( 'java', - '-jar ${p.join(workingDirectory.path, 'bundletool.jar')} dump manifest --bundle=$appBundlePath --xpath /manifest/@package' - .split(' '), + [ + '-jar', + p.join(workingDirectory.path, 'bundletool.jar'), + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@package', + ], environment: { 'JAVA_HOME': javaHome, }, @@ -293,8 +311,15 @@ void main() { verify( () => process.run( 'java', - '-jar ${p.join(workingDirectory.path, 'bundletool.jar')} dump manifest --bundle=$appBundlePath --xpath /manifest/@android:versionName' - .split(' '), + [ + '-jar', + p.join(workingDirectory.path, 'bundletool.jar'), + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@android:versionName', + ], environment: { 'JAVA_HOME': javaHome, }, @@ -353,8 +378,15 @@ void main() { verify( () => process.run( 'java', - '-jar ${p.join(workingDirectory.path, 'bundletool.jar')} dump manifest --bundle=$appBundlePath --xpath /manifest/@android:versionCode' - .split(' '), + [ + '-jar', + p.join(workingDirectory.path, 'bundletool.jar'), + 'dump', + 'manifest', + '--bundle=$appBundlePath', + '--xpath', + '/manifest/@android:versionCode', + ], environment: { 'JAVA_HOME': javaHome, },