From f857da7c295bad9146e1705ba4eb325e7cb2039a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 5 Feb 2018 10:34:41 +0100 Subject: [PATCH] Remove deprecated license check from ValidatingArrayLoader, fixes #7026, fixes #7073 --- .../Package/Loader/ValidatingArrayLoader.php | 22 ------------- src/Composer/Util/ConfigValidator.php | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index b228460d8..4ee444f02 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -126,28 +126,6 @@ class ValidatingArrayLoader implements LoaderInterface 'If the software is closed-source, you may use "proprietary" as license.', json_encode($this->config['license']) ); - } else if (!$releaseDate || $releaseDate->format('Y-m-d H:i:s') >= '2018-01-20 00:00:00') { // only warn for deprecations for releases/branches that follow the introduction of deprecated licenses - foreach ($licenses as $license) { - $spdxLicense = $licenseValidator->getLicenseByIdentifier($license); - if ($spdxLicense && $spdxLicense[3]) { - if (preg_match('{^[AL]?GPL-[123](\.[01])?\+$}i', $license)) { - $this->warnings[] = sprintf( - 'License "%s" is a deprecated SPDX license identifier, use "'.str_replace('+', '', $license).'-or-later" instead', - $license - ); - } elseif (preg_match('{^[AL]?GPL-[123](\.[01])?$}i', $license)) { - $this->warnings[] = sprintf( - 'License "%s" is a deprecated SPDX license identifier, use "'.$license.'-only" or "'.$license.'-or-later" instead', - $license - ); - } else { - $this->warnings[] = sprintf( - 'License "%s" is a deprecated SPDX license identifier, see https://spdx.org/licenses/', - $license - ); - } - } - } } } } diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index e5f64ec23..c5f762f92 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -18,6 +18,7 @@ use Composer\Package\Loader\InvalidPackageException; use Composer\Json\JsonValidationException; use Composer\IO\IOInterface; use Composer\Json\JsonFile; +use Composer\Spdx\SpdxLicenses; /** * Validates a composer configuration. @@ -74,6 +75,38 @@ class ConfigValidator // validate actual data if (empty($manifest['license'])) { $warnings[] = 'No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.'; + } else { + $licenses = (array) $manifest['license']; + + // strip proprietary since it's not a valid SPDX identifier, but is accepted by composer + foreach ($licenses as $key => $license) { + if ('proprietary' === $license) { + unset($licenses[$key]); + } + } + + $licenseValidator = new SpdxLicenses(); + foreach ($licenses as $license) { + $spdxLicense = $licenseValidator->getLicenseByIdentifier($license); + if ($spdxLicense && $spdxLicense[3]) { + if (preg_match('{^[AL]?GPL-[123](\.[01])?\+$}i', $license)) { + $warnings[] = sprintf( + 'License "%s" is a deprecated SPDX license identifier, use "'.str_replace('+', '', $license).'-or-later" instead', + $license + ); + } elseif (preg_match('{^[AL]?GPL-[123](\.[01])?$}i', $license)) { + $warnings[] = sprintf( + 'License "%s" is a deprecated SPDX license identifier, use "'.$license.'-only" or "'.$license.'-or-later" instead', + $license + ); + } else { + $warnings[] = sprintf( + 'License "%s" is a deprecated SPDX license identifier, see https://spdx.org/licenses/', + $license + ); + } + } + } } if (isset($manifest['version'])) {