Represents the metadata needed to generate a platform-specific project file for a service (eg compile constants, build configuration and platform etc).
Пример #1
0
        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList <string> GetProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string serviceRootFolder)
        {
            // Start with the standard generated code folders for the platform
            var sourceCodeFolders = new List <string>
            {
                "Generated",
                @"Generated\Model",
                @"Generated\Model\Internal",
                @"Generated\Model\Internal\MarshallTransformations"
            };

            var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;

            sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            // Augment the returned folders with any custom subfolders already in existence. If the custom folder
            // ends with a recognised platform, only add it to the set if it matches the platform being generated
            if (Directory.Exists(serviceRootFolder))
            {
                var subFolders = Directory.GetDirectories(serviceRootFolder, "*", SearchOption.AllDirectories);
                if (subFolders.Any())
                {
                    foreach (var folder in subFolders)
                    {
                        var serviceRelativeFolder = folder.Substring(serviceRootFolder.Length);

                        if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
                        {
                            if (projectFileConfiguration.IsValidPlatformPathForProject(serviceRelativeFolder))
                            {
                                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                            }
                        }
                        else
                        {
                            sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                        }
                    }
                }
            }

            var foldersThatExist = new List <string>();

            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(serviceRootFolder, folder)))
                {
                    foldersThatExist.Add(folder);
                }
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return(foldersThatExist);
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
        /// <summary>
        /// Parses the Visual Studio project metadata entries from the manifest. These
        /// are used when generating project files for a service.
        /// Sets the ProjectFileConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        void LoadProjectConfigurations(JsonData document)
        {
            var projectConfigurations = new List <ProjectFileConfiguration>();

            var projectsNode = document[ProjectsSectionKeys.ProjectsKey];

            foreach (JsonData projectNode in projectsNode)
            {
                var projectTypeName = projectNode[ProjectsSectionKeys.NameKey].ToString();
                var config          = new ProjectFileConfiguration
                {
                    Name = projectTypeName,
                    TargetFrameworkVersion = projectNode[ProjectsSectionKeys.TargetFrameworkKey].ToString(),
                    CompilationConstants   = projectNode[ProjectsSectionKeys.DefineConstantsKey].ToString(),
                    BinSubFolder           = projectNode[ProjectsSectionKeys.BinSubFolderKey].ToString(),
                    Template            = projectNode[ProjectsSectionKeys.TemplateKey].ToString(),
                    NuGetTargetPlatform = projectNode[ProjectsSectionKeys.NuGetTargetFrameworkKey] == null ? string.Empty : projectNode[ProjectsSectionKeys.NuGetTargetFrameworkKey].ToString(),
                    Configurations      = (from object bc in projectNode[ProjectsSectionKeys.ConfigurationsKey] select bc.ToString()).ToList(),
                    PlatformCodeFolders = (from object pcf in projectNode[ProjectsSectionKeys.PlatformCodeFoldersKey] select pcf.ToString()).ToList(),
                };

                var extraTestProjects = projectNode.SafeGet(ProjectsSectionKeys.ExtraTestProjects);
                if (extraTestProjects == null)
                {
                    config.ExtraTestProjects = new List <string>();
                }
                else
                {
                    config.ExtraTestProjects = (from object etp in extraTestProjects
                                                select etp.ToString()).ToList();
                }

                var sharedNugetFrameworks = projectNode.SafeGet(ProjectsSectionKeys.SharedNugetTargetFrameworksKey);
                config.SharedNugetTargetFrameworks = sharedNugetFrameworks == null ? new List <string>() : (from object bc in sharedNugetFrameworks select bc.ToString()).ToList();

                // This code assumes that the parent profile (project configuration) is defined in the manifest
                // before it's being referred by a sub profile.
                if (projectNode.PropertyNames.Contains(ProjectsSectionKeys.ParentProfile))
                {
                    var parentProfileName = projectNode[ProjectsSectionKeys.ParentProfile].ToString();
                    if (!string.IsNullOrEmpty(parentProfileName))
                    {
                        var parentProfile = projectConfigurations.SingleOrDefault(
                            p => p.Name.Equals(parentProfileName, StringComparison.InvariantCulture));
                        if (parentProfile == null)
                        {
                            throw new KeyNotFoundException(string.Format("Parent profile {0} referred by current profile {1} does not exist.",
                                                                         parentProfile, config.Name));
                        }
                        config.ParentProfile = parentProfile;
                    }
                }

                projectConfigurations.Add(config);
            }

            ProjectFileConfigurations = projectConfigurations;
        }
Пример #4
0
        private void AddExtraTestProjects(ProjectFileConfiguration projectConfig, Dictionary <string, ProjectFileCreator.ProjectConfigurationData> solutionProjects, List <Project> testProjects)
        {
            foreach (var extraTestProject in projectConfig.ExtraTestProjects)
            {
                var projectPath = @"..\..\..\..\sdk\" + extraTestProject;

                var projectGuid = Utils.GetProjectGuid(projectPath);
                var testProject = ProjectFromFile(extraTestProject, projectGuid);

                var testProjectConfig = new ProjectFileCreator.ProjectConfigurationData
                {
                    ProjectGuid            = projectGuid,
                    ConfigurationPlatforms = GetProjectPlatformsFromFile(projectPath).ToList()
                };

                solutionProjects.Add(testProject.Name, testProjectConfig);
                testProjects.Add(testProject);
            }
        }
Пример #5
0
        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList <string> GetCoreProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string coreRootFolder)
        {
            var exclusionList = new List <string>
            {
                "Properties",
                "bin",
                "obj",
                ".vs"
            };

            // Start with the standard folders for core
            var sourceCodeFolders = new List <string>
            {
                "."
            };

            var childDirectories = Directory.GetDirectories(coreRootFolder, "*", SearchOption.AllDirectories);

            foreach (var childDirectory in childDirectories)
            {
                var folder = childDirectory.Substring(coreRootFolder.Length).TrimStart('\\');

                if (exclusionList.Any(e => folder.Equals(e, StringComparison.InvariantCulture) ||
                                      folder.StartsWith(e + "\\", StringComparison.InvariantCulture)))
                {
                    continue;
                }

                if (projectFileConfiguration.IsPlatformCodeFolder(folder))
                {
                    if (projectFileConfiguration.IsValidPlatformPathForProject(folder))
                    {
                        sourceCodeFolders.Add(folder);
                    }
                }
                else
                {
                    sourceCodeFolders.Add(folder);
                }
            }



            //var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;
            //sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            //// Augment the returned folders with any custom subfolders already in existence. If the custom folder
            //// ends with a recognised platform, only add it to the set if it matches the platform being generated
            ////if (Directory.Exists(serviceRootFolder))
            //{
            //    var subFolders = Directory.GetDirectories(coreRootFolder, "*", SearchOption.AllDirectories);
            //    subFolders = subFolders.Except(exclusionList).ToArray();
            //    if (subFolders.Any())
            //    {
            //        foreach (var folder in subFolders)
            //        {
            //            var serviceRelativeFolder = folder.Substring(coreRootFolder.Length);

            //            if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
            //                continue;

            //            if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
            //            {
            //                if (projectFileConfiguration.IsValidPlatformCodeFolderForProject(serviceRelativeFolder))
            //                    sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
            //            }
            //            else
            //                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
            //        }
            //    }
            //}

            var foldersThatExist = new List <string>();

            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(coreRootFolder, folder)))
                {
                    foldersThatExist.Add(folder);
                }
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return(foldersThatExist);
        }
Пример #6
0
        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);
        }
Пример #7
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);
        }
Пример #8
0
        /// <summary>
        /// Parses the Visual Studio project metadata entries from the manifest. These
        /// are used when generating project files for a service.
        /// Sets the ProjectFileConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        void LoadProjectConfigurations(JsonData document)
        {
            var projectConfigurations = new List<ProjectFileConfiguration>();

            var projectsNode = document[ProjectsSectionKeys.ProjectsKey];
            foreach (JsonData projectNode in projectsNode)
            {
                var projectTypeName = projectNode[ProjectsSectionKeys.NameKey].ToString();
                var config = new ProjectFileConfiguration
                {
                    Name = projectTypeName,
                    TargetFrameworkVersion = projectNode[ProjectsSectionKeys.TargetFrameworkKey].ToString(),
                    CompilationConstants = projectNode[ProjectsSectionKeys.DefineConstantsKey].ToString(),
                    BinSubFolder = projectNode[ProjectsSectionKeys.BinSubFolderKey].ToString(),
                    Template = projectNode[ProjectsSectionKeys.TemplateKey].ToString(),
                    NuGetTargetPlatform = projectNode[ProjectsSectionKeys.NuGetTargetFrameworkKey] == null ? string.Empty : projectNode[ProjectsSectionKeys.NuGetTargetFrameworkKey].ToString()
                };

                config.Configurations = (from object bc in projectNode[ProjectsSectionKeys.ConfigurationsKey]
                                         select bc.ToString()).ToList();
                config.PlatformCodeFolders = (from object pcf in projectNode[ProjectsSectionKeys.PlatformCodeFoldersKey]
                                              select pcf.ToString()).ToList();
                var extraTestProjects = projectNode.SafeGet(ProjectsSectionKeys.ExtraTestProjects);
                if (extraTestProjects == null)
                {
                    config.ExtraTestProjects = new List<string>();
                }
                else
                {
                    config.ExtraTestProjects = (from object etp in extraTestProjects
                                                select etp.ToString()).ToList();
                }

                // This code assumes that the parent profile (project configuration) is defined in the manifest
                // before it's being referred by a sub profile.
                if (projectNode.PropertyNames.Contains(ProjectsSectionKeys.ParentProfile))
                {
                    var parentProfileName = projectNode[ProjectsSectionKeys.ParentProfile].ToString();
                    if (!string.IsNullOrEmpty(parentProfileName))
                    {
                        var parentProfile = projectConfigurations.SingleOrDefault(
                            p => p.Name.Equals(parentProfileName, StringComparison.InvariantCulture));
                        if (parentProfile == null)
                        {
                            throw new KeyNotFoundException(string.Format("Parent profile {0} referred by current profile {1} does not exist.",
                                parentProfile, config.Name));
                        }
                        config.ParentProfile = parentProfile;
                    }
                }

                projectConfigurations.Add(config);
            }

            ProjectFileConfigurations = projectConfigurations;
        }
Пример #9
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);
        }
Пример #10
0
        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be 
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList<string> GetProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string serviceRootFolder)
        {
            // Start with the standard generated code folders for the platform
            var sourceCodeFolders = new List<string>
            {
                "Generated", 
                @"Generated\Model", 
                @"Generated\Model\Internal", 
                @"Generated\Model\Internal\MarshallTransformations"
            };

            var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;
            sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            // Augment the returned folders with any custom subfolders already in existence. If the custom folder 
            // ends with a recognised platform, only add it to the set if it matches the platform being generated
            if (Directory.Exists(serviceRootFolder))
            {
                var subFolders = Directory.GetDirectories(serviceRootFolder, "*", SearchOption.AllDirectories);
                if (subFolders.Any())
                {
                    foreach (var folder in subFolders)
                    {
                        var serviceRelativeFolder = folder.Substring(serviceRootFolder.Length);

                        if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
                            continue;

                        

                        if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
                        {
                            if (projectFileConfiguration.IsValidPlatformPathForProject(serviceRelativeFolder))
                                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                        }
                        else
                            sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                    }
                }
            }

            var foldersThatExist = new List<string>();
            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(serviceRootFolder, folder)))
                    foldersThatExist.Add(folder);
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return foldersThatExist;
        }
Пример #11
0
        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be 
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList<string> GetCoreProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string coreRootFolder)
        {
            var exclusionList = new List<string>
            {
                "Properties",
                "bin",
                "obj"
            };

            // Start with the standard folders for core
            var sourceCodeFolders = new List<string>
            {
                "."
            };

            var childDirectories = Directory.GetDirectories(coreRootFolder, "*", SearchOption.AllDirectories);
            foreach (var childDirectory in childDirectories)
            {
                var folder = childDirectory.Substring(coreRootFolder.Length).TrimStart('\\');

                if (exclusionList.Any(e => folder.Equals(e, StringComparison.InvariantCulture) ||
                    folder.StartsWith(e + "\\", StringComparison.InvariantCulture)))
                    continue;

                if (projectFileConfiguration.IsPlatformCodeFolder(folder))
                {
                    if (projectFileConfiguration.IsValidPlatformPathForProject(folder))
                        sourceCodeFolders.Add(folder);
                }
                else
                {
                    sourceCodeFolders.Add(folder);
                }


            }



            //var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;
            //sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            //// Augment the returned folders with any custom subfolders already in existence. If the custom folder 
            //// ends with a recognised platform, only add it to the set if it matches the platform being generated
            ////if (Directory.Exists(serviceRootFolder))
            //{
            //    var subFolders = Directory.GetDirectories(coreRootFolder, "*", SearchOption.AllDirectories);
            //    subFolders = subFolders.Except(exclusionList).ToArray();
            //    if (subFolders.Any())
            //    {
            //        foreach (var folder in subFolders)
            //        {
            //            var serviceRelativeFolder = folder.Substring(coreRootFolder.Length);

            //            if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
            //                continue;

            //            if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
            //            {
            //                if (projectFileConfiguration.IsValidPlatformCodeFolderForProject(serviceRelativeFolder))
            //                    sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
            //            }
            //            else
            //                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
            //        }
            //    }
            //}

            var foldersThatExist = new List<string>();
            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(coreRootFolder, folder)))
                    foldersThatExist.Add(folder);
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return foldersThatExist;
        }
Пример #12
0
        /// <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;
        }
        /// <summary>
        /// Parses the Visual Studio project metadata entries from the manifest. These
        /// are used when generating project files for a service.
        /// Sets the ProjectFileConfigurations member on exit with the collection of loaded
        /// configurations.
        /// </summary>
        /// <param name="document"></param>
        void LoadProjectConfigurations(JsonData document)
        {
            var projectConfigurations = new List<ProjectFileConfiguration>();

            var projectsNode = document[ProjectsSectionKeys.ProjectsKey];
            foreach (JsonData projectNode in projectsNode)
            {
                var projectTypeName = projectNode[ProjectsSectionKeys.NameKey].ToString();
                var config = new ProjectFileConfiguration
                {
                    Name = projectTypeName,
                    TargetFrameworkVersion = projectNode[ProjectsSectionKeys.TargetFrameworkKey].ToString(),
                    CompilationConstants = projectNode[ProjectsSectionKeys.DefineConstantsKey].ToString(),
                    BinSubFolder = projectNode[ProjectsSectionKeys.BinSubFolderKey].ToString(),
                    Template = projectNode[ProjectsSectionKeys.TemplateKey].ToString()
                };

                config.Configurations = (from object bc in projectNode[ProjectsSectionKeys.ConfigurationsKey] 
                                         select bc.ToString()).ToList();
                config.PlatformCodeFolders = (from object pcf in projectNode[ProjectsSectionKeys.PlatformCodeFoldersKey]
                                              select pcf.ToString()).ToList();

                projectConfigurations.Add(config);
            }

            ProjectFileConfigurations = projectConfigurations;
        }
Пример #14
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;
            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);
        }
Пример #15
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.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);
        }
Пример #16
0
        private void AddExtraTestProjects(ProjectFileConfiguration projectConfig, Dictionary<string, ProjectFileCreator.ProjectConfigurationData> solutionProjects, List<Project> testProjects)
        {
            foreach (var extraTestProject in projectConfig.ExtraTestProjects)
            {
                var projectPath = @"..\..\..\..\sdk\" + extraTestProject;

                var projectGuid = Utils.GetProjectGuid(projectPath);
                var testProject = ProjectFromFile(extraTestProject, projectGuid);

                var testProjectConfig = new ProjectFileCreator.ProjectConfigurationData
                {
                    ProjectGuid = projectGuid,
                    ConfigurationPlatforms = GetProjectPlatformsFromFile(projectPath).ToList()
                };

                solutionProjects.Add(testProject.Name, testProjectConfig);
                testProjects.Add(testProject);
            }
        }
        /// <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);

            // have not found a reasonable way to be able to activate from a string typename and
            // cast back to actual generator type instance :-(. Was hoping to make this completely
            // generic.
            string generatedContent;
            switch (projectFileConfiguration.Template)
            {
                case "BclProjectFile":
                    {
                        var generator = new BclProjectFile { Session = session };
                        generatedContent = generator.TransformText();
                    }
                    break;
                case "PhoneProjectFile":
                    {
                        var generator = new PhoneProjectFile { Session = session };
                        generatedContent = generator.TransformText();
                    }
                    break;
                case "RtProjectFile":
                    {
                        var generator = new RtProjectFile { Session = session };
                        generatedContent = generator.TransformText();
                    }
                    break;
                case "PortableProjectFile":
                    {
                        var generator = new PortableProjectFile { Session = session };
                        generatedContent = generator.TransformText();
                    }
                    break;
                default:
                    throw new ArgumentException("Project template name " + projectFileConfiguration.Template + " is not recognized");
            }


            GeneratorDriver.WriteFile(serviceFilesRoot, string.Empty, projectFilename, generatedContent);
            projectConfiguration.ConfigurationPlatforms = projectFileConfiguration.Configurations;
        }