Skip to content
Permalink
Browse files

[Assets] Added the concept of Package container (project or standalone)

  • Loading branch information
xen2 committed Sep 6, 2018
1 parent c444d02 commit eb15b2caaf37ef0d99c691119fde4345c62f6f81
Showing with 585 additions and 587 deletions.
  1. +1 −11 sources/assets/Xenko.Core.Assets.Tests/TestPackage.cs
  2. +1 −1 sources/assets/Xenko.Core.Assets/AssetItemExtensions.cs
  3. +17 −80 sources/assets/Xenko.Core.Assets/Package.cs
  4. +4 −4 sources/assets/Xenko.Core.Assets/PackageCollection.cs
  5. +1 −1 sources/assets/Xenko.Core.Assets/PackageExtensions.cs
  6. +257 −135 sources/assets/Xenko.Core.Assets/PackageSession.cs
  7. +6 −6 sources/editor/Xenko.Assets.Presentation/AssetEditors/ProjectWatcher.cs
  8. +1 −1 ...o.Assets.Presentation/AssetEditors/ScriptEditor/BindScriptTextEditorWorkspaceProjectIdBehavior.cs
  9. +4 −3 sources/editor/Xenko.Assets.Presentation/EffectCompilerServerSession.cs
  10. +8 −8 sources/editor/Xenko.Assets.Presentation/Templates/NewGameTemplateGenerator.cs
  11. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/NewPackageTemplateGenerator.cs
  12. +2 −2 sources/editor/Xenko.Assets.Presentation/Templates/ProjectLibraryTemplateGenerator.cs
  13. +4 −4 sources/editor/Xenko.Assets.Presentation/Templates/UpdatePlatformsTemplateGenerator.cs
  14. +8 −5 sources/editor/Xenko.Assets.Presentation/ViewModel/CodeViewModel.cs
  15. +2 −2 sources/editor/Xenko.Assets.Presentation/ViewModel/GameSettingsViewModel.cs
  16. +2 −2 sources/editor/Xenko.Assets.Presentation/ViewModel/SceneViewModel.cs
  17. +2 −1 sources/editor/Xenko.Assets.Presentation/ViewModel/ScriptSourceFileAssetViewModel.cs
  18. +2 −2 sources/editor/Xenko.Assets.Presentation/ViewModel/SpriteFontViewModel.cs
  19. +2 −2 sources/editor/Xenko.Core.Assets.Editor/Services/UserDocumentationService.cs
  20. +11 −1 sources/editor/Xenko.Core.Assets.Editor/View/CommonResources.xaml
  21. +1 −0 sources/editor/Xenko.Core.Assets.Editor/View/PackagePickerWindow.xaml.cs
  22. +8 −2 sources/editor/Xenko.Core.Assets.Editor/View/TreeViewTemplateSelector.cs
  23. +6 −6 sources/editor/Xenko.Core.Assets.Editor/ViewModel/AssetCollectionViewModel.cs
  24. +4 −4 sources/editor/Xenko.Core.Assets.Editor/ViewModel/AssetDependenciesViewModel.cs
  25. +1 −1 sources/editor/Xenko.Core.Assets.Editor/ViewModel/AssetViewModel.cs
  26. +2 −2 sources/editor/Xenko.Core.Assets.Editor/ViewModel/DirectoryBaseViewModel.cs
  27. +1 −1 sources/editor/Xenko.Core.Assets.Editor/ViewModel/DirectoryViewModel.cs
  28. +1 −1 sources/editor/Xenko.Core.Assets.Editor/ViewModel/MountPointViewModel.cs
  29. +15 −77 sources/editor/Xenko.Core.Assets.Editor/ViewModel/PackageViewModel.cs
  30. +0 −42 sources/editor/Xenko.Core.Assets.Editor/ViewModel/ProfileViewModel.cs
  31. +80 −55 sources/editor/Xenko.Core.Assets.Editor/ViewModel/ProjectViewModel.cs
  32. +58 −48 sources/editor/Xenko.Core.Assets.Editor/ViewModel/SessionViewModel.cs
  33. +2 −2 sources/editor/Xenko.Editor/Build/GameSettingsProviderService.cs
  34. +10 −8 sources/editor/Xenko.Editor/Build/XenkoShaderImporter.cs
  35. +1 −1 sources/editor/Xenko.GameStudio/CrashReportHelper.cs
  36. +1 −1 sources/editor/Xenko.GameStudio/Debugging/IDebugService.cs
  37. +3 −3 sources/editor/Xenko.GameStudio/Debugging/XenkoDebugService.cs
  38. +16 −16 sources/editor/Xenko.GameStudio/DebuggingViewModel.cs
  39. +5 −5 sources/editor/Xenko.GameStudio/GameStudioWindow.xaml.cs
  40. +1 −0 sources/editor/Xenko.GameStudio/XenkoEditorPlugin.cs
  41. +4 −3 sources/engine/Xenko.Assets/Analysis/GamePackageSessionAnalysis.cs
  42. +8 −11 sources/engine/Xenko.Assets/GameSettingsAssetCompiler.cs
  43. +2 −7 sources/engine/Xenko.Assets/GameSettingsAssetExtensions.cs
  44. +1 −1 sources/engine/Xenko.Assets/Scripts/VisualScriptAsset.cs
  45. +9 −11 sources/engine/Xenko.Assets/Templates/ProjectTemplateGeneratorHelper.cs
  46. +4 −3 sources/engine/Xenko.Assets/XenkoPackageUpgrader.NamespaceRenaming.cs
  47. +4 −3 sources/engine/Xenko.Assets/XenkoPackageUpgrader.cs
  48. +1 −1 sources/tools/Xenko.ProjectGenerator/PackageUnitTestGenerator.cs
@@ -29,9 +29,6 @@ public void TestBasicPackageCreateSaveLoad()
var project = new Package { Id = Guid.Empty, FullPath = testGenerated1 };
project.Profile.AssetFolders.Clear();
project.Profile.AssetFolders.Add(new AssetFolder("."));
project.ProjectFullPath = Path.Combine(dirPath, "test.csproj");
project.Type = PackageType.ProjectAndPackage;
project.ProjectType = ProjectType.Executable;

var session = new PackageSession(project);
// Write the solution when saving
@@ -53,7 +50,6 @@ public void TestBasicPackageCreateSaveLoad()
var rawSourceFolder = rawPackage.Profile.AssetFolders.FirstOrDefault();
Assert.NotNull(rawSourceFolder);
Assert.Equal(".", (string)rawSourceFolder.Path);
Assert.Equal("test.csproj", (string)rawPackage.ProjectFullPath);

// Reload the package directly from the xkpkg
var project2Result = PackageSession.Load(testGenerated1);
@@ -62,7 +58,7 @@ public void TestBasicPackageCreateSaveLoad()
Assert.NotNull(project2);
Assert.Equal(project.Id, project2.Id);
Assert.True(project2.Profile.AssetFolders.Count > 0);
Assert.Equal(project2, project2Result.Session.CurrentPackage); // Check that the current package is setup when loading a single package
Assert.Equal(project2.Container, project2Result.Session.CurrentProject); // Check that the current package is setup when loading a single package
var sourceFolder = project.Profile.AssetFolders.First().Path;
Assert.Equal(sourceFolder, project2.Profile.AssetFolders.First().Path);

@@ -74,12 +70,6 @@ public void TestBasicPackageCreateSaveLoad()
Assert.Single(sessionReload.LocalPackages);
var reloadPackage = sessionReload.LocalPackages.First();
Assert.Equal(project.Id, reloadPackage.Id);

Assert.NotNull(reloadPackage.ProjectFullPath);

Assert.Equal(project.ProjectFullPath, reloadPackage.ProjectFullPath);
Assert.Equal(project.Type, reloadPackage.Type);
Assert.Equal(project.ProjectType, reloadPackage.ProjectType);
}

[Fact]
@@ -17,7 +17,7 @@ public static class AssetItemExtensions
public static string GetProjectInclude([NotNull] this AssetItem assetItem)
{
var assetFullPath = assetItem.FullPath;
var projectFullPath = assetItem.Package.ProjectFullPath;
var projectFullPath = (assetItem.Package.Container as SolutionProject)?.FullPath;
return assetFullPath.MakeRelative(projectFullPath.GetFullDirectory()).ToWindowsPath();
}

@@ -32,11 +32,6 @@ 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.
@@ -50,17 +45,6 @@ public enum PackageState
AssetsReady,
}

public enum PackageType
{
/// <summary>
/// Typically from a NuGet folder.
/// </summary>
Standalone,

ProjectOnly,
ProjectAndPackage,
}

/// <summary>
/// A package managing assets.
/// </summary>
@@ -82,9 +66,6 @@ public sealed partial class Package : IIdentifiable, IFileSynchronizable, IAsset
/// </summary>
internal bool IsIdLocked;

[DataMemberIgnore]
public VisualStudio.Project VSProject;

private readonly List<UFile> filesToDelete = new List<UFile>();

private PackageSession session;
@@ -214,21 +195,6 @@ public Guid Id
[DataMember(100)]
public RootAssetCollection RootAssets { get; private set; } = new RootAssetCollection();

/// <summary>
/// Type of package.
/// </summary>
[DataMemberIgnore]
public PackageType Type { get; set; } = PackageType.Standalone;

[DataMemberIgnore]
public ProjectType? ProjectType { get; set; }

[DataMemberIgnore]
public List<LockFileLibrary> Dependencies { get; } = new List<LockFileLibrary>();

[DataMemberIgnore]
public List<Package> LoadedDependencies { get; } = new List<Package>();

/// <summary>
/// Gets the loaded templates from the <see cref="TemplateFolders"/>
/// </summary>
@@ -271,9 +237,6 @@ public UFile FullPath
}
}

[DataMemberIgnore]
public UFile ProjectFullPath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this instance has been modified since last saving.
/// </summary>
@@ -303,28 +266,16 @@ public bool IsDirty
[DataMemberIgnore]
public UDirectory RootDirectory => FullPath?.GetParent();

[DataMemberIgnore]
public PackageContainer Container { get; internal set; }

/// <summary>
/// Gets the session.
/// </summary>
/// <value>The session.</value>
/// <exception cref="System.InvalidOperationException">Cannot attach a package to more than one session</exception>
[DataMemberIgnore]
public PackageSession Session
{
get
{
return session;
}
internal set
{
if (value != null && session != null && !ReferenceEquals(session, value))
{
throw new InvalidOperationException("Cannot attach a package to more than one session");
}
session = value;
IsIdLocked = (session != null);
}
}
public PackageSession Session => Container?.Session;

/// <summary>
/// Gets the package user settings. Usually stored in a .user file alongside the package. Lazily loaded on first time.
@@ -526,9 +477,6 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
return;
}

if (Type == PackageType.ProjectOnly)
return;

saveParameters = saveParameters ?? PackageSaveParameters.Default();

// Use relative paths when saving
@@ -612,7 +560,7 @@ public void Save(ILogger log, PackageSaveParameters saveParameters = null)
var projectAsset = asset.Asset as IProjectAsset;
if (projectAsset != null)
{
var projectFullPath = asset.Package.ProjectFullPath;
var projectFullPath = (asset.Package.Container as SolutionProject)?.FullPath;
var projectInclude = asset.GetProjectInclude();

Project project;
@@ -764,17 +712,6 @@ public static Package Load(ILogger log, string filePath, PackageLoadParameters l
{
var package = LoadRaw(log, filePath);

// TODO CSPROJ=XKPKG temp code until Package loading supports csproj format natively
var projectFullPath = Path.ChangeExtension(package.FullPath, ".csproj");
if (File.Exists(projectFullPath))
{
var project = new VisualStudio.Project(package.Id, VisualStudio.KnownProjectTypeGuid.CSharp, Path.GetFileNameWithoutExtension(projectFullPath), projectFullPath, Guid.Empty, null, null, null);
package.ProjectFullPath = project.FullPath;
package.Type = PackageType.ProjectAndPackage;
package.ProjectType = Core.Assets.ProjectType.Library;
package.VSProject = project;
}

if (package != null)
{
if (!package.LoadAssembliesAndAssets(log, loadParametersArg))
@@ -1144,9 +1081,6 @@ 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);
}
@@ -1157,9 +1091,10 @@ public void UpdateAssemblyReferences(ILogger log, PackageLoadParameters loadPara
/// <param name="log">The log.</param>
public void RestoreNugetPackages(ILogger log)
{
if (ProjectFullPath != null)
var projectFullPath = (Container as SolutionProject)?.FullPath;
if (projectFullPath != null)
{
VSProjectHelper.RestoreNugetPackagesNonRecursive(log, ProjectFullPath.ToWindowsPath()).Wait();
VSProjectHelper.RestoreNugetPackagesNonRecursive(log, projectFullPath.ToWindowsPath()).Wait();
}
}

@@ -1189,16 +1124,17 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters
if (loadParameters == null) throw new ArgumentNullException(nameof(loadParameters));
var assemblyContainer = loadParameters.AssemblyContainer ?? AssemblyContainer.Default;

if (ProjectFullPath != null)
var projectFullPath = (Container as SolutionProject)?.FullPath;
if (projectFullPath != null)
{
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, ProjectFullPath, Core.Assets.ProjectType.Library);
var projectReference = new ProjectReference(Id, projectFullPath, Core.Assets.ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;

string assemblyPath = null;
var fullProjectLocation = ProjectFullPath.ToWindowsPath();
var fullProjectLocation = projectFullPath.ToWindowsPath();

try
{
@@ -1370,7 +1306,7 @@ public static List<PackageLoadingAssetFile> ListAssetFiles(ILogger log, Package
var ext = fileUPath.GetFileExtension();

//make sure to add default shaders in this case, since we don't have a csproj for them
if (AssetRegistry.IsProjectCodeGeneratorAssetFileExtension(ext) && package.ProjectFullPath == null)
if (AssetRegistry.IsProjectCodeGeneratorAssetFileExtension(ext) && !(package.Container is SolutionProject))
{
listFiles.Add(new PackageLoadingAssetFile(fileUPath, sourceFolder) { CachedFileSize = filePath.Length });
continue;
@@ -1424,12 +1360,13 @@ private static void FindAssetsInProject(ICollection<PackageLoadingAssetFile> lis
{
if (package.IsSystem) return;

if (package.ProjectFullPath != null)
var projectFullPath = (package.Container as SolutionProject)?.FullPath;
if (projectFullPath != null)
{
string defaultNamespace;
var codePaths = FindAssetsInProject(package.ProjectFullPath, out defaultNamespace);
var codePaths = FindAssetsInProject(projectFullPath, out defaultNamespace);
package.RootNamespace = defaultNamespace;
var dir = new UDirectory(package.ProjectFullPath.GetFullDirectory());
var dir = new UDirectory(projectFullPath.GetFullDirectory());

foreach (var codePath in codePaths)
{
@@ -1,12 +1,12 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using NuGet.ProjectModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using NuGet.ProjectModel;
using Xenko.Core;
using Xenko.Core.Diagnostics;

@@ -66,10 +66,10 @@ IEnumerator IEnumerable.GetEnumerator()
/// </summary>
/// <param name="packageDependency">The package dependency.</param>
/// <returns>Package.</returns>
public Package Find(LockFileLibrary lockFileLibrary)
public Package Find(Dependency dependency)
{
if (lockFileLibrary == null) throw new ArgumentNullException(nameof(lockFileLibrary));
return Find(lockFileLibrary.Name, new PackageVersionRange(new PackageVersion(lockFileLibrary.Version.Version, lockFileLibrary.Version.Release)));
if (dependency == null) throw new ArgumentNullException(nameof(dependency));
return Find(dependency.Name, dependency.VersionRange);
}

/// <summary>
@@ -40,7 +40,7 @@ internal static IEnumerable<Package> GetPackagesWithDependencies(this Package cu

var session = currentPackage.Session;

foreach (var package in currentPackage.LoadedDependencies)
foreach (var package in currentPackage.Container.LoadedDependencies)
{
yield return package;
}

0 comments on commit eb15b2c

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