Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Xamarin.Android.Tools;

Expand Down Expand Up @@ -56,13 +55,12 @@ internal override bool ProcessOutput (string singleLine, AssemblyIdentityMap ass
{
var match = installErrorRegEx.Match (singleLine);
if (match.Success) {
// error message
var error = match.Groups ["error"].Value;
var exception = match.Groups ["exception"].Value;
SetFileLineAndColumn (ApkSet, line: 1, column: 0);
AppendTextToErrorText (exception);
AppendTextToErrorText (error);
return LogFromException (exception, error);;
return LogFromException (exception, error);
}
return base.ProcessOutput (singleLine, assemblyMap);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Framework;
using NUnit.Framework;
using Xamarin.Android.Tasks;
using Xamarin.Android.Tools;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -31,18 +34,59 @@ public void BuildApkSetCommand ()
}

[Test]
public void InstallApkSetCommand ()
public void InstallApkSetCommandPreservesJavaOptions ()
{
var task = new InstallApkSet {
ApkSet = "foo.apks",
AdbToolPath = Path.Combine ("path", "with spaces"),
AdbToolExe = "adb",
AdbTarget = "-s emulator-5554",
JarPath = "bundletool.jar",
JavaOptions = "-Dexample=\"cost$5\"",
};
string adb = Path.Combine (task.AdbToolPath, task.AdbToolExe);
string cmd = task.GetCommandLineBuilder ().ToString ();
Assert.AreEqual ($"-jar bundletool.jar install-apks --apks foo.apks --adb \"{adb}\" --device-id emulator-5554 --allow-downgrade --modules _ALL_", cmd);
Assert.AreEqual ($"-Dexample=\"cost$5\" -jar bundletool.jar install-apks --apks foo.apks --adb \"{adb}\" --device-id emulator-5554 --allow-downgrade --modules _ALL_", cmd);
}

[Test]
public void InstallApkSetReportsQuotedBundletoolErrors ()
{
var errors = new List<BuildErrorEventArgs> ();
var task = new TestableInstallApkSet {
ApkSet = "application.apks",
BuildEngine = new MockBuildEngine (TextWriter.Null, errors),
};

task.AddOutput ("com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: Device 'emulator-5554' not found.");
task.ProcessErrors ();

Assert.AreEqual (1, errors.Count);
Assert.AreEqual ("BT0000", errors [0].Code);
Assert.AreEqual ("application.apks", errors [0].File);
StringAssert.Contains ("Device 'emulator-5554' not found.", errors [0].Message);
}

[Test]
public void InstallApkSetIgnoresQuotedNonmatchingOutput ()
{
var errors = new List<BuildErrorEventArgs> ();
var task = new TestableInstallApkSet {
ApkSet = "application.apks",
BuildEngine = new MockBuildEngine (TextWriter.Null, errors),
};

Assert.IsTrue (task.ProcessOutputLine ("File 'application.apks' was not found."));
Assert.IsEmpty (errors);
}

sealed class TestableInstallApkSet : InstallApkSet
{
public void AddOutput (string line) => LogEventsFromTextOutput (line, MessageImportance.Normal);

public void ProcessErrors () => HandleTaskExecutionErrors ();

public bool ProcessOutputLine (string line) => ProcessOutput (line, new AssemblyIdentityMap ());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,7 @@ because xbuild doesn't support framework reference assemblies.
JdkVersion="$(_JdkVersion)"
JarPath="$(AndroidBundleToolJarPath)"
AdbToolPath="$(AdbToolPath)"
AdbToolExe="$(AdbToolExe)"
AdbTarget="$(AdbTarget)"
ApkSet="$(_ApkSetIntermediate)"
Modules="@(AndroidInstallModules)"
Expand Down