Skip to content

Commit

Permalink
fix: not reading all versions (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson authored Jan 5, 2020
1 parent 46fc19c commit 1e64ca1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/Pharmacist.Core/Generation/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static IReadOnlyCollection<ITypeDefinition> GetReferenceTypeDefinitionsWi
/// </summary>
/// <param name="compilation">The compilation to get the type definitions from.</param>
/// <returns>The list of type definitions.</returns>
public static IEnumerable<ITypeDefinition> GetPublicNonGenericTypeDefinitions(this ICompilation compilation)
public static IEnumerable<ITypeDefinition> GetPublicTypeDefinitions(this ICompilation compilation)
{
return _publicNonGenericTypeMapping.GetOrAdd(
compilation,
Expand Down Expand Up @@ -179,7 +179,7 @@ private static IEnumerable<ITypeDefinition> GetPublicTypeDefinitionsWithEvents(I
compilation,
comp =>
{
return comp.GetPublicNonGenericTypeDefinitions()
return comp.GetPublicTypeDefinitions()
.Where(x =>
x.Events.Any(eventInfo => eventInfo.Accessibility == Accessibility.Public))
.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class DelegateTemplateNamespaceResolver : INamespaceResolver

public IEnumerable<NamespaceDeclarationSyntax> Create(ICompilation compilation)
{
IEnumerable<(ITypeDefinition typeDefinition, bool isAbstract, IEnumerable<IMethod> methods)> values = compilation.GetPublicNonGenericTypeDefinitions()
IEnumerable<(ITypeDefinition typeDefinition, bool isAbstract, IEnumerable<IMethod> methods)> values = compilation.GetPublicTypeDefinitions()
.Where(
x => x.Kind != TypeKind.Interface
&& (!IsMulticastDelegateDerived(x)
Expand Down
44 changes: 32 additions & 12 deletions src/Pharmacist.MsBuild.NuGet/PharmacistNuGetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Frameworks;
Expand All @@ -27,7 +28,14 @@ namespace Pharmacist.MsBuild.NuGet
[SuppressMessage("Design", "CA1031: Catch specific exceptions", Justification = "Final logging location for exceptions.")]
public class PharmacistNuGetTask : Task, IEnableLogger
{
private const string DefaultTargetFramework = "netstandard2.0";
private static readonly Regex _versionRegex = new Regex(@"(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)", RegexOptions.Compiled | RegexOptions.CultureInvariant);
private static readonly Dictionary<Guid, string> _guidToFramework = new Dictionary<Guid, string>()
{
[new Guid("EFBA0AD7-5A72-4C68-AF49-83D382785DCF")] = "MonoAndroid",
[new Guid("6BC8ED88-2882-458C-8E55-DFD12B67127B")] = "Xamarin.iOS",
[new Guid("A5A43C5B-DE2A-4C0C-9213-0A381AF9435A")] = "uap",
[new Guid("A3F8F2AB-B479-4A4A-A458-A89E7DC349F1")] = "Xamarin.Mac",
};

private static readonly ISet<string> ExclusionPackageReferenceSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
{
Expand All @@ -51,6 +59,11 @@ public class PharmacistNuGetTask : Task, IEnableLogger
/// </summary>
public string TargetFrameworkVersion { get; set; }

/// <summary>
/// Gets or sets the version of the project type associated with UWP projects.
/// </summary>
public string TargetPlatformVersion { get; set; }

/// <summary>
/// Gets or sets the target framework.
/// </summary>
Expand Down Expand Up @@ -103,23 +116,30 @@ public override bool Execute()

private IReadOnlyCollection<NuGetFramework> GetTargetFrameworks()
{
IReadOnlyCollection<NuGetFramework> nugetFrameworks;
if (!string.IsNullOrWhiteSpace(TargetFramework))
{
nugetFrameworks = TargetFramework.ToFrameworks();
return TargetFramework.ToFrameworks();
}
else

var nugetFrameworks = new List<NuGetFramework>();

if (string.IsNullOrWhiteSpace(ProjectTypeGuids))
{
if (string.IsNullOrWhiteSpace(ProjectTypeGuids) || string.IsNullOrWhiteSpace(TargetFrameworkVersion))
{
return null;
}
return null;
}

var splitProjectTypeGuids = ProjectTypeGuids
.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => new Guid(x.Trim()));
var projectGuids = ProjectTypeGuids
.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => new Guid(x.Trim()));

nugetFrameworks = new List<NuGetFramework> { splitProjectTypeGuids.GetTargetFramework(TargetFrameworkVersion) };
var versionText = string.IsNullOrWhiteSpace(TargetFrameworkVersion) ? TargetFrameworkVersion : TargetPlatformVersion;
foreach (var projectGuid in projectGuids)
{
if (_guidToFramework.TryGetValue(projectGuid, out var targetFrameworkValue))
{
var versionMatch = new Version(_versionRegex.Match(versionText).Value);
nugetFrameworks.Add(new NuGetFramework(targetFrameworkValue, versionMatch));
}
}

return nugetFrameworks;
Expand Down
38 changes: 0 additions & 38 deletions src/Pharmacist.MsBuild.NuGet/ProjectGuidToTargetFramework.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
TargetFramework="$(TargetFramework)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
ProjectTypeGuids="$(ProjectTypeGuids)"
TargetPlatformVersion="$(TargetPlatformVersion)"
OutputFile="$(IntermediateOutputPath)\Pharmacist.NuGet.g.cs" />

<Message Text="Processed Pharmacist Packages" />
Expand Down

0 comments on commit 1e64ca1

Please sign in to comment.