/// <summary>
        /// Installs the specified resource.
        /// </summary>
        /// <param name="package">The package resource.</param>
        /// <param name="type">The package type.</param>
        /// <param name="path">The location where to install the resource.</param>
        /// <returns>The installed files.</returns>
        public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            // find npm
            _log.Debug("looking for npm.cmd");
            var npmTool = _toolLocator.Resolve("npm.cmd");

            if (npmTool == null)
            {
                _log.Debug("looking for npm");
                npmTool = _toolLocator.Resolve("npm");
            }

            if (npmTool == null)
            {
                throw new FileNotFoundException("npm could not be found.");
            }

            _log.Debug("Found npm at {0}", npmTool);

            // Install the package.
            _log.Debug("Installing package {0} with npm...", package.Package);
            var process = _processRunner.Start(
                npmTool.FullPath,
                new ProcessSettings {
                Arguments = GetArguments(package, _config), RedirectStandardOutput = true, Silent = _log.Verbosity < Verbosity.Diagnostic
            });

            process.WaitForExit();

            var exitCode = process.GetExitCode();

            if (exitCode != 0)
            {
                _log.Warning("npm exited with {0}", exitCode);
                var output = string.Join(Environment.NewLine, process.GetStandardOutput());
                _log.Verbose(Verbosity.Diagnostic, "Output:\r\n{0}", output);
            }

            var result = _contentResolver.GetFiles(package, type, package.GetSwitch("global"));

            if (result.Count != 0)
            {
                return(result);
            }

            _log.Warning("Could not determine installed package files! Installation may not be complete.");

            // TODO: maybe some warnings here
            return(result);
        }
Esempio n. 2
0
File: Tool.cs Progetto: gitfool/cake
        private FilePath GetToolPathUsingToolService(TSettings settings)
        {
            var toolPath = settings.ToolPath;

            if (toolPath != null)
            {
                return(toolPath.MakeAbsolute(_environment));
            }

            // Look for each possible executable name in various places.
            var result = _tools.Resolve(GetToolExecutableNames(settings));

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

            // Look through all the alternative directories for the tool.
            var alternativePaths = GetAlternativeToolPaths(settings) ?? Enumerable.Empty <FilePath>();

            foreach (var alternativePath in alternativePaths)
            {
                if (_fileSystem.Exist(alternativePath))
                {
                    return(alternativePath.MakeAbsolute(_environment));
                }
            }

            return(null);
        }
Esempio n. 3
0
        public void Run(SonarSettings settings)
        {
            Prepare(settings);

            var arguments = settings.GetArguments(_environment);

            _log.Information(arguments.RenderSafe());

            if (_environment.Runtime.IsCoreClr)
            {
                var tool = _toolsLocator.Resolve(CORECLR_TOOL_NAME);
                if (tool == null)
                {
                    throw new Exception($"No CoreCLR executable found ({CORECLR_TOOL_NAME})");
                }
                _log.Debug("We're launching for CoreCLR with executable " + tool.FullPath);
                _coreRunner.Execute(new FilePath("dummy.file").MakeAbsolute(_environment), tool.FullPath, arguments, new DotNetCoreToolSettings {
                });
            }
            else
            {
                _log.Debug("We're launching for CLR.");
                Run(settings, arguments, new ProcessSettings {
                    RedirectStandardOutput = settings.Silent
                }, null);
            }
        }
Esempio n. 4
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.");
        }
        public void Setup()
        {
            environment = FakeEnvironmentHelper.CreateFromRuntime();
            fileSystem  = new FakeFileSystem(environment);
            runner      = A.Fake <IProcessRunner>();
            tools       = A.Fake <IToolLocator>();
            mavenClient = A.Fake <IMavenClient>();

            fileSystem.CreateFile(javaExecutable, FileAttributes.Normal);
            A.CallTo(() => runner.Start(A <FilePath> ._, A <ProcessSettings> ._)).Returns(A.Fake <IProcess>());
            A.CallTo(() => tools.Resolve(A <string> ._)).Returns(javaExecutable);
            A.CallTo(() => mavenClient.Resolve(A <MavenPackage> ._)).Returns("/path/to/package.jar");
        }
Esempio n. 6
0
        /// <summary>
        /// Resolves the path to Migrate.exe.
        /// </summary>
        /// <returns>The path to Migrate.exe.</returns>
        public FilePath ResolvePath()
        {
            var arch             = _environment.Platform.Is64Bit ? "AnyCPU" : "x86";
            var frameworkVersion = _environment.Runtime.BuiltFramework.Version.Major >= 4 ? "40" : "35";
            var toolPath         = _toolLocator.Resolve($"{arch}/{frameworkVersion}/Migrate.exe");

            if (toolPath == null || !_fileSystem.Exist(toolPath))
            {
                throw new CakeException($"Could not locate Migrate.exe for {arch}/{frameworkVersion}");
            }

            return(toolPath);
        }
Esempio n. 7
0
            public void ShouldThrowIfChutzpahExecutableNotFound(
                [Frozen] ICakeEnvironment environment, [Frozen] IFileSystem fileSystem, [Frozen] IToolLocator tools,
                ChutzpahRunner sut)
            {
                environment.WorkingDirectory.Returns("/Working");
                tools.Resolve(Arg.Any <string>()).Returns(null as FilePath);
                fileSystem.Exist(
                    Arg.Is <FilePath>(a => a.FullPath.Contains("chutzpah.console.exe")))
                .Returns(false);

                sut.Invoking(x => x.Run())
                .ShouldThrow <CakeException>()
                .WithMessage("Chutzpah: Could not locate executable.");
            }
Esempio n. 8
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.");
        }
Esempio n. 9
0
        private DirectoryPath ResolveRootPath()
        {
            var platform = _environment.Platform.IsUnix() ? "linux_" : "windows_";

            platform = _environment.Platform.Is64Bit ? platform + "x64" : platform + "x86";
            var protocPath = _tools.Resolve(_environment.Platform.IsUnix() ? $"{platform}/protoc" : $"{platform}/protoc.exe");

            var toolPath = protocPath.GetDirectory();

            if (toolPath == null || !_fileSystem.Exist(toolPath))
            {
                throw new CakeException($"Could not locate the grpc.tools folder for the platform {platform}");
            }

            return(toolPath);
        }
Esempio n. 10
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}.");
        }
        private FilePath GetToolPathUsingToolService(AndroidSdkManagerToolSettings settings)
        {
            var ext = _environment.Platform.Family == PlatformFamily.Windows ? ".bat" : "";

            FilePath toolPath = null;

            if (settings.SdkRoot != null && _fileSystem.Exist(settings.SdkRoot))
            {
                toolPath = settings?.SdkRoot?.Combine("tools")?.Combine("bin")?.CombineWithFilePath("sdkmanager" + ext);
            }

            if (toolPath != null)
            {
                return(toolPath.MakeAbsolute(_environment));
            }

            toolPath = settings.ToolPath;
            if (toolPath != null)
            {
                return(toolPath.MakeAbsolute(_environment));
            }

            // Look for each possible executable name in various places.
            var toolExeNames = GetToolExecutableNames();

            foreach (var toolExeName in toolExeNames)
            {
                var result = _tools.Resolve(toolExeName);
                if (result != null)
                {
                    return(result);
                }
            }

            // Look through all the alternative directories for the tool.
            var alternativePaths = GetAlternativeToolPaths(settings) ?? Enumerable.Empty <FilePath>();

            foreach (var alternativePath in alternativePaths)
            {
                if (_fileSystem.Exist(alternativePath))
                {
                    return(alternativePath.MakeAbsolute(_environment));
                }
            }

            return(null);
        }
Esempio n. 12
0
        public FilePath ResolvePath()
        {
            if (_cachedPath != null)
            {
                return(_cachedPath);
            }

            var toolsExe = _tools.Resolve("makeappx.exe");

            if (toolsExe != null)
            {
                _cachedPath = toolsExe;
                return(_cachedPath);
            }

            _cachedPath = GetFromDisc() ?? GetFromRegistry();
            if (_cachedPath == null)
            {
                throw new CakeException("Failed to find MakeAppx.exe.");
            }
            return(_cachedPath);
        }
Esempio n. 13
0
        internal ProcessStartInfo GetProcessStartInfo(FilePath filePath, ProcessSettings settings, out Func <string, string> filterUnsafe)
        {
            // Get the fileName
            var fileName = _environment.Platform.IsUnix() ? filePath.FullPath : filePath.FullPath.Quote();

            // Get the arguments.
            var arguments = settings.Arguments ?? new ProcessArgumentBuilder();

            filterUnsafe = arguments.FilterUnsafe;

            if (!_noMonoCoersion &&
                _environment.Platform.IsUnix() &&
                _environment.Runtime.IsCoreClr &&
                fileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) &&
                _fileSystem.GetFile(fileName).IsClrAssembly())
            {
                FilePath monoPath = _tools.Resolve("mono");
                if (monoPath != null)
                {
                    if (!settings.Silent)
                    {
                        _log.Verbose(Verbosity.Diagnostic, "{0} is a .NET Framework executable, will try execute using Mono.", fileName);
                    }
                    arguments.PrependQuoted(fileName);
                    fileName = monoPath.FullPath;
                }
                else
                {
                    if (!settings.Silent)
                    {
                        _log.Verbose(Verbosity.Diagnostic, "{0} is a .NET Framework executable, you might need to install Mono for it to execute successfully.", fileName);
                    }
                }
            }

            if (!settings.Silent)
            {
                // Log the filename and arguments.
                var message = string.Concat(fileName, " ", arguments.RenderSafe().TrimEnd());
                _log.Verbose(_showCommandLine ? _log.Verbosity : Verbosity.Diagnostic, "Executing: {0}", message);
            }

            // Create the process start info.
            var info = new ProcessStartInfo(fileName)
            {
                Arguments              = arguments.Render(),
                UseShellExecute        = false,
                RedirectStandardError  = settings.RedirectStandardError,
                RedirectStandardOutput = settings.RedirectStandardOutput
            };

            // Allow working directory?
            if (!settings.NoWorkingDirectory)
            {
                var workingDirectory = settings.WorkingDirectory ?? _environment.WorkingDirectory;
                info.WorkingDirectory = workingDirectory.MakeAbsolute(_environment).FullPath;
            }

            // Add environment variables
            ProcessHelper.SetEnvironmentVariable(info, "CAKE", "True");
            ProcessHelper.SetEnvironmentVariable(info, "CAKE_VERSION", _environment.Runtime.CakeVersion.ToString(3));
            if (settings.EnvironmentVariables != null)
            {
                foreach (var environmentVariable in settings.EnvironmentVariables)
                {
                    ProcessHelper.SetEnvironmentVariable(info, environmentVariable.Key, environmentVariable.Value);
                }
            }

            return(info);
        }
Esempio n. 14
0
        private IFile SafeResolvePath()
        {
            // this method should _only_ return if the file exists.
            const string executableFile = "acs.exe";

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

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

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

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

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

            // last resort, try plain vanilla program files
            var exeFile = new[]
            {
                "c:\\Program Files (x86)\\Apprenda\\Tools\\ACS",
                "c:\\Program Files\\Apprenda\\Tools\\ACS"
            }
            .Select(path => _fileSystem.GetDirectory(path))
            .Where(path => path.Exists)
            .Select(path => path.Path.CombineWithFilePath(executableFile))
            .Select(_fileSystem.GetFile)
            .FirstOrDefault(file => file.Exists);

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

            throw new CakeException($"Could not locate {executableFile}.");
        }