From c966a6b25a5e4fc87a2c6661dd6d838d4673767d Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Thu, 18 Mar 2021 15:58:43 -0400 Subject: [PATCH 01/18] First pass - deal with packages with different versions at load time. --- src/DynamoPackages/PackageLoader.cs | 41 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index eac5ab32d3d..d41ccc13578 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -276,6 +276,7 @@ public void Load(Package package) public void LoadAll(LoadPackageParams loadPackageParams) { ScanAllPackageDirectories(loadPackageParams.Preferences); + return; var pathManager = loadPackageParams.PathManager; if (pathManager != null) @@ -421,13 +422,47 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) CheckPackageNodeLibraryCertificates(directory, discoveredPkg); } - // prevent duplicates - if (LocalPackages.All(pkg => pkg.Name != discoveredPkg.Name)) + var dupePackage = LocalPackages.FirstOrDefault(pkg => pkg.Name == discoveredPkg.Name); + + // Is this a duplicate? + if (dupePackage == null) { + // No Add(discoveredPkg); return discoveredPkg; // success } - throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); + + var existingVersion = new Version(dupePackage.VersionName); + var newVersion = new Version(discoveredPkg.VersionName); + + // Check version on the duplicate + if (existingVersion == newVersion) + { + // Duplicate with the same version + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); + } + + // Is the existing version newer? + if (existingVersion > newVersion) + { + // New version exist + throw new LibraryLoadFailedException(directory, + String.Format( + "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", + discoveredPkg.Name, discoveredPkg.RootDirectory, existingVersion.ToString(), + newVersion.ToString())); + } + + // Older version exist, replace with newer version + Remove(dupePackage); + Add(discoveredPkg); + + throw new LibraryLoadFailedException(directory, + String.Format( + "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", + dupePackage.Name, dupePackage.RootDirectory, newVersion.ToString(), + existingVersion.ToString())); + } catch (Exception e) { From 4a9601a5bf236222f587101e2b0e6a70956d4de6 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Thu, 18 Mar 2021 16:05:25 -0400 Subject: [PATCH 02/18] Remove debugging code. --- src/DynamoPackages/PackageLoader.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index d41ccc13578..95c4b605884 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -276,7 +276,6 @@ public void Load(Package package) public void LoadAll(LoadPackageParams loadPackageParams) { ScanAllPackageDirectories(loadPackageParams.Preferences); - return; var pathManager = loadPackageParams.PathManager; if (pathManager != null) From 82f1f40c00b2febe1f326b5bdc46fa17d65f9d96 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Thu, 18 Mar 2021 16:09:02 -0400 Subject: [PATCH 03/18] Cleanup code. --- src/DynamoPackages/PackageLoader.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 95c4b605884..6fdba7bbbc3 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -421,30 +421,30 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) CheckPackageNodeLibraryCertificates(directory, discoveredPkg); } - var dupePackage = LocalPackages.FirstOrDefault(pkg => pkg.Name == discoveredPkg.Name); + var existingPackage = LocalPackages.FirstOrDefault(pkg => pkg.Name == discoveredPkg.Name); - // Is this a duplicate? - if (dupePackage == null) + // Is this a new package? + if (existingPackage == null) { - // No + // Yes Add(discoveredPkg); return discoveredPkg; // success } - var existingVersion = new Version(dupePackage.VersionName); + var existingVersion = new Version(existingPackage.VersionName); var newVersion = new Version(discoveredPkg.VersionName); - // Check version on the duplicate + // Is this a duplicated package? if (existingVersion == newVersion) { - // Duplicate with the same version + // Duplicated with the same version throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); } // Is the existing version newer? if (existingVersion > newVersion) { - // New version exist + // Newer version already exist throw new LibraryLoadFailedException(directory, String.Format( "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", @@ -453,13 +453,13 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) } // Older version exist, replace with newer version - Remove(dupePackage); + Remove(existingPackage); Add(discoveredPkg); throw new LibraryLoadFailedException(directory, String.Format( "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", - dupePackage.Name, dupePackage.RootDirectory, newVersion.ToString(), + existingPackage.Name, existingPackage.RootDirectory, newVersion.ToString(), existingVersion.ToString())); } From c53b46faa94d60bc4f8da5ceb37f059d3f26a9b7 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 19 Mar 2021 09:59:33 -0400 Subject: [PATCH 04/18] Log only when packages have version mismatches. --- src/DynamoPackages/PackageLoader.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 6fdba7bbbc3..802edb3325b 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -445,23 +445,24 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) if (existingVersion > newVersion) { // Newer version already exist - throw new LibraryLoadFailedException(directory, - String.Format( - "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", - discoveredPkg.Name, discoveredPkg.RootDirectory, existingVersion.ToString(), - newVersion.ToString())); + Log(String.Format( + "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", + discoveredPkg.Name, discoveredPkg.RootDirectory, existingVersion.ToString(), + newVersion.ToString()), WarningLevel.Moderate); + + return null; } // Older version exist, replace with newer version Remove(existingPackage); Add(discoveredPkg); - throw new LibraryLoadFailedException(directory, - String.Format( - "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", - existingPackage.Name, existingPackage.RootDirectory, newVersion.ToString(), - existingVersion.ToString())); + Log(String.Format( + "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", + existingPackage.Name, existingPackage.RootDirectory, newVersion.ToString(), + existingVersion.ToString()), WarningLevel.Moderate); + return discoveredPkg; } catch (Exception e) { From b26a8602f9a527e3df8d7d0327c390cf05dfc6fc Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 19 Mar 2021 10:46:16 -0400 Subject: [PATCH 05/18] Add version validation --- src/DynamoPackages/PackageLoader.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 802edb3325b..987a1b03dc7 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -431,8 +431,11 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) return discoveredPkg; // success } - var existingVersion = new Version(existingPackage.VersionName); - var newVersion = new Version(discoveredPkg.VersionName); + var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, + existingPackage.RootDirectory); + + var newVersion = CheckAndGetPackageVersion(discoveredPkg.VersionName, discoveredPkg.Name, + discoveredPkg.RootDirectory); // Is this a duplicated package? if (existingVersion == newVersion) @@ -473,6 +476,27 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) return null; } + /// + /// Check and get the version from the version string. Throw a libray load expection if anything is wrong with the version + /// + /// the version string + /// name of the package + /// package directory + /// Returns a valid Version + private Version CheckAndGetPackageVersion(string version, string name, string directory) + { + try + { + return new Version(version); + } + catch (Exception e) when (e is ArgumentException || e is FormatException || e is OverflowException) + { + throw new LibraryLoadFailedException(directory, String.Format( + "The version of the package called {0} found at {1} is invalid (version: \"{2}\"). Ignoring it.", + name, directory, version)); + } + } + /// /// Check the node libraries defined in the package json file are valid and have a valid certificate /// From d8d32a4a4df2bec203023e95b4e3d9ec372d712f Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 19 Mar 2021 13:51:00 -0400 Subject: [PATCH 06/18] Move strings to resources plus renaming a few variables. --- .../Properties/Resources.Designer.cs | 18 ++++++++ .../Properties/Resources.en-US.resx | 6 +++ src/DynamoCore/Properties/Resources.resx | 6 +++ src/DynamoPackages/PackageLoader.cs | 43 ++++++++----------- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs index e24b4c4b8ef..8caf4d47e9a 100644 --- a/src/DynamoCore/Properties/Resources.Designer.cs +++ b/src/DynamoCore/Properties/Resources.Designer.cs @@ -450,6 +450,15 @@ public static string DuplicatedModelGuidError { } } + /// + /// Looks up a localized string similar to An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.. + /// + public static string DuplicatedOlderPackage { + get { + return ResourceManager.GetString("DuplicatedOlderPackage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Duplicate migration type registered for {0}. /// @@ -836,6 +845,15 @@ public static string InvalidLibraryFormat { } } + /// + /// Looks up a localized string similar to The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it.. + /// + public static string InvalidPackageVersion { + get { + return ResourceManager.GetString("InvalidPackageVersion", resourceCulture); + } + } + /// /// Looks up a localized string similar to The start or end of a range is greater than the number of available elements in the list.. /// diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx index 751bda2b600..402eb236dba 100644 --- a/src/DynamoCore/Properties/Resources.en-US.resx +++ b/src/DynamoCore/Properties/Resources.en-US.resx @@ -735,4 +735,10 @@ Parameter name: {0} The current user, '{0}', is not a maintainer of the package '{1}'. {0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x') + + An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it. + + + The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. + \ No newline at end of file diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx index 91e0ec39974..4bebd137807 100644 --- a/src/DynamoCore/Properties/Resources.resx +++ b/src/DynamoCore/Properties/Resources.resx @@ -735,4 +735,10 @@ Parameter name: {0} The current user, '{0}', is not a maintainer of the package '{1}'. {0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x') + + An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it. + + + The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. + \ No newline at end of file diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 987a1b03dc7..e094df34bad 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -401,13 +401,13 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) { var headerPath = Path.Combine(directory, "pkg.json"); - Package discoveredPkg; + Package discoveredPackage; // get the package name and the installed version if (PathHelper.IsValidPath(headerPath)) { - discoveredPkg = Package.FromJson(headerPath, AsLogger()); - if (discoveredPkg == null) + discoveredPackage = Package.FromJson(headerPath, AsLogger()); + if (discoveredPackage == null) throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.MalformedHeaderPackage, headerPath)); } else @@ -418,54 +418,45 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) // prevent loading unsigned packages if the certificates are required on package dlls if (checkCertificates) { - CheckPackageNodeLibraryCertificates(directory, discoveredPkg); + CheckPackageNodeLibraryCertificates(directory, discoveredPackage); } - var existingPackage = LocalPackages.FirstOrDefault(pkg => pkg.Name == discoveredPkg.Name); + var existingPackage = LocalPackages.FirstOrDefault(package => package.Name == discoveredPackage.Name); // Is this a new package? if (existingPackage == null) { // Yes - Add(discoveredPkg); - return discoveredPkg; // success + Add(discoveredPackage); + return discoveredPackage; // success } - var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, - existingPackage.RootDirectory); + var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, existingPackage.RootDirectory); - var newVersion = CheckAndGetPackageVersion(discoveredPkg.VersionName, discoveredPkg.Name, - discoveredPkg.RootDirectory); + var discoveredVersion = CheckAndGetPackageVersion(discoveredPackage.VersionName, discoveredPackage.Name, discoveredPackage.RootDirectory); // Is this a duplicated package? - if (existingVersion == newVersion) + if (existingVersion == discoveredVersion) { // Duplicated with the same version - throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPkg.Name, discoveredPkg.RootDirectory)); + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPackage.Name, discoveredPackage.RootDirectory)); } // Is the existing version newer? - if (existingVersion > newVersion) + if (existingVersion > discoveredVersion) { // Newer version already exist - Log(String.Format( - "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", - discoveredPkg.Name, discoveredPkg.RootDirectory, existingVersion.ToString(), - newVersion.ToString()), WarningLevel.Moderate); - + Log(String.Format(Properties.Resources.DuplicatedOlderPackage, discoveredPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString()), WarningLevel.Moderate); return null; } // Older version exist, replace with newer version Remove(existingPackage); - Add(discoveredPkg); + Add(discoveredPackage); - Log(String.Format( - "An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.", - existingPackage.Name, existingPackage.RootDirectory, newVersion.ToString(), - existingVersion.ToString()), WarningLevel.Moderate); + Log(String.Format(Properties.Resources.DuplicatedOlderPackage, existingPackage.Name, existingPackage.RootDirectory, discoveredVersion.ToString(), existingVersion.ToString()), WarningLevel.Moderate); - return discoveredPkg; + return discoveredPackage; } catch (Exception e) { @@ -492,7 +483,7 @@ private Version CheckAndGetPackageVersion(string version, string name, string di catch (Exception e) when (e is ArgumentException || e is FormatException || e is OverflowException) { throw new LibraryLoadFailedException(directory, String.Format( - "The version of the package called {0} found at {1} is invalid (version: \"{2}\"). Ignoring it.", + Properties.Resources.InvalidPackageVersion, name, directory, version)); } } From cff784654790a067b8a526d36d8905adda23dc6a Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Fri, 19 Mar 2021 13:56:50 -0400 Subject: [PATCH 07/18] Cleanup code --- src/DynamoPackages/PackageLoader.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index e094df34bad..1107a3207f2 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -482,9 +482,7 @@ private Version CheckAndGetPackageVersion(string version, string name, string di } catch (Exception e) when (e is ArgumentException || e is FormatException || e is OverflowException) { - throw new LibraryLoadFailedException(directory, String.Format( - Properties.Resources.InvalidPackageVersion, - name, directory, version)); + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.InvalidPackageVersion, name, directory, version)); } } From f01e2289f53e2b4828bd3931294eb0eceeb44d0c Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Mon, 22 Mar 2021 16:48:15 -0400 Subject: [PATCH 08/18] Add tests --- src/DynamoPackages/PackageLoader.cs | 4 +- .../PackageManagerTests/PackageLoaderTests.cs | 92 ++++++++++++++++++ .../PackageWithBadVersion/bin/Package.dll | Bin 0 -> 4096 bytes .../BadVersion/PackageWithBadVersion/pkg.json | 1 + .../PackageWithGoodVersion/bin/Package.dll | Bin 0 -> 4096 bytes .../PackageWithGoodVersion/pkg.json | 1 + .../PackageWithNewVersion/bin/Package.dll | Bin 0 -> 4096 bytes .../Version/PackageWithNewVersion/pkg.json | 1 + .../PackageWithOldVersion/bin/Package.dll | Bin 0 -> 4096 bytes .../Version/PackageWithOldVersion/pkg.json | 1 + 10 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/pkgs/BadVersion/PackageWithBadVersion/bin/Package.dll create mode 100644 test/pkgs/BadVersion/PackageWithBadVersion/pkg.json create mode 100644 test/pkgs/BadVersion/PackageWithGoodVersion/bin/Package.dll create mode 100644 test/pkgs/BadVersion/PackageWithGoodVersion/pkg.json create mode 100644 test/pkgs/Version/PackageWithNewVersion/bin/Package.dll create mode 100644 test/pkgs/Version/PackageWithNewVersion/pkg.json create mode 100644 test/pkgs/Version/PackageWithOldVersion/bin/Package.dll create mode 100644 test/pkgs/Version/PackageWithOldVersion/pkg.json diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 1107a3207f2..c944d80b10b 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -421,6 +421,8 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) CheckPackageNodeLibraryCertificates(directory, discoveredPackage); } + var discoveredVersion = CheckAndGetPackageVersion(discoveredPackage.VersionName, discoveredPackage.Name, discoveredPackage.RootDirectory); + var existingPackage = LocalPackages.FirstOrDefault(package => package.Name == discoveredPackage.Name); // Is this a new package? @@ -433,8 +435,6 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) var existingVersion = CheckAndGetPackageVersion(existingPackage.VersionName, existingPackage.Name, existingPackage.RootDirectory); - var discoveredVersion = CheckAndGetPackageVersion(discoveredPackage.VersionName, discoveredPackage.Name, discoveredPackage.RootDirectory); - // Is this a duplicated package? if (existingVersion == discoveredVersion) { diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index beee97e7782..b0f645a828e 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -658,6 +658,98 @@ public void HasValidStandardLibraryPath() Assert.AreEqual(standardDirectory, directory); } + [Test] + public void PackageLoaderLoadPackageWithBadVersion() + { + // Arrange + var loader = GetPackageLoader(); + var badPackageLocation = Path.Combine(PackagesDirectory, @"BadVersion\PackageWithBadVersion"); + + // Act + var badPackage = loader.ScanPackageDirectory(badPackageLocation); + + // Assert + Assert.IsNull(badPackage); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Bad package")); + } + + [Test] + public void PackageLoaderLoadMultiplePackagesWithBadVersion() + { + // Arrange + var loader = GetPackageLoader(); + var goodPackageLocation = Path.Combine(PackagesDirectory, @"BadVersion\PackageWithGoodVersion"); + var badPackageLocation = Path.Combine(PackagesDirectory, @"BadVersion\PackageWithBadVersion"); + + // Act + var goodPackage = loader.ScanPackageDirectory(goodPackageLocation); + var badPackage = loader.ScanPackageDirectory(badPackageLocation); + + // Assert + Assert.IsNotNull(goodPackage); + Assert.IsNull(badPackage); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Good package")); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Bad package")); + } + + [Test] + public void PackageLoaderLoadMultiplePackagesWithBadVersionReversed() + { + // Arrange + var loader = GetPackageLoader(); + var goodPackageLocation = Path.Combine(PackagesDirectory, @"BadVersion\PackageWithGoodVersion"); + var badPackageLocation = Path.Combine(PackagesDirectory, @"BadVersion\PackageWithBadVersion"); + + // Act + var badPackage = loader.ScanPackageDirectory(badPackageLocation); + var goodPackage = loader.ScanPackageDirectory(goodPackageLocation); + + // Assert + Assert.IsNotNull(goodPackage); + Assert.IsNull(badPackage); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Good package")); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Bad package")); + } + + + [Test] + public void PackageLoaderLoadNewPackage() + { + // Arrange + var loader = GetPackageLoader(); + var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); + var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); + + // Act + var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); + var newPackage = loader.ScanPackageDirectory(newPackageLocation); + + // Assert + Assert.IsNotNull(oldPackage); + Assert.IsNotNull(newPackage); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); + } + + [Test] + public void PackageLoaderLoadOldPackage() + { + // Arrange + var loader = GetPackageLoader(); + var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); + var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); + + // Act + var newPackage = loader.ScanPackageDirectory(newPackageLocation); + var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); + + // Assert + Assert.IsNull(oldPackage); + Assert.IsNotNull(newPackage); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); + } + [Test] public void IsUnderPackageControlIsCorrectForValidFunctionDefinition() { diff --git a/test/pkgs/BadVersion/PackageWithBadVersion/bin/Package.dll b/test/pkgs/BadVersion/PackageWithBadVersion/bin/Package.dll new file mode 100644 index 0000000000000000000000000000000000000000..58050bf72fc19d52531dcabdebf0b36eef896704 GIT binary patch literal 4096 zcmeHKU2GIp6h5>4p_Ec61>`54Q~cj;=Wif-F&X|=SaTPn&XbawZ$9hjXNXJ(;m zjH!wm-i-0V7!w~%On8teF%gYF2?;UL;G4$yV2Dq?C_dD#aUfFz68NRZ4V%qRj$F=jW zUQn~TW!b)(5vp6XRKrq}qbapu=Y+O=dE?fy>#=^KVWo!l{V;>s1Gq|C)MZMPr~!0+ zz>Dlauc9T;h*rvRB#4_CWi_H%5a2V^(A2Z6%71fxnPe8={C1*I9wdmSxeyCsil_;^ zpSBV0TPV93tp?$TDh;3qLjt|#iy0q%!xA8s2WaKEF_NGXO=+&@WD>&}my{QL#m9lq^^;BGoYMs%}ST|2rM<(zGFl&2~XeV-rqqU`c*Rb*) zYow7sFK64~6q(`pz~P}Jcu#1X;~si%y>co%)9tf1RrT2F`QO>n-F_&te-6y~gvSd(~K^7qp>;BS=p zRmpjVX2EHXydftEX5zXi$gUN?9yuOUIg;n-V`T^Ed_b+c3`+$WT}Fg0!1c5qxDl~k zR#s9>;%WrzGd7#94YCoRjo6uty)!2CAJ6s!J7U#RyAQflbvL`@VyAu4sz;so-U8 z*EBLTre{y;c|iw?My|)lmdF%+K}nG*=JR^S6mz^jyD({Z#ynn+=ZQkbEKL}GwQ7a! z>N!!+-IH@(CUiG1`~h5L;^L2 zN}ewYT3Jaer-@S-E`ydcO$xNioi;9xnBLIyP-5`=y}Wbd?V|HtkCiPGHg?&Imn_3^7`q0o$LgfC>GO?)ILB5NOZ zb!Wu3`e(92F51MjYoGQM=q-_lw+VxAgHoMj-KNm0%7Unu&Z+9&C|`5C6x!O|wKsm( z@w?+4v3(-m5%27bb#!-kWji`EA|CG&@oqiFmpPoqa6jTlG^Ef5ZKQvqvLV~ci?Sbg zXcvNPUR@C-4bL(4(g?QhDz;H85*50f*KaQ$dXam+1D{4~$2-s-q|9sy^4Sat^y8^y z>dw!{E`0a($l#fm+J*;?p1;PK_T7^{?BN`w9qe}9(Y2mrDxI{m#e%SWFO8#E)J-+z z7juTqHRwuX1M`x3>7;Okm4jNjcImLUGbbR#(GEG9lgrST<=2XX`jN*fj}}Atss)l` zeYTr4&4apO1-FS1a`y((>)YUEVXBK={wFy6`Vg%PzM`r!=0iY)O*mV{#E`kcx5JSH zwrhe`FtBXFYz4k}-s~h@!pzMm@2i~LAkOZN? zt4=Qb7&z|&J}o+4KKEPYt1fAzNMQl~wQ^*#NCD@+3TXl$CKf^Wq$XT^4Vs zj_3r8qx0-0!E<3bmsbpLZM4$(d$kGkaAka{Yr&IQ70rDA8s#A6@2^2x1-oI`QG5Wn5SuY!iQ|TNIl1h6KLyY)yZa2JC`w3Pg2fqdQb&*+EHKK%!b+kMOuL#E) z)`%&tG|^wh9MonE_BQe;qHcawrVH)xT`6lhUw>gm7uS>5tp`ziGKUNzEFt5+vqRXo WE~vr(47KuAxOKz)KeB(P0)GObpg=GH literal 0 HcmV?d00001 diff --git a/test/pkgs/BadVersion/PackageWithBadVersion/pkg.json b/test/pkgs/BadVersion/PackageWithBadVersion/pkg.json new file mode 100644 index 00000000000..7a1ce82d993 --- /dev/null +++ b/test/pkgs/BadVersion/PackageWithBadVersion/pkg.json @@ -0,0 +1 @@ +{"license":"","file_hash":null,"name":"Package","version":"","description":"Bad package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]} \ No newline at end of file diff --git a/test/pkgs/BadVersion/PackageWithGoodVersion/bin/Package.dll b/test/pkgs/BadVersion/PackageWithGoodVersion/bin/Package.dll new file mode 100644 index 0000000000000000000000000000000000000000..58050bf72fc19d52531dcabdebf0b36eef896704 GIT binary patch literal 4096 zcmeHKU2GIp6h5>4p_Ec61>`54Q~cj;=Wif-F&X|=SaTPn&XbawZ$9hjXNXJ(;m zjH!wm-i-0V7!w~%On8teF%gYF2?;UL;G4$yV2Dq?C_dD#aUfFz68NRZ4V%qRj$F=jW zUQn~TW!b)(5vp6XRKrq}qbapu=Y+O=dE?fy>#=^KVWo!l{V;>s1Gq|C)MZMPr~!0+ zz>Dlauc9T;h*rvRB#4_CWi_H%5a2V^(A2Z6%71fxnPe8={C1*I9wdmSxeyCsil_;^ zpSBV0TPV93tp?$TDh;3qLjt|#iy0q%!xA8s2WaKEF_NGXO=+&@WD>&}my{QL#m9lq^^;BGoYMs%}ST|2rM<(zGFl&2~XeV-rqqU`c*Rb*) zYow7sFK64~6q(`pz~P}Jcu#1X;~si%y>co%)9tf1RrT2F`QO>n-F_&te-6y~gvSd(~K^7qp>;BS=p zRmpjVX2EHXydftEX5zXi$gUN?9yuOUIg;n-V`T^Ed_b+c3`+$WT}Fg0!1c5qxDl~k zR#s9>;%WrzGd7#94YCoRjo6uty)!2CAJ6s!J7U#RyAQflbvL`@VyAu4sz;so-U8 z*EBLTre{y;c|iw?My|)lmdF%+K}nG*=JR^S6mz^jyD({Z#ynn+=ZQkbEKL}GwQ7a! z>N!!+-IH@(CUiG1`~h5L;^L2 zN}ewYT3Jaer-@S-E`ydcO$xNioi;9xnBLIyP-5`=y}Wbd?V|HtkCiPGHg?&Imn_3^7`q0o$LgfC>GO?)ILB5NOZ zb!Wu3`e(92F51MjYoGQM=q-_lw+VxAgHoMj-KNm0%7Unu&Z+9&C|`5C6x!O|wKsm( z@w?+4v3(-m5%27bb#!-kWji`EA|CG&@oqiFmpPoqa6jTlG^Ef5ZKQvqvLV~ci?Sbg zXcvNPUR@C-4bL(4(g?QhDz;H85*50f*KaQ$dXam+1D{4~$2-s-q|9sy^4Sat^y8^y z>dw!{E`0a($l#fm+J*;?p1;PK_T7^{?BN`w9qe}9(Y2mrDxI{m#e%SWFO8#E)J-+z z7juTqHRwuX1M`x3>7;Okm4jNjcImLUGbbR#(GEG9lgrST<=2XX`jN*fj}}Atss)l` zeYTr4&4apO1-FS1a`y((>)YUEVXBK={wFy6`Vg%PzM`r!=0iY)O*mV{#E`kcx5JSH zwrhe`FtBXFYz4k}-s~h@!pzMm@2i~LAkOZN? zt4=Qb7&z|&J}o+4KKEPYt1fAzNMQl~wQ^*#NCD@+3TXl$CKf^Wq$XT^4Vs zj_3r8qx0-0!E<3bmsbpLZM4$(d$kGkaAka{Yr&IQ70rDA8s#A6@2^2x1-oI`QG5Wn5SuY!iQ|TNIl1h6KLyY)yZa2JC`w3Pg2fqdQb&*+EHKK%!b+kMOuL#E) z)`%&tG|^wh9MonE_BQe;qHcawrVH)xT`6lhUw>gm7uS>5tp`ziGKUNzEFt5+vqRXo WE~vr(47KuAxOKz)KeB(P0)GObpg=GH literal 0 HcmV?d00001 diff --git a/test/pkgs/BadVersion/PackageWithGoodVersion/pkg.json b/test/pkgs/BadVersion/PackageWithGoodVersion/pkg.json new file mode 100644 index 00000000000..2a64e3cd73c --- /dev/null +++ b/test/pkgs/BadVersion/PackageWithGoodVersion/pkg.json @@ -0,0 +1 @@ +{"license":"","file_hash":null,"name":"Package","version":"1.0.0","description":"Good package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]} \ No newline at end of file diff --git a/test/pkgs/Version/PackageWithNewVersion/bin/Package.dll b/test/pkgs/Version/PackageWithNewVersion/bin/Package.dll new file mode 100644 index 0000000000000000000000000000000000000000..58050bf72fc19d52531dcabdebf0b36eef896704 GIT binary patch literal 4096 zcmeHKU2GIp6h5>4p_Ec61>`54Q~cj;=Wif-F&X|=SaTPn&XbawZ$9hjXNXJ(;m zjH!wm-i-0V7!w~%On8teF%gYF2?;UL;G4$yV2Dq?C_dD#aUfFz68NRZ4V%qRj$F=jW zUQn~TW!b)(5vp6XRKrq}qbapu=Y+O=dE?fy>#=^KVWo!l{V;>s1Gq|C)MZMPr~!0+ zz>Dlauc9T;h*rvRB#4_CWi_H%5a2V^(A2Z6%71fxnPe8={C1*I9wdmSxeyCsil_;^ zpSBV0TPV93tp?$TDh;3qLjt|#iy0q%!xA8s2WaKEF_NGXO=+&@WD>&}my{QL#m9lq^^;BGoYMs%}ST|2rM<(zGFl&2~XeV-rqqU`c*Rb*) zYow7sFK64~6q(`pz~P}Jcu#1X;~si%y>co%)9tf1RrT2F`QO>n-F_&te-6y~gvSd(~K^7qp>;BS=p zRmpjVX2EHXydftEX5zXi$gUN?9yuOUIg;n-V`T^Ed_b+c3`+$WT}Fg0!1c5qxDl~k zR#s9>;%WrzGd7#94YCoRjo6uty)!2CAJ6s!J7U#RyAQflbvL`@VyAu4sz;so-U8 z*EBLTre{y;c|iw?My|)lmdF%+K}nG*=JR^S6mz^jyD({Z#ynn+=ZQkbEKL}GwQ7a! z>N!!+-IH@(CUiG1`~h5L;^L2 zN}ewYT3Jaer-@S-E`ydcO$xNioi;9xnBLIyP-5`=y}Wbd?V|HtkCiPGHg?&Imn_3^7`q0o$LgfC>GO?)ILB5NOZ zb!Wu3`e(92F51MjYoGQM=q-_lw+VxAgHoMj-KNm0%7Unu&Z+9&C|`5C6x!O|wKsm( z@w?+4v3(-m5%27bb#!-kWji`EA|CG&@oqiFmpPoqa6jTlG^Ef5ZKQvqvLV~ci?Sbg zXcvNPUR@C-4bL(4(g?QhDz;H85*50f*KaQ$dXam+1D{4~$2-s-q|9sy^4Sat^y8^y z>dw!{E`0a($l#fm+J*;?p1;PK_T7^{?BN`w9qe}9(Y2mrDxI{m#e%SWFO8#E)J-+z z7juTqHRwuX1M`x3>7;Okm4jNjcImLUGbbR#(GEG9lgrST<=2XX`jN*fj}}Atss)l` zeYTr4&4apO1-FS1a`y((>)YUEVXBK={wFy6`Vg%PzM`r!=0iY)O*mV{#E`kcx5JSH zwrhe`FtBXFYz4k}-s~h@!pzMm@2i~LAkOZN? zt4=Qb7&z|&J}o+4KKEPYt1fAzNMQl~wQ^*#NCD@+3TXl$CKf^Wq$XT^4Vs zj_3r8qx0-0!E<3bmsbpLZM4$(d$kGkaAka{Yr&IQ70rDA8s#A6@2^2x1-oI`QG5Wn5SuY!iQ|TNIl1h6KLyY)yZa2JC`w3Pg2fqdQb&*+EHKK%!b+kMOuL#E) z)`%&tG|^wh9MonE_BQe;qHcawrVH)xT`6lhUw>gm7uS>5tp`ziGKUNzEFt5+vqRXo WE~vr(47KuAxOKz)KeB(P0)GObpg=GH literal 0 HcmV?d00001 diff --git a/test/pkgs/Version/PackageWithNewVersion/pkg.json b/test/pkgs/Version/PackageWithNewVersion/pkg.json new file mode 100644 index 00000000000..fd9318ebdd3 --- /dev/null +++ b/test/pkgs/Version/PackageWithNewVersion/pkg.json @@ -0,0 +1 @@ +{"license":"","file_hash":null,"name":"Package","version":"2.0.0","description":"New package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]} \ No newline at end of file diff --git a/test/pkgs/Version/PackageWithOldVersion/bin/Package.dll b/test/pkgs/Version/PackageWithOldVersion/bin/Package.dll new file mode 100644 index 0000000000000000000000000000000000000000..58050bf72fc19d52531dcabdebf0b36eef896704 GIT binary patch literal 4096 zcmeHKU2GIp6h5>4p_Ec61>`54Q~cj;=Wif-F&X|=SaTPn&XbawZ$9hjXNXJ(;m zjH!wm-i-0V7!w~%On8teF%gYF2?;UL;G4$yV2Dq?C_dD#aUfFz68NRZ4V%qRj$F=jW zUQn~TW!b)(5vp6XRKrq}qbapu=Y+O=dE?fy>#=^KVWo!l{V;>s1Gq|C)MZMPr~!0+ zz>Dlauc9T;h*rvRB#4_CWi_H%5a2V^(A2Z6%71fxnPe8={C1*I9wdmSxeyCsil_;^ zpSBV0TPV93tp?$TDh;3qLjt|#iy0q%!xA8s2WaKEF_NGXO=+&@WD>&}my{QL#m9lq^^;BGoYMs%}ST|2rM<(zGFl&2~XeV-rqqU`c*Rb*) zYow7sFK64~6q(`pz~P}Jcu#1X;~si%y>co%)9tf1RrT2F`QO>n-F_&te-6y~gvSd(~K^7qp>;BS=p zRmpjVX2EHXydftEX5zXi$gUN?9yuOUIg;n-V`T^Ed_b+c3`+$WT}Fg0!1c5qxDl~k zR#s9>;%WrzGd7#94YCoRjo6uty)!2CAJ6s!J7U#RyAQflbvL`@VyAu4sz;so-U8 z*EBLTre{y;c|iw?My|)lmdF%+K}nG*=JR^S6mz^jyD({Z#ynn+=ZQkbEKL}GwQ7a! z>N!!+-IH@(CUiG1`~h5L;^L2 zN}ewYT3Jaer-@S-E`ydcO$xNioi;9xnBLIyP-5`=y}Wbd?V|HtkCiPGHg?&Imn_3^7`q0o$LgfC>GO?)ILB5NOZ zb!Wu3`e(92F51MjYoGQM=q-_lw+VxAgHoMj-KNm0%7Unu&Z+9&C|`5C6x!O|wKsm( z@w?+4v3(-m5%27bb#!-kWji`EA|CG&@oqiFmpPoqa6jTlG^Ef5ZKQvqvLV~ci?Sbg zXcvNPUR@C-4bL(4(g?QhDz;H85*50f*KaQ$dXam+1D{4~$2-s-q|9sy^4Sat^y8^y z>dw!{E`0a($l#fm+J*;?p1;PK_T7^{?BN`w9qe}9(Y2mrDxI{m#e%SWFO8#E)J-+z z7juTqHRwuX1M`x3>7;Okm4jNjcImLUGbbR#(GEG9lgrST<=2XX`jN*fj}}Atss)l` zeYTr4&4apO1-FS1a`y((>)YUEVXBK={wFy6`Vg%PzM`r!=0iY)O*mV{#E`kcx5JSH zwrhe`FtBXFYz4k}-s~h@!pzMm@2i~LAkOZN? zt4=Qb7&z|&J}o+4KKEPYt1fAzNMQl~wQ^*#NCD@+3TXl$CKf^Wq$XT^4Vs zj_3r8qx0-0!E<3bmsbpLZM4$(d$kGkaAka{Yr&IQ70rDA8s#A6@2^2x1-oI`QG5Wn5SuY!iQ|TNIl1h6KLyY)yZa2JC`w3Pg2fqdQb&*+EHKK%!b+kMOuL#E) z)`%&tG|^wh9MonE_BQe;qHcawrVH)xT`6lhUw>gm7uS>5tp`ziGKUNzEFt5+vqRXo WE~vr(47KuAxOKz)KeB(P0)GObpg=GH literal 0 HcmV?d00001 diff --git a/test/pkgs/Version/PackageWithOldVersion/pkg.json b/test/pkgs/Version/PackageWithOldVersion/pkg.json new file mode 100644 index 00000000000..eebf1dbb6ce --- /dev/null +++ b/test/pkgs/Version/PackageWithOldVersion/pkg.json @@ -0,0 +1 @@ +{"license":"","file_hash":null,"name":"Package","version":"1.0.0","description":"Old package","group":"","keywords":null,"dependencies":[],"contents":"","engine_version":"2.1.0.7840","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":["Package, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"]} \ No newline at end of file From 5687a33c95bbe069cd2dd172da0ea75bbc2c3333 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 13:53:27 -0400 Subject: [PATCH 09/18] Fix spelling. --- src/DynamoPackages/PackageLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index c944d80b10b..b227dcb5b29 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -468,7 +468,7 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) } /// - /// Check and get the version from the version string. Throw a libray load expection if anything is wrong with the version + /// Check and get the version from the version string. Throw a library load exception if anything is wrong with the version /// /// the version string /// name of the package From faaee64991ba6a2f3e50572b090caab42c603b2c Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 15:28:55 -0400 Subject: [PATCH 10/18] Change wording for warning message. --- src/DynamoCore/Properties/Resources.Designer.cs | 2 +- src/DynamoCore/Properties/Resources.en-US.resx | 2 +- src/DynamoCore/Properties/Resources.resx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs index 8caf4d47e9a..681d28fc9f5 100644 --- a/src/DynamoCore/Properties/Resources.Designer.cs +++ b/src/DynamoCore/Properties/Resources.Designer.cs @@ -451,7 +451,7 @@ public static string DuplicatedModelGuidError { } /// - /// Looks up a localized string similar to An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it.. + /// Looks up a localized string similar to An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored.. /// public static string DuplicatedOlderPackage { get { diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx index 402eb236dba..d9e3c100cc2 100644 --- a/src/DynamoCore/Properties/Resources.en-US.resx +++ b/src/DynamoCore/Properties/Resources.en-US.resx @@ -736,7 +736,7 @@ Parameter name: {0} {0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x') - An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it. + An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored. The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx index 4bebd137807..f92577a7c8b 100644 --- a/src/DynamoCore/Properties/Resources.resx +++ b/src/DynamoCore/Properties/Resources.resx @@ -736,7 +736,7 @@ Parameter name: {0} {0} = user name (i.e. 'DynamoTeam'), {1} = package name (i.e. 'Clockwork for Dynamo 1.x') - An older version of the package called {0} version {2} was found at {1} with version {3}. Ignoring it. + An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored. The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. From c3c2798eef2fb5905bde53028f3a1a4d9f302c0a Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 17:14:07 -0400 Subject: [PATCH 11/18] Address review comments: Use VersionUtilities.PartialParse(). --- src/DynamoPackages/PackageLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index b227dcb5b29..3c5f87f8a88 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -478,7 +478,7 @@ private Version CheckAndGetPackageVersion(string version, string name, string di { try { - return new Version(version); + return VersionUtilities.PartialParse(version); } catch (Exception e) when (e is ArgumentException || e is FormatException || e is OverflowException) { From 630e81725e582edf62855bd72b18e4cc01f744e7 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 17:38:12 -0400 Subject: [PATCH 12/18] Enhance conflict tests. --- test/Libraries/PackageManagerTests/PackageLoaderTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index b0f645a828e..f351b0ebc6e 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -727,6 +727,10 @@ public void PackageLoaderLoadNewPackage() // Assert Assert.IsNotNull(oldPackage); Assert.IsNotNull(newPackage); + Assert.AreEqual("Package", oldPackage.Name); + Assert.AreEqual("Package", newPackage.Name); + Assert.AreEqual("1.0.0", oldPackage.VersionName); + Assert.AreEqual("2.0.0", newPackage.VersionName); Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); } @@ -746,6 +750,8 @@ public void PackageLoaderLoadOldPackage() // Assert Assert.IsNull(oldPackage); Assert.IsNotNull(newPackage); + Assert.AreEqual("Package", newPackage.Name); + Assert.AreEqual("2.0.0", newPackage.VersionName); Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); } From b340de34c0d37fd3902d5b3d93f98096cec5b957 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 18:55:50 -0400 Subject: [PATCH 13/18] Cover the case when a package has been loaded already with test cases. --- .../Properties/Resources.Designer.cs | 9 ++++ .../Properties/Resources.en-US.resx | 3 ++ src/DynamoCore/Properties/Resources.resx | 3 ++ src/DynamoPackages/PackageLoader.cs | 6 +++ .../PackageManagerTests/PackageLoaderTests.cs | 44 +++++++++++++++++++ 5 files changed, 65 insertions(+) diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs index 681d28fc9f5..7eee04eef9e 100644 --- a/src/DynamoCore/Properties/Resources.Designer.cs +++ b/src/DynamoCore/Properties/Resources.Designer.cs @@ -459,6 +459,15 @@ public static string DuplicatedOlderPackage { } } + /// + /// Looks up a localized string similar to A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package.. + /// + public static string DuplicatedPackageAlreadyLoaded { + get { + return ResourceManager.GetString("DuplicatedPackageAlreadyLoaded", resourceCulture); + } + } + /// /// Looks up a localized string similar to Duplicate migration type registered for {0}. /// diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx index d9e3c100cc2..73f40977d2b 100644 --- a/src/DynamoCore/Properties/Resources.en-US.resx +++ b/src/DynamoCore/Properties/Resources.en-US.resx @@ -741,4 +741,7 @@ Parameter name: {0} The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. + + A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package. + \ No newline at end of file diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx index f92577a7c8b..b797a7e9777 100644 --- a/src/DynamoCore/Properties/Resources.resx +++ b/src/DynamoCore/Properties/Resources.resx @@ -741,4 +741,7 @@ Parameter name: {0} The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. + + A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package. + \ No newline at end of file diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 3c5f87f8a88..f9487219066 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -450,6 +450,12 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) return null; } + // If the existing package already loaded + if (existingPackage.Loaded) + { + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedPackageAlreadyLoaded, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); + } + // Older version exist, replace with newer version Remove(existingPackage); Add(discoveredPackage); diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index f351b0ebc6e..f98975dd3f9 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -756,6 +756,50 @@ public void PackageLoaderLoadOldPackage() Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); } + [Test] + public void PackageLoaderLoadNewWhenOldPackageHasBeenLoadedAlready() + { + // Arrange + var loader = GetPackageLoader(); + var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); + var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); + + // Act + var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); + oldPackage.Loaded = true; + var newPackage = loader.ScanPackageDirectory(newPackageLocation); + + // Assert + Assert.IsNotNull(oldPackage); + Assert.IsNull(newPackage); + Assert.AreEqual("Package", oldPackage.Name); + Assert.AreEqual("1.0.0", oldPackage.VersionName); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); + } + + [Test] + public void PackageLoaderLoadOldWhenNewPackageHasBeenLoadedAlready() + { + // Arrange + var loader = GetPackageLoader(); + var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); + var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); + + // Act + var newPackage = loader.ScanPackageDirectory(newPackageLocation); + newPackage.Loaded = true; + var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); + + // Assert + Assert.IsNull(oldPackage); + Assert.IsNotNull(newPackage); + Assert.AreEqual("Package", newPackage.Name); + Assert.AreEqual("2.0.0", newPackage.VersionName); + Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); + Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); + } + [Test] public void IsUnderPackageControlIsCorrectForValidFunctionDefinition() { From 0355a8f0236d3052ce77677cb16a751b677ef191 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Tue, 23 Mar 2021 19:05:53 -0400 Subject: [PATCH 14/18] Fix spelling. --- src/DynamoPackages/PackageLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index f9487219066..10ac9d63ea5 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -450,7 +450,7 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) return null; } - // If the existing package already loaded + // Is the existing package already loaded? if (existingPackage.Loaded) { throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedPackageAlreadyLoaded, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); From fd0e38a70695316b2aa31d901b16274e00b83208 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Wed, 24 Mar 2021 13:25:29 -0400 Subject: [PATCH 15/18] Address review comments --- src/DynamoPackages/PackageLoader.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 10ac9d63ea5..56b59e67cac 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -439,28 +439,48 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) if (existingVersion == discoveredVersion) { // Duplicated with the same version - throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DulicatedPackage, discoveredPackage.Name, discoveredPackage.RootDirectory)); + throw new LibraryLoadFailedException(directory, + String.Format(Properties.Resources.DulicatedPackage, + discoveredPackage.Name, + discoveredPackage.RootDirectory)); } // Is the existing version newer? if (existingVersion > discoveredVersion) { // Newer version already exist - Log(String.Format(Properties.Resources.DuplicatedOlderPackage, discoveredPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString()), WarningLevel.Moderate); + Log(String.Format(Properties.Resources.DuplicatedOlderPackage, + discoveredPackage.Name, + discoveredPackage.RootDirectory, + existingVersion.ToString(), + discoveredVersion.ToString()), + WarningLevel.Moderate); return null; } // Is the existing package already loaded? + // This can happen when we reload after a new package directory has been added + // and the new package directory has a newer version of a package that has been loaded already if (existingPackage.Loaded) { - throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedPackageAlreadyLoaded, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); + throw new LibraryLoadFailedException(directory, + String.Format(Properties.Resources.DuplicatedPackageAlreadyLoaded, + existingPackage.Name, + discoveredPackage.RootDirectory, + existingVersion.ToString(), + discoveredVersion.ToString())); } // Older version exist, replace with newer version Remove(existingPackage); Add(discoveredPackage); - Log(String.Format(Properties.Resources.DuplicatedOlderPackage, existingPackage.Name, existingPackage.RootDirectory, discoveredVersion.ToString(), existingVersion.ToString()), WarningLevel.Moderate); + Log(String.Format(Properties.Resources.DuplicatedOlderPackage, + existingPackage.Name, + existingPackage.RootDirectory, + discoveredVersion.ToString(), + existingVersion.ToString()), + WarningLevel.Moderate); return discoveredPackage; } From 877df83e09862a9d0177ba0a8bd29395d1f9fd00 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Wed, 24 Mar 2021 16:50:57 -0400 Subject: [PATCH 16/18] Always load the first version of a package found. --- .../Properties/Resources.Designer.cs | 12 ++--- .../Properties/Resources.en-US.resx | 4 +- src/DynamoCore/Properties/Resources.resx | 4 +- src/DynamoPackages/PackageLoader.cs | 37 ++++---------- .../PackageManagerTests/PackageLoaderTests.cs | 48 +------------------ 5 files changed, 19 insertions(+), 86 deletions(-) diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs index 7eee04eef9e..6eb63ef69da 100644 --- a/src/DynamoCore/Properties/Resources.Designer.cs +++ b/src/DynamoCore/Properties/Resources.Designer.cs @@ -451,20 +451,20 @@ public static string DuplicatedModelGuidError { } /// - /// Looks up a localized string similar to An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored.. + /// Looks up a localized string similar to A newer version of the package called {0} version {2} was found at {1} with version {3}. The newer version has been ignored.. /// - public static string DuplicatedOlderPackage { + public static string DuplicatedNewerPackage { get { - return ResourceManager.GetString("DuplicatedOlderPackage", resourceCulture); + return ResourceManager.GetString("DuplicatedNewerPackage", resourceCulture); } } /// - /// Looks up a localized string similar to A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package.. + /// Looks up a localized string similar to An older version of the package called {0} version {2} was found at {1} with version {3}. The older version has been ignored.. /// - public static string DuplicatedPackageAlreadyLoaded { + public static string DuplicatedOlderPackage { get { - return ResourceManager.GetString("DuplicatedPackageAlreadyLoaded", resourceCulture); + return ResourceManager.GetString("DuplicatedOlderPackage", resourceCulture); } } diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx index 73f40977d2b..dc67d7f99b9 100644 --- a/src/DynamoCore/Properties/Resources.en-US.resx +++ b/src/DynamoCore/Properties/Resources.en-US.resx @@ -741,7 +741,7 @@ Parameter name: {0} The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. - - A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package. + + A newer version of the package called {0} version {2} was found at {1} with version {3}. The newer version has been ignored. \ No newline at end of file diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx index b797a7e9777..22805eb4d2a 100644 --- a/src/DynamoCore/Properties/Resources.resx +++ b/src/DynamoCore/Properties/Resources.resx @@ -741,7 +741,7 @@ Parameter name: {0} The version of the package called {0} found at {1} is invalid (version: "{2}"). Ignoring it. - - A newer version of the package called {0} version {2} was found at {1} with version {3}. The old version of the package is already loaded. Please restart Dynamo for loading the new version of the package. + + A newer version of the package called {0} version {2} was found at {1} with version {3}. The newer version has been ignored. \ No newline at end of file diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index 56b59e67cac..fbfb5f7e98d 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -91,8 +91,8 @@ public PackageLoader(IEnumerable packagesDirectories) if (packagesDirectories == null) throw new ArgumentNullException("packagesDirectories"); - this.packagesDirectories.AddRange(packagesDirectories); this.packagesDirectories.Add(StandardLibraryDirectory); + this.packagesDirectories.AddRange(packagesDirectories); var error = PathHelper.CreateFolderIfNotExist(DefaultPackagesDirectory); @@ -448,41 +448,20 @@ public Package ScanPackageDirectory(string directory, bool checkCertificates) // Is the existing version newer? if (existingVersion > discoveredVersion) { - // Newer version already exist - Log(String.Format(Properties.Resources.DuplicatedOlderPackage, - discoveredPackage.Name, - discoveredPackage.RootDirectory, - existingVersion.ToString(), - discoveredVersion.ToString()), - WarningLevel.Moderate); - return null; - } - - // Is the existing package already loaded? - // This can happen when we reload after a new package directory has been added - // and the new package directory has a newer version of a package that has been loaded already - if (existingPackage.Loaded) - { - throw new LibraryLoadFailedException(directory, - String.Format(Properties.Resources.DuplicatedPackageAlreadyLoaded, + // Older version found, show notification + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedOlderPackage, existingPackage.Name, discoveredPackage.RootDirectory, existingVersion.ToString(), discoveredVersion.ToString())); } - // Older version exist, replace with newer version - Remove(existingPackage); - Add(discoveredPackage); - - Log(String.Format(Properties.Resources.DuplicatedOlderPackage, + // Newer version found, show notification. + throw new LibraryLoadFailedException(directory, String.Format(Properties.Resources.DuplicatedNewerPackage, existingPackage.Name, - existingPackage.RootDirectory, - discoveredVersion.ToString(), - existingVersion.ToString()), - WarningLevel.Moderate); - - return discoveredPackage; + discoveredPackage.RootDirectory, + existingVersion.ToString(), + discoveredVersion.ToString())); } catch (Exception e) { diff --git a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs index f98975dd3f9..84d0c36c4e2 100644 --- a/test/Libraries/PackageManagerTests/PackageLoaderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageLoaderTests.cs @@ -724,51 +724,6 @@ public void PackageLoaderLoadNewPackage() var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); var newPackage = loader.ScanPackageDirectory(newPackageLocation); - // Assert - Assert.IsNotNull(oldPackage); - Assert.IsNotNull(newPackage); - Assert.AreEqual("Package", oldPackage.Name); - Assert.AreEqual("Package", newPackage.Name); - Assert.AreEqual("1.0.0", oldPackage.VersionName); - Assert.AreEqual("2.0.0", newPackage.VersionName); - Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); - Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); - } - - [Test] - public void PackageLoaderLoadOldPackage() - { - // Arrange - var loader = GetPackageLoader(); - var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); - var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); - - // Act - var newPackage = loader.ScanPackageDirectory(newPackageLocation); - var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); - - // Assert - Assert.IsNull(oldPackage); - Assert.IsNotNull(newPackage); - Assert.AreEqual("Package", newPackage.Name); - Assert.AreEqual("2.0.0", newPackage.VersionName); - Assert.IsNotNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"New package")); - Assert.IsNull(loader.LocalPackages.FirstOrDefault(package => package.Description == @"Old package")); - } - - [Test] - public void PackageLoaderLoadNewWhenOldPackageHasBeenLoadedAlready() - { - // Arrange - var loader = GetPackageLoader(); - var oldPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithOldVersion"); - var newPackageLocation = Path.Combine(PackagesDirectory, @"Version\PackageWithNewVersion"); - - // Act - var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); - oldPackage.Loaded = true; - var newPackage = loader.ScanPackageDirectory(newPackageLocation); - // Assert Assert.IsNotNull(oldPackage); Assert.IsNull(newPackage); @@ -779,7 +734,7 @@ public void PackageLoaderLoadNewWhenOldPackageHasBeenLoadedAlready() } [Test] - public void PackageLoaderLoadOldWhenNewPackageHasBeenLoadedAlready() + public void PackageLoaderLoadOldPackage() { // Arrange var loader = GetPackageLoader(); @@ -788,7 +743,6 @@ public void PackageLoaderLoadOldWhenNewPackageHasBeenLoadedAlready() // Act var newPackage = loader.ScanPackageDirectory(newPackageLocation); - newPackage.Loaded = true; var oldPackage = loader.ScanPackageDirectory(oldPackageLocation); // Assert From dc63bb8e86132d35bb4d109c920c28d36924a0f6 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Wed, 24 Mar 2021 22:13:31 -0400 Subject: [PATCH 17/18] Fix failing test --- src/DynamoPackages/PackageLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index fbfb5f7e98d..b4a901cd189 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -71,7 +71,7 @@ public IEnumerable RequestedExtensions private readonly List packagesDirectories = new List(); public string DefaultPackagesDirectory { - get { return packagesDirectories[0]; } + get { return packagesDirectories[1]; } } private readonly List packagesDirectoriesToVerifyCertificates = new List(); From 720557bef33fcad39123903fed327ce1bd503ad4 Mon Sep 17 00:00:00 2001 From: Jorgen Dahl Date: Thu, 25 Mar 2021 07:04:07 -0400 Subject: [PATCH 18/18] Add comment --- src/DynamoPackages/PackageLoader.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DynamoPackages/PackageLoader.cs b/src/DynamoPackages/PackageLoader.cs index b4a901cd189..86f5e011526 100644 --- a/src/DynamoPackages/PackageLoader.cs +++ b/src/DynamoPackages/PackageLoader.cs @@ -69,6 +69,10 @@ public IEnumerable RequestedExtensions public IEnumerable LocalPackages { get { return localPackages; } } private readonly List packagesDirectories = new List(); + + // Returns the default package directory where new packages will be installed + // The default package directory is currently the second entry in the list + // The first entry is the standard library public string DefaultPackagesDirectory { get { return packagesDirectories[1]; }