Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
int line = 0;
if (!string.IsNullOrEmpty (match.Groups["line"]?.Value))
line = int.Parse (match.Groups["line"].Value) + 1;
var error = match.Groups["message"].Value;
if (error.Contains ("warning")) {
var level = match.Groups["level"].Value;
var message = match.Groups ["message"].Value;
if (level.Contains ("warning")) {
LogWarning (singleLine);
return;
}
Expand All @@ -379,10 +380,10 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
}

// Strip any "Error:" text from aapt's output
if (error.StartsWith ("error: ", StringComparison.InvariantCultureIgnoreCase))
error = error.Substring ("error: ".Length);
if (message.StartsWith ("error: ", StringComparison.InvariantCultureIgnoreCase))
message = message.Substring ("error: ".Length);

LogError ("APT0000", error, file, line);
LogError ("APT0000", message, file, line);
return;
}

Expand Down
26 changes: 24 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,32 @@ protected virtual Regex ErrorRegex {
// res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.]
// Look for them and convert them to MSBuild compatible errors.
static Regex androidErrorRegex;
internal static Regex AndroidErrorRegex {
public static Regex AndroidErrorRegex {
get {
if (androidErrorRegex == null)
androidErrorRegex = new Regex (@"^(?<file>.+?)([:(](?<line>\d+)[:)])?:+\s*((error)\s*(?<level>\w*(?=:)):?)?(?<message>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
androidErrorRegex = new Regex (@"
^
( # start optional path followed by `:`
(?<path>
(?<file>.+[\\/][^:\(]+)
(
([:](?<line>\d+))
|
(\((?<line>\d+)\))
)?
)
\s*
:
)?
( # optional warning|error:
\s*
(?<level>(warning|error)[^:]*)\s*
:
)?
\s*
(?<message>.*)
$
", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
return androidErrorRegex;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace Xamarin.Android.Build.Tests
{
public class AndroidRegExTests
{


/*
"Resources/values/theme.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'." \
"Resources/values/theme.xml:2: error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'." \
"res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.]"

*/
class AndroidRegExTestsCases : IEnumerable {
public IEnumerator GetEnumerator ()
{
yield return new object [] {
/*message*/ "warning: string 'app_name1' has no default translation.",
/*expectedToMatch*/ true,
/*expectedFile*/ "",
/*expectedLine*/ "",
/*expectedLevel*/ "warning",
/*expectedMessage*/ "string 'app_name1' has no default translation."
};
yield return new object [] {
/*message*/ "res\\layout\\main.axml: error: No resource identifier found for attribute \"id2\" in package \"android\" (TaskId:22)",
/*expectedToMatch*/ true,
/*expectedFile*/ "res\\layout\\main.axml",
/*expectedLine*/ "",
/*expectedLevel*/ "error",
/*expectedMessage*/ "No resource identifier found for attribute \"id2\" in package \"android\" (TaskId:22)"
};
yield return new object [] {
/*message*/ "Resources/values/theme.xml(2): error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.",
/*expectedToMatch*/ true,
/*expectedFile*/ "Resources/values/theme.xml",
/*expectedLine*/ "2",
/*expectedLevel*/ "error APT0000",
/*expectedMessage*/ "Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'."
};
yield return new object [] {
/*message*/ "Resources/values/theme.xml:2: error APT0000: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'.",
/*expectedToMatch*/ true,
/*expectedFile*/ "Resources/values/theme.xml",
/*expectedLine*/ "2",
/*expectedLevel*/ "error APT0000",
/*expectedMessage*/ "Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat'."
};
yield return new object [] {
/*message*/ "res/drawable/foo-bar.jpg: Invalid file name: must contain only [a-z0-9_.]",
/*expectedToMatch*/ true,
/*expectedFile*/ "res/drawable/foo-bar.jpg",
/*expectedLine*/ "",
/*expectedLevel*/ "",
/*expectedMessage*/ "Invalid file name: must contain only [a-z0-9_.]"
};

}
}

[Test]
[TestCaseSource(typeof (AndroidRegExTestsCases))]
public void RegExTests(string message, bool expectedToMatch, string expectedFile, string expectedLine, string expectedLevel, string expextedMessage)
{
var regex = Xamarin.Android.Tasks.AndroidToolTask.AndroidErrorRegex;
var result = regex.Match (message);
Assert.AreEqual (expectedToMatch,result.Success);
Assert.AreEqual (expectedFile, result.Groups["file"].Value);
Assert.AreEqual (expectedLine.ToString (), result.Groups ["line"].Value);
Assert.AreEqual (expectedLevel, result.Groups ["level"].Value);
Assert.AreEqual (expextedMessage, result.Groups ["message"].Value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1083,5 +1083,29 @@ public void BuildAppWithManagedResourceParserAndLibraries ()
}
}
}

[Test]
public void CheckDefaultTranslationWarnings ()
{
var path = Path.Combine ("temp", TestName);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
OtherBuildItems = {
new BuildItem.Folder ("Resources\\values-fr\\") {
},
},
};

proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values-fr\\Strings.xml") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-8""?>
<resources>
<string name=""test"" >Test</string>
</resources>",
});
using (var builder = CreateApkBuilder (path, false, false)) {
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
StringAssert.Contains ("has no default translation", builder.LastBuildOutput, "Build output should contain a warning about 'no default translation'");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<!-- Because Xamarin.Android.Build.Tasks.csproj doesn't build in VsForMac :(
<Reference Include="Xamarin.Android.Build.Tasks" Condition="Exists('$(OutputPath)..\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll')">
<HintPath>$(OutputPath)..\$(Configuration)\lib\xamarin.android\xbuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll</HintPath>
</Reference>
-->
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand All @@ -49,6 +57,10 @@
<Project>{E248B2CA-303B-4645-ADDC-9D4459D550FD}</Project>
<Name>libZipSharp</Name>
</ProjectReference>
<ProjectReference Include="..\..\Xamarin.Android.Build.Tasks.csproj">
<Project>{3F1F2F50-AF1A-4A5A-BEDB-193372F068D7}</Project>
<Name>Xamarin.Android.Build.Tasks</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -59,5 +71,6 @@
<ItemGroup>
<Compile Include="BuildTest.OSS.cs" />
<Compile Include="ManifestTest.OSS.cs" />
<Compile Include="AndroidRegExTests.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public static class BuildActions
public const string Compile = "Compile";
public const string EmbeddedResource = "EmbeddedResource";
public const string Content = "Content";
public const string Folder = "Folder";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ public NoActionResource (Func<string> include)
}
}

public class Folder : BuildItem
{
public Folder (string include)
: this (() => include)
{
}
public Folder (Func<string> include)
: base (BuildActions.Folder, include)
{
}
}

public class Content : BuildItem
{
public Content (string include)
Expand Down