コード例 #1
0
        /// <summary>
        /// Configure the optimizer
        /// </summary>
        /// <param name="environment">The environment.</param>
        public void Configure(ICakeEnvironment environment)
        {
            this.Key = environment.GetEnvironmentVariable("PUNYPNG_KEY");

            this.Timeout  = Convert.ToInt32(environment.GetEnvironmentVariable("PUNYPNG_TIMEOUT"));
            this.FileSize = Convert.ToInt32(environment.GetEnvironmentVariable("PUNYPNG_FILESIZE"));
        }
コード例 #2
0
        public static bool SupportsAnsi(ICakeEnvironment environment)
        {
            // Github action doesn't setup a correct PTY but supports ANSI.
            if (!string.IsNullOrWhiteSpace(environment.GetEnvironmentVariable("GITHUB_ACTION")))
            {
                return(true);
            }

            // Running on Windows?
            if (environment.Platform.Family == PlatformFamily.Windows)
            {
                // Running under ConEmu?
                var conEmu = environment.GetEnvironmentVariable("ConEmuANSI");
                if (!string.IsNullOrEmpty(conEmu) && conEmu.Equals("On", StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                return(Windows.SupportsAnsi());
            }

            // Check if the terminal is of type ANSI/VT100/xterm compatible.
            var term = environment.GetEnvironmentVariable("TERM");

            if (!string.IsNullOrWhiteSpace(term))
            {
                if (_regexes.Any(regex => regex.IsMatch(term)))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Collects all the files for the given dotnet Tool Package.
        /// </summary>
        /// <param name="package">The dotnet Tool Package.</param>
        /// <param name="type">The type of dotnet Tool Package.</param>
        /// <returns>All the files for the Package.</returns>
        public IReadOnlyCollection <IFile> GetFiles(PackageReference package, PackageType type)
        {
            if (type == PackageType.Addin)
            {
                throw new InvalidOperationException("DotNetTool Module does not support Addins'");
            }

            if (type == PackageType.Tool)
            {
                if (package.Parameters.ContainsKey("global"))
                {
                    if (_environment.Platform.IsUnix())
                    {
                        return(GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("HOME")).Combine(".dotnet/tools"), package));
                    }
                    else
                    {
                        return(GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE")).Combine(".dotnet/tools"), package));
                    }
                }
                else
                {
                    return(GetToolFiles(_config.GetToolPath(_environment.WorkingDirectory, _environment), package));
                }
            }

            throw new InvalidOperationException("Unknown resource type.");
        }
コード例 #4
0
        /// <summary>
        /// Helper method to get the AWS Credentials from environment variables
        /// </summary>
        /// <param name="environment">The cake environment.</param>
        /// <param name="settings">The S3 settings.</param>
        /// <returns>The same <see cref="S3Settings"/> instance so that multiple calls can be chained.</returns>
        private static T SetSettings <T>(this ICakeEnvironment environment, T settings) where T : S3Settings
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            //AWS Fallback
            AWSCredentials creds = FallbackCredentialsFactory.GetCredentials();

            if (creds != null)
            {
                settings.Credentials = creds;
            }

            //Environment Variables
            settings.EncryptionKey = environment.GetEnvironmentVariable("AWS_ENCRYPTION_KEY");

            string region = environment.GetEnvironmentVariable("AWS_REGION");

            if (!String.IsNullOrEmpty(region))
            {
                settings.Region = RegionEndpoint.GetBySystemName(region);
            }

            return(settings);
        }
コード例 #5
0
        /// <summary>
        /// Gets the alternative tool paths for the tool
        /// </summary>
        /// <param name="settings"></param>
        /// <returns>The alternate tool paths</returns>
        protected override IEnumerable <FilePath> GetAlternativeToolPaths(CoverletSettings settings)
        {
            var globalToolLocation = _environment.Platform.IsUnix()
                ? new DirectoryPath(_environment.GetEnvironmentVariable("HOME"))
                : new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE"));

            return(GetToolExecutableNames()
                   .Select(name => globalToolLocation.Combine(".dotnet/tools").GetFilePath(name)));
        }
コード例 #6
0
        /// <summary>
        /// Resolves the path to upack.exe.
        /// </summary>
        /// <returns>The path to upack.exe.</returns>
        public FilePath ResolvePath()
        {
            // Check if path allready resolved
            if (_cachedPath != null && _cachedPath.Exists)
            {
                return(_cachedPath.Path);
            }

            // Try to resolve it with the regular tool resolver.
            var toolsExe = _tools.Resolve(UPackExe);

            if (toolsExe != null)
            {
                var toolsFile = _fileSystem.GetFile(toolsExe);
                if (toolsFile.Exists)
                {
                    _cachedPath = toolsFile;
                    return(_cachedPath.Path);
                }
            }

            // Check if path set to environment variable
            var upackInstallationFolder = _environment.GetEnvironmentVariable("UPackInstall");

            if (!string.IsNullOrWhiteSpace(upackInstallationFolder))
            {
                var envFile = _fileSystem.GetFile(System.IO.Path.Combine(upackInstallationFolder, UPackExe));
                if (envFile.Exists)
                {
                    _cachedPath = envFile;
                    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(UPackExe))
                               .Select(_fileSystem.GetFile)
                               .FirstOrDefault(file => file.Exists);

                if (pathFile != null)
                {
                    _cachedPath = pathFile;
                    return(_cachedPath.Path);
                }
            }

            throw new CakeException("Could not locate upack.exe.");
        }
コード例 #7
0
        /// <summary>
        /// Configure the optimizer
        /// </summary>
        /// <param name="environment">The environment.</param>
        public void Configure(ICakeEnvironment environment)
        {
            this.ApiKey    = environment.GetEnvironmentVariable("KRAKEN_API_KEY");
            this.SecretKey = environment.GetEnvironmentVariable("KRAKEN_SECRET_KEY");

            this.Lossy = Convert.ToBoolean(environment.GetEnvironmentVariable("KRAKEN_LOSSY"));

            this.Timeout  = Convert.ToInt32(environment.GetEnvironmentVariable("KRAKEN_TIMEOUT"));
            this.FileSize = Convert.ToInt32(environment.GetEnvironmentVariable("KRAKEN_FILESIZE"));
        }
コード例 #8
0
        public BitbucketPipelinesInfoFixture()
        {
            Environment = Substitute.For <ICakeEnvironment>();

            // BitbucketPipelines RepositoryInfo
            Environment.GetEnvironmentVariable("BITBUCKET_COMMIT").Returns("4efbc1ffb993dfbcf024e6a9202865cc0b6d9c50");
            Environment.GetEnvironmentVariable("BITBUCKET_REPO_SLUG").Returns("cake");
            Environment.GetEnvironmentVariable("BITBUCKET_REPO_OWNER").Returns("cakebuild");
            Environment.GetEnvironmentVariable("BITBUCKET_BRANCH").Returns("develop");
            Environment.GetEnvironmentVariable("BITBUCKET_TAG").Returns("BitbucketPipelines");
        }
コード例 #9
0
        public TeamCityInfoFixture()
        {
            Environment = Substitute.For <ICakeEnvironment>();

            Environment.GetEnvironmentVariable("TEAMCITY_BUILDCONF_NAME").Returns(@"Cake Build");
            Environment.GetEnvironmentVariable("BUILD_NUMBER").Returns("10-Foo");

            Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME").Returns("Cake");

            Environment.GetEnvironmentVariable("Git_Branch").Returns("refs/pull-requests/7/from");
        }
コード例 #10
0
        /// <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.");
        }
コード例 #11
0
        /// <summary>
        /// Resolves the path to vsce..
        /// </summary>
        /// <returns>The path to vsce.</returns>
        public FilePath ResolvePath()
        {
            // Check if path allready resolved
            if (_cachedPath != null && _cachedPath.Exists)
            {
                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("vsce.cmd"))
                               .Select(_fileSystem.GetFile)
                               .FirstOrDefault(file => file.Exists);

                if (pathFile != null)
                {
                    _cachedPath = pathFile;
                    return(_cachedPath.Path);
                }
            }

            throw new CakeException("Could not locate vsce.");
        }
コード例 #12
0
ファイル: CakeRunner.cs プロジェクト: natificent/cake
        public void ExecuteExpression(string cakeExpression, CakeSettings settings = null)
        {
            if (string.IsNullOrWhiteSpace(cakeExpression))
            {
                throw new ArgumentNullException("cakeExpression");
            }
            DirectoryPath tempPath       = _environment.GetEnvironmentVariable("TEMP") ?? "./";
            var           tempScriptFile = _fileSystem.GetFile(tempPath
                                                               .CombineWithFilePath(string.Format(CultureInfo.InvariantCulture, "{0}.cake", Guid.NewGuid()))
                                                               .MakeAbsolute(_environment));

            try
            {
                using (var stream = tempScriptFile.OpenWrite())
                {
                    using (var streamWriter = new StreamWriter(stream, Encoding.UTF8))
                    {
                        streamWriter.WriteLine(cakeExpression);
                    }
                }
                ExecuteScript(tempScriptFile.Path.FullPath, settings);
            }
            finally
            {
                if (tempScriptFile.Exists)
                {
                    tempScriptFile.Delete();
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Helper method to get the AWS Credentials from environment variables
        /// </summary>
        /// <param name="environment">The cake environment.</param>
        /// <returns>A new <see cref="EC2Settings"/> instance to be used in calls to the <see cref="IEC2Manager"/>.</returns>
        public static EC2Settings CreateEC2Settings(this ICakeEnvironment environment)
        {
            if (environment == null)
            {
                throw new ArgumentNullException("environment");
            }

            EC2Settings settings = new EC2Settings();

            //AWS Fallback
            AWSCredentials creds = FallbackCredentialsFactory.GetCredentials();

            if (creds != null)
            {
                settings.Credentials = creds;
            }

            //Environment Variables
            string region = environment.GetEnvironmentVariable("AWS_REGION");

            if (!String.IsNullOrEmpty(region))
            {
                settings.Region = RegionEndpoint.GetBySystemName(region);
            }

            return(settings);
        }
コード例 #14
0
        /// <summary>
        /// Uploads test results XML file to AppVeyor. Results type can be one of the following: mstest, xunit, nunit, nunit3, junit.
        /// </summary>
        /// <param name="path">The file path of the test results XML to upload.</param>
        /// <param name="resultsType">The results type. Can be mstest, xunit, nunit, nunit3 or junit.</param>
        public void UploadTestResults(FilePath path, AppVeyorTestResultsType resultsType)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (!IsRunningOnAppVeyor)
            {
                throw new CakeException("The current build is not running on AppVeyor.");
            }

            var baseUri = _environment.GetEnvironmentVariable("APPVEYOR_URL").TrimEnd('/');

            if (string.IsNullOrWhiteSpace(baseUri))
            {
                throw new CakeException("Failed to get AppVeyor API url.");
            }

            var url = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/api/testresults/{1}/{2}", baseUri, resultsType, Environment.JobId).ToLowerInvariant());

            _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Uploading [{0}] to [{1}]", path.FullPath, url);
            Task.Run(async() =>
            {
                using (var client = new HttpClient())
                {
                    var response = await client.UploadFileAsync(url, path.FullPath, "text/xml");
                    var content  = await response.Content.ReadAsStringAsync();
                    _cakeLog.Write(Verbosity.Diagnostic, LogLevel.Verbose, "Server response [{0}:{1}]:\n\r{2}", response.StatusCode, response.ReasonPhrase, content);
                }
            }).Wait();
        }
コード例 #15
0
ファイル: AppVeyorProvider.cs プロジェクト: qhris/cake
        /// <summary>
        /// Uploads test results XML file to AppVeyor. Results type can be one of the following: mstest, xunit, nunit, nunit3, junit.
        /// </summary>
        /// <param name="path">The file path of the test results XML to upload.</param>
        /// <param name="resultsType">The results type. Can be mstest, xunit, nunit, nunit3 or junit.</param>
        public void UploadTestResults(FilePath path, AppVeyorTestResultsType resultsType)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (!IsRunningOnAppVeyor)
            {
                throw new CakeException("The current build is not running on AppVeyor.");
            }

            var baseUri = _environment.GetEnvironmentVariable("APPVEYOR_URL").TrimEnd('/');

            if (string.IsNullOrWhiteSpace(baseUri))
            {
                throw new CakeException("Failed to get AppVeyor API url.");
            }

            var url = string.Format(CultureInfo.InvariantCulture, "{0}/api/testresults/{1}/{2}", baseUri, resultsType, Environment.JobId);

            using (var stream = File.OpenRead(path.FullPath))
                using (var client = new HttpClient())
                {
                    client.PostAsync(url, new StreamContent(stream)).Wait();
                }
        }
コード例 #16
0
        private IFile SafeResolvePath()
        {
            // Try to resolve it with the regular tool resolver.
            var toolsExe = _tools.Resolve(AmmExe);

            if (toolsExe != null)
            {
                var toolsFile = _fileSystem.GetFile(toolsExe);
                if (toolsFile.Exists)
                {
                    return(toolsFile);
                }
            }

            // Check if path set to environment variable
            var acsFolder = _environment.GetEnvironmentVariable("ApprendaAMMInstall");

            if (!string.IsNullOrWhiteSpace(acsFolder))
            {
                var envFile = _fileSystem.GetFile(System.IO.Path.Combine(acsFolder, AmmExe));
                if (envFile.Exists)
                {
                    return(envFile);
                }
            }

            // try looking in locationes defined in 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(AmmExe))
                               .Select(_fileSystem.GetFile)
                               .FirstOrDefault(file => file.Exists);

                if (pathFile != null)
                {
                    return(pathFile);
                }
            }

            throw new CakeException($"Could not locate {AmmExe}.");
        }
コード例 #17
0
ファイル: Tool.cs プロジェクト: SharpeRAD/Cake
        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);
        }
コード例 #18
0
        public EnvironmentExtensionsTests()
        {
            environment = A.Fake <ICakeEnvironment>();
            A.CallTo(() => environment.GetEnvironmentVariable(TestVariableName)).Returns(TestVariableValue);

            cakeContext = A.Fake <ICakeContext>();
            A.CallTo(() => cakeContext.Environment).Returns(environment);
        }
コード例 #19
0
ファイル: MSTestRunner.cs プロジェクト: worming004/cake
        private FilePath GetCommonToolPath(string environmentVariable)
        {
            var visualStudioCommonToolsPath = _environment.GetEnvironmentVariable(environmentVariable);

            if (string.IsNullOrWhiteSpace(visualStudioCommonToolsPath))
            {
                return(null);
            }

            var root = new DirectoryPath(visualStudioCommonToolsPath).Combine("../IDE").Collapse();

            return(root.CombineWithFilePath("mstest.exe"));
        }
コード例 #20
0
        private List <DirectoryPath> GetPathDirectories()
        {
            var result = new List <DirectoryPath>();
            var path   = _environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(path))
            {
                var separator = new[] { _environment.Platform.IsUnix() ? ':' : ';' };
                var paths     = path.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                result.AddRange(paths.Select(p => new DirectoryPath(p)));
            }

            return(result);
        }
コード例 #21
0
ファイル: AnsiDetector.cs プロジェクト: weiplanet/cake
        public static bool SupportsAnsi(ICakeEnvironment environment)
        {
            // Prevents the addition of ANSI color if NO_COLOR env. variable is present
            // https://no-color.org
            if (!string.IsNullOrWhiteSpace(environment.GetEnvironmentVariable("NO_COLOR")))
            {
                return(false);
            }

            // Github action doesn't setup a correct PTY but supports ANSI.
            if (!string.IsNullOrWhiteSpace(environment.GetEnvironmentVariable("GITHUB_ACTION")))
            {
                return(true);
            }

            // Azure Pipelines doesn't set the TERM environment variable but supports ANSI
            // https://github.com/microsoft/azure-pipelines-agent/issues/1569
            if (!string.IsNullOrWhiteSpace(environment.GetEnvironmentVariable("TF_BUILD")))
            {
                return(true);
            }

            // TeamCity doesn't set the TERM environment variable but supports ANSI since 9.1
            // https://blog.jetbrains.com/teamcity/2015/07/teamcity-9-1-release-truly-historical-and-very-personal-builds/
            var teamCityVersion = environment.GetEnvironmentVariable("TEAMCITY_VERSION");

            if (!string.IsNullOrWhiteSpace(teamCityVersion) && _teamCityVersionWithAnsiSupportRegEx.IsMatch(teamCityVersion))
            {
                return(true);
            }

            // Check if the terminal is of type ANSI/VT100/xterm compatible.
            var term = environment.GetEnvironmentVariable("TERM");

            if (!string.IsNullOrWhiteSpace(term))
            {
                if (_regexes.Any(regex => regex.IsMatch(term)))
                {
                    return(true);
                }
            }

            // Running on Windows?
            if (environment.Platform.Family == PlatformFamily.Windows)
            {
                // Running under ConEmu?
                var conEmu = environment.GetEnvironmentVariable("ConEmuANSI");
                if (!string.IsNullOrEmpty(conEmu) && conEmu.Equals("On", StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                return(Windows.SupportsAnsi());
            }

            return(false);
        }
コード例 #22
0
        /// <summary>
        /// Resolves the path to nuget.exe.
        /// </summary>
        /// <returns>The path to nuget.exe.</returns>
        public FilePath ResolvePath()
        {
            // Check if path already resolved
            if (_cachedPath != null && _cachedPath.Exists)
            {
                return(_cachedPath.Path);
            }

            // Try to resolve it with the regular tool resolver.
            var toolsExe = _tools.Resolve("nuget.exe");

            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 or /usr/local/bin/nuget are viable options
            if (_environment.IsUnix())
            {
                foreach (var systemPath in _unixSystemPaths)
                {
                    if (_fileSystem.Exist(systemPath))
                    {
                        _cachedPath = _fileSystem.GetFile(systemPath);
                        return(_cachedPath.Path);
                    }
                }
            }

            throw new CakeException("Could not locate nuget.exe.");
        }
コード例 #23
0
        public string GetEnvironmentVariable(string name, string defaultValue = null)
        {
            if (!(_overrides is null) && _overrides.TryGetValue(name, out var value))
            {
                return(string.IsNullOrWhiteSpace(value) ? defaultValue : value);
            }

            value = _cakeEnvironment.GetEnvironmentVariable(name);
            if (!string.IsNullOrWhiteSpace(value))
            {
                return(value);
            }

            return(defaultValue);
        }
コード例 #24
0
ファイル: CakeScriptGenerator.cs プロジェクト: nils-a/bakery
        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());
        }
コード例 #25
0
        /// <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.");
        }
コード例 #26
0
        private IReadOnlyCollection <IFile> GetToolFiles(PackageReference package)
        {
            var result = new List <IFile>();
            var chocoInstallLocation = _environment.GetEnvironmentVariable("ChocolateyInstall");

            if (string.IsNullOrWhiteSpace(chocoInstallLocation))
            {
                throw new InvalidOperationException("Chocolatey does not appear to be installed.");
            }

            var toolDirectory = _fileSystem.GetDirectory(chocoInstallLocation + "/lib/" + package.Package);

            if (toolDirectory.Exists)
            {
                result.AddRange(GetFiles(toolDirectory.Path.FullPath, package));
            }

            return(result);
        }
コード例 #27
0
        protected override IEnumerable <FilePath> GetAlternativeToolPaths(AndroidEmulatorToolSettings settings)
        {
            var results = new List <FilePath>();

            var ext         = environment.Platform.Family == PlatformFamily.Windows ? ".exe" : "";
            var androidHome = settings.SdkRoot?.MakeAbsolute(environment)?.FullPath;

            if (string.IsNullOrEmpty(androidHome) || !System.IO.Directory.Exists(androidHome))
            {
                androidHome = environment.GetEnvironmentVariable("ANDROID_HOME");
            }

            if (!string.IsNullOrEmpty(androidHome) && System.IO.Directory.Exists(androidHome))
            {
                var exe = new DirectoryPath(androidHome).Combine("emulator").CombineWithFilePath("emulator" + ext);
                results.Add(exe);
            }

            return(results);
        }
コード例 #28
0
        protected override IEnumerable <FilePath> GetAlternativeToolPaths(AndroidSdkManagerToolSettings settings)
        {
            var results = new List <FilePath>();

            var ext         = environment.Platform.IsUnix() ? "" : ".bat";
            var androidHome = settings.SdkRoot.MakeAbsolute(environment).FullPath;

            if (!System.IO.Directory.Exists(androidHome))
            {
                androidHome = environment.GetEnvironmentVariable("ANDROID_HOME");
            }

            if (!string.IsNullOrEmpty(androidHome) && System.IO.Directory.Exists(androidHome))
            {
                var exe = new DirectoryPath(androidHome).Combine("tools").Combine("bin").CombineWithFilePath("sdkmanager" + ext);
                results.Add(exe);
            }

            return(results);
        }
コード例 #29
0
        private List <DirectoryPath> GetPathDirectories()
        {
            var result = new List <DirectoryPath>();
            var path   = _environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(path))
            {
                var separator = new[] { _environment.Platform.IsUnix() ? ':' : ';' };
                var paths     = path.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                foreach (var p in paths)
                {
                    try
                    {
                        result.Add(new DirectoryPath(p.Trim(' ', '"', '\'')));
                    }
                    catch
                    {
                    }
                }
            }

            return(result);
        }
コード例 #30
0
        /// <summary>
        /// Helper method to get the AWS Credentials from environment variables
        /// </summary>
        /// <param name="environment">The cake environment.</param>
        /// <param name="settings">The Labda settings.</param>
        /// <returns>The same <see cref="ClientSettings"/> instance so that multiple calls can be chained.</returns>
        private static T Initialize <T>(this T settings, ICakeEnvironment environment) where T : ClientSettings
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            //AWS Fallback
            AWSCredentials creds = FallbackCredentialsFactory.GetCredentials();

            if (creds != null)
            {
                settings.Credentials = creds;
            }

            string region = environment.GetEnvironmentVariable("AWS_REGION");

            if (!String.IsNullOrEmpty(region))
            {
                settings.Region = RegionEndpoint.GetBySystemName(region);
            }

            return(settings);
        }