generated from eitco/maven-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add code from closed source repository
- Loading branch information
1 parent
40d334d
commit ee175e2
Showing
17 changed files
with
1,000 additions
and
11 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
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. |
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
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> |
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,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> |
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,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> |
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,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> |
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,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> |
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,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' |
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,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
62
src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.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,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); | ||
} | ||
} |
Oops, something went wrong.