Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Merge 0d667ab into 7395bc1
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinYSpasov committed Jul 19, 2018
2 parents 7395bc1 + 0d667ab commit da12de9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## Unreleased
### Changed
- Load catalog resources from Thread context class loader

## [1.3.2] - 2018-07-11
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private Catalog loadCatalog(final URL catalogUrl) {
private List<URL> listAllCatalogsFromClasspath() {
final String catalogFullPath = catalogContext.getCatalogFullPath();
try {
return classpathResourceLoader.getResources(getClass(), catalogFullPath);
return classpathResourceLoader.getResources(catalogFullPath);
} catch (final IOException e) {
throw new SchemaCatalogException(format("Failed to load the catalogs from the classpath for location '%s'", catalogFullPath), e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.schema.catalog.util;

import static java.lang.Thread.currentThread;
import static java.util.Collections.list;

import java.io.IOException;
Expand All @@ -13,12 +14,11 @@ public class ClasspathResourceLoader {


/**
* @param clazz A class from which to get its classloader
* @param resourceName The name of the resource on the classpath
* @return a {@link URL} to the resource
* @throws IOException If the get fails
*/
public List<URL> getResources(final Class<?> clazz, final String resourceName) throws IOException {
return list(clazz.getClassLoader().getResources(resourceName));
public List<URL> getResources( final String resourceName) throws IOException {
return list(currentThread().getContextClassLoader().getResources(resourceName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void shouldThrowExceptionIfLoadingFileThrowsIOException() throws Exceptio
final URL url = new URL("file://src/code/my-file.txt");
final URI uri = url.toURI();

when(classpathResourceLoader.getResources(ClasspathCatalogLoader.class, "META-INF/schema_catalog.json")).thenReturn(singletonList(url));
when(classpathResourceLoader.getResources( "META-INF/schema_catalog.json")).thenReturn(singletonList(url));
when(urlConverter.toUri(url)).thenReturn(uri);
when(objectMapper.readValue(url, Catalog.class)).thenThrow(ioException);

Expand All @@ -67,7 +67,7 @@ public void shouldThrowExceptionIfLoadingResourcesThrowsIOException() throws Exc

final IOException ioException = new IOException("Ooops");

when(classpathResourceLoader.getResources(ClasspathCatalogLoader.class, "META-INF/schema_catalog.json")).thenThrow(ioException);
when(classpathResourceLoader.getResources("META-INF/schema_catalog.json")).thenThrow(ioException);

try {
classpathCatalogLoader.getCatalogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ClasspathResourceLoaderTest {
public void shouldLoadResourcesFromTheClasspath() throws Exception {

final String filename = "json/random-classpath-resource.txt";
final List<URL> resources = classpathResourceLoader.getResources(getClass(), filename);
final List<URL> resources = classpathResourceLoader.getResources(filename);

assertThat(resources.size(), is(1));
assertThat(resources.get(0).toString(), endsWith(filename));
Expand Down

0 comments on commit da12de9

Please sign in to comment.