@@ -223,49 +223,55 @@ public void testXMLCatalog() throws Exception {
223223 Plugin plugin = org .eclipse .wildwebdeveloper .xml .internal .Activator .getDefault ();
224224 BundleContext bundleContext = plugin .getBundle ().getBundleContext ();
225225 URL bundleUrl = bundlePath .toUri ().toURL ();
226- Bundle catalogBundle = bundleContext .installBundle (bundleUrl .toExternalForm (), bundleUrl .openStream ());
227- catalogBundle .start ();
228-
229- // Open preferences dialog to trigger the refresh of the system catalog
230- PreferenceDialog dialog = PreferencesUtil .createPreferenceDialogOn (PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
231- "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCatalogPreferencePage" , null , null );
232- dialog .getShell ().open ();
233- dialog .getShell ().close ();
234-
235- // Find system.catalog in well known location from plugin
236- File systemCatalog = plugin .getStateLocation ().append ("system-catalog.xml" ).toFile ();
237- // Parse system-catalog to check it
238- Document systemCatalogDom = runWithLocalCatalogOnlyForTestXMLCatalog (() -> DocumentBuilderFactory .newDefaultInstance ()
239- .newDocumentBuilder ().parse (systemCatalog ));
240-
241- // root
242- Node catalogNode = systemCatalogDom .getLastChild ();
243- assertEquals (Node .ELEMENT_NODE , catalogNode .getNodeType ());
244- assertEquals ("catalog" , catalogNode .getNodeName ());
245-
246- // find URI-entries
247- NodeList catalogEntries = catalogNode .getChildNodes ();
248- List <Node > uriNodes = IntStream .range (0 , catalogEntries .getLength ()).mapToObj (catalogEntries ::item ).filter (n -> n
249- .getNodeType () == Node .ELEMENT_NODE ).filter (n -> "uri" .equals (n .getNodeName ())).collect (Collectors .toList ());
250- assertFalse (uriNodes .isEmpty (), "uri-nodes expected" );
251-
252- // find expected entry
253- List <Node > expectedNodes = uriNodes .stream ().filter (n -> "http://eclipse.org/wildwebdeveloper/test" .equals (n .getAttributes ()
254- .getNamedItem ("name" ).getNodeValue ())).collect (Collectors .toList ());
255- assertEquals (1 , expectedNodes .size (), "one uri-node with the used name expected" );
256- Node uriNode = expectedNodes .get (0 );
257-
258- // value of uri
259- assertNotNull (uriNode .getAttributes ().getNamedItem ("uri" ), "uri-attribute expected" );
260- String uri = uriNode .getAttributes ().getNamedItem ("uri" ).getNodeValue ();
261- assertNotNull (uri , "value fro uri expected" );
262- // use of jar-uri - file is not cached in local filesystem. This enables
263- // relative includes in schemas
264- assertTrue (uri .startsWith ("jar:file:/" ), "jar-uri expected: " + uri );
265- assertTrue (uri .endsWith ("/org/eclipse/wildwebdeveloper/test/schema.xsd" ), "relative path of schema in uri expected: " + uri );
266-
267- // Uninstall bundle once again
268- catalogBundle .uninstall ();
226+ Bundle catalogBundle ;
227+ try (var is = bundleUrl .openStream ()) {
228+ catalogBundle = bundleContext .installBundle (bundleUrl .toExternalForm (), is );
229+ }
230+ try {
231+ catalogBundle .start ();
232+
233+ // Open preferences dialog to trigger the refresh of the system catalog
234+ PreferenceDialog dialog = PreferencesUtil .createPreferenceDialogOn (
235+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
236+ "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCatalogPreferencePage" , null , null );
237+ dialog .getShell ().open ();
238+ dialog .getShell ().close ();
239+
240+ // Find system.catalog in well known location from plugin
241+ File systemCatalog = plugin .getStateLocation ().append ("system-catalog.xml" ).toFile ();
242+ // Parse system-catalog to check it
243+ Document systemCatalogDom = runWithLocalCatalogOnlyForTestXMLCatalog (() -> DocumentBuilderFactory .newDefaultInstance ()
244+ .newDocumentBuilder ().parse (systemCatalog ));
245+
246+ // root
247+ Node catalogNode = systemCatalogDom .getLastChild ();
248+ assertEquals (Node .ELEMENT_NODE , catalogNode .getNodeType ());
249+ assertEquals ("catalog" , catalogNode .getNodeName ());
250+
251+ // find URI-entries
252+ NodeList catalogEntries = catalogNode .getChildNodes ();
253+ List <Node > uriNodes = IntStream .range (0 , catalogEntries .getLength ()).mapToObj (catalogEntries ::item ).filter (n -> n
254+ .getNodeType () == Node .ELEMENT_NODE ).filter (n -> "uri" .equals (n .getNodeName ())).collect (Collectors .toList ());
255+ assertFalse (uriNodes .isEmpty (), "uri-nodes expected" );
256+
257+ // find expected entry
258+ List <Node > expectedNodes = uriNodes .stream ().filter (n -> "http://eclipse.org/wildwebdeveloper/test" .equals (n .getAttributes ()
259+ .getNamedItem ("name" ).getNodeValue ())).collect (Collectors .toList ());
260+ assertEquals (1 , expectedNodes .size (), "one uri-node with the used name expected" );
261+ Node uriNode = expectedNodes .get (0 );
262+
263+ // value of uri
264+ assertNotNull (uriNode .getAttributes ().getNamedItem ("uri" ), "uri-attribute expected" );
265+ String uri = uriNode .getAttributes ().getNamedItem ("uri" ).getNodeValue ();
266+ assertNotNull (uri , "value fro uri expected" );
267+ // use of jar-uri - file is not cached in local filesystem. This enables
268+ // relative includes in schemas
269+ assertTrue (uri .startsWith ("jar:file:/" ), "jar-uri expected: " + uri );
270+ assertTrue (uri .endsWith ("/org/eclipse/wildwebdeveloper/test/schema.xsd" ), "relative path of schema in uri expected: " + uri );
271+ } finally {
272+ // Uninstall bundle once again
273+ catalogBundle .uninstall ();
274+ }
269275 }
270276
271277 /**
@@ -367,42 +373,45 @@ public void testXMLCatalogHttpsUriIncluded() throws Exception {
367373 Bundle catalogBundle ;
368374 try (var is = bundleUrl .openStream ()) {
369375 catalogBundle = bundleContext .installBundle (bundleUrl .toExternalForm (), is );
376+ }
377+ try {
370378 catalogBundle .start ();
379+ // Open preferences dialog to trigger the refresh of the system catalog
380+ PreferenceDialog dialog = PreferencesUtil .createPreferenceDialogOn (
381+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
382+ "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCatalogPreferencePage" , null , null );
383+ dialog .getShell ().open ();
384+ dialog .getShell ().close ();
385+
386+ // Find system-catalog and parse it
387+ File systemCatalog = plugin .getStateLocation ().append ("system-catalog.xml" ).toFile ();
388+ Document systemCatalogDom = DocumentBuilderFactory .newDefaultInstance ().newDocumentBuilder ().parse (systemCatalog );
389+
390+ // root element
391+ Node catalogNode = systemCatalogDom .getLastChild ();
392+ assertEquals (Node .ELEMENT_NODE , catalogNode .getNodeType ());
393+ assertEquals ("catalog" , catalogNode .getNodeName ());
394+
395+ // collect <uri> entries
396+ NodeList catalogEntries = catalogNode .getChildNodes ();
397+ List <Node > uriNodes = IntStream .range (0 , catalogEntries .getLength ()).mapToObj (catalogEntries ::item ).filter (n -> n
398+ .getNodeType () == Node .ELEMENT_NODE ).filter (n -> "uri" .equals (n .getNodeName ())).toList ();
399+ assertFalse (uriNodes .isEmpty (), "uri-nodes expected" );
400+
401+ // find contributed HTTPS entry
402+ List <Node > expectedNodes = uriNodes .stream ()
403+ .filter (n -> HTTPS_NAME .equals (n .getAttributes ().getNamedItem ("name" ).getNodeValue ()))
404+ .toList ();
405+ assertEquals (1 , expectedNodes .size (), "one https uri-node with the used name expected" );
406+ Node uriNode = expectedNodes .get (0 );
407+
408+ // ensure the https URI is preserved
409+ assertNotNull (uriNode .getAttributes ().getNamedItem ("uri" ), "uri-attribute expected" );
410+ String uri = uriNode .getAttributes ().getNamedItem ("uri" ).getNodeValue ();
411+ assertEquals (HTTPS_URI , uri , "https uri value should be preserved in catalog" );
412+ } finally {
413+ // cleanup
414+ catalogBundle .uninstall ();
371415 }
372-
373- // Open preferences dialog to trigger the refresh of the system catalog
374- PreferenceDialog dialog = PreferencesUtil .createPreferenceDialogOn (PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell (),
375- "org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLCatalogPreferencePage" , null , null );
376- dialog .getShell ().open ();
377- dialog .getShell ().close ();
378-
379- // Find system-catalog and parse it
380- File systemCatalog = plugin .getStateLocation ().append ("system-catalog.xml" ).toFile ();
381- Document systemCatalogDom = DocumentBuilderFactory .newDefaultInstance ().newDocumentBuilder ().parse (systemCatalog );
382-
383- // root element
384- Node catalogNode = systemCatalogDom .getLastChild ();
385- assertEquals (Node .ELEMENT_NODE , catalogNode .getNodeType ());
386- assertEquals ("catalog" , catalogNode .getNodeName ());
387-
388- // collect <uri> entries
389- NodeList catalogEntries = catalogNode .getChildNodes ();
390- List <Node > uriNodes = IntStream .range (0 , catalogEntries .getLength ()).mapToObj (catalogEntries ::item ).filter (n -> n
391- .getNodeType () == Node .ELEMENT_NODE ).filter (n -> "uri" .equals (n .getNodeName ())).toList ();
392- assertFalse (uriNodes .isEmpty (), "uri-nodes expected" );
393-
394- // find contributed HTTPS entry
395- List <Node > expectedNodes = uriNodes .stream ().filter (n -> HTTPS_NAME .equals (n .getAttributes ().getNamedItem ("name" ).getNodeValue ()))
396- .toList ();
397- assertEquals (1 , expectedNodes .size (), "one https uri-node with the used name expected" );
398- Node uriNode = expectedNodes .get (0 );
399-
400- // ensure the https URI is preserved
401- assertNotNull (uriNode .getAttributes ().getNamedItem ("uri" ), "uri-attribute expected" );
402- String uri = uriNode .getAttributes ().getNamedItem ("uri" ).getNodeValue ();
403- assertEquals (HTTPS_URI , uri , "https uri value should be preserved in catalog" );
404-
405- // cleanup
406- catalogBundle .uninstall ();
407416 }
408417}
0 commit comments