Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transitive NoWarn properties from project references #1672

Merged
merged 39 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e3e150f
temp status
Aug 4, 2017
e25192e
working through merging warning properties
Aug 7, 2017
dbb4e78
Adding better quality across and changing tests
Aug 8, 2017
3512c8a
checkpoint for correctly extracting transitive no warn from a basic case
Aug 8, 2017
5bac353
Checkpoint with a functional case (A->B->C->Pkg) and lazy initialization
Aug 9, 2017
7b06260
Adding code to deal with path exclusion logic and fixing test breaks
Aug 9, 2017
32dd874
making TransitiveNoWarnUtils conditional on projectspec and restoreme…
Aug 9, 2017
b41d9d3
Adding scenario tests
Aug 9, 2017
d2d095a
addressing some PR feedback
Aug 14, 2017
aff0915
Addressing warning properties related PR feedback
Aug 21, 2017
fd2954d
Addressing feedback on TransitiveNoWarnUtil
Aug 21, 2017
2bb5484
Adding unit tests for TransitiveNoWarnUtils
Aug 22, 2017
bac6ebd
Adding more unit tests
Aug 22, 2017
206783d
Adding unit tests related to Merging warning properties and dependenc…
Aug 23, 2017
41d1a6d
Adding a test project generator
Aug 23, 2017
d770dd7
Revert "Adding a test project generator"
Aug 24, 2017
96c32f1
Changing to less data per node
Aug 24, 2017
df69083
Adding 1. merging into path 2. fixing seen.add
Aug 24, 2017
fda157f
removing merging into path
Aug 24, 2017
92da3ce
perf improvements working with Justin
Aug 26, 2017
6e32f5d
fixing broken functional tests
Aug 26, 2017
91c45b6
fixing broken unit tests
Aug 26, 2017
cac363e
cleaning up an equals call
Aug 26, 2017
1ab17fc
IsSubSet check
emgarten Aug 26, 2017
8ec53f8
Use null or existing dictionary when possible
emgarten Aug 26, 2017
355759e
Optimize merges to keep the same objects if possible
emgarten Aug 26, 2017
7011324
Removing unused code
emgarten Aug 26, 2017
bae7e09
SubSet check fix
emgarten Aug 26, 2017
f8bfc05
Track only NoWarn codes that have not yet been walked
emgarten Aug 26, 2017
8e1fbbb
Fixing AddToSeen and test break
Aug 28, 2017
05f56da
fixing broken unit test
Aug 28, 2017
7c68020
delaying transitive initialization further
Aug 28, 2017
3af5cee
Adding more functional tests
Aug 28, 2017
9319b37
Addressing PR comments
Aug 28, 2017
38ed522
Excluding Apex test project from run test projects as apex package is…
Aug 28, 2017
dfca74f
adding func test for incompatible project reference
Aug 28, 2017
0fed85f
Adding preference order for properties based on offline discussion
Aug 29, 2017
bfb6c41
Adding few more functional tests
Aug 29, 2017
154fe93
addressing PR feedback
Aug 29, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public void Log(IRestoreLogMessage message)
// This will be true if the message is not or warning or it is not suppressed.
if (!IsWarningSuppressed(message))
{
UpgradeWarningIfNeeded(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment explaining what this does


if (string.IsNullOrEmpty(message.FilePath))
{
message.FilePath = message.ProjectPath ?? ProjectPath;
Expand All @@ -152,6 +154,8 @@ public Task LogAsync(IRestoreLogMessage message)
// This will be true if the message is not or warning or it is not suppressed.
if (!IsWarningSuppressed(message))
{
UpgradeWarningIfNeeded(message);

if (string.IsNullOrEmpty(message.FilePath))
{
message.FilePath = message.ProjectPath ?? ProjectPath;
Expand Down Expand Up @@ -205,20 +209,39 @@ protected bool DisplayMessage(IRestoreLogMessage message)
/// <returns>bool indicating if the message should be suppressed.</returns>
private bool IsWarningSuppressed(IRestoreLogMessage message)
{

if (ProjectWarningPropertiesCollection != null && ProjectWarningPropertiesCollection.ApplyWarningProperties(message))
{
return true;
}
else if (message.Level == LogLevel.Warning)
if (message.Level == LogLevel.Warning)
{
// Use transitive warning properties only if the project does not suppress the warning or upgrade it to an error
return TransitiveWarningPropertiesCollection != null && TransitiveWarningPropertiesCollection.ApplyWarningProperties(message);
// If the ProjectWarningPropertiesCollection is present then test if the warning is suppressed in
// project wide no warn or package specific no warn
if (ProjectWarningPropertiesCollection != null && ProjectWarningPropertiesCollection.ApplyNoWarnProperties(message))
{
return true;
}
else
{
// Use transitive warning properties only if the project does not suppress the warning
// In transitive warning properties look at only the package specific ones as all properties are per package reference.
return TransitiveWarningPropertiesCollection != null && TransitiveWarningPropertiesCollection.ApplyNoWarnProperties(message);
}
}

return false;
}

/// <summary>
/// This method upgrades the warning to an error if the project wide warning properties have set the code in WarningsAsErrors or
/// set TreatWarningsAsErrors to true
/// </summary>
/// <param name="message">IRestoreLogMessage to be logged as an error or warning.</param>
/// <returns>bool indicating if the message should be suppressed.</returns>
private void UpgradeWarningIfNeeded(IRestoreLogMessage message)
{
if (ProjectWarningPropertiesCollection != null)
{
ProjectWarningPropertiesCollection.ApplyWarningAsErrorProperties(message);
}
}

private static IRestoreLogMessage ToRestoreLogMessage(ILogMessage message)
{
var restoreLogMessage = message as IRestoreLogMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,75 +55,116 @@ public WarningPropertiesCollection(WarningProperties projectWideWarningPropertie
/// If not then the param message sould have been mutated to an error</returns>
public bool ApplyWarningProperties(IRestoreLogMessage message)
{
if (message.Level != LogLevel.Warning)
if (ApplyProjectWideNoWarnProperties(message) || ApplyPackageSpecificNoWarnProperties(message))
{
return false;
return true;
}
else
{
// First look at PackageSpecificWarningProperties and then at ProjectWideWarningProperties.
if (!string.IsNullOrEmpty(message.LibraryId) && PackageSpecificWarningProperties != null)
{
var messageTargetFrameworks = message.TargetGraphs.Select(GetNuGetFramework).ToList();
ApplyWarningAsErrorProperties(message);
return false;
}
}

/// <summary>
/// Attempts to suppress a warning log message.
/// The decision is made based on the Package Specific or Project wide no warn properties.
/// </summary>
/// <param name="message">Message that should be suppressed.</param>
/// <returns>Bool indicating is the warning should be suppressed or not.</returns>
public bool ApplyNoWarnProperties(IRestoreLogMessage message)
{
return ApplyProjectWideNoWarnProperties(message) || ApplyPackageSpecificNoWarnProperties(message);
}

/// <summary>
/// Method is used to upgrade a warning to an error if needed.
/// </summary>
/// <param name="message">Message which should be upgraded to error if needed.</param>
public void ApplyWarningAsErrorProperties(IRestoreLogMessage message)
{
ApplyProjectWideWarningsAsErrorProperties(message);
}

/// <summary>
/// Method is used to check is a warning should be suppressed due to package specific no warn properties.
/// </summary>
/// <param name="message">Message to be checked for no warn.</param>
/// <returns>bool indicating if the IRestoreLogMessage should be suppressed or not.</returns>
private bool ApplyPackageSpecificNoWarnProperties(IRestoreLogMessage message)
{
if (message.Level == LogLevel.Warning &&
PackageSpecificWarningProperties != null &&
!string.IsNullOrEmpty(message.LibraryId))
{
var messageTargetFrameworks = message.TargetGraphs.Select(GetNuGetFramework).ToList();

// If the message does not contain a target graph, assume that it is applicable for all project frameworks.
if (messageTargetFrameworks.Count == 0)
// If the message does not contain a target graph, assume that it is applicable for all project frameworks.
if (messageTargetFrameworks.Count == 0)
{
// Suppress the warning if the code + libraryId combination is suppressed for all project frameworks.
if (ProjectFrameworks.Count > 0 &&
ProjectFrameworks.All(e => PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, e)))
{
// Suppress the warning if the code + libraryId combination is suppressed for all project frameworks.
if (ProjectFrameworks.Count > 0 &&
ProjectFrameworks.All(e => PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, e)))
{
return true;
}
return true;
}
else
}
else
{
// Get all the target graphs for which code + libraryId combination is not suppressed.
message.TargetGraphs = message
.TargetGraphs
.Where(e => !PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, GetNuGetFramework(e)))
.ToList();

// If the message is left with no target graphs then suppress it.
if (message.TargetGraphs.Count == 0)
{
// Get all the target graphs for which code + libraryId combination is not suppressed.
message.TargetGraphs = message
.TargetGraphs
.Where(e => !PackageSpecificWarningProperties.Contains(message.Code, message.LibraryId, GetNuGetFramework(e)))
.ToList();

// If the message is left with no target graphs then suppress it.
if (message.TargetGraphs.Count == 0)
{
return true;
}
return true;
}
}

// The message does not contain a LibraryId or it is not suppressed in package specific settings.
// Apply ProjectWideWarningProperties.
return ProjectWideWarningProperties != null && ApplyProjectWideWarningProperties(message);
}

// The message is not a warning or it does not contain a LibraryId or it is not suppressed in package specific settings.
return false;
}

/// <summary>
/// Method is used to check is a warning should be suppressed and if not then if it should be treated as an error.
/// Method is used to check is a warning should be suppressed due to project wide no warn properties.
/// </summary>
/// <param name="logMessage">Message which should be mutated if needed.</param>
/// <param name="message">Message to be checked for no warn.</param>
/// <returns>bool indicating if the ILogMessage should be suppressed or not.</returns>
private bool ApplyProjectWideWarningProperties(ILogMessage logMessage)
private bool ApplyProjectWideNoWarnProperties(ILogMessage message)
{
if (logMessage.Level == LogLevel.Warning)
if (message.Level == LogLevel.Warning && ProjectWideWarningProperties != null)
{
if (ProjectWideWarningProperties.NoWarn.Contains(logMessage.Code))
if (ProjectWideWarningProperties.NoWarn.Contains(message.Code))
{
// If the project wide NoWarn contains the message code then suppress it.
return true;
}
else if ((ProjectWideWarningProperties.AllWarningsAsErrors && logMessage.Code > NuGetLogCode.Undefined) ||
ProjectWideWarningProperties.WarningsAsErrors.Contains(logMessage.Code))
}
}

// the project wide NoWarn does contain the message code. do not suppress the warning.
return false;
}

/// <summary>
/// Method is used to check is a warning should be treated as an error.
/// </summary>
/// <param name="message">Message which should be upgraded to error if needed.</param>
private void ApplyProjectWideWarningsAsErrorProperties(ILogMessage message)
{
if (message.Level == LogLevel.Warning && ProjectWideWarningProperties != null)
{
if ((ProjectWideWarningProperties.AllWarningsAsErrors && message.Code > NuGetLogCode.Undefined) ||
ProjectWideWarningProperties.WarningsAsErrors.Contains(message.Code))
{
// If the project wide AllWarningsAsErrors is true and the message has a valid code or
// project wide WarningsAsErrors contains the message code then pgrade to error and do not suppress it.
logMessage.Level = LogLevel.Error;
return false;
// Project wide WarningsAsErrors contains the message code then upgrade to error.
message.Level = LogLevel.Error;
}
}

// Finally do not suppress or modify the message.
return false;
}

private NuGetFramework GetNuGetFramework(string targetGraph)
Expand Down
Loading