Skip to content

Commit

Permalink
Update license script apps
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Dec 5, 2019
1 parent 3eb3c3f commit a166796
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions build/license.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ function handleFile($path, $gitRoot) {
$license = str_replace('@COPYRIGHT@', $copyrightNotices, $license);
}

$source = $this->eatOldLicense($source);
$source = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
[$source, $isStrict] = $this->eatOldLicense($source);
if ($isStrict) {
$source = "<?php" . PHP_EOL . PHP_EOL . 'declare(strict_types=1);' . PHP_EOL . PHP_EOL . $license . PHP_EOL . $source;
} else {
$source = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
}
file_put_contents($path,$source);
echo "License updated: $path" . PHP_EOL;
}
Expand All @@ -184,28 +188,44 @@ private function isMITLicensed($source) {
return false;
}

private function isOwnCloudLicensed($source) {
$lines = explode(PHP_EOL, $source);
while(!empty($lines)) {
$line = $lines[0];
array_shift($lines);
if (strpos($line, 'ownCloud, Inc') !== false || strpos($line, 'ownCloud GmbH') !== false) {
return true;
}
private function isOwnCloudLicensed($source) {
$lines = explode(PHP_EOL, $source);
while(!empty($lines)) {
$line = $lines[0];
array_shift($lines);
if (strpos($line, 'ownCloud, Inc') !== false || strpos($line, 'ownCloud GmbH') !== false) {
return true;
}
}

return false;
}
return false;
}

/**
* @param string $source
* @return string
*/
private function eatOldLicense($source) {
$lines = explode(PHP_EOL, $source);
$isStrict = false;
while(!empty($lines)) {
$line = $lines[0];
if (strpos($line, '<?php') !== false) {
if (trim($line) === '<?php') {
array_shift($lines);
continue;
}
if (strpos($line, '<?php declare(strict_types') !== false) {
$isStrict = true;
array_shift($lines);
continue;
}
if (strpos($line, 'declare (strict_types') !== false) {
$isStrict = true;
array_shift($lines);
continue;
}
if (strpos($line, 'declare(strict_types') !== false) {
$isStrict = true;
array_shift($lines);
continue;
}
Expand All @@ -228,7 +248,7 @@ private function eatOldLicense($source) {
break;
}

return implode(PHP_EOL, $lines);
return [implode(PHP_EOL, $lines), $isStrict];
}

private function getCopyrightNotices($path, $file) {
Expand Down Expand Up @@ -364,7 +384,9 @@ private function fixInvalidEmail($author) {
$licenses->exec($argv[1], isset($argv[2]) ? $argv[1] : false);
} else {
$licenses->exec([
'../apps/accessibility',
'../apps/admin_audit',
'../apps/cloud_federation_api',
'../apps/comments',
'../apps/dav',
'../apps/encryption',
Expand All @@ -375,17 +397,21 @@ private function fixInvalidEmail($author) {
'../apps/files_sharing',
'../apps/files_trashbin',
'../apps/files_versions',
'../apps/lookup_server_connector',
'../apps/oauth2',
'../apps/provisioning_api',
'../apps/settings',
'../apps/sharebymail',
'../apps/systemtags',
'../apps/testing',
'../apps/theming',
'../apps/twofactor_backupcodes',
'../apps/updatenotification',
'../apps/user_ldap',
'../build/integration/features/bootstrap',
'../core',
'../lib',
'../ocs',
'../settings',
'../console.php',
'../cron.php',
'../index.php',
Expand Down

0 comments on commit a166796

Please sign in to comment.