summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Catteau <fcatteau@gitlab.com>2018-06-14 18:36:22 +0000
committerFabien Catteau <fcatteau@gitlab.com>2018-06-14 18:36:22 +0000
commit670a77f83573b859684a19392074267e1a1128c0 (patch)
treecb42f99f76906d6ae652dc0b0dfc1ad5256cbf59
parentae265f62905777bd9df4c6397399413794afb15e (diff)
parent2bf9bc8145a881b7b6e17423ab8dfccbfd138fc7 (diff)
Merge branch 'ensure-license-order' into 'master'
Ensure that license name order is consistent See merge request gitlab-org/security-products/license-management!4
-rw-r--r--html2json.js28
-rwxr-xr-xrun.sh28
-rw-r--r--test/results/java-maven.json245
-rwxr-xr-xtest/test.sh36
4 files changed, 296 insertions, 41 deletions
diff --git a/html2json.js b/html2json.js
index 841149a..8e9f5c6 100644
--- a/html2json.js
+++ b/html2json.js
@@ -8,6 +8,7 @@ try {
htmlContent = fs.readFileSync(process.argv[2], 'utf8');
} catch(e) {
console.log('Error:', e.stack);
+ process.exit(1);
}
// Get the directory containing the results to make pathes relative to it later.
@@ -15,16 +16,8 @@ report_directory = path.dirname(process.argv[2])
const $ = cheerio.load(htmlContent)
-// Extract licenses and the number of occurences.
-var licenses = [];
-$('div.summary div.row').children().first().find('ul li').each(function(i, doc) {
- tmp = $(this).text();
- matches = tmp.match(/^([0-9]+) ((\s|\S)*)/m)
- licenses.push({
- count: parseInt(matches[1], 10),
- name: matches[2]
- })
-})
+// Map that keeps the total tally of the license occurrences
+var licenses = {};
// Extract dependencies info.
var dependencies = []
@@ -33,6 +26,12 @@ $('div.dependencies div').each(function(i, doc) {
license = $(this).find('blockquote p').text().trim();
license = license.split("\n")[0];
+ if(licenses[license]) {
+ licenses[license].count += 1;
+ } else {
+ licenses[license] = { count: 1, name: license }
+ }
+
// Get URL.
license_url = $(this).find('blockquote p a[href]').attr('href');
@@ -72,6 +71,15 @@ $('div.dependencies div').each(function(i, doc) {
})
})
+// Stable sort of licenses. First license count descending, then license name ascending
+licenses = Object.values(licenses)
+ .sort(function (a, b) {
+ if (a.count === b.count) {
+ return a.name > b.name ? 1 : -1;
+ }
+ return a.count < b.count ? 1 : -1;
+});
+
console.log(JSON.stringify({
licenses: licenses,
dependencies: dependencies}, null, 4))
diff --git a/run.sh b/run.sh
index e5433e2..6326f07 100755
--- a/run.sh
+++ b/run.sh
@@ -46,7 +46,7 @@ if [ "$COMMAND" = "analyse" ] ; then
COMMAND="analyze"
fi
-# "/test/test.sh" as a command means the user want the "test" command.
+# "/test/test.sh" as a command means the user want the "test" command.
if [ "$COMMAND" = "/test/test.sh" ] ; then
COMMAND="test"
fi
@@ -80,7 +80,7 @@ case "$COMMAND" in
APP_PATH=$1
shift
pushd $APP_PATH
-
+
# Before running license_finder, we need to install dependencies for the project.
if test -f Gemfile ; then
if test -n "$rvm_recommended_ruby" ; then
@@ -93,33 +93,33 @@ case "$COMMAND" in
# We need to install the license_finder gem into this Ruby version too.
gem install license_finder
fi
-
+
# Ignore test and development dependencies.
license_finder ignored_groups add development
license_finder ignored_groups add test
bundle install --without "development test"
fi
-
+
if test -f requirements.txt ; then
# Install Python Pip packages.
pip install -r requirements.txt
fi
-
+
if test -f package.json ; then
# Install NPM packages.
npm install --production
# Try to install Peer packages too, npm install doesn't do it anymore.
/node_modules/.bin/npm-install-peers
fi
-
+
if test -f bower.json ; then
# Install Bower packages.
bower install
fi
-
+
# Symlink the project into GOPATH to allow fetching dependencies.
- ln -s $APP_PATH /gopath/src/app
-
+ ln -sf `realpath $APP_PATH` /gopath/src/app
+
if test -f Godeps/Godeps.json ; then
# Install Go dependencies with Godeps.
pushd /gopath/src/app
@@ -131,22 +131,22 @@ case "$COMMAND" in
go get
popd
fi
-
+
if test -f pom.xml ; then
# Install Java Maven dependencies.
mvn install
fi
-
+
if test -f build.gradle ; then
# Install Java Gradle dependencies.
gradle build
fi
-
+
# Run License Finder.
echo "Running license_finder $@ in $PWD"
license_finder report --format=html --save=gl-license-management-report.html
popd
-
+
# Extract data from the HTML report and put it into a JSON file
node /html2json.js $APP_PATH/gl-license-management-report.html > $APP_PATH/gl-license-management-report.json
;;
@@ -156,4 +156,4 @@ case "$COMMAND" in
echo "Unknown command: $COMMAND"
echo "$usage"
exit 1
-esac
+esac
diff --git a/test/results/java-maven.json b/test/results/java-maven.json
new file mode 100644
index 0000000..fa7bf74
--- /dev/null
+++ b/test/results/java-maven.json
@@ -0,0 +1,245 @@
+{
+ "licenses": [
+ {
+ "count": 13,
+ "name": "Apache 2.0"
+ },
+ {
+ "count": 1,
+ "name": "BSD style"
+ },
+ {
+ "count": 1,
+ "name": "Common Public License Version 1.0"
+ },
+ {
+ "count": 1,
+ "name": "MIT"
+ },
+ {
+ "count": 1,
+ "name": "MPL 1.1, LGPL 2.1, Apache 2.0"
+ }
+ ],
+ "dependencies": [
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "commons-lang3",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "BSD style"
+ },
+ "dependency": {
+ "name": "hamcrest-core",
+ "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": "MPL 1.1, LGPL 2.1, Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "javassist",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Common Public License Version 1.0"
+ },
+ "dependency": {
+ "name": "junit",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "maven-artifact",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "MIT",
+ "url": "http://opensource.org/licenses/mit-license"
+ },
+ "dependency": {
+ "name": "mockito-core",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "netty",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "objenesis",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "plexus-utils",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "powermock-api-mockito",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "powermock-api-mockito-common",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "powermock-api-support",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "powermock-core",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ },
+ {
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
+ },
+ "dependency": {
+ "name": "powermock-reflect",
+ "description": "",
+ "pathes": [
+ "."
+ ]
+ }
+ }
+ ]
+}
diff --git a/test/test.sh b/test/test.sh
index c77ec1d..0130492 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -2,24 +2,26 @@
set -e
-# Clone the Ruby Bundler test repository.
-echo "Cloning the test repository https://gitlab.com/gitlab-org/security-products/tests/ruby-bundler.git"
-git clone https://gitlab.com/gitlab-org/security-products/tests/ruby-bundler.git /code
+for project in ruby-bundler java-maven; do
+ # Clone the test repository.
+ echo "Cloning the test repository https://gitlab.com/gitlab-org/security-products/tests/$project.git"
+ git clone "https://gitlab.com/gitlab-org/security-products/tests/$project.git" "/code/$project"
-# Run license management on it.
-echo "Running license management on the cloned repository"
-cd /code
-/run.sh analyze .
+ # Run license management on it.
+ echo "Running license management on the $project"
+ cd "/code/$project"
+ /run.sh analyze .
-# Compare results with expected results.
-set +e
-diff /code/gl-license-management-report.json /test/results/ruby-bundler.json > /diff.txt
+ # Compare results with expected results.
+ set +e
+ diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" > /diff.txt
+ set -e
-if [ -s /diff.txt ] ; then
- echo "Unexpected result. Here is the diff between actual results and those expected :"
- cat /diff.txt
- exit 1
-else
- echo "All tests are OK."
-fi
+ if [ -s /diff.txt ] ; then
+ echo "Unexpected result. Here is the diff between actual results and those expected :"
+ cat /diff.txt
+ exit 1
+ fi
+done
+echo "All tests are OK."