Skip to content
Permalink
Browse files

[Assets] Removed PackageProfile.ProjectReferences

  • Loading branch information
xen2 committed Aug 31, 2018
1 parent 9f8f407 commit 62266f4a62756f5ddaf1fbfba1d6f85b87b3ed6c
@@ -29,8 +29,9 @@ public void TestBasicPackageCreateSaveLoad()
var project = new Package { Id = Guid.Empty, FullPath = testGenerated1 };
project.Profile.AssetFolders.Clear();
project.Profile.AssetFolders.Add(new AssetFolder("."));
var projectReference = new ProjectReference(Guid.Empty, Path.Combine(dirPath, "test.csproj"), ProjectType.Executable);
sharedProfile.ProjectReferences.Add(projectReference);
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
@@ -52,7 +53,7 @@ public void TestBasicPackageCreateSaveLoad()
var rawSourceFolder = rawPackage.Profile.AssetFolders.FirstOrDefault();
Assert.NotNull(rawSourceFolder);
Assert.Equal(".", (string)rawSourceFolder.Path);
Assert.Equal("test.csproj", (string)rawPackage.Profile.ProjectReferences[0].Location);
Assert.Equal("test.csproj", (string)rawPackage.ProjectFullPath);

// Reload the package directly from the xkpkg
var project2Result = PackageSession.Load(testGenerated1);
@@ -71,11 +72,14 @@ public void TestBasicPackageCreateSaveLoad()

var sessionReload = sessionResult.Session;
Assert.Single(sessionReload.LocalPackages);
Assert.Equal(project.Id, sessionReload.LocalPackages.First().Id);
var reloadPackage = sessionReload.LocalPackages.First();
Assert.Equal(project.Id, reloadPackage.Id);

var sharedProfileReload = sessionReload.LocalPackages.First().Profile;
Assert.Single(sharedProfileReload.ProjectReferences);
Assert.Equal(projectReference, sharedProfileReload.ProjectReferences[0]);
Assert.NotNull(reloadPackage.ProjectFullPath);

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

[Fact]
@@ -219,6 +219,9 @@ public Guid Id
[DataMemberIgnore]
public PackageType Type { get; set; } = PackageType.Standalone;

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

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

@@ -1177,7 +1180,7 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters
{
// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, ProjectFullPath, ProjectType.Library);
var projectReference = new ProjectReference(Id, ProjectFullPath, Core.Assets.ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;

@@ -1327,9 +1330,6 @@ public static List<PackageLoadingAssetFile> ListAssetFiles(ILogger log, Package
return listFiles;
}

var sharedProfile = package.Profile;
var hasProject = sharedProfile != null && sharedProfile.ProjectReferences.Count > 0;

// Iterate on each source folders
foreach (var sourceFolder in package.GetDistinctAssetFolderPaths())
{
@@ -1357,7 +1357,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) && !hasProject)
if (AssetRegistry.IsProjectCodeGeneratorAssetFileExtension(ext) && package.ProjectFullPath == null)
{
listFiles.Add(new PackageLoadingAssetFile(fileUPath, sourceFolder) { CachedFileSize = filePath.Length });
continue;
@@ -29,7 +29,6 @@ public PackageProfile()
{
assetFolders = new AssetFolderCollection();
OutputGroupDirectories = new Dictionary<string, UDirectory>();
ProjectReferences = new List<ProjectReference>();
}

/// <summary>
@@ -96,13 +95,6 @@ public PackageProfile(string name, params AssetFolder[] folders)
[DataMember(50)]
public Dictionary<string, UDirectory> OutputGroupDirectories { get; private set; }

/// <summary>
/// Gets the assembly references to load when compiling this package.
/// </summary>
/// <value>The assembly references.</value>
[DataMember(70)]
public List<ProjectReference> ProjectReferences { get; private set; }

/// <summary>
/// Creates a a default shared package profile.
/// </summary>
@@ -886,6 +886,7 @@ private Package PreLoadPackage(ILogger log, string filePath, bool isSystemPackag
{
package.ProjectFullPath = project.FullPath;
package.Type = PackageType.ProjectAndPackage;
package.ProjectType = ProjectType.Library;
package.VSProject = project;
}

@@ -30,8 +30,7 @@ private static List<string> ExtractReferencesList(PackageTemplateGeneratorParame
{
// libraries and executables
var referencedBinaryNames = new List<string>();
var references = parameters.Package.Profile.ProjectReferences.Where(projectRef => projectRef.Type == ProjectType.Library || projectRef.Type == ProjectType.Executable);
referencedBinaryNames.AddRange(references.Select(pr => pr.Location.GetFileNameWithoutExtension()));
referencedBinaryNames.AddRange(parameters.Package.Session.Packages.Where(x => x.ProjectFullPath != null).Select(x => x.ProjectFullPath.GetFileNameWithoutExtension()));
return referencedBinaryNames;
}

@@ -96,10 +96,6 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
return false;
}

// We are going to replace all projects id by new ids
var idsToReplace = package.Profile.ProjectReferences.Select(project => project.Id).Distinct().ToDictionary(guid => guid.ToString("D"), guid => Guid.NewGuid(), StringComparer.OrdinalIgnoreCase);
idsToReplace.Add(package.Id.ToString("D"), Guid.NewGuid());

// Add dependencies
foreach (var packageReference in package.LocalDependencies)
{
@@ -125,12 +121,12 @@ protected override bool Generate(SessionTemplateGeneratorParameters parameters)
{
return false;
}

var extraIdsToReplace = reference.Profile.ProjectReferences.Select(project => project.Id).Distinct().ToDictionary(guid => guid.ToString("D"), guid => Guid.NewGuid(), StringComparer.OrdinalIgnoreCase);

idsToReplace.AddRange(extraIdsToReplace);
}

// We are going to replace all projects/packages id by new ids
var idsToReplace = package.Session.Packages.Select(x => x.Id).Distinct().ToDictionary(guid => guid.ToString("D"), guid => Guid.NewGuid(), StringComparer.OrdinalIgnoreCase);
idsToReplace.Add(package.Id.ToString("D"), Guid.NewGuid());

var guidRegexPattern = new StringBuilder();
guidRegexPattern.Append("(");
guidRegexPattern.Append(string.Join("|", idsToReplace.Keys));
@@ -111,7 +111,7 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)
var sharedProfile = package.Profile;

// TODO: this is not a safe way to get a game project see PDX-1128
var gameProjectRef = FindSharedGameProject(package, sharedProfile, logger);
var gameProjectRef = package.ProjectFullPath;

if (gameProjectRef == null)
{
@@ -122,11 +122,12 @@ public sealed override bool Run(PackageTemplateGeneratorParameters parameters)
var templateGameLibrary = PrepareTemplate(parameters, "ProjectLibrary.Game/ProjectLibrary.Game.ttproj", PlatformType.Shared, null, null, ProjectType.Library);
var options = ProjectTemplateGeneratorHelper.GetOptions(parameters);
var newGameTargetFrameworks = templateGameLibrary.GeneratePart(@"..\Common.TargetFrameworks.targets.t4", logger, options);
PatchGameProject(newGameTargetFrameworks, gameProjectRef.Location.FullPath);
PatchGameProject(newGameTargetFrameworks, gameProjectRef.FullPath);

// Generate missing platforms
bool forceGenerating = parameters.GetTag(ForcePlatformRegenerationKey);
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), gameProjectRef.Id, name, package, forceGenerating);
// TODO CSPROJ=XKPKG
ProjectTemplateGeneratorHelper.UpdatePackagePlatforms(parameters, parameters.GetTag(PlatformsKey), parameters.GetTag(OrientationKey), package.Id, name, package, forceGenerating);

// Save the session after the update
// FIXME: Saving like this is not supported anymore - let's not save for now be we should provide a proper way to save!
@@ -151,13 +152,13 @@ private static string GetDefaultNamespace(PackageTemplateGeneratorParameters par
var sharedProfile = package.Profile;

// Get the game project
var gameProjectRef = FindSharedGameProject(package, sharedProfile, logger);
var gameProjectRef = package.ProjectFullPath;
if (gameProjectRef != null)
{

try
{
var project = VSProjectHelper.LoadProject(gameProjectRef.Location);
var project = VSProjectHelper.LoadProject(gameProjectRef);
defaultNamespace = project.GetPropertyValue("RootNamespace");
}
catch (Exception e)
@@ -185,20 +186,6 @@ private static ProjectTemplate PrepareTemplate(PackageTemplateGeneratorParameter
return ProjectTemplateGeneratorHelper.PrepareTemplate(parameters, package, templateRelativePath, platformType, graphicsPlatform, projectType);
}

private static ProjectReference FindSharedGameProject(Package package, PackageProfile sharedProfile, ILogger logger)
{
if (sharedProfile == null) throw new ArgumentNullException(nameof(sharedProfile));

// TODO: this is not a reliable way to get a game project see PDX-1128
var gameProjectRef = sharedProfile.ProjectReferences.FirstOrDefault(projectRef => projectRef.Type == ProjectType.Library && projectRef.Location.FullPath.EndsWith("Game.csproj", StringComparison.InvariantCultureIgnoreCase));
if (gameProjectRef == null)
{
logger.Error($"Unable to find the game project reference from the package [{package.Meta.Name}]");
return null;
}
return gameProjectRef;
}

private static bool MatchPropertyGroup(XElement element)
{
return element.Name.LocalName == "PropertyGroup";
@@ -282,11 +282,11 @@ internal void LoadPackageInformation(LoggerResult loggerResult, WorkProgressView
//if (projectSourceCodeAsset != null && asset.SourceProject != null)
//{
// var project = Content.OfType<ProjectViewModel>().First(x => string.Compare(asset.SourceProject.GetFileNameWithoutExtension(), x.Name, StringComparison.InvariantCultureIgnoreCase) == 0);
// directory = GetOrCreateProjectDirectory(project, url.GetDirectory() ?? "", false);
// directory = GetOrCreateProjectDirectory(project, url.GetFullDirectory() ?? "", false);
//}
//else
{
directory = GetOrCreateAssetDirectory(url.GetDirectory() ?? "", false);
directory = GetOrCreateAssetDirectory(url.GetFullDirectory() ?? "", false);
}
CreateAsset(directory, asset, false, loggerResult, true);
++progress;
@@ -28,10 +28,9 @@ public ProfileViewModel(SessionViewModel session, Package package, PackageProfil

Package = container;

foreach (var projectReference in profile.ProjectReferences)
if (Package.Package.ProjectFullPath != null)
{
var viewModel = new ProjectViewModel(projectReference, this);
Projects.Add(viewModel);
Projects.Add(new ProjectViewModel(this));
}
}

@@ -61,56 +60,26 @@ public bool HasExecutables
}
}

/// <summary>
/// Delete the given project from this profile.
/// </summary>
/// <param name="projectReference">The project to delete.</param>
/// <remarks>This method is intended to be invoked only by the <see cref="ProjectViewModel"/> class.</remarks>
internal void DeleteProject(ProjectReference projectReference)
{
profile.ProjectReferences.RemoveWhere(x => x.Id == projectReference.Id);
Projects.RemoveWhere(x => x.Id == projectReference.Id);
var projectViewModel = Package.Content.OfType<ProjectViewModel>().FirstOrDefault(x => x.Id == projectReference.Id);
Package.RemoveProject(projectViewModel);
}

/// <summary>
/// Add the given project to this profile.
/// </summary>
/// <param name="projectToAdd">The view model of the project to add.</param>
/// <param name="projectReference">The project to add.</param>
/// <remarks>This method is intended to be invoked only by the <see cref="ProjectViewModel"/> class.</remarks>
internal void AddProject(ProjectViewModel projectToAdd, ProjectReference projectReference)
{
if (!profile.ProjectReferences.Contains(projectReference))
{
profile.ProjectReferences.Add(projectReference);
Projects.Add(projectToAdd);
Package.AddProject(projectToAdd);
}
}

/// <summary>
/// Updates the list of projects contained in this profile from the related <see cref="PackageProfile"/>.
/// </summary>
/// <remarks>The actions undertaken by this method are not cancellable via the action stack.</remarks>
internal bool UpdateProjectList()
{
bool changed = false;
foreach (var projectReference in profile.ProjectReferences.Where(x => Projects.All(y => y.Id != x.Id)))

if (Package.Package.ProjectFullPath != null && Projects.Count == 0)
{
var viewModel = new ProjectViewModel(projectReference, this);
Projects.Add(viewModel);
Projects.Add(new ProjectViewModel(this));
changed = true;
}

// Remove projects deleted
var projectsToRemove = Projects.Where(projectViewModel => profile.ProjectReferences.All(projectReference => projectReference.Id != projectViewModel.Id)).ToList();
foreach (var projectToRemove in projectsToRemove)
if (Package.Package.ProjectFullPath == null && Projects.Count != 0)
{
projectToRemove.Delete();
Projects[0].Delete();
changed = true;
}

return changed;
}
}
@@ -14,30 +14,29 @@ namespace Xenko.Core.Assets.Editor.ViewModel
// TODO: For the moment we consider that a project has only a single parent profile. Sharing project in several profile is not supported.
public class ProjectViewModel : MountPointViewModel, IComparable<ProjectViewModel>
{
private readonly ProjectReference project;
private readonly Package package;
private bool isCurrentProject;

public ProjectViewModel(ProjectReference project, ProfileViewModel container)
public ProjectViewModel(ProfileViewModel container)
: base(container.SafeArgument(nameof(container)).Package)
{
if (project == null) throw new ArgumentNullException(nameof(project));
if (container == null) throw new ArgumentNullException(nameof(container));
Profile = container;
this.project = project;
this.package = container.Package.Package;

// Use the property in order to create an action item
InitialUndelete(false);
}

public override string Name { get { return project.Location.GetFileNameWithoutExtension(); } set { if (value != Name) throw new InvalidOperationException("The name of a project cannot be set"); } }
public override string Name { get { return package.ProjectFullPath.GetFileNameWithoutExtension(); } set { if (value != Name) throw new InvalidOperationException("The name of a project cannot be set"); } }

public override string Path => Name + Separator;

public Guid Id => project.Id;
public Guid Id => package.Id;

public UFile ProjectPath => project.Location;
public UFile ProjectPath => package.ProjectFullPath;

public ProjectType Type => project.Type;
public ProjectType Type => package.ProjectType.Value;

/// <summary>
/// Gets the generic type (either PlatformType or ProjectType)
@@ -84,7 +83,6 @@ public override bool CanDelete(out string error)

public override void Delete()
{
IsDeleted = true;
}

public override bool AcceptAssetType(Type assetType)
@@ -94,14 +92,6 @@ public override bool AcceptAssetType(Type assetType)

protected override void UpdateIsDeletedStatus()
{
if (IsDeleted)
{
Profile.DeleteProject(project);
}
else
{
Profile.AddProject(this, project);
}
}
}
}
@@ -34,7 +34,7 @@ public override void Run(ILogger log)
if (package.State < PackageState.AssetsReady)
continue;

var hasGameExecutable = package.Profile.ProjectReferences.Any(projectRef => projectRef.Type == ProjectType.Executable);
var hasGameExecutable = package.ProjectFullPath != null && package.ProjectType == ProjectType.Executable;
if (!hasGameExecutable)
{
continue;
@@ -157,11 +157,10 @@ public static void SetPlatformOrientation(Package package, PlatformType platform
break;
case PlatformType.iOS:
{
var exeProjectLocation = profile.ProjectReferences.FirstOrDefault(x => x.Type == ProjectType.Executable);
var exeProjectLocation = package.ProjectFullPath;
if (exeProjectLocation == null) return;

var path = exeProjectLocation.Location;
var plistFile = UPath.Combine(path.GetFullDirectory(), new UFile("Info.plist"));
var plistFile = UPath.Combine(exeProjectLocation.GetFullDirectory(), new UFile("Info.plist"));
if (!File.Exists(plistFile)) return;

var xmlDoc = XDocument.Load(plistFile);

0 comments on commit 62266f4

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