Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Nov 22, 2024
1 parent da4196c commit 8e663e2
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 233 deletions.
4 changes: 2 additions & 2 deletions source/Nuke.Build/Execution/TargetDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ public ITargetDefinition Requires(Expression<Func<bool>> requirement, params Exp
public ITargetDefinition Requires<T>()
where T : IRequireTool
{
ToolRequirements.Add(typeof(T).GetCustomAttribute<ToolRequirementAttributeBase>().NotNull().GetRequirement());
ToolRequirements.Add(typeof(T).GetCustomAttribute<ToolAttribute>().NotNull().GetRequirement());
return this;
}

public ITargetDefinition Requires<T>(string version)
where T : IRequireToolWithVersion
{
ToolRequirements.Add(typeof(T).GetCustomAttribute<ToolRequirementAttributeBase>().NotNull().GetRequirement(version));
ToolRequirements.Add(typeof(T).GetCustomAttribute<ToolAttribute>().NotNull().GetRequirement(version));
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Build/RequiresAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public class RequiresAttribute<T> : RequiresAttribute

public override ToolRequirement GetRequirement()
{
return typeof(T).GetCustomAttribute<ToolRequirementAttributeBase>().NotNull().GetRequirement(Version);
return typeof(T).GetCustomAttribute<ToolAttribute>().NotNull().GetRequirement(Version);
}
}
2 changes: 1 addition & 1 deletion source/Nuke.Common/Attributes/NpmPackageAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public NpmPackageAttribute(string packageId, string packageExecutable = null)

public override ToolRequirement GetRequirement(MemberInfo member)
{
return NpmPackageRequirement.Create(_packageId, Version);
return new NpmPackageRequirement(_packageId, Version);
}

public override object GetValue(MemberInfo member, object instance)
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/Attributes/NuGetPackageAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public NuGetPackageAttribute(string packageId, string packageExecutable32, strin

public override ToolRequirement GetRequirement(MemberInfo member)
{
return NuGetPackageRequirement.Create(_packageId, Version);
return new NuGetPackageRequirement(_packageId, Version);
}

public override object GetValue(MemberInfo member, object instance)
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/Attributes/PathVariableAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PathVariableAttribute(string pathExecutable = null)
public override ToolRequirement GetRequirement(MemberInfo member)
{
var name = _pathExecutable ?? member.Name.ToLowerInvariant();
return PathToolRequirement.Create(name);
return new PathToolRequirement(name);
}

public override object GetValue(MemberInfo member, object instance)
Expand Down
6 changes: 2 additions & 4 deletions source/Nuke.Tooling.Generator/Generators/TaskGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public static void Run(Tool tool, ToolWriter toolWriter)
.WriteSummary(tool)
.WriteLine("[PublicAPI]")
.WriteLine("[ExcludeFromCodeCoverage]")
.WriteLineIfTrue(tool.NuGetPackageId != null, "[NuGetPackageRequirement(PackageId)]")
.WriteLineIfTrue(tool.NuGetPackageId != null && tool.PackageExecutable == null, "[NuGetTool(Id = PackageId)]")
.WriteLineIfTrue(tool.NuGetPackageId != null && tool.PackageExecutable != null, "[NuGetTool(Id = PackageId, Executable = PackageExecutable)]")
.WriteLineIfTrue(tool.NpmPackageId != null, "[NpmPackageRequirement(PackageId)]")
.WriteLineIfTrue(tool.AptGetPackageId != null, "[AptGetPackageRequirement(PackageId)]")
.WriteLineIfTrue(tool.PathExecutable != null, "[PathToolRequirement(PathExecutable)]")
.WriteLineIfTrue(tool.NpmPackageId != null && tool.PackageExecutable != null, "[NpmTool(Id = PackageId, Executable = PackageExecutable)]")
.WriteLineIfTrue(tool.AptGetPackageId != null, "[AptGetTool(Id = PackageId)]")
.WriteLineIfTrue(tool.PathExecutable != null, "[PathTool(Executable = PathExecutable)]")
.WriteLine($"public partial class {tool.GetClassName()} : {baseClasses.JoinCommaSpace()}")
.WriteBlock(w =>
Expand Down
25 changes: 0 additions & 25 deletions source/Nuke.Tooling/Requirements/AptGetPackageRequirement.cs

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions source/Nuke.Tooling/Requirements/NpmPackageRequirement.cs

This file was deleted.

25 changes: 0 additions & 25 deletions source/Nuke.Tooling/Requirements/NpmPackageRequirementAttribute.cs

This file was deleted.

27 changes: 0 additions & 27 deletions source/Nuke.Tooling/Requirements/NuGetPackageRequirement.cs

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions source/Nuke.Tooling/Requirements/PathToolRequirement.cs

This file was deleted.

25 changes: 0 additions & 25 deletions source/Nuke.Tooling/Requirements/PathToolRequirementAttribute.cs

This file was deleted.

34 changes: 33 additions & 1 deletion source/Nuke.Tooling/Requirements/ToolRequirement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@

namespace Nuke.Common.Tooling;

public class ToolRequirement
public class ToolRequirement;

public class PathToolRequirement(string pathExecutable) : ToolRequirement
{
public string PathExecutable { get; init => field = pathExecutable; }
}

public class NuGetPackageRequirement(string packageId, string version = null) : ToolRequirement
{
public string PackageId { get; init => field = packageId; }
public string Version
{
get;
init => field = version ?? NuGetVersionResolver.GetLatestVersion(packageId, includePrereleases: false).GetAwaiter().GetResult();
}
}

public class NpmPackageRequirement(string packageId, string version = null) : ToolRequirement
{
public string PackageId { get; init => field = packageId; }
public string Version
{
get;
init => field = version ?? NpmVersionResolver.GetLatestVersion(packageId).GetAwaiter().GetResult();
}
}

public class AptGetPackageRequirement(string packageId) : ToolRequirement
{
public string PackageId
{
get;
init => field = packageId;
}
}
13 changes: 0 additions & 13 deletions source/Nuke.Tooling/Requirements/ToolRequirementAttributeBase.cs

This file was deleted.

Loading

0 comments on commit 8e663e2

Please sign in to comment.