From 91510d95f15b5b84482b5700b04d229db28fbdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 17 Dec 2020 11:45:13 +0100 Subject: [PATCH] Add js files to license MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .eslintrc.js | 2 +- build/license.php | 148 ++++++++++++++++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 111 insertions(+), 41 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0315c64d76..000c46b1a8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,7 +8,7 @@ module.exports = { escapeHTML: true, oc_userconfig: true, dayNames: true, - firstDay: true + firstDay: true, }, extends: ['@nextcloud'], rules: { diff --git a/build/license.php b/build/license.php index 689d7e5e19..49fba751d0 100644 --- a/build/license.php +++ b/build/license.php @@ -1,5 +1,4 @@ * */ + class Licenses { protected $paths = []; protected $mailMap = []; @@ -98,7 +98,7 @@ EOD; $excludes = array_map(function ($item) use ($folder) { return $folder . '/' . $item; - }, ['vendor', '3rdparty', '.git', 'l10n', 'templates', 'composer']); + }, ['vendor', '3rdparty', '.git', 'l10n', 'templates', 'composer', 'js', 'node_modules']); $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); $iterator = new RecursiveCallbackFilterIterator($iterator, function ($item) use ($folder, $excludes) { @@ -111,7 +111,7 @@ EOD; return true; }); $iterator = new RecursiveIteratorIterator($iterator); - $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); + $iterator = new RegexIterator($iterator, '/^.+\.(js)$/i'); foreach ($iterator as $file) { /** @var SplFileInfo $file */ @@ -140,6 +140,8 @@ With help from many libraries and frameworks including: } public function handleFile($path, $gitRoot) { + $isPhp = preg_match('/^.+\.php$/i', $path); + $source = file_get_contents($path); if ($this->isMITLicensed($source)) { echo "MIT licensed file: $path" . PHP_EOL; @@ -155,18 +157,25 @@ With help from many libraries and frameworks including: } if ($copyrightNotices === '') { - $license = str_replace('@COPYRIGHT@', ' *', $license); + $creator = $this->getCreatorCopyright($path, $gitRoot); + $license = str_replace('@COPYRIGHT@', $creator, $license); } else { $license = str_replace('@COPYRIGHT@', $copyrightNotices, $license); } [$source, $isStrict] = $this->eatOldLicense($source); - if ($isStrict) { - $source = "filterAuthors($authors); + + if ($gitRoot) { + $authors = array_map([$this, 'checkCoreMailMap'], $authors); + $authors = array_unique($authors); + } + + $creator = array_key_exists(0, $authors) + ? $this->fixInvalidEmail($authors[0]) + : ''; + return " * @copyright Copyright (c) $year $creator"; + } + + private function getAuthors($file, $gitRoot) { + // only add authors that changed code and not the license header + $licenseHeaderEndsAtLine = trim(shell_exec("grep -n '*/' $file | head -n 1 | cut -d ':' -f 1")); + $buildDir = getcwd(); + + if ($gitRoot) { + chdir($gitRoot); + $file = substr($file, strlen($gitRoot)); + } + $out = shell_exec("git blame --line-porcelain -L $licenseHeaderEndsAtLine, $file | sed -n 's/^author //p;s/^author-mail //p' | sed 'N;s/\\n/ /' | sort -f | uniq"); + + if ($gitRoot) { + chdir($buildDir); + } + + $authors = explode(PHP_EOL, $out); + $authors = $this->filterAuthors($authors); + if ($gitRoot) { $authors = array_map([$this, 'checkCoreMailMap'], $authors); $authors = array_unique($authors); @@ -386,6 +451,8 @@ if (isset($argv[1])) { '../apps/admin_audit', '../apps/cloud_federation_api', '../apps/comments', + '../apps/contactsinteraction', + '../apps/dashboard', '../apps/dav', '../apps/encryption', '../apps/federatedfilesharing', @@ -406,6 +473,9 @@ if (isset($argv[1])) { '../apps/twofactor_backupcodes', '../apps/updatenotification', '../apps/user_ldap', + '../apps/user_status', + '../apps/weather_status', + '../apps/workflowengine', '../build/integration/features/bootstrap', '../core', '../lib', diff --git a/package.json b/package.json index 0ca099b6d8..8a9dfebc2e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "NODE_ENV=development webpack --progress --config webpack.dev.js", "watch": "NODE_ENV=development webpack --progress --watch --config webpack.dev.js", "lint": "eslint '**/src/**/*.{vue,js}'", - "lint:fix": "eslint '**/*.{vue,js}' --fix", + "lint:fix": "eslint '**/src/**/*.{vue,js}' --fix", "test": "mochapack --webpack-config core/webpack.test.js --require core/src/tests/setup.js \"core/src/tests/**/*.spec.js\"", "test:watch": "mochapack -w --webpack-config core/webpack.test.js --require core/src/tests/setup.js \"core/src/tests/**/*.spec.js\"" },