Beispiel #1
0
        private static Project[] BuildProjects(out FileVersionInfo apiVersion, out Project[] allProjects)
        {
            CommandLine.WriteLine("{{white}} =======================================");
            CommandLine.WriteLine("{{white}} Building the Projects");
            CommandLine.WriteLine("{{white}} =======================================");

            var projects = new List<Project>();
            Project baseApi = new Project(Default.Combine("Src", "GoogleApis", "GoogleApis.csproj"));
            Project baseApiSilverlight = new Project(Default.Combine("Src", "GoogleApis", "GoogleApis.Silverlight.csproj"));
            Project codegen = new Project(Default.Combine("Src", "GoogleApis.Tools.CodeGen", "GoogleApis.Tools.CodeGen.csproj"));
            Project oauth2 = new Project(Default.Combine("Src", "GoogleApis.Authentication.OAuth2", "GoogleApis.Authentication.OAuth2.csproj"));
            Project generator = new Project(Default.Combine("GoogleApis.Tools.ServiceGenerator", "GoogleApis.Tools.ServiceGenerator.csproj"));

            var releaseProjects = new[] { baseApi, baseApiSilverlight, codegen, oauth2, generator };
            projects.AddRange(releaseProjects);
            projects.Add(new Project(Default.Combine("Src", "GoogleApis.Tests.Utility", "GoogleApis.Tests.Utility.csproj")));
            projects.Add(new Project(Default.Combine("Src", "GoogleApis.Tests", "GoogleApis.Tests.csproj")));
            projects.Add(new Project(Default.Combine("Src", "GoogleApis.Tools.CodeGen.Tests", "GoogleApis.Tools.CodeGen.Tests.csproj")));
            projects.Add(new Project(Default.Combine("Src", "GoogleApis.Authentication.OAuth2.Tests", "GoogleApis.Authentication.OAuth2.Tests.csproj")));
            projects.Add(new Project(Default.Combine("GoogleApis.Tools.CodeGen.IntegrationTests", "GoogleApis.Tools.CodeGen.IntegrationTests.csproj")));

            foreach (Project proj in projects)
            {
                proj.RunBuildTask();
                if (!releaseProjects.Contains(proj)) // If this assembly may contain tests, then run them.
                {
                    RunUnitTest(proj.BinaryFile);
                }
            }

            CommandLine.WriteLine();
            apiVersion = FileVersionInfo.GetVersionInfo(baseApi.BinaryFile);
            allProjects = projects.ToArray();
            return releaseProjects;
        }
Beispiel #2
0
        private static void UpdateSamples(IEnumerable<Project> releaseProjects, Project serviceGenerator)
        {
            CommandLine.WriteLine("{{white}} =======================================");
            CommandLine.WriteLine("{{white}} Updating Samples");
            CommandLine.WriteLine("{{white}} =======================================");

            // Update all the dependencies.
            string libDir = Samples.Combine("Lib");
            DirUtils.ClearDir(libDir);

            foreach (Project p in releaseProjects)
            {
                p.CopyTo(libDir);
            }

            string thirdpartyDir = Samples.Combine("Lib", "ThirdParty");
            Directory.CreateDirectory(thirdpartyDir);
            foreach (string file in ThirdPartyFiles)
            {
                DirUtils.CopyFile(file, thirdpartyDir);
            }

            // Generate all strongly typed services.
            DirUtils.ClearDir(ServiceDir);
            var runner = new Runner(
                serviceGenerator.BinaryFile, "--google", "--output", ServiceDir, "repository");
            runner.WorkingDirectory = Path.GetDirectoryName(serviceGenerator.BinaryFile);
            runner.Run();

            // Build all the samples projects.
            CommandLine.WriteAction("Building samples...");
            foreach (string csproj in
                Directory.GetFiles(Samples.WorkingDirectory, "*.csproj", SearchOption.AllDirectories))
            {
                Project project = new Project(csproj);
                project.RunBuildTask();
                project.Clean();
            }
            CommandLine.WriteLine();
        }
Beispiel #3
0
        /// <summary>
        /// Builds the Releases in the Contrib repository.
        /// Depends on: 
        ///     - Compiled BaseLibrary
        ///     - Updated Sample repository
        ///     - Existing release tag name
        /// </summary>
        /// <returns>Edited changelog.</returns>
        private static string BuildContribRelease(string tag,
            string changelog,
            IEnumerable<Project> baseLibrary,
            IEnumerable<Project> allProjects,
            Project serviceGenerator,
            out string zipDir)
        {
            CommandLine.WriteLine("{{white}} =======================================");
            CommandLine.WriteLine("{{white}} Building Contrib-Release");
            CommandLine.WriteLine("{{white}} =======================================");

            string releaseDir = Contrib.Combine(tag);
            string currentDir = Contrib.Combine("Current");
            string stableDir = Contrib.Combine("Stable");

            // Clear existing directories.
            DirUtils.ClearOrCreateDir(releaseDir);
            DirUtils.ClearOrCreateDir(currentDir);
            if (Arguments.IsStableRelease)
            {
                DirUtils.ClearOrCreateDir(stableDir);
            }

            // Create the <current> release
            string genDir = Path.Combine(currentDir, "Generated");
            Directory.CreateDirectory(genDir);

            #region Current/Generated/Lib
            string libDir = Path.Combine(genDir, "Lib");
            CommandLine.WriteAction("Generating dir: "+DirUtils.GetRelativePath(libDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(libDir);
            {
                // Copy all third party dlls into this directory.
                foreach (string file in ThirdPartyFiles)
                {
                    DirUtils.CopyFile(file, libDir);
                }

                // Copy all release dlls to this directory.
                foreach (Project project in baseLibrary)
                {
                    project.CopyTo(libDir);
                }
            }
            #endregion

            #region Current/Generated/Bin - and - Current/Generated/Source
            string binDir = Path.Combine(genDir, "Bin");
            string sourceDir = Path.Combine(genDir, "Source");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(binDir, Contrib.WorkingDirectory));
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(sourceDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(binDir);
            Directory.CreateDirectory(sourceDir);
            {
                // Iterate through all services, and put them into the right directory
                string[] toBin = new[] { ".dll", ".xml", ".pdb" };
                string[] toSrc = new[] { ".cs" };

                foreach (string file in Directory.GetFiles(ServiceDir, "*"))
                {
                    string fileName = Path.GetFileName(file);
                    CommandLine.WriteResult("File", fileName);
                    string ext = Path.GetExtension(fileName).ToLower();
                    if (toSrc.Contains(ext)) // Copy this file into the "Source" directory.
                    {
                        DirUtils.CopyFile(file, sourceDir);
                    }
                    if (toBin.Contains(ext)) // Copy this file into the "Binary" directory.
                    {
                        // Get the folder name by looking at the .dll assembly info.
                        string id = FileVersionInfo.GetVersionInfo(Path.ChangeExtension(file, ".dll")).ProductName;
                        string serviceName = id.Split(':')[0]; // "buzz:v1" -> "buzz"
                        string folderName = serviceName.ToUpperFirstChar() + "Service"; // "buzz" -> "BuzzService"

                        // Copy the file there.
                        string folder = Path.Combine(binDir, folderName);
                        DirUtils.CopyFile(file, folder);
                    }
                }
            }

            #endregion

            #region Current/ZipFiles
            string zipFilesDir = Path.Combine(genDir, "ZipFiles");
            CommandLine.WriteAction("Generating dir: " + DirUtils.GetRelativePath(zipFilesDir, Contrib.WorkingDirectory));
            Directory.CreateDirectory(zipFilesDir);
            {

                // Source.zip
                foreach (Project project in allProjects)
                {
                    project.Clean();
                }
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Source.zip")))
                {
                    zip.AddDirectory(Default.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }

                // Binary.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Binary.zip")))
                {
                    zip.AddDirectory(binDir, "Services");
                    zip.AddDirectory(libDir, "Lib");
                }

                // Samples.zip
                using (Zip zip = new Zip(Path.Combine(zipFilesDir, "Samples.zip")))
                {
                    zip.AddDirectory(Samples.WorkingDirectory, "");
                    zip.RemoveDirectory(".hg");
                    zip.RemoveFile(".hgtags");
                    zip.RemoveFile(".hgignore");
                }
            }
            #endregion

            #region Current/ReleaseNotes.txt
            CommandLine.WriteAction("Writing file...");
            string changelogFile = Path.Combine(currentDir, "ReleaseNotes.txt");
            using (var writer = new StreamWriter(changelogFile, false))
            {
                writer.WriteLine(changelog);
            }
            #endregion

            // Open the created changelog.
            CommandLine.WriteAction("Showing result...");
            Process.Start(changelogFile).WaitForExit();

            // Copy the content to the <tagname> release directory.
            DirUtils.CopyFiles(currentDir, releaseDir);
            if (Arguments.IsStableRelease)
            {
                DirUtils.CopyFiles(currentDir, stableDir);
            }

            // Rename the zips in the named release.
            // Example: Binary.zip -> google-api-dotnet-client-1.0.0-beta.Binary.zip
            string fileFormat = "google-api-dotnet-client-" + ExtractTagVersionAndName(tag) + ".{0}";
            zipDir = zipFilesDir.Replace(currentDir, releaseDir);
            foreach (string file in Directory.GetFiles(zipDir, "*.zip"))
            {
                string dir = Path.GetDirectoryName(file);
                string newFile = string.Format(fileFormat, Path.GetFileName(file).ToLower());
                File.Move(file, Path.Combine(dir, newFile));
            }

            CommandLine.WriteLine();
            return File.ReadAllText(changelogFile);
        }