From 049e3473b2d0c4461d68ccb65b52d28b166cfb79 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Feb 2016 09:04:40 +0100 Subject: [PATCH 1/2] Allow the script to run for different git roots --- build/license.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/build/license.php b/build/license.php index ce6fceb8160a..9a2495683c27 100644 --- a/build/license.php +++ b/build/license.php @@ -48,17 +48,25 @@ public function __construct() { $this->licenseText = str_replace('@YEAR@', date("Y"), $this->licenseText); } - function exec($folder) { + /** + * @param string|string[] $folder + * @param string|bool $gitRoot + */ + function exec($folder, $gitRoot = false) { if (is_array($folder)) { foreach($folder as $f) { - $this->exec($f); + $this->exec($f, $gitRoot); } return; } + if ($gitRoot !== false && substr($gitRoot, -1) !== '/') { + $gitRoot .= '/'; + } + if (is_file($folder)) { - $this->handleFile($folder); + $this->handleFile($folder, $gitRoot); return; } @@ -81,7 +89,7 @@ function exec($folder) { foreach ($iterator as $file) { /** @var SplFileInfo $file */ - $this->handleFile($file); + $this->handleFile($file, $gitRoot); } } @@ -103,14 +111,14 @@ function writeAuthorsFile() { file_put_contents(__DIR__.'/../AUTHORS', $template); } - function handleFile($path) { + function handleFile($path, $gitRoot) { $source = file_get_contents($path); if ($this->isMITLicensed($source)) { echo "MIT licensed file: $path" . PHP_EOL; return; } $source = $this->eatOldLicense($source); - $authors = $this->getAuthors($path); + $authors = $this->getAuthors($path, $gitRoot); $license = str_replace('@AUTHORS@', $authors, $this->licenseText); $source = "exec($argv[1]); + $licenses->exec($argv[1], isset($argv[2]) ? $argv[1] : false); } else { $licenses->exec([ '../apps/dav', From 100b357c688868dc4104c05dba3677cf2b650b2e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Feb 2016 09:06:07 +0100 Subject: [PATCH 2/2] Check the mailmap file of core as well --- build/license.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/build/license.php b/build/license.php index 9a2495683c27..d7ac4e0a143a 100644 --- a/build/license.php +++ b/build/license.php @@ -20,7 +20,8 @@ */ class Licenses { - protected $paths = array(); + protected $paths = []; + protected $mailMap = []; public $authors = []; public function __construct() { @@ -196,12 +197,38 @@ private function getAuthors($file, $gitRoot) { 'Not Committed Yet ', 'Jenkins for ownCloud ']); }); + + if ($gitRoot) { + $authors = array_map([$this, 'checkCoreMailMap'], $authors); + $authors = array_unique($authors); + } + $authors = array_map(function($author){ $this->authors[$author] = $author; return " * @author $author"; }, $authors); return implode(PHP_EOL, $authors); } + + private function checkCoreMailMap($author) { + if (empty($this->mailMap)) { + $content = file_get_contents(__DIR__ . '/../.mailmap'); + $entries = explode("\n", $content); + foreach ($entries as $entry) { + if (strpos($entry, '> ') === false) { + $this->mailMap[$entry] = $entry; + } else { + list($use, $actual) = explode('> ', $entry); + $this->mailMap[$actual] = $use . '>'; + } + } + } + + if (isset($this->mailMap[$author])) { + return $this->mailMap[$author]; + } + return $author; + } } $licenses = new Licenses;