1717 */
1818package org .spdx .library ;
1919
20- import java .io .IOException ;
21- import java .io .InputStream ;
2220import java .util .*;
2321import java .util .concurrent .locks .ReadWriteLock ;
2422import java .util .concurrent .locks .ReentrantReadWriteLock ;
2523
2624import org .slf4j .Logger ;
2725import org .slf4j .LoggerFactory ;
26+ import org .spdx .Configuration ;
2827import org .spdx .core .InvalidSPDXAnalysisException ;
2928import org .spdx .library .model .v2 .SpdxConstantsCompatV2 ;
3029import org .spdx .library .model .v2 .SpdxModelFactoryCompatV2 ;
4948public class ListedLicenses {
5049
5150 static final Logger logger = LoggerFactory .getLogger (ListedLicenses .class .getName ());
52- private static final String PROPERTIES_DIR = "resources" ;
53- private static final String LISTED_LICENSE_PROPERTIES_FILENAME = PROPERTIES_DIR + "/" + "licenses.properties" ;
5451
5552 Properties licenseProperties ;
5653 boolean onlyUseLocalLicenses ;
@@ -72,46 +69,14 @@ public class ListedLicenses {
7269 * This constructor should only be called by the getListedLicenses method
7370 */
7471 private ListedLicenses () {
75- licenseProperties = loadLicenseProperties ();
76- onlyUseLocalLicenses = Boolean .parseBoolean (
77- System .getProperty ("SPDXParser.OnlyUseLocalLicenses" , licenseProperties .getProperty ("OnlyUseLocalLicenses" , "false" )));
72+ // Note: this code is confusing as this property changed names several times over time, and we want to preserve
73+ // backwards compatibility for those downstream library users who are using the old/deprecated names
74+ onlyUseLocalLicenses = Boolean .parseBoolean (Configuration .getInstance ().getProperty ("org.spdx.useJARLicenseInfoOnly" ,
75+ Configuration .getInstance ().getProperty ("SPDXParser.OnlyUseLocalLicenses" ,
76+ Configuration .getInstance ().getProperty ("OnlyUseLocalLicenses" , "false" ))));
7877 initializeLicenseModelStore ();
7978 }
8079
81- /**
82- * Tries to load properties from LISTED_LICENSE_PROPERTIES_FILENAME, ignoring errors
83- * encountered during the process (e.g., the properties file doesn't exist, etc.).
84- *
85- * @return a (possibly empty) set of properties
86- */
87- private static Properties loadLicenseProperties () {
88- listedLicenseModificationLock .writeLock ().lock ();
89- try {
90- Properties licenseProperties = new Properties ();
91- InputStream in = null ;
92- try {
93- in = ListedLicenses .class .getResourceAsStream ("/" + LISTED_LICENSE_PROPERTIES_FILENAME );
94- if (in != null ) {
95- licenseProperties .load (in );
96- }
97- } catch (IOException e ) {
98- // Ignore it and fall through
99- logger .warn ("IO Exception reading listed license properties file: {}" , e .getMessage ());
100- } finally {
101- if (in != null ) {
102- try {
103- in .close ();
104- } catch (IOException e ) {
105- logger .warn ("Unable to close listed license properties file: {}" , e .getMessage ());
106- }
107- }
108- }
109- return licenseProperties ;
110- } finally {
111- listedLicenseModificationLock .writeLock ().unlock ();
112- }
113- }
114-
11580 private void initializeLicenseModelStore () {
11681 listedLicenseModificationLock .writeLock ().lock ();
11782 try {
0 commit comments