Get all license information from the database.

Change-Id: Icca9120dc0d52c0a1c66e1e8128706b6ada566d4
Signed-off-by: Wayne Beaton <wayne.beaton@eclipse-foundation.org>
diff --git a/classes/License.class.inc b/classes/License.class.inc
index 65a8bf0..b7b2162 100644
--- a/classes/License.class.inc
+++ b/classes/License.class.inc
@@ -25,52 +25,22 @@
  }
 
  public static function getLicense($id) {
-  // FIXME This should be in the (a) database.
-  switch ($id) {
-   case 'EPL2.0':
-   case 'EPL-2.0':
-    return new License('EPL-2.0', 'Eclipse Public License v. 2.0', 'https://www.eclipse.org/legal/epl-2.0');
-   case 'EPL1.0':
-   case 'EPL-1.0':
-    return new License('EPL-1.0', 'Eclipse Public License v. 1.0', 'https://www.eclipse.org/legal/epl-v10.html');
-   case 'EDL1.0':
-   case 'EDL-1.0':
-   case 'EDL':
-    return new License('BSD-3-Clause', 'Eclipse Distribution License v. 1.0', 'https://www.eclipse.org/org/documents/edl-v10.php');
-   case 'ASL2.0':
-   case 'Apache-2.0':
-    return new License('Apache-2.0', 'Apache License, Version 2.0', 'https://www.apache.org/licenses/LICENSE-2.0');
-   case 'MIT':
-   	return new License('MIT', 'The MIT License', 'https://opensource.org/licenses/MIT');
-   case 'CCBY3':
-   case 'CC-BY-3.0':
-    return new License('CC-BY-3.0', 'Creative Commons Attribution 3.0 Unported', 'https://creativecommons.org/licenses/by/4.0/');
-   case 'W3C-20150513':
-    return new License('W3C-20150513', 'W3C Software Notice and Document License (2015-05-13)','https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document');
-   case 'OFL-1.1':
-   	return new License('OFL-1.1', 'SIL Open Font License 1.1', 'https://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web');
-   case 'SHL-2.0':
-   	return new License('Apache-2.0 WITH SHL-2.0', 'Solderpad Hardware Licence, Version 2.0', 'https://solderpad.org/licenses/SHL-2.0/');
+  $sql = "
+    select
+       l.LicenseID as id,
+       l.description as text,
+       l.SPDXCode as spdx,
+       l.Url as url,
+       l.IsPrimary as isPrimary
+    from SYS_Licenses as l
+    where l.LicenseId='$id' or l.SPDXCode='$id'";
 
-   // Secondary licenses. The fourth parameter for all of these is false, indicating that they are not primary licenses.
-   case 'GPL-2.0':
-    return new License('GPL-2.0', 'GNU General Public License, version 2', 'https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html', false);
-   case 'GPL-2.0+':
-   case 'GPL-2.0-or-later':
-   	return new License('GPL-2.0-or-later', 'GNU General Public License v2.0 or later', 'https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html', false);
-   case 'GPL-2.0_CP':
-   case 'GPL-2.0-with-classpath-exception':
-    return new License('GPL-2.0-with-classpath-exception', 'GNU General Public License v2.0 w/Classpath exception', 'https://www.gnu.org/software/classpath/license.html', false);
-   case 'GPL-2.0_AE':
-   case 'OpenJDK-assembly-exception-1.0':
-    return new License('GPL-2.0 WITH OpenJDK-assembly-exception-1.0', 'GNU General Public License, version 2 with OpenJDK Assembly Exception', 'https://openjdk.java.net/legal/assembly-exception.html', false);
-   case 'GPL-3.0':
-   case 'GPL-3.0-only':
-   	return new License('GPL-3.0-only', 'GNU General Public License v3.0 only', 'https://www.gnu.org/licenses/gpl-3.0-standalone.html', false);
+ 	$licenses = array ();
+ 	query ( 'foundation', $sql, array (), function ($row) use (&$licenses) {
+ 		$licenses [] = new License($row['spdx'], $row['text'], $row['url'], $row['isPrimary'] ? true : false);
+ 	} );
 
-   default:
-    return new License('UNKNOWN', 'A LICENSE THAT WE DON\'T SUPPORT YET', 'https://www.eclipse.org/legal/licenses.php');
-  }
+ 	return $licenses ? $licenses[0] : null;
  }
 
  public static function getLicenses($codes) {
@@ -91,14 +61,17 @@
   $sql = "
     select
        l.LicenseId as id,
-       l.description as text
+       l.description as text,
+       l.SPDXCode as spdx,
+       l.Url as url,
+       l.IsPrimary as isPrimary
     from ProjectLicenses as pl
       join SYS_Licenses as l on pl.LicenseId=l.LicenseId
     where pl.ProjectId='$id'";
 
   $licenses = array ();
   query ( 'foundation', $sql, array (), function ($row) use (&$licenses) {
-   $licenses [] = self::getLicense($row ['id']);
+   $licenses [] = new License($row['spdx'], $row['text'], $row['url'], $row['isPrimary'] ? true : false);
   } );
 
   self::sortLicenses($licenses);
diff --git a/tools/legal/header.php b/tools/legal/header.php
index 220126f..58aade4 100644
--- a/tools/legal/header.php
+++ b/tools/legal/header.php
@@ -29,4 +29,8 @@
  }
 }
 
-echo getDefaultFileHeader($licenses, $width);
\ No newline at end of file
+if (!$licenses) {
+	echo "No licenses specified or available.";
+} else {
+	echo getDefaultFileHeader($licenses, $width);
+}
\ No newline at end of file