Commit 43fec0e1 authored by mo's avatar mo Committed by Can Eldem
Browse files

Install maven packages for multi-module setup

* Install packages when multiple maven modules are detected
* Add CHANGELOG entry
* Install gem silently
* Add package manager to test description
* Sort paths
parent df97efac
......@@ -27,7 +27,8 @@ build commit:
script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build -t $TMP_IMAGE .
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $TMP_IMAGE .
- docker image inspect $TMP_IMAGE --format='{{.Size}}'
- docker push $TMP_IMAGE
......
# GitLab License management changelog
## v3.1.2
- Use `license-maven-plugin:aggreate-download-licenses` for multi-module projects. (!123)
## v3.1.1
- Fix invocation of `SETUP_CMD`. (!122)
......
......@@ -11,11 +11,11 @@ RUN apt-get update -q \
&& apt-get install -y --no-install-recommends ruby \
&& gem build *.gemspec
# Install org.codehaus.mojo:license-maven-plugin:download-licenses to $HOME/.m2/repository
# Install org.codehaus.mojo:license-maven-plugin to $HOME/.m2/repository
FROM debian:stable AS license-maven-plugin-builder
RUN apt-get update -q \
&& apt-get install -y --no-install-recommends maven \
&& mvn license:help
&& mvn license:license-list
FROM debian:stable-slim as tools-builder
ENV ASDF_DATA_DIR="/opt/asdf"
......
PATH
remote: .
specs:
license-management (3.1.1)
license-management (3.1.2)
license_finder (~> 6.0.0)
GEM
......
......@@ -38,16 +38,16 @@ You can then run License Management on some target directory:
docker run --rm --volume "/path/to/my/project":/code license-management analyze /code
```
You can run the tests using the following command:
You can run the tests from your host machine using the following command:
```sh
./bin/test
```
It is much more efficient to run the tests from inside the docker container. This can be
accomplished by following these steps:
It is much more efficient to run the tests from inside the docker container:
```sh
./bin/docker-build
./bin/docker-shell
cd /opt/license-management/
./bin/test
......
......@@ -8,9 +8,7 @@ export CI_PROJECT_DIR="$1"
echo "Scanning $CI_PROJECT_DIR"
if [ -n "${LM_HOME:-}" ]; then
gem build ./*.gemspec
mkdir -p pkg/
mv ./*.gem pkg/
mkdir -p pkg/ && gem build --silent -o pkg/license-management-test.gem ./*.gemspec
./run.sh analyze "$CI_PROJECT_DIR"
else
export IMAGE_NAME=${IMAGE_NAME:-$(basename "$PWD"):latest}
......
......@@ -25,7 +25,7 @@ function enable_dev_mode() {
export EDITOR=vim
set -o vi
apt-get update -y
apt-get install -y --no-install-recommends vim less
apt-get install -y --no-install-recommends vim less shellcheck
}
inflate /opt/asdf.tar.zst /opt
......
......@@ -11,7 +11,7 @@
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/${env.CI_PROJECT_ID}/packages/maven</url>
<url>${env.CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</repository>
</repositories>
</profile>
......
# frozen_string_literal: true
require 'license/finder/ext/license'
require 'license/finder/ext/maven'
require 'license/finder/ext/nuget'
require 'license/finder/ext/shared_helpers'
......
# frozen_string_literal: true
module LicenseFinder
Maven.class_eval do
XML_PARSE_OPTIONS = {
'ForceArray' => %w[license dependency],
'GroupTags' => {
'licenses' => 'license',
'dependencies' => 'dependency'
}
}.freeze
def current_packages
Dir.chdir(project_path) do
LicenseFinder::SharedHelpers::Cmd.run(detect_licenses_command)
resource_files.flat_map { |file| map_from(file.read) }.uniq
end
end
private
def detect_licenses_command
[
package_management_command,
"-e",
"org.codehaus.mojo:license-maven-plugin:aggregate-download-licenses",
"-Dlicense.excludedScopes=#{@ignored_groups.to_a.join(',')}",
ENV.fetch('MAVEN_CLI_OPTS', '-DskipTests')
].join(' ')
end
def resource_files
Pathname.glob(project_path.join('**', 'target', 'generated-resources', 'licenses.xml'))
end
def map_from(xml)
::License::Management.logger.debug(xml)
XmlSimple
.xml_in(xml, XML_PARSE_OPTIONS)['dependencies']
.map { |dependency| MavenPackage.new(dependency) }
end
end
end
......@@ -5,15 +5,9 @@ module LicenseFinder
class Cmd
def self.run(command)
stdout, stderr, status = Open3.capture3(command)
debug([command, stdout].join('\n'))
::License::Management.logger.debug([command, stdout].join('\n'))
[stdout, stderr, status]
end
def self.debug(message)
return unless ENV['CI_DEBUG_TRACE'] == 'true'
::LicenseFinder::Core.default_logger.info(self.class, message)
end
end
end
end
# frozen_string_literal: true
require 'json'
require 'logger'
require 'pathname'
require 'yaml'
require 'json'
require 'license_finder'
require 'license/management/loggable'
require 'license/management/verifiable'
......@@ -18,11 +20,8 @@ module License
Pathname.new(File.dirname(__FILE__)).join('../..')
end
def self.http
@http ||= Net::Hippie::Client.new.tap do |client|
client.logger = ::Logger.new('http.log')
client.follow_redirects = 3
end
def self.logger
@logger ||= Logger.new(STDOUT)
end
end
end
......@@ -4,15 +4,15 @@ module License
module Management
module Loggable
def logger
::LicenseFinder::Core.default_logger
License::Management.logger
end
def log_info(message)
logger.info(self.class, message)
logger.info(message)
end
def log_error(message)
logger.info(self.class, message, color: :red)
logger.error(message)
end
end
end
......
......@@ -26,7 +26,7 @@ module License
paths = dependency.aggregate_paths
return [] if blank?(paths)
paths.map { |x| x.gsub(Dir.pwd, '.') }
paths.map { |x| x.gsub(Dir.pwd, '.') }.sort
end
def description_for(dependency)
......
......@@ -2,6 +2,6 @@
module License
module Management
VERSION = '3.1.1'
VERSION = '3.1.2'
end
end
......@@ -6,14 +6,15 @@ set -e
BUNDLE_JOBS="$(nproc)"
export BUNDLE_JOBS
export BUNDLE_WITHOUT="development:test"
export CI_API_V4_URL="${CI_API_V4_URL:-https://gitlab.com/api/v4}"
export CI_DEBUG_TRACE=${CI_DEBUG_TRACE:='false'}
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export HISTFILESIZE=0
export HISTSIZE=0
export LICENSE_FINDER_CLI_OPTS=${LICENSE_FINDER_CLI_OPTS:='--no-debug'}
export LM_REPORT_FILE=${LM_REPORT_FILE:-'gl-license-management-report.json'}
export MAVEN_CLI_OPTS="${MAVEN_CLI_OPTS:='-DskipTests'}"
export PREPARE="--prepare-no-fail"
export MAVEN_CLI_OPTS="${MAVEN_CLI_OPTS:--DskipTests}"
export PREPARE="${PREPARE:---prepare-no-fail}"
export RECURSIVE='--no-recursive'
export RUBY_GC_HEAP_INIT_SLOTS=800000
export RUBY_GC_MALLOC_LIMIT=79000000
......@@ -42,7 +43,7 @@ function debug_env() {
}
function scan_project() {
gem install --quiet --silent "$LM_HOME/pkg/*.gem"
gem install -f --silent "$LM_HOME/pkg/*.gem"
license_management ignored_groups add development
license_management ignored_groups add test
echo license_management report "$@"
......@@ -112,5 +113,4 @@ scan_project "$PREPARE" \
--save="${LM_REPORT_FILE}" \
--python-version="${python_version}" \
"$RECURSIVE" \
--maven-options="$MAVEN_CLI_OPTS" \
"$LICENSE_FINDER_CLI_OPTS"
{
"licenses": [
{ "count": 15, "name": "Apache 2.0" },
{ "count": 4, "name": "BSD" },
{ "count": 1, "name": "MPL 1.1, GNU Lesser General Public License version 2.1, Apache 2.0" },
{ "count": 1, "name": "unknown" }
],
"dependencies": [
{
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm-commons", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm-tree", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-fileupload", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-io", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-lang3", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "freemarker", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-annotations", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-core", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-databind", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-dataformat-xml", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-module-jaxb-annotations", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "MPL 1.1, GNU Lesser General Public License version 2.1, Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "javassist", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-api", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-api", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-core", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "unknown" },
"dependency": { "name": "model", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "netty-all", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "ognl", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "stax2-api", "description": "", "pathes": [ "." ] }
},
{
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "struts2-core", "description": "", "pathes": [ "." ] }
}
]
}
{
"version": "1.1",
"licenses": [
{ "count": 15, "name": "Apache 2.0" },
{ "count": 4, "name": "BSD" },
{ "count": 1, "name": "MPL 1.1, GNU Lesser General Public License version 2.1, Apache 2.0" },
{ "count": 1, "name": "unknown" }
],
"dependencies": [
{
"licenses": [
{ "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" }
],
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm", "description": "", "pathes": [ "." ] }
},
{
"licenses": [ { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" } ],
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm-commons", "description": "", "pathes": [ "." ] }
},
{
"licenses": [ { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" } ],
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "asm-tree", "description": "", "pathes": [ "." ] }
},
{
"licenses": [ { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" } ],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-fileupload", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-io", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "commons-lang3", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "freemarker", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-annotations", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-core", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-databind", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-dataformat-xml", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "jackson-module-jaxb-annotations", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
{ "name": "GNU Lesser General Public License version 2.1", "url": "https://opensource.org/licenses/LGPL-2.1" },
{ "name": "MPL 1.1", "url": "" }
],
"license": { "name": "MPL 1.1, GNU Lesser General Public License version 2.1, Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "javassist", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-api", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-api", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "log4j-core", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "unknown", "url": "" }
],
"license": { "name": "unknown" },
"dependency": { "name": "model", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "netty-all", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "ognl", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" }
],
"license": { "name": "BSD", "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" },
"dependency": { "name": "stax2-api", "description": "", "pathes": [ "." ] }
},
{
"licenses": [
{ "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" }
],
"license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.txt" },
"dependency": { "name": "struts2-core", "description": "", "pathes": [ "." ] }
}
]
}
{
"version": "2.0",
"licenses": [
{
"id": "Apache-2.0",
"name": "Apache License 2.0",
"url": "https://opensource.org/licenses/Apache-2.0",
"count": 16
},
{
"id": "BSD-4-Clause",
"name": "BSD 4-Clause \"Original\" or \"Old\" License",
"url": "http://directory.fsf.org/wiki/License:BSD_4Clause",
"count": 4
},
{
"id": "LGPL-2.1",
"name": "GNU Lesser General Public License v2.1 only",
"url": "https://opensource.org/licenses/LGPL-2.1",
"count": 1
},
{
"id": "MPL-1.1",
"name": "Mozilla Public License 1.1",
"url": "https://opensource.org/licenses/MPL-1.1",
"count": 1
},
{
"id": "unknown",
"name": "unknown",
"url": "",
"count": 1
}
],
"dependencies": [
{ "name": "asm", "url": "", "description": "", "paths": [ "." ], "licenses": [ "BSD-4-Clause" ] },
{ "name": "asm-commons", "url": "", "description": "", "paths": [ "." ], "licenses": [ "BSD-4-Clause" ] },
{ "name":