static void Main() { var repo = new LocalPackageRepository(@"C:\Code\Common\Group\Business-Logic\packages"); IQueryable <IPackage> packages = repo.GetPackages(); OutputGraph(repo, packages, 0); }
public IEnumerable <string> CreatePackageFile() { var packagesFile = Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFile); var packageReferenceFile = new PackageReferenceFile(packagesFile); var packagesFolder = Path.Combine(_fileSystem.CurrentDirectory, Constants.PackagesFolder); var repository = new LocalPackageRepository(packagesFolder); var newestPackages = repository.GetPackages().GroupBy(p => p.Id) .Select(g => g.OrderByDescending(p => p.Version).FirstOrDefault()); foreach (var package in newestPackages) { var newestFramework = GetNewestSupportedFramework(package); packageReferenceFile.AddEntry(package.Id, package.Version, newestFramework); if (newestFramework == null) { yield return(string.Format("{0}, Version {1}", package.Id, package.Version)); } else { yield return(string.Format("{0}, Version {1}, .NET {2}", package.Id, package.Version, newestFramework.Version)); } } }
public NuGetPackageFolder( string physicalPath, IReport report) { _repository = new LocalPackageRepository(physicalPath, report); _report = report; }
public V2SourceRepository(PackageSource source, IPackageRepository repository, string host) { _source = source; _repository = repository; // TODO: Get context from current UI activity (PowerShell, Dialog, etc.) _userAgent = UserAgentUtil.GetUserAgent("NuGet.Client.Interop", host); var events = _repository as IHttpClientEvents; if (events != null) { events.SendingRequest += (sender, args) => { var httpReq = args.Request as HttpWebRequest; if (httpReq != null) { httpReq.UserAgent = _userAgent; } NuGetTraceSources.V2SourceRepository.Verbose("http", "{0} {1}", args.Request.Method, args.Request.RequestUri.ToString()); }; } _lprepo = _repository as LocalPackageRepository; }
protected internal override IPackagePushLocation GetPushLocation() { var ret = new LocalPackageRepository(Path.FullName); ret.PathResolver = new LocalPathResolver(Path); return(new LocalPushLocation(ret)); }
private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package) { string id = package.ItemSpec; string version = package.GetMetadata("Version"); Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version); // Initial version just searches a machine-level repository var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib")); var defaultResolver = new DefaultPackagePathResolver(localFs); var machineRepo = new LocalPackageRepository(defaultResolver, localFs); var buildRepo = new BuildPackageRepository(); var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2")); var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences); var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo); var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo); // Install the package var ver = new SemanticVersion(version); manager.PackageInstalling += manager_PackageInstalling; manager.InstallPackage(id, ver); projectManager.AddPackageReference(id, ver); return project.OutputReferences.Select(item => { var name = AssemblyName.GetAssemblyName(item); return new TaskItem(name.FullName, new Dictionary<string, string>() { {"HintPath", item }, {"Private", "true"} }); }); }
static void Main(string[] args) { var orchardDirectory = args[0]; var inputDirectory = args[1]; var outputDirectory = args[2]; var cacheDirectory = args[3]; var cacheFileSystem = new PhysicalFileSystem(cacheDirectory); var cachePackageResolver = new DefaultPackagePathResolver(cacheFileSystem, false); var orchardRepository = new AggregateRepository(new IPackageRepository[] { new LocalPackageRepository(orchardDirectory), new DataServicePackageRepository(new Uri("http://nuget.org/api/v2")), }); var orchardManager = new PackageManager(orchardRepository, cachePackageResolver, cacheFileSystem); var inputRepository = new LocalPackageRepository(inputDirectory); var inputManager = new PackageManager(inputRepository, cachePackageResolver, cacheFileSystem); var references = new[] { "Orchard.Core", "Orchard.Framework", "Orchard.External" }; foreach (var reference in references) { orchardManager.InstallPackage(orchardRepository.FindPackage(reference), false, false); } foreach (var inputPackage in inputRepository.GetPackages().Where(p => p.Id.StartsWith("Orchard.Module."))) { Do(inputRepository, inputManager, inputPackage, cacheDirectory, references, outputDirectory); } }
public void FindPackagesByIdFindPackagesMatchingExactId() { // Arrange string id = "Test"; var repositoryRoot = CreatePackage(id, version: "1.2", packageFileName: "Test.1.2.nupkg"); CreatePackage(id, version: "1.3", packageFileName: "Test.1.3.nupkg", rootDir: repositoryRoot); CreatePackage(id, version: "2.0.0.9200-alpha", packageFileName: "Test.2.0.0.9200.nupkg", rootDir: repositoryRoot); IPackageRepository repository = new LocalPackageRepository(repositoryRoot); // Act var packages = repository.FindPackagesById(id).ToList(); // Assert foreach (var p in packages) { Assert.True(p is OptimizedZipPackage); } Assert.Equal(3, packages.Count); Assert.Equal("1.2", packages[0].Version.ToString()); Assert.Equal("1.3", packages[1].Version.ToString()); Assert.Equal("2.0.0.9200-alpha", packages[2].Version.ToString()); }
public void FindPackageMatchesExactVersionIfSideBySideIsEnabled() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"A.1.1\A.1.1.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: true), fileSystem, enableCaching: false); var searchedPaths = new List <string>(); Func <string, IPackage> openPackage = p => { searchedPaths.Add(p); return(PackageUtility.CreatePackage("A", "1.1")); }; // Act and Assert IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("0.8")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.1")); Assert.Equal(@"A.1.1\A.1.1.nupkg", searchedPaths.Single()); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.1"), result.Version); }
/*<summary> * Using Nuget.Core API, we gather all nuget`s packages that specific project depend on them. * </summary> * <returns></returns> */ private static void addDependencies(string projectName, Module module, string localSource, string[] packageConfigPath, string Configuration) { if (packageConfigPath.Length != 0) { var sharedPackages = new LocalPackageRepository(localSource); var packageReferenceFile = new PackageReferenceFile(packageConfigPath[0]); IEnumerable <PackageReference> projectPackages = packageReferenceFile.GetPackageReferences(); foreach (PackageReference package in projectPackages) { var pack = sharedPackages.FindPackage(package.Id, package.Version); using (Stream packageStream = ((NuGet.OptimizedZipPackage)(pack)).GetStream()) { byte[] buf = new byte[packageStream.Length]; int byteread = packageStream.Read(buf, 0, buf.Length); module.Dependencies.Add(new Dependency { type = "nupkg", md5 = MD5CheckSum.GenerateMD5(buf), sha1 = Sha1Reference.GenerateSHA1(buf), scopes = new List <string> { Configuration }, id = pack.Id + ":" + pack.Version }); } } } }
public static async Task <string> Install(this IPackage package, string source, string dest) { IPackageRepository packageRepository = new LocalPackageRepository(source); IPackageManager packageManager = new PackageManager(packageRepository, dest); var tcs = new TaskCompletionSource <string>(); var handler = new EventHandler <PackageOperationEventArgs>((sender, args) => tcs.SetResult(args.InstallPath)); packageManager.PackageInstalled += handler; packageManager.InstallPackage(package, true, true); packageManager.PackageInstalled -= handler; if (await Task.WhenAny(tcs.Task, Task.Delay(5000)) == tcs.Task) { await tcs.Task; return(tcs.Task.Result); } else { throw new TimeoutException("Package install timeout"); } }
public void FindPackageVerifiesPackageFileExistsOnFileSystemWhenCaching() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"A.1.0.0.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: true), fileSystem, enableCaching: true); var searchedPaths = new List <string>(); Func <string, IPackage> openPackage = p => { searchedPaths.Add(p); return(PackageUtility.CreatePackage("A", "1.0")); }; // Act - 1 IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 1 Assert.NotNull(result); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.0"), result.Version); // Act - 2 fileSystem.DeleteFile("A.1.0.0.nupkg"); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 2 Assert.Null(result); }
public static IPackageRepository GetV2SourceRepository(Configuration.PackageSource source) { IPackageRepository repo = new PackageRepositoryFactory().CreateRepository(source.Source); LocalPackageRepository _lprepo = repo as LocalPackageRepository; if (_lprepo != null) { return(_lprepo); } string _userAgent = UserAgentUtil.GetUserAgent("NuGet.Client.Interop", "host"); var events = repo as IHttpClientEvents; if (events != null) { events.SendingRequest += (sender, args) => { var httpReq = args.Request as HttpWebRequest; if (httpReq != null) { httpReq.UserAgent = _userAgent; } }; } return(repo); }
public Task <PackageDownloadMetadata> GetNupkgUrlForDownload(PackageIdentity identity) { //*TODOs: Temp implementation. Need to do erorr handling and stuff. return(Task.Factory.StartNew(() => { if (V2Client is DataServicePackageRepository) { //TODOs:Not sure if there is some other standard way to get the Url from a dataservice repo. DataServicePackage has downloadurl property but not sure how to get it. return new PackageDownloadMetadata(new Uri(Path.Combine(V2Client.Source, "api/v2/" + identity.Id + "." + identity.Version + ".nupkg"))); } else if (V2Client is LocalPackageRepository) { LocalPackageRepository lrepo = V2Client as LocalPackageRepository; SemanticVersion semVer = new SemanticVersion(identity.Version.Version); return new PackageDownloadMetadata(new Uri(Path.Combine(V2Client.Source, lrepo.PathResolver.GetPackageFileName(identity.Id, semVer)))); } else { // TODO: move the string into a resoure file throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "Unable to get download metadata for package {0}", identity.Id)); } })); }
static void OutputGraph(LocalPackageRepository repository, IEnumerable <IPackage> packages, int depth, int maxDepth) { foreach (IPackage package in packages) { Console.WriteLine("{0}{1} v{2}", new string(' ', depth * 3), package.Id, package.Version); IList <IPackage> dependentPackages = new List <IPackage>(); foreach (var dependencySet in package.DependencySets) { foreach (var dependency in dependencySet.Dependencies) { var dependentPackage = repository.FindPackage(dependency.Id, dependency.VersionSpec, true, true); if (dependentPackage != null) { dependentPackages.Add(dependentPackage); } } } if (depth < maxDepth) { OutputGraph(repository, dependentPackages, depth + 1, maxDepth); } } }
public NuGetPackageFolder( string physicalPath, Reports reports) { _repository = new LocalPackageRepository(physicalPath, reports.Quiet); _reports = reports; Source = physicalPath; }
public void FindPackagesByIdThrowsIfIdIsNullOrEmpty(string id) { // Arrange var repository = new LocalPackageRepository(Mock.Of <IPackagePathResolver>(), Mock.Of <IFileSystem>()); // Act and Assert ExceptionAssert.ThrowsArgNullOrEmpty(() => repository.FindPackagesById(id), "packageId"); }
private IPackage ReadPackage(string packageName) { var path = Path.Combine(TestRootPath, packageName, "bin/Debug"); var repository = new LocalPackageRepository(path); return(repository.FindPackage(packageName)); }
public IEnumerable <IPackage> GetAllPackages(string rootFolder) //rootFolder is repository root { var targetFolder = rootFolder.AppendPath(PackagesFolder); var packagePathResolver = new DefaultPackagePathResolver(targetFolder); var packagesFolderFileSystem = new PhysicalFileSystem(targetFolder); var localRepository = new LocalPackageRepository(packagePathResolver, packagesFolderFileSystem); return(localRepository.GetPackages()); }
public IPackageRepository get_local_repository(IPackagePathResolver pathResolver, NuGet.IFileSystem nugetPackagesFileSystem) { this.Log().Debug(() => "Setting up local repository at '{0}'".format_with(nugetPackagesFileSystem.Root)); IPackageRepository localRepository = new LocalPackageRepository(pathResolver, nugetPackagesFileSystem); localRepository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec; return(localRepository); }
public IPackageObject FindPackage(string path, IPackageReference packageRef) { var repository = new LocalPackageRepository(path); var package = packageRef.Version != null ? repository.FindPackage(packageRef.PackageId, new SemanticVersion(packageRef.Version, packageRef.SpecialVersion), true, true) : repository.FindPackage(packageRef.PackageId); return(package == null ? null : new PackageObject(package, packageRef.FrameworkName)); }
public PackageFolder( string physicalPath, IReport report) { _repository = new LocalPackageRepository(physicalPath) { Report = report }; _report = report; }
internal static IPackage GetLastestVersionPackage(string packageDir, string packageId) { var repo = new LocalPackageRepository(Path.GetFullPath(packageDir)); var pkgs = repo.GetPackages().ToArray(); var targetPackages = pkgs.Where(x => x.Id == packageId).ToArray(); var newbePk = targetPackages.First(x => x.Id == packageId && x.Version == targetPackages.Max(a => a.Version)); return(newbePk); }
public void Setup() { var mfs = new Mock<MockFileSystem>() { CallBase = true }; var pr = new DefaultPackagePathResolver(mfs.Object); var mc = MachineCache.Default; var l = new LocalPackageRepository(pr, mfs.Object); var r1 = new DataServicePackageRepository(new Uri(@"http://nuget.org")); var r2 = new DataServicePackageRepository(new Uri(@"http://beta.nuget.org")); ar = new AggregateRepository(new List<IPackageRepository>() { mc, l, r1, r2 }); }
public IPackageObject FindPackage(string path, IPackageReference packageRef) { Guard.AgainstNullArgument("packageRef", packageRef); var repository = new LocalPackageRepository(path); var package = packageRef.Version != null && !(packageRef.Version.Major == 0 && packageRef.Version.Minor == 0) ? repository.FindPackage(packageRef.PackageId, new SemanticVersion(packageRef.Version, packageRef.SpecialVersion), true, true) : repository.FindPackage(packageRef.PackageId); return(package == null ? null : new PackageObject(package, packageRef.FrameworkName)); }
/// <summary> /// Loads build and sort the packages information. /// </summary> /// <param name="preRelease">if set to <c>true</c> [pre release].</param> private void PreparePackagesInfo(/*bool preRelease*/) { try { #region AggregateRepository nugetRepositories = ... List <LocalPackageRepository> repositories = new List <LocalPackageRepository>(); foreach (string source in PackagesSources) { LocalPackageRepository repository = new LocalPackageRepository(source); repositories.Add(repository); } AggregateRepository nugetRepositories = new AggregateRepository(repositories); #endregion // AggregateRepository nugetRepositories = ... string targetFramework = ((TargetFrameworkAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(TargetFrameworkAttribute), false)[0]).FrameworkName; string frameWorkVersion = targetFramework.Substring(targetFramework.LastIndexOf("v") + 1); var frameworkName = new FrameworkName(frameWorkVersion, Version.Parse(frameWorkVersion)); PackageSorter sorter = new PackageSorter(frameworkName) { //DependencyVersion = preRelease ? DependencyVersion.HighestPatch : DependencyVersion.Highest, }; var packages = from nuget in sorter.GetPackagesByDependencyOrder(nugetRepositories) //.Where(m => preRelease ? m.IsAbsoluteLatestVersion : m.IsLatestVersion) .AsCollapsed() group nuget by nuget.Id into g let p = g.Last() let version = p.Version let assemblyName = p.GetFiles() .Select(f => f.EffectivePath) .Where(path => path.EndsWith(".dll")) .Select(path => Path.GetFileNameWithoutExtension(path)) .FirstOrDefault() let packageFileName = $"{p.Id}.{version}.nupkg" select new NuGetPackageInfo { Id = p.Id, Name = p.GetFullName(), Version = version.ToNormalizedString(), PackageFileName = packageFileName, NuGetPackage = p, RepositoryPath = FindPackagePath(packageFileName), AssemblyName = assemblyName }; PackagesInfo = packages.ToArray(); } catch (Exception ex) { _errors.AppendLine("Failed to load NuGet packages. Error: " + ex.Message); } }
/// <summary> /// Returns true if the package is already installed in the local repository. /// </summary> /// <param name="fileSystem">The file system of the local repository.</param> /// <param name="packageId">The package id.</param> /// <param name="version">The package version</param> /// <returns>True if the package is installed in the local repository.</returns> private static bool IsPackageInstalled(IFileSystem fileSystem, string packageId, SemanticVersion version) { if (version != null) { // If we know exactly what package to lookup, check if it's already installed locally. // We'll do this by checking if the package directory exists on disk. var localRepository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); var packagePaths = localRepository.GetPackageLookupPaths(packageId, version); return(packagePaths.Any(fileSystem.FileExists)); } return(false); }
/// <summary> /// Returns true if the package is already installed in the local repository. /// </summary> /// <param name="fileSystem">The file system of the local repository.</param> /// <param name="packageId">The package id.</param> /// <param name="version">The package version</param> /// <returns>True if the package is installed in the local repository.</returns> private static bool IsPackageInstalled(IFileSystem fileSystem, string packageId, SemanticVersion version) { if (version != null) { // If we know exactly what package to lookup, check if it's already installed locally. // We'll do this by checking if the package directory exists on disk. var localRepository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); var packagePaths = localRepository.GetPackageLookupPaths(packageId, version); return packagePaths.Any(fileSystem.FileExists); } return false; }
public void FindPackageReturnsPackageWithVersionedFileNameAtRoot(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var repository = new LocalPackageRepository(repositoryRoot); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void OpenPackagePrintsPathToPackageIfItCannotBeRead() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"Foo.nupkg"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act and Assert ExceptionAssert.Throws <InvalidDataException>(() => repository.GetPackages().ToList(), "Unable to read package from path 'Foo.nupkg'."); }
public void FindPackagesByIdReturnsEmptySequenceIfNoPackagesWithSpecifiedIdAreFound() { // Arramge var fileSystem = new MockFileSystem(); var pathResolver = new DefaultPackagePathResolver(fileSystem); var localPackageRepository = new LocalPackageRepository(pathResolver, fileSystem); // Act var packages = localPackageRepository.FindPackagesById("Foo"); // Assert Assert.Empty(packages); }
public static bool IsPackageInstalled(this PackageReference packageReference, PhysicalFileSystem fileSystem) { if (packageReference.Version == null) { return(false); } var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); return(repository .GetPackageLookupPaths(packageReference.Id, packageReference.Version) .Any()); }
static void Main(string[] args) { Console.Write("Enter the local repo folder (ie C:\\...\\packages\\) : "); var repoFolder = Console.ReadLine(); var repo = new LocalPackageRepository(repoFolder); IQueryable <IPackage> packages = repo.GetPackages(); OutputGraph(repo, packages, 0); Console.Write("Press enter to exit :"); Console.ReadLine(); }
public void AddPackageAddsFileToFileSystem() { // Arrange var mockFileSystem = new MockProjectSystem(); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem), mockFileSystem); IPackage package = PackageUtility.CreatePackage("A", "1.0"); // Act repository.AddPackage(package); // Assert Assert.IsTrue(mockFileSystem.FileExists(@"A.1.0\A.1.0.nupkg")); }
public void FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var fileSystem = new PhysicalFileSystem(repositoryRoot); var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void GetPackageFilesOnlyDetectsFilesWithPackageExtension() { // Arrange var mockFileSystem = new MockProjectSystem(); mockFileSystem.AddFile("foo.nupkg"); mockFileSystem.AddFile("bar.zip"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem), mockFileSystem); // Act var files = repository.GetPackageFiles().ToList(); // Assert Assert.Equal(1, files.Count); Assert.Equal("foo.nupkg", files[0]); }
public IPackageInstaller CreatePackageInstaller(string installationPath, string configurationPath) { var packagePath = this.configurationManager.PackagePath; var sourceRepository = this.source.CreatePackageRepository(); var logger = new PackageLogger(); var packagePathResolver = new DefaultPackagePathResolver(packagePath); var fileSystem = new PhysicalFileSystem(installationPath ?? this.directorySystem.CurrentDirectory) { Logger = logger }; var destinationRepository = new LocalPackageRepository(packagePath); var manager = new PackageManager( sourceRepository, packagePathResolver, fileSystem, destinationRepository) { Logger = logger }; var powerShellPackageFile = new PowerShellPackageFile( new BackgroundProcess(), manager, new PhysicalFileSystem(this.directorySystem.TemporaryPath), configurationPath); return new DefaultPackageInstaller(manager, powerShellPackageFile, logger); }
public void GetPackageFilesDetectsFilesInRootOrFirstLevelOfFolders() { // Arrange var mockFileSystem = new MockProjectSystem(); mockFileSystem.AddFile("P1.nupkg"); mockFileSystem.AddFile("bar.zip"); mockFileSystem.AddFile(PathFixUtility.FixPath(@"baz\P2.nupkg")); mockFileSystem.AddFile(PathFixUtility.FixPath(@"A\B\P3.nupkg")); mockFileSystem.AddFile(PathFixUtility.FixPath(@"A\P4.nupkg")); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem), mockFileSystem); // Act var files = repository.GetPackageFiles().ToList(); // Assert Assert.Equal(3, files.Count); Assert.Equal(PathFixUtility.FixPath(@"baz\P2.nupkg"), files[0]); Assert.Equal(PathFixUtility.FixPath(@"A\P4.nupkg"), files[1]); Assert.Equal("P1.nupkg", files[2]); }
public void FindPackageMatchesExactVersion() { // Arrange string id = "Test"; string version = "1.3.1.0"; string packageName = "Test.1.3.1.nupkg"; var repositoryRoot = CreatePackage(id, version, packageName); CreatePackage(id, "1.3.4", "Test.nupkg", repositoryRoot); // Create dummy files. Attempting to open these packages would throw, so we know we're not opening it. File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.2.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.31.nupkg"), ""); var repository = new LocalPackageRepository(repositoryRoot); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void GetPackagesOnlyRetrievesPackageFilesWhereLastModifiedIsOutOfDate() { // Arrange var mockFileSystem = new Mock<MockProjectSystem>() { CallBase = true }; var lastModified = new Dictionary<string, DateTimeOffset>(); mockFileSystem.Setup(m => m.GetLastModified("P1.nupkg")).Returns(() => lastModified["P1.nupkg"]); mockFileSystem.Setup(m => m.GetLastModified("P2.nupkg")).Returns(() => lastModified["P2.nupkg"]); mockFileSystem.Object.AddFile("P1.nupkg"); mockFileSystem.Object.AddFile("P2.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem.Object), mockFileSystem.Object); var results = new List<string>(); Func<string, IPackage> openPackage = p => { results.Add(p); string id = Path.GetFileNameWithoutExtension(p); return PackageUtility.CreatePackage(id, "1.0"); }; // Populate cache lastModified["P1.nupkg"] = GetDateTimeOffset(seconds: 30); lastModified["P2.nupkg"] = GetDateTimeOffset(seconds: 30); repository.GetPackages(openPackage).ToList(); // Verify that both packages have been created from the file system Assert.Equal(2, results.Count); results.Clear(); // Act lastModified["P1.nupkg"] = GetDateTimeOffset(seconds: 35); lastModified["P2.nupkg"] = GetDateTimeOffset(seconds: 30); repository.GetPackages(openPackage).ToList(); // Assert Assert.Equal(results.Count, 1); Assert.Equal(results[0], "P1.nupkg"); }
public void FindPackageVerifiesPackageFileExistsOnFileSystemWhenCaching() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"A.1.0.0.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: true), fileSystem, enableCaching: true); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); return PackageUtility.CreatePackage("A", "1.0"); }; // Act - 1 IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 1 Assert.NotNull(result); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.0"), result.Version); // Act - 2 fileSystem.DeleteFile("A.1.0.0.nupkg"); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 2 Assert.Null(result); }
public void FindPackagesByUsesIdFromManifestToValidateIdMatches() { // Arrange string id = "Test"; var repositoryRoot = CreatePackage(id, version: "1.2", packageFileName: "Test.1.2.nupkg"); CreatePackage(id, version: "1.3", packageFileName: "TeST.1.3.nupkg", rootDir: repositoryRoot); CreatePackage("Blah", version: "2.0.0", packageFileName: "Test.2.0.0.nupkg", rootDir: repositoryRoot); IPackageRepository repository = new LocalPackageRepository(repositoryRoot); // Act var packages = repository.FindPackagesById(id).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal("1.2", packages[0].Version.ToString()); Assert.Equal("1.3", packages[1].Version.ToString()); }
public void FindPackagesByIdThrowsIfIdIsNullOrEmpty(string id) { // Arrange var repository = new LocalPackageRepository(Mock.Of<IPackagePathResolver>(), Mock.Of<IFileSystem>()); // Act and Assert ExceptionAssert.ThrowsArgNullOrEmpty(() => repository.FindPackagesById(id), "packageId"); }
protected virtual IPackageManager CreatePackageManager(IFileSystem fileSystem) { var repository = GetRepository(); var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: AllowMultipleVersions); IPackageRepository localRepository = new LocalPackageRepository(pathResolver, fileSystem); var packageManager = new PackageManager(repository, pathResolver, fileSystem, localRepository) { Logger = Console }; return packageManager; }
public void FindPackageMatchesExactVersionIfSideBySideIsEnabled() { // Arrange var fileSystem = new Mock<MockProjectSystem> { CallBase = true }; fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.1.0\A.1.0.nupkg")))).Returns(false); fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.0.8\A.0.8.nupkg")))).Returns(false); fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.1.1\A.1.1.nupkg")))).Returns(true); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem.Object, useSideBySidePaths: true), fileSystem.Object, enableCaching: false); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); string id = Path.GetFileNameWithoutExtension(p); return PackageUtility.CreatePackage("A", "1.1"); }; // Act and Assert IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("0.8")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.1")); Assert.Equal(@"A.1.1\A.1.1.nupkg", searchedPaths.Single()); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.1"), result.Version); fileSystem.Verify(); }
public void OpenPackagePrintsPathToPackageIfItCannotBeRead() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"Foo.nupkg"); var pathResolver = new DefaultPackagePathResolver(fileSystem); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act and Assert ExceptionAssert.Throws<InvalidDataException>(() => repository.GetPackages().ToList(), "Unable to read package from path 'Foo.nupkg'."); }
public void FindPackageMatchesExactVersionIfSideBySideIsDisabled() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(PathFixUtility.FixPath(@"A\A.nupkg")); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false), fileSystem, enableCaching: false); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); return PackageUtility.CreatePackage("A", "1.1"); }; // Act and Assert IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); Assert.Null(result); Assert.Equal(PathFixUtility.FixPath(@"A\A.nupkg"), searchedPaths.Single()); searchedPaths.Clear(); result = repository.FindPackage(openPackage, "A", new SemanticVersion("0.8")); Assert.Null(result); Assert.Equal(PathFixUtility.FixPath(@"A\A.nupkg"), searchedPaths.Single()); searchedPaths.Clear(); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.1")); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.1"), result.Version); }
public void GetPackageReturnsPackagesFromNestedDirectories() { // Arrange string id = "Test"; string version = "1.3.1.0"; string packageName = @"SubDir\Test.1.3.1.nupkg"; var repositoryRoot = CreatePackage(id, version, packageName); CreatePackage(id, "1.3.4", "Test.nupkg", repositoryRoot); CreatePackage("Foo", "1.4", @"SubDir2\Test.1.4.nupkg", repositoryRoot); var repository = new LocalPackageRepository(repositoryRoot); // Act var packages = repository.GetPackages().ToList(); // Assert Assert.Equal(3, packages.Count); AssertPackage("Test", "1.3.1.0", packages[0]); AssertPackage("Foo", "1.4", packages[1]); AssertPackage("Test", "1.3.4", packages[2]); }
private void BuildPackage(Manifest manifest) { var builder = new PackageBuilder(); builder.Populate(manifest.Metadata); builder.PopulateFiles(_outputPath, manifest.Files); var file = Path.Combine(_outputPath, string.Format("{0}.{1}.nupkg", builder.Id, builder.Version)); var localRepo = new LocalPackageRepository(_outputPath, NuspecDefinition.PackageSource); if (File.Exists(file)) { File.Delete(file); } using (var buildFile = File.Open(file, FileMode.OpenOrCreate)) { builder.Save(buildFile); buildFile.Flush(); buildFile.Close(); } var package = localRepo.GetPackage(builder.Id, builder.Version); if (NuspecDefinition.PublishPackage) { localRepo.PushPackage(package); } }
public void FindPackagesByIdIgnoresPackagesThatDoNotMatchId() { // Arrange string id = "Test"; var repositoryRoot = CreatePackage(id, version: "1.2", packageFileName: "Test.1.2.nupkg"); CreatePackage(id, version: "1.3", packageFileName: "TeST.1.3.nupkg", rootDir: repositoryRoot); CreatePackage(id, version: "2.0.0.9200-alpha", packageFileName: "TEst.2.0.0.9200.nupkg", rootDir: repositoryRoot); CreatePackage("Test2", version: "2.0", packageFileName: "Test2.2.0.nupkg", rootDir: repositoryRoot); File.WriteAllBytes(Path.Combine(repositoryRoot, "NotTest.1.0.nupkg"), new byte[0]); IPackageRepository repository = new LocalPackageRepository(repositoryRoot); // Act var packages = repository.FindPackagesById(id).ToList(); // Assert Assert.Equal(3, packages.Count); Assert.Equal("1.2", packages[0].Version.ToString()); Assert.Equal("1.3", packages[1].Version.ToString()); Assert.Equal("2.0.0.9200-alpha", packages[2].Version.ToString()); }
// Do a very quick check of whether a package in installed by checked whether the nupkg file exists private static bool IsPackageInstalled(LocalPackageRepository packageRepository, IFileSystem fileSystem, string packageId, SemanticVersion version) { var packagePaths = packageRepository.GetPackageLookupPaths(packageId, version); return packagePaths.Any(fileSystem.FileExists); }
public void RemovePackageDoesNotRemovesRootIfNotEmpty() { // Arrange var mockFileSystem = new MockProjectSystem(); mockFileSystem.AddFile(PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg")); mockFileSystem.AddFile(PathFixUtility.FixPath(@"B.1.0\B.1.0.nupkg")); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem), mockFileSystem); IPackage package = PackageUtility.CreatePackage("A", "1.0"); // Act repository.RemovePackage(package); // Assert Assert.Equal(2, mockFileSystem.Deleted.Count); Assert.True(mockFileSystem.Deleted.Contains(Path.Combine(mockFileSystem.Root, @"A.1.0"))); Assert.True(mockFileSystem.Deleted.Contains(Path.Combine(mockFileSystem.Root, PathFixUtility.FixPath(@"A.1.0\A.1.0.nupkg")))); }
public void RemovePackageRemovesPackageFileAndDirectoryAndRoot() { // Arrange var mockFileSystem = new MockProjectSystem(); mockFileSystem.AddFile(@"A.1.0\A.1.0.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(mockFileSystem), mockFileSystem); IPackage package = PackageUtility.CreatePackage("A", "1.0"); // Act repository.RemovePackage(package); // Assert Assert.Equal(3, mockFileSystem.Deleted.Count); Assert.True(mockFileSystem.Deleted.Contains("")); Assert.True(mockFileSystem.Deleted.Contains("A.1.0")); Assert.True(mockFileSystem.Deleted.Contains(@"A.1.0\A.1.0.nupkg")); }
public void FindPackageReturnsPackagesWithDotInId() { // Arrange var repositoryRoot = CreatePackage("Test", "1.0.0", @"Test.1.0.0.nupkg"); CreatePackage("Test", "1.2.0", @"SubDir\Test.1.0.0.nupkg"); CreatePackage("test.extensions", "1.0", "Test.Extensions.1.0.0.0.nupkg", repositoryRoot); CreatePackage("test.extensions", "1.3.0-alpha", "Test.Extensions.1.3.0-alpha.nupkg", repositoryRoot); var repository = new LocalPackageRepository(repositoryRoot); // Act var result1 = repository.FindPackage("test.extensions", new SemanticVersion("1.0")); var result2 = repository.FindPackage("test.extensions", new SemanticVersion("1.3-alpha")); // Assert AssertPackage("test.extensions", "1.0", result1); AssertPackage("test.extensions", "1.3.0-alpha", result2); }
protected virtual IPackageManager CreatePackageManager(IFileSystem packagesFolderFileSystem, bool useSideBySidePaths) { var repository = CreateRepository(); var pathResolver = new DefaultPackagePathResolver(packagesFolderFileSystem, useSideBySidePaths); IPackageRepository localRepository = new LocalPackageRepository(pathResolver, packagesFolderFileSystem); if (EffectivePackageSaveMode != PackageSaveModes.None) { localRepository.PackageSaveMode = EffectivePackageSaveMode; } var packageManager = new PackageManager(repository, pathResolver, packagesFolderFileSystem, localRepository) { Logger = Console }; return packageManager; }