Skip to content

Commit

Permalink
Add/generate/verify NOTICE.txt file (#17504)
Browse files Browse the repository at this point in the history
* [dev/notice] add scripts for generating NOTICE.txt file

* [notice] react-resize-detector@0.6.0 was removed in b445389

* [notice] move notice text into relevant source

* [dev/notice] Generate NOTICE.txt file

* [jenkins] verify that notice.txt is up to date in CI

* [tasks/notice] update test to use new NOTICE.txt file

* [dev/notice] update company name in NOTICE.txt

* [notice/cli] exit with 0 when --help requested

* [notice/cli] add helpful logging

* [notice/cli] use --validate flag name instead

* [notice/cli] simplify NEWLINE_RE, ignore obscure line endings

* [utils/decode_geo_hash] fixup comment

* [utils/decode_geo_hash] remove useless comment
  • Loading branch information
spalger authored Apr 4, 2018
1 parent dee741c commit 608a1e3
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 54 deletions.
29 changes: 2 additions & 27 deletions tasks/lib/notice/base_notice.txt → NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
Kibana
Copyright 2012-2017 Elasticsearch

---
This product bundles react-resize-detector@0.6.0 which is available under a
"MIT" license.

The MIT License

Copyright (c) 2017 Vitalii Maslianok <maslianok@gmail.com>

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.
Copyright 2012-2018 Elasticsearch B.V.

---
This product bundles angular-ui-bootstrap@0.12.1 which is available under a
Expand Down Expand Up @@ -108,3 +82,4 @@ 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.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
"tree-kill": "1.1.0",
"ts-jest": "^22.0.4",
"typescript": "^2.7.2",
"vinyl-fs": "^3.0.2",
"xml2js": "0.4.19",
"xmlbuilder": "9.0.4"
},
Expand Down
2 changes: 2 additions & 0 deletions scripts/notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('../src/babel-register');
require('../src/dev/notice/cli');
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
* Version: 0.14.2 - 2015-10-17
* License: MIT
*/

/* @notice
* 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.
*/
angular.module("sense.ui.bootstrap", ["sense.ui.bootstrap.tpls","sense.ui.bootstrap.typeahead","sense.ui.bootstrap.position"]);
angular.module("sense.ui.bootstrap.tpls", ["sense/template/typeahead/typeahead-match.html","sense/template/typeahead/typeahead-popup.html"]);
angular.module('sense.ui.bootstrap.typeahead', ['sense.ui.bootstrap.position'])
Expand Down
74 changes: 74 additions & 0 deletions src/dev/notice/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { readFileSync, writeFileSync } from 'fs';
import { resolve, relative } from 'path';

import getopts from 'getopts';
import dedent from 'dedent';
import { createToolingLog, pickLevelFromFlags } from '@kbn/dev-utils';

import { REPO_ROOT } from '../constants';
import { generateNoticeText } from './generate_notice_text';

const NOTICE_PATH = resolve(REPO_ROOT, 'NOTICE.txt');

const unknownFlags = [];
const opts = getopts(process.argv.slice(2), {
boolean: [
'help',
'validate',
'verbose',
'debug',
],
unknown(flag) {
unknownFlags.push(flag);
}
});

const log = createToolingLog(pickLevelFromFlags(opts));
log.pipe(process.stdout);

if (unknownFlags.length) {
log.error(`Unknown flags ${unknownFlags.map(f => `"${f}"`).join(',')}`);
process.exitCode = 1;
opts.help = true;
}

if (opts.help) {
process.stdout.write('\n' + dedent`
Regenerate or validate NOTICE.txt.
Entries in NOTICE.txt are collected by finding all multi-line comments
that start with a "@notice" tag and copying their text content into
NOTICE.txt at the root of the repository.
Options:
--help Show this help info
--validate Don't write the NOTICE.txt, just fail if updates would have been made
--verbose Set logging level to verbose
--debug Set logging level to debug
` + '\n\n');
process.exit();
}

(async function run() {
log.info('Searching source files for multi-line comments starting with @notify');
const newText = await generateNoticeText(log);
if (!opts.validate) {
log.info('Wrote notice text to', NOTICE_PATH);
writeFileSync(NOTICE_PATH, newText, 'utf8');
return;
}

const currentText = readFileSync(NOTICE_PATH, 'utf8');
if (currentText === newText) {
log.success(NOTICE_PATH, 'is up to date');
return;
}

log.error(
`${relative(process.cwd(), NOTICE_PATH)} is out of date, run \`node scripts/notice\` to update the file and commit the results.`
);
process.exit(1);
}()).catch(error => {
log.error(error);
process.exit(1);
});
67 changes: 67 additions & 0 deletions src/dev/notice/generate_notice_text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import vfs from 'vinyl-fs';

import { REPO_ROOT } from '../constants';

const NOTICE_COMMENT_RE = /\/\*[\s\n\*]*@notice([\w\W]+?)\*\//g;
const NEWLINE_RE = /\r?\n/g;

export async function generateNoticeText(log) {
const globs = [
'**/*.{js,less,css,ts}',
];

const options = {
cwd: REPO_ROOT,
nodir: true,
ignore: [
'{node_modules,build,target,dist,optimize}/**',
'packages/*/{node_modules,build,target,dist}/**',
]
};

log.debug('vfs.src globs', globs);
log.debug('vfs.src options', options);
const files = vfs.src(globs, options);

const noticeComments = [];
await new Promise((resolve, reject) => {
files
.on('data', (file) => {
log.verbose(`Checking for @notice comments in ${file.relative}`);

const source = file.contents.toString('utf8');
let match;
while ((match = NOTICE_COMMENT_RE.exec(source)) !== null) {
log.info(`Found @notice comment in ${file.relative}`);
noticeComments.push(match[1]);
}
})
.on('error', reject)
.on('end', resolve);
});

let noticeText = '';
noticeText += 'Kibana\n';
noticeText += `Copyright 2012-${(new Date()).getUTCFullYear()} Elasticsearch B.V.\n`;

for (const comment of noticeComments.sort()) {
noticeText += '\n---\n';
noticeText += comment
.split(NEWLINE_RE)
.map(line => (
line
// trim whitespace
.trim()
// trim leading * and a single space
.replace(/(^\* ?)/, '')
))
.join('\n')
.trim();
noticeText += '\n';
}

noticeText += '\n';

log.debug(`notice text:\n\n${noticeText}`);
return noticeText;
}
1 change: 1 addition & 0 deletions src/dev/notice/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { generateNoticeText } from './generate_notice_text';
27 changes: 27 additions & 0 deletions src/ui/public/flot-charts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/* @notice
* This product includes code that is based on flot-charts, which was available
* under a "MIT" license.
*
* The MIT License (MIT)
*
* Copyright (c) 2007-2014 IOLA and Ole Laursen
*
* 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.
*/

import $ from 'jquery';
if (window) window.jQuery = $;
require('ui/flot-charts/jquery.flot');
Expand Down
27 changes: 27 additions & 0 deletions src/ui/public/styles/bootstrap/bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/

/* @notice
* 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.
*/

// Core variables and mixins
@import "variables.less";
@import "mixins.less";
Expand Down
23 changes: 14 additions & 9 deletions src/ui/public/utils/decode_geo_hash.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/*
* Decodes geohash to object containing
* top-left and bottom-right corners of
* rectangle and center point.
*
* geohash.js
* Geohash library for Javascript
* (c) 2008 David Troy
* Distributed under the MIT License
*/

/*
* @notice
* This product bundles geohash.js which is available under a
* "MIT" license. For details, see src/ui/public/utils/decode_geo_hash.js.
*/

/**
* Decodes geohash to object containing
* top-left and bottom-right corners of
* rectangle and center point.
*
* @method refine_interval
* @param interval {Array} [long, lat]
* @param cd {Number}
* @param mask {Number}
* @return {Object} interval
* @param {string} geohash
* @return {{latitude,longitude}}
*/
export function decodeGeoHash(geohash) {
let BITS = [16, 8, 4, 2, 1];
Expand Down
11 changes: 11 additions & 0 deletions tasks/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,16 @@ module.exports = function (grunt) {
`http.port=${esTestConfig.getPort()}`,
],
},

verifyNotice: {
options: {
wait: true,
},
cmd: process.execPath,
args: [
'scripts/notice',
'--validate'
]
}
};
};
1 change: 1 addition & 0 deletions tasks/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function (grunt) {

'run:eslint',
'licenses',
'run:verifyNotice',
'test:server',
'test:jest',
'test:jest_integration',
Expand Down
4 changes: 2 additions & 2 deletions tasks/lib/notice/__tests__/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe('tasks/lib/notice', () => {
expect(notice).to.contain(readFileSync(resolve(NODE_DIR, 'LICENSE'), 'utf8'));
});

it('includes the base_notice.txt file', () => {
expect(notice).to.contain(readFileSync(resolve(__dirname, '../base_notice.txt'), 'utf8'));
it('includes the NOTICE.txt file', () => {
expect(notice).to.contain(readFileSync(resolve(__dirname, '../../../../NOTICE.txt'), 'utf8'));
});
});
});
4 changes: 2 additions & 2 deletions tasks/lib/notice/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync } from 'fs';
import { generatePackageNoticeText } from './package_notice';
import { generateNodeNoticeText } from './node_notice';

const BASE_NOTICE = resolve(__dirname, './base_notice.txt');
const BASE_NOTICE_PATH = resolve(__dirname, '../../../NOTICE.txt');

/**
* When given a list of packages and the directory to the
Expand All @@ -26,7 +26,7 @@ export async function generateNoticeText(options = {}) {
);

return [
readFileSync(BASE_NOTICE, 'utf8'),
readFileSync(BASE_NOTICE_PATH, 'utf8'),
...packageNotices,
generateNodeNoticeText(nodeDir),
].join('\n---\n');
Expand Down
Loading

0 comments on commit 608a1e3

Please sign in to comment.