From 90dccc087b32218939ff288a1811029a2c5bdfea Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 13 Feb 2017 18:04:14 -0600 Subject: [PATCH 1/7] [build] Add notice file --- tasks/build/index.js | 1 + tasks/build/notice.js | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tasks/build/notice.js diff --git a/tasks/build/index.js b/tasks/build/index.js index 55b5ee51af578..cb5cbe08b95ca 100644 --- a/tasks/build/index.js +++ b/tasks/build/index.js @@ -17,6 +17,7 @@ module.exports = function (grunt) { '_build:readme', '_build:babelCache', '_build:installNpmDeps', + '_build:notice', '_build:removePkgJsonDeps', 'clean:testsFromModules', 'run:optimizeBuild', diff --git a/tasks/build/notice.js b/tasks/build/notice.js new file mode 100644 index 0000000000000..c04f9b57ca34b --- /dev/null +++ b/tasks/build/notice.js @@ -0,0 +1,53 @@ +import _ from 'lodash'; +import npm from 'npm'; +import npmLicense from 'license-checker'; +import path from 'path'; +import fs from 'fs'; +import { execSync } from 'child_process'; + +export default function licenses(grunt) { + grunt.registerTask('_build:notice', 'Adds a notice', async function () { + const overrides = grunt.config.get('licenses.options.overrides'); + const done = this.async(); + const buildPath = path.join(grunt.config.get('buildDir'), 'kibana'); + const noticePath = path.join(buildPath, 'NOTICE.txt'); + const fd = fs.openSync(noticePath, 'w'); + + function getPackagePaths() { + const packagePaths = {}; + const installedPackages = execSync(`npm ls --parseable --long`, { + cwd: buildPath + }); + installedPackages.toString().trim().split('\n').forEach(pkg => { + const packageDetails = pkg.split(':'); + packagePaths[packageDetails[1]] = packageDetails[0].replace(/.*\/kibana\//, ''); + }); + return packagePaths; + } + + fs.appendFileSync(fd, + 'Elasticsearch Kibana\nCopyright 2012-2017 Elasticsearch' + + '\n\n---\n' + ); + npmLicense.init({ + start: buildPath, + production: true, + json: true + }, (result, error) => { + if (error) return grunt.fail.fatal(error); + const packagePaths = getPackagePaths(); + _.forOwn(result, (value, key) => { + const licenses = [].concat(overrides.hasOwnProperty(key) ? overrides[key] : value.licenses); + if (!licenses.length || licenses.includes('UNKNOWN')) return grunt.fail.fatal(`Unknown license for ${key}`); + + const licenseText = licenses.length > 1 ? `the\n"${licenses.join('", ')} licenses` : `a\n"${licenses[0]}" license`; + const noticeText = + `This product bundles ${key} which is available under ${licenseText}. ` + + `For details, see ${packagePaths[key]}/.\n\n---\n`; + fs.appendFileSync(fd, noticeText); + }); + fs.closeSync(fd); + done(); + }); + }); +} From 7cfa6bf6b479fda08dff7987a14b704b69cb5e2b Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Tue, 14 Feb 2017 15:58:15 -0600 Subject: [PATCH 2/7] [build] Include license text if available --- tasks/build/notice.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/build/notice.js b/tasks/build/notice.js index c04f9b57ca34b..45ce8e09e1a7f 100644 --- a/tasks/build/notice.js +++ b/tasks/build/notice.js @@ -40,10 +40,11 @@ export default function licenses(grunt) { const licenses = [].concat(overrides.hasOwnProperty(key) ? overrides[key] : value.licenses); if (!licenses.length || licenses.includes('UNKNOWN')) return grunt.fail.fatal(`Unknown license for ${key}`); + const licenseFile = value.licenseFile && fs.readFileSync(value.licenseFile); const licenseText = licenses.length > 1 ? `the\n"${licenses.join('", ')} licenses` : `a\n"${licenses[0]}" license`; - const noticeText = - `This product bundles ${key} which is available under ${licenseText}. ` - + `For details, see ${packagePaths[key]}/.\n\n---\n`; + const licenseFileText = licenseFile ? `\n\n${licenseFile}` : ` For details, see ${packagePaths[key]}/.`; + const noticeText = `This product bundles ${key} which is available under ${licenseText}.${licenseFileText}\n\n---\n`; + fs.appendFileSync(fd, noticeText); }); fs.closeSync(fd); From 090a2d928203c9b384302003b9742181ed887f09 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Wed, 15 Feb 2017 10:37:10 -0600 Subject: [PATCH 3/7] [build] Look for both license and notice files --- tasks/build/notice.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tasks/build/notice.js b/tasks/build/notice.js index 45ce8e09e1a7f..ff0d155da145f 100644 --- a/tasks/build/notice.js +++ b/tasks/build/notice.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import npm from 'npm'; import npmLicense from 'license-checker'; +import glob from 'glob'; import path from 'path'; import fs from 'fs'; import { execSync } from 'child_process'; @@ -20,11 +21,26 @@ export default function licenses(grunt) { }); installedPackages.toString().trim().split('\n').forEach(pkg => { const packageDetails = pkg.split(':'); - packagePaths[packageDetails[1]] = packageDetails[0].replace(/.*\/kibana\//, ''); + const [modulePath, packageName] = packageDetails; + const licenses = glob.sync(path.join(modulePath, '*LICENSE*')); + const notices = glob.sync(path.join(modulePath, '*NOTICE*')); + packagePaths[packageName] = { + relative: modulePath.replace(/.*\/kibana\//, ''), + licenses, + notices + }; }); return packagePaths; } + function combineFiles(filePaths) { + let content = ''; + filePaths.forEach(filePath => { + content += fs.readFileSync(filePath) + '\n'; + }); + return content; + } + fs.appendFileSync(fd, 'Elasticsearch Kibana\nCopyright 2012-2017 Elasticsearch' + '\n\n---\n' @@ -39,13 +55,13 @@ export default function licenses(grunt) { _.forOwn(result, (value, key) => { const licenses = [].concat(overrides.hasOwnProperty(key) ? overrides[key] : value.licenses); if (!licenses.length || licenses.includes('UNKNOWN')) return grunt.fail.fatal(`Unknown license for ${key}`); + const packagePath = packagePaths[key]; + const readLicenseAndNotice = combineFiles([].concat(packagePath.licenses, packagePath.notices)); + const licenseOverview = licenses.length > 1 ? `the\n"${licenses.join('", ')} licenses` : `a\n"${licenses[0]}" license`; + const licenseAndNotice = readLicenseAndNotice ? `\n${readLicenseAndNotice}` : ` For details, see ${packagePath.relative}/.`; + const combinedText = `This product bundles ${key} which is available under ${licenseOverview}.${licenseAndNotice}\n---\n`; - const licenseFile = value.licenseFile && fs.readFileSync(value.licenseFile); - const licenseText = licenses.length > 1 ? `the\n"${licenses.join('", ')} licenses` : `a\n"${licenses[0]}" license`; - const licenseFileText = licenseFile ? `\n\n${licenseFile}` : ` For details, see ${packagePaths[key]}/.`; - const noticeText = `This product bundles ${key} which is available under ${licenseText}.${licenseFileText}\n\n---\n`; - - fs.appendFileSync(fd, noticeText); + fs.appendFileSync(fd, combinedText); }); fs.closeSync(fd); done(); From e9226b96811cdc845bac2052d8cc7e5a8125acde Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Wed, 15 Feb 2017 11:08:32 -0600 Subject: [PATCH 4/7] [build] Add node license to notice --- tasks/build/notice.js | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/tasks/build/notice.js b/tasks/build/notice.js index ff0d155da145f..1bd46cc9755d4 100644 --- a/tasks/build/notice.js +++ b/tasks/build/notice.js @@ -7,12 +7,9 @@ import fs from 'fs'; import { execSync } from 'child_process'; export default function licenses(grunt) { - grunt.registerTask('_build:notice', 'Adds a notice', async function () { - const overrides = grunt.config.get('licenses.options.overrides'); + grunt.registerTask('_build:notice', 'Adds a notice', function () { const done = this.async(); const buildPath = path.join(grunt.config.get('buildDir'), 'kibana'); - const noticePath = path.join(buildPath, 'NOTICE.txt'); - const fd = fs.openSync(noticePath, 'w'); function getPackagePaths() { const packagePaths = {}; @@ -41,18 +38,19 @@ export default function licenses(grunt) { return content; } - fs.appendFileSync(fd, - 'Elasticsearch Kibana\nCopyright 2012-2017 Elasticsearch' + - '\n\n---\n' - ); - npmLicense.init({ - start: buildPath, - production: true, - json: true - }, (result, error) => { - if (error) return grunt.fail.fatal(error); + function getNodeInfo() { + const nodeVersion = grunt.config.get('nodeVersion'); + const nodeDir = path.join(grunt.config.get('root'), '.node_binaries', nodeVersion); + const licensePath = path.join(nodeDir, 'linux-x64', 'LICENSE'); + const license = fs.readFileSync(licensePath); + return `This product bundles Node.js.\n\n${license}`; + } + + function getPackageInfo(packages) { const packagePaths = getPackagePaths(); - _.forOwn(result, (value, key) => { + const overrides = grunt.config.get('licenses.options.overrides'); + let content = ''; + _.forOwn(packages, (value, key) => { const licenses = [].concat(overrides.hasOwnProperty(key) ? overrides[key] : value.licenses); if (!licenses.length || licenses.includes('UNKNOWN')) return grunt.fail.fatal(`Unknown license for ${key}`); const packagePath = packagePaths[key]; @@ -61,8 +59,22 @@ export default function licenses(grunt) { const licenseAndNotice = readLicenseAndNotice ? `\n${readLicenseAndNotice}` : ` For details, see ${packagePath.relative}/.`; const combinedText = `This product bundles ${key} which is available under ${licenseOverview}.${licenseAndNotice}\n---\n`; - fs.appendFileSync(fd, combinedText); + content += combinedText; }); + return content; + } + + npmLicense.init({ + start: buildPath, + production: true, + json: true + }, (result, error) => { + if (error) return grunt.fail.fatal(error); + const noticePath = path.join(buildPath, 'NOTICE.txt'); + const fd = fs.openSync(noticePath, 'w'); + fs.appendFileSync(fd, 'Elasticsearch Kibana\nCopyright 2012-2017 Elasticsearch\n\n---\n'); + fs.appendFileSync(fd, getPackageInfo(result)); + fs.appendFileSync(fd, getNodeInfo()); fs.closeSync(fd); done(); }); From c30d1bd284d10a72491628b93ddde1c46b00ff14 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Wed, 15 Feb 2017 12:23:08 -0600 Subject: [PATCH 5/7] [build] Add a base notice file including info on committed dependencies --- tasks/build/notice.js | 6 ++- tasks/build/notice/base_notice.txt | 59 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tasks/build/notice/base_notice.txt diff --git a/tasks/build/notice.js b/tasks/build/notice.js index 1bd46cc9755d4..b546902a96a03 100644 --- a/tasks/build/notice.js +++ b/tasks/build/notice.js @@ -64,6 +64,10 @@ export default function licenses(grunt) { return content; } + function getBaseNotice() { + return fs.readFileSync(path.join(__dirname, 'notice', 'base_notice.txt')); + } + npmLicense.init({ start: buildPath, production: true, @@ -72,7 +76,7 @@ export default function licenses(grunt) { if (error) return grunt.fail.fatal(error); const noticePath = path.join(buildPath, 'NOTICE.txt'); const fd = fs.openSync(noticePath, 'w'); - fs.appendFileSync(fd, 'Elasticsearch Kibana\nCopyright 2012-2017 Elasticsearch\n\n---\n'); + fs.appendFileSync(fd, getBaseNotice()); fs.appendFileSync(fd, getPackageInfo(result)); fs.appendFileSync(fd, getNodeInfo()); fs.closeSync(fd); diff --git a/tasks/build/notice/base_notice.txt b/tasks/build/notice/base_notice.txt new file mode 100644 index 0000000000000..247285f4d6ab2 --- /dev/null +++ b/tasks/build/notice/base_notice.txt @@ -0,0 +1,59 @@ +Elasticsearch Kibana +Copyright 2012-2017 Elasticsearch + +--- +This product bundles angular-ui-bootstrap@0.12.1 which is available under a +"MIT" license. + +The MIT License + +Copyright (c) 2012-2014 the AngularUI Team, https://github.com/organizations/angular-ui/teams/291112 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +--- +This product bundles bootstrap@3.3.6 which is available under a +"MIT" license. + +The MIT License (MIT) + +Copyright (c) 2011-2015 Twitter, Inc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +--- +This product bundles geohash.js which is available under a +"MIT" license. For details, see src/ui/public/utils/decode_geo_hash.js. +--- From 268ae9795e7583f6b485cf692ce3a4d1f47f87b8 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Wed, 15 Feb 2017 12:29:31 -0600 Subject: [PATCH 6/7] Bump license copyright year --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index b4a47058738d7..be4e1b688571a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright 2012–2016 Elasticsearch BV +Copyright 2012–2017 Elasticsearch BV 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 From f3228fafc8fafbd2ec6ca7f8e895a7fddfd1cc42 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Thu, 16 Feb 2017 08:00:51 -0600 Subject: [PATCH 7/7] [build] Kibana at top of notice --- tasks/build/notice/base_notice.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/notice/base_notice.txt b/tasks/build/notice/base_notice.txt index 247285f4d6ab2..19f505cdfe61b 100644 --- a/tasks/build/notice/base_notice.txt +++ b/tasks/build/notice/base_notice.txt @@ -1,4 +1,4 @@ -Elasticsearch Kibana +Kibana Copyright 2012-2017 Elasticsearch ---