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); }
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"); }
/// <summary> /// Load from an XML package definition file. /// This file is not expected to have info about the plugins in it, so this method will enumerate the plugins inside each dll by loading them. /// </summary> /// <param name="xmlFilePath">The Package Definition xml file. Usually named package.xml</param> /// <param name="projectDir">Directory used byt GitVersionCalculator to expand any $(GitVersion) macros in the XML file.</param> /// <returns></returns> public static PackageDef FromInputXml(string xmlFilePath, string projectDir) { PackageDef.ValidateXml(xmlFilePath); var pkgDef = PackageDef.FromXml(xmlFilePath); if (pkgDef.Files.Any(f => f.HasCustomData <UseVersionData>() && f.HasCustomData <SetAssemblyInfoData>())) { throw new InvalidDataException("A file cannot specify <SetAssemblyInfo/> and <UseVersion/> at the same time."); } pkgDef.Files = expandGlobEntries(pkgDef.Files); var excludeAdd = pkgDef.Files.Where(file => file.IgnoredDependencies != null).SelectMany(file => file.IgnoredDependencies).Distinct().ToList(); List <Exception> exceptions = new List <Exception>(); foreach (PackageFile item in pkgDef.Files) { string fullPath = Path.GetFullPath(item.FileName); if (!File.Exists(fullPath)) { string fileName = Path.GetFileName(item.FileName); if (File.Exists(fileName) && item.SourcePath == null) { // this is to support building everything to the root folder. This way the developer does not have to specify SourcePath. log.Warning("Specified file '{0}' was not found, using file '{1}' as source instead. Consider setting SourcePath to remove this warning.", item.FileName, fileName); item.SourcePath = fileName; } else { exceptions.Add(new FileNotFoundException("Missing file for package.", fullPath)); } } } if (exceptions.Count > 0) { throw new AggregateException("Missing files", exceptions); } pkgDef.Date = DateTime.UtcNow; // Copy to output directory first foreach (var file in pkgDef.Files) { if (file.RelativeDestinationPath != file.FileName) { try { var destPath = Path.GetFullPath(file.RelativeDestinationPath); if (!File.Exists(destPath)) { Directory.CreateDirectory(Path.GetDirectoryName(destPath)); ProgramHelper.FileCopy(file.FileName, destPath); } } catch { // Catching here. The files might be used by themselves } } } var searcher = new PluginSearcher(PluginSearcher.Options.IncludeSameAssemblies); searcher.Search(Directory.GetCurrentDirectory()); List <AssemblyData> assemblies = searcher.Assemblies.ToList(); // Enumerate plugins if this has not already been done. if (!pkgDef.Files.SelectMany(pfd => pfd.Plugins).Any()) { EnumeratePlugins(pkgDef, assemblies); } log.Info("Updating package version."); pkgDef.updateVersion(projectDir); log.Info("Package version is {0}", pkgDef.Version); pkgDef.findDependencies(excludeAdd, assemblies); return(pkgDef); }