Skip to content

Commit

Permalink
Merge pull request #208 from derekfreed/dev/dependencyFailures
Browse files Browse the repository at this point in the history
Makes package fail install if dependencies fail to install
  • Loading branch information
jwittner authored Nov 16, 2018
2 parents 7be323c + 2015705 commit a3f653c
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions Assets/NuGet/Editor/NugetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@ public static void Uninstall(NugetPackageIdentifier package, bool refreshAssets
/// <param name="currentVersion">The current package to uninstall.</param>
/// <param name="newVersion">The package to install.</param>
/// <param name="refreshAssets">True to refresh the assets inside Unity. False to ignore them (for now). Defaults to true.</param>
public static void Update(NugetPackageIdentifier currentVersion, NugetPackage newVersion, bool refreshAssets = true)
public static bool Update(NugetPackageIdentifier currentVersion, NugetPackage newVersion, bool refreshAssets = true)
{
LogVerbose("Updating {0} {1} to {2}", currentVersion.Id, currentVersion.Version, newVersion.Version);
Uninstall(currentVersion, false);
InstallIdentifier(newVersion, refreshAssets);
return InstallIdentifier(newVersion, refreshAssets);
}

/// <summary>
Expand Down Expand Up @@ -1012,17 +1012,18 @@ private static void CopyStream(Stream input, Stream output)
/// </summary>
/// <param name="package">The identifer of the package to install.</param>
/// <param name="refreshAssets">True to refresh the Unity asset database. False to ignore the changes (temporarily).</param>
internal static void InstallIdentifier(NugetPackageIdentifier package, bool refreshAssets = true)
internal static bool InstallIdentifier(NugetPackageIdentifier package, bool refreshAssets = true)
{
NugetPackage foundPackage = GetSpecificPackage(package);

if (foundPackage != null)
{
Install(foundPackage, refreshAssets);
return Install(foundPackage, refreshAssets);
}
else
{
Debug.LogErrorFormat("Could not find {0} {1} or greater.", package.Id, package.Version);
return false;
}
}

Expand Down Expand Up @@ -1057,31 +1058,34 @@ public static void LogVerbose(string format, params object[] args)
/// </summary>
/// <param name="package">The package to install.</param>
/// <param name="refreshAssets">True to refresh the Unity asset database. False to ignore the changes (temporarily).</param>
public static void Install(NugetPackage package, bool refreshAssets = true)
public static bool Install(NugetPackage package, bool refreshAssets = true)
{
NugetPackage installedPackage = null;
if (installedPackages.TryGetValue(package.Id, out installedPackage))
{
if (installedPackage < package)
{
LogVerbose("{0} {1} is installed, but need {2} or greater. Updating to {3}", installedPackage.Id, installedPackage.Version, package.Version, package.Version);
return Update(installedPackage, package, false);
}
else if (installedPackage > package)
{
LogVerbose("{0} {1} is installed. {2} or greater is needed, so using installed version.", installedPackage.Id, installedPackage.Version, package.Version);
}
else
{
LogVerbose("Already installed: {0} {1}", package.Id, package.Version);
}
return true;
}

bool installSuccess = false;
try
{
LogVerbose("Installing: {0} {1}", package.Id, package.Version);

// look to see if the package (any version) is already installed
NugetPackage installedPackage = null;
if (installedPackages.TryGetValue(package.Id, out installedPackage))
{
if (installedPackage < package)
{
LogVerbose("{0} {1} is installed, but need {2} or greater. Updating to {3}", installedPackage.Id, installedPackage.Version, package.Version, package.Version);
Update(installedPackage, package, false);
}
else if (installedPackage > package)
{
LogVerbose("{0} {1} is installed. {2} or greater is needed, so using installed version.", installedPackage.Id, installedPackage.Version, package.Version);
}
else
{
LogVerbose("Already installed: {0} {1}", package.Id, package.Version);
}
return;
}


if (refreshAssets)
EditorUtility.DisplayProgressBar(string.Format("Installing {0} {1}", package.Id, package.Version), "Installing Dependencies", 0.1f);
Expand All @@ -1090,7 +1094,11 @@ public static void Install(NugetPackage package, bool refreshAssets = true)
foreach (var dependency in package.Dependencies)
{
LogVerbose("Installing Dependency: {0} {1}", dependency.Id, dependency.Version);
InstallIdentifier(dependency);
bool installed = InstallIdentifier(dependency);
if (!installed)
{
throw new Exception(String.Format("Failed to install dependency: {0} {1}.", dependency.Id, dependency.Version));
}
}

// update packages.config
Expand Down Expand Up @@ -1175,11 +1183,13 @@ public static void Install(NugetPackage package, bool refreshAssets = true)

// update the installed packages list
installedPackages.Add(package.Id, package);
installSuccess = true;
}
catch (Exception e)
{
WarnIfDotNetAuthenticationIssue(e);
Debug.LogErrorFormat("Unable to install package {0}\n{1}", package.Id, e.ToString());
Debug.LogErrorFormat("Unable to install package {0} {1}\n{2}", package.Id, package.Version, e.ToString());
installSuccess = false;
}
finally
{
Expand All @@ -1190,6 +1200,7 @@ public static void Install(NugetPackage package, bool refreshAssets = true)
EditorUtility.ClearProgressBar();
}
}
return installSuccess;
}

private static void WarnIfDotNetAuthenticationIssue(Exception e)
Expand Down

0 comments on commit a3f653c

Please sign in to comment.