private List <BdioNode> GetBdioNodes() { BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper(); BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper); string projectGroup = "com.blackducksoftware.gradle.test"; string projectName = "gradleTestProject"; string projectVersion = "99.5-SNAPSHOT"; string projectExternalId = bdioPropertyHelper.CreateMavenExternalId(projectGroup, projectName, projectVersion); string projectBdioId = bdioPropertyHelper.CreateBdioId(projectGroup, projectName, projectVersion); BdioBillOfMaterials bdioBillOfMaterials = bdioNodeFactory.CreateBillOfMaterials("", projectName, projectVersion); // we are overriding the default value of a new uuid just to pass the json comparison bdioBillOfMaterials.Id = "uuid:45772d33-5353-44f1-8681-3d8a15540646"; BdioProject bdioProject = bdioNodeFactory.CreateProject(projectName, projectVersion, projectBdioId, "maven", projectExternalId); BdioComponent cxfBundle = bdioNodeFactory.CreateComponent("cxf-bundle", "2.7.7", bdioPropertyHelper.CreateBdioId("org.apache.cxf", "cxf-bundle", "2.7.7"), "maven", bdioPropertyHelper.CreateMavenExternalId("org.apache.cxf", "cxf-bundle", "2.7.7")); BdioComponent velocity = bdioNodeFactory.CreateComponent("velocity", "1.7", bdioPropertyHelper.CreateBdioId("org.apache.velocity", "velocity", "1.7"), "maven", bdioPropertyHelper.CreateMavenExternalId("org.apache.velocity", "velocity", "1.7")); BdioComponent commonsCollections = bdioNodeFactory.CreateComponent("commons-collections", "3.2.1", bdioPropertyHelper.CreateBdioId("commons-collections", "commons-collections", "3.2.1"), "maven", bdioPropertyHelper.CreateMavenExternalId("commons-collections", "commons-collections", "3.2.1")); BdioComponent commonsLang = bdioNodeFactory.CreateComponent("commons-lang", "2.6", bdioPropertyHelper.CreateBdioId("commons-lang", "commons-lang", "2.6"), "maven", bdioPropertyHelper.CreateMavenExternalId("commons-lang", "commons-lang", "2.6")); // we will now relate the constructed bdio nodes // first, add the cxfBundle component as a child of the project - this project has a single direct dependency bdioPropertyHelper.AddRelationship(bdioProject, cxfBundle); // now, the cxfBundle component itself has two dependencies, which will appear in the final BOM as they are // transitive dependencies of the project bdioPropertyHelper.AddRelationships(cxfBundle, new List <BdioNode> { velocity, commonsLang }); // and the velocity component also has two dependencies - it will only add one additional entry to our final BOM // as the commonsLang component was already included from the cxfBundle component above bdioPropertyHelper.AddRelationships(velocity, new List <BdioNode> { commonsCollections, commonsLang }); List <BdioNode> bdioNodes = new List <BdioNode> { bdioBillOfMaterials, bdioProject, cxfBundle, velocity, commonsCollections, commonsLang }; return(bdioNodes); }
public void BdioContentTest() { string sampleBdio = Resources.sample; BdioContent content = BdioContent.Parse(sampleBdio); BdioContent content2 = BdioContent.Parse(sampleBdio); Assert.AreEqual(6, content.Count); Assert.IsNotNull(content.ToString()); Assert.IsTrue(content.Equals(content2)); Assert.IsFalse(content.Equals(null)); Assert.AreNotEqual(0, content.GetHashCode()); foreach (BdioNode node in content2.Components) { if (node.Relationships != null && node.Relationships.Count > 0) { node.Relationships[0].RelationshipType = "Not a type"; break; } } Assert.IsFalse(content.Equals(content2)); BdioComponent component = new BdioComponent(); component.Id = "Another component"; content2.Components.Add(component); Assert.IsFalse(content.Equals(content2)); }
public BdioComponent CreateComponent(string componentName, string componentVersion, string bdioId, BdioExternalIdentifier externalIdentifier) { BdioComponent component = new BdioComponent(); component.Id = bdioId; component.Name = componentName; component.Version = componentVersion; component.BdioExternalIdentifier = externalIdentifier; return(component); }
public BdioContent BuildBOMFromMetadata(List <NuGet.PackageReference> packages, PackageMetadataResource metadataResource) { BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper(); BdioNodeFactory bdioNodeFactory = new BdioNodeFactory(bdioPropertyHelper); BdioContent bdio = new BdioContent(); // Create bdio bill of materials node BdioBillOfMaterials bdioBillOfMaterials = bdioNodeFactory.CreateBillOfMaterials(HubCodeLocationName, HubProjectName, HubVersionName); // Create bdio project node string projectBdioId = bdioPropertyHelper.CreateBdioId(HubProjectName, HubVersionName); BdioExternalIdentifier projectExternalIdentifier = bdioPropertyHelper.CreateNugetExternalIdentifier(HubProjectName, HubVersionName); // Note: Could be different. Look at config file BdioProject bdioProject = bdioNodeFactory.CreateProject(HubProjectName, HubVersionName, projectBdioId, projectExternalIdentifier); // Create relationships for every bdio node List <BdioNode> bdioComponents = new List <BdioNode>(); foreach (NuGet.PackageReference packageRef in packages) { // Create component node string componentName = packageRef.Id; string componentVersion = packageRef.Version.ToString(); string componentBdioId = bdioPropertyHelper.CreateBdioId(componentName, componentVersion); BdioExternalIdentifier componentExternalIdentifier = bdioPropertyHelper.CreateNugetExternalIdentifier(componentName, componentVersion); BdioComponent component = bdioNodeFactory.CreateComponent(componentName, componentVersion, componentBdioId, componentExternalIdentifier); // Add references List <PackageDependency> packageDependencies = GetPackageDependencies(packageRef, metadataResource); foreach (PackageDependency packageDependency in packageDependencies) { // Create node from dependency info string dependencyName = packageDependency.Id; string dependencyVersion = GetDependencyVersion(packageDependency, packages); string dependencyBdioId = bdioPropertyHelper.CreateBdioId(dependencyName, dependencyVersion); BdioExternalIdentifier dependencyExternalIdentifier = bdioPropertyHelper.CreateNugetExternalIdentifier(dependencyName, dependencyVersion); BdioComponent dependency = bdioNodeFactory.CreateComponent(dependencyName, dependencyVersion, dependencyBdioId, dependencyExternalIdentifier); // Add relationship bdioPropertyHelper.AddRelationship(component, dependency); } bdioComponents.Add(component); } bdio.BillOfMaterials = bdioBillOfMaterials; bdio.Project = bdioProject; bdio.Components = bdioComponents; return(bdio); }