Skip to content

Commit

Permalink
Merge pull request #2 from spdx/fixbugs
Browse files Browse the repository at this point in the history
Fixbugs
  • Loading branch information
goneall authored Sep 2, 2024
2 parents 9216a37 + 5fb79f8 commit 665b65d
Show file tree
Hide file tree
Showing 31 changed files with 77 additions and 851 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/spdx/core/CoreModelObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.spdx.storage.IModelStore.ModelUpdate;

/**
* @author Gary O'Neall
*
* Superclass for all SPDX model objects
*
Expand Down Expand Up @@ -70,12 +69,16 @@
*
* This class also handles the conversion of a CoreModelObject to and from a TypeValue for storage in the ModelStore.
*
* @author Gary O'Neall
*
*/
public abstract class CoreModelObject {

static final Logger logger = LoggerFactory.getLogger(CoreModelObject.class);

static final String PROPERTY_MSG = "Property ";

private static final String ATTEMPTING_EXTERNAL_MSG = "Attempting to set {0} for an external model object";
protected IModelStore modelStore;
protected String objectUri;
protected String specVersion;
Expand Down Expand Up @@ -340,7 +343,7 @@ public void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Ob
throw new InvalidSPDXAnalysisException("Can not set a property for the literal value "+((IndividualUriValue)this).getIndividualURI());
}
if (isExternal()) {
logger.warn("Attempting to set "+propertyDescriptor+" for an external model object");
logger.warn(ATTEMPTING_EXTERNAL_MSG, propertyDescriptor);
return;
}
ModelObjectHelper.setPropertyValue(this.modelStore, objectUri, propertyDescriptor, value,
Expand Down Expand Up @@ -461,7 +464,7 @@ public Optional<Boolean> getBooleanPropertyValue(PropertyDescriptor propertyDesc
*/
public void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
if (isExternal()) {
logger.warn("Attempting to set "+propertyDescriptor+" for an external model object");
logger.warn(ATTEMPTING_EXTERNAL_MSG, propertyDescriptor);
return;
}
ModelObjectHelper.removeProperty(modelStore, objectUri, propertyDescriptor);
Expand All @@ -484,7 +487,7 @@ public ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor) {
*/
public void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException {
if (isExternal()) {
logger.warn("Attempting to set "+propertyDescriptor+" for an external model object");
logger.warn(ATTEMPTING_EXTERNAL_MSG, propertyDescriptor);
return;
}
ModelObjectHelper.clearValueCollection(modelStore, objectUri, propertyDescriptor);
Expand All @@ -510,7 +513,7 @@ public ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescrip
*/
public void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException {
if (isExternal()) {
logger.warn("Attempting to set "+propertyDescriptor+" for an external model object");
logger.warn(ATTEMPTING_EXTERNAL_MSG, propertyDescriptor);
return;
}
ModelObjectHelper.addValueToCollection(modelStore, objectUri, propertyDescriptor, value,
Expand Down Expand Up @@ -539,7 +542,7 @@ public ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propert
*/
public void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException {
if (isExternal()) {
logger.warn("Attempting to set "+propertyDescriptor+" for an external model object");
logger.warn(ATTEMPTING_EXTERNAL_MSG, propertyDescriptor);
return;
}
ModelObjectHelper.removePropertyValueFromCollection(modelStore, objectUri, propertyDescriptor, value);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/DefaultModelStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.spdx.storage.IModelStore;

/**
* @author Gary O'Neall
*
* Singleton class to hold a default model store used when no model store is provided
*
* WARNING: The model store is in memory and will continue to grow as it is utilized. There is NO garbage collection.
*
* @author Gary O'Neall
*
*/
public class DefaultModelStore {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/DefaultStoreNotInitialized.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Exception where the default store is used before it has been initialized
*
* @author Gary O'Neall
*
*/
public class DefaultStoreNotInitialized extends InvalidSPDXAnalysisException {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/spdx/core/DuplicateSpdxIdException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
package org.spdx.core;

/**
* @author gary
*
* Exception for duplicate SPDX ID creations
*
* @author Gary O'Neall
*/
public class DuplicateSpdxIdException extends InvalidSPDXAnalysisException {

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/spdx/core/IExternalElementInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Information about an Element which is external to the collection or store
*
* The information stored is version dependent and implemented in the models
*
*
* @author Gary O'Neall
*/
public interface IExternalElementInfo {

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/spdx/core/IModelCopyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
import org.spdx.storage.IModelStore;

/**
* @author Gary O'Neall
*
* Implementation classes of this interface helps facilitate copying objects from one model to another.
*
* In addition to the copy functions (methods), these objects keeps track of
* what was copied where so that the same object is not copied twice.
*
* These objects can be passed into the constructor for ModelObjects to allow the objects to be copied.
*
*
* @author Gary O'Neall
*/
public interface IModelCopyManager {

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/spdx/core/ISpdxModelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import org.spdx.storage.IModelStore;

/**
* @author Gary O'Neall
*
* Interface for SPDX model information
*
*
* @author Gary O'Neall
*/
public interface ISpdxModelInfo {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/InvalidSPDXAnalysisException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Exception for invalid SPDX Documents
*
* @author Gary O'Neall
*
*/
public class InvalidSPDXAnalysisException extends Exception {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/InvalidSpdxPropertyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Invalid property name or value for an SPDX item
*
* @author Gary O'Neall
*
*/
public class InvalidSpdxPropertyException extends InvalidSPDXAnalysisException {
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/spdx/core/ModelCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public class ModelCollection<T extends Object> implements Collection<Object> {
*/
protected Map<String, IExternalElementInfo> externalMap;
private Class<?> type;
//TODO: See if this boolean is needed before deleting the comments
// private boolean licensePrimitiveAssignable; // If true, NONE and NOASSERTION should be converted to NoneLicense and NoAssertionLicense


/**
* @author Gary O'Neall
*
Expand Down Expand Up @@ -111,13 +109,9 @@ public ModelCollection(IModelStore modelStore, String objectUri, PropertyDescrip
}
if (Objects.nonNull(type)) {
this.type = type;
// TODO: make sure the following commented logic is not needed
// licensePrimitiveAssignable = type.isAssignableFrom(SpdxNoneLicense.class) || type.isAssignableFrom(SpdxNoAssertionLicense.class);
if (!modelStore.isCollectionMembersAssignableTo(objectUri, propertyDescriptor, type)) {
throw new SpdxInvalidTypeException("Incompatible type for property "+propertyDescriptor+": "+type.toString());
}
// } else {
// licensePrimitiveAssignable = false;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/spdx/core/ModelRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import org.spdx.storage.IModelStore;

/**
* @author Gary O'Neall
*
* Singleton class which contains a registry of SPDX model versions
*
* Each model version implements a model interface <code>ISpdxModelInfo</code> which
* supports inflating an SPDX type specific to that version
* s
*
* @author Gary O'Neall
*/
public class ModelRegistry {

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/spdx/core/ModelRegistryException.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package org.spdx.core;

/**
* @author gary
* Exceptions related to a model registry
*
* @author Gary O'Neall
*/
public class ModelRegistryException extends InvalidSPDXAnalysisException {

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/spdx/core/NotEquivalentReason.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import org.spdx.storage.PropertyDescriptor;

/**
* @author Gary O'Neall
*
* Primarily used for debugging. Records details when two model objects are compared and are determined to not
* be equivalent
*
*
* @author Gary O'Neall
*/
public class NotEquivalentReason {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spdx/core/SimpleUriValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Object toModelObject(IModelStore store, IModelCopyManager copyManager,
} else {
retval = ModelRegistry.getModelRegistry().getExternalElement(store, uri, copyManager, type, specVersion);
if (Objects.isNull(retval)) {
logger.warn(this.getIndividualURI() + " does not match an enum, individual, or external pattern");
logger.warn("{0} does not match an enum, individual, or external pattern", this.getIndividualURI());
retval = this;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/spdx/core/SpdxCoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Common constants used in the SPDX core library
*
* @author Gary O'Neall
*/
public class SpdxCoreConstants {

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/spdx/core/SpdxIdInUseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Exception when an SPDX element is in use (e.g. exception thrown when attempting to delete)
*
* @author Gary O'Neall
*
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/SpdxIdNotFoundException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Exception for no SPDX identifier found
*
* @author Gary O'Neall
*
*/
public class SpdxIdNotFoundException extends InvalidSPDXAnalysisException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/SpdxInvalidIdException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
* Invalid SPDX identifier
*
* Ivalid SPDX identifier
* @author Gary O'Neall
*
*/
public class SpdxInvalidIdException extends InvalidSPDXAnalysisException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/core/SpdxInvalidTypeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.spdx.core;

/**
* @author Gary O'Neall
*
* Invalid type for an SPDX property
*
* @author Gary O'Neall
*
*/
public class SpdxInvalidTypeException extends InvalidSPDXAnalysisException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/**
* Exception when an SDPX ID or object was not found in a model store
*
* @author Gary O'Neall
*
*/
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/spdx/core/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Copyright (c) 2024 Source Auditor Inc.
*/
/**
* @author Gary O'Neall
*
* Common classes used by the SPDX model and library
*
* @author Gary O'Neall
*/
package org.spdx.core;
24 changes: 10 additions & 14 deletions src/main/java/org/spdx/licenseTemplate/LicenseTextHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.util.regex.Pattern;

/**
* @author Gary O'Neall
*
* Static helper class for comparing license text
*
* @author Gary O'Neall
*
*/
public class LicenseTextHelper {
Expand Down Expand Up @@ -101,7 +101,7 @@ public class LicenseTextHelper {

private LicenseTextHelper() {
// static class
};
}

/**
* Returns true if two sets of license text is considered a match per
Expand Down Expand Up @@ -271,11 +271,7 @@ public static boolean canSkip(String token) {
*/
public static boolean tokensEquivalent(String tokenA, String tokenB) {
if (tokenA == null) {
if (tokenB == null) {
return true;
} else {
return false;
}
return tokenB == null;
} else if (tokenB == null) {
return false;
} else {
Expand Down Expand Up @@ -349,12 +345,12 @@ public static String replaceMultWord(String s) {
public static String normalizeText(String s) {
// First normalize single quotes, then normalize two single quotes to a double quote, normalize double quotes
// then normalize non-breaking spaces to spaces
return s.replaceAll("‘|’|‛|‚|`", "'") // Take care of single quotes first
.replaceAll("http://", "https://") // Normalize the http protocol scheme
.replaceAll("''","\"") // This way, we can change doulbe single quotes to a single double cquote
.replaceAll("“|”|‟|„", "\"") // Now we can normalize the double quotes
return s.replaceAll("[‘’‛‚`]", "'") // Take care of single quotes first
.replace("http://", "https://") // Normalize the http protocol scheme
.replace("''","\"") // This way, we can change doulbe single quotes to a single double cquote
.replaceAll("[“”‟„]", "\"") // Now we can normalize the double quotes
.replaceAll("\\u00A0", " ") // replace non-breaking spaces with spaces since Java does not handle the former well
.replaceAll("—|–","-") // replace em dash, en dash with simple dash
.replaceAll("[—–]","-") // replace em dash, en dash with simple dash
.replaceAll("\\u2028", "\n"); // replace line separator with newline since Java does not handle the former well
}

Expand All @@ -363,6 +359,6 @@ public static String normalizeText(String s) {
* @return s without any line separators (---, ***, ===)
*/
public static String removeLineSeparators(String s) {
return s.replaceAll("(-|=|\\*){3,}\\s*$", ""); // Remove ----, ***, and ====
return s.replaceAll("[-=*]{3,}\\s*$", ""); // Remove ----, ***, and ====
}
}
Loading

0 comments on commit 665b65d

Please sign in to comment.