private IEnumerable <IFile> GetFiles(DirectoryPath path, PackageReference package) { var collection = new FilePathCollection(new PathComparer(_environment)); // Get default files (exe and dll). var patterns = new[] { path.FullPath + "/**/*.exe", path.FullPath + "/**/*.dll" }; foreach (var pattern in patterns) { collection.Add(_globber.GetFiles(pattern)); } // Include files. if (package.Parameters.ContainsKey("include")) { foreach (var include in package.Parameters["include"]) { var includePath = string.Concat(path.FullPath, "/", include.TrimStart('/')); collection.Add(_globber.GetFiles(includePath)); } } // Exclude files. if (package.Parameters.ContainsKey("exclude")) { foreach (var exclude in package.Parameters["exclude"]) { var excludePath = string.Concat(path.FullPath, "/", exclude.TrimStart('/')); collection.Remove(_globber.GetFiles(excludePath)); } } // Return the files. return(collection.Select(p => _fileSystem.GetFile(p)).ToArray()); }
private IReadOnlyCollection <IFile> GetAddinAssemblies(DirectoryPath path, PackageReference package) { if (!_fileSystem.Exist(path)) { return(new List <IFile>()); } // Get current framework. var provider = DefaultFrameworkNameProvider.Instance; var current = NuGetFramework.Parse(_environment.Runtime.BuiltFramework.FullName, provider); // Get all ref assemblies. var refAssemblies = _globber.GetFiles(path.FullPath + "/ref/**/*.dll"); // Get all candidate files. var pathComparer = PathComparer.Default; var assemblies = GetFiles(path, package, new[] { path.FullPath + "/**/*.dll" }) .Where(file => !"Cake.Core.dll".Equals(file.Path.GetFilename().FullPath, StringComparison.OrdinalIgnoreCase) && IsCLRAssembly(file) && !refAssemblies.Contains(file.Path, pathComparer)) .ToList(); // Iterate all found files. var comparer = new NuGetFrameworkFullComparer(); var mapping = new Dictionary <NuGetFramework, List <FilePath> >(comparer); foreach (var assembly in assemblies) { // Get relative path. var relative = path.GetRelativePath(assembly.Path); var framework = ParseFromDirectoryPath(current, relative.GetDirectory()); if (!mapping.ContainsKey(framework)) { mapping.Add(framework, new List <FilePath>()); } mapping[framework].Add(assembly.Path); } // Reduce found frameworks to the closest one. var reducer = new FrameworkReducer(); var nearest = reducer.GetNearest(current, mapping.Keys); if (nearest == null || !mapping.ContainsKey(nearest)) { return(new List <IFile>()); } if (nearest == NuGetFramework.AnyFramework) { var framework = _environment.Runtime.BuiltFramework; _log.Warning("Could not find any assemblies compatible with {0} in NuGet package {1}. " + "Falling back to using root folder of NuGet package.", framework.FullName, package.Package); } // Return the result. return(mapping[nearest].Select(p => _fileSystem.GetFile(p)).ToList()); }
private FilePath LookInToolsDirectory(string tool) { var pattern = string.Concat(GetToolsDirectory().FullPath, "/**/", tool); var toolPath = _globber.GetFiles(pattern).FirstOrDefault(); return(toolPath != null?toolPath.MakeAbsolute(_environment) : null); }
private DirectoryPath GetCakePath(DirectoryPath toolPath) { var pattern = string.Concat(toolPath.FullPath, "/**/Cake.exe"); var cakeCorePath = _globber.GetFiles(pattern).FirstOrDefault(); return(cakeCorePath?.GetDirectory().MakeAbsolute(_environment) ?? toolPath.Combine("Cake").Collapse()); }
public IEnumerable <IFile> Install(PackageDefinition package, DirectoryPath root) { var result = new List <FilePath>(); var paths = new FilePathCollection(PathComparer.Default); // InstallPackage the package. var packagePath = InstallPackage(package, root); var packageDirectory = _fileSystem.GetDirectory(packagePath); if (package.Filters != null && package.Filters.Count > 0) { // Get all files matching the filters. foreach (var filter in package.Filters) { var pattern = string.Concat(packagePath.FullPath, "/", filter.TrimStart('/', '\\')); paths.Add(_globber.GetFiles(pattern)); } } else { // Do a recursive search in the package directory. paths.Add(packageDirectory. GetFiles("*", SearchScope.Recursive) .Select(file => file.Path)); } if (paths.Count > 0) { result.AddRange(paths); } return(result.Select(path => _fileSystem.GetFile(path))); }
protected FilePath GetToolPath(TSettings settings, FilePath toolPath) { if (toolPath != null) { return(toolPath.MakeAbsolute(_environment)); } var toolExeNames = GetToolExecutableNames(); string[] pathDirs = null; // Look for each possible executable name in various places. foreach (var toolExeName in toolExeNames) { // First look in ./tools/ toolPath = _globber.GetFiles("./tools/**/" + toolExeName).FirstOrDefault(); if (toolPath != null) { return(toolPath.MakeAbsolute(_environment)); } // Cache the PATH directory list if we didn't already. if (pathDirs == null) { var pathEnv = _environment.GetEnvironmentVariable("PATH"); if (!string.IsNullOrEmpty(pathEnv)) { pathDirs = pathEnv.Split(new[] { _environment.IsUnix() ? ':' : ';' }, StringSplitOptions.RemoveEmptyEntries); } else { pathDirs = new string[] { }; } } // Look in every PATH directory for the file. foreach (var pathDir in pathDirs) { var file = new DirectoryPath(pathDir).CombineWithFilePath(toolExeName); if (_fileSystem.Exist(file)) { return(file.MakeAbsolute(_environment)); } } } // Look through all the alternative directories for the tool. var alternativePaths = GetAlternativeToolPaths(settings) ?? Enumerable.Empty <FilePath>(); foreach (var altPath in alternativePaths) { if (_fileSystem.Exist(altPath)) { return(altPath.MakeAbsolute(_environment)); } } return(null); }
private DirectoryPath GetCakePath(DirectoryPath toolPath) { // Check for local cake in tools path var pattern = string.Concat(toolPath.FullPath, "/**/Cake.exe"); var cakeCorePath = _globber.GetFiles(pattern).FirstOrDefault(); if (cakeCorePath != null) { return(cakeCorePath.GetDirectory().MakeAbsolute(_environment)); } pattern = string.Concat(toolPath.FullPath, "/**/Cake.dll"); cakeCorePath = _globber.GetFiles(pattern).FirstOrDefault(); if (cakeCorePath != null) { return(cakeCorePath.GetDirectory().MakeAbsolute(_environment)); } // Check path for cake.exe var separatorChar = _environment.Platform.Family == PlatformFamily.Windows ? ';' : ':'; var directoriesInPath = (_environment.GetEnvironmentVariable("PATH") ?? string.Empty) .Split(new[] { separatorChar }, StringSplitOptions.RemoveEmptyEntries) .Select(x => (DirectoryPath)x).ToArray(); var cakeExePath = directoriesInPath.FirstOrDefault(x => _fileSystem.Exist(x.CombineWithFilePath("Cake.exe"))); if (cakeExePath != null) { return(cakeExePath.MakeAbsolute(_environment)); } // Check path for dotnet-cake.exe var dotnetCakePath = directoriesInPath.FirstOrDefault(x => _fileSystem.Exist(x.CombineWithFilePath("dotnet-cake.exe"))) ?? directoriesInPath.FirstOrDefault(x => _fileSystem.Exist(x.CombineWithFilePath("dotnet-cake"))); if (dotnetCakePath != null) { pattern = string.Concat(dotnetCakePath.FullPath, "/.store/**/Cake.dll"); var cakeDllPath = _globber.GetFiles(pattern).FirstOrDefault(); if (cakeDllPath != null) { return(cakeDllPath.GetDirectory().MakeAbsolute(_environment)); } } return(toolPath.Combine("Cake").Collapse()); }
/// <summary> /// Parses Xml documentation example code from file(s) using given pattern /// </summary> /// <param name="pattern">The globber file pattern.</param> /// <returns>Parsed Example Code</returns> public IEnumerable <XmlDocExampleCode> ParseFiles(string pattern) { if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentNullException("pattern", "Invalid pattern supplied."); } return(_globber.GetFiles(pattern) .SelectMany(Parse)); }
/// <summary> /// Resolves the tool path. /// </summary> /// <returns> /// The tool path. /// </returns> /// <exception cref="CakeException">No nuget.exe found by resolver.</exception> public FilePath ResolveToolPath() { // Check if path allready resolved if (_nugetExeFile != null && _nugetExeFile.Exists) { return(_nugetExeFile.Path); } // Check if path set to environment variable var environmentExe = _environment.GetEnvironmentVariable("NUGET_EXE"); if (!string.IsNullOrWhiteSpace(environmentExe)) { var envFile = _fileSystem.GetFile(environmentExe); if (envFile.Exists) { return((_nugetExeFile = envFile).Path); } } // Check if tool exists in tool folder const string expression = "./tools/**/NuGet.exe"; var toolsExe = _globber.GetFiles(expression).FirstOrDefault(); if (toolsExe != null) { var toolsFile = _fileSystem.GetFile(toolsExe); if (toolsFile.Exists) { return((_nugetExeFile = toolsFile).Path); } } // Last resort try path var envPath = _environment.GetEnvironmentVariable("path"); if (!string.IsNullOrWhiteSpace(envPath)) { var pathFile = envPath .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(path => _fileSystem.GetDirectory(path)) .Where(path => path.Exists) .Select(path => path.Path.CombineWithFilePath("nuget.exe")) .Select(_fileSystem.GetFile) .FirstOrDefault(file => file.Exists); if (pathFile != null) { return((_nugetExeFile = pathFile).Path); } } throw new CakeException("No nuget.exe found by resolver."); }
public void Load(IScriptAnalyzerContext context, LoadReference reference) { FilePath path = null; if (reference.Parameters.ContainsKey("path")) { if (reference.Parameters["path"].Count == 1) { path = reference.Parameters["path"].FirstOrDefault(); } else if (reference.Parameters["path"].Count > 1) { throw new CakeException("Query string for #load contains more than one parameter 'path'."); } } if (path == null) { throw new CakeException("Query string for #load is missing parameter 'path'."); } // URL decode the path. path = new FilePath(WebUtility.UrlDecode(path.FullPath)); // Get the current script path. var current = context.Current.Path.GetDirectory(); path = path.MakeAbsolute(current); var expectedExtension = path.HasExtension ? path.GetExtension() : ".cake"; var files = _globber .GetFiles(path.FullPath) .Where(file => { var extension = file.GetExtension(); return(extension != null && (extension.Equals(".cake", StringComparison.OrdinalIgnoreCase) || extension.Equals(expectedExtension, StringComparison.OrdinalIgnoreCase))); }) .ToArray(); if (files.Length == 0) { // No scripts found. _log.Warning("No scripts found at {0}.", path); return; } foreach (var file in files) { context.Analyze(file); } }
/// <summary> /// Parses Xml documentation example code from file(s) using given pattern /// </summary> /// <param name="pattern">The globber file pattern.</param> /// <returns>Parsed Example Code</returns> public IEnumerable <XmlDocExampleCode> ParseFiles(string pattern) { if (string.IsNullOrWhiteSpace(pattern)) { throw new ArgumentNullException("pattern", "Invalid pattern supplied."); } var files = _globber.GetFiles(pattern).ToArray(); if (files.Length == 0) { _log.Verbose("The provided pattern did not match any files."); return(Enumerable.Empty <XmlDocExampleCode>()); } return(files.SelectMany(Parse)); }
/// <summary> /// Resolves the path to GitReleaseManager.exe. /// </summary> /// <returns>The path to GitReleaseManager.exe.</returns> public FilePath ResolvePath() { // Check if path already resolved if (_cachedPath != null && _cachedPath.Exists) { return(_cachedPath.Path); } // Check if tool exists in tool folder const string expression = "./tools/**/GitReleaseManager.exe"; var toolsExe = _globber.GetFiles(expression).FirstOrDefault(); if (toolsExe != null) { var toolsFile = _fileSystem.GetFile(toolsExe); if (toolsFile.Exists) { _cachedPath = toolsFile; return(_cachedPath.Path); } } // Last resort try path var envPath = _environment.GetEnvironmentVariable("path"); if (!string.IsNullOrWhiteSpace(envPath)) { var pathFile = envPath .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(path => _fileSystem.GetDirectory(path)) .Where(path => path.Exists) .Select(path => path.Path.CombineWithFilePath("GitReleaseManager.exe")) .Select(_fileSystem.GetFile) .FirstOrDefault(file => file.Exists); if (pathFile != null) { _cachedPath = pathFile; return(_cachedPath.Path); } } throw new CakeException("Could not locate GitReleaseManager.exe."); }
public IReadOnlyCollection <UnityEditorDescriptor> Seek() { var searchPattern = $"{ProgramFiles}/*Unity*/**/Editor/Unity.exe"; log.Debug("Searching for available Unity Editors..."); log.Debug("Search pattern: {0}", searchPattern); var candidates = globber.GetFiles(searchPattern).ToList(); log.Debug("Found {0} candidates.", candidates.Count); log.Debug(string.Empty); var editors = from candidatePath in candidates let version = DetermineVersion(candidatePath) where version != null select new UnityEditorDescriptor(version, candidatePath); return(editors.ToList()); }
public IEnumerable <IFile> Install(CompilerConfiguration options, bool installAddins) { var result = new List <FilePath>(); foreach (var package in options.Packages) { if (!package.IsCore && !installAddins) { continue; } var paths = new FilePathCollection(PathComparer.Default); // Install the package. var packagePath = Install(package); var packageDirectory = _fileSystem.GetDirectory(packagePath); if (package.Filters != null && package.Filters.Count > 0) { // Get all files matching the filters. foreach (var filter in package.Filters) { var pattern = string.Concat(packagePath.FullPath, "/", filter.TrimStart('/', '\\')); paths.Add(_globber.GetFiles(pattern)); } } else { // Do a recursive search in the package directory. paths.Add(packageDirectory. GetFiles("*", SearchScope.Recursive) .Select(file => file.Path)); } if (paths.Count > 0) { result.AddRange(paths); } } return(result.Select(path => _fileSystem.GetFile(path))); }
/// <summary> /// Gets alternative file paths which the tool may exist in /// </summary> /// <param name="settings">The settings.</param> /// <returns>The default tool path.</returns> protected override IEnumerable <FilePath> GetAlternativeToolPaths(CakeSettings settings) { const string homebrewCakePath = "/usr/local/Cellar/cake/"; if (!_environment.IsUnix()) { return(Enumerable.Empty <FilePath>()); } if (!_fileSystem.Exist(new DirectoryPath(homebrewCakePath))) { return(Enumerable.Empty <FilePath>()); } var files = _globber.GetFiles(homebrewCakePath + "**/Cake.exe"); var filePaths = files as FilePath[] ?? files.ToArray(); return(filePaths.Length == 0 ? Enumerable.Empty <FilePath>() : filePaths.OrderByDescending(f => f.FullPath)); }
public void PatchAllAssemblyInfo(VersionResult versionInfo, string copyrightText) { var parser = new AssemblyInfoParser(_fileSystem, _environment); var creator = new AssemblyInfoCreator(_fileSystem, _environment, _log); var assemblyFiles = _globber.GetFiles("./**/AssemblyInfo.cs"); foreach (var file in assemblyFiles) { _log.Verbose($"Possibly file to patch:{file}"); if (file.ToString().Contains("packages/")) { continue; } var assemblyInfo = parser.Parse(file); string rootVersion = versionInfo.RootVersion; //on AppVeyor, if it is a PullRequest and "pull_requests: do_not_increment_build_number" is true, it will make up a build like 1.0.2-fisiek //It does this because it requires unique version numbers. //So, what is in RootVersion has this 'prerelease' tag of 'fisiek' or whatever on it. This is not valid when versioning assembiles! //we of course are not going to publish prereleases to nuget, so just make up any version for this. //if do_not_increment_build_number is false, then the version does NOT contain the extra tag and it does not matter. //of course we do not know if this is true or false. So we will just look... if (IsPullRequest && rootVersion.Contains("-")) { rootVersion = "1.0.1"; } _log.Information($"Creating File Version:{rootVersion} Info Version:{versionInfo.FullVersion} for {file} "); creator.Create(file, new AssemblyInfoSettings { Product = assemblyInfo.Product, Version = rootVersion, FileVersion = rootVersion, InformationalVersion = versionInfo.FullVersion, Copyright = string.Format(copyrightText, DateTime.Now.Year) }); } }
/// <summary> /// Resolves the path to nuget.exe. /// </summary> /// <returns>The path to nuget.exe.</returns> public FilePath ResolvePath() { // Check if path allready resolved if (_cachedPath != null && _cachedPath.Exists) { return(_cachedPath.Path); } // Check if tool exists in tool folder const string expression = "./tools/**/NuGet.exe"; var toolsExe = _globber.GetFiles(expression).FirstOrDefault(); if (toolsExe != null) { var toolsFile = _fileSystem.GetFile(toolsExe); if (toolsFile.Exists) { _cachedPath = toolsFile; return(_cachedPath.Path); } } // Check if path set to environment variable var environmentExe = _environment.GetEnvironmentVariable("NUGET_EXE"); if (!string.IsNullOrWhiteSpace(environmentExe)) { var envFile = _fileSystem.GetFile(environmentExe); if (envFile.Exists) { _cachedPath = envFile; return(_cachedPath.Path); } } // On Unix /usr/bin/nuget is a viable option if (_environment.IsUnix()) { var nugetUnixPath = new FilePath("/usr/bin/nuget"); if (_fileSystem.Exist(nugetUnixPath)) { _cachedPath = _fileSystem.GetFile(nugetUnixPath); return(_cachedPath.Path); } } // Last resort try path var envPath = _environment.GetEnvironmentVariable("path"); if (!string.IsNullOrWhiteSpace(envPath)) { var pathFile = envPath .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(path => _fileSystem.GetDirectory(path)) .Where(path => path.Exists) .Select(path => path.Path.CombineWithFilePath("nuget.exe")) .Select(_fileSystem.GetFile) .FirstOrDefault(file => file.Exists); if (pathFile != null) { _cachedPath = pathFile; return(_cachedPath.Path); } } throw new CakeException("Could not locate nuget.exe."); }
public static IEnumerable <FilePath> GetFiles(string pattern) => Globber.GetFiles(pattern);
/// <summary> /// Gets the default tool path. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The default tool path.</returns> protected override FilePath GetDefaultToolPath(XUnitSettings settings) { return(_globber.GetFiles("./tools/**/xunit.console.clr4.exe").FirstOrDefault()); }
/// <summary> /// Gets the default tool path. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The default tool path.</returns> protected override FilePath GetDefaultToolPath(CakeSettings settings) { const string expression = "./tools/**/Cake.exe"; return(_globber.GetFiles(expression).FirstOrDefault()); }
private DirectoryPath GetCakePath(DirectoryPath toolPath) { // Check for local cake in tools path var pattern = string.Concat(toolPath.FullPath, "/**/Cake.exe"); var cakeCorePath = _globber.GetFiles(pattern).FirstOrDefault(); if (cakeCorePath != null) { return(cakeCorePath.GetDirectory().MakeAbsolute(_environment)); } pattern = string.Concat(toolPath.FullPath, "/**/Cake.dll"); cakeCorePath = _globber.GetFiles(pattern).FirstOrDefault(); if (cakeCorePath != null) { return(cakeCorePath.GetDirectory().MakeAbsolute(_environment)); } // get .dotnet/tools default installation folder var userDotNetToolsPaths = new[] { "USERPROFILE", "HOME" } .Select(env => _environment.GetEnvironmentVariable(env)) .Where(x => x != null) .Distinct() .Select(x => ((DirectoryPath)x).Combine(".dotnet/tools")) .Where(x => _fileSystem.Exist(x)) .ToArray(); // get all directories in PATH var separatorChar = _environment.Platform.Family == PlatformFamily.Windows ? ';' : ':'; var directoriesInPath = (_environment.GetEnvironmentVariable("PATH") ?? string.Empty) .Split(new[] { separatorChar }, StringSplitOptions.RemoveEmptyEntries) .Select(x => (DirectoryPath)x).ToArray(); // Check DotNetToolsPath and PATH for dotnet-cake[.exe] var dotnetCakePath = new[] { "dotnet-cake.exe", "dotnet-cake" } .SelectMany(exe => userDotNetToolsPaths .Union(directoriesInPath) .Select(dir => dir.CombineWithFilePath(exe))) .FirstOrDefault(x => _fileSystem.Exist(x))?.GetDirectory(); if (dotnetCakePath != null) { pattern = string.Concat(dotnetCakePath.FullPath, "/.store/**/^{netcoreapp3.1,netcoreapp2.1}/**/Cake.dll"); var cakeDllPath = _globber.GetFiles(pattern).LastOrDefault(); if (cakeDllPath != null) { return(cakeDllPath.GetDirectory().MakeAbsolute(_environment)); } } // Check PATH for cake.exe var cakeExePath = directoriesInPath.FirstOrDefault(x => _fileSystem.Exist(x.CombineWithFilePath("Cake.exe"))); if (cakeExePath != null) { return(cakeExePath.MakeAbsolute(_environment)); } return(toolPath.Combine("Cake").Collapse()); }
/// <summary> /// Gets the default tool path. /// </summary> /// <returns>The default tool path.</returns> protected override FilePath GetDefaultToolPath(XUnitSettings settings) { const string expression = "./tools/**/xunit.console.clr4.exe"; return(_globber.GetFiles(expression).FirstOrDefault()); }