Skip to content

Commit

Permalink
Target net6.0 and net8.0 (#422)
Browse files Browse the repository at this point in the history
* Revert "chore: bump dotnet sdk to 8 (#406)"

This reverts commit 2714d38.

* Revert "Revert "chore: bump dotnet sdk to 8 (#406)""

This reverts commit a86fa86.

* Target net6.0 and net8.0

* Remove pragma disable. (Moved to .editorconfig)

* Styling.

* Remove [Serializable] from custom exceptions.

* Fix missing mono.posix on ARM devices.

* Use bitwise AND to determine permissions.

* Use HasFlag to check for permissions

---------

Co-authored-by: Sebastian Gomez <[email protected]>
  • Loading branch information
sebasgomez238 and sebasgomez238 authored Oct 16, 2023
1 parent 5107648 commit ba02542
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 118 deletions.
39 changes: 35 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ dotnet_diagnostic.CA1859.severity = none
# https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5104
dotnet_diagnostic.NU5104.severity = none

# SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implemenatation at compile-time
# Justification: Would not have much impact on us / is only available in .NET8
# https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1045
dotnet_diagnostic.SYSLIB1045.severity = none

# CA1863: Cache a 'CompositeFormat' for repeated use in this formatting operation
# Justification: Only supported in .NET8.
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1863 (This is the link provided by the error message but shows a 404 error)
dotnet_diagnostic.CA1863.severity = none

##########################################
# Temporary rules
#
Expand Down Expand Up @@ -811,10 +821,6 @@ dotnet_diagnostic.CA1852.severity = suggestion
# CA1854: Prefer 'TryGetValue' over 'ContainsKey' and 'Item' when accessing dictionary items
dotnet_diagnostic.CA1854.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1859
# CA1859: Use culture-aware string operations
dotnet_diagnostic.CA1859.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1860
# CA1860: Avoid using 'Enumerable.Any()' extension method.
dotnet_diagnostic.CA1860.severity = suggestion
Expand All @@ -823,6 +829,18 @@ dotnet_diagnostic.CA1860.severity = suggestion
# CA1861: Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly
dotnet_diagnostic.CA1861.severity = suggestion

# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1862
# CA1862: Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison
dotnet_diagnostic.CA1862.severity = suggestion

# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1865
# CA1865: Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char
dotnet_diagnostic.CA1865.severity = suggestion

# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1869
# CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead.
dotnet_diagnostic.CA1869.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2000
# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = suggestion
Expand Down Expand Up @@ -1035,6 +1053,14 @@ dotnet_diagnostic.IDE0220.severity = suggestion
# IDE0251: Member can be made 'readonly'
dotnet_diagnostic.IDE0251.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0290
# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0300
# IDE0290: Collection initialization can be simplified
dotnet_diagnostic.IDE0300.severity = suggestion

# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide1006
# IDE1006: Naming rule violation: These words must begin with upper case characters: ...
dotnet_diagnostic.IDE1006.severity = suggestion
Expand All @@ -1043,6 +1069,11 @@ dotnet_diagnostic.IDE1006.severity = suggestion
# IL3000: Avoid accessing Assembly file path when publishing as a single file
dotnet_diagnostic.IL3000.severity = suggestion

#IDE0305: Collection initialization can be simplified
# Justification: The suggestion leads to a styling error. This suggestion is new to .NET8 and performance issues have been reported with it although fixes have been made we should hold on until full release https://github.com/dotnet/roslyn/issues/69988.
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0305
dotnet_diagnostic.IDE0305.severity = none

##########################################
# Provided by Microsoft.VisualStudio.Threading.Analyzers
# https://github.com/Microsoft/vs-threading
Expand Down
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup Label="Build">
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<RootNamespace>Microsoft.Sbom</RootNamespace>
Expand All @@ -10,7 +10,8 @@
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CA1014;CS8002</NoWarn>
<NoWarn>$(NoWarn);CA1014;CS8002;CA1416</NoWarn>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

<PropertyGroup Label="Package">
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageVersion Include="Mono.Posix.NETStandard" Version="1.0.0" Condition="'$(TargetFramework)' == 'net6.0'"/>
<PackageVersion Include="Moq" Version="4.17.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NuGet.Frameworks" Version="6.7.0" />
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Sbom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Adapters", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B4BFDF6F-4AFB-40AB-B2CE-3027FE04DBCD}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
README.md = README.md
.editorconfig = .editorconfig
global.json = global.json
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Contracts", "src\Microsoft.Sbom.Contracts\Microsoft.Sbom.Contracts.csproj", "{AA73B697-C992-4940-8375-17B9B77AB351}"
Expand Down
5 changes: 2 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"sdk": {
"version": "7.0.400",
"rollForward": "latestMajor",
"allowPrerelease": false
"version": "8.0.100-rc.2.23502.2",
"rollForward": "latestMajor"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when we encounter a problem while running the component detector.
/// </summary>
[Serializable]
public class ComponentDetectorException : Exception
{
public ComponentDetectorException()
Expand All @@ -25,9 +23,4 @@ public ComponentDetectorException(string message, Exception innerException)
: base(message, innerException)
{
}

protected ComponentDetectorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
9 changes: 1 addition & 8 deletions src/Microsoft.Sbom.Api/Exceptions/ConfigurationException.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;
using Microsoft.Sbom.Common.Config;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when there is a problem in parsing the <see cref="IConfiguration"/>.
/// </summary>
[Serializable]
public class ConfigurationException : Exception
{
public ConfigurationException()
Expand All @@ -26,9 +24,4 @@ public ConfigurationException(string message, Exception innerException)
: base(message, innerException)
{
}

protected ConfigurationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
9 changes: 1 addition & 8 deletions src/Microsoft.Sbom.Api/Exceptions/HashGenerationException.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when the generated hash is invalid.
/// </summary>
[Serializable]
public class HashGenerationException : Exception
{
public HashGenerationException()
Expand All @@ -25,9 +23,4 @@ public HashGenerationException(string message, Exception innerException)
: base(message, innerException)
{
}

protected HashGenerationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

Expand All @@ -13,7 +12,6 @@ namespace Microsoft.Sbom.Api.Exceptions;
/// <remarks>
/// Thrown out of public classes implementing IPackageInfoConverter so it must also be public.
/// <remarks>
[Serializable]
public class InvalidConverterException : Exception
{
public InvalidConverterException()
Expand All @@ -29,9 +27,4 @@ public InvalidConverterException(string message, Exception innerException)
: base(message, innerException)
{
}

protected InvalidConverterException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
9 changes: 1 addition & 8 deletions src/Microsoft.Sbom.Api/Exceptions/InvalidPathException.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when the file path is invalid or inaccessible.
/// </summary>
[Serializable]
public class InvalidPathException : Exception
{
public InvalidPathException()
Expand All @@ -25,9 +23,4 @@ public InvalidPathException(string message, Exception innerException)
: base(message, innerException)
{
}

protected InvalidPathException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand All @@ -8,7 +8,6 @@ namespace Microsoft.Sbom.Api.Exceptions;
/// <summary>
/// Thrown when the manifest tool is unable to serialize the SBOM component.
/// </summary>
[Serializable]
public class ManifestToolSerializerException : Exception
{
public ManifestToolSerializerException() { }
Expand All @@ -18,9 +17,4 @@ public ManifestToolSerializerException(string message)

public ManifestToolSerializerException(string message, Exception inner)
: base(message, inner) { }

protected ManifestToolSerializerException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when we are unable to find a generator to serialize the SBOM.
/// </summary>
[Serializable]
public class MissingGeneratorException : Exception
{
public MissingGeneratorException()
Expand All @@ -25,9 +23,4 @@ public MissingGeneratorException(string message, Exception innerException)
: base(message, innerException)
{
}

protected MissingGeneratorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when the manifest tool cannot find a signature validator for the current
/// operating system.
/// </summary>
[Serializable]
public class SignValidatorNotFoundException : Exception
{
public SignValidatorNotFoundException()
Expand All @@ -26,9 +24,4 @@ public SignValidatorNotFoundException(string message, Exception innerException)
: base(message, innerException)
{
}

protected SignValidatorNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Exceptions;

/// <summary>
/// Thrown when we are provided a hash algorithm value that is currently not supported by our service.
/// </summary>
[Serializable]
public class UnsupportedHashAlgorithmException : Exception
{
public UnsupportedHashAlgorithmException()
Expand All @@ -25,9 +23,4 @@ public UnsupportedHashAlgorithmException(string message, Exception innerExceptio
: base(message, innerException)
{
}

protected UnsupportedHashAlgorithmException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace Microsoft.Sbom.Common.Config.Attributes;

/// <summary>
/// Attribute denoting that an <see cref="Microsoft.Sbom.Api.Config.Configuration" /> property is a Component Detector argument.
/// Attribute denoting that an <see cref="Sbom.Api.Config.Configuration" /> property is a Component Detector argument.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class ComponentDetectorArgumentAttribute : Attribute
{
/// <summary>
/// Gets the name of the paramter to be specified when passing the value of the target to Component Detection.
/// Gets the name of the parameter to be specified when passing the value of the target to Component Detection.
/// </summary>
public string ParameterName { get; } = string.Empty;

Expand Down
Loading

0 comments on commit ba02542

Please sign in to comment.