Пример #1
0
        public void InstalledPackages_InvalidXmlIgnored()
        {
            Assert.IsTrue(File.Exists(PackageDef.GetDefaultPackageMetadataPath("XSeries")), "Necessary package file missing.");


            File.WriteAllText(Path.Combine(PackageDef.PackageDefDirectory, "Invalid.package.xml"),
                              @"<?xml version='1.0' encoding='utf-8' ?>
<Package Name='Invalid' xmlns='http://keysight.com/schemas/TAP/Package'>
  <Files>
    <File Path='Tap.Engine.dll' Obfuscate='false'><UseVersion/></File>
  </Files>
  <FileName>This should not be there<FileName/>
</Package>");

            System.Collections.Generic.List <PackageDef> target = new Installation(Directory.GetCurrentDirectory()).GetPackages();;


            CollectionAssert.AllItemsAreInstancesOfType(target, typeof(PackageDef));
            CollectionAssert.AllItemsAreNotNull(target);
            CollectionAssert.AllItemsAreUnique(target);
            Assert.IsTrue(target.Any(pkg => pkg.Name == "XSeries"));
            Assert.IsTrue(target.Any(pkg => pkg.Name == "Test"));
            Assert.IsFalse(target.Any(pkg => pkg.Name == "Invalid"));

            File.Delete(Path.Combine(PackageDef.PackageDefDirectory, "Invalid.package.xml"));
        }
Пример #2
0
        public void InstalledPackages_TwoPackages()
        {
            Assert.IsTrue(File.Exists(PackageDef.GetDefaultPackageMetadataPath("XSeries")), "Necessary package file missing.");

            System.Collections.Generic.List <PackageDef> target = new Installation(Directory.GetCurrentDirectory()).GetPackages();
            CollectionAssert.AllItemsAreInstancesOfType(target, typeof(PackageDef));
            CollectionAssert.AllItemsAreNotNull(target);
            CollectionAssert.AllItemsAreUnique(target);
            Assert.IsTrue(target.Any(pkg => pkg.Name == "XSeries"));
            Assert.IsTrue(target.Any(pkg => pkg.Name == "Test"));
        }
Пример #3
0
        public void CheckDependencies_AllDepsInstalled()
        {
            var xseries = PackageDef.FromXml(PackageDef.GetDefaultPackageMetadataPath("XSeries"));

            //var test2 = PackageDef.FromXmlFile(PackageDef.GetDefaultPackageMetadataPath("Test2"));
            File.Copy(PackageDef.GetDefaultPackageMetadataPath("CheckDependencies_AllDepsInstalled"), "CheckDependencies_AllDepsInstalled.xml", true);
            PackageDef.ValidateXml("CheckDependencies_AllDepsInstalled.xml");
            var alldeps = PackageDef.FromXml("CheckDependencies_AllDepsInstalled.xml");
            //var tree = DependencyAnalyzer.BuildAnalyzerContext(new List<PackageDef> { xseries, test2, alldeps });
            //Assert.AreEqual(tree.BrokenPackages.Count, 1);
            //PackageDependencyExt.CheckDependencies(inputFilename);
        }
Пример #4
0
        public void CheckDependencies_MissingDep()
        {
            string inputFilename = "Packages/CheckDependencies_MissingDep/package.xml";

            //PackageDependencyExt.CheckDependencies(inputFilename);
            var xseries = PackageDef.FromXml(PackageDef.GetDefaultPackageMetadataPath("XSeries"));

            PackageDef.ValidateXml(inputFilename);
            var missing = PackageDef.FromXml(inputFilename);
            var tree    = DependencyAnalyzer.BuildAnalyzerContext(new List <PackageDef> {
                xseries, missing
            });

            Assert.IsTrue(tree.GetIssues(missing).Any(issue => issue.IssueType == DependencyIssueType.Missing));
            //Assert.Fail("CheckDependencies should have thrown an exception");
        }
Пример #5
0
        private int Process(string[] OutputPaths)
        {
            try
            {
                PackageDef pkg = null;
                if (!File.Exists(PackageXmlFile))
                {
                    log.Error("Cannot locate XML file '{0}'", PackageXmlFile);
                    return((int)ExitCodes.FileSystemError);
                }
                if (!Directory.Exists(ProjectDir))
                {
                    log.Error("Project directory '{0}' does not exist.", ProjectDir);
                    return((int)ExitCodes.FileSystemError);
                }
                try
                {
                    var fullpath = Path.GetFullPath(PackageXmlFile);
                    pkg = PackageDefExt.FromInputXml(fullpath, ProjectDir);

                    // Check if package name has invalid characters or is not a valid path
                    var illegalCharacter = pkg.Name.IndexOfAny(Path.GetInvalidFileNameChars());
                    if (illegalCharacter >= 0)
                    {
                        log.Error("Package name cannot contain invalid file path characters: '{0}'", pkg.Name[illegalCharacter]);
                        return((int)ExitCodes.InvalidPackageName);
                    }
                }
                catch (AggregateException aex)
                {
                    foreach (var ex in aex.InnerExceptions)
                    {
                        if (ex is FileNotFoundException)
                        {
                            log.Error("File not found: '{0}'", ((FileNotFoundException)ex).FileName);
                        }
                        else
                        {
                            log.Error(ex.ToString());
                        }
                    }
                    log.Error("Caught errors while loading package definition.");
                    return(4);
                }

                var tmpFile = Path.GetTempFileName();

                // If user omitted the Version XML attribute or put Version="", lets inform.
                if (string.IsNullOrEmpty(pkg.RawVersion))
                {
                    log.Warning($"Package version is {pkg.Version} due to blank or missing 'Version' XML attribute in 'Package' element");
                }

                pkg.CreatePackage(tmpFile);

                if (OutputPaths == null || OutputPaths.Length == 0)
                {
                    OutputPaths = new string[1] {
                        ""
                    }
                }
                ;

                foreach (var outputPath in OutputPaths)
                {
                    var path = outputPath;

                    if (String.IsNullOrEmpty(path))
                    {
                        path = GetRealFilePathFromName(pkg.Name, pkg.Version.ToString(), DefaultEnding);
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

                    ProgramHelper.FileCopy(tmpFile, path);
                    log.Info("OpenTAP plugin package '{0}' containing '{1}' successfully created.", path, pkg.Name);
                }

                if (FakeInstall)
                {
                    log.Warning("--fake-install argument is obsolete, use --install instead");
                    Install = FakeInstall;
                }
                if (Install)
                {
                    var path = PackageDef.GetDefaultPackageMetadataPath(pkg, Directory.GetCurrentDirectory());
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                    {
                        pkg.SaveTo(fs);
                    }
                    log.Info($"Installed '{pkg.Name}' ({Path.GetFullPath(path)})");
                }
            }
            catch (ArgumentException ex)
            {
                Console.Error.WriteLine(ex.Message);
                return((int)ExitCodes.GeneralPackageCreateError);
            }
            catch (InvalidDataException ex)
            {
                log.Error("Caught invalid data exception: {0}", ex.Message);

                return((int)ExitCodes.InvalidPackageDefinition);
            }
            return(0);
        }
Пример #6
0
        private static ActionResult DoUninstall(PluginInstaller pluginInstaller, ActionExecuter action, PackageDef package, bool force, string target)
        {
            var result      = ActionResult.Ok;
            var destination = package.IsSystemWide() ? PackageDef.SystemWideInstallationDirectory : target;

            var filesToRemain = new Installation(destination).GetPackages().Where(p => p.Name != package.Name).SelectMany(p => p.Files).Select(f => f.RelativeDestinationPath).Distinct(StringComparer.InvariantCultureIgnoreCase).ToHashSet(StringComparer.InvariantCultureIgnoreCase);

            try
            {
                CustomPackageActionHelper.RunCustomActions(package, PackageActionStage.Uninstall, new CustomPackageActionArgs(null, force));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = ActionResult.Error;
            }

            try
            {
                if (action.ExecutePackageActionSteps(package, force, target) == ActionResult.Error)
                {
                    throw new Exception();
                }
            }
            catch
            {
                log.Error($"Uninstall package action failed to execute for package '{package.Name}'.");
                result = ActionResult.Error;
            }

            foreach (var file in package.Files)
            {
                if (file.RelativeDestinationPath == "tap" || file.RelativeDestinationPath.ToLower() == "tap.exe") // ignore tap.exe as it is not meant to be overwritten.
                {
                    continue;
                }

                string fullPath;
                if (package.IsSystemWide())
                {
                    fullPath = Path.Combine(PackageDef.SystemWideInstallationDirectory, file.RelativeDestinationPath);
                }
                else
                {
                    fullPath = Path.Combine(destination, file.RelativeDestinationPath);
                }

                if (filesToRemain.Contains(file.RelativeDestinationPath))
                {
                    log.Debug("Skipping deletion of file '{0}' since it is required by another plugin package.", file.RelativeDestinationPath);
                    continue;
                }

                try
                {
                    log.Debug("Deleting file '{0}'.", file.RelativeDestinationPath);
                    File.Delete(fullPath);
                }
                catch (Exception e)
                {
                    log.Debug(e);
                    result = ActionResult.Error;
                }

                DeleteEmptyDirectory(new FileInfo(fullPath).Directory);
            }

            var packageFile = PackageDef.GetDefaultPackageMetadataPath(package, target);

            if (!File.Exists(packageFile))
            {
                // TAP 8.x support:
                packageFile = $"Package Definitions/{package.Name}.package.xml";
            }
            if (File.Exists(packageFile))
            {
                log.Debug("Deleting file '{0}'.", packageFile);
                File.Delete(packageFile);
                DeleteEmptyDirectory(new FileInfo(packageFile).Directory);
            }
            return(result);
        }