Пример #1
0
        public void CreatePackage_NoObfuscation()
        {
            string inputFilename  = "Packages/Package/package.xml";
            string outputFilename = "Test.TapPlugin";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            try
            {
                pkg.CreatePackage(outputFilename);
                Assert.IsTrue(File.Exists(outputFilename));
            }
            finally
            {
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }
Пример #2
0
        public void CreatePackage_NoBinFiles()
        {
            File.Copy("Packages/Package_NoBinFiles/package.xml", "package_NoBinFiles.xml", true);
            string inputFilename  = "package_NoBinFiles.xml";
            string outputFilename = "Test.TapPackage";

            PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());

            try
            {
                pkg.CreatePackage(outputFilename);
                Assert.IsTrue(File.Exists(outputFilename));
            }
            finally
            {
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }
Пример #3
0
        public void GitVersionDependency()
        {
            string inputFilename  = "Packages/GitVersionDependency/package.xml";
            string outputFilename = "GitversionDependency.TapPlugin";

            try
            {
                DummyPackageGenerator.InstallDummyPackage("DepName", new GitVersionCalulator(Directory.GetCurrentDirectory()).GetVersion().ToString());
                PackageDef pkg = PackageDefExt.FromInputXml(inputFilename, Directory.GetCurrentDirectory());
                pkg.CreatePackage(outputFilename);
                Assert.AreNotSame("$(GitVersion)", pkg.Dependencies.First().Version.ToString());
                VersionSpecifier versionSpecifier = new VersionSpecifier(pkg.Version, VersionMatchBehavior.Exact);

                Assert.AreEqual(pkg.Dependencies.FirstOrDefault(p => p.Name == "DepName").Version.ToString(), versionSpecifier.ToString());
            }
            finally
            {
                DummyPackageGenerator.UninstallDummyPackage("DepName");
                if (File.Exists(outputFilename))
                {
                    File.Delete(outputFilename);
                }
            }
        }
Пример #4
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);
        }