Skip to content

Bring back config code updates #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README-V3-UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Notes:
- Step #1 is optional; if not provided, a default ModelStore and CopyManager will be automatically created and configured by `SpdxModelFactory.init()`.
- Once initialized (via Step #2), further calls to `DefaultModelStore.initialize(...)` will be ignored.

## Deprecated configuration for using online licenses from Jar file removed

The configuration properties `OnlyUseLocalLicenses` and `SPDXParser.OnlyUseLocalLicenses` will no longer force the
library to use the licenses distributed with the Jar file. The supported property `org.spdx.useJARLicenseInfoOnly` should be used.

## Classes and Methods moved to SPDX Java Core library

The SPDX Java Core Library is in a separate repository and jar file.
Expand Down
44 changes: 3 additions & 41 deletions src/main/java/org/spdx/library/ListedLicenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
*/
package org.spdx.library;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spdx.Configuration;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.SpdxConstantsCompatV2;
import org.spdx.library.model.v2.SpdxModelFactoryCompatV2;
Expand All @@ -49,8 +48,6 @@
public class ListedLicenses {

static final Logger logger = LoggerFactory.getLogger(ListedLicenses.class.getName());
private static final String PROPERTIES_DIR = "resources";
private static final String LISTED_LICENSE_PROPERTIES_FILENAME = PROPERTIES_DIR + "/" + "licenses.properties";

Properties licenseProperties;
boolean onlyUseLocalLicenses;
Expand All @@ -72,46 +69,11 @@ public class ListedLicenses {
* This constructor should only be called by the getListedLicenses method
*/
private ListedLicenses() {
licenseProperties = loadLicenseProperties();
onlyUseLocalLicenses = Boolean.parseBoolean(
System.getProperty("SPDXParser.OnlyUseLocalLicenses", licenseProperties.getProperty("OnlyUseLocalLicenses", "false")));
onlyUseLocalLicenses = Boolean.parseBoolean(Configuration.getInstance().getProperty("org.spdx.useJARLicenseInfoOnly",
"false"));
initializeLicenseModelStore();
}

/**
* Tries to load properties from LISTED_LICENSE_PROPERTIES_FILENAME, ignoring errors
* encountered during the process (e.g., the properties file doesn't exist, etc.).
*
* @return a (possibly empty) set of properties
*/
private static Properties loadLicenseProperties() {
listedLicenseModificationLock.writeLock().lock();
try {
Properties licenseProperties = new Properties();
InputStream in = null;
try {
in = ListedLicenses.class.getResourceAsStream("/" + LISTED_LICENSE_PROPERTIES_FILENAME);
if (in != null) {
licenseProperties.load(in);
}
} catch (IOException e) {
// Ignore it and fall through
logger.warn("IO Exception reading listed license properties file: {}", e.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.warn("Unable to close listed license properties file: {}", e.getMessage());
}
}
}
return licenseProperties;
} finally {
listedLicenseModificationLock.writeLock().unlock();
}
}

private void initializeLicenseModelStore() {
listedLicenseModificationLock.writeLock().lock();
try {
Expand Down