- keep copyright notice and only update the authors list
- check if all changes to a file happened after the fork, this allows the authors to check if the file can be relicensed to AGPLv3 or later
This commit is contained in:
parent
4c19a0099d
commit
762d76f0c3
1 changed files with 81 additions and 18 deletions
|
@ -22,11 +22,14 @@ class Licenses
|
||||||
{
|
{
|
||||||
protected $paths = [];
|
protected $paths = [];
|
||||||
protected $mailMap = [];
|
protected $mailMap = [];
|
||||||
|
protected $checkFiles = [];
|
||||||
public $authors = [];
|
public $authors = [];
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->licenseText = <<<EOD
|
$this->licenseText = <<<EOD
|
||||||
/**
|
/**
|
||||||
|
@COPYRIGHT@
|
||||||
|
*
|
||||||
@AUTHORS@
|
@AUTHORS@
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
@ -48,9 +51,10 @@ class Licenses
|
||||||
EOD;
|
EOD;
|
||||||
$this->licenseTextLegacy = <<<EOD
|
$this->licenseTextLegacy = <<<EOD
|
||||||
/**
|
/**
|
||||||
|
@COPYRIGHT@
|
||||||
|
*
|
||||||
@AUTHORS@
|
@AUTHORS@
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) @YEAR@, ownCloud, Inc.
|
|
||||||
* @license AGPL-3.0
|
* @license AGPL-3.0
|
||||||
*
|
*
|
||||||
* This code is free software: you can redistribute it and/or modify
|
* This code is free software: you can redistribute it and/or modify
|
||||||
|
@ -89,6 +93,7 @@ EOD;
|
||||||
|
|
||||||
if (is_file($folder)) {
|
if (is_file($folder)) {
|
||||||
$this->handleFile($folder, $gitRoot);
|
$this->handleFile($folder, $gitRoot);
|
||||||
|
$this->printFilesToCheck();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +118,8 @@ EOD;
|
||||||
/** @var SplFileInfo $file */
|
/** @var SplFileInfo $file */
|
||||||
$this->handleFile($file, $gitRoot);
|
$this->handleFile($file, $gitRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->printFilesToCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeAuthorsFile() {
|
function writeAuthorsFile() {
|
||||||
|
@ -139,13 +146,15 @@ With help from many libraries and frameworks including:
|
||||||
echo "MIT licensed file: $path" . PHP_EOL;
|
echo "MIT licensed file: $path" . PHP_EOL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$copyrightNotices = $this->getCopyrightNotices($path, $source);
|
||||||
|
$authors = $this->getAuthors($path, $gitRoot);
|
||||||
if ($this->isOwnCloudLicensed($source)) {
|
if ($this->isOwnCloudLicensed($source)) {
|
||||||
$authors = $this->getAuthors($path, $gitRoot, true);
|
|
||||||
$license = str_replace('@AUTHORS@', $authors, $this->licenseTextLegacy);
|
$license = str_replace('@AUTHORS@', $authors, $this->licenseTextLegacy);
|
||||||
|
$this->checkCopyrightState($path, $gitRoot);
|
||||||
} else {
|
} else {
|
||||||
$authors = $this->getAuthors($path, $gitRoot);
|
|
||||||
$license = str_replace('@AUTHORS@', $authors, $this->licenseText);
|
$license = str_replace('@AUTHORS@', $authors, $this->licenseText);
|
||||||
}
|
}
|
||||||
|
$license = str_replace('@COPYRIGHT@', $copyrightNotices, $license);
|
||||||
|
|
||||||
$source = $this->eatOldLicense($source);
|
$source = $this->eatOldLicense($source);
|
||||||
$source = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
|
$source = "<?php" . PHP_EOL . $license . PHP_EOL . $source;
|
||||||
|
@ -155,6 +164,7 @@ With help from many libraries and frameworks including:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $source
|
* @param string $source
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isMITLicensed($source) {
|
private function isMITLicensed($source) {
|
||||||
$lines = explode(PHP_EOL, $source);
|
$lines = explode(PHP_EOL, $source);
|
||||||
|
@ -181,7 +191,7 @@ With help from many libraries and frameworks including:
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -216,7 +226,68 @@ With help from many libraries and frameworks including:
|
||||||
return implode(PHP_EOL, $lines);
|
return implode(PHP_EOL, $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAuthors($file, $gitRoot, $legacyFiles = false) {
|
private function getCopyrightNotices($path, $file) {
|
||||||
|
$licenseHeaderEndsAtLine = (int)trim(shell_exec("grep -n '*/' $path | head -n 1 | cut -d ':' -f 1"));
|
||||||
|
$lineByLine = explode(PHP_EOL, $file, $licenseHeaderEndsAtLine);
|
||||||
|
$copyrightNotice = [];
|
||||||
|
foreach ($lineByLine as $line) {
|
||||||
|
if (strpos($line, '@copyright') !== false) {
|
||||||
|
$copyrightNotice[] = $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(PHP_EOL, $copyrightNotice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if all lines where changed after the Nextcloud fork.
|
||||||
|
* That's not a guarantee that we can switch to AGPLv3 or later,
|
||||||
|
* but a good indicator that we should have a look at the file
|
||||||
|
*
|
||||||
|
* @param $path
|
||||||
|
* @param $gitRoot
|
||||||
|
*/
|
||||||
|
private function checkCopyrightState($path, $gitRoot) {
|
||||||
|
// This was the date the Nextcloud fork was created
|
||||||
|
$deadline = new DateTime('06/06/2016');
|
||||||
|
$deadlineTimestamp = $deadline->getTimestamp();
|
||||||
|
|
||||||
|
$buildDir = getcwd();
|
||||||
|
if ($gitRoot) {
|
||||||
|
chdir($gitRoot);
|
||||||
|
$path = substr($path, strlen($gitRoot));
|
||||||
|
}
|
||||||
|
$out = shell_exec("git --no-pager blame --line-porcelain $path | sed -n 's/^author-time //p'");
|
||||||
|
if ($gitRoot) {
|
||||||
|
chdir($buildDir);
|
||||||
|
}
|
||||||
|
$timestampChanges = explode(PHP_EOL, $out);
|
||||||
|
$timestampChanges = array_slice($timestampChanges, 0, count($timestampChanges)-1);
|
||||||
|
foreach ($timestampChanges as $timestamp) {
|
||||||
|
if ((int)$timestamp < $deadlineTimestamp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//all changes after the deadline
|
||||||
|
$this->checkFiles[] = $path;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function printFilesToCheck() {
|
||||||
|
if (!empty($this->checkFiles)) {
|
||||||
|
print "\n";
|
||||||
|
print "For following files all lines changes since the Nextcloud fork." . PHP_EOL;
|
||||||
|
print "Please check if these files can be moved over to AGPLv3 or later" . PHP_EOL;
|
||||||
|
print "\n";
|
||||||
|
foreach ($this->checkFiles as $file) {
|
||||||
|
print $file . PHP_EOL;
|
||||||
|
}
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getAuthors($file, $gitRoot) {
|
||||||
// only add authors that changed code and not the license header
|
// 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"));
|
$licenseHeaderEndsAtLine = trim(shell_exec("grep -n '*/' $file | head -n 1 | cut -d ':' -f 1"));
|
||||||
$buildDir = getcwd();
|
$buildDir = getcwd();
|
||||||
|
@ -244,19 +315,11 @@ With help from many libraries and frameworks including:
|
||||||
$authors = array_unique($authors);
|
$authors = array_unique($authors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($legacyFiles) {
|
$authors = array_map(function($author){
|
||||||
$authors = array_map(function($author){
|
$this->authors[$author] = $author;
|
||||||
$this->authors[$author] = $author;
|
return " * @author $author";
|
||||||
return " * @author $author";
|
}, $authors);
|
||||||
}, $authors);
|
|
||||||
} else {
|
|
||||||
$authors = array_map(function($author){
|
|
||||||
$this->authors[$author] = $author;
|
|
||||||
return " * @copyright Copyright (c) " . date("Y") . ", $author";
|
|
||||||
}, $authors);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return implode(PHP_EOL, $authors);
|
return implode(PHP_EOL, $authors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue