Skip to content

Commit

Permalink
fix(bundletool): support spaces in path. (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Nov 14, 2023
1 parent 968ed2e commit 723b6ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main() {

// Initialize Shorebird
final initShorebirdResult = runCommand(
'shorebird init',
'shorebird init --verbose',
workingDirectory: cwd,
);
expect(initShorebirdResult.stderr, isEmpty);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 31 additions & 7 deletions packages/shorebird_cli/lib/src/executables/bundletool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Bundletool get bundletool => read(bundletoolRef);
class Bundletool {
static const jar = 'bundletool.jar';

Future<ShorebirdProcessResult> _exec(String command) async {
Future<ShorebirdProcessResult> _exec(List<String> command) async {
await cache.updateAll();
final bundletool = p.join(cache.getArtifactDirectory(jar).path, jar);
final javaHome = java.home;
final javaExecutable = java.executable ?? 'java';

return process.run(
javaExecutable,
['-jar', bundletool, ...command.split(' ')],
['-jar', bundletool, ...command],
environment: {
if (javaHome != null) 'JAVA_HOME': javaHome,
},
Expand All @@ -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}');
Expand All @@ -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}');
}
Expand All @@ -70,7 +76,13 @@ class Bundletool {
/// Extract the package name from an app bundle.
Future<String> 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) {
Expand All @@ -85,7 +97,13 @@ class Bundletool {
/// Extract the version name from an app bundle.
Future<String> 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) {
Expand All @@ -100,7 +118,13 @@ class Bundletool {
/// Extract the version code from an app bundle.
Future<String> 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) {
Expand Down
58 changes: 45 additions & 13 deletions packages/shorebird_cli/test/src/executables/bundletool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
}

setUp(() {
workingDirectory = Directory.systemTemp.createTempSync();
workingDirectory = Directory.systemTemp.createTempSync('bundletool test');
cache = MockCache();
java = MockJava();
process = MockShorebirdProcess();
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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', () {
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 723b6ac

Please sign in to comment.