protected NuGetFixture() { Environment = FakeEnvironment.CreateUnixEnvironment(); Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/nuget.exe").Returns(new[] { (FilePath)"/Working/tools/NuGet.exe" }); Globber.Match("./tools/**/NuGet.exe").Returns(new[] { (FilePath)"/Working/tools/NuGet.exe" }); NuGetToolResolver = Substitute.For <INuGetToolResolver>(); Log = Substitute.For <ICakeLog>(); FileSystem = new FakeFileSystem(Environment); // By default, there is a default tool. NuGetToolResolver.ResolvePath().Returns("/Working/tools/NuGet.exe"); FileSystem.CreateFile("/Working/tools/NuGet.exe"); // Set standard output. Process.GetStandardOutput().Returns(new string[0]); }
/// <summary> /// Gets all directories matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern.</param> /// <returns>The directories matching the specified pattern.</returns> public static IEnumerable <DirectoryPath> GetDirectories(this IGlobber globber, string pattern) { if (globber == null) { throw new ArgumentNullException("globber"); } return(globber.Match(pattern).OfType <DirectoryPath>()); }
/// <summary> /// Returns <see cref="Path" /> instances matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern to match.</param> /// <returns> /// <see cref="Path" /> instances matching the specified pattern. /// </returns> public static IEnumerable <Path> Match(this IGlobber globber, string pattern) { if (globber == null) { throw new ArgumentNullException(nameof(globber)); } return(globber.Match(pattern, new GlobberSettings())); }
/// <summary> /// Gets all files matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern.</param> /// <returns>The files matching the specified pattern.</returns> public static IEnumerable <FilePath> GetFiles(this IGlobber globber, string pattern) { if (globber == null) { throw new ArgumentNullException(nameof(globber)); } return(globber.Match(pattern).OfType <FilePath>()); }
/// <summary> /// Returns <see cref="Path" /> instances matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern to match.</param> /// <returns> /// <see cref="Path" /> instances matching the specified pattern. /// </returns> public static IEnumerable <Path> Match(this IGlobber globber, string pattern) { if (globber == null) { throw new ArgumentNullException("globber"); } return(globber.Match(pattern, null)); }
private IEnumerable <FilePath> FindProjects(string folder) { var root = new DirectoryPath(folder).MakeAbsolute(_environment); var globberSettings = new GlobberSettings { Comparer = new PathComparer(false), Root = root }; return(_globber.Match(@"**/*.{c|f}sproj", globberSettings).OfType <FilePath>()); }
private void Install(SemanticVersion version) { var root = _environment.GetApplicationRoot().MakeAbsolute(_environment); var installRoot = root.Combine(Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)); var packages = new Dictionary <string, SemanticVersion> { { "Microsoft.CodeAnalysis.Scripting", version }, { "Microsoft.CodeAnalysis.CSharp", version } }; // Install package. var nugetSource = _configuration.GetValue("Roslyn_NuGetSource") ?? "https://packages.nuget.org/api/v2"; var repo = PackageRepositoryFactory.Default.CreateRepository(nugetSource); var packageManager = new PackageManager(repo, installRoot.FullPath); _log.Verbose("Installing packages (using {0})...", nugetSource); foreach (var package in packages) { _log.Information("Downloading package {0} ({1})...", package.Key, package.Value); packageManager.InstallPackage(package.Key, package.Value, false, true); } // Copy files. _log.Verbose("Copying files..."); foreach (var path in _paths) { // Find the file within the temporary directory. var exp = string.Concat(installRoot.FullPath, "/**/", path); var foundFile = _globber.Match(exp).FirstOrDefault(); if (foundFile == null) { var format = "Could not find file {0}."; var message = string.Format(CultureInfo.InvariantCulture, format, path); throw new CakeException(message); } var source = _fileSystem.GetFile((FilePath)foundFile); var destination = _fileSystem.GetFile(root.CombineWithFilePath(path.GetFilename())); _log.Information("Copying {0}...", source.Path.GetFilename()); if (!destination.Exists) { source.Copy(destination.Path, true); } } // Delete the install directory. _log.Verbose("Deleting installation directory..."); _fileSystem.GetDirectory(installRoot).Delete(true); }
public WiXFixture(FilePath toolPath = null) { Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory = "/Working"; Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/candle.exe").Returns(new[] { (FilePath)"/Working/tools/candle.exe" }); Globber.Match("./tools/**/light.exe").Returns(new[] { (FilePath)"/Working/tools/light.exe" }); FileSystem = Substitute.For <IFileSystem>(); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/candle.exe")).Returns(true); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/light.exe")).Returns(true); if (toolPath != null) { FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true); } }
private FilePath?FindProgram(ProjectInformation project) { var directory = project.Path.GetDirectory(); var result = _globber.Match("**/Program.{f|c}s", new GlobberSettings { Root = directory }).OfType <FilePath>().ToList(); if (result.Count == 0) { AnsiConsole.Markup("[red]Error:[/] Could not find Program.cs for example [underline]{0}[/].", project.Name); return(null); } if (result.Count > 1) { AnsiConsole.Markup("[red]Error:[/] Found multiple Program.cs for example [underline]{0}[/].", project.Name); return(null); } return(result.First()); }
public XUnitRunnerFixture(FilePath toolPath = null, bool defaultToolExist = true) { Process = Substitute.For <IProcess>(); Process.GetExitCode().Returns(0); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Environment = Substitute.For <ICakeEnvironment>(); Environment.WorkingDirectory = "/Working"; Globber = Substitute.For <IGlobber>(); Globber.Match("./tools/**/xunit.console.clr4.exe").Returns(new[] { (FilePath)"/Working/tools/xunit.console.clr4.exe" }); FileSystem = Substitute.For <IFileSystem>(); FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/xunit.console.clr4.exe")).Returns(defaultToolExist); if (toolPath != null) { FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true); } }
/// <summary> /// Returns <see cref="Path" /> instances matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern to match.</param> /// <returns> /// <see cref="Path" /> instances matching the specified pattern. /// </returns> public static IEnumerable <Path> Match(this IGlobber globber, string pattern) { return(globber.Match(pattern, null)); }
public int Process(DirectoryPath root, DirectoryPath repository, string version) { var comparer = new PathComparer(_environment); var regex = new Regex(Pattern); var toolPackages = repository.CombineWithFilePath(new FilePath("tools/packages.config")); var packageFiles = _globber.Match("**/packages.config", new GlobberSettings { Root = repository, Comparer = comparer }).OfType <FilePath>(); var processed = 0; foreach (var packageFile in packageFiles) { _log.Write("Processing {0}...", packageFile); using (var scope = _log.Indent()) { if (comparer.Equals(packageFile, toolPackages)) { scope.Write("Skipping packages.config in tools."); continue; } if (!_nuget.Restore(scope, root, packageFile)) { scope.Error("Could not restore NuGet package."); throw new InvalidOperationException("An error occured when restoring packages!"); } // Read the file contents. string contents; using (var stream = _filesystem.File.OpenRead(packageFile)) using (var reader = new StreamReader(stream)) { contents = reader.ReadToEnd(); } // Find all packages that need to be updated. var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var match = regex.Match(contents); if (match.Success) { while (match.Success) { var package = match.Groups["package"].Value; if (package == "Cake.Core" || package == "Cake.Testing") { result.Add(package); } match = match.NextMatch(); } processed++; } foreach (var package in result) { if (!_nuget.Update(scope, root, packageFile, package, version)) { scope.Error("Could not update package '{0}' in file '{1}'.", package, packageFile); throw new InvalidOperationException("An error occured when updating package!"); } } } } return(processed); }
/// <summary> /// Gets all directories matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern.</param> /// <returns>The directories matching the specified pattern.</returns> public static IEnumerable <DirectoryPath> GetDirectories(this IGlobber globber, string pattern) { return(globber.Match(pattern).OfType <DirectoryPath>()); }
/// <summary> /// Gets all files matching the specified pattern. /// </summary> /// <param name="globber">The globber.</param> /// <param name="pattern">The pattern.</param> /// <returns>The files matching the specified pattern.</returns> public static IEnumerable <FilePath> GetFiles(this IGlobber globber, string pattern) { return(globber.Match(pattern).OfType <FilePath>()); }