@@ -27,6 +27,27 @@ class Licenses
2727 public function __construct () {
2828 $ this ->licenseText = <<<EOD
2929/**
30+ @AUTHORS@
31+ *
32+ * @license GNU AGPL version 3 or any later version
33+ *
34+ * This program is free software: you can redistribute it and/or modify
35+ * it under the terms of the GNU Affero General Public License as
36+ * published by the Free Software Foundation, either version 3 of the
37+ * License, or (at your option) any later version.
38+ *
39+ * This program is distributed in the hope that it will be useful,
40+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
41+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42+ * GNU Affero General Public License for more details.
43+ *
44+ * You should have received a copy of the GNU Affero General Public License
45+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
46+ *
47+ */
48+ EOD ;
49+ $ this ->licenseTextLegacy = <<<EOD
50+ /**
3051@AUTHORS@
3152 *
3253 * @copyright Copyright (c) @YEAR@, ownCloud, Inc.
@@ -46,7 +67,7 @@ public function __construct() {
4667 *
4768 */
4869EOD ;
49- $ this ->licenseText = str_replace ('@YEAR@ ' , date ("Y " ), $ this ->licenseText );
70+ $ this ->licenseTextLegacy = str_replace ('@YEAR@ ' , date ("Y " ), $ this ->licenseTextLegacy );
5071 }
5172
5273 /**
@@ -118,10 +139,15 @@ function handleFile($path, $gitRoot) {
118139 echo "MIT licensed file: $ path " . PHP_EOL ;
119140 return ;
120141 }
121- $ source = $ this ->eatOldLicense ($ source );
122- $ authors = $ this ->getAuthors ($ path , $ gitRoot );
123- $ license = str_replace ('@AUTHORS@ ' , $ authors , $ this ->licenseText );
142+ if ($ this ->isOwnCloudLicensed ($ source )) {
143+ $ authors = $ this ->getAuthors ($ path , $ gitRoot , true );
144+ $ license = str_replace ('@AUTHORS@ ' , $ authors , $ this ->licenseTextLegacy );
145+ } else {
146+ $ authors = $ this ->getAuthors ($ path , $ gitRoot );
147+ $ license = str_replace ('@AUTHORS@ ' , $ authors , $ this ->licenseText );
148+ }
124149
150+ $ source = $ this ->eatOldLicense ($ source );
125151 $ source = "<?php " . PHP_EOL . $ license . PHP_EOL . $ source ;
126152 file_put_contents ($ path ,$ source );
127153 echo "License updated: $ path " . PHP_EOL ;
@@ -143,6 +169,19 @@ private function isMITLicensed($source) {
143169 return false ;
144170 }
145171
172+ private function isOwnCloudLicensed ($ source ) {
173+ $ lines = explode (PHP_EOL , $ source );
174+ while (!empty ($ lines )) {
175+ $ line = $ lines [0 ];
176+ array_shift ($ lines );
177+ if (strpos ($ line , 'ownCloud, Inc ' ) !== false ) {
178+ return true ;
179+ }
180+ }
181+
182+ return false ;
183+ }
184+
146185 /**
147186 * @param string $source
148187 * @return string
@@ -177,7 +216,7 @@ private function eatOldLicense($source) {
177216 return implode (PHP_EOL , $ lines );
178217 }
179218
180- private function getAuthors ($ file , $ gitRoot ) {
219+ private function getAuthors ($ file , $ gitRoot, $ legacyFiles = false ) {
181220 // only add authors that changed code and not the license header
182221 $ licenseHeaderEndsAtLine = trim (shell_exec ("grep -n '*/' $ file | head -n 1 | cut -d ':' -f 1 " ));
183222 $ buildDir = getcwd ();
@@ -205,10 +244,19 @@ private function getAuthors($file, $gitRoot) {
205244 $ authors = array_unique ($ authors );
206245 }
207246
208- $ authors = array_map (function ($ author ){
209- $ this ->authors [$ author ] = $ author ;
210- return " * @author $ author " ;
211- }, $ authors );
247+ if ($ legacyFiles ) {
248+ $ authors = array_map (function ($ author ){
249+ $ this ->authors [$ author ] = $ author ;
250+ return " * @author $ author " ;
251+ }, $ authors );
252+ } else {
253+ $ authors = array_map (function ($ author ){
254+ $ this ->authors [$ author ] = $ author ;
255+ return " * @copyright Copyright (c) " . date ("Y " ) . ", $ author " ;
256+ }, $ authors );
257+ }
258+
259+
212260 return implode (PHP_EOL , $ authors );
213261 }
214262
0 commit comments