Skip to content

Commit

Permalink
Handle pod 1.0+ changes
Browse files Browse the repository at this point in the history
No more --no-integrate and other options, so deprecate them, and warn if using them on 1.0+
Also add method to fetch the pod version
  • Loading branch information
Redth committed Jun 3, 2016
1 parent 1905304 commit 565f383
Showing 1 changed file with 80 additions and 15 deletions.
95 changes: 80 additions & 15 deletions Cake.XCode/CocoaPodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Cake.Core.Utilities;
using Cake.Core;
using System.Collections.Generic;
using System.Linq;

namespace Cake.CocoaPods
{
Expand All @@ -27,18 +28,21 @@ public class CocoaPodInstallSettings : CocoaPodSettings
/// Gets or sets a value indicating whether or not to integrate the pods into an xcode project.
/// </summary>
/// <value><c>true</c> to not integrate into a project; otherwise, <c>false</c>.</value>
[Obsolete ("Not available in CocoaPods >= 1.0")]
public bool NoIntegrate { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to clean .
/// </summary>
/// <value><c>true</c> if no cleaning should occur; otherwise, <c>false</c>.</value>
[Obsolete ("Not available in CocoaPods >= 1.0")]
public bool NoClean { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to update the repo.
/// </summary>
/// <value><c>true</c> if repo should not be updated; otherwise, <c>false</c>.</value>
[Obsolete ("Not available in CocoaPods >= 1.0")]
public bool NoRepoUpdate { get; set; }

/// <summary>
Expand Down Expand Up @@ -69,12 +73,14 @@ public class CocoaPodUpdateSettings : CocoaPodSettings
/// Gets or sets a value indicating whether or not to integrate the pods into an xcode project.
/// </summary>
/// <value><c>true</c> to not integrate into a project; otherwise, <c>false</c>.</value>
[Obsolete ("Not available in CocoaPods >= 1.0")]
public bool NoIntegrate { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to clean .
/// </summary>
/// <value><c>true</c> if no cleaning should occur; otherwise, <c>false</c>.</value>
[Obsolete ("Not available in CocoaPods >= 1.0")]
public bool NoClean { get; set; }

/// <summary>
Expand Down Expand Up @@ -130,23 +136,37 @@ protected override IEnumerable<FilePath> GetAlternativeToolPaths (CocoaPodSettin
};
}

public void Install (DirectoryPath projectDirectory, CocoaPodInstallSettings settings)
public void Install (ICakeContext context, DirectoryPath projectDirectory, CocoaPodInstallSettings settings)
{
if (settings == null)
settings = new CocoaPodInstallSettings ();

var builder = new ProcessArgumentBuilder ();

builder.Append ("install");
var version = GetVersion (settings);

if (settings.NoClean)
builder.Append ("--no-clean");
var builder = new ProcessArgumentBuilder ();

if (settings.NoIntegrate)
builder.Append ("--no-integrate");
builder.Append ("install");

if (settings.NoRepoUpdate)
builder.Append ("--no-repo-update");
if (version < new Version (1, 0)) {
if (settings.NoClean)
builder.Append ("--no-clean");

if (settings.NoIntegrate)
builder.Append ("--no-integrate");

if (settings.NoRepoUpdate)
builder.Append ("--no-repo-update");
} else {

if (settings.NoClean)
Warn (context, "--no-clean is not a valid option for CocoaPods >= 1.0");
if (settings.NoIntegrate)
Warn (context, "--no-integrate is not a valid option for CocoaPods >= 1.0"
+ Environment.NewLine
+ "Use `install! 'cocoapods', :integrate_targets => false` in your Podfile instead");
if (settings.NoRepoUpdate)
Warn (context, "--no-repo-update is not a valid option for CocoaPods >= 1.0");
}

if (settings.Silent)
builder.Append ("--silent");
Expand All @@ -163,8 +183,13 @@ public void Install (DirectoryPath projectDirectory, CocoaPodInstallSettings set
Run (settings, builder, settings.ToolPath);
}

public void Update (DirectoryPath projectDirectory, string[] podNames, CocoaPodUpdateSettings settings)
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 ();

builder.Append ("update");
Expand All @@ -174,11 +199,21 @@ public void Update (DirectoryPath projectDirectory, string[] podNames, CocoaPodU
builder.Append (pn);
}

if (settings.NoClean)
builder.Append ("--no-clean");
if (version < new Version (1, 0)) {
if (settings.NoClean)
builder.Append ("--no-clean");

if (settings.NoIntegrate)
builder.Append ("--no-integrate");
if (settings.NoIntegrate)
builder.Append ("--no-integrate");
} else {

if (settings.NoClean)
Warn (context, "--no-clean is not a valid option for CocoaPods >= 1.0");
if (settings.NoIntegrate)
Warn (context, "--no-integrate is not a valid option for CocoaPods >= 1.0"
+ Environment.NewLine
+ "Use `install! 'cocoapods', :integrate_targets => false` in your Podfile instead");
}

if (settings.NoRepoUpdate)
builder.Append ("--no-repo-update");
Expand All @@ -200,6 +235,36 @@ public void Update (DirectoryPath projectDirectory, string[] podNames, CocoaPodU
else
Run (settings, builder, settings.ToolPath);
}

public Version GetVersion (CocoaPodSettings settings)
{
var s = settings ?? new CocoaPodSettings ();

var builder = new ProcessArgumentBuilder ();

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


process.WaitForExit ();

var text = process.GetStandardOutput ().ToList ();

foreach (var line in text) {
Version tmpVersion;
if (Version.TryParse (line.Trim (), out tmpVersion))
return tmpVersion;
}

return null;
}

void Warn (ICakeContext context, string text, params object[] args)
{
context.Log.Write (Core.Diagnostics.Verbosity.Normal, Core.Diagnostics.LogLevel.Warning, text, args);
}
}
}

0 comments on commit 565f383

Please sign in to comment.