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 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..b546902a96a03 --- /dev/null +++ b/tasks/build/notice.js @@ -0,0 +1,86 @@ +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'; + +export default function licenses(grunt) { + grunt.registerTask('_build:notice', 'Adds a notice', function () { + const done = this.async(); + const buildPath = path.join(grunt.config.get('buildDir'), 'kibana'); + + function getPackagePaths() { + const packagePaths = {}; + const installedPackages = execSync(`npm ls --parseable --long`, { + cwd: buildPath + }); + installedPackages.toString().trim().split('\n').forEach(pkg => { + const packageDetails = pkg.split(':'); + 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; + } + + 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(); + 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]; + 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`; + + content += combinedText; + }); + return content; + } + + function getBaseNotice() { + return fs.readFileSync(path.join(__dirname, 'notice', 'base_notice.txt')); + } + + 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, getBaseNotice()); + fs.appendFileSync(fd, getPackageInfo(result)); + fs.appendFileSync(fd, getNodeInfo()); + fs.closeSync(fd); + done(); + }); + }); +} diff --git a/tasks/build/notice/base_notice.txt b/tasks/build/notice/base_notice.txt new file mode 100644 index 0000000000000..19f505cdfe61b --- /dev/null +++ b/tasks/build/notice/base_notice.txt @@ -0,0 +1,59 @@ +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. +---