Skip to content

Commit 4bc24bd

Browse files
committed
fix for GRAILS-6086 "Reloading currently broken when adding new artefacts (controllers/taglibs etc.)"
1 parent 37be7e9 commit 4bc24bd

File tree

1 file changed

+49
-39
lines changed

1 file changed

+49
-39
lines changed

src/java/org/codehaus/groovy/grails/plugins/DefaultGrailsPlugin.java

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ private void evaluateOnChangeListener() {
297297
if(this.pluginBean.isReadableProperty(ON_CHANGE)) {
298298
this.onChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(this.plugin, ON_CHANGE);
299299
}
300-
if(Environment.getCurrent().isReloadEnabled() || !Metadata.getCurrent().isWarDeployed()) {
300+
301+
final boolean warDeployed = Metadata.getCurrent().isWarDeployed();
302+
final boolean reloadEnabled = Environment.getCurrent().isReloadEnabled();
303+
304+
if(reloadEnabled || !warDeployed) {
301305
if(this.onChangeListener!=null) {
302306
Object referencedResources = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(this.plugin, WATCHED_RESOURCES);
303307

@@ -317,54 +321,49 @@ else if(referencedResources instanceof List) {
317321

318322
if(resourceList!=null) {
319323

320-
this.resourcesReferences = new String[resourceList.size()];
321-
this.resourceCount = new int[resourceList.size()];
324+
List<String> resourceListTmp = new ArrayList<String>();
325+
final Resource[] pluginDirs = GrailsPluginUtils.getPluginDirectories();
326+
final Environment env = Environment.getCurrent();
327+
final String baseLocation = env.getReloadLocation();
328+
329+
for (Object ref : resourceList) {
330+
String stringRef = ref.toString();
331+
if(!warDeployed) {
332+
for (Resource pluginDir : pluginDirs) {
333+
if(pluginDir !=null) {
334+
String pluginResources = getResourcePatternForBaseLocation(pluginDir.getFile().getCanonicalPath(), stringRef);
335+
resourceListTmp.add(pluginResources);
336+
}
337+
}
338+
addBaseLocationPattern(resourceListTmp,
339+
baseLocation, stringRef);
340+
341+
}
342+
else {
343+
addBaseLocationPattern(resourceListTmp,
344+
baseLocation, stringRef);
345+
}
346+
}
347+
348+
349+
350+
this.resourcesReferences = new String[resourceListTmp.size()];
351+
this.resourceCount = new int[resourceListTmp.size()];
322352
for (int i = 0; i < resourcesReferences.length; i++) {
323-
String resRef = resourceList.get(i).toString();
353+
String resRef = resourceListTmp.get(i);
324354
resourcesReferences[i]=resRef;
325355
}
326-
final Resource[] pluginDirs = GrailsPluginUtils.getPluginDirectories();
327356
for (int i = 0; i < resourcesReferences.length; i++) {
328357
String res = resourcesReferences[i];
329358

330359
// Try to load the resources that match the "res" pattern.
331360
Resource[] tmp = new Resource[0];
332361
try {
333-
final Environment env = Environment.getCurrent();
334-
final String baseLocation = env.getReloadLocation();
335-
if(Metadata.getCurrent().isWarDeployed() && env.isReloadEnabled()) {
336-
res = getResourcePatternForBaseLocation(baseLocation, res);
337-
tmp = resolver.getResources(res);
362+
try {
363+
tmp = (Resource[]) ArrayUtils.addAll(tmp,resolver.getResources(res));
338364
}
339-
else {
340-
for (Resource pluginDir : pluginDirs) {
341-
if(pluginDir !=null) {
342-
String pluginResources = getResourcePatternForBaseLocation(pluginDir.getFile().getCanonicalPath(), res);
343-
try {
344-
final Resource[] pluginResourceInstances = resolver.getResources(pluginResources);
345-
tmp = (Resource[]) ArrayUtils.addAll(tmp, pluginResourceInstances);
346-
}
347-
catch (IOException e) {
348-
// ignore. Plugin has no resources of the type
349-
}
350-
}
351-
}
352-
try {
353-
tmp = (Resource[]) ArrayUtils.addAll(tmp,resolver.getResources(res));
354-
}
355-
catch (IOException e) {
356-
// ignore, no resources at default location
357-
}
358-
if(baseLocation!=null) {
359-
final String reloadLocationResourcePattern = getResourcePatternForBaseLocation(baseLocation, res);
360-
try {
361-
final Resource[] reloadLocationResources = resolver.getResources(reloadLocationResourcePattern);
362-
tmp = (Resource[]) ArrayUtils.addAll(tmp, reloadLocationResources);
363-
}
364-
catch (IOException e) {
365-
// ignore, no resources at base location
366-
}
367-
}
365+
catch (IOException e) {
366+
// ignore, no resources at default location
368367
}
369368
}
370369
catch (Exception ex) {
@@ -408,6 +407,17 @@ else if(referencedResources instanceof List) {
408407
}
409408
}
410409

410+
private void addBaseLocationPattern(List<String> resourceList,
411+
final String baseLocation, String pattern) {
412+
if(baseLocation!=null) {
413+
final String reloadLocationResourcePattern = getResourcePatternForBaseLocation(baseLocation, pattern);
414+
resourceList.add(reloadLocationResourcePattern);
415+
}
416+
else {
417+
resourceList.add(pattern);
418+
}
419+
}
420+
411421
private String getResourcePatternForBaseLocation(String baseLocation, String resourcePath) {
412422
String location = baseLocation;
413423
if(!location.endsWith(File.separator)) location = location + File.separator;

0 commit comments

Comments
 (0)