public void ShouldCreateSolutionWithDockerComposeProjectManualVerify() { //Arrange var metaRepo = new MetaRepoBuilder().BuildSampleMetaRepo(); var dockerComposeFile = new DockerComposeFileService().Build(metaRepo); var project = new CProject() { ProjectName = "docker-compose", ProjectIs = CProjectIs.DockerCompose, ProjectType = CProjectType.DockerProj, TemplateProjectPath = @"templates\Docker\docker-compose.dcproj" }; project.ProjectContent.Add(new CProjectContent { Content = dockerComposeFile, File = new CFile { FileName = "docker-compose.yml" }, BuildAction = CBuildAction.None }); var solution = new CSolution() { SolutionName = "MetaSolution" }; solution.Project.Add(project); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddTransient <IVisualStudioSolutionWriter, VisualStudioSolutionWriter>(); var serviceProvider = serviceCollection.BuildServiceProvider(); var writer = serviceProvider.GetRequiredService <IVisualStudioSolutionWriter>(); //Act writer.Write(@"c:\temp\", solution); //Assert //todo: manual verification }
public CProject BuildProject(KSolution kSolution, KDockerComposeProject dockerComposeKProject) { _dockerComposeKProject = dockerComposeKProject; var project = new CProject { ProjectName = dockerComposeKProject.ProjectFullName, ProjectShortName = dockerComposeKProject.ProjectShortName, ProjectFolder = dockerComposeKProject.ProjectFolder, ProjectType = CProjectType.DockerProj, ProjectIs = dockerComposeKProject.ProjectIs }; project.TemplateProjectPath = @"templates\Docker\docker-compose.dcproj"; var dockerComposeFile = new DockerComposeFileService().Build(); project.ProjectContent.Add(new CProjectContent { Content = dockerComposeFile, File = new CFile { FileName = "docker-compose.yml" }, BuildAction = CBuildAction.None }); return(project); }
public void BuildSellersMegaSolution() { var tempPath = OutputDir; var codeWriter = new CodeWriter(); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddTransient <IVisualStudioSolutionWriter, VisualStudioSolutionWriter>(); serviceCollection.AddTransient <ICSolutionVisitor, FastSolutionVisitor>(); var fileWriter = new FileWriter(); fileWriter.RootPath = tempPath; serviceCollection.AddSingleton <IFileWriter>(fileWriter); serviceCollection.AddSingleton <ILogger <CVisualStudioVisitorBase> >(new Logger <CVisualStudioVisitorBase>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CMetaRepoVisitor> >(new Logger <CMetaRepoVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CRepoVisitor> >(new Logger <CRepoVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <VisualStudioSolutionWriter> >(new Logger <VisualStudioSolutionWriter>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CProjectVisitor> >(new Logger <CProjectVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CProjectFileVisitor> >(new Logger <CProjectFileVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CProjectContentVisitor> >(new Logger <CProjectContentVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CDockerComposeFileVisitor> >(new Logger <CDockerComposeFileVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ILogger <CDockerFileServiceVisitor> >(new Logger <CDockerFileServiceVisitor>(new NullLoggerFactory())); serviceCollection.AddSingleton <ICodeWriter>(codeWriter); serviceCollection.AddTransient <ICVisualStudioVisitorBase, CVisualStudioVisitorBase>(); serviceCollection.AddTransient <IFastSolutionVisitor, FastSolutionVisitor>(); //serviceCollection.AddTransient<ICVisualStudioVisitor, CVisualStudioVisitor>(); serviceCollection.AddTransient <ICMetaRepoVisitor, CMetaRepoVisitor>(); serviceCollection.AddTransient <ICRepoVisitor, CRepoVisitor>(); serviceCollection.AddTransient <ICVisualStudioVisitor, CVisualStudioVisitor>(); //var serviceProvider = serviceCollection.BuildServiceProvider(); var container = new Container(); container.Configure(config => { config.Scan(scanner => { scanner.AssemblyContainingType <ILogger>(); scanner.AssemblyContainingType <IKickstartService>(); scanner.SingleImplementationsOfInterface(); }); config.Populate(serviceCollection); }); var serviceProvider = container.GetInstance <IServiceProvider>(); var metaRepo = new MetaRepoBuilder().BuildSampleMetaRepo(); var visitor = serviceProvider.GetRequiredService <ICVisualStudioVisitorBase>(); // new CVisualStudioVisitor(new Mock<ILogger>().Object, codeWriter); metaRepo.Accept(visitor as IVisitor); Directory.CreateDirectory(tempPath); //http://thesoftwarecondition.com/blog/2014/06/08/nuget-issues-with-nested-solutions-branches/ //get code from repos CommandProcessor.ExecuteCommandWindow(codeWriter.ToString(), tempPath, true); UpdateLibraryPaths(tempPath); var compositeSolution = new CSolution() { SolutionName = metaRepo.MetaRepoName }; compositeSolution.SolutionPath = Path.Combine(tempPath, $"{compositeSolution.SolutionName}.sln"); var compositeRepo = new CRepo(); compositeRepo.RepoSolution.Add(compositeSolution); metaRepo.CompositeRepo = compositeRepo; //todo: dockerize Asp.Net apps //set docker-compose to looking in the Publish folder otherwise there's way too many files //add docker file to project //set dockerfile to copy when Publish //find all the solutions in repos foreach (var repo in metaRepo.Repos) { var repoPath = Path.Combine(tempPath, repo.Name); var solutionPaths = new VisualStudioScanner().ScanForSolutions(repoPath); var solutions = new SlnToCSolutionConverter().Convert(solutionPaths); repo.RepoSolution.Clear();//remove any existing foreach (var solution in solutions) { if (repo.SolutionWhiteList.Count > 0 && !repo.SolutionWhiteList.Contains(solution.SolutionName)) { continue; } repo.RepoSolution.Add(solution); } } var dockerComposeFile = new DockerComposeFileService().Build(metaRepo); var dockerComposeProject = new CProject() { ProjectName = "docker-compose", ProjectIs = CProjectIs.DockerCompose, ProjectType = CProjectType.DockerProj, TemplateProjectPath = @"templates\Docker\docker-compose.dcproj" }; dockerComposeProject.ProjectContent.Add(new CProjectContent { Content = dockerComposeFile, File = new CFile { FileName = "docker-compose.yml", Encoding = Encoding.ASCII }, BuildAction = CBuildAction.None }); compositeSolution.Project.Add(dockerComposeProject); var writer = serviceProvider.GetRequiredService <IVisualStudioSolutionWriter>(); writer.Write(tempPath, compositeSolution); //add all the projects to the composite solution var fastSolutionVisitor = serviceProvider.GetRequiredService <IFastSolutionVisitor>(); // new FastSolutionVisitor(codeWriter, new Mock<IFileWriter>().Object); foreach (var repo in metaRepo.Repos) { foreach (var solution in repo.RepoSolution) { fastSolutionVisitor.AddAllProjectsToMasterSln(solution, tempPath, compositeSolution.SolutionName); } } //generate batch script to do "Nuget Restore" //todo: move into library var batchWriter = new CodeWriter(); foreach (var repo in metaRepo.Repos) { foreach (var solution in repo.RepoSolution) { System.Uri uri1 = new Uri(tempPath); System.Uri uri2 = new Uri(Path.GetDirectoryName(solution.SolutionPath)); Uri relativeUri = uri1.MakeRelativeUri(uri2); var relativePath = relativeUri.ToString().Replace("%20", " "); batchWriter.WriteLine($@"copy nuget.exe ""{relativePath}/nuget.exe"" /Y"); batchWriter.WriteLine($"cd {relativePath}"); batchWriter.WriteLine($@"Nuget Restore ""{solution.SolutionPath}"""); batchWriter.WriteLine($@"del nuget.exe"); batchWriter.WriteLine("cd /D %~dp0"); //go back to where batch was run } } File.WriteAllText(Path.Combine(tempPath, "NugetRestore.cmd"), batchWriter.ToString()); }