Browse Source

Allow for "proprietary" as license identifier

Jordi Boggiano 12 years ago
parent
commit
e43d0b5a5b
2 changed files with 15 additions and 3 deletions
  1. 2 0
      doc/04-schema.md
  2. 13 3
      src/Composer/Util/ConfigValidator.php

+ 2 - 0
doc/04-schema.md

@@ -150,6 +150,8 @@ The recommended notation for the most common licenses is (alphabetical):
 Optional, but it is highly recommended to supply this. More identifiers are
 listed at the [SPDX Open Source License Registry](http://www.spdx.org/licenses/).
 
+For closed-source software, you may use `"proprietary"` as the license identifier.
+
 An Example:
 
     {

+ 13 - 3
src/Composer/Util/ConfigValidator.php

@@ -74,15 +74,25 @@ class ConfigValidator
 
         // validate actual data
         if (!empty($manifest['license'])) {
+            // strip proprietary since it's not a valid SPDX identifier, but is accepted by composer
+            if (is_array($manifest['license'])) {
+                foreach ($manifest['license'] as $key => $license) {
+                    if ('proprietary' === $license) {
+                        unset($manifest['license'][$key]);
+                    }
+                }
+            }
+
             $licenseValidator = new SpdxLicenseIdentifier();
-            if (!$licenseValidator->validate($manifest['license'])) {
+            if ('proprietary' !== $manifest['license'] && array() !== $manifest['license'] && !$licenseValidator->validate($manifest['license'])) {
                 $warnings[] = sprintf(
-                    'License %s is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if you use an open license',
+                    'License %s is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if you use an open license.'
+                    ."\nIf the software is closed-source, you may use \"proprietary\" as license.",
                     json_encode($manifest['license'])
                 );
             }
         } else {
-            $warnings[] = 'No license specified, it is recommended to do so';
+            $warnings[] = 'No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.';
         }
 
         if (!empty($manifest['name']) && preg_match('{[A-Z]}', $manifest['name'])) {