Skip to content

Commit

Permalink
Remove dependency on ThisAssembly
Browse files Browse the repository at this point in the history
Simplifying the approach to leverage just SDK features makes it easier to consume and apply across projects that might not use ThisAssembly (or have version incompatibilities).
  • Loading branch information
kzu committed Jun 18, 2024
1 parent c4830fc commit c879f25
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 76 deletions.
4 changes: 4 additions & 0 deletions src/SponsorLink/Analyzer/Analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<None Update="buildTransitive\SponsorableLib.targets" Pack="true" />
</ItemGroup>

<ItemGroup>
<Compile Remove="C:\Code\devlooped.oss\src\SponsorLink\SponsorLink\ThisAssembly.cs" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion src/SponsorLink/Analyzer/StatusReportingAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using static Devlooped.Sponsors.SponsorLink;
using static ThisAssembly.Constants;

namespace Analyzer;

Expand Down
36 changes: 29 additions & 7 deletions src/SponsorLink/SponsorLink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<MergeAnalyzerAssemblies Condition="'$(MergeAnalyzerAssemblies)' == '' and '$(Configuration)' == 'Release'">true</MergeAnalyzerAssemblies>
<!-- If we are going to merge files, we need to copy local -->
<CopyLocalLockFileAssemblies Condition="'$(MergeAnalyzerAssemblies)' == 'true'">true</CopyLocalLockFileAssemblies>
<!-- Make Resources visible to intellisense -->
<CoreCompileDependsOn>CoreResGen;$(CoreCompileDependsOn)</CoreCompileDependsOn>

<!-- Default funding product the Product, which already part of ThisAssembly -->
<FundingProduct Condition="'$(FundingProduct)' == ''">$(Product)</FundingProduct>
Expand All @@ -18,20 +20,19 @@
<FundingGrace Condition="'$(FundingGrace)' == ''">21</FundingGrace>
</PropertyGroup>

<ItemGroup>
<Constant Include="Funding.Product" Value="$(FundingProduct)" />
<Constant Include="Funding.Prefix" Value="$(FundingPrefix)" />
<Constant Include="Funding.Grace" Value="$(FundingGrace)" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)SponsorLink/*.cs"
Exclude="$(MSBuildThisFileDirectory)SponsorLink/bin/**;$(MSBuildThisFileDirectory)SponsorLink/obj/**"
Source="SponsorLink"/>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)SponsorLink/*.resx"
Exclude="$(MSBuildThisFileDirectory)SponsorLink/bin/**;$(MSBuildThisFileDirectory)SponsorLink/obj/**"
Source="SponsorLink"
ManifestResourceName="Devlooped.%(Filename)"/>
ManifestResourceName="Devlooped.Sponsors.%(Filename)"/>
<EmbeddedResource Update="$(MSBuildThisFileDirectory)SponsorLink/Resources.resx"
StronglyTypedManifestPrefix="Devlooped.Sponsors"
StronglyTypedClassName="%(Filename)"
StronglyTypedNamespace="Devlooped.Sponsors"
StronglyTypedLanguage="$(Language)" />
<None Include="$(MSBuildThisFileDirectory)SponsorLink/buildTransitive/*.*"
Source="SponsorLink"
PackagePath="buildTransitive/%(Filename)%(Extension)"/>
Expand Down Expand Up @@ -81,6 +82,27 @@
<PackageReference Include="ILRepack" Version="2.0.33" PrivateAssets="all" Pack="false" />
</ItemGroup>

<Target Name="EmitFunding" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)SponsorLink.g.cs">
<PropertyGroup>
<SponsorLinkPartial>namespace Devlooped.Sponsors%3B

partial class SponsorLink
{
public partial class Funding
{
public const string Product = "$(FundingProduct)"%3B
public const string Prefix = "$(FundingPrefix)"%3B
public const int Grace = $(FundingGrace)%3B
}
}
</SponsorLinkPartial>
</PropertyGroup>
<WriteLinesToFile File="$(IntermediateOutputPath)SponsorLink.g.cs" Lines="$(SponsorLinkPartial)" WriteOnlyWhenDifferent="true" Overwrite="true" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)SponsorLink.g.cs" />
</ItemGroup>
</Target>

<Target Name="ILRepack" AfterTargets="CoreCompile" BeforeTargets="CopyFilesToOutputDirectory"
Inputs="@(IntermediateAssembly -&gt; '%(FullPath)')"
Outputs="$(IntermediateOutputPath)ilrepack.txt"
Expand Down
25 changes: 13 additions & 12 deletions src/SponsorLink/SponsorLink/DiagnosticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Globalization;
using Humanizer;
using Microsoft.CodeAnalysis;

Expand Down Expand Up @@ -92,47 +93,47 @@ public Diagnostic Push(string product, Diagnostic diagnostic)

static DiagnosticDescriptor CreateSponsor(string[] sponsorable, string prefix) => new(
$"{prefix}100",
ThisAssembly.Strings.Sponsor.Title,
ThisAssembly.Strings.Sponsor.MessageFormat,
Resources.Sponsor_Title,
Resources.Sponsor_Message,
"SponsorLink",
DiagnosticSeverity.Info,
isEnabledByDefault: true,
description: ThisAssembly.Strings.Sponsor.Description,
description: Resources.Sponsor_Description,
helpLinkUri: "https://github.com/devlooped#sponsorlink",
"DoesNotSupportF1Help");

static DiagnosticDescriptor CreateUnknown(string[] sponsorable, string product, string prefix) => new(
$"{prefix}101",
ThisAssembly.Strings.Unknown.Title,
ThisAssembly.Strings.Unknown.MessageFormat,
Resources.Unknown_Title,
Resources.Unknown_Message,
"SponsorLink",
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: ThisAssembly.Strings.Unknown.Description(
description: string.Format(CultureInfo.CurrentCulture, Resources.Unknown_Description,
sponsorable.Humanize(x => $"https://github.com/sponsors/{x}"),
string.Join(" ", sponsorable)),
helpLinkUri: "https://github.com/devlooped#sponsorlink",
WellKnownDiagnosticTags.NotConfigurable);

static DiagnosticDescriptor CreateExpiring(string[] sponsorable, string prefix) => new(
$"{prefix}103",
ThisAssembly.Strings.Expiring.Title,
ThisAssembly.Strings.Expiring.MessageFormat,
Resources.Expiring_Title,
Resources.Expiring_Message,
"SponsorLink",
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: ThisAssembly.Strings.Expiring.Description(string.Join(" ", sponsorable)),
description: string.Format(CultureInfo.CurrentCulture, Resources.Expiring_Description, string.Join(" ", sponsorable)),
helpLinkUri: "https://github.com/devlooped#autosync",
"DoesNotSupportF1Help", WellKnownDiagnosticTags.NotConfigurable);

static DiagnosticDescriptor CreateExpired(string[] sponsorable, string prefix) => new(
$"{prefix}104",
ThisAssembly.Strings.Expired.Title,
ThisAssembly.Strings.Expired.MessageFormat,
Resources.Expired_Title,
Resources.Expired_Message,
"SponsorLink",
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: ThisAssembly.Strings.Expired.Description(string.Join(" ", sponsorable)),
description: string.Format(CultureInfo.CurrentCulture, Resources.Expired_Description, string.Join(" ", sponsorable)),
helpLinkUri: "https://github.com/devlooped#autosync",
"DoesNotSupportF1Help", WellKnownDiagnosticTags.NotConfigurable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</resheader>
<data name="Unknown_Description" xml:space="preserve">
<value>Patrocinar los proyectos en que dependes asegura que se mantengan activos, y que recibas el apoyo que necesitas. También es muy económico y está disponible en todo el mundo!
Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando posteriormente 'sponsor sync {spaced}'.</value>
Por favor considera apoyar el proyecto patrocinando en {0} y ejecutando posteriormente 'sponsor sync {1}'.</value>
</data>
<data name="Unknown_Message" xml:space="preserve">
<value>Por favor considere apoyar {0} patrocinando @{1} 🙏</value>
Expand All @@ -128,7 +128,7 @@ Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando post
<value>Estado de patrocinio desconocido</value>
</data>
<data name="Expired_Description" xml:space="preserve">
<value>Funcionalidades exclusivas para patrocinadores pueden no estar disponibles. Ejecuta 'sponsor sync {spaced}' y, opcionalmente, habilita la sincronización automática.</value>
<value>Funcionalidades exclusivas para patrocinadores pueden no estar disponibles. Ejecuta 'sponsor sync {0}' y, opcionalmente, habilita la sincronización automática.</value>
</data>
<data name="Expired_Message" xml:space="preserve">
<value>El estado de patrocino ha expirado y la sincronización automática no está habilitada.</value>
Expand All @@ -146,7 +146,7 @@ Por favor considera apoyar el proyecto patrocinando en {links} y ejecutando post
<value>Eres un patrocinador del proyecto, eres lo máximo 💟!</value>
</data>
<data name="Expiring_Description" xml:space="preserve">
<value>El estado de patrocino ha expirado y estás en un período de gracia. Ejecuta 'sponsor sync {spaced}' y, opcionalmente, habilita la sincronización automática.</value>
<value>El estado de patrocino ha expirado y estás en un período de gracia. Ejecuta 'sponsor sync {0}' y, opcionalmente, habilita la sincronización automática.</value>
</data>
<data name="Expiring_Message" xml:space="preserve">
<value>El estado de patrocino necesita actualización periódica y la sincronización automática no está habilitada.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</resheader>
<data name="Unknown_Description" xml:space="preserve">
<value>Sponsoring projects you depend on ensures they remain active, and that you get the support you need. It's also super affordable and available worldwide!
Please consider supporting the project by sponsoring at {links} and running 'sponsor sync {spaced}' afterwards.</value>
Please consider supporting the project by sponsoring at {0} and running 'sponsor sync {1}' afterwards.</value>
<comment>Unknown sponsor description</comment>
</data>
<data name="Unknown_Message" xml:space="preserve">
Expand All @@ -129,7 +129,7 @@ Please consider supporting the project by sponsoring at {links} and running 'spo
<value>Unknown sponsor status</value>
</data>
<data name="Expired_Description" xml:space="preserve">
<value>Sponsor-only features may be disabled. Please run 'sponsor sync {spaced}' and optionally enable automatic sync.</value>
<value>Sponsor-only features may be disabled. Please run 'sponsor sync {0}' and optionally enable automatic sync.</value>
</data>
<data name="Expired_Message" xml:space="preserve">
<value>Sponsor status has expired and automatic sync has not been enabled.</value>
Expand All @@ -147,7 +147,7 @@ Please consider supporting the project by sponsoring at {links} and running 'spo
<value>You are a sponsor of the project, you rock 💟!</value>
</data>
<data name="Expiring_Description" xml:space="preserve">
<value>Sponsor status has expired and you are in the grace period. Please run 'sponsor sync {spaced}' and optionally enable automatic sync.</value>
<value>Sponsor status has expired and you are in the grace period. Please run 'sponsor sync {0}' and optionally enable automatic sync.</value>
</data>
<data name="Expiring_Message" xml:space="preserve">
<value>Sponsor status needs periodic updating and automatic sync has not been enabled.</value>
Expand Down
38 changes: 25 additions & 13 deletions src/SponsorLink/SponsorLink/SponsorLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Product>SponsorLink</Product>
<ImplicitUsings>disable</ImplicitUsings>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<CoreCompileDependsOn>CoreResGen;$(CoreCompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>

<PropertyGroup Label="SponsorLink">
Expand All @@ -24,30 +25,41 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" Pack="false" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Constants" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Git" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Strings" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Project" Version="1.4.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="SponsorLink.es.resx" ManifestResourceName="Devlooped.%(Filename)" />
<EmbeddedResource Update="SponsorLink.resx" ManifestResourceName="Devlooped.%(Filename)" />
</ItemGroup>

<ItemGroup>
<Constant Include="Funding.Product" Value="$(FundingProduct)" />
<Constant Include="Funding.Prefix" Value="$(FundingPrefix)" />
<Constant Include="Funding.Grace" Value="$(FundingGrace)" />
<EmbeddedResource Update="Resources.es.resx" ManifestResourceName="Devlooped.Sponsors.%(Filename)"/>
<EmbeddedResource Update="Resources.resx" ManifestResourceName="Devlooped.Sponsors.%(Filename)" StronglyTypedManifestPrefix="Devlooped.Sponsors" StronglyTypedClassName="%(Filename)" StronglyTypedNamespace="Devlooped.Sponsors" StronglyTypedLanguage="$(Language)" />
</ItemGroup>

<ItemGroup>
<None Include="..\SponsorLink.targets" Link="SponsorLink.targets" />
</ItemGroup>

<Target Name="EmitFunding" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)SponsorLink.g.cs">
<PropertyGroup>
<SponsorLinkPartial>namespace Devlooped.Sponsors%3B

partial class SponsorLink
{
public partial class Funding
{
public const string Product = "$(FundingProduct)"%3B
public const string Prefix = "$(FundingPrefix)"%3B
public const int Grace = $(FundingGrace)%3B
}
}
</SponsorLinkPartial>
</PropertyGroup>
<WriteLinesToFile File="$(IntermediateOutputPath)SponsorLink.g.cs" Lines="$(SponsorLinkPartial)" WriteOnlyWhenDifferent="true" Overwrite="true" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)SponsorLink.g.cs" />
</ItemGroup>
</Target>

<Target Name="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes" Inputs="$(MSBuildProjectFullPath)" Outputs="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk">
<Exec Command="pwsh -nop -f $(MSBuildThisFileDirectory)..\jwk.ps1" ConsoleToMSBuild="true" EchoOff="true">
<Output TaskParameter="ConsoleOutput" PropertyName="DevloopedJwk"/>
<Output TaskParameter="ConsoleOutput" PropertyName="DevloopedJwk" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Error Text="$(DevloopedJwk)" Condition="'$(MSBuildLastExitCode)' != '0'" />
Expand Down
9 changes: 4 additions & 5 deletions src/SponsorLink/SponsorLink/SponsorLinkAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using System.IO;
using System.Linq;
using Humanizer;
using Humanizer.Localisation;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using static Devlooped.Sponsors.SponsorLink;
using static ThisAssembly.Constants;

namespace Devlooped.Sponsors;

Expand All @@ -20,7 +20,6 @@ namespace Devlooped.Sponsors;
[DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)]
public class SponsorLinkAnalyzer : DiagnosticAnalyzer
{
static readonly int graceDays = int.Parse(Funding.Grace);
static readonly Dictionary<SponsorStatus, DiagnosticDescriptor> descriptors = new()
{
// Requires:
Expand Down Expand Up @@ -76,7 +75,7 @@ public override void Initialize(AnalysisContext context)
// We'll report it as unknown as a fallback for now.
ctx.ReportDiagnostic(Diagnostic.Create(descriptors[SponsorStatus.Unknown], null,
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Unknown)),
Funding.Product, Sponsorables.Keys.Humanize(ThisAssembly.Strings.Or)));
Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)));
}
});
}
Expand All @@ -93,13 +92,13 @@ SponsorStatus SetStatus(ImmutableArray<AdditionalText> manifests)
// report unknown, either unparsed manifest or one with no expiration (which we never emit).
Diagnostics.Push(Funding.Product, Diagnostic.Create(descriptors[SponsorStatus.Unknown], null,
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Unknown)),
Funding.Product, Sponsorables.Keys.Humanize(ThisAssembly.Strings.Or)));
Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)));
return SponsorStatus.Unknown;
}
else if (exp < DateTime.Now)
{
// report expired or expiring soon if still within the configured days of grace period
if (exp.AddDays(graceDays) < DateTime.Now)
if (exp.AddDays(Funding.Grace) < DateTime.Now)
{
// report expiring soon
Diagnostics.Push(Funding.Product, Diagnostic.Create(descriptors[SponsorStatus.Expiring], null,
Expand Down
31 changes: 0 additions & 31 deletions src/SponsorLink/SponsorLink/ThisAssembly.cs

This file was deleted.

Loading

0 comments on commit c879f25

Please sign in to comment.