Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… & bump to Cake 1.1
  • Loading branch information
dmariogatto committed May 9, 2021
1 parent b4269b1 commit 331974a
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 124 deletions.
12 changes: 6 additions & 6 deletions src/Cake.XCode.Tests/Cake.XCode.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Common" Version="0.33.0" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="Cake.Core" Version="1.1.0" />
<PackageReference Include="Cake.Common" Version="1.1.0" />
<PackageReference Include="Cake.Testing" Version="1.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 13 additions & 10 deletions src/Cake.XCode.Tests/Fakes/FakeCakeArguments.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Cake.Core;

namespace Cake.XCode.Tests.Fakes
{
internal sealed class FakeCakeArguments : ICakeArguments
{
private readonly Dictionary<string, string> _arguments;
private readonly Dictionary<string, List<string>> _arguments;

/// <summary>
/// Gets the arguments.
/// </summary>
/// <value>The arguments.</value>
public IReadOnlyDictionary<string, string> Arguments
{
get { return _arguments; }
}
public IReadOnlyDictionary<string, List<string>> Arguments => _arguments;

/// <summary>
/// Initializes a new instance of the <see cref="CakeArguments"/> class.
/// </summary>
public FakeCakeArguments()
{
_arguments = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_arguments = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Initializes the argument list.
/// </summary>
/// <param name="arguments">The arguments.</param>
public void SetArguments(IDictionary<string, string> arguments)
public void SetArguments(IDictionary<string, List<string>> arguments)
{
if (arguments == null)
{
throw new ArgumentNullException("arguments");
throw new ArgumentNullException(nameof(arguments));
}
_arguments.Clear();
foreach (var argument in arguments)
Expand All @@ -54,15 +52,20 @@ public bool HasArgument(string name)
return _arguments.ContainsKey(name);
}

public ICollection<string> GetArguments(string name)
{
_arguments.TryGetValue(name, out var arguments);
return arguments ?? (ICollection<string>)Array.Empty<string>();
}

/// <summary>
/// Gets an argument.
/// </summary>
/// <param name="name">The argument name.</param>
/// <returns>The argument value.</returns>
public string GetArgument(string name)
{
return _arguments.ContainsKey(name)
? _arguments[name] : null;
return GetArguments(name).LastOrDefault();
}
}
}
112 changes: 59 additions & 53 deletions src/Cake.XCode.Tests/Fakes/FakeCakeContext.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
using System;
using Cake.Core.IO;
using Cake.Core;
using System.Collections.Generic;
using Cake.Core.Tooling;
using Cake.Testing;

namespace Cake.XCode.Tests.Fakes
{
public class FakeCakeContext
{
ICakeContext context;
FakeLog log;
DirectoryPath testsDir;

public FakeCakeContext ()
{
testsDir = new DirectoryPath (System.IO.Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", ".."));

var fileSystem = new FileSystem ();
var environment = new FakeEnvironment (PlatformFamily.OSX);
var globber = new Globber (fileSystem, environment);
log = new FakeLog ();
var args = new FakeCakeArguments ();
var registry = new WindowsRegistry ();
var toolRepo = new ToolRepository(environment);
var config = new Core.Configuration.CakeConfigurationProvider(fileSystem, environment).CreateConfiguration(testsDir, new Dictionary<string, string>());
var toolResolutionStrategy = new ToolResolutionStrategy(fileSystem, environment, globber, config);
var toolLocator = new ToolLocator(environment, toolRepo, toolResolutionStrategy);
var processRunner = new ProcessRunner(fileSystem, environment, log, toolLocator, config);
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Tooling;
using Cake.Testing;
using System;

namespace Cake.XCode.Tests.Fakes
{
public class FakeCakeContext
{
readonly ICakeContext context;
readonly FakeLog log;
readonly DirectoryPath testsDir;

public FakeCakeContext()
{
testsDir = new DirectoryPath(
System.IO.Path.GetFullPath(AppContext.BaseDirectory));

var fileSystem = new FileSystem();
log = new FakeLog();
var runtime = new CakeRuntime();
var platform = new FakePlatform(PlatformFamily.Windows);
var environment = new CakeEnvironment(platform, runtime);
var globber = new Globber(fileSystem, environment);

var args = new FakeCakeArguments();
var registry = new WindowsRegistry();

var dataService = new FakeDataService();
context = new CakeContext(fileSystem, environment, globber, log, args, processRunner, registry, toolLocator, dataService, config);
context.Environment.WorkingDirectory = testsDir;
}

public DirectoryPath WorkingDirectory {
get { return testsDir; }
}

public ICakeContext CakeContext {
get { return context; }
}

public string GetLogs ()
var toolRepository = new ToolRepository(environment);
var config = new FakeConfiguration();
var toolResolutionStrategy = new ToolResolutionStrategy(fileSystem, environment, globber, config, log);
IToolLocator tools = new ToolLocator(environment, toolRepository, toolResolutionStrategy);
var processRunner = new ProcessRunner(fileSystem, environment, log, tools, config);
context = new CakeContext(fileSystem, environment, globber, log, args, processRunner, registry, tools, dataService, config);
context.Environment.WorkingDirectory = testsDir;
}

public DirectoryPath WorkingDirectory
{
get { return testsDir; }
}

public ICakeContext CakeContext
{
get { return context; }
}

public string GetLogs()
{
return string.Join(Environment.NewLine, log.Messages);
}

public void DumpLogs ()
{
foreach (var m in log.Messages)
Console.WriteLine (m);
}
}
}

}

public void DumpLogs()
{
foreach (var m in log.Messages)
Console.WriteLine(m);
}
}
}
2 changes: 1 addition & 1 deletion src/Cake.XCode.Tests/Fakes/FakeCakeDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Cake.XCode.Tests.Fakes
{
public class FakeDataService : ICakeDataService
{
List<object> values = new List<object>();
readonly List<object> values = new List<object>();

public void Add<TData>(TData value) where TData : class
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.XCode.Tests/Fakes/FakeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public FakeLog()
public Verbosity Verbosity
{
get { return Verbosity.Diagnostic; }
set { }
set { }
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Cake.XCode.Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public XCodeTests ()

context.CakeContext.CreateDirectory ("./TestProjects/tmp");
}

public void Dispose ()
{
context.DumpLogs ();
Expand Down Expand Up @@ -55,7 +55,7 @@ public void PodInstall ()

if (version < new Version (1, 0))
podfile.RemoveRange (0, 4);

var f = new FilePath ("./TestProjects/tmp/Podfile")
.MakeAbsolute (context.CakeContext.Environment).FullPath;
System.IO.File.WriteAllLines (f, podfile.ToArray ());
Expand Down Expand Up @@ -98,7 +98,7 @@ public void PodUpdate ()

context.CakeContext.CocoaPodUpdate ("./TestProjects/tmp/", new CocoaPodUpdateSettings {
NoIntegrate = true
});
});

var pfl = new FilePath ("./TestProjects/tmp/Podfile.lock");
var text = System.IO.File.ReadAllText (pfl.MakeAbsolute (context.CakeContext.Environment).FullPath);
Expand Down
8 changes: 4 additions & 4 deletions src/Cake.XCode/Cake.XCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<Title>Cake.XCode</Title>
<Summary>XCode and CocoaPods addon for cake build.</Summary>
<Description>Cake Build addon for XCode and CocoaPods.</Description>
<PackageTags>Cake Script Build XCode CocoaPods Pod</PackageTags>
<PackageTags>Cake Script Build XCode CocoaPods Pod cake-addin</PackageTags>
<Authors>Redth</Authors>
<Owners>Redth, cake-contrib</Owners>
<PackageProjectUrl>https://github.com/cake-contrib/Cake.XCode</PackageProjectUrl>
<PackageIconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png</PackageIconUrl>
<PackageIconUrl>https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/addin/cake-contrib-addin-medium.png</PackageIconUrl>
<RepositoryUrl>https://github.com/cake-contrib/Cake.XCode.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="0.33.0" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="1.1.0" PrivateAssets="All" />
<PackageReference Include="Cake.Common" Version="1.1.0" PrivateAssets="All" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Cake.XCode/CocoaPodAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void CocoaPodInstall (this ICakeContext context, DirectoryPath pro
[CakeMethodAlias]
public static void CocoaPodInstall (this ICakeContext context, DirectoryPath projectDirectory, CocoaPodInstallSettings settings)
{
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Globber);
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
r.Install (context, projectDirectory, settings);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ public static void CocoaPodUpdate (this ICakeContext context, DirectoryPath proj
[CakeMethodAlias]
public static void CocoaPodUpdate (this ICakeContext context, DirectoryPath projectDirectory, string[] podNames, CocoaPodUpdateSettings settings)
{
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Globber);
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
r.Update (context, projectDirectory, podNames, settings);
}

Expand All @@ -91,7 +91,7 @@ public static System.Version CocoaPodVersion (this ICakeContext context)
[CakeMethodAlias]
public static System.Version CocoaPodVersion (this ICakeContext context, CocoaPodSettings settings)
{
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Globber);
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
return r.GetVersion (settings);
}

Expand All @@ -103,7 +103,7 @@ public static System.Version CocoaPodVersion (this ICakeContext context, CocoaPo
[CakeMethodAlias]
public static void CocoaPodRepoUpdate (this ICakeContext context)
{
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Globber);
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
r.RepoUpdate (new CocoaPodSettings ());
}

Expand All @@ -115,7 +115,7 @@ public static void CocoaPodRepoUpdate (this ICakeContext context)
[CakeMethodAlias]
public static void CocoaPodRepoUpdate (this ICakeContext context, CocoaPodSettings settings)
{
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Globber);
var r = new CocoaPodRunner (context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
r.RepoUpdate (settings);
}
}
Expand Down
25 changes: 10 additions & 15 deletions src/Cake.XCode/CocoaPodRunner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Utilities;
using Cake.Core;
using Cake.Core.Tooling;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -10,13 +10,8 @@ namespace Cake.CocoaPods
/// <summary>
/// CocoaPod settings.
/// </summary>
public class CocoaPodSettings
public class CocoaPodSettings : ToolSettings
{
/// <summary>
/// Gets or sets the path to pod executable.
/// </summary>
/// <value>The tool path.</value>
public FilePath ToolPath { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -112,8 +107,8 @@ internal class CocoaPodRunner : Tool<CocoaPodSettings>
{
readonly ICakeEnvironment _cakeEnvironment;

public CocoaPodRunner (IFileSystem fileSystem, ICakeEnvironment cakeEnvironment, IProcessRunner processRunner, IGlobber globber)
: base (fileSystem, cakeEnvironment, processRunner, globber)
public CocoaPodRunner (IFileSystem fileSystem, ICakeEnvironment cakeEnvironment, IProcessRunner processRunner, IToolLocator toolLocator)
: base (fileSystem, cakeEnvironment, processRunner, toolLocator)
{
_cakeEnvironment = cakeEnvironment;
}
Expand Down Expand Up @@ -180,14 +175,14 @@ public void Install (ICakeContext context, DirectoryPath projectDirectory, Cocoa
if (projectDirectory != null)
builder.Append ("--project-directory=" + projectDirectory.MakeAbsolute (_cakeEnvironment).FullPath.Quote ());

Run (settings, builder, settings.ToolPath);
Run (settings, builder);
}

public void Update (ICakeContext context, DirectoryPath projectDirectory, string[] podNames, CocoaPodUpdateSettings settings)
{
if (settings == null)
settings = new CocoaPodUpdateSettings ();

var version = GetVersion (settings);

var builder = new ProcessArgumentBuilder ();
Expand Down Expand Up @@ -233,7 +228,7 @@ public void Update (ICakeContext context, DirectoryPath projectDirectory, string
if (settings.ToolPath == null)
Run (settings, builder);
else
Run (settings, builder, settings.ToolPath);
Run (settings, builder);
}

public Version GetVersion (CocoaPodSettings settings)
Expand All @@ -243,7 +238,7 @@ public Version GetVersion (CocoaPodSettings settings)
var builder = new ProcessArgumentBuilder ();

builder.Append ("--version");
var process = RunProcess (s, builder, s.ToolPath, new ProcessSettings {
var process = RunProcess (s, builder, new ProcessSettings {
RedirectStandardOutput = true
});

Expand Down
Loading

0 comments on commit 331974a

Please sign in to comment.