diff options
| author | Lukas Eipert <leipert@gitlab.com> | 2018-06-14 18:36:22 +0000 |
|---|---|---|
| committer | Fabien Catteau <fcatteau@gitlab.com> | 2018-06-14 20:43:56 +0200 |
| commit | 70b8f51792b4445539f7fa05caaab36fcda963ab (patch) | |
| tree | d9a605ed2105029af7f472cb132a2c03696d846a | |
| parent | 2a372c2fb9fa055ed7b10386c64172fb52d7408a (diff) | |
Ensure that license name order is consistent
| -rw-r--r-- | html2json.js | 28 | ||||
| -rwxr-xr-x | run.sh | 28 | ||||
| -rw-r--r-- | test/results/java-maven.json | 245 | ||||
| -rwxr-xr-x | test/test.sh | 36 |
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)) @@ -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." |
