diff --git a/Editor/Manifest/Dependency.cs b/Editor/Manifest/Dependency.cs
index 432f826..9d46ef9 100644
--- a/Editor/Manifest/Dependency.cs
+++ b/Editor/Manifest/Dependency.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
namespace StansAssets.Foundation.Editor
{
@@ -8,15 +9,41 @@ namespace StansAssets.Foundation.Editor
public class Dependency
{
///
- /// The dependency name.
+ /// The name.
///
public string Name { get; }
///
- /// The dependency version.
+ /// The version.
///
public string Version { get; private set; }
+ ///
+ /// `true` if the has ; otherwise, `false`.
+ ///
+ public bool HasSemanticVersion { get; private set; }
+
+ ///
+ /// The semantic version.
+ ///
+ public SemanticVersion SemanticVersion { get; private set; }
+
+ ///
+ /// Initializes a new instance of the class with provided properties.
+ ///
+ /// full name which contains name and version (e.g. 'com.company.package@1.0.0').
+ public Dependency(string fullName)
+ {
+ if (TryGetNameAndVersion(fullName, out string name, out string version))
+ {
+ Name = name;
+ Version = version;
+ TryAssignSemanticVersion();
+ }
+ else
+ throw new ArgumentException("Dependency fullName has wrong format");
+ }
+
///
/// Initializes a new instance of the class with provided properties.
///
@@ -26,6 +53,27 @@ public Dependency(string name, string version)
{
Name = name;
Version = version;
+ TryAssignSemanticVersion();
+ }
+
+ internal static bool TryGetNameAndVersion(string fullName, out string name, out string version)
+ {
+ name = version = null;
+ var dependencyData = fullName.Split('@');
+ if (dependencyData.Length == 2)
+ {
+ name = dependencyData[0];
+ version = dependencyData[1];
+ return true;
+ }
+ return false;
+ }
+
+ void TryAssignSemanticVersion()
+ {
+ HasSemanticVersion = SemanticVersion.TryCreateSemanticVersion(Version, out var semanticVersion);
+ if (HasSemanticVersion)
+ SemanticVersion = semanticVersion;
}
///
@@ -35,6 +83,7 @@ public Dependency(string name, string version)
public void SetVersion(string version)
{
Version = version;
+ TryAssignSemanticVersion();
}
///
diff --git a/Editor/Manifest/Manifest.cs b/Editor/Manifest/Manifest.cs
index becf9af..b7c2b2d 100644
--- a/Editor/Manifest/Manifest.cs
+++ b/Editor/Manifest/Manifest.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
@@ -68,6 +69,48 @@ public void Fetch()
}
}
+ ///
+ /// Gets the associated with the specified name.
+ ///
+ /// The name of the to get.
+ /// When this method returns, contains the associated with the specified name,
+ /// if the name is found; otherwise, `null`. This parameter is passed uninitialized.
+ /// true if the contains a with the specified name; otherwise, false.
+ public bool TryGetDependency(string name, out Dependency dependency)
+ {
+ return m_Dependencies.TryGetValue(name, out dependency);
+ }
+
+ ///
+ /// Gets the associated with the specified url.
+ ///
+ /// The url of the to get.
+ /// When this method returns, contains the associated with the specified url,
+ /// if the url is found; otherwise, `null`. This parameter is passed uninitialized.
+ /// true if the contains a with the specified url; otherwise, false.
+ public bool TryGetScopeRegistry(string url, out ScopeRegistry registry)
+ {
+ return m_ScopeRegistries.TryGetValue(url, out registry);
+ }
+
+ ///
+ /// Returns dependencies of the manifest.
+ ///
+ /// Dependencies of the manifest.
+ public IEnumerable GetDependencies()
+ {
+ return m_Dependencies.Values;
+ }
+
+ ///
+ /// Returns scope registries of the manifest.
+ ///
+ /// Scope registries of the manifest.
+ public IEnumerable GetScopeRegistries()
+ {
+ return m_ScopeRegistries.Values;
+ }
+
///
/// Returns dependency by a provided name.
///
@@ -89,29 +132,119 @@ public ScopeRegistry GetScopeRegistry(string url)
}
///
- /// Adds scope registry.
+ /// Sets by given url. If manifest already contains with given url,
+ /// existing will be overwritten.
///
- /// An entry to add.
- public void AddScopeRegistry(ScopeRegistry registry)
+ /// Scope registry url.
+ /// to set.
+ public void SetScopeRegistry(string url, ScopeRegistry registry)
{
- if (!IsRegistryExists(registry.Url))
+ m_ScopeRegistries[url] = registry;
+ }
+
+ ///
+ /// Adds with the provided properties. If manifest already contains with given url,
+ /// provided scopes will be merged with existing scopes.
+ /// Name of existing won't be updated.
+ ///
+ /// Scope registry url.
+ /// Scope registry name.
+ /// Scope registry scopes.
+ /// New with provided properties or existing with updated scopes, if
+ /// already contains with given name.
+ public ScopeRegistry AddScopeRegistry(string url, string name, IEnumerable scopes)
+ {
+ ScopeRegistry registry;
+ if (!IsScopeRegistryExists(url))
{
- m_ScopeRegistries.Add(registry.Url, registry);
+ registry = new ScopeRegistry(name, url, scopes);
+ SetScopeRegistry(url, registry);
}
+ else
+ {
+ registry = GetScopeRegistry(url);
+ foreach (var scope in scopes)
+ {
+ if (!registry.HasScope(scope))
+ {
+ registry.AddScope(scope);
+ }
+ }
+ }
+ return registry;
}
///
- /// Adds dependency.
+ /// Sets by given full name. If manifest already contains with given name, its'
+ /// s will be taken into account. with higher
+ /// will be placed into the .
+ ///
+ /// Dependency full name.
+ /// New or existing with given name.
+ /// Thrown when dependency fullName has wrong format
+ public Dependency SetOrUpdateDependency(string fullName)
+ {
+ if (Dependency.TryGetNameAndVersion(fullName, out string name, out string version))
+ {
+ return SetOrUpdateDependency(name, version);
+ }
+
+ throw new ArgumentException("Dependency fullName has wrong format");
+ }
+
+ ///
+ /// Sets by given name. If manifest already contains with given name, its'
+ /// s will be taken into account. with higher
+ /// will be placed into the .
///
/// Dependency name.
- /// Dependency version.
- public void AddDependency(string name, string version)
+ /// Dependency name.
+ /// New or existing with given name.
+ public Dependency SetOrUpdateDependency(string name, string version)
{
- if (!IsDependencyExists(name))
+ if (IsDependencyExists(name))
{
- var dependency = new Dependency(name, version);
- m_Dependencies.Add(dependency.Name, dependency);
+ var newDependency = new Dependency(name, version);
+ var existingDependency = GetDependency(name);
+ // We have to be sure that both Dependencies have Semantic Version
+ if (newDependency.HasSemanticVersion && existingDependency.HasSemanticVersion)
+ {
+ if (newDependency.SemanticVersion > existingDependency.SemanticVersion)
+ {
+ // Set new Dependency because it has higher Semantic Version
+ SetDependency(name, version);
+ }
+ }
+ else
+ SetDependency(name, version);
}
+ else
+ SetDependency(name, version);
+
+ return GetDependency(name);
+ }
+
+ ///
+ /// Sets by given full name. If manifest already contains with given name,
+ /// existing will be overwritten.
+ ///
+ /// Dependency full name.
+ public void SetDependency(string fullName)
+ {
+ var dependency = new Dependency(fullName);
+ m_Dependencies[dependency.Name] = dependency;
+ }
+
+ ///
+ /// Sets by given name. If manifest already contains with given name,
+ /// existing will be overwritten.
+ ///
+ /// Dependency name.
+ /// Dependency version.
+ public void SetDependency(string name, string version)
+ {
+ var dependency = new Dependency(name, version);
+ m_Dependencies[dependency.Name] = dependency;
}
///
@@ -147,7 +280,7 @@ public void ApplyChanges()
///
/// ScopeRegistry url to search for.
/// `true` if scoped registry found, `false` otherwise.
- public bool IsRegistryExists(string url)
+ public bool IsScopeRegistryExists(string url)
{
return m_ScopeRegistries.ContainsKey(url);
}
diff --git a/Editor/Manifest/ScopeRegistry.cs b/Editor/Manifest/ScopeRegistry.cs
index 15e522c..18a4bbb 100644
--- a/Editor/Manifest/ScopeRegistry.cs
+++ b/Editor/Manifest/ScopeRegistry.cs
@@ -25,7 +25,9 @@ public class ScopeRegistry
///
/// Registry scopes.
///
- public HashSet Scopes { get; }
+ public IEnumerable Scopes => m_Scopes;
+
+ readonly HashSet m_Scopes;
///
/// Initializes a new instance of class with the provided properties.
@@ -33,27 +35,26 @@ public class ScopeRegistry
/// Name of new scope registry.
/// Url of new scope registry.
/// Scopes of new scope registry.
- public ScopeRegistry(string name, string url, HashSet scopes)
+ public ScopeRegistry(string name, string url, IEnumerable scopes)
{
Name = name;
Url = url;
- Scopes = scopes;
+ m_Scopes = new HashSet(scopes);
}
///
/// Initializes a new instance of class with the provided data.
///
- /// Data to fill this object. Must contain name,
- /// url and scopes.
+ /// Data to fill this object. Must contain name, url and scopes.
public ScopeRegistry(Dictionary dictionary)
{
Name = (string) dictionary[k_KeyName];
Url = (string) dictionary[k_KeyUrl];
var scopes = (List