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
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper.tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
point="org.eclipse.wildwebdeveloper.json.schema">
<schema
pattern="dep.yml"
url="https://json.schemastore.org/dependabot">
url="https://www.schemastore.org/dependabot">
</schema>
<schema
pattern="depp.yml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.tests;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -24,7 +21,9 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -242,8 +241,8 @@ public void testXMLCatalog() throws Exception {
// Find system.catalog in well known location from plugin
File systemCatalog = plugin.getStateLocation().append("system-catalog.xml").toFile();
// Parse system-catalog to check it
Document systemCatalogDom = DocumentBuilderFactory.newDefaultInstance().newDocumentBuilder()
.parse(systemCatalog);
Document systemCatalogDom = runWithLocalCatalogOnlyForTestXMLCatalog(
() -> DocumentBuilderFactory.newDefaultInstance().newDocumentBuilder().parse(systemCatalog));

// root
Node catalogNode = systemCatalogDom.getLastChild();
Expand Down Expand Up @@ -276,4 +275,47 @@ public void testXMLCatalog() throws Exception {
// Uninstall bundle once again
catalogBundle.uninstall();
}

/**
* Workaround for erratic runtime exceptions because of catalog.dtd temporarily not being available online:
* <pre>{@code
* java.io.FileNotFoundException: http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd
* at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:2010)
* at ...
* at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:206)
* at org.eclipse.wildwebdeveloper.tests.TestXML.testXMLCatalog(TestXML.java:246)
* at java.base/java.lang.reflect.Method.invoke(Method.java:580)
* at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
* at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
* }</pre>
*/
private <T> T runWithLocalCatalogOnlyForTestXMLCatalog(Callable<T> callable) throws Exception {
var origSysProps = new HashMap<String, String>();
List.of( //
"javax.xml.useCatalog", //
"javax.xml.catalog.files", //
"javax.xml.catalog.prefer", //
"javax.xml.catalog.resolve"
).forEach(k -> origSysProps.put(k, System.getProperty(k)));

var catalogRedirect = Path.of("src/org/eclipse/wildwebdeveloper/tests/catalog/oasis-catalog-redirect.xml");
assertTrue(Files.exists(catalogRedirect));
// enforce usage of local catalog.dtd file
System.setProperty("javax.xml.useCatalog", "true");
System.setProperty("javax.xml.catalog.files", catalogRedirect.toUri().toString());
System.setProperty("javax.xml.catalog.prefer", "system");
System.setProperty("javax.xml.catalog.resolve", "strict");
try {
return callable.call();
} finally {
// restore previous behaviour
for (var e : origSysProps.entrySet()) {
if (e.getValue() == null) {
System.clearProperty(e.getKey());
} else {
System.setProperty(e.getKey(), e.getValue());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ private void testErrorFile(String name) throws Exception {

@Test
public void testSchemaExtensionPoint() throws Exception {
// loads remote file https://www.schemastore.org/dependabot as configured in plugin.xml
testErrorFile("dep.yml");
}

@Test
public void testSchemaExtensionPointUsingPlatformURL() throws Exception {
// loads local file platform:/plugin/org.eclipse.wildwebdeveloper.tests/resources/dependabot.json as configured in plugin.xml
testErrorFile("depp.yml");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<!-- copied from http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd -->
<!-- $Id: catalog.dtd,v 1.10 2002/10/18 23:54:58 ndw Exp $ -->

<!ENTITY % pubIdChars "CDATA">
<!ENTITY % publicIdentifier "%pubIdChars;">
<!ENTITY % partialPublicIdentifier "%pubIdChars;">
<!ENTITY % uriReference "CDATA">
<!ENTITY % string "CDATA">
<!ENTITY % systemOrPublic "(system|public)">

<!ENTITY % p "">
<!ENTITY % s "">
<!ENTITY % nsdecl "xmlns%s;">

<!ENTITY % catalog "%p;catalog">
<!ENTITY % public "%p;public">
<!ENTITY % system "%p;system">
<!ENTITY % uri "%p;uri">
<!ENTITY % rewriteSystem "%p;rewriteSystem">
<!ENTITY % rewriteURI "%p;rewriteURI">
<!ENTITY % delegatePublic "%p;delegatePublic">
<!ENTITY % delegateSystem "%p;delegateSystem">
<!ENTITY % delegateURI "%p;delegateURI">
<!ENTITY % nextCatalog "%p;nextCatalog">
<!ENTITY % group "%p;group">

<!ENTITY % local.catalog.mix "">
<!ENTITY % local.catalog.attribs "">

<!ELEMENT %catalog; (%public;|%system;|%uri;
|%rewriteSystem;|%rewriteURI;
|%delegatePublic;|%delegateSystem;|%delegateURI;
|%nextCatalog;|%group; %local.catalog.mix;)+>
<!ATTLIST %catalog;
%nsdecl; %uriReference; #FIXED
'urn:oasis:names:tc:entity:xmlns:xml:catalog'
prefer %systemOrPublic; #IMPLIED
xml:base %uriReference; #IMPLIED
%local.catalog.attribs;
>

<!ENTITY % local.public.attribs "">

<!ELEMENT %public; EMPTY>
<!ATTLIST %public;
id ID #IMPLIED
publicId %publicIdentifier; #REQUIRED
uri %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.public.attribs;
>

<!ENTITY % local.system.attribs "">

<!ELEMENT %system; EMPTY>
<!ATTLIST %system;
id ID #IMPLIED
systemId %string; #REQUIRED
uri %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.system.attribs;
>

<!ENTITY % local.uri.attribs "">

<!ELEMENT %uri; EMPTY>
<!ATTLIST %uri;
id ID #IMPLIED
name %string; #REQUIRED
uri %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.uri.attribs;
>

<!ENTITY % local.rewriteSystem.attribs "">

<!ELEMENT %rewriteSystem; EMPTY>
<!ATTLIST %rewriteSystem;
id ID #IMPLIED
systemIdStartString %string; #REQUIRED
rewritePrefix %string; #REQUIRED
%local.rewriteSystem.attribs;
>

<!ENTITY % local.rewriteURI.attribs "">

<!ELEMENT %rewriteURI; EMPTY>
<!ATTLIST %rewriteURI;
id ID #IMPLIED
uriStartString %string; #REQUIRED
rewritePrefix %string; #REQUIRED
%local.rewriteURI.attribs;
>

<!ENTITY % local.delegatePublic.attribs "">

<!ELEMENT %delegatePublic; EMPTY>
<!ATTLIST %delegatePublic;
id ID #IMPLIED
publicIdStartString %partialPublicIdentifier; #REQUIRED
catalog %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.delegatePublic.attribs;
>

<!ENTITY % local.delegateSystem.attribs "">

<!ELEMENT %delegateSystem; EMPTY>
<!ATTLIST %delegateSystem;
id ID #IMPLIED
systemIdStartString %string; #REQUIRED
catalog %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.delegateSystem.attribs;
>

<!ENTITY % local.delegateURI.attribs "">

<!ELEMENT %delegateURI; EMPTY>
<!ATTLIST %delegateURI;
id ID #IMPLIED
uriStartString %string; #REQUIRED
catalog %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.delegateURI.attribs;
>

<!ENTITY % local.nextCatalog.attribs "">

<!ELEMENT %nextCatalog; EMPTY>
<!ATTLIST %nextCatalog;
id ID #IMPLIED
catalog %uriReference; #REQUIRED
xml:base %uriReference; #IMPLIED
%local.nextCatalog.attribs;
>

<!ENTITY % local.group.mix "">
<!ENTITY % local.group.attribs "">

<!ELEMENT %group; (%public;|%system;|%uri;
|%rewriteSystem;|%rewriteURI;
|%delegatePublic;|%delegateSystem;|%delegateURI;
|%nextCatalog; %local.group.mix;)+>
<!ATTLIST %group;
id ID #IMPLIED
prefer %systemOrPublic; #IMPLIED
xml:base %uriReference; #IMPLIED
%local.group.attribs;
>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.0//EN" "catalog-1.0.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<!-- Map legacy and current systemIds to the bundled local DTD -->
<system systemId="http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd" uri="catalog-1.0.dtd" />
<system systemId="https://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd" uri="catalog-1.0.dtd" />
<system systemId="https://docs.oasis-open.org/entity/release/1.0/catalog-1.0.dtd" uri="catalog-1.0.dtd" />
</catalog>
Loading