Skip to content

Commit

Permalink
Fix issue #43
Browse files Browse the repository at this point in the history
Generated resources (SASS, less, ...) are not updated in debug mode
  • Loading branch information
ic3fox committed Jul 13, 2017
1 parent 4b77ff8 commit dc3b2fa
Showing 1 changed file with 53 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class ServletContextResourceReaderHandler implements ResourceReaderHandle
/** The list of stream resource readers */
private final List<StreamResourceReader> streamResourceReaders = new ArrayList<>();

/** The list of resource generator info providers */
private final List<ResourceBrowser> resourceGeneratorInfoProviders = new ArrayList<>();

/** The list of resource info providers */
private final List<ResourceBrowser> resourceInfoProviders = new ArrayList<>();

Expand Down Expand Up @@ -191,7 +194,11 @@ private void initReader(Object obj) {
}

if (obj instanceof ResourceBrowser) {
resourceInfoProviders.add(0, (ResourceBrowser) obj);
if(obj instanceof ResourceGenerator){
resourceGeneratorInfoProviders.add(0, (ResourceBrowser) obj);
}else{
resourceInfoProviders.add(0, (ResourceBrowser) obj);
}
}
}

Expand Down Expand Up @@ -445,26 +452,44 @@ public Set<String> getResourceNames(String dirName) {
@Override
public boolean isDirectory(String resourceName) {
boolean result = false;
List<ResourceBrowser> list = new ArrayList<>();
list.addAll(resourceInfoProviders);
for (Iterator<ResourceBrowser> iterator = list.iterator(); iterator.hasNext() && !result;) {
ResourceBrowser rsBrowser = iterator.next();
if (generatorRegistry.isPathGenerated(resourceName)) {
List<ResourceBrowser> browsers = new ArrayList<>();
browsers.addAll(resourceGeneratorInfoProviders);
if (generatorRegistry.isPathGenerated(resourceName)) {
for (Iterator<ResourceBrowser> iterator = browsers.iterator(); iterator.hasNext() && !result;) {
ResourceBrowser rsBrowser = iterator.next();
if (rsBrowser instanceof ResourceGenerator) {
ResourceGenerator rsGeneratorBrowser = (ResourceGenerator) rsBrowser;
if (rsGeneratorBrowser.getResolver().matchPath(resourceName)) {
result = rsBrowser.isDirectory(resourceName);
}
}
} else {
if (!(rsBrowser instanceof ResourceGenerator)) {
result = rsBrowser.isDirectory(resourceName);
}
}
}

if(!result){
browsers.clear();
browsers.addAll(resourceInfoProviders);

for (Iterator<ResourceBrowser> iterator = browsers.iterator(); iterator.hasNext() && !result;) {
ResourceBrowser rsBrowser = iterator.next();
if (generatorRegistry.isPathGenerated(resourceName)) {
if (rsBrowser instanceof ResourceGenerator) {
ResourceGenerator rsGeneratorBrowser = (ResourceGenerator) rsBrowser;
if (rsGeneratorBrowser.getResolver().matchPath(resourceName)) {
result = rsBrowser.isDirectory(resourceName);
}
}
} else {
if (!(rsBrowser instanceof ResourceGenerator)) {
result = rsBrowser.isDirectory(resourceName);
}
}
}
}
return result;
}


/*
* (non-Javadoc)
*
Expand All @@ -476,23 +501,31 @@ public boolean isDirectory(String resourceName) {
public String getFilePath(String resourcePath) {

String filePath = null;
List<ResourceBrowser> list = new ArrayList<>();
list.addAll(resourceInfoProviders);
for (Iterator<ResourceBrowser> iterator = list.iterator(); iterator.hasNext() && filePath == null;) {
ResourceBrowser rsBrowser = iterator.next();
if (generatorRegistry.isPathGenerated(resourcePath)) {

List<ResourceBrowser> browsers = new ArrayList<>();

if (generatorRegistry.isPathGenerated(resourcePath)) {
browsers.addAll(resourceGeneratorInfoProviders);
for (Iterator<ResourceBrowser> iterator = browsers.iterator(); iterator.hasNext() && filePath == null;) {
ResourceBrowser rsBrowser = iterator.next();
if (rsBrowser instanceof ResourceGenerator) {
ResourceGenerator rsGeneratorBrowser = (ResourceGenerator) rsBrowser;
if (rsGeneratorBrowser.getResolver().matchPath(resourcePath)) {
filePath = rsBrowser.getFilePath(resourcePath);
}
}
} else {
if (!(rsBrowser instanceof ResourceGenerator)) {
filePath = rsBrowser.getFilePath(resourcePath);
}
}
}
}

if(filePath == null){
browsers.clear();
browsers.addAll(resourceInfoProviders);
for (Iterator<ResourceBrowser> iterator = resourceInfoProviders.iterator(); iterator.hasNext() && filePath == null;) {
ResourceBrowser rsBrowser = iterator.next();
filePath = rsBrowser.getFilePath(resourcePath);
}
}

return filePath;
}

Expand Down

0 comments on commit dc3b2fa

Please sign in to comment.