Skip to content

Commit 5c35064

Browse files
committed
Bring back config code updates
These changes were made to the SPDX 1.X version of the library and were not properly merged into the 2.X version. Fixes #324
1 parent a7c8876 commit 5c35064

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

src/main/java/org/spdx/library/ListedLicenses.java

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
*/
1818
package org.spdx.library;
1919

20-
import java.io.IOException;
21-
import java.io.InputStream;
2220
import java.util.*;
2321
import java.util.concurrent.locks.ReadWriteLock;
2422
import java.util.concurrent.locks.ReentrantReadWriteLock;
2523

2624
import org.slf4j.Logger;
2725
import org.slf4j.LoggerFactory;
26+
import org.spdx.Configuration;
2827
import org.spdx.core.InvalidSPDXAnalysisException;
2928
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
3029
import org.spdx.library.model.v2.SpdxModelFactoryCompatV2;
@@ -49,8 +48,6 @@
4948
public 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

Comments
 (0)