WriteFile() static private method

static private WriteFile ( string baseOutputDir, string subNamespace, string filename, string content, bool trimWhitespace = true, bool replaceTabs = true ) : bool
baseOutputDir string
subNamespace string
filename string
content string
trimWhitespace bool
replaceTabs bool
return bool
        /// <summary>
        /// Invokes the T4 generator to emit a platform-specific project file.
        /// </summary>
        /// <param name="projectFileConfiguration"></param>
        /// <param name="session"></param>
        /// <param name="serviceFilesRoot"></param>
        /// <param name="projectFilename"></param>
        private void GenerateProjectFile(ProjectFileConfiguration projectFileConfiguration,
                                         ProjectConfigurationData projectConfiguration,
                                         IDictionary <string, object> session,
                                         string serviceFilesRoot,
                                         string projectFilename)
        {
            var    projectName      = Path.GetFileNameWithoutExtension(projectFilename);
            string generatedContent = null;

            try
            {
                var projectTemplateType = Type.GetType(
                    "ServiceClientGenerator.Generators.ProjectFiles." +
                    projectFileConfiguration.Template);
                dynamic generator = Activator.CreateInstance(projectTemplateType);
                generator.Session = session;
                generatedContent  = generator.TransformText();
            }
            catch (Exception)
            {
                throw new ArgumentException("Project template name "
                                            + projectFileConfiguration.Template + " is not recognized");
            }

            GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, generatedContent);
            projectConfiguration.ConfigurationPlatforms = projectFileConfiguration.Configurations;
        }
        private void SetupPackageConfigFile(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            CodeAnalysisPackages generator = new CodeAnalysisPackages();
            var generatedContent           = generator.TransformText();

            GeneratorDriver.WriteFile(codeAnalysisRoot, string.Empty, "packages.config", generatedContent);
        }
        private void GenerateProjectFile(IDictionary <string, object> session,
                                         string unitTestProjectRoot,
                                         string projectFilename)
        {
            var    projectName      = Path.GetFileNameWithoutExtension(projectFilename);
            string generatedContent = null;

            try
            {
                var projectTemplateType = Type.GetType(
                    "ServiceClientGenerator.Generators.ProjectFiles." +
                    TemplateName);
                dynamic generator = Activator.CreateInstance(projectTemplateType);
                generator.Session = session;
                generatedContent  = generator.TransformText();
            }
            catch (ArgumentNullException)
            {
                throw new ArgumentException("Project template name "
                                            + TemplateName + " is not recognized");
            }
            catch (Exception e)
            {
                throw new Exception("Exception encountered while generating text from template " + TemplateName, e);
            }

            GeneratorDriver.WriteFile(unitTestProjectRoot, string.Empty, projectFilename, generatedContent);
        }
        private void GenerateProperyValueAnalyzer(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            var generator = new PropertyValueAssignmentAnalyzer {
                Config = serviceConfiguration
            };
            var text = generator.TransformText();

            GeneratorDriver.WriteFile(codeAnalysisRoot, "Generated", "PropertyValueAssignmentAnalyzer.cs", text);
        }
        private void GenerateAssemblyInfo(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            var generator = new CodeAnalysisAssemblyInfo {
                Config = serviceConfiguration
            };
            var text = generator.TransformText();

            GeneratorDriver.WriteFile(codeAnalysisRoot, "Properties", "AssemblyInfo.cs", text);
        }
        private void GenerateCoreCLRProjectFiles(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, string assemblyName)
        {
            var    projectFilename = string.Concat(assemblyName, ".CoreCLR.xproj");
            string projectGuid;

            if (File.Exists(Path.Combine(serviceFilesRoot, projectFilename)))
            {
                Console.WriteLine("...updating existing project file {0}", projectFilename);
                var projectPath = Path.Combine(serviceFilesRoot, projectFilename);
                projectGuid = Utils.GetProjectGuid(projectPath);
            }
            else
            {
                projectGuid = Utils.NewProjectGuid;
                Console.WriteLine("...creating project file {0}", projectFilename);
            }


            {
                var templateSession = new Dictionary <string, object>();
                templateSession["RootNamespace"] = serviceConfiguration.Namespace;
                templateSession["AssemblyName"]  = assemblyName;
                templateSession["ProjectGuid"]   = projectGuid;

                CoreCLRProjectFile projectFileTemplate = new CoreCLRProjectFile();
                projectFileTemplate.Session = templateSession;
                var content = projectFileTemplate.TransformText();

                GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, content);
            }

            {
                var templateSession = new Dictionary <string, object>();

                var dependencies = new List <string>();
                foreach (var dependency in serviceConfiguration.ServiceDependencies.Keys)
                {
                    if (string.Equals(dependency, "Core", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    dependencies.Add(dependency);
                }

                templateSession["ServiceDependencies"] = dependencies;
                templateSession["AssemblyName"]        = assemblyName;

                var projectJsonTemplate = new CoreCLRProjectJson();
                projectJsonTemplate.Session = templateSession;

                var content = projectJsonTemplate.TransformText();

                GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, "project.json", content);
            }
        }
        private void UpdateNuspec()
        {
            var avi = new CoreNuspec {
                Session = session
            };
            var text = avi.TransformText();

            GeneratorDriver.WriteFile(
                Options.SdkRootFolder, corePath, nuspecPath, text);
        }
Example #8
0
        private void GenerateCoreCLRSolution(string solutionFileName, bool includeTests, ICollection <string> serviceProjectsForPartialBuild = null)
        {
            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);
            var session         = new Dictionary <string, object>();

            var coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);
            var coreProjects     = new List <Project>()
            {
                CoreProjectFromFile(Path.Combine(coreProjectsRoot, "AWSSDK.Core.CoreCLR.xproj"))
            };

            session["CoreProjects"] = coreProjects;
            session["IncludeTests"] = includeTests;

            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var solutionProjects    = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);

                // If we are generating a partial solution, and the service project has not changed, omit it from the partial solution.
                bool omitService = serviceProjectsForPartialBuild != null && !serviceProjectsForPartialBuild.Contains(di.Name, StringComparer.InvariantCultureIgnoreCase);
                if (omitService)
                {
                    continue;
                }

                foreach (var projectFile in Directory.GetFiles(servicePath, "*CoreCLR.xproj", SearchOption.TopDirectoryOnly))
                {
                    folder.Projects.Add(ServiceProjectFromFile(di.Name, projectFile));
                    SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                }

                if (folder.Projects.Count > 0)
                {
                    serviceSolutionFolders.Add(folder);
                }
            }
            session["ServiceSolutionFolders"] = serviceSolutionFolders;

            var generator = new CoreCLRSolutionFile()
            {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, solutionFileName, content, true, false);
        }
Example #9
0
        private void GenerateVS2017ProjectFile(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, ProjectFileConfiguration projectFileConfiguration)
        {
            var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1];
            var projectType  = projectFileConfiguration.Name;

            var projectProperties = new Project();

            projectProperties.AssemblyName      = assemblyName;
            projectProperties.ProjectReferences = projectFileConfiguration.ProjectReferences;
            projectProperties.TargetFrameworks  = projectFileConfiguration.TargetFrameworkVersions;
            projectProperties.DefineConstants   = projectFileConfiguration.CompilationConstants;
            projectProperties.CompileRemoveList = projectFileConfiguration.PlatformExcludeFolders.ToList();
            if (serviceConfiguration.IsTestService)
            {
                var toExclude = projectProperties.CompileRemoveList as List <string>;
                toExclude.Add("UnitTests");
            }
            projectProperties.FrameworkPathOverride                = projectFileConfiguration.FrameworkPathOverride;
            projectProperties.ReferenceDependencies                = projectFileConfiguration.DllReferences;
            projectProperties.SupressWarnings                      = projectFileConfiguration.NoWarn;
            projectProperties.SignBinaries                         = true;
            projectProperties.PackageReferences                    = projectFileConfiguration.PackageReferences;
            projectProperties.FxcopAnalyzerRuleSetFilePath         = @"..\..\..\AWSDotNetSDK.ruleset";
            projectProperties.FxcopAnalyzerRuleSetFilePathForBuild = @"..\..\..\AWSDotNetSDKForBuild.ruleset";
            projectProperties.CustomRoslynAnalyzersDllDirectory    = @"..\..\..\..\buildtools\CustomRoslynAnalyzers.dll";

            List <Dependency>       dependencies;
            List <PackageReference> references = new List <PackageReference>();

            if (serviceConfiguration.NugetDependencies != null &&
                serviceConfiguration.NugetDependencies.TryGetValue(projectFileConfiguration.Name, out dependencies))
            {
                foreach (var dependency in dependencies)
                {
                    references.Add(new PackageReference
                    {
                        Include = dependency.Name,
                        Version = dependency.Version,
                    });
                }

                projectProperties.PackageReferences = references;
            }

            var projectJsonTemplate = new VS2017ProjectFile();

            projectJsonTemplate.Project = projectProperties;

            var content = projectJsonTemplate.TransformText();

            GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, string.Format("{0}.{1}.csproj", assemblyName, projectType), content);
        }
        public void GenerateVsixManifest(List <Project> codeAnalysisProjects)
        {
            var templateSession = new Dictionary <string, object>();

            templateSession["CodeAnalysisProjects"] = codeAnalysisProjects;

            var generator = new VsixManifest();

            generator.Session = templateSession;
            var generatedContent = generator.TransformText();

            GeneratorDriver.WriteFile(Path.Combine(Options.SdkRootFolder, GeneratorDriver.CodeAnalysisFoldername), "AWSCodeAnalysisTestExtension", "source.extension.vsixmanifest", generatedContent, false, false);
        }
        public void GenerateSolutionFile(List <Project> codeAnalysisProjects)
        {
            var templateSession = new Dictionary <string, object>();

            templateSession["CodeAnalysisProjects"] = codeAnalysisProjects;

            CodeAnalysisSolutionFile generator = new CodeAnalysisSolutionFile();

            generator.Session = templateSession;
            var generatedContent = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, string.Empty, "AWSSDK.CodeAnalysis.sln", generatedContent, false, false);
        }
        private void GenerateVS2017ProjectFile(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, ProjectFileConfiguration projectFileConfiguration)
        {
            var serviceName  = serviceConfiguration.Namespace.Split('.')[1];
            var assemblyName = "AWSSDK." + serviceName;
            var projectType  = projectFileConfiguration.Name;

            var templateSession = new Dictionary <string, object>();

            templateSession["AssemblyName"]          = assemblyName;
            templateSession["ProjectReferenceList"]  = projectFileConfiguration.ProjectReferences;
            templateSession["TargetFramework"]       = projectFileConfiguration.TargetFrameworkVersion;
            templateSession["DefineConstants"]       = projectFileConfiguration.CompilationConstants;
            templateSession["CompileRemoveList"]     = projectFileConfiguration.PlatformExcludeFolders;
            templateSession["FrameworkPathOverride"] = projectFileConfiguration.FrameworkPathOverride;
            templateSession["ReferencePath"]         = projectFileConfiguration.ReferencePath;
            templateSession["FrameworkReferences"]   = projectFileConfiguration.FrameworkReferences;
            templateSession["NoWarn"]            = projectFileConfiguration.NoWarn;
            templateSession["SignBinaries"]      = true;
            templateSession["ConfigurationName"] = projectFileConfiguration.TargetFrameworkVersion;
            templateSession["PathMapValue"]      = Path.Combine(@"aws-sdk-net\sdk\src\Services\", serviceName);

            List <Dependency>       dependencies;
            List <PackageReference> references = new List <PackageReference>();

            if (serviceConfiguration.NugetDependencies != null &&
                serviceConfiguration.NugetDependencies.TryGetValue(projectFileConfiguration.Name, out dependencies))
            {
                foreach (var dependency in dependencies)
                {
                    references.Add(new PackageReference
                    {
                        Include = dependency.Name,
                        Version = dependency.Version,
                    });
                }

                templateSession["PackageReferenceList"] = references;
            }

            var projectJsonTemplate = new VS2017ProjectFile();

            projectJsonTemplate.Session = templateSession;

            var content = projectJsonTemplate.TransformText();

            GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, string.Format("{0}.{1}.csproj", assemblyName, projectType), content);
        }
        private void GenerateProperyValueRules(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            StringBuilder sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb, new XmlWriterSettings {
                Indent = true
            }))
            {
                writer.WriteStartElement("property-value-rules");

                if (!string.Equals(serviceConfiguration.ClassName, "S3", StringComparison.InvariantCultureIgnoreCase))
                {
                    HashSet <string> requestAndResponseShapes = new HashSet <string>();
                    foreach (var operation in serviceConfiguration.ServiceModel.Operations)
                    {
                        if (operation.RequestStructure != null)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, operation.Name + "Request", operation.RequestStructure);
                            requestAndResponseShapes.Add(operation.RequestStructure.Name);
                        }
                        if (operation.ResponseStructure != null)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, operation.Name + "Response", operation.ResponseStructure);
                            requestAndResponseShapes.Add(operation.ResponseStructure.Name);
                        }
                    }

                    foreach (var shape in serviceConfiguration.ServiceModel.Shapes.OrderBy(x => x.Name))
                    {
                        if (requestAndResponseShapes.Contains(shape.Name))
                        {
                            continue;
                        }

                        if (shape.IsStructure)
                        {
                            GenerateProperyValueRules(serviceConfiguration, writer, shape.Name, shape);
                        }
                    }
                }
                writer.WriteEndElement();
            }
            var content = sb.ToString();

            GeneratorDriver.WriteFile(Path.Combine(codeAnalysisRoot, "Generated"), string.Empty, "PropertyValueRules.xml", content);
        }
Example #14
0
        private void GenerateCoreCLRSolution()
        {
            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);
            var session         = new Dictionary <string, object>();

            var coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);
            var coreProjects     = new List <Project>()
            {
                CoreProjectFromFile(Path.Combine(coreProjectsRoot, "AWSSDK.Core.CoreCLR.xproj"))
            };

            session["CoreProjects"] = coreProjects;

            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var solutionProjects    = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);

                foreach (var projectFile in Directory.GetFiles(servicePath, "*CoreCLR.xproj", SearchOption.TopDirectoryOnly))
                {
                    folder.Projects.Add(ServiceProjectFromFile(di.Name, projectFile));
                    SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                }

                if (folder.Projects.Count > 0)
                {
                    serviceSolutionFolders.Add(folder);
                }
            }
            session["ServiceSolutionFolders"] = serviceSolutionFolders;

            var generator = new CoreCLRSolutionFile()
            {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, "AWSSDK.CoreCLR.sln", content, true, false);
        }
        private void UpdateAssemblyVersion()
        {
            var avi = new CoreAssemblyInfo {
                Session = session
            };
            var text = avi.TransformText();

            GeneratorDriver.WriteFile(
                Options.SdkRootFolder, corePath, assemblyInfoPath, text);

            var sdkUtil = new InternalSDKUtils {
                Session = session
            };
            var sdkUtilText = sdkUtil.TransformText();

            GeneratorDriver.WriteFile(
                Options.SdkRootFolder, corePath, internalSdkUtilPath, sdkUtilText);
        }
        private void GenerateVS2017ProjectFile(string serviceFilesRoot, ServiceConfiguration serviceConfiguration, ProjectFileConfiguration projectFileConfiguration)
        {
            var assemblyName = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1];
            var projectType  = projectFileConfiguration.Name;

            var projectProperties = new Project();

            projectProperties.AssemblyName          = assemblyName;
            projectProperties.ProjectReferences     = projectFileConfiguration.ProjectReferences;
            projectProperties.TargetFrameworks      = projectFileConfiguration.TargetFrameworkVersions;
            projectProperties.DefineConstants       = projectFileConfiguration.CompilationConstants;
            projectProperties.CompileRemoveList     = projectFileConfiguration.PlatformExcludeFolders;
            projectProperties.FrameworkPathOverride = projectFileConfiguration.FrameworkPathOverride;
            projectProperties.ReferenceDependencies = projectFileConfiguration.DllReferences;
            projectProperties.SupressWarnings       = projectFileConfiguration.NoWarn;
            projectProperties.SignBinaries          = true;

            List <Dependency>       dependencies;
            List <PackageReference> references = new List <PackageReference>();

            if (serviceConfiguration.NugetDependencies != null &&
                serviceConfiguration.NugetDependencies.TryGetValue(projectFileConfiguration.Name, out dependencies))
            {
                foreach (var dependency in dependencies)
                {
                    references.Add(new PackageReference
                    {
                        Include = dependency.Name,
                        Version = dependency.Version,
                    });
                }

                projectProperties.PackageReferences = references;
            }

            var projectJsonTemplate = new VS2017ProjectFile();

            projectJsonTemplate.Project = projectProperties;

            var content = projectJsonTemplate.TransformText();

            GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, string.Format("{0}.{1}.csproj", assemblyName, projectType), content);
        }
Example #17
0
        private void GenerateProjectFile(Project projectProperties, string unitTestProjectRoot, string projectFilename)
        {
            var    projectName      = Path.GetFileNameWithoutExtension(projectFilename);
            string generatedContent = null;

            try
            {
                var projectTemplateType = Type.GetType(
                    "ServiceClientGenerator.Generators.ProjectFiles." +
                    TemplateName);
                dynamic generator = Activator.CreateInstance(projectTemplateType);
                generator.Project = projectProperties;
                generatedContent  = generator.TransformText();
            }
            catch (Exception)
            {
                throw new ArgumentException("Project template name "
                                            + TemplateName + " is not recognized");
            }

            GeneratorDriver.WriteFile(unitTestProjectRoot, string.Empty, projectFilename, generatedContent);
        }
        void SetupProjectFile(string codeAnalysisRoot, ServiceConfiguration serviceConfiguration)
        {
            if (!Directory.Exists(codeAnalysisRoot))
            {
                Directory.CreateDirectory(codeAnalysisRoot);
            }

            var    assemblyName    = "AWSSDK." + serviceConfiguration.Namespace.Split('.')[1] + ".CodeAnalysis";
            var    projectFilename = string.Concat(assemblyName, ".csproj");
            string projectGuid;

            if (File.Exists(Path.Combine(codeAnalysisRoot, projectFilename)))
            {
                Console.WriteLine("...updating existing project file {0}", projectFilename);
                var projectPath = Path.Combine(codeAnalysisRoot, projectFilename);
                projectGuid = Utils.GetProjectGuid(projectPath);
            }
            else
            {
                projectGuid = Utils.NewProjectGuid;
                Console.WriteLine("...creating project file {0}", projectFilename);
            }

            var templateSession = new Dictionary <string, object>();

            templateSession["ProjectGuid"]       = projectGuid;
            templateSession["RootNamespace"]     = serviceConfiguration.Namespace + ".CodeAnalysis";
            templateSession["AssemblyName"]      = assemblyName;
            templateSession["SourceDirectories"] = GetProjectSourceFolders(codeAnalysisRoot);
            templateSession["EmbeddedResources"] = GetEmbeddedResources(codeAnalysisRoot);

            CodeAnalysisProjectFile generator = new CodeAnalysisProjectFile();

            generator.Session = templateSession;
            var generatedContent = generator.TransformText();

            GeneratorDriver.WriteFile(codeAnalysisRoot, string.Empty, projectFilename, generatedContent);
        }
Example #19
0
        private void GeneratePlatformSpecificSolution(ProjectFileConfiguration projectConfig, bool includeTests, bool travisSolution, string solutionFileName = null)
        {
            // Do not generate solutions for PCL sub profiles.
            if (projectConfig.IsSubProfile)
            {
                return;
            }

            var projectType = projectConfig.Name;

            Console.WriteLine("...generating platform-specific solution file AWSSDK.{0}.sln", projectType);

            var session = new Dictionary <string, object>();

            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var solutionProjects    = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            var projectTypeWildCard = string.Format("AWSSDK.*.{0}.csproj", projectType);

            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);

            var coreProjects     = new List <Project>();
            var coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);

            foreach (var projectFile in Directory.GetFiles(coreProjectsRoot, projectTypeWildCard, SearchOption.TopDirectoryOnly))
            {
                coreProjects.Add(CoreProjectFromFile(projectFile));
                SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
            }

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);

                foreach (var projectFile in Directory.GetFiles(servicePath, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                {
                    if (travisSolution && projectFile.Contains("AWSSDK.MobileAnalytics"))
                    {
                        continue;
                    }

                    folder.Projects.Add(ServiceProjectFromFile(di.Name, projectFile));
                    SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                }

                serviceSolutionFolders.Add(folder);
            }

            var testProjects = new List <Project>();

            if (includeTests)
            {
                var sdkTestsFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.TestsSubFoldername);
                foreach (var testFoldername in new[] { GeneratorDriver.CommonTestSubFoldername, GeneratorDriver.UnitTestsSubFoldername, GeneratorDriver.IntegrationTestsSubFolderName })
                {
                    var testFolder = Path.Combine(sdkTestsFolder, testFoldername);
                    foreach (var projectFile in Directory.GetFiles(testFolder, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                    {
                        testProjects.Add(TestProjectFromFile(testFoldername, projectFile));

                        var projectKey = Path.GetFileNameWithoutExtension(projectFile);
                        solutionProjects.Add(projectKey, _allProjects[projectKey]);
                        SelectBuildConfigurationsForProject(projectKey, buildConfigurations);
                    }
                }

                if (projectType.Equals(ProjectTypes.Net35, StringComparison.Ordinal) || projectType.Equals(ProjectTypes.Net45, StringComparison.Ordinal))
                {
                    solutionProjects.Add(GeneratorLibProjectName, GeneratorLibProjectConfig);
                    testProjects.Add(GeneratorLibProject);
                    SelectBuildConfigurationsForProject(GeneratorLibProjectName, buildConfigurations);
                }

                AddExtraTestProjects(projectConfig, solutionProjects, testProjects);
            }

            var configurationsList = buildConfigurations.ToList();

            configurationsList.Sort();

            session["AllProjects"]            = solutionProjects;
            session["CoreProjects"]           = coreProjects;
            session["ServiceSolutionFolders"] = serviceSolutionFolders;
            session["TestProjects"]           = testProjects;
            session["Configurations"]         = configurationsList;

            var generator = new SolutionFileGenerator {
                Session = session
            };
            var content = generator.TransformText();

            if (string.IsNullOrEmpty(solutionFileName))
            {
                solutionFileName = string.Format("AWSSDK.{0}.sln", projectType);
            }
            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, solutionFileName, content, true, false);
        }
Example #20
0
        private void GenerateVS2017Solution(string solutionFileName, bool includeTests, bool isTravisSolution, IEnumerable <ProjectFileConfiguration> projectFileConfigurations, ICollection <string> serviceProjectsForPartialBuild = null)
        {
            //
            // Since vs2017 .csproj files are not identified by guid, see if we can scan and determine the guid ahead of time to reduce changes
            // to .sln files if possible.
            //
            IDictionary <string, string> projectGuidDictionary = GetItemGuidDictionary(Path.Combine(Options.SdkRootFolder, solutionFileName));

            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);
            var session         = new Dictionary <string, object>();

            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var solutionProjects    = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);

                // If we are generating a partial solution, and the service project has not changed, omit it from the partial solution.
                bool omitService = serviceProjectsForPartialBuild != null && !serviceProjectsForPartialBuild.Contains(di.Name, StringComparer.InvariantCultureIgnoreCase);
                if (omitService)
                {
                    continue;
                }

                foreach (var configuration in projectFileConfigurations)
                {
                    string projectFilePattern = string.Format("*.{0}.csproj", configuration.Name);
                    foreach (var projectFile in Directory.GetFiles(servicePath, projectFilePattern, SearchOption.TopDirectoryOnly))
                    {
                        if (isTravisSolution && projectFile.Contains("AWSSDK.MobileAnalytics"))
                        {
                            continue;
                        }

                        string projectName = Path.GetFileNameWithoutExtension(projectFile);
                        folder.Projects.Add(new Project
                        {
                            Name        = projectName,
                            ProjectPath = string.Format(@"src\Services\{0}\{1}", di.Name, Path.GetFileName(projectFile)),
                            ProjectGuid = projectGuidDictionary.ContainsKey(projectName) ? projectGuidDictionary[projectName] : Guid.NewGuid().ToString("B").ToUpper(),
                        });
                        SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                    }
                }

                if (folder.Projects.Count > 0)
                {
                    serviceSolutionFolders.Add(folder);
                }
            }

            IList <Project> coreProjects     = new List <Project>();
            var             coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);

            foreach (var configuration in projectFileConfigurations)
            {
                string projectFilePattern = string.Format("*.{0}.csproj", configuration.Name);
                foreach (var projectFile in Directory.GetFiles(coreProjectsRoot, projectFilePattern, SearchOption.TopDirectoryOnly))
                {
                    string projectName = Path.GetFileNameWithoutExtension(projectFile);
                    coreProjects.Add(new Project
                    {
                        Name        = projectName,
                        ProjectPath = string.Format(@"src\Core\{0}", Path.GetFileName(projectFile)),
                        ProjectGuid = projectGuidDictionary.ContainsKey(projectName) ? projectGuidDictionary[projectName] : Guid.NewGuid().ToString("B").ToUpper(),
                    });
                }
            }

            IList <Project> testProjects = new List <Project>();

            if (includeTests)
            {
                var testProjectsRoot = Path.Combine(Options.SdkRootFolder, GeneratorDriver.TestsSubFoldername);
                foreach (var configuration in projectFileConfigurations)
                {
                    string projectFilePattern = string.Format("*.{0}.csproj", configuration.Name);
                    foreach (var projectFile in Directory.GetFiles(testProjectsRoot, projectFilePattern, SearchOption.AllDirectories))
                    {
                        string projectName = Path.GetFileNameWithoutExtension(projectFile);
                        testProjects.Add(new Project
                        {
                            Name        = projectName,
                            ProjectPath = CreateRelativePath(Options.SdkRootFolder, projectFile),
                            ProjectGuid = projectGuidDictionary.ContainsKey(projectName) ? projectGuidDictionary[projectName] : Guid.NewGuid().ToString("B").ToUpper(),
                        });
                    }

                    if (configuration.Name.Equals(ProjectTypes.Net35, StringComparison.Ordinal) || configuration.Name.Equals(ProjectTypes.Net45, StringComparison.Ordinal))
                    {
                        solutionProjects.Add(GeneratorLibProjectName, GeneratorLibProjectConfig);
                        testProjects.Add(GeneratorLibProject);
                        SelectBuildConfigurationsForProject(GeneratorLibProjectName, buildConfigurations);
                    }
                }
            }
            session["TestProjects"]           = testProjects;
            session["CoreProjects"]           = coreProjects;
            session["ServiceSolutionFolders"] = serviceSolutionFolders;

            var generator = new CoreCLRSolutionFile()
            {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, solutionFileName, content, true, false);
        }
Example #21
0
        private void GenerateBuildUnitTestSolution(string solutionFileName, IEnumerable <ProjectFileConfiguration> projectFileConfigurations, ICollection <string> serviceProjectsForPartialBuild = null)
        {
            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // AllProjects
            var solutionProjects = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            // CoreProjects
            var coreProjects = new List <Project>();

            // TestProjects
            var testProjects = new List <Project>
            {
                GeneratorLibProject
            };

            foreach (var pfc in projectFileConfigurations)
            {
                var projectType    = pfc.Name;
                var sdkTestsFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.TestsSubFoldername);

                // Add partial project files
                var projectTypeWildCard = string.Format("AWSSDK.*.{0}.partial.csproj", pfc.Name);
                var testFolder          = Path.Combine(sdkTestsFolder, GeneratorDriver.UnitTestsSubFoldername);
                foreach (var projectFile in Directory.GetFiles(testFolder, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                {
                    testProjects.Add(TestProjectFromFile(GeneratorDriver.UnitTestsSubFoldername, projectFile));

                    var projectKey = Path.GetFileNameWithoutExtension(projectFile);
                    solutionProjects.Add(projectKey, _allProjects[projectKey]);
                    SelectBuildConfigurationsForProject(projectKey, buildConfigurations);
                }

                // Add common test project files
                projectTypeWildCard = string.Format("AWSSDK.*.{0}.csproj", pfc.Name);
                testFolder          = Path.Combine(sdkTestsFolder, GeneratorDriver.CommonTestSubFoldername);
                foreach (var projectFile in Directory.GetFiles(testFolder, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                {
                    testProjects.Add(TestProjectFromFile(GeneratorDriver.CommonTestSubFoldername, projectFile));

                    var projectKey = Path.GetFileNameWithoutExtension(projectFile);
                    solutionProjects.Add(projectKey, _allProjects[projectKey]);
                    SelectBuildConfigurationsForProject(projectKey, buildConfigurations);
                }

                if (projectType.Equals(ProjectTypes.Net35, StringComparison.Ordinal) || projectType.Equals(ProjectTypes.Net45, StringComparison.Ordinal) &&
                    !solutionProjects.ContainsKey(GeneratorLibProjectName))
                {
                    solutionProjects.Add(GeneratorLibProjectName, GeneratorLibProjectConfig);
                    SelectBuildConfigurationsForProject(GeneratorLibProjectName, buildConfigurations);
                }

                AddExtraTestProjects(pfc, solutionProjects, testProjects);
            }

            var configurationsList = buildConfigurations.ToList();

            configurationsList.Sort();

            var session = new Dictionary <string, object>();

            session["AllProjects"]            = solutionProjects;
            session["CoreProjects"]           = coreProjects;
            session["ServiceSolutionFolders"] = new List <ServiceSolutionFolder>();
            session["TestProjects"]           = testProjects;
            session["Configurations"]         = configurationsList;

            var generator = new SolutionFileGenerator {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, "Build.UnitTests.partial.sln", content, true, false);
        }
Example #22
0
        private void GenerateAllPlatformsSolution(string solutionFileName, IEnumerable <ProjectFileConfiguration> projectFileConfigurations)
        {
            var session = new Dictionary <string, object>();

            Console.WriteLine("...generating all-platforms solution file solutionFileName", solutionFileName);

            // use an AWSSDK prefix on project names so as to not collect any user-created projects (unless they
            // chose to use our naming pattern)
            const string awssdkProjectFileNamePattern = "AWSSDK.*.csproj";

            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);

            var coreProjects     = new List <Project>();
            var coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);

            foreach (var projectFile in Directory.GetFiles(coreProjectsRoot, awssdkProjectFileNamePattern, SearchOption.TopDirectoryOnly))
            {
                coreProjects.Add(CoreProjectFromFile(projectFile));
            }

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);

                foreach (var projectFile in Directory.GetFiles(servicePath, awssdkProjectFileNamePattern, SearchOption.TopDirectoryOnly))
                {
                    folder.Projects.Add(ServiceProjectFromFile(di.Name, projectFile));
                }

                serviceSolutionFolders.Add(folder);
            }

            var testProjects = new List <Project>
            {
                GeneratorLibProject
            };

            var sdkTestsFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.TestsSubFoldername);

            foreach (var testFoldername in new[] { GeneratorDriver.CommonTestSubFoldername, GeneratorDriver.UnitTestsSubFoldername, GeneratorDriver.IntegrationTestsSubFolderName })
            {
                var testsFolder = Path.Combine(sdkTestsFolder, testFoldername);
                foreach (var projectFile in Directory.GetFiles(testsFolder, awssdkProjectFileNamePattern, SearchOption.TopDirectoryOnly))
                {
                    testProjects.Add(TestProjectFromFile(testFoldername, projectFile));
                }
            }

            foreach (var pfc in projectFileConfigurations)
            {
                AddExtraTestProjects(pfc, _allProjects, testProjects);
            }

            // as we are processing _allProjects, construct the set of distinct build configurations at the end
            var distinctConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var projectKey in _allProjects.Keys)
            {
                foreach (var cp in _allProjects[projectKey].ConfigurationPlatforms)
                {
                    distinctConfigurations.Add(cp);
                }
            }

            var configurationsList = distinctConfigurations.ToList();

            configurationsList.Sort();

            session["AllProjects"]            = _allProjects;
            session["CoreProjects"]           = coreProjects;
            session["ServiceSolutionFolders"] = serviceSolutionFolders;
            session["TestProjects"]           = testProjects;
            session["Configurations"]         = configurationsList;

            var generator = new SolutionFileGenerator {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, solutionFileName, content, true, false);
        }
Example #23
0
        private void GenerateCombinedSolution(string solutionFileName, bool includeTests, IEnumerable <ProjectFileConfiguration> projectFileConfigurations)
        {
            Console.WriteLine("Generating solution file {0}", solutionFileName);

            var session = new Dictionary <string, object>();

            var buildConfigurations = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var solutionProjects    = new Dictionary <string, ProjectFileCreator.ProjectConfigurationData>();

            var sdkSourceFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.SourceSubFoldername);

            var coreProjects     = new List <Project>();
            var coreProjectsRoot = Path.Combine(sdkSourceFolder, GeneratorDriver.CoreSubFoldername);

            foreach (var pfc in projectFileConfigurations)
            {
                var projectTypeWildCard = string.Format("AWSSDK.*.{0}.csproj", pfc.Name);
                foreach (var projectFile in Directory.GetFiles(coreProjectsRoot, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                {
                    coreProjects.Add(CoreProjectFromFile(projectFile));
                    SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                }
            }

            var serviceSolutionFolders = new List <ServiceSolutionFolder>();
            var serviceProjectsRoot    = Path.Combine(sdkSourceFolder, GeneratorDriver.ServicesSubFoldername);

            foreach (var servicePath in Directory.GetDirectories(serviceProjectsRoot))
            {
                var di     = new DirectoryInfo(servicePath);
                var folder = ServiceSolutionFolderFromPath(di.Name);
                foreach (var pfc in projectFileConfigurations)
                {
                    var projectTypeWildCard = string.Format("AWSSDK.*.{0}.csproj", pfc.Name);
                    foreach (var projectFile in Directory.GetFiles(servicePath, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                    {
                        folder.Projects.Add(ServiceProjectFromFile(di.Name, projectFile));
                        SelectProjectAndConfigurationsForSolution(projectFile, solutionProjects, buildConfigurations);
                    }
                }

                if (folder.Projects.Count > 0)
                {
                    serviceSolutionFolders.Add(folder);
                }
            }

            var testProjects = new List <Project>();

            if (includeTests)
            {
                foreach (var pfc in projectFileConfigurations)
                {
                    var projectType         = pfc.Name;
                    var projectTypeWildCard = string.Format("AWSSDK.*.{0}.csproj", pfc.Name);

                    var sdkTestsFolder = Path.Combine(Options.SdkRootFolder, GeneratorDriver.TestsSubFoldername);
                    foreach (var testFoldername in new[] { GeneratorDriver.CommonTestSubFoldername, GeneratorDriver.UnitTestsSubFoldername, GeneratorDriver.IntegrationTestsSubFolderName })
                    {
                        var testFolder = Path.Combine(sdkTestsFolder, testFoldername);
                        foreach (var projectFile in Directory.GetFiles(testFolder, projectTypeWildCard, SearchOption.TopDirectoryOnly))
                        {
                            testProjects.Add(TestProjectFromFile(testFoldername, projectFile));

                            var projectKey = Path.GetFileNameWithoutExtension(projectFile);
                            solutionProjects.Add(projectKey, _allProjects[projectKey]);
                            SelectBuildConfigurationsForProject(projectKey, buildConfigurations);
                        }
                    }

                    if (projectType.Equals(ProjectTypes.Net35, StringComparison.Ordinal) || projectType.Equals(ProjectTypes.Net45, StringComparison.Ordinal) &&
                        !solutionProjects.ContainsKey(GeneratorLibProjectName))
                    {
                        solutionProjects.Add(GeneratorLibProjectName, GeneratorLibProjectConfig);
                        testProjects.Add(GeneratorLibProject);
                        SelectBuildConfigurationsForProject(GeneratorLibProjectName, buildConfigurations);
                    }

                    AddExtraTestProjects(pfc, solutionProjects, testProjects);
                }
            }

            var configurationsList = buildConfigurations.ToList();

            configurationsList.Sort();

            session["AllProjects"]            = solutionProjects;
            session["CoreProjects"]           = coreProjects;
            session["ServiceSolutionFolders"] = serviceSolutionFolders;
            session["TestProjects"]           = testProjects;
            session["Configurations"]         = configurationsList;

            var generator = new SolutionFileGenerator {
                Session = session
            };
            var content = generator.TransformText();

            GeneratorDriver.WriteFile(Options.SdkRootFolder, null, solutionFileName, content, true, false);
        }