diff --git a/src/main/java/org/spdx/core/CoreModelObject.java b/src/main/java/org/spdx/core/CoreModelObject.java index b25bbc4..e36a0df 100644 --- a/src/main/java/org/spdx/core/CoreModelObject.java +++ b/src/main/java/org/spdx/core/CoreModelObject.java @@ -77,6 +77,8 @@ 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; @@ -341,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, @@ -462,7 +464,7 @@ public Optional 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); @@ -485,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); @@ -511,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, @@ -540,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); diff --git a/src/main/java/org/spdx/core/ModelCollection.java b/src/main/java/org/spdx/core/ModelCollection.java index 48f8559..66387a3 100644 --- a/src/main/java/org/spdx/core/ModelCollection.java +++ b/src/main/java/org/spdx/core/ModelCollection.java @@ -54,9 +54,7 @@ public class ModelCollection implements Collection { */ protected Map 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 * @@ -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; } } diff --git a/src/main/java/org/spdx/core/SimpleUriValue.java b/src/main/java/org/spdx/core/SimpleUriValue.java index 561de77..1bfbcf3 100644 --- a/src/main/java/org/spdx/core/SimpleUriValue.java +++ b/src/main/java/org/spdx/core/SimpleUriValue.java @@ -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; } } diff --git a/src/main/java/org/spdx/licenseTemplate/LicenseTextHelper.java b/src/main/java/org/spdx/licenseTemplate/LicenseTextHelper.java index 2a0aee4..ca25971 100644 --- a/src/main/java/org/spdx/licenseTemplate/LicenseTextHelper.java +++ b/src/main/java/org/spdx/licenseTemplate/LicenseTextHelper.java @@ -101,7 +101,7 @@ public class LicenseTextHelper { private LicenseTextHelper() { // static class - }; + } /** * Returns true if two sets of license text is considered a match per @@ -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 { @@ -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 } @@ -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 ==== } } diff --git a/src/main/java/org/spdx/storage/CompatibleModelStoreWrapper.java b/src/main/java/org/spdx/storage/CompatibleModelStoreWrapper.java index c9beca7..3fa7019 100644 --- a/src/main/java/org/spdx/storage/CompatibleModelStoreWrapper.java +++ b/src/main/java/org/spdx/storage/CompatibleModelStoreWrapper.java @@ -253,7 +253,7 @@ public List getPropertyValueDescriptors( * @return all property names stored for the Object URI * @throws InvalidSPDXAnalysisException on any SPDX exception */ - public Collection getPropertyValueNames( + public Collection getPropertyValueNames( String objectUri) throws InvalidSPDXAnalysisException { return StreamSupport.stream(getPropertyValueDescriptors(objectUri).spliterator(), false) .map(descriptor -> descriptor.getName()) @@ -266,7 +266,7 @@ public Collection getPropertyValueNames( * @return all property names stored for the documentUri#id * @throws InvalidSPDXAnalysisException on any SPDX exception */ - public Collection getPropertyValueNames( + public Collection getPropertyValueNames( String documentUri, String id) throws InvalidSPDXAnalysisException { return getPropertyValueNames(documentUriIdToUri(documentUri, id, baseStore)); } @@ -575,7 +575,7 @@ public IModelStore getBaseModelStore() { @Override public boolean equals(Object comp) { return comp instanceof CompatibleModelStoreWrapper && getBaseModelStore().equals(((CompatibleModelStoreWrapper)comp).getBaseModelStore()); - // TODO: Return true if the base is equal since this contains no properties + // Return true if the base is equal since this contains no properties } @Override diff --git a/src/main/java/org/spdx/storage/NullModelStore.java b/src/main/java/org/spdx/storage/NullModelStore.java index 8979d44..6fff00c 100644 --- a/src/main/java/org/spdx/storage/NullModelStore.java +++ b/src/main/java/org/spdx/storage/NullModelStore.java @@ -21,6 +21,8 @@ */ public class NullModelStore implements IModelStore { + private static final String NULL_MODEL_MSG = "Null model store - can only be used with constants and individuals"; + @Override public void close() throws Exception { // Nothing to close @@ -34,7 +36,7 @@ public boolean exists(String objectUri) { @Override public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override @@ -47,7 +49,7 @@ public List getPropertyValueDescriptors( public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override @@ -59,14 +61,14 @@ public Optional getValue(String objectUri, @Override public String getNextId(IdType idType) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override @@ -97,35 +99,35 @@ public void leaveCriticalSection(IModelStoreLock lock) { public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override @@ -139,21 +141,21 @@ public Iterator listValues(String objectUri, public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class clazz, String specVersion) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override @@ -175,7 +177,7 @@ public Optional getTypedValue(String objectUri) @Override public void delete(String objectUri) throws InvalidSPDXAnalysisException { - throw new InvalidSPDXAnalysisException("Null model store - can only be used with constants and individuals"); + throw new InvalidSPDXAnalysisException(NULL_MODEL_MSG); } @Override diff --git a/src/test/java/org/spdx/core/TestCoreModelObject.java b/src/test/java/org/spdx/core/TestCoreModelObject.java index d8864b2..c9c5b92 100644 --- a/src/test/java/org/spdx/core/TestCoreModelObject.java +++ b/src/test/java/org/spdx/core/TestCoreModelObject.java @@ -62,6 +62,7 @@ public void setUp() throws Exception { */ @After public void tearDown() throws Exception { + // Nothing to tear down (yet) } /** diff --git a/src/test/java/org/spdx/core/TestModelObjectHelper.java b/src/test/java/org/spdx/core/TestModelObjectHelper.java index b7080a9..f153ead 100644 --- a/src/test/java/org/spdx/core/TestModelObjectHelper.java +++ b/src/test/java/org/spdx/core/TestModelObjectHelper.java @@ -58,6 +58,7 @@ public void setUp() throws Exception { */ @After public void tearDown() throws Exception { + // Nothing to tear down (yet) } /** diff --git a/src/test/java/org/spdx/licenseTemplate/LicenseTextHelperTest.java b/src/test/java/org/spdx/licenseTemplate/LicenseTextHelperTest.java index a026cdf..65e02a5 100644 --- a/src/test/java/org/spdx/licenseTemplate/LicenseTextHelperTest.java +++ b/src/test/java/org/spdx/licenseTemplate/LicenseTextHelperTest.java @@ -35,6 +35,7 @@ public class LicenseTextHelperTest extends TestCase { /** * @throws java.lang.Exception */ + @Override public void setUp() throws Exception { super.setUp(); } @@ -42,6 +43,7 @@ public void setUp() throws Exception { /** * @throws java.lang.Exception */ + @Override public void tearDown() throws Exception { super.tearDown(); } diff --git a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java b/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java index 4339029..1d68fcb 100644 --- a/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java +++ b/src/test/java/org/spdx/licenseTemplate/TestHtmlTemplateOutputHandler.java @@ -18,10 +18,6 @@ import static org.junit.Assert.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; @@ -31,34 +27,6 @@ */ public class TestHtmlTemplateOutputHandler { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link org.spdx.licenseTemplate.HtmlTemplateOutputHandler#normalText(java.lang.String)}. */ diff --git a/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java b/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java index aa50a67..99f89b4 100644 --- a/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java +++ b/src/test/java/org/spdx/licenseTemplate/TestTextTemplateOutputHandler.java @@ -18,10 +18,6 @@ import static org.junit.Assert.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.spdx.licenseTemplate.LicenseTemplateRule.RuleType; @@ -31,34 +27,6 @@ */ public class TestTextTemplateOutputHandler { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link org.spdx.licenseTemplate.TextTemplateOutputHandler#normalText(java.lang.String)}. */