Allow providing local license texts from a relative path for aggregate-download-licenses
duracotton opened this issue · 1 comments
The goal download-licenses/aggregate-download-licenses currently does not support using locally provided license text files. We have dependencies which are that old or are proprietary so that there isn't any license file available online.
Actually it does, using the "file://" descriptor in the licensesConfigFile's "URL" element:
https://github.com/mojohaus/license-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/license/download/LicenseDownloader.java#L181
(This is not documented)
But scanning the URL value for a "file://" descriptor does not make it support a relative local URI using the working directory like "./LICENSES/abc.license". Using file://./LICENSE/abc.license" will produce a Java URI exception: Caused by: java.lang.IllegalArgumentException: URI authority component has undefined host
It only supports absolute paths.
Of course, I could also use the "aggregate-add-third-party" goal, but this does not offer as many options as "aggregate-download-licenses" does and I also want to collect all the licenses (whether downloaded from the Web or provided locally) in one folder.
Any suggestions / workarounds how to solve this?
It is now working in combination with the Maven resource plugin.
Back to the problem I had: We want to check-in old licenses not available on the web anymore in our GIT repository of the Maven multi module project. It should reside just there with the source code.
And we wanted to use the goal "aggregate-download-licenses" as it is producing a nice xml for all used licenses.
Problem: not documented file:// descriptor for element inside is working but allows only absolute paths. Problem: We don't want to check-in absolute paths into our GIT repository as this changes dependend where the user clones out the repo on his machine.
So....
My file structure in the git repository now:
Root dir of maven multi module project: has subfolder /LICENSES/configuration/offline_available_licenses which contains all license texts which are not available on the Internet
Root dir of maven multi module project: has subfolder /LICENSES/configuration/template which contains the previously on the first mvn clean package execution) generated (now renamed to licenses-missing-configuration.xml). It will be the base for the (see documentation, by populating it manually with all missing licenses and paths to the license texts. In this file we can also use Maven properties to make it now support relative paths to the license texts.
E.g.:
<dependency>
<groupId>\Qcom.ibm\E</groupId>
<artifactId>\QJLog\E</artifactId>
<version>\Q2.1.2\E</version>
<matchLicenses>
<!-- Match dependency with no licenses -->
</matchLicenses>
<licenses>
<!-- Manually add license elements here: -->
<license>
<name>IBM (IBM developerWorks International License Agreement for Non-Warrented Programs)</name>
<url>file:///${maven.multiModuleProjectDirectory}/LICENSES/configuration/offline_available_licenses/com.ibm.jlog-v2.1.2-LICENSE.txt</url>
</license>
</licenses>
<downloaderMessages>
<downloaderMessage>No license information available for: com.ibm:JLog:2.1.2</downloaderMessage>
</downloaderMessages>
</dependency>
This file is then copied by the Maven resource plugin in an earlier lifecycle phase than the Maven license plugin to
Root dir of maven multi module project/LICENSES/configuration/runtime
and all Maven properties in there are replaced at runtime (see my example Parent pom.xml).
Now we have a final with absolute paths for the specific user we can configure in our parent pom :)
Parent pom,xml:
<build>
<resources>
<resource>
<directory>${maven.multiModuleProjectDirectory}/LICENSES/configuration/template</directory>
<includes>
<include>licenses-missing-configuration.xml</include>
</includes>
<filtering>true</filtering>
<targetPath>${maven.multiModuleProjectDirectory}/LICENSES/configuration/runtime</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>${maven.plugin.license-report.version}</version>
<executions>
<execution>
<id>licenses-download</id>
<configuration>
<!-- REPORT -->
<licensesOutputDirectory>${maven.multiModuleProjectDirectory}/LICENSES/generated_report/licenses</licensesOutputDirectory>
<licensesOutputFile>${maven.multiModuleProjectDirectory}/LICENSES/generated_report/licenses-overview.xml</licensesOutputFile>
<!-- ERROR HANDLING -->
<!-- write all errors regarding license retrieval to <licensesErrorsFile> -->
<errorRemedy>xmlOutput</errorRemedy>
<!-- file which logs the dependencies whose licenses could not be downloaded plus the reason.
Can be used as template for building up (or complete the existing) template of <licensesConfigFile> -->
<licensesErrorsFile>${maven.multiModuleProjectDirectory}/LICENSES/generated_report/licenses-errors.xml</licensesErrorsFile>
<!-- CONFIGURATION -->
<cleanLicensesOutputDirectory>true</cleanLicensesOutputDirectory>
<!-- download the license for each dependency individually to <licensesOutputDirectory> -->
<organizeLicensesByDependencies>true</organizeLicensesByDependencies>
<!-- sort & group <licensesOutputFile> -->
<sortByGroupIdAndArtifactId>true</sortByGroupIdAndArtifactId>
<!-- exclude our own artifacts as we do not provide a license for them. Expects a regular expression -->
<excludedGroups>vwg.fh.fismon.*|de.volkswagen.fismon.*</excludedGroups>
<!-- some license hosting websites take a lot of time to load -->
<connectTimeout>15000</connectTimeout>
<!-- MISSING LICENSE HANDLING -->
<!-- configuration file which provides manually added missing license information for all projects. Is generated at Maven runtime and based on the template in /LICENSES/configuration/template/ which again is based on <licensesErrorsFile> -->
<licensesConfigFile>${maven.multiModuleProjectDirectory}/LICENSES/configuration/runtime/licenses-missing-configuration.xml</licensesConfigFile>
</configuration>
</execution>
</executions>
</plugin>
</pluginManagement>
</build>