From ee175e2e2d7f948830cbe842b40150ee5877cce8 Mon Sep 17 00:00:00 2001 From: jschwarz Date: Fri, 10 May 2024 18:31:17 +0200 Subject: [PATCH] add code from closed source repository --- README.md | 5 +- pom.xml | 67 +++++++-- src/it/modules/first/first/pom.xml | 15 ++ src/it/modules/first/pom.xml | 19 +++ src/it/modules/pom.xml | 114 +++++++++++++++ src/it/modules/second/pom.xml | 14 ++ src/it/modules/third/pom.xml | 16 +++ src/it/modules/verify.groovy | 15 ++ src/it/settings.xml | 39 +++++ .../cicd/bom/AbstractBillOfMaterialsMojo.java | 62 ++++++++ .../cicd/bom/CreateBillOfMaterialsMojo.java | 132 +++++++++++++++++ .../cicd/bom/DeployBillOfMaterialsMojo.java | 122 ++++++++++++++++ .../cicd/bom/InstallBillOfMaterialsMojo.java | 72 ++++++++++ .../eitco/cicd/bom/xml/BillOfMaterials.java | 115 +++++++++++++++ .../de/eitco/cicd/bom/xml/Dependency.java | 135 ++++++++++++++++++ .../cicd/bom/xml/DependencyManagement.java | 33 +++++ .../java/de/eitco/cicd/bom/xml/Exclusion.java | 36 +++++ 17 files changed, 1000 insertions(+), 11 deletions(-) create mode 100644 src/it/modules/first/first/pom.xml create mode 100644 src/it/modules/first/pom.xml create mode 100644 src/it/modules/pom.xml create mode 100644 src/it/modules/second/pom.xml create mode 100644 src/it/modules/third/pom.xml create mode 100644 src/it/modules/verify.groovy create mode 100644 src/it/settings.xml create mode 100644 src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java create mode 100644 src/main/java/de/eitco/cicd/bom/CreateBillOfMaterialsMojo.java create mode 100644 src/main/java/de/eitco/cicd/bom/DeployBillOfMaterialsMojo.java create mode 100644 src/main/java/de/eitco/cicd/bom/InstallBillOfMaterialsMojo.java create mode 100644 src/main/java/de/eitco/cicd/bom/xml/BillOfMaterials.java create mode 100644 src/main/java/de/eitco/cicd/bom/xml/Dependency.java create mode 100644 src/main/java/de/eitco/cicd/bom/xml/DependencyManagement.java create mode 100644 src/main/java/de/eitco/cicd/bom/xml/Exclusion.java diff --git a/README.md b/README.md index ca92670..6f5d0b9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# maven-template -a template repository containing a minimal maven build and the eitco default maven github actions +# Bill of Materials Maven Plugin + +This maven plugin supports creating bill of materials (bom) of given maven projects. diff --git a/pom.xml b/pom.xml index 805e099..4e22682 100644 --- a/pom.xml +++ b/pom.xml @@ -10,22 +10,71 @@ - - de.eitco - eitco-maven-template - 0.0.1-SNAPSHOT + bom-maven-plugin + maven-plugin - + + Jan Schwarz + jschwarz@eitco.de + - - https://github.com/eitco/maven-template.git - scm:git:https://github.com/eitco/maven-template.git - scm:git:https://github.com/eitco/maven-template.git + https://github.com/eitco/bom-maven-plugin.git + scm:git:https://github.com/eitco/bom-maven-plugin.git + scm:git:https://github.com/eitco/bom-maven-plugin.git + + + org.springframework.boot + spring-boot-dependencies + 2.7.5 + pom + + + org.apache.maven + maven-plugin-api + + + org.apache.maven.plugin-tools + maven-plugin-annotations + + + org.codehaus.plexus + plexus-utils + + + org.apache.maven + maven-core + + + org.apache.maven + maven-compat + 3.2.5 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.codehaus.mojo + flatten-maven-plugin + 1.5.0 + + + org.jetbrains + annotations + + + + diff --git a/src/it/modules/first/first/pom.xml b/src/it/modules/first/first/pom.xml new file mode 100644 index 0000000..002b036 --- /dev/null +++ b/src/it/modules/first/first/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + + de.eitco.bom.test + cicd-bom-test-first + @project.version@ + + + cicd-bom-test-first-first + pom + + \ No newline at end of file diff --git a/src/it/modules/first/pom.xml b/src/it/modules/first/pom.xml new file mode 100644 index 0000000..eae5050 --- /dev/null +++ b/src/it/modules/first/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + + de.eitco.bom.test + cicd-bom-test + @project.version@ + + + cicd-bom-test-first + pom + + + first + + + \ No newline at end of file diff --git a/src/it/modules/pom.xml b/src/it/modules/pom.xml new file mode 100644 index 0000000..4fe18ef --- /dev/null +++ b/src/it/modules/pom.xml @@ -0,0 +1,114 @@ + + + 4.0.0 + + de.eitco.bom.test + cicd-bom-test + @project.version@ + pom + + + first + second + third + + + + + + org.springframework.boot + spring-boot-dependencies + 2.7.5 + pom + import + + + org.jooq + jooq + + + + + commons-io + commons-io + 2.6 + + + org.apache.commons + commons-compress + 1.5 + + + org.codehaus.mojo + wagon-maven-plugin + 2.0.2 + + + + + + + + org.codehaus.mojo + flatten-maven-plugin + 1.3.0 + false + + + generate-bom + + flatten + + generate-sources + + defaults + false + ${project.build.directory} + dependency-management.xml + + flatten + resolve + + + + + + + @project.groupId@ + bom-maven-plugin + @project.version@ + false + + + ${project.build.directory}/dependency-management.xml + + + + + + create + install + + + + deploy + + deploy + + install + + + + + + + + + + local-deploy + file://${project.build.directory}/repository + + + + diff --git a/src/it/modules/second/pom.xml b/src/it/modules/second/pom.xml new file mode 100644 index 0000000..39e5d16 --- /dev/null +++ b/src/it/modules/second/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + + de.eitco.bom.test + cicd-bom-test + @project.version@ + + + cicd-bom-test-second + + \ No newline at end of file diff --git a/src/it/modules/third/pom.xml b/src/it/modules/third/pom.xml new file mode 100644 index 0000000..6b25357 --- /dev/null +++ b/src/it/modules/third/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + + de.eitco.bom.test + cicd-bom-test + @project.version@ + + + + cicd-bom-test-third + jar + + \ No newline at end of file diff --git a/src/it/modules/verify.groovy b/src/it/modules/verify.groovy new file mode 100644 index 0000000..3912ec7 --- /dev/null +++ b/src/it/modules/verify.groovy @@ -0,0 +1,15 @@ + +File deployDirectory = new File(basedir, "target/repository/de/eitco/bom/test/cicd-bom-test-bom") + +assert deployDirectory.isDirectory() + +File createdFile = new File(basedir, "target/bom.xml"); + +def project = new XmlSlurper().parse(createdFile) + +assert project.groupId.text() == 'de.eitco.bom.test' +assert project.dependencyManagement != null +assert project.dependencyManagement.dependencies != null +assert project.dependencyManagement.dependencies.dependency[0].artifactId.text() == 'cicd-bom-test' +assert project.dependencyManagement.dependencies.dependency[1].artifactId.text() == 'cicd-bom-test-first-first' +assert project.dependencyManagement.dependencies.dependency[7].artifactId.text() == 'wagon-maven-plugin' diff --git a/src/it/settings.xml b/src/it/settings.xml new file mode 100644 index 0000000..30e2a98 --- /dev/null +++ b/src/it/settings.xml @@ -0,0 +1,39 @@ + + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + never + + + true + never + + + + + + local.central + @localRepositoryUrl@ + + true + never + + + true + never + + + + + + \ No newline at end of file diff --git a/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java b/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java new file mode 100644 index 0000000..82c50a0 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public abstract class AbstractBillOfMaterialsMojo extends AbstractMojo { + @Parameter(defaultValue = "${project.build.directory}/bom.xml") + protected File targetFile; + + @Parameter(defaultValue = "${project.groupId}") + protected String groupId; + + @Parameter(defaultValue = "${project.artifactId}-bom") + protected String artifactId; + + @Parameter(defaultValue = "${project.version}") + protected String version; + @Component + protected ArtifactFactory artifactFactory; + @Parameter(property = "localRepository", required = true, readonly = true) + protected ArtifactRepository localRepository; + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) + private RepositorySystemSession repoSession; + + + @NotNull + protected File getLocalRepositoryFile(Artifact billOfMaterials) { + + String pathForLocalArtifact = repoSession.getLocalRepositoryManager().getPathForLocalArtifact( + new DefaultArtifact( + billOfMaterials.getGroupId(), + billOfMaterials.getArtifactId(), + billOfMaterials.getClassifier(), + billOfMaterials.getType(), + billOfMaterials.getVersion() + )); + + getLog().info("path of repo for artifact " + billOfMaterials + " is " + pathForLocalArtifact); + + return new File(localRepository.getBasedir(), pathForLocalArtifact); + } +} diff --git a/src/main/java/de/eitco/cicd/bom/CreateBillOfMaterialsMojo.java b/src/main/java/de/eitco/cicd/bom/CreateBillOfMaterialsMojo.java new file mode 100644 index 0000000..d8da36b --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/CreateBillOfMaterialsMojo.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import de.eitco.cicd.bom.xml.BillOfMaterials; +import de.eitco.cicd.bom.xml.Dependency; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Mojo(name = "create", defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class CreateBillOfMaterialsMojo extends AbstractBillOfMaterialsMojo { + + public static final Map DEFAULT_TYPES_BY_PACKAGING = new HashMap<>() { + { + put("pom", "pom"); + put("jar", "jar"); + put("war", "war"); + } + }; + + @Parameter + private List additionalBoms = new ArrayList<>(); + + @Parameter + private Map typesByPackaging = new HashMap<>(); + + private Map usedTypesByPackaging; + + public Map getTypesByPackaging() { + + if (usedTypesByPackaging != null) return usedTypesByPackaging; + + usedTypesByPackaging = typesByPackaging; + usedTypesByPackaging.putAll(DEFAULT_TYPES_BY_PACKAGING); + + return usedTypesByPackaging; + } + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + BillOfMaterials billOfMaterials = new BillOfMaterials(); + + billOfMaterials.setGroupId(groupId); + billOfMaterials.setArtifactId(artifactId); + billOfMaterials.setVersion(version); + + addProject(billOfMaterials, project); + + for (MavenProject collectedProject : project.getCollectedProjects()) { + + addProject(billOfMaterials, collectedProject); + } + + XmlMapper mapper = new XmlMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + + Map dependencies = new LinkedHashMap<>(); + + billOfMaterials.getDependencyManagement().getDependencies().forEach(dependency -> { + + dependencies.put(dependency.dependencyKey(), dependency); + }); + + try { + + for (File file : additionalBoms) { + + final BillOfMaterials bom = mapper.readValue(file, BillOfMaterials.class); + + bom.getDependencyManagement().getDependencies().forEach(dependency -> { + + dependencies.put(dependency.dependencyKey(), dependency); + }); + } + + billOfMaterials.getDependencyManagement().setDependencies(new ArrayList<>(dependencies.values())); + + FileUtils.forceMkdir(targetFile.getParentFile()); + + mapper.writeValue(targetFile, billOfMaterials); + + } catch (IOException e) { + + throw new MojoExecutionException(e.getMessage(), e); + } + + } + + private void addProject(BillOfMaterials billOfMaterials, MavenProject collectedProject) { + + String type = getTypesByPackaging().get(collectedProject.getPackaging()); + + if (type == null) { + + return; + } + + if (type.equals("jar")) type = null; + + final Dependency dependency = new Dependency(); + + dependency.setGroupId(collectedProject.getGroupId()); + dependency.setArtifactId(collectedProject.getArtifactId()); + dependency.setVersion(collectedProject.getVersion()); + dependency.setType(type); + + billOfMaterials.getDependencyManagement().getDependencies().add(dependency); + } +} diff --git a/src/main/java/de/eitco/cicd/bom/DeployBillOfMaterialsMojo.java b/src/main/java/de/eitco/cicd/bom/DeployBillOfMaterialsMojo.java new file mode 100644 index 0000000..37ac890 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/DeployBillOfMaterialsMojo.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.deployer.ArtifactDeployer; +import org.apache.maven.artifact.deployer.ArtifactDeploymentException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; + +@Mojo(name = "deploy", defaultPhase = LifecyclePhase.DEPLOY) +public class DeployBillOfMaterialsMojo extends AbstractBillOfMaterialsMojo { + + @Component + private ArtifactDeployer deployer; + + @Parameter(defaultValue = "${settings.offline}", readonly = true) + private boolean offline; + + @Parameter(property = "retryFailedDeploymentCount", defaultValue = "1") + private int retryFailedDeploymentCount; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + failIfOffline(); + + if (!targetFile.exists()) { + + throw new MojoExecutionException(targetFile.getPath() + " not found."); + } + + ArtifactRepository deploymentRepository = + project.getDistributionManagementArtifactRepository(); + + String protocol = deploymentRepository.getProtocol(); + + if (StringUtils.isEmpty(protocol)) { + throw new MojoExecutionException("No transfer protocol found."); + } + + // Create the artifact + Artifact artifact = + artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "pom", null); + + if (targetFile.equals(getLocalRepositoryFile(artifact))) { + + throw new MojoFailureException("Cannot deploy artifact from the local repository: " + targetFile); + } + + // Upload the POM if requested, generating one if need be + try { + + deploy(targetFile, artifact, deploymentRepository, localRepository, retryFailedDeploymentCount); + + } catch (ArtifactDeploymentException e) { + + throw new MojoExecutionException(e.getMessage(), e); + } + } + + private void failIfOffline() throws MojoFailureException { + + if (offline) { + + throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode"); + } + } + + + private void deploy( + File source, Artifact artifact, ArtifactRepository deploymentRepository, + ArtifactRepository localRepository, int retryFailedDeploymentCount + ) + throws ArtifactDeploymentException { + int retryFailedDeploymentCounter = Math.max(1, Math.min(10, retryFailedDeploymentCount)); + ArtifactDeploymentException exception = null; + + for (int count = 0; count < retryFailedDeploymentCounter; count++) { + + try { + + if (count > 0) { + getLog().info("Retrying deployment attempt " + (count + 1) + " of " + retryFailedDeploymentCounter); + } + + deployer.deploy(source, artifact, deploymentRepository, localRepository); + exception = null; + break; + + } catch (ArtifactDeploymentException e) { + + if (count + 1 < retryFailedDeploymentCounter) { + getLog().warn("Encountered issue during deployment: " + e.getLocalizedMessage()); + getLog().debug(e); + } + + if (exception == null) { + exception = e; + } + } + } + + if (exception != null) { + throw exception; + } + } + +} diff --git a/src/main/java/de/eitco/cicd/bom/InstallBillOfMaterialsMojo.java b/src/main/java/de/eitco/cicd/bom/InstallBillOfMaterialsMojo.java new file mode 100644 index 0000000..aa46417 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/InstallBillOfMaterialsMojo.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.install.DualDigester; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.shared.utils.io.FileUtils; + +import java.io.File; +import java.io.IOException; + +@Mojo(name = "install", defaultPhase = LifecyclePhase.INSTALL) +public class InstallBillOfMaterialsMojo extends AbstractBillOfMaterialsMojo { + + @Component + protected ArtifactInstaller installer; + + protected final DualDigester digester = new DualDigester(); + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + try { + + final Artifact billOfMaterials = artifactFactory.createArtifact(groupId, artifactId, version, null, "pom"); + + installer.install(targetFile, billOfMaterials, localRepository); + + File installedFile = getLocalRepositoryFile(billOfMaterials); + + getLog().debug("Calculating checksums for " + installedFile); + digester.calculate(installedFile); + installChecksum(installedFile, ".md5", digester.getMd5()); + installChecksum(installedFile, ".sha1", digester.getSha1()); + + } catch (ArtifactInstallationException e) { + + throw new MojoExecutionException(e.getMessage(), e); + } + + } + + private void installChecksum(File installedFile, String ext, String checksum) throws MojoExecutionException { + + File checksumFile = new File(installedFile.getAbsolutePath() + ext); + getLog().debug("Installing checksum to " + checksumFile); + + try { + //noinspection ResultOfMethodCallIgnored + checksumFile.getParentFile().mkdirs(); + + FileUtils.fileWrite(checksumFile.getAbsolutePath(), "UTF-8", checksum); + + } catch (IOException e) { + + throw new MojoExecutionException("Failed to install checksum to " + checksumFile, e); + } + } + +} diff --git a/src/main/java/de/eitco/cicd/bom/xml/BillOfMaterials.java b/src/main/java/de/eitco/cicd/bom/xml/BillOfMaterials.java new file mode 100644 index 0000000..9279869 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/xml/BillOfMaterials.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom.xml; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +@JsonRootName(value = "project", namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) +@JsonIgnoreProperties(ignoreUnknown = true) +public class BillOfMaterials { + + public static final String MAVEN_XML_NAMESPACE = "http://maven.apache.org/POM/4.0.0"; + + @JacksonXmlProperty(isAttribute = true, localName = "xsi:schemaLocation") + private String schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"; + + @JacksonXmlProperty(isAttribute = true, localName = "xmlns:xsi") + private String xsi = "http://www.w3.org/2001/XMLSchema-instance"; + + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private String modelVersion = "4.0.0"; + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private String groupId; + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private String artifactId; + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private String version; + + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private String packaging = "pom"; + + @JacksonXmlProperty(namespace = MAVEN_XML_NAMESPACE) + private DependencyManagement dependencyManagement = new DependencyManagement(); + + public String getModelVersion() { + return modelVersion; + } + + public BillOfMaterials setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + return this; + } + + public String getGroupId() { + return groupId; + } + + public BillOfMaterials setGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + public String getArtifactId() { + return artifactId; + } + + public BillOfMaterials setArtifactId(String artifactId) { + this.artifactId = artifactId; + return this; + } + + public String getVersion() { + return version; + } + + public BillOfMaterials setVersion(String version) { + this.version = version; + return this; + } + + public DependencyManagement getDependencyManagement() { + return dependencyManagement; + } + + public BillOfMaterials setDependencyManagement(DependencyManagement dependencyManagement) { + + if (dependencyManagement == null) dependencyManagement = new DependencyManagement(); + + this.dependencyManagement = dependencyManagement; + return this; + } + + public String getPackaging() { + return packaging; + } + + public String getSchemaLocation() { + return schemaLocation; + } + + public BillOfMaterials setSchemaLocation(String schemaLocation) { + this.schemaLocation = schemaLocation; + return this; + } + + public String getXsi() { + return xsi; + } + + public BillOfMaterials setXsi(String xsi) { + this.xsi = xsi; + return this; + } + + public BillOfMaterials setPackaging(String packaging) { + this.packaging = packaging; + return this; + } +} diff --git a/src/main/java/de/eitco/cicd/bom/xml/Dependency.java b/src/main/java/de/eitco/cicd/bom/xml/Dependency.java new file mode 100644 index 0000000..8c4e2d1 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/xml/Dependency.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom.xml; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class Dependency { + + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private String groupId; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private String artifactId; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private String version; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_NULL) + private String type; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_NULL) + private String classifier; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_NULL) + private String scope; + + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_NULL) + private String optional; + + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_NULL) + private String systemPath; + + @JacksonXmlElementWrapper(localName = "exclusions", namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JacksonXmlProperty(localName = "exclusion", namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JsonInclude(value = JsonInclude.Include.NON_EMPTY) + private List exclusions = new ArrayList<>(); + + @NotNull + public String dependencyKey() { + + return groupId + ":" + artifactId + ":" + (type != null ? (type) : "") + ":" + (classifier != null ? (classifier) : ""); + } + + public String getGroupId() { + return groupId; + } + + public Dependency setGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + public String getArtifactId() { + return artifactId; + } + + public Dependency setArtifactId(String artifactId) { + this.artifactId = artifactId; + return this; + } + + public String getVersion() { + return version; + } + + public Dependency setVersion(String version) { + this.version = version; + return this; + } + + public String getType() { + return type; + } + + public Dependency setType(String type) { + this.type = type; + return this; + } + + public String getScope() { + return scope; + } + + public Dependency setScope(String scope) { + this.scope = scope; + return this; + } + + public List getExclusions() { + return exclusions; + } + + public Dependency setExclusions(List exclusions) { + this.exclusions = exclusions; + return this; + } + + public String getClassifier() { + return classifier; + } + + public Dependency setClassifier(String classifier) { + this.classifier = classifier; + return this; + } + + public String getOptional() { + return optional; + } + + public Dependency setOptional(String optional) { + this.optional = optional; + return this; + } + + public String getSystemPath() { + return systemPath; + } + + public Dependency setSystemPath(String systemPath) { + this.systemPath = systemPath; + return this; + } +} diff --git a/src/main/java/de/eitco/cicd/bom/xml/DependencyManagement.java b/src/main/java/de/eitco/cicd/bom/xml/DependencyManagement.java new file mode 100644 index 0000000..b6ad2d9 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/xml/DependencyManagement.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom.xml; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +import java.util.ArrayList; +import java.util.List; + +public class DependencyManagement { + + @JacksonXmlElementWrapper(localName = "dependencies", namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + @JacksonXmlProperty(localName = "dependency", namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private List dependencies = new ArrayList<>(); + + public List getDependencies() { + return dependencies; + } + + public DependencyManagement setDependencies(List dependencies) { + + if (dependencies == null) dependencies = new ArrayList<>(); + + this.dependencies = dependencies; + return this; + } +} diff --git a/src/main/java/de/eitco/cicd/bom/xml/Exclusion.java b/src/main/java/de/eitco/cicd/bom/xml/Exclusion.java new file mode 100644 index 0000000..abda272 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/xml/Exclusion.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 EITCO GmbH + * All rights reserved. + * + * Created on 12.01.2023 + * + */ +package de.eitco.cicd.bom.xml; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +public class Exclusion { + + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private String groupId; + @JacksonXmlProperty(namespace = BillOfMaterials.MAVEN_XML_NAMESPACE) + private String artifactId; + + public String getGroupId() { + return groupId; + } + + public Exclusion setGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + public String getArtifactId() { + return artifactId; + } + + public Exclusion setArtifactId(String artifactId) { + this.artifactId = artifactId; + return this; + } +}