Skip to content
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
22 changes: 11 additions & 11 deletions examples/org/spdx/examples/ExpandedLicenseExampleV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* <br/>
* Example of serializing a single expanded license
*/

Expand All @@ -12,10 +12,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.networknt.schema.Error;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
import com.networknt.schema.SpecificationVersion;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.ValidationMessage;
import org.spdx.core.DefaultModelStore;
import org.spdx.core.IModelCopyManager;
import org.spdx.library.LicenseInfoFactory;
Expand All @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import static org.spdx.tools.Verify.JSON_SCHEMA_RESOURCE_V3;

Expand Down Expand Up @@ -158,18 +159,17 @@ public static void main(String[] args) throws Exception {
try (OutputStream outStream = new FileOutputStream(outFile)) {
modelStore.serialize(outStream, doc);
}
SchemaRegistry schemaRegistry =
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
Schema schema;
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
JsonSchema schema;
try (InputStream is = Verify.class.getResourceAsStream("/" + JSON_SCHEMA_RESOURCE_V3)) {
schema = schemaRegistry.getSchema(is);
schema = jsonSchemaFactory.getSchema(is);
}
JsonNode root;
try (InputStream is = new FileInputStream(outFile)) {
root = JSON_MAPPER.readTree(is);
}
List<com.networknt.schema.Error> messages = schema.validate(root);
for (Error msg:messages) {
Set<ValidationMessage> messages = schema.validate(root);
for (ValidationMessage msg:messages) {
warnings.add(msg.toString());
}
if (!warnings.isEmpty()) {
Expand Down
21 changes: 10 additions & 11 deletions examples/org/spdx/examples/FullSpdxV3Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-FileCopyrightText: Copyright (c) 2025 Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* <br/>
* Full example of an SPDX document using all classes
*/

Expand All @@ -12,10 +12,10 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.networknt.schema.Error;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
import com.networknt.schema.SpecificationVersion;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.ValidationMessage;
import org.spdx.core.DefaultModelStore;
import org.spdx.core.IModelCopyManager;
import org.spdx.core.InvalidSPDXAnalysisException;
Expand Down Expand Up @@ -838,18 +838,17 @@ public static void main(String[] args) throws Exception {
}

// Validate using the schema
SchemaRegistry schemaRegistry =
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
Schema schema;
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
JsonSchema schema;
try (InputStream is = Verify.class.getResourceAsStream("/" + JSON_SCHEMA_RESOURCE_V3)) {
schema = schemaRegistry.getSchema(is);
schema = jsonSchemaFactory.getSchema(is);
}
JsonNode root;
try (InputStream is = new FileInputStream(outFile)) {
root = JSON_MAPPER.readTree(is);
}
List<Error> messages = schema.validate(root);
for (Error msg:messages) {
Set<ValidationMessage> messages = schema.validate(root);
for (ValidationMessage msg:messages) {
warnings.add(msg.toString());
}
if (!warnings.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.0.0</version>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/org/spdx/tools/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* SPDX-FileCopyrightText: Copyright (c) 2015 Source Auditor Inc.
* SPDX-FileType: SOURCE
* SPDX-License-Identifier: Apache-2.0
*
* <br/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <br/>
* https://www.apache.org/licenses/LICENSE-2.0
*
* <br/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import com.fasterxml.jackson.core.JsonParseException;

Expand All @@ -39,10 +40,11 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.networknt.schema.Schema;
import com.networknt.schema.SchemaRegistry;
import com.networknt.schema.SpecificationVersion;
import com.networknt.schema.Error;

import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.ValidationMessage;

/**
* Verifies an SPDX document and lists any verification errors
Expand Down Expand Up @@ -171,18 +173,17 @@ public static List<String> verify(String filePath, SerFileType fileType) throws
} else {
jsonSchemaResource = JSON_SCHEMA_RESOURCE_V3;
}
SchemaRegistry schemaRegistry =
SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
Schema schema;
JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V202012);
JsonSchema schema;
try (InputStream is = Verify.class.getResourceAsStream("/" + jsonSchemaResource)) {
schema = schemaRegistry.getSchema(is);
schema = jsonSchemaFactory.getSchema(is);
}
JsonNode root;
try (InputStream is = new FileInputStream(file)) {
root = JSON_MAPPER.readTree(is);
}
List<Error> messages = schema.validate(root);
for (Error msg:messages) {
Set<ValidationMessage> messages = schema.validate(root);
for (ValidationMessage msg:messages) {
retval.add(msg.toString());
}
} catch (IOException e) {
Expand Down