-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate the licenses-generator as a module of Bacon
- Loading branch information
1 parent
dac07ab
commit 64295fc
Showing
65 changed files
with
4,555 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Overview | ||
|
||
This project generates `licenses.xml` and `licenses.html` files based on a `pom.xml`. It loads all transitive dependnencies from `dependencies` section of the project's `pom.xml` and collects all their licenses. Then it aligns the license names and URLs to comply with the approved Red Hat license names and URLs. Finally, when generating `licenses.html`, it also downloads license contents for offline use. | ||
|
||
# Standalone usage | ||
This project can be pakaged as an uber-jar and used standalone. To create an uber-jar run the following command: | ||
``` | ||
mvn clean package | ||
``` | ||
|
||
Then generate `licenses.(xml|html)`: | ||
``` | ||
java -jar target/licenses-generator-shaded.jar -Dpom={path to pom.xml} -Ddestination={destination directory} [-DgeneratorProperties={path to a properties file}] [-DaliasesFile={path to aliases file}] [-DexceptionsFile={path to exceptions file}] | ||
``` | ||
|
||
# Usage in an application | ||
You can add this project as a dependency and generate license files by using its API directly. Add the following dependency to your project's `pom.xml`: | ||
``` | ||
<dependency> | ||
<groupId>me.snowdrop</groupId> | ||
<artifactId>licenses-generator</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
``` | ||
|
||
Create an instance of `LicensesGenerator` and use `generateLicensesForPom` or `generateLicensesForGavs`. The latter method is only exposed to use directly and will not resolve transitive dependencies. | ||
|
||
# Configuration | ||
Project can be configured with a `src/main/resources/generator.properties` file. However, it can be oveerriden when running in standalone mode by providing `-DgeneratorProperties={path to a properties file}` as an application argument. When using generator via API, you can provide `GeneratorProperties` when creating an instance of `LicensesGenerator`. | ||
|
||
These are the available properties (you can also see them in `PropertyKeys`): | ||
|
||
Name|Description|Default value | ||
---|---|--- | ||
repository.names | Comma separated list of repository names. Must be the same length as repository.urls | Maven Central | ||
repository.urls | Comma separated list of repository URLs. Must be the same length as repository.names | http://repo1.maven.org/maven2 | ||
licenseServiceUrl | An optional URL of a license service. <br> If not provided, the license data will be collected from the the rh-license-exceptions.json file or artifacts' pom.xml | *null* | ||
aliasesFile | An absolute path to the license aliases file (can be overwritten by -DaliasesFile) | rh-license-names.json from this project | ||
exceptionsFile | An absolute path to the license exceptions file (can be overwritten by -DexceptionsFile) | rh-license-exceptions.json from this 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,239 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2017 Red Hat, Inc, and individual contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<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>org.jboss.pnc.bacon</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>2.5.6-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>licenses-generator</artifactId> | ||
|
||
<description>Licenses Generator to gather dependency licenses and generate licenses.xml|html files</description> | ||
|
||
<dependencies> | ||
<!-- Qute --> | ||
<dependency> | ||
<groupId>io.quarkus.qute</groupId> | ||
<artifactId>qute-core</artifactId> | ||
</dependency> | ||
|
||
<!-- JSON --> | ||
<dependency> | ||
<groupId>org.glassfish</groupId> | ||
<artifactId>javax.json</artifactId> | ||
</dependency> | ||
|
||
<!-- Maven Embedder --> | ||
<dependency> | ||
<groupId>org.jenkins-ci.lib</groupId> | ||
<artifactId>lib-jenkins-maven-embedder</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-artifact</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-compat</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-core</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker-qual</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-embedder</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<!-- let's prefer the plexus-utils pulled by maven-resolver-provider --> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker-qual</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-connector-basic</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-transport-wagon</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-spi</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-impl</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.resolver</groupId> | ||
<artifactId>maven-resolver-util</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.wagon</groupId> | ||
<artifactId>wagon-file</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.wagon</groupId> | ||
<artifactId>wagon-http</artifactId> | ||
</dependency> | ||
|
||
<!-- JAXB --> | ||
<dependency> | ||
<groupId>org.glassfish.jaxb</groupId> | ||
<artifactId>jaxb-runtime</artifactId> | ||
</dependency> | ||
|
||
<!--JAX-RS--> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jackson2-provider</artifactId> | ||
</dependency> | ||
|
||
<!-- Configuration --> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-configuration2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-beanutils</groupId> | ||
<artifactId>commons-beanutils</artifactId> | ||
</dependency> | ||
|
||
<!-- File management --> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<!-- Test --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-inline</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.undertow</groupId> | ||
<artifactId>undertow-servlet</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jenkins-ci-releases</id> | ||
<url>https://repo.jenkins-ci.org/releases/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>licenses-generator</id> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<phase>package</phase> | ||
<configuration> | ||
<finalName>licenses-generator-shaded</finalName> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.jboss.pnc.bacon.licenses.LicensesGeneratorApplication</mainClass> | ||
</transformer> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" /> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> | ||
<resource>META-INF/sisu/javax.inject.Named</resource> | ||
</transformer> | ||
</transformers> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
licenses-generator/src/main/java/org/jboss/pnc/bacon/licenses/GavFinder.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,33 @@ | ||
package org.jboss.pnc.bacon.licenses; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.project.MavenProject; | ||
import org.jboss.pnc.bacon.licenses.maven.MavenProjectFactory; | ||
import org.jboss.pnc.bacon.licenses.utils.Gav; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class GavFinder { | ||
private final MavenProjectFactory mavenProjectFactory; | ||
|
||
GavFinder(MavenProjectFactory mavenProjectFactory) { | ||
this.mavenProjectFactory = mavenProjectFactory; | ||
} | ||
|
||
public Collection<Gav> inMavenProject(Path pomPath) { | ||
return getArtifactsForMavenProject(pomPath) | ||
.map(a -> new Gav(a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType())) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
Stream<Artifact> getArtifactsForMavenProject(Path pomPath) { | ||
return mavenProjectFactory.getMavenProjects(pomPath.toFile(), true) | ||
.stream() | ||
.map(MavenProject::getArtifacts) | ||
.flatMap(Set::stream); | ||
} | ||
} |
Oops, something went wrong.