public void Test_Maven_Google()
        {
            MavenRepository repo = MavenRepository.FromGoogle();

            repo.Refresh("androidx.car");

            global::MavenNet.Models.Project project;
            project = repo.GetProjectAsync("androidx.car", "car").Result;

            #if MSTEST
            Assert.IsNotNull(repo);
            #elif NUNIT
            Assert.NotNull(repo);
            #elif XUNIT
            Assert.NotNull(repo);
            #endif

            return;
        }
Beispiel #2
0
        static async Task ProcessConfig(MavenRepository maven, BindingConfig config)
        {
            var mavenProjects = new Dictionary <string, Project>();
            var mavenGroups   = new List <MavenGroup>();

            foreach (var artifact in config.MavenArtifacts)
            {
                if (artifact.DependencyOnly)
                {
                    continue;
                }

                var mavenGroup = maven.Groups.FirstOrDefault(g => g.Id == artifact.GroupId);

                Project project = null;

                project = await maven.GetProjectAsync(artifact.GroupId, artifact.ArtifactId, artifact.Version);

                if (project != null)
                {
                    mavenProjects.Add($"{artifact.GroupId}/{artifact.ArtifactId}-{artifact.Version}", project);
                }
            }

            if (config.DownloadExternals)
            {
                await DownloadArtifacts(maven, config, mavenProjects);
            }

            var slnProjModels = new Dictionary <string, BindingProjectModel>();

            foreach (var template in config.Templates)
            {
                var models = BuildProjectModels(config, template, mavenProjects);

                var json = Newtonsoft.Json.JsonConvert.SerializeObject(models);

                if (config.Debug.DumpModels)
                {
                    File.WriteAllText(Path.Combine(config.BasePath, "models.json"), json);
                }

                var inputTemplateFile = Path.Combine(config.BasePath, template.TemplateFile);
                var templateSrc       = File.ReadAllText(inputTemplateFile);

                var engine = new RazorLightEngineBuilder()
                             .UseMemoryCachingProvider()
                             .Build();

                foreach (var model in models)
                {
                    var outputFile = new FileInfo(template.GetOutputFile(config, model));
                    if (!outputFile.Directory.Exists)
                    {
                        outputFile.Directory.Create();
                    }

                    string result = await engine.CompileRenderAsync(inputTemplateFile, templateSrc, model);

                    File.WriteAllText(outputFile.FullName, result);

                    // We want to collect all the models for the .csproj's so we can add them to a .sln file after
                    if (!slnProjModels.ContainsKey(outputFile.FullName) && template.OutputFileRule.EndsWith(".csproj"))
                    {
                        slnProjModels.Add(outputFile.FullName, model);
                    }
                }
            }

            if (!string.IsNullOrEmpty(config.SolutionFile))
            {
                var slnPath = Path.Combine(config.BasePath ?? AppDomain.CurrentDomain.BaseDirectory, config.SolutionFile);
                var sln     = SolutionFileBuilder.Build(config, slnProjModels);
                File.WriteAllText(slnPath, sln);
            }
        }