Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ This error is likely caused by an issue with the AndroidManifest.xml file or an
<data name="APT0004" xml:space="preserve">
<value>Invalid file name: It must start with A-z or a-z or an underscore.</value>
</data>
<data name="APT0005" xml:space="preserve">
<value>Invalid file name: Filenames cannot use Java reserved words.</value>
</data>
<data name="XA0000_API_for_TargetFrameworkVersion" xml:space="preserve">
<value>Could not determine API level for $(TargetFrameworkVersion) of '{0}'.</value>
<comment>The following are literal names and should not be translated: $(TargetFrameworkVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class CheckForInvalidResourceFileNames : AndroidTask {
Regex fileNameCheck = new Regex ("[^a-zA-Z0-9_.]+", RegexOptions.Compiled);
Regex fileNameWithHyphenCheck = new Regex ("[^a-zA-Z0-9_.-]+", RegexOptions.Compiled);

Regex fileNameJavaReservedWordCheck = new Regex("^\\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strict|fp|volatile|const|float|native|super|while)\\b$", RegexOptions.Compiled);

public override bool RunTask ()
{
foreach (var resource in Resources) {
Expand All @@ -45,6 +47,10 @@ public override bool RunTask ()
if (match.Success) {
Log.LogCodedError ("APT0003", resource.ItemSpec, 0, Properties.Resources.APT0003, fileNameCheck);
}
match = fileNameJavaReservedWordCheck.Match (Path.GetFileNameWithoutExtension (fileName));
if (match.Success) {
Log.LogCodedError ("APT0005", resource.ItemSpec, 0, Properties.Resources.APT0005, fileNameCheck);
}
}
}
return !Log.HasLoggedErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public class CheckForInvalidResourceFileNamesTests : BaseTest {
false,
2,
},
new object[] {
"import.xml",
false,
1,
},
new object[] {
"class.png",
false,
1,
},
new object[] {
"class1.png",
true,
0,
},
};
#pragma warning restore 414
[Test]
Expand Down
Loading