public void InstallFileWithMissingDependencyTest() { var def = new PackageDef(); def.Name = "Dummy2"; def.OS = "Windows,Linux"; def.Version = SemanticVersion.Parse("1.0"); def.AddFile("Dummy.txt"); def.Dependencies.Add(new PackageDependency("Missing", VersionSpecifier.Parse("1.0"))); DummyPackageGenerator.InstallDummyPackage("Missing"); string pkgFile = DummyPackageGenerator.GeneratePackage(def); DummyPackageGenerator.UninstallDummyPackage("Missing"); try { int exitCode; string output = RunPackageCli("install Dummy2 -y", out exitCode); //Assert.AreNotEqual(0, exitCode, "Unexpected exit code"); StringAssert.Contains("'Missing' with a version compatible with 1.0", output); } finally { File.Delete(pkgFile); } }
public void CyclicDependenciesTest() { DummyPackageGenerator.InstallDummyPackage(); // We need to have "Dummy" installed before we can create a package that depends on it. var depDef = new PackageDef(); depDef.Name = "Dependency"; depDef.OS = "Windows,Linux"; depDef.Version = SemanticVersion.Parse("1.0"); depDef.AddFile("Dependency.txt"); depDef.Dependencies.Add(new PackageDependency("Dummy", VersionSpecifier.Parse("1.0"))); string dep0File = DummyPackageGenerator.GeneratePackage(depDef); DummyPackageGenerator.UninstallDummyPackage(); DummyPackageGenerator.InstallDummyPackage("Dependency"); var dummyDef = new PackageDef(); dummyDef.Name = "Dummy"; dummyDef.OS = "Windows,Linux"; dummyDef.Version = SemanticVersion.Parse("1.0"); dummyDef.AddFile("Dummy.txt"); dummyDef.Dependencies.Add(new PackageDependency("Dependency", VersionSpecifier.Parse("1.0"))); string dummyFile = DummyPackageGenerator.GeneratePackage(dummyDef); DummyPackageGenerator.UninstallDummyPackage("Dependency"); try { if (File.Exists("Dependency.txt")) { File.Delete("Dependency.txt"); } if (File.Exists("Dummy.txt")) { File.Delete("Dummy.txt"); } int exitCode; string output = RunPackageCli("install Dummy -y", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code.\r\n" + output); StringAssert.Contains("Dummy", output); StringAssert.Contains("Dependency", output); Assert.IsTrue(File.Exists("Dependency.txt")); Assert.IsTrue(File.Exists("Dummy.txt")); } finally { PluginInstaller.Uninstall(dummyDef, Directory.GetCurrentDirectory()); PluginInstaller.Uninstall(depDef, Directory.GetCurrentDirectory()); File.Delete(dep0File); File.Delete(dummyFile); } }
public void UpgradeDependencyTest() { var dep0Def = new PackageDef(); dep0Def.Name = "Dependency"; dep0Def.Version = SemanticVersion.Parse("0.1"); dep0Def.AddFile("Dependency0.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(dep0Def); var dep1Def = new PackageDef(); dep1Def.Name = "Dependency"; dep1Def.Version = SemanticVersion.Parse("1.0"); dep1Def.AddFile("Dependency1.txt"); string dep1File = DummyPackageGenerator.GeneratePackage(dep1Def); var dummyDef = new PackageDef(); dummyDef.Name = "Dummy"; dummyDef.Version = SemanticVersion.Parse("1.0"); dummyDef.AddFile("Dummy.txt"); dummyDef.Dependencies.Add(new PackageDependency("Dependency", VersionSpecifier.Parse("1.0"))); DummyPackageGenerator.InstallDummyPackage("Dependency"); string dummyFile = DummyPackageGenerator.GeneratePackage(dummyDef); DummyPackageGenerator.UninstallDummyPackage("Dependency"); try { int exitCode; string output = RunPackageCli("install " + dep0File + " --force", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code"); output = RunPackageCli("install Dummy -y", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code"); //StringAssert.Contains("upgrading", output); Assert.IsTrue(File.Exists("Dependency1.txt")); } finally { PluginInstaller.Uninstall(dummyDef, Directory.GetCurrentDirectory()); PluginInstaller.Uninstall(dep1Def, Directory.GetCurrentDirectory()); File.Delete(dep0File); File.Delete(dep1File); File.Delete(dummyFile); } }
public static List <PackageDef> GetConflictingVersion() { var D = new PackageDef { Name = "D", RawVersion = "2.0.0" }; D.Dependencies.Add(new PackageDependency("OpenTAP", VersionSpecifier.Parse("2.0.0"))); var file = new PackageFile { FileName = "Package/D/test" }; file.CustomData.Add(new FileHashPackageAction.Hash { Value = "TEST123" }); D.Files.Add(file); return(new List <PackageDef> { D }); }
public void SpecifierToStringTest(string specifier, int fieldCount) { Assert.AreEqual(specifier, VersionSpecifier.Parse(specifier).ToString()); Assert.AreEqual(specifier, VersionSpecifier.Parse(specifier).ToString(fieldCount)); }
[TestCase("1.2.3+Build-something", "1.2.3+Build-something-else", false)] // buildMetadata public void SpecifierExactTest(string specifier, string version, bool expected) { Assert.AreEqual(expected, VersionSpecifier.Parse(specifier).IsCompatible(SemanticVersion.Parse(version))); }
public int Execute(CancellationToken cancellationToken) { if (string.IsNullOrEmpty(PackageName)) { log.Error("Please specify a valid package name."); return(1); } { // check if the package exists in the repo. var repo = new HttpPackageRepository(PackageRepository); var spec = new PackageSpecifier(PackageName, Version != null ? VersionSpecifier.Parse(Version) : null); var pkg = repo.GetPackages(spec, TapThread.Current.AbortToken).FirstOrDefault(); if (pkg == null) { log.Error("No such package"); return(2); } if (Version == null) { Version = pkg.Version.ToString(); } PackageName = pkg.Name; } string ifRefStr = ""; if (NoReference) { ifRefStr = " Reference=\"false\""; } string insert = $"<OpenTapPackageReference Include=\"{PackageName}\" Version=\"{Version}\" Repository=\"{PackageRepository}\"{ifRefStr}/>"; var csproj = Project ?? get_csproj(); if (csproj == null) { // error was already printed. return(1); } if (File.Exists(csproj) == false) { log.Error("C# project files does not exist {0}", csproj); return(2); } var document = XDocument.Load(csproj, LoadOptions.PreserveWhitespace); var projectXml = document.Element("Project"); XElement itemGroupXml = null; var condition = $"'$(Configuration)' == '{Configuration}'"; var itemGroups = projectXml.Elements("ItemGroup"); // if condition is select take the group matching the conditions. if (string.IsNullOrWhiteSpace(Configuration) == false) { itemGroups = itemGroups.Where(grp => grp.Attribute("Condition")?.Value == condition); } bool needsAddNewElem = true; foreach (var grp in itemGroups) { var existingElem = grp.Elements("OpenTapPackageReference") .Where(elem => string.Equals(elem.Attribute("Reference")?.Value ?? "True", (!NoReference).ToString(), StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(elem => elem.Attribute("Include")?.Value == PackageName); if (existingElem != null) { // the package reference already exists. In this case, lets try to just update set the version. var version = existingElem.Attribute("Version"); if (version != null) { if (version.Value == Version) { log.Info("Package {0} version {1} already in the csproj.", PackageName, Version); return(0); } log.Info("Package {0} version {1} changed to version {2}.", PackageName, version.Value, Version); version.Value = Version; needsAddNewElem = false; break; } } } if (needsAddNewElem) { // add a new OpenTapPackageReference or AdditionalOpenTapPackage element. // to make the whitespace look right, there is some adding additional whitespace // Try to find the existing item group used for package references. foreach (var grp in itemGroups) { if (grp.Elements("OpenTapPackageReference").Any()) { itemGroupXml = grp; break; } } if (itemGroupXml == null) { itemGroupXml = new XElement("ItemGroup"); if (string.IsNullOrWhiteSpace(Configuration) == false) { // e.g Condition="'{Configuration}' == 'Debug'" itemGroupXml.Add(new XAttribute("Condition", condition)); } itemGroupXml.Add("\n"); itemGroupXml.Add(" "); projectXml.Add("\n"); projectXml.Add(" "); projectXml.Add(itemGroupXml); projectXml.Add("\n"); } itemGroupXml.Add(" "); itemGroupXml.Add(XElement.Parse(insert)); itemGroupXml.Add("\n"); itemGroupXml.Add(" "); log.Info("Package {0} version {1} reference added to the project.", PackageName, Version); } document.Save(csproj, SaveOptions.DisableFormatting); return(0); }
public void CreatePackageDepReuse() { if (Directory.Exists("Packages2")) { Directory.Delete("Packages2", true); } Directory.Move("Packages", "Packages2"); File.Copy("Packages2/DependencyTest.dll", "DependencyTest.dll", true); try { Directory.CreateDirectory("Packages"); { PackageDef def = new PackageDef() { Name = "pkg1", Version = SemanticVersion.Parse("1.2") }; def.AddFile("OpenTap.dll"); Directory.CreateDirectory("Packages/pkg1"); using (var f = File.OpenWrite("Packages/pkg1/package.xml")) def.SaveTo(f); } { PackageDef def = new PackageDef() { Name = "gui", Version = SemanticVersion.Parse("1.2") }; def.AddFile("Keysight.OpenTap.Wpf.dll"); Directory.CreateDirectory("Packages/gui"); using (var f = File.OpenWrite("Packages/gui/package.xml")) def.SaveTo(f); } { PackageDef def = new PackageDef() { Name = "rv", Version = SemanticVersion.Parse("1.2") }; def.AddFile("Keysight.OpenTap.Wpf.dll"); Directory.CreateDirectory("Packages/rv"); using (var f = File.OpenWrite("Packages/rv/package.xml")) def.SaveTo(f); } { PackageDef def = new PackageDef(); def.Name = "test"; def.InfoLink = "a"; def.Date = DateTime.Today; def.Dependencies.Add(new PackageDependency("rv", VersionSpecifier.Parse("1.2"))); def.AddFile("DependencyTest.dll"); def.Files[0].DependentAssemblies.AddRange(PluginManager.GetSearcher().Assemblies.First(f => f.Name == "DependencyTest").References); var searcher = new PluginSearcher(); searcher.Search(Directory.GetCurrentDirectory()); List <AssemblyData> assemblies = searcher.Assemblies.ToList(); def.findDependencies(new List <string>(), assemblies); //Assert.AreEqual(3, def.Dependencies.Count); Assert.IsTrue(def.Dependencies.Any(d => d.Name == "rv")); Assert.IsTrue(def.Dependencies.Any(d => d.Name == "pkg1")); } { PackageDef def = new PackageDef(); def.Name = "test"; def.InfoLink = "a"; def.Date = DateTime.Today; def.Dependencies.Add(new PackageDependency("gui", VersionSpecifier.Parse("1.2"))); def.AddFile("DependencyTest.dll"); def.Files[0].DependentAssemblies.AddRange(PluginManager.GetSearcher().Assemblies.First(f => f.Name == "DependencyTest").References); var searcher = new PluginSearcher(); searcher.Search(Directory.GetCurrentDirectory()); List <AssemblyData> assemblies = searcher.Assemblies.ToList(); def.findDependencies(new List <string>(), assemblies); //Assert.AreEqual(2, def.Dependencies.Count); Assert.IsTrue(def.Dependencies.Any(d => d.Name == "gui")); Assert.IsTrue(def.Dependencies.Any(d => d.Name == "pkg1")); } } finally { if (Directory.Exists("Packages")) { Directory.Delete("Packages", true); } Directory.Move("Packages2", "Packages"); } }