Exemplo n.º 1
0
        private void InstallToolIntoUserApplicationFolder(string toolName, string toolPath)
        {
            var appToolPath = toolPath.Replace(".exe", ".app");

            if (!Directory.Exists(appToolPath))
            {
                return;
            }

            var basename    = Path.GetFileName(appToolPath);
            var installPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                "Applications",
                basename);

            if (File.Exists(installPath))
            {
                File.Delete(installPath);
            }

            var install = System.Diagnostics.Process.Start("ln", "-s '" + appToolPath + "' '" + installPath + "'");

            if (install != null)
            {
                install.WaitForExit();

                RedirectableConsole.WriteLine("Global tool '" + toolName + "' is now available in the application menu");
            }
            else
            {
                RedirectableConsole.WriteLine("Unable to install global tool '" + toolName + "' into the application menu (unable to create link)");
            }
        }
Exemplo n.º 2
0
 public void FinalizeRendering()
 {
     if (this.m_DidOutput)
     {
         RedirectableConsole.WriteLine();
     }
 }
Exemplo n.º 3
0
        private static void RunGitInternal(string str, string workingDirectory, string consoleWriteLine)
        {
            var processStartInfo = new ProcessStartInfo
            {
                FileName              = GetCachedGitPath(),
                Arguments             = str,
                WorkingDirectory      = workingDirectory,
                UseShellExecute       = false,
                RedirectStandardInput = true
            };

            RedirectableConsole.WriteLine(consoleWriteLine);

            var process = Process.Start(processStartInfo);

            if (process == null)
            {
                throw new InvalidOperationException("Unable to execute Git!");
            }

            process.StandardInput.Close();
            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                throw new InvalidOperationException("Got an unexpected exit code of " + process.ExitCode + " from Git");
            }
        }
Exemplo n.º 4
0
        private static string FindGitOnSystemPath()
        {
            if (Path.DirectorySeparatorChar != '/')
            {
                // We're on Windows.  We split the environment PATH to see if we
                // can find Git, then we check standard directories (like
                // C:\Program Files (x86)\Git) etc.
                var pathEnv = Environment.GetEnvironmentVariable("PATH");
                var paths   = new string[0];
                if (pathEnv != null)
                {
                    paths = pathEnv.Split(';');
                }

                var standardPaths = new List <string>
                {
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Git", "cmd"),
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Git", "bin"),
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", "cmd"),
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", "bin"),
                };

                // Add standard paths that GitHub for Windows uses.  Because the file
                // contains a hash, or some other mutable component, we need to search for
                // the PortableGit path.
                var github = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                          "GitHub");
                if (Directory.Exists(github))
                {
                    foreach (var subfolder in new DirectoryInfo(github).GetDirectories())
                    {
                        if (subfolder.Name.StartsWith("PortableGit_"))
                        {
                            standardPaths.Add(Path.Combine(subfolder.FullName, "cmd"));
                        }
                    }
                }

                var filenames = new[] { "git.exe", "git.bat", "git.cmd" };
                foreach (var path in paths.Concat(standardPaths))
                {
                    foreach (var filename in filenames)
                    {
                        if (File.Exists(Path.Combine(path, filename)))
                        {
                            // We found Git.
                            return(Path.Combine(path, filename));
                        }
                    }
                }

                RedirectableConsole.ErrorWriteLine(
                    "WARNING: Unable to find Git on your PATH, or any standard " +
                    "locations.  Have you installed Git on this system?");
                return("git");
            }

            // For UNIX systems, Git should always be on the PATH.
            return("git");
        }
Exemplo n.º 5
0
        public int Execute(Execution execution)
        {
            var url    = execution.PackageUrl;
            var module = ModuleInfo.Load(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            if (module.Packages == null)
            {
                module.Packages = new List <PackageRef>();
            }

            var package = _packageUrlParser.Parse(url);

            if (module.Packages.Any(x => x.Uri == package.Uri))
            {
                RedirectableConsole.WriteLine("WARNING: Package with URI " + package.Uri + " is already present; ignoring request to add package.");
                return(0);
            }

            if (Directory.Exists(Path.Combine(module.Path, package.Folder)))
            {
                throw new InvalidOperationException(package.Folder + " already exists");
            }

            RedirectableConsole.WriteLine("Adding " + package.Uri + " as " + package.Folder + "...");
            module.Packages.Add(package);
            module.Save(Path.Combine(execution.WorkingDirectory, "Build", "Module.xml"));

            return(0);
        }
Exemplo n.º 6
0
        public int Execute(Execution execution)
        {
            var archiveType = this.DetectPackageType(execution.PackagePushFile);

            if (archiveType == PackageManager.ARCHIVE_FORMAT_NUGET_ZIP)
            {
                if (execution.PackagePushVersion != ArgumentOmitted || execution.PackagePushPlatform != ArgumentOmitted)
                {
                    RedirectableConsole.ErrorWriteLine("You must omit the version and platform arguments when pushing packages in the NuGet format.");
                }
            }
            else
            {
                if (execution.PackagePushVersion == ArgumentOmitted || execution.PackagePushPlatform == ArgumentOmitted)
                {
                    RedirectableConsole.ErrorWriteLine("You must provide the version and platform arguments.");
                }
            }

            RedirectableConsole.WriteLine("Detected package type as " + archiveType + ".");

            switch (archiveType)
            {
            case PackageManager.ARCHIVE_FORMAT_NUGET_ZIP:
                return(PushToNuGetRepository(execution));

            case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
            case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
            default:
                return(PushToProtobuildRepository(execution, archiveType));
            }
        }
Exemplo n.º 7
0
        public int Execute(Execution execution)
        {
            var package = _packageUrlParser.Parse(execution.PackageUrl);

            RedirectableConsole.WriteLine("Installing " + package.Uri + "...");
            this.m_PackageManager.Resolve(execution.WorkingDirectory, null, package, this.m_HostPlatformDetector.DetectPlatform(), null, false, true, false);

            return(0);
        }
Exemplo n.º 8
0
 private void PrintFilterMappings(FileFilter mappings)
 {
     RedirectableConsole.WriteLine("The filter mappings resulted in: ");
     foreach (var kv in mappings)
     {
         foreach (var v in kv.Value)
         {
             RedirectableConsole.WriteLine("  " + kv.Key + " -> " + v);
         }
     }
 }
        private string FindNativeProgram(string program)
        {
            var search = _hostPlatformDetector.DetectPlatform() == "Windows"
                ? new[] { @"C:\Windows\System32\where.exe" }
                : new[] { "/usr/bin/which", "/bin/which" };
            string searchFound = null;

            foreach (var s in search)
            {
                if (File.Exists(s))
                {
                    searchFound = s;
                    break;
                }
            }

            if (searchFound == null)
            {
                throw new ApplicationException("ERROR: Could not find which or where on your system.");
            }

            RedirectableConsole.WriteLine("+ native-execute " + searchFound + " " + program);
            var searchProcess =
                Process.Start(new ProcessStartInfo(searchFound, program)
            {
                UseShellExecute        = false,
                RedirectStandardOutput = true
            });

            if (searchProcess == null)
            {
                throw new ApplicationException("ERROR: Process did not start when searching for " + program);
            }
            var path = searchProcess.StandardOutput.ReadToEnd().Split('\r', '\n').First();

            if (string.IsNullOrWhiteSpace(path) && _hostPlatformDetector.DetectPlatform() == "MacOS")
            {
                if (File.Exists("/usr/local/bin/" + program))
                {
                    // After upgrading to OSX El Capitan, the /usr/local/bin folder is no longer in
                    // the system PATH.  If we can't find Mono with the which tool, manually set the
                    // path here in an attempt to find it.
                    path = "/usr/local/bin/" + program;
                }
            }

            if (!File.Exists(path))
            {
                throw new ApplicationException("ERROR: Located file '" + path + "' for " + program +
                                               " does not actually exist.");
            }

            return(path);
        }
        public int Execute(Execution execution)
        {
            var scriptPath = execution.AutomatedBuildScriptPath ?? "automated.build";

            if (!File.Exists(scriptPath))
            {
                RedirectableConsole.ErrorWriteLine("ERROR: Automated build script not found at " + scriptPath + ".");
            }

            return(_automatedBuildController.Execute(execution.WorkingDirectory, scriptPath));
        }
Exemplo n.º 11
0
        public IPackageMetadata Lookup(string workingDirectory, ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source,
                                       bool forceUpgrade, bool?safeResolve)
        {
            if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement))
            {
                return(null);
            }

            if (module != null && reference.Folder != null)
            {
                var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform);
                if (existingPath != null && Directory.Exists(existingPath))
                {
                    RedirectableConsole.WriteLine("Found an existing working copy of this package at " + existingPath);

                    Directory.CreateDirectory(Path.Combine(workingDirectory, reference.Folder));
                    using (var writer = new StreamWriter(Path.Combine(workingDirectory, reference.Folder, ".redirect")))
                    {
                        writer.WriteLine(existingPath);
                    }

                    return(null);
                }
                else
                {
                    if (File.Exists(Path.Combine(workingDirectory, reference.Folder, ".redirect")))
                    {
                        try
                        {
                            File.Delete(Path.Combine(workingDirectory, reference.Folder, ".redirect"));
                        }
                        catch
                        {
                        }
                    }
                }
            }

            var request = new PackageRequestRef(
                reference.Uri,
                reference.GitRef,
                platform,
                forceUpgrade,
                reference.IsStaticReference);

            return(_packageLookup.Lookup(workingDirectory, request));
        }
Exemplo n.º 12
0
        public string RedirectPackageUrl(string url)
        {
            foreach (var kv in this.m_LocalRedirects)
            {
                if (url == kv.Key)
                {
                    RedirectableConsole.WriteLine("Redirecting package from " + kv.Key + " to " + kv.Value + " due to command line options");
                    return(kv.Value);
                }
            }

            var redirects = this.m_PackageCacheConfiguration.GetRedirectsFile();

            if (!File.Exists(redirects))
            {
                return(url);
            }

            var redirectMappings = new Dictionary <string, string>();

            using (var reader = new StreamReader(redirects))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine().Trim();
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    var components = line.Split(new[] { "->" }, StringSplitOptions.None);
                    if (components.Length >= 2)
                    {
                        var original = components[0].Trim();
                        var replace  = components[1].Trim();

                        if (url == original)
                        {
                            RedirectableConsole.WriteLine("Redirecting package from " + original + " to " + replace + " due to configuration in " + redirects);
                            return(replace);
                        }
                    }
                }
            }

            return(url);
        }
Exemplo n.º 13
0
 private void InstallAssemblyIntoGAC(string gacPath)
 {
     try
     {
         var assembly      = Assembly.Load("System.EnterpriseServices");
         var type          = assembly.GetType("System.EnterpriseServices.Internal.Publish");
         var constructor   = type.GetConstructor(Type.EmptyTypes);
         var publishObject = constructor.Invoke(null);
         var gacInstall    = type.GetMethod("GacInstall");
         gacInstall.Invoke(publishObject, new object[] { gacPath });
         RedirectableConsole.WriteLine("GAC installation completed successfully for '" + gacPath + "'");
     }
     catch (Exception ex)
     {
         RedirectableConsole.ErrorWriteLine("Got an exception while performing GAC install for '" + gacPath + "': " + ex.Message);
     }
 }
Exemplo n.º 14
0
        public void ScanPackageForToolsAndInstall(string toolFolder)
        {
            var projectsPath = Path.Combine(toolFolder, "Build", "Projects");
            var projectsInfo = new DirectoryInfo(projectsPath);

            foreach (var file in projectsInfo.GetFiles("*.definition"))
            {
                var document = XDocument.Load(file.FullName);
                var tools    = document.XPathSelectElements("/ExternalProject/Tool");

                foreach (var tool in tools)
                {
                    var toolPath = Path.Combine(toolFolder, tool.Attribute(XName.Get("Path")).Value);
                    var toolName = tool.Attribute(XName.Get("Name")).Value;

                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        toolPath = toolPath.Replace("/", "\\");
                    }
                    else if (Path.DirectorySeparatorChar == '/')
                    {
                        toolPath = toolPath.Replace("\\", "/");
                    }

                    using (var writer = new StreamWriter(Path.Combine(this.GetToolsPath(), toolName + ".tool")))
                    {
                        writer.WriteLine(toolPath);
                    }

                    RedirectableConsole.WriteLine("Global tool '" + toolName + "' now points to '" + toolPath + "'");

                    if (_hostPlatformDetector.DetectPlatform() == "Windows")
                    {
                        this.InstallToolIntoWindowsStartMenu(toolName, toolPath);
                    }
                    else if (_hostPlatformDetector.DetectPlatform() == "MacOS")
                    {
                        this.InstallToolIntoUserApplicationFolder(toolName, toolPath);
                    }
                    else if (_hostPlatformDetector.DetectPlatform() == "Linux")
                    {
                        this.InstallToolIntoLinuxApplicationMenu(toolName, toolPath);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private Feature?LookupFeatureByID(string str)
        {
            foreach (var name in Enum.GetNames(typeof(Feature)))
            {
                var field             = typeof(Feature).GetField(name);
                var internalAttribute = field.GetCustomAttributes(typeof(FeatureInternalAttribute), false).FirstOrDefault() as FeatureInternalAttribute;
                if (internalAttribute != null)
                {
                    if (internalAttribute.InternalId == str)
                    {
                        return((Feature)field.GetValue(null));
                    }
                }
            }

            RedirectableConsole.ErrorWriteLine("WARNING: Unable to find feature based on ID '" + str + "'");
            return(null);
        }
Exemplo n.º 16
0
        private void PerformRetryableRequest(string message, Uri baseUri, Action <Uri> func)
        {
            var exceptions = new List <Exception>();
            var backoff    = 100;

            for (var i = 0; i < MaxRequests; i++)
            {
                try
                {
                    RedirectableConsole.WriteLine("(" + (i + 1) + "/" + MaxRequests + ") " + message);
                    func(baseUri);
                    return;
                }
                catch (Exception ex)
                {
                    RedirectableConsole.ErrorWriteLine("Exception during web request: ");
                    RedirectableConsole.ErrorWriteLine(ex);
                    exceptions.Add(ex);

                    var webException = ex as WebException;
                    if (webException != null)
                    {
                        switch (webException.Status)
                        {
                        case WebExceptionStatus.NameResolutionFailure:
                            // This is a permanent failure.
                            i       = MaxRequests;
                            backoff = 0;
                            break;
                        }
                    }

                    RedirectableConsole.WriteLine("Backing off web requests for " + backoff + "ms...");
                    System.Threading.Thread.Sleep(backoff);
                    backoff *= 2;
                    if (backoff > 20000)
                    {
                        backoff = 20000;
                    }
                }
            }

            throw new AggregateException(exceptions);
        }
        public int Execute(string workingDirectory, string path)
        {
            IAutomatedBuildRuntime runtime = null;
            string script = null;

            using (var reader = new StreamReader(path))
            {
                script = reader.ReadToEnd();
                if (script.StartsWith("#version 1"))
                {
                    script  = script.Substring("#version 1".Length).TrimStart();
                    runtime = _automatedBuildRuntimeV1;
                }
                else
                {
                    throw new InvalidOperationException(
                              "Your automated build script must start with #version N, where " +
                              "N is the number indicating the script runtime version for " +
                              "automated builds.");
                }
            }

            object handle;

            try
            {
                handle = runtime.Parse(script);
            }
            catch (Exception ex)
            {
                RedirectableConsole.ErrorWriteLine("ERROR: " + ex.Message);
                return(1);
            }
            try
            {
                return(runtime.Execute(workingDirectory, handle));
            }
            catch (Exception ex)
            {
                RedirectableConsole.ErrorWriteLine("ERROR: " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(1);
            }
        }