Skip to content

Commit

Permalink
add code from closed source repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarz-eitco-de committed May 10, 2024
1 parent 40d334d commit ee175e2
Show file tree
Hide file tree
Showing 17 changed files with 1,000 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
67 changes: 58 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,71 @@
</parent>


<!-- TODO: replace with your coordinates -->
<groupId>de.eitco</groupId>
<artifactId>eitco-maven-template</artifactId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>bom-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>

<developers>
<!-- TODO: add developers concerned -->
<developer>
<name>Jan Schwarz</name>
<email>jschwarz@eitco.de</email>
</developer>
</developers>

<scm>
<!-- TODO: replace with your repository url -->
<url>https://github.com/eitco/maven-template.git</url>
<connection>scm:git:https://github.com/eitco/maven-template.git</connection>
<developerConnection>scm:git:https://github.com/eitco/maven-template.git</developerConnection>
<url>https://github.com/eitco/bom-maven-plugin.git</url>
<connection>scm:git:https://github.com/eitco/bom-maven-plugin.git</connection>
<developerConnection>scm:git:https://github.com/eitco/bom-maven-plugin.git</developerConnection>
</scm>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
15 changes: 15 additions & 0 deletions src/it/modules/first/first/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.eitco.bom.test</groupId>
<artifactId>cicd-bom-test-first</artifactId>
<version>@project.version@</version>
</parent>

<artifactId>cicd-bom-test-first-first</artifactId>
<packaging>pom</packaging>

</project>
19 changes: 19 additions & 0 deletions src/it/modules/first/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.eitco.bom.test</groupId>
<artifactId>cicd-bom-test</artifactId>
<version>@project.version@</version>
</parent>

<artifactId>cicd-bom-test-first</artifactId>
<packaging>pom</packaging>

<modules>
<module>first</module>
</modules>

</project>
114 changes: 114 additions & 0 deletions src/it/modules/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.eitco.bom.test</groupId>
<artifactId>cicd-bom-test</artifactId>
<version>@project.version@</version>
<packaging>pom</packaging>

<modules>
<module>first</module>
<module>second</module>
<module>third</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.5</version>
<type>pom</type>
<scope>import</scope>
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.3.0</version>
<inherited>false</inherited>
<executions>
<execution>
<id>generate-bom</id>
<goals>
<goal>flatten</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<flattenMode>defaults</flattenMode>
<updatePomFile>false</updatePomFile>
<outputDirectory>${project.build.directory}</outputDirectory>
<flattenedPomFilename>dependency-management.xml</flattenedPomFilename>
<pomElements>
<repositories>flatten</repositories>
<dependencyManagement>resolve</dependencyManagement>
</pomElements>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>bom-maven-plugin</artifactId>
<version>@project.version@</version>
<inherited>false</inherited>
<configuration>
<additionalBoms>
<additionalBom>${project.build.directory}/dependency-management.xml</additionalBom>
</additionalBoms>
</configuration>
<executions>
<execution>
<goals>
<goal>create</goal>
<goal>install</goal>
</goals>
</execution>
<execution>
<id>deploy</id>
<goals>
<goal>deploy</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>


<distributionManagement>
<repository>
<id>local-deploy</id>
<url>file://${project.build.directory}/repository</url>
</repository>
</distributionManagement>

</project>
14 changes: 14 additions & 0 deletions src/it/modules/second/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.eitco.bom.test</groupId>
<artifactId>cicd-bom-test</artifactId>
<version>@project.version@</version>
</parent>

<artifactId>cicd-bom-test-second</artifactId>

</project>
16 changes: 16 additions & 0 deletions src/it/modules/third/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.eitco.bom.test</groupId>
<artifactId>cicd-bom-test</artifactId>
<version>@project.version@</version>
</parent>


<artifactId>cicd-bom-test-third</artifactId>
<packaging>jar</packaging>

</project>
15 changes: 15 additions & 0 deletions src/it/modules/verify.groovy
Original file line number Diff line number Diff line change
@@ -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'
39 changes: 39 additions & 0 deletions src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
62 changes: 62 additions & 0 deletions src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit ee175e2

Please sign in to comment.