Ejemplo n.º 1
0
        static void AssignMetadata(BindingProjectModel project, TemplateConfig template)
        {
            // Calculate metadata from the config file and template file
            var baseMetadata = new Dictionary <string, string>();

            MergeValues(baseMetadata, project.Config.Metadata);
            MergeValues(baseMetadata, template.Metadata);

            // Add metadata for artifact
            var artifactMetadata = new Dictionary <string, string>();

            MergeValues(artifactMetadata, baseMetadata);

            if (project.MavenArtifacts.FirstOrDefault() is MavenArtifactModel artifact)
            {
                MergeValues(artifactMetadata, artifact.MavenArtifactConfig.Metadata);
            }

            project.Metadata = artifactMetadata;

            foreach (var art in project.MavenArtifacts)
            {
                art.Metadata = artifactMetadata;
            }

            // Add metadata for dependency
            var dependencyMetadata = new Dictionary <string, string>();

            MergeValues(dependencyMetadata, baseMetadata);

            if (project.NuGetDependencies.FirstOrDefault() is NuGetDependencyModel depMapping)
            {
                MergeValues(dependencyMetadata, depMapping.MavenArtifactConfig.Metadata);
            }

            foreach (var dep in project.NuGetDependencies)
            {
                dep.Metadata = dependencyMetadata;
                dep.MavenArtifact.Metadata = dependencyMetadata;
            }
        }
Ejemplo n.º 2
0
        static List <BindingProjectModel> BuildProjectModels(BindingConfig config, TemplateConfig template, Dictionary <string, Project> mavenProjects)
        {
            var projectModels = new List <BindingProjectModel>();

            var baseMetadata = new Dictionary <string, string>();

            MergeValues(baseMetadata, config.Metadata);
            MergeValues(baseMetadata, template.Metadata);

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

                if (!mavenProjects.TryGetValue($"{mavenArtifact.GroupId}/{mavenArtifact.ArtifactId}-{mavenArtifact.Version}", out var mavenProject))
                {
                    continue;
                }

                var artifactMetadata = new Dictionary <string, string>();
                MergeValues(artifactMetadata, baseMetadata);
                MergeValues(artifactMetadata, mavenArtifact.Metadata);

                var projectModel = new BindingProjectModel
                {
                    Name               = mavenArtifact.ArtifactId,
                    NuGetPackageId     = mavenArtifact.NugetPackageId,
                    NuGetVersionBase   = mavenArtifact.NugetVersion,
                    NuGetVersionSuffix = config.NugetVersionSuffix,
                    MavenGroupId       = mavenArtifact.GroupId,
                    AssemblyName       = mavenArtifact.AssemblyName,
                    Metadata           = artifactMetadata,
                    Config             = config
                };
                projectModels.Add(projectModel);


                var artifactDir        = Path.Combine(config.BasePath, config.ExternalsDir, mavenArtifact.GroupId);
                var artifactFile       = Path.Combine(artifactDir, $"{mavenArtifact.ArtifactId}.{mavenProject.Packaging}");
                var md5File            = artifactFile + ".md5";
                var sha256File         = artifactFile + ".sha256";
                var md5                = File.Exists(md5File) ? File.ReadAllText(md5File) : string.Empty;
                var sha256             = File.Exists(sha256File) ? File.ReadAllText(sha256File) : string.Empty;
                var artifactExtractDir = Path.Combine(artifactDir, mavenArtifact.ArtifactId);

                var proguardFile = Path.Combine(artifactExtractDir, "proguard.txt");

                projectModel.MavenArtifacts.Add(new MavenArtifactModel
                {
                    MavenGroupId           = mavenArtifact.GroupId,
                    MavenArtifactId        = mavenArtifact.ArtifactId,
                    MavenArtifactPackaging = mavenProject.Packaging,
                    MavenArtifactVersion   = mavenArtifact.Version,
                    MavenArtifactMd5       = md5,
                    MavenArtifactSha256    = sha256,
                    ProguardFile           = File.Exists(proguardFile) ? GetRelativePath(proguardFile, config.BasePath).Replace("/", "\\") : null,
                    Metadata = artifactMetadata,
                });


                // Gather maven dependencies to try and map out nuget dependencies
                foreach (var mavenDep in mavenProject.Dependencies)
                {
                    // We only really care about 'compile' scoped dependencies (also null/blank means compile)
                    if (!string.IsNullOrEmpty(mavenDep.Scope) && !mavenDep.Scope.ToLowerInvariant().Equals("compile"))
                    {
                        continue;
                    }

                    mavenDep.Version = FixVersion(mavenDep.Version);

                    var depMapping = config.MavenArtifacts.FirstOrDefault(
                        ma => !string.IsNullOrEmpty(ma.Version) &&
                        ma.GroupId == mavenDep.GroupId &&
                        ma.ArtifactId == mavenDep.ArtifactId &&
                        mavenDep.Satisfies(ma.Version));

                    if (depMapping == null)
                    {
                        throw new Exception($"No matching artifact config found for: {mavenDep.GroupId}.{mavenDep.ArtifactId}:{mavenDep.Version} to satisfy dependency of: {mavenArtifact.GroupId}.{mavenArtifact.ArtifactId}:{mavenArtifact.Version}");
                    }

                    var dependencyMetadata = new Dictionary <string, string>();
                    MergeValues(dependencyMetadata, baseMetadata);
                    MergeValues(dependencyMetadata, depMapping.Metadata);

                    projectModel.NuGetDependencies.Add(new NuGetDependencyModel
                    {
                        IsProjectReference = !depMapping.DependencyOnly,
                        NuGetPackageId     = depMapping.NugetPackageId,
                        NuGetVersionBase   = depMapping.NugetVersion,
                        NuGetVersionSuffix = config.NugetVersionSuffix,
                        Metadata           = dependencyMetadata,

                        MavenArtifact = new MavenArtifactModel
                        {
                            MavenGroupId         = mavenDep.GroupId,
                            MavenArtifactId      = mavenDep.ArtifactId,
                            MavenArtifactVersion = mavenDep.Version,
                            MavenArtifactMd5     = md5,
                            MavenArtifactSha256  = sha256,
                            DownloadedArtifact   = artifactFile,
                            Metadata             = dependencyMetadata,
                        }
                    });
                }
            }

            return(projectModels);
        }
Ejemplo n.º 3
0
        static List <BindingProjectModel> BuildProjectModels(BindingConfig config, TemplateConfig template, Dictionary <string, Project> mavenProjects)
        {
            var projectModels = new List <BindingProjectModel>();
            var exceptions    = new List <Exception>();

            var baseMetadata = new Dictionary <string, string>();

            MergeValues(baseMetadata, config.Metadata);
            MergeValues(baseMetadata, template.Metadata);

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

                if (!mavenProjects.TryGetValue($"{mavenArtifact.GroupId}/{mavenArtifact.ArtifactId}-{mavenArtifact.Version}", out var mavenProject))
                {
                    continue;
                }

                var artifactMetadata = new Dictionary <string, string>();
                MergeValues(artifactMetadata, baseMetadata);
                MergeValues(artifactMetadata, mavenArtifact.Metadata);

                var projectModel = new BindingProjectModel
                {
                    Name               = mavenArtifact.ArtifactId,
                    NuGetPackageId     = mavenArtifact.NugetPackageId,
                    NuGetVersionBase   = mavenArtifact.NugetVersion,
                    NuGetVersionSuffix = config.NugetVersionSuffix,
                    MavenGroupId       = mavenArtifact.GroupId,
                    AssemblyName       = mavenArtifact.AssemblyName,
                    Metadata           = artifactMetadata,
                    Config             = config
                };
                projectModels.Add(projectModel);


                var artifactDir        = Path.Combine(config.BasePath, config.ExternalsDir, mavenArtifact.GroupId);
                var artifactFile       = Path.Combine(artifactDir, $"{mavenArtifact.ArtifactId}.{mavenProject.Packaging}");
                var md5File            = artifactFile + ".md5";
                var sha256File         = artifactFile + ".sha256";
                var md5                = File.Exists(md5File) ? File.ReadAllText(md5File) : string.Empty;
                var sha256             = File.Exists(sha256File) ? File.ReadAllText(sha256File) : string.Empty;
                var artifactExtractDir = Path.Combine(artifactDir, mavenArtifact.ArtifactId);

                var proguardFile = Path.Combine(artifactExtractDir, "proguard.txt");

                projectModel.MavenArtifacts.Add(new MavenArtifactModel
                {
                    MavenGroupId           = mavenArtifact.GroupId,
                    MavenArtifactId        = mavenArtifact.ArtifactId,
                    MavenArtifactPackaging = mavenProject.Packaging,
                    MavenArtifactVersion   = mavenArtifact.Version,
                    MavenArtifactMd5       = md5,
                    MavenArtifactSha256    = sha256,
                    ProguardFile           = File.Exists(proguardFile) ? GetRelativePath(proguardFile, config.BasePath).Replace("/", "\\") : null,
                    Metadata = artifactMetadata,
                });


                // Gather maven dependencies to try and map out nuget dependencies
                foreach (var mavenDep in mavenProject.Dependencies)
                {
                    if (!ShouldIncludeDependency(config, mavenArtifact, mavenDep, exceptions))
                    {
                        continue;
                    }

                    mavenDep.Version = FixVersion(mavenDep.Version);

                    var depMapping = config.MavenArtifacts.FirstOrDefault(
                        ma => !string.IsNullOrEmpty(ma.Version) &&
                        ma.GroupId == mavenDep.GroupId &&
                        ma.ArtifactId == mavenDep.ArtifactId &&
                        mavenDep.Satisfies(ma.Version));

                    if (depMapping is null && mavenDep.IsRuntimeDependency())
                    {
                        exceptions.Add(new Exception($"Artifact '{mavenArtifact.GroupAndArtifactId}' has unknown 'Runtime' dependency '{mavenDep.GroupAndArtifactId()}'. Either fulfill or exclude this dependency."));
                        continue;
                    }

                    if (depMapping == null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine($"");
                        sb.AppendLine($"No matching artifact config found for: ");
                        sb.AppendLine($"			{mavenDep.GroupId}.{mavenDep.ArtifactId}:{mavenDep.Version}");
                        sb.AppendLine($"to satisfy dependency of: ");
                        sb.AppendLine($"			{mavenArtifact.GroupId}.{mavenArtifact.ArtifactId}:{mavenArtifact.Version}");
                        sb.AppendLine($"");
                        sb.AppendLine($"	Please add following json snippet to config.json:");
                        sb.AppendLine($"");
                        sb.AppendLine
                            ($@"
      {{
        ""groupId"": ""{mavenDep.GroupId}"",
        ""artifactId"": ""{mavenDep.ArtifactId}"",
        ""version"": ""{mavenDep.Version}"",
        ""nugetVersion"": ""CHECK NUGET ID"",
        ""nugetId"": ""CHECK PREFIX {mavenDep.Version}"",
        ""dependencyOnly"": true/false
      }}
						"                        );
                        sb.AppendLine($"");
                        exceptions.Add(new Exception(sb.ToString()));
                        continue;
                    }

                    var dependencyMetadata = new Dictionary <string, string>();
                    MergeValues(dependencyMetadata, baseMetadata);
                    MergeValues(dependencyMetadata, depMapping.Metadata);

                    projectModel.NuGetDependencies.Add(new NuGetDependencyModel
                    {
                        IsProjectReference = !depMapping.DependencyOnly,
                        NuGetPackageId     = depMapping.NugetPackageId,
                        NuGetVersionBase   = depMapping.NugetVersion,
                        NuGetVersionSuffix = config.NugetVersionSuffix,
                        Metadata           = dependencyMetadata,

                        MavenArtifact = new MavenArtifactModel
                        {
                            MavenGroupId         = mavenDep.GroupId,
                            MavenArtifactId      = mavenDep.ArtifactId,
                            MavenArtifactVersion = mavenDep.Version,
                            MavenArtifactMd5     = md5,
                            MavenArtifactSha256  = sha256,
                            DownloadedArtifact   = artifactFile,
                            Metadata             = dependencyMetadata,
                        }
                    });
                }
            }

            if (exceptions.Any())
            {
                throw new AggregateException(exceptions.ToArray());
            }


            return(projectModels);
        }