diff --git a/build/license.php b/build/license.php new file mode 100644 index 0000000000..bd3bce15a4 --- /dev/null +++ b/build/license.php @@ -0,0 +1,166 @@ + + * + */ +class Licenses +{ + protected $paths = array(); + + public function __construct() { + $this->licenseText = << + * + */ +EOD; + $this->licenseText = str_replace('@YEAR@', date("Y"), $this->licenseText); + } + + function exec($folder) { + + if (is_array($folder)) { + foreach($folder as $f) { + $this->exec($f); + } + return; + } + + if (is_file($folder)) { + $this->handleFile($folder); + return; + } + + $excludes = array_map(function($item) use ($folder) { + return $folder . '/' . $item; + }, ['vendor', '3rdparty', '.git', 'l10n', 'templates']); + + $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS); + $iterator = new RecursiveCallbackFilterIterator($iterator, function($item) use ($folder, $excludes){ + /** @var SplFileInfo $item */ + foreach($excludes as $exclude) { + if (substr($item->getPath(), 0, strlen($exclude)) === $exclude) { + return false; + } + } + return true; + }); + $iterator = new RecursiveIteratorIterator($iterator); + $iterator = new RegexIterator($iterator, '/^.+\.php$/i'); + + foreach ($iterator as $file) { + /** @var SplFileInfo $file */ + $this->handleFile($file); + } + + } + + function handleFile($path) { + $source = file_get_contents($path); + $source = $this->eatOldLicense($source); + $authors = $this->getAuthors($path); + $license = str_replace('@AUTHORS@', $authors, $this->licenseText); + + $source = "']); + }); + $authors = array_map(function($author){ + return " * @author $author"; + }, $authors); + return implode(PHP_EOL, $authors); + } +} + +$licenses = new Licenses; +$licenses->exec([ + '../apps/files', + '../apps/files_encryption', + '../apps/files_external', + '../apps/files_sharing', + '../apps/files_trashbin', + '../apps/files_versions', + '../apps/provisioning_api', + '../apps/user_ldap', + '../apps/user_webdavauth', + '../core', + '../lib', + '../ocs', + '../settings', + '../console.php', + '../cron.php', + '../index.php', + '../public.php', + '../remote.php', + '../status.php', + '../version.php', +]); +