16
16
import static org .junit .jupiter .api .Assertions .assertFalse ;
17
17
import static org .junit .jupiter .api .Assertions .assertTrue ;
18
18
19
- import java .nio .file .Path ;
20
- import java .nio .file .Paths ;
21
19
import java .util .ArrayList ;
22
20
import java .util .Collection ;
23
21
import java .util .List ;
24
22
import javax .xml .XMLConstants ;
25
- import javax .xml .transform .Source ;
26
23
import javax .xml .transform .stream .StreamSource ;
27
24
import javax .xml .validation .Schema ;
28
25
import javax .xml .validation .SchemaFactory ;
@@ -45,38 +42,26 @@ public class XmlSchemaVerificationTest extends BaseSchemaVerificationTest {
45
42
private static final Schema VERSION_16 ;
46
43
47
44
static {
48
- // Surefire sets a `basedir` system property
49
- // Otherwise we assume that the project is in the current working directory (should work in IDEs)
50
- Path toolsPath = Paths .get (System .getProperty ("basedir" , "." ));
51
- Path schemaPath = toolsPath .resolve ("../schema" );
52
- SchemaFactory factory = SchemaFactory .newInstance (XMLConstants .W3C_XML_SCHEMA_NS_URI );
53
- ClassLoader cl = XmlSchemaVerificationTest .class .getClassLoader ();
54
45
try {
55
- VERSION_10 = factory .newSchema (
56
- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.0.xsd" ))});
57
- VERSION_11 = factory .newSchema (
58
- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.1.xsd" ))});
59
- VERSION_12 = factory .newSchema (
60
- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.2.xsd" ))});
61
- VERSION_13 = factory .newSchema (
62
- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.3.xsd" ))});
63
- VERSION_14 = factory .newSchema (
64
- new Source [] {spdxSource (), new StreamSource (cl .getResourceAsStream ("bom-1.4.xsd" ))});
65
- VERSION_15 = factory .newSchema (new Source [] {
66
- spdxSource (), new StreamSource (schemaPath .resolve ("bom-1.5.xsd" ).toFile ())
67
- });
68
- VERSION_16 = factory .newSchema (new Source [] {
69
- spdxSource (), new StreamSource (schemaPath .resolve ("bom-1.6.xsd" ).toFile ())
70
- });
46
+ SchemaFactory factory = SchemaFactory .newInstance (XMLConstants .W3C_XML_SCHEMA_NS_URI );
47
+ factory .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "file" );
48
+ ClassLoader cl = XmlSchemaVerificationTest .class .getClassLoader ();
49
+ // Override the `schemaLocation` property in the file
50
+ factory .setProperty (
51
+ "http://apache.org/xml/properties/schema/external-schemaLocation" ,
52
+ "http://cyclonedx.org/schema/spdx spdx.xsd" );
53
+ VERSION_10 = factory .newSchema (cl .getResource ("bom-1.0.xsd" ));
54
+ VERSION_11 = factory .newSchema (cl .getResource ("bom-1.1.xsd" ));
55
+ VERSION_12 = factory .newSchema (cl .getResource ("bom-1.2.xsd" ));
56
+ VERSION_13 = factory .newSchema (cl .getResource ("bom-1.3.xsd" ));
57
+ VERSION_14 = factory .newSchema (cl .getResource ("bom-1.4.xsd" ));
58
+ VERSION_15 = factory .newSchema (cl .getResource ("bom-1.5.xsd" ));
59
+ VERSION_16 = factory .newSchema (cl .getResource ("bom-1.6.xsd" ));
71
60
} catch (SAXException e ) {
72
61
throw new IllegalStateException (e );
73
62
}
74
63
}
75
64
76
- private static Source spdxSource () {
77
- return new StreamSource (XmlSchemaVerificationTest .class .getClassLoader ().getResourceAsStream ("spdx.xsd" ));
78
- }
79
-
80
65
/**
81
66
* Generates a collection of dynamic tests based on the available XML files.
82
67
*
0 commit comments