@Test public void testFielesystemResourceOverriding() throws Exception { StaticResourceClassloader klas = new StaticResourceClassloader(new MockBundle(), overrideDir, bundlePath); URL result = klas.getResource(overriddenBundleResource); Assert.assertNotNull(result); Assert.assertEquals(overrideResource.toURI().toURL(), result); }
@Override public URL getResource(String path) { if (overrideIsSane()) { String fspath = path.replaceAll("../", ""); fspath = fspath.replace(bundlePathPrefix, ""); File file = new File(overrideDir.getAbsoluteFile() + File.separator + fspath); if (file.exists() && file.isFile()) { try { logger.debug("Resource from filesystem overrides bundle resource: {}", file.getAbsolutePath()); return file.toURI().toURL(); } catch (MalformedURLException e) { logger.error("Failed to get filesystem URL for override file! ", e); } } } URL out = bundle.getResource(path); logger.debug("Serving resource from bundle: {}", out); return out; }
StaticResourceClassloader extends ClassLoader { @Override public URL getResource(String path) { if (overrideIsSane()) { String fspath = path.replaceAll("../", ""); fspath = fspath.replace(bundlePathPrefix, ""); File file = new File(overrideDir.getAbsoluteFile() + File.separator + fspath); if (file.exists() && file.isFile()) { try { logger.debug("Resource from filesystem overrides bundle resource: {}", file.getAbsolutePath()); return file.toURI().toURL(); } catch (MalformedURLException e) { logger.error("Failed to get filesystem URL for override file! ", e); } } } URL out = bundle.getResource(path); logger.debug("Serving resource from bundle: {}", out); return out; } }
StaticResourceClassloader extends ClassLoader { @Override public URL getResource(String path) { if (overrideIsSane()) { String fspath = path.replaceAll("../", ""); fspath = fspath.replace(bundlePathPrefix, ""); File file = new File(overrideDir.getAbsoluteFile() + File.separator + fspath); if (file.exists() && file.isFile()) { try { logger.debug("Resource from filesystem overrides bundle resource: {}", file.getAbsolutePath()); return file.toURI().toURL(); } catch (MalformedURLException e) { logger.error("Failed to get filesystem URL for override file! ", e); } } } URL out = bundle.getResource(path); logger.debug("Serving resource from bundle: {}", out); return out; } StaticResourceClassloader(Bundle bundle, File overrideDir, String bundleResourcePath); }
StaticResourceClassloader extends ClassLoader { @Override public URL getResource(String path) { if (overrideIsSane()) { String fspath = path.replaceAll("../", ""); fspath = fspath.replace(bundlePathPrefix, ""); File file = new File(overrideDir.getAbsoluteFile() + File.separator + fspath); if (file.exists() && file.isFile()) { try { logger.debug("Resource from filesystem overrides bundle resource: {}", file.getAbsolutePath()); return file.toURI().toURL(); } catch (MalformedURLException e) { logger.error("Failed to get filesystem URL for override file! ", e); } } } URL out = bundle.getResource(path); logger.debug("Serving resource from bundle: {}", out); return out; } StaticResourceClassloader(Bundle bundle, File overrideDir, String bundleResourcePath); @Override URL getResource(String path); boolean overrideIsSane(); }
StaticResourceClassloader extends ClassLoader { @Override public URL getResource(String path) { if (overrideIsSane()) { String fspath = path.replaceAll("../", ""); fspath = fspath.replace(bundlePathPrefix, ""); File file = new File(overrideDir.getAbsoluteFile() + File.separator + fspath); if (file.exists() && file.isFile()) { try { logger.debug("Resource from filesystem overrides bundle resource: {}", file.getAbsolutePath()); return file.toURI().toURL(); } catch (MalformedURLException e) { logger.error("Failed to get filesystem URL for override file! ", e); } } } URL out = bundle.getResource(path); logger.debug("Serving resource from bundle: {}", out); return out; } StaticResourceClassloader(Bundle bundle, File overrideDir, String bundleResourcePath); @Override URL getResource(String path); boolean overrideIsSane();  }