From e17f1a34718c71c884d0fd3a481148295e40800c Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Wed, 25 Oct 2017 11:19:07 +0100 Subject: [PATCH 1/2] [Xamarin.Android.Build.Tasks] Remove Unsupported Lint Checks If a user provides lint checks which are not supported by the current lint version it will error. Invalid id or ategory "StatckFieldLeak" This is normally ok. But in our build system we sometimes end up on a bot which has an older version of lint. And in this case the test fails, which in reality it should ignore the id we are trying to use. So this commit addds some validation to the Disabled and Enabled checks. If its not supported we will remove the check and issue a warning. --- src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs index 548b81999b4..daefbe65307 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs @@ -174,7 +174,7 @@ public Lint () { "MissingSuperCall", new Version (26, 1, 1) }, }; - static readonly Regex lintVersionRegex = new Regex (@"version[\t\s]+(?[\d\.]+)"); + static readonly Regex lintVersionRegex = new Regex (@"version[\t\s]+(?[\d\.]+)", RegexOptions.Compiled); public override bool Execute () { @@ -205,6 +205,26 @@ public override bool Execute () Log.LogDebugTaskItems (" LibraryDirectories:", LibraryDirectories); Log.LogDebugTaskItems (" LibraryJars:", LibraryJars); + foreach (var issue in DisabledIssuesByVersion) { + if (lintToolVersion < issue.Value) { + Regex issueReplaceRegex = new Regex ($"{issue.Key}(,)?"); + if (!string.IsNullOrEmpty (DisabledIssues) && DisabledIssues.Contains (issue.Key)) { + var match = issueReplaceRegex.Match (DisabledIssues); + if (match.Success) { + DisabledIssues = DisabledIssues.Replace (match.Value, string.Empty); + Log.LogWarning ($"Removing {issue.Key} from DisabledIssues. Lint {lintToolVersion} does not support this check."); + } + } + if (!string.IsNullOrEmpty (EnabledIssues) && EnabledIssues.Contains (issue.Key)) { + var match = issueReplaceRegex.Match (EnabledIssues); + if (match.Success) { + EnabledIssues = EnabledIssues.Replace (match.Value, string.Empty); + Log.LogWarning ($"Removing {issue.Key} from EnabledIssues. Lint {lintToolVersion} does not support this check."); + } + } + } + } + base.Execute (); return !Log.HasLoggedErrors; From 51627bcf1f95924d829dcc52947ced53b87c5ec8 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 26 Oct 2017 09:42:43 +0100 Subject: [PATCH 2/2] Reworked code to use a common method --- src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs index daefbe65307..e113944a62f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs @@ -207,21 +207,8 @@ public override bool Execute () foreach (var issue in DisabledIssuesByVersion) { if (lintToolVersion < issue.Value) { - Regex issueReplaceRegex = new Regex ($"{issue.Key}(,)?"); - if (!string.IsNullOrEmpty (DisabledIssues) && DisabledIssues.Contains (issue.Key)) { - var match = issueReplaceRegex.Match (DisabledIssues); - if (match.Success) { - DisabledIssues = DisabledIssues.Replace (match.Value, string.Empty); - Log.LogWarning ($"Removing {issue.Key} from DisabledIssues. Lint {lintToolVersion} does not support this check."); - } - } - if (!string.IsNullOrEmpty (EnabledIssues) && EnabledIssues.Contains (issue.Key)) { - var match = issueReplaceRegex.Match (EnabledIssues); - if (match.Success) { - EnabledIssues = EnabledIssues.Replace (match.Value, string.Empty); - Log.LogWarning ($"Removing {issue.Key} from EnabledIssues. Lint {lintToolVersion} does not support this check."); - } - } + DisabledIssues = CleanIssues (issue.Key, lintToolVersion, DisabledIssues, nameof (DisabledIssues)); + EnabledIssues = CleanIssues (issue.Key, lintToolVersion, EnabledIssues, nameof (EnabledIssues) ); } } @@ -230,6 +217,19 @@ public override bool Execute () return !Log.HasLoggedErrors; } + string CleanIssues (string issueToRemove, Version lintToolVersion, string issues, string issuePropertyName) + { + Regex issueReplaceRegex = new Regex ($"\b{issueToRemove}\b(,)?"); + if (!string.IsNullOrEmpty (issues) && issues.Contains (issueToRemove)) { + var match = issueReplaceRegex.Match (DisabledIssues); + if (match.Success) { + issues = issues.Replace (match.Value, string.Empty); + Log.LogWarning ($"Removing {issueToRemove} from {issuePropertyName}. Lint {lintToolVersion} does not support this check."); + } + } + return issues; + } + protected override string GenerateCommandLineCommands () { var cmd = new CommandLineBuilder ();