Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recursive file set resolving for the WebAppFileSetResolver #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 15 additions & 16 deletions src/main/java/com/papercut/silken/WebAppFileSetResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public List<URL> filesFromNamespace(String searchPath, String namespace, String
if (!WEB_APP_ROOT_VAR.equals(path)) {
base = path.substring(WEB_APP_ROOT_VAR.length());
}
resourcesList.addAll(listResourcesFromWebDir(base, namespace, suffix));
// Make sure we end in a slash
StringBuilder pathBuilder = new StringBuilder(base);
if (!base.endsWith("/")) {
pathBuilder.append('/');
}
pathBuilder.append(namespace.replace(".", "/")).append('/');

resourcesList.addAll(listResourcesFromWebDir(pathBuilder.toString(), suffix));
}

// We and return when we find our first match on out path.
Expand Down Expand Up @@ -79,22 +86,15 @@ private List<URL> listResourcesFromClasspath(String namespace, String suffix) {

return resourceList;
}

private List<URL> listResourcesFromWebDir(String base, String namespace, String suffix) {
Preconditions.checkNotNull(base, "No base defined");

// Make sure we end in a slash
StringBuilder path = new StringBuilder(base);
if (!base.endsWith("/")) {
path.append('/');
}
path.append(namespace.replace(".", "/")).append('/');

Set<String> files = (Set<String>) servletContext.getResourcePaths(path.toString());


private List<URL> listResourcesFromWebDir(String path, String suffix) {
Set<String> files = (Set<String>) servletContext.getResourcePaths(path);

List<URL> resourceList = new ArrayList<URL>();
for (String file : files) {
if (file.endsWith(suffix)) {
if (file.endsWith("/")) {
resourceList.addAll(listResourcesFromWebDir(file, suffix));
} else if (file.endsWith(suffix)) {
try {
resourceList.add(servletContext.getResource(file));
} catch (MalformedURLException e) {
Expand All @@ -104,5 +104,4 @@ private List<URL> listResourcesFromWebDir(String base, String namespace, String
}
return resourceList;
}

}