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

Upgrade to .NET SDK 8.0 #276

Merged
merged 4 commits into from
Nov 28, 2023
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
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ jobs:
with:
submodules: true

# Build with .NET 6.0 SDK
- name: Setup .NET 6.0
# Build with .NET 8.0 SDK
# Test with .NET 6.0 and 8.0
- name: Setup .NET 6.0 and 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: |
8.0.x
6.0.x

- name: Build
run: |
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ jobs:
with:
submodules: true

# Build with .NET 6.0 SDK
- name: Setup .NET 6.0
# Build with .NET 8.0 SDK
# Test with .NET 6.0 and 8.0
- name: Setup .NET 6.0 and 8.0
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: |
8.0.x
6.0.x

- name: Build
run: |
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestMinor"
}
}
7 changes: 4 additions & 3 deletions src/CloudNative.CloudEvents.Amqp/AmqpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Cloud Native Foundation.
// Copyright (c) Cloud Native Foundation.
// Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information.

Expand All @@ -8,6 +8,7 @@
using CloudNative.CloudEvents.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Mime;

Expand Down Expand Up @@ -145,7 +146,7 @@ public static CloudEvent ToCloudEvent(
}
}

private static bool HasCloudEventsContentType(Message message, out string? contentType)
private static bool HasCloudEventsContentType(Message message, [NotNullWhen(true)] out string? contentType)
{
contentType = message.Properties.ContentType?.ToString();
return MimeUtilities.IsCloudEventsContentType(contentType);
Expand Down Expand Up @@ -249,4 +250,4 @@ private static ApplicationProperties MapHeaders(CloudEvent cloudEvent, string pr
return applicationProperties;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>AMQP extensions for CloudNative.CloudEvents</Description>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -12,6 +12,8 @@
<PackageReference Include="AMQPNetLite" Version="2.4.2" />
<PackageReference Include="AMQPNetLite.Serialization" Version="2.4.2" />
<ProjectReference Include="..\CloudNative.CloudEvents\CloudNative.CloudEvents.csproj" />
<!-- Source-only package with nullable reference annotations. -->
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>ASP.Net Core extensions for CloudNative.CloudEvents</Description>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand Down
4 changes: 2 additions & 2 deletions src/CloudNative.CloudEvents.Avro/AvroEventFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ private static RecordSchema ParseEmbeddedSchema()
// will fail and that's okay since the type is useless without the proper schema.
using var sr = new StreamReader(typeof(AvroEventFormatter)
.Assembly
.GetManifestResourceStream("CloudNative.CloudEvents.Avro.AvroSchema.json"));
.GetManifestResourceStream("CloudNative.CloudEvents.Avro.AvroSchema.json")!);

return (RecordSchema) Schema.Parse(sr.ReadToEnd());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>Avro extensions for CloudNative.CloudEvents</Description>
<PackageTags>cncf;cloudnative;cloudevents;events;avro</PackageTags>
<LangVersion>10.0</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>Kafka extensions for CloudNative.CloudEvents</Description>
<PackageTags>cncf;cloudnative;cloudevents;events;kafka</PackageTags>
<LangVersion>8.0</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>MQTT extensions for CloudNative.CloudEvents</Description>
<PackageTags>cncf;cloudnative;cloudevents;events;mqtt</PackageTags>
<LangVersion>8.0</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>JSON support for the CNCF CloudEvents SDK, based on Newtonsoft.Json.</Description>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
Expand Down
17 changes: 12 additions & 5 deletions src/CloudNative.CloudEvents.NewtonsoftJson/JsonEventFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Cloud Native Foundation.
// Copyright (c) Cloud Native Foundation.
// Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information.

Expand Down Expand Up @@ -345,7 +345,7 @@ protected virtual void DecodeStructuredModeDataBase64Property(JToken dataBase64T
{
throw new ArgumentException($"Structured mode property '{DataBase64PropertyName}' must be a string, when present.");
}
cloudEvent.Data = Convert.FromBase64String((string?) dataBase64Token);
cloudEvent.Data = Convert.FromBase64String((string) dataBase64Token!);
}

/// <summary>
Expand Down Expand Up @@ -498,7 +498,7 @@ private void WriteCloudEventForBatchOrStructuredMode(JsonWriter writer, CloudEve
/// </summary>
/// <param name="data">The CloudEvent to infer the data content from. Must not be null.</param>
/// <returns>The inferred data content type, or null if no inference is performed.</returns>
protected override string? InferDataContentType(object data) => data is byte[]? null : JsonMediaType;
protected override string? InferDataContentType(object data) => data is byte[] ? null : JsonMediaType;

/// <summary>
/// Encodes structured mode data within a CloudEvent, writing it to the specified <see cref="JsonWriter"/>.
Expand All @@ -524,7 +524,14 @@ protected virtual void EncodeStructuredModeData(CloudEvent cloudEvent, JsonWrite
}
else
{
ContentType dataContentType = new ContentType(GetOrInferDataContentType(cloudEvent));
string? dataContentTypeText = GetOrInferDataContentType(cloudEvent);
// This would only happen in a derived class which overrides GetOrInferDataContentType further...
// This class infers application/json for anything other than byte arrays.
if (dataContentTypeText is null)
{
throw new ArgumentException("Data content type cannot be inferred");
}
ContentType dataContentType = new ContentType(dataContentTypeText);
if (IsJsonMediaType(dataContentType.MediaType))
{
writer.WritePropertyName(DataPropertyName);
Expand Down Expand Up @@ -710,4 +717,4 @@ protected override void DecodeStructuredModeDataProperty(JToken dataToken, Cloud
protected override void DecodeStructuredModeDataBase64Property(JToken dataBase64Token, CloudEvent cloudEvent) =>
throw new ArgumentException($"Data unexpectedly represented using '{DataBase64PropertyName}' within structured mode CloudEvent.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>Support for the Protobuf event format in for CloudNative.CloudEvents</Description>
<PackageTags>cncf;cloudnative;cloudevents;events;protobuf</PackageTags>
<LangVersion>10.0</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>JSON support for the CNCF CloudEvents SDK, based on System.Text.Json.</Description>
<LangVersion>8.0</LangVersion>
<PackageTags>cncf;cloudnative;cloudevents;events;json;systemtextjson</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CloudEventFormatterAttribute(Type formatterType) =>
throw new ArgumentException($"The {nameof(CloudEventFormatterAttribute)} on type {targetType} has no converter type specified.", nameof(targetType));
}

object instance;
object? instance;
try
{
instance = Activator.CreateInstance(formatterType);
Expand Down
4 changes: 2 additions & 2 deletions src/CloudNative.CloudEvents/CloudNative.CloudEvents.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<Description>CNCF CloudEvents SDK</Description>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<PackageTags>cloudnative;cloudevents;events</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)'=='netstandard2.0' or '$(TargetFramework)'=='netstandard2.1'" />
<!-- Source-only package with nullable reference annotations. -->
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="All" />
</ItemGroup>
Expand Down
11 changes: 6 additions & 5 deletions src/CloudNative.CloudEvents/Core/BinaryDataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static ReadOnlyMemory<byte> ToReadOnlyMemory(Stream stream)
public static MemoryStream AsStream(ReadOnlyMemory<byte> memory)
{
var segment = GetArraySegment(memory);
return new MemoryStream(segment.Array, segment.Offset, segment.Count, false);
return new MemoryStream(segment.Array!, segment.Offset, segment.Count, false);
}

/// <summary>
Expand All @@ -79,7 +79,7 @@ public static string GetString(ReadOnlyMemory<byte> memory, Encoding encoding)

// TODO: If we introduce an additional netstandard2.1 target, we can use encoding.GetString(memory.Span)
var segment = GetArraySegment(memory);
return encoding.GetString(segment.Array, segment.Offset, segment.Count);
return encoding.GetString(segment.Array!, segment.Offset, segment.Count);
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public static async Task CopyToStreamAsync(ReadOnlyMemory<byte> source, Stream d
{
Validation.CheckNotNull(destination, nameof(destination));
var segment = GetArraySegment(source);
await destination.WriteAsync(segment.Array, segment.Offset, segment.Count).ConfigureAwait(false);
await destination.WriteAsync(segment.Array!, segment.Offset, segment.Count).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -108,13 +108,14 @@ public static byte[] AsArray(ReadOnlyMemory<byte> memory)
var segment = GetArraySegment(memory);
// We probably don't actually need to check the offset: if the count is the same as the length,
// I can't see how the offset can be non-zero. But it doesn't *hurt* as a check.
return segment.Offset == 0 && segment.Count == segment.Array.Length
return segment.Offset == 0 && segment.Count == segment.Array!.Length
? segment.Array
: memory.ToArray();
}

// Note: when this returns, the Array property of the returned segment is guaranteed not to be null.
private static ArraySegment<byte> GetArraySegment(ReadOnlyMemory<byte> memory) =>
MemoryMarshal.TryGetArray(memory, out var segment)
MemoryMarshal.TryGetArray(memory, out var segment) && segment.Array is not null
? segment
: new ArraySegment<byte>(memory.ToArray());
}
Expand Down
9 changes: 5 additions & 4 deletions src/CloudNative.CloudEvents/Core/MimeUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2021 Cloud Native Foundation.
// Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static Encoding GetEncoding(ContentType? contentType) =>
var header = new MediaTypeHeaderValue(contentType.MediaType);
foreach (string parameterName in contentType.Parameters.Keys)
{
header.Parameters.Add(new NameValueHeaderValue(parameterName, contentType.Parameters[parameterName].ToString()));
header.Parameters.Add(new NameValueHeaderValue(parameterName, contentType.Parameters[parameterName]));
}
return header;
}
Expand All @@ -76,7 +77,7 @@ public static Encoding GetEncoding(ContentType? contentType) =>
/// </summary>
/// <param name="contentType">The content type to check. May be null, in which case the result is false.</param>
/// <returns>true if the given content type denotes a (non-batch) CloudEvent; false otherwise</returns>
public static bool IsCloudEventsContentType(string? contentType) =>
public static bool IsCloudEventsContentType([NotNullWhen(true)] string? contentType) =>
contentType is string &&
contentType.StartsWith(MediaType, StringComparison.InvariantCultureIgnoreCase) &&
!contentType.StartsWith(BatchMediaType, StringComparison.InvariantCultureIgnoreCase);
Expand All @@ -86,7 +87,7 @@ contentType is string &&
/// </summary>
/// <param name="contentType">The content type to check. May be null, in which case the result is false.</param>
/// <returns>true if the given content type represents a CloudEvent batch; false otherwise</returns>
public static bool IsCloudEventsBatchContentType(string? contentType) =>
public static bool IsCloudEventsBatchContentType([NotNullWhen(true)] string? contentType) =>
contentType is string && contentType.StartsWith(BatchMediaType, StringComparison.InvariantCultureIgnoreCase);
}
}
Loading