Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update license script: no more CLA and switch to AGPLv3 or later #11

Merged
merged 1 commit into from
Jun 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletions build/license.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ class Licenses
public function __construct() {
$this->licenseText = <<<EOD
/**
@AUTHORS@
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
EOD;
$this->licenseTextLegacy = <<<EOD
/**
@AUTHORS@
*
* @copyright Copyright (c) @YEAR@, ownCloud, Inc.
Expand All @@ -46,7 +67,7 @@ public function __construct() {
*
*/
EOD;
$this->licenseText = str_replace('@YEAR@', date("Y"), $this->licenseText);
$this->licenseTextLegacy = str_replace('@YEAR@', date("Y"), $this->licenseTextLegacy);
}

/**
Expand Down Expand Up @@ -118,10 +139,15 @@ function handleFile($path, $gitRoot) {
echo "MIT licensed file: $path" . PHP_EOL;
return;
}
$source = $this->eatOldLicense($source);
$authors = $this->getAuthors($path, $gitRoot);
$license = str_replace('@AUTHORS@', $authors, $this->licenseText);
if ($this->isOwnCloudLicensed($source)) {
$authors = $this->getAuthors($path, $gitRoot, true);
$license = str_replace('@AUTHORS@', $authors, $this->licenseTextLegacy);
} else {
$authors = $this->getAuthors($path, $gitRoot);
$license = str_replace('@AUTHORS@', $authors, $this->licenseText);
}

$source = $this->eatOldLicense($source);
$source = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
file_put_contents($path,$source);
echo "License updated: $path" . PHP_EOL;
Expand All @@ -143,6 +169,19 @@ 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) {
return true;
}
}

return false;
}

/**
* @param string $source
* @return string
Expand Down Expand Up @@ -177,7 +216,7 @@ private function eatOldLicense($source) {
return implode(PHP_EOL, $lines);
}

private function getAuthors($file, $gitRoot) {
private function getAuthors($file, $gitRoot, $legacyFiles = false) {
// 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();
Expand Down Expand Up @@ -205,10 +244,19 @@ private function getAuthors($file, $gitRoot) {
$authors = array_unique($authors);
}

$authors = array_map(function($author){
$this->authors[$author] = $author;
return " * @author $author";
}, $authors);
if ($legacyFiles) {
$authors = array_map(function($author){
$this->authors[$author] = $author;
return " * @author $author";
}, $authors);
} else {
$authors = array_map(function($author){
$this->authors[$author] = $author;
return " * @copyright Copyright (c) " . date("Y") . ", $author";
}, $authors);
}


return implode(PHP_EOL, $authors);
}

Expand Down