-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed setAuthors, moved manufacurer to component section
Signed-off-by: Björn Kornefalk <[email protected]>
- Loading branch information
Showing
5 changed files
with
191 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/org/cyclonedx/maven/DeveloperInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) Giesecke+Devrient Mobile Security GmbH 2018-2024 | ||
*/ | ||
package org.cyclonedx.maven; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.cyclonedx.model.OrganizationalContact; | ||
|
||
/** | ||
* Help class for parse a list of developers | ||
*/ | ||
class DeveloperInformation { | ||
|
||
private final List<OrganizationalContact> contacts = new ArrayList<>(); | ||
private String organization; | ||
private final List<String> urls = new ArrayList<>(); | ||
|
||
/** | ||
* Add contact information | ||
* | ||
* @param contact The contact | ||
*/ | ||
void addOrganizationalContact(OrganizationalContact contact) { | ||
contacts.add(contact); | ||
} | ||
|
||
/** | ||
* If Maven section "<organization>" is missing, see if we can find any organization information from | ||
* a developers section | ||
* @param organization The organization name | ||
*/ | ||
void setOrganization(String organization) { | ||
if (this.organization == null && organization != null) { | ||
this.organization = organization; | ||
} | ||
} | ||
|
||
/** | ||
* Add a defined url | ||
* @param url The url | ||
*/ | ||
void addUrl(String url) { | ||
if (url != null) { | ||
urls.add(url); | ||
} | ||
} | ||
|
||
/** | ||
* @return List of contacts | ||
*/ | ||
public List<OrganizationalContact> getContacts() { | ||
return contacts; | ||
} | ||
|
||
/** | ||
* @return First organization name if found | ||
*/ | ||
public String getOrganization() { | ||
return organization; | ||
} | ||
|
||
/** | ||
* @return List of configured urls | ||
*/ | ||
public List<String> getUrls() { | ||
return urls; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.maven.model.Developer; | ||
import org.apache.maven.model.Organization; | ||
import org.apache.maven.project.MavenProject; | ||
import org.cyclonedx.model.Component; | ||
import org.cyclonedx.model.Dependency; | ||
import org.cyclonedx.model.OrganizationalContact; | ||
|
@@ -30,10 +32,9 @@ protected String extractComponentsAndDependencies(Set<String> topLevelComponents | |
} | ||
|
||
@Test | ||
@DisplayName("") | ||
void createListOfAuthors() { | ||
@DisplayName("Using developers information only") | ||
void setManufacturer1() { | ||
BaseCycloneDxMojoImpl mojo = new BaseCycloneDxMojoImpl(); | ||
OrganizationalEntity manufacturer = new OrganizationalEntity(); | ||
List<Developer> developers = new ArrayList<>(); | ||
Developer developer = new Developer(); | ||
developer.setName("Developer"); | ||
|
@@ -47,21 +48,96 @@ void createListOfAuthors() { | |
developer = new Developer(); | ||
developer.setOrganizationUrl("http://foo.com"); | ||
developers.add(developer); | ||
List<OrganizationalContact> listOfAuthors = mojo.createListOfAuthors(manufacturer, developers); | ||
assertNotNull(listOfAuthors); | ||
assertEquals(4, listOfAuthors.size()); | ||
assertEquals("Developer", listOfAuthors.get(0).getName()); | ||
Component projectBomComponent = new Component(); | ||
MavenProject mavenProject = new MavenProject(); | ||
mavenProject.setDevelopers(developers); | ||
mojo.setManufacturer(mavenProject, projectBomComponent); | ||
OrganizationalEntity manufacturer = projectBomComponent.getManufacturer(); | ||
assertNotNull(manufacturer); | ||
assertEquals(4, manufacturer.getContacts().size()); | ||
assertEquals("Developer", manufacturer.getContacts().get(0).getName()); | ||
assertEquals("My Organization", manufacturer.getName()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify addContacts") | ||
void addContacts() { | ||
@DisplayName("Using developers information with empty organization") | ||
void setManufacturer2() { | ||
BaseCycloneDxMojoImpl mojo = new BaseCycloneDxMojoImpl(); | ||
OrganizationalEntity manufacturer = new OrganizationalEntity(); | ||
List<Developer > developers = new ArrayList<>(); | ||
mojo.addContacts(manufacturer, developers); | ||
assertNotNull(manufacturer.getContacts()); | ||
assertTrue(manufacturer.getContacts().isEmpty()); | ||
List<Developer> developers = new ArrayList<>(); | ||
Developer developer = new Developer(); | ||
developer.setName("Developer"); | ||
developers.add(developer); | ||
developer = new Developer(); | ||
developer.setEmail("[email protected]"); | ||
developers.add(developer); | ||
developer = new Developer(); | ||
developer.setOrganization("My Organization"); | ||
developers.add(developer); | ||
developer = new Developer(); | ||
developer.setOrganizationUrl("http://foo.com"); | ||
developers.add(developer); | ||
Component projectBomComponent = new Component(); | ||
MavenProject mavenProject = new MavenProject(); | ||
mavenProject.setDevelopers(developers); | ||
mavenProject.setOrganization(new Organization()); | ||
mojo.setManufacturer(mavenProject, projectBomComponent); | ||
OrganizationalEntity manufacturer = projectBomComponent.getManufacturer(); | ||
assertNotNull(manufacturer); | ||
assertEquals(4, manufacturer.getContacts().size()); | ||
assertEquals("Developer", manufacturer.getContacts().get(0).getName()); | ||
assertEquals("My Organization", manufacturer.getName()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Using developers and organization information") | ||
void setManufacturer3() { | ||
BaseCycloneDxMojoImpl mojo = new BaseCycloneDxMojoImpl(); | ||
|
||
MavenProject mavenProject = new MavenProject(); | ||
List<Developer> developers = new ArrayList<>(); | ||
Developer developer = new Developer(); | ||
developer.setName("Developer 2"); | ||
developer.setEmail("[email protected]"); | ||
developer.setOrganization("My Organization"); | ||
developer.setOrganizationUrl("http://foo.com"); | ||
developers.add(developer); | ||
mavenProject.setDevelopers(developers); | ||
|
||
Organization organization = new Organization(); | ||
organization.setName("My Company"); | ||
organization.setUrl("http://example.com"); | ||
mavenProject.setOrganization(organization); | ||
|
||
Component projectBomComponent = new Component(); | ||
mojo.setManufacturer(mavenProject, projectBomComponent); | ||
OrganizationalEntity manufacturer = projectBomComponent.getManufacturer(); | ||
assertNotNull(manufacturer); | ||
assertEquals(1, manufacturer.getContacts().size()); | ||
assertEquals("Developer 2", manufacturer.getContacts().get(0).getName()); | ||
assertEquals("My Company", manufacturer.getName()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Using organization information only") | ||
void setManufacturer4() { | ||
BaseCycloneDxMojoImpl mojo = new BaseCycloneDxMojoImpl(); | ||
|
||
MavenProject mavenProject = new MavenProject(); | ||
List<Developer> developers = new ArrayList<>(); | ||
Organization organization = new Organization(); | ||
organization.setName("My Organization"); | ||
organization.setUrl("http://example.org"); | ||
mavenProject.setOrganization(organization); | ||
|
||
mavenProject.setDevelopers(developers); | ||
mavenProject.setOrganization(organization); | ||
|
||
Component projectBomComponent = new Component(); | ||
mojo.setManufacturer(mavenProject, projectBomComponent); | ||
OrganizationalEntity manufacturer = projectBomComponent.getManufacturer(); | ||
assertNotNull(manufacturer); | ||
assertNull(manufacturer.getContacts()); | ||
assertEquals("My Organization", manufacturer.getName()); | ||
} | ||
|
||
@Test | ||
|