Skip to content
Permalink
Browse files

[Assets] Reunified ProjectState and PackageState

  • Loading branch information
xen2 committed Sep 19, 2018
1 parent f7a8e09 commit c5cd46ae0b7bb4800c731e4d96b92858b6cfcefe
@@ -32,6 +32,11 @@ public enum PackageState
/// </summary>
Raw,

/// <summary>
/// Dependencies have all been resolved and are also in <see cref="DependenciesReady"/> state.
/// </summary>
DependenciesReady,

/// <summary>
/// Package upgrade has been failed (either error or denied by user).
/// Dependencies are ready, but not assets.
@@ -1082,6 +1087,9 @@ private void LoadAsset(AssetMigrationContext context, PackageLoadingAssetFile as
/// <param name="loadParametersArg">The load parameters argument.</param>
public void UpdateAssemblyReferences(ILogger log, PackageLoadParameters loadParametersArg = null)
{
if (State < PackageState.DependenciesReady)
return;

var loadParameters = loadParametersArg ?? PackageLoadParameters.Default();
LoadAssemblyReferencesForPackage(log, loadParameters);
}
@@ -81,8 +81,10 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje

bool packageDependencyErrors = false;

var package = project.Package;

// TODO: Remove and recheck Dependencies Ready if some secondary packages are removed?
if (project.State >= ProjectState.DependenciesReady)
if (package.State >= PackageState.DependenciesReady)
return;

log.Verbose("Restore NuGet packages...");
@@ -121,7 +123,6 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
}
}

var package = project.Package;
if (pendingPackageUpgrades.Count > 0)
{
var upgradeAllowed = packageUpgradeAllowed != false ? PackageUpgradeRequestedAnswer.Upgrade : PackageUpgradeRequestedAnswer.DoNotUpgrade;
@@ -299,7 +300,7 @@ private async Task PreLoadPackageDependencies(ILogger log, SolutionProject proje
// 3. Update package state
if (!packageDependencyErrors)
{
project.State = ProjectState.DependenciesReady;
package.State = PackageState.DependenciesReady;
}
}

@@ -106,19 +106,6 @@ public DependencyRange(string name, PackageVersionRange versionRange, Dependency
public DependencyType Type { get; set; }
}

public enum ProjectState
{
/// <summary>
/// Project has been deserialized. References and assets are not ready.
/// </summary>
Raw,

/// <summary>
/// Dependencies have all been resolved and are also in <see cref="DependenciesReady"/> state.
/// </summary>
DependenciesReady,
}

public class SolutionProject : PackageContainer
{
private PackageSession session;
@@ -151,8 +138,6 @@ public SolutionProject([NotNull] Package package, VisualStudio.Project vsProject

public UFile FullPath => VSProject.FullPath;

public ProjectState State { get; set; }

public ObservableCollection<DependencyRange> DirectDependencies { get; } = new ObservableCollection<DependencyRange>();

public ObservableCollection<Dependency> FlattenedDependencies { get; } = new ObservableCollection<Dependency>();
@@ -674,9 +659,11 @@ public void LoadMissingDependencies(ILogger log, PackageLoadParameters loadParam

var cancelToken = loadParameters.CancelToken;

var previousProjects = Projects.ToList();
foreach (var project in previousProjects)
// Note: list can grow as dependencies get loaded
for (int i = 0; i < Projects.Count; ++i)
{
var project = Projects[i];

// Output the session only if there is no cancellation
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
@@ -685,6 +672,8 @@ public void LoadMissingDependencies(ILogger log, PackageLoadParameters loadParam

if (project is SolutionProject solutionProject)
PreLoadPackageDependencies(log, solutionProject, loadParameters).Wait();
else if (project.Package.State < PackageState.DependenciesReady) // not handling standalone packages yet
project.Package.State = PackageState.DependenciesReady;
}
}

@@ -1132,6 +1121,10 @@ private bool TryLoadAssets(PackageSession session, ILogger log, Package package,
if (package.State >= PackageState.AssetsReady)
return true;

// Dependencies could not properly be loaded
if (package.State < PackageState.DependenciesReady)
return false;

// A package upgrade has previously been tried and denied, so let's keep the package in this state
if (package.State == PackageState.UpgradeFailed)
return false;

0 comments on commit c5cd46a

Please sign in to comment.
You can’t perform that action at this time.