summaryrefslogtreecommitdiffstats
path: root/build/license.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-02-20 12:16:23 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-02-22 20:36:36 +0000
commitb86891435453cfdcc5b5df468ced941d4779b6f4 (patch)
tree2e5b6a08645792f22054c41be6ca6bc6004541c2 /build/license.php
parent0751ee087f90077d311b6168be653cb95dba6370 (diff)
downloadnextcloud-server-b86891435453cfdcc5b5df468ced941d4779b6f4.tar.gz
nextcloud-server-b86891435453cfdcc5b5df468ced941d4779b6f4.zip
php script which updates the license header in all php file in the repo
Diffstat (limited to 'build/license.php')
-rw-r--r--build/license.php166
1 files changed, 166 insertions, 0 deletions
diff --git a/build/license.php b/build/license.php
new file mode 100644
index 00000000000..bd3bce15a43
--- /dev/null
+++ b/build/license.php
@@ -0,0 +1,166 @@
+<?php
+/**
+ * @author Thomas Müller
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+class Licenses
+{
+ protected $paths = array();
+
+ public function __construct() {
+ $this->licenseText = <<<EOD
+/**
+@AUTHORS@
+ *
+ * @copyright Copyright (c) @YEAR@, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+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 = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
+ file_put_contents($path,$source);
+ echo "License updated: $path\n";
+ }
+
+ private function eatOldLicense($source) {
+ $lines = explode(PHP_EOL, $source);
+ while(!empty($lines)) {
+ $line = $lines[0];
+ if (strpos($line, '<?php') !== false) {
+ array_shift($lines);
+ continue;
+ }
+ if (strpos($line, '/**') !== false) {
+ array_shift($lines);
+ continue;
+ }
+ if (strpos($line, '*') !== false) {
+ array_shift($lines);
+ continue;
+ }
+ if (strpos($line, '*/') !== false) {
+ array_shift($lines);
+ continue;
+ }
+ if (trim($line) === '') {
+ array_shift($lines);
+ continue;
+ }
+ break;
+ }
+
+ return implode(PHP_EOL, $lines);
+ }
+
+ private function getAuthors($file) {
+ $out = shell_exec("git blame --line-porcelain $file | sed -n 's/^author //p;s/^author-mail //p' | sed 'N;s/\\n/ /' | sort | uniq");
+ $authors = explode(PHP_EOL, $out);
+
+ $authors = array_filter($authors, function($author) {
+ return !in_array($author, ['', 'Not Committed Yet', 'Jenkins for ownCloud <owncloud-bot@tmit.eu>']);
+ });
+ $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',
+]);
+