Skip to content

Commit 898e5ee

Browse files
committed
fix for GRAILS-12076 and GRAILS-12077
1 parent 5f1a286 commit 898e5ee

File tree

8 files changed

+24
-15
lines changed

8 files changed

+24
-15
lines changed

grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ class BuildSettings {
249249
/**
250250
* Whether the application is running inside the development environment or deployed
251251
*/
252-
public static final boolean IS_DEPLOYED = !new File(BASE_DIR, "grails-app").exists() && !new File(BASE_DIR, "Application.groovy").exists()
252+
public static final boolean GRAILS_APP_DIR_PRESENT = new File(BASE_DIR, "grails-app").exists() || new File(BASE_DIR, "Application.groovy").exists()
253253

254254
/**
255255
* The target directory of the project, null outside of the development environment
256256
*/
257-
public static final File TARGET_DIR = IS_DEPLOYED ? null : (System.getProperty(PROJECT_TARGET_DIR) ? new File(System.getProperty(PROJECT_TARGET_DIR)) : new File(BASE_DIR, "build"))
257+
public static final File TARGET_DIR = !GRAILS_APP_DIR_PRESENT ? null : (System.getProperty(PROJECT_TARGET_DIR) ? new File(System.getProperty(PROJECT_TARGET_DIR)) : new File(BASE_DIR, "build"))
258258
/**
259259
* The resources directory of the project, null outside of the development environment
260260
*/
261-
public static final File RESOURCES_DIR = IS_DEPLOYED ? null : (System.getProperty(PROJECT_RESOURCES_DIR) ? new File(System.getProperty(PROJECT_RESOURCES_DIR)) : new File(TARGET_DIR, "resources/main"))
261+
public static final File RESOURCES_DIR = !GRAILS_APP_DIR_PRESENT ? null : (System.getProperty(PROJECT_RESOURCES_DIR) ? new File(System.getProperty(PROJECT_RESOURCES_DIR)) : new File(TARGET_DIR, "resources/main"))
262262
/**
263263
* The classes directory of the project, null outside of the development environment
264264
*/
265-
public static final File CLASSES_DIR = IS_DEPLOYED ? null : (System.getProperty(PROJECT_CLASSES_DIR) ? new File(System.getProperty(PROJECT_CLASSES_DIR)) : new File(TARGET_DIR, "classes/main"))
265+
public static final File CLASSES_DIR = !GRAILS_APP_DIR_PRESENT ? null : (System.getProperty(PROJECT_CLASSES_DIR) ? new File(System.getProperty(PROJECT_CLASSES_DIR)) : new File(TARGET_DIR, "classes/main"))
266266
public static final String RUN_EXECUTED = "grails.run.executed"
267267
}

grails-bootstrap/src/main/groovy/grails/util/Environment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static Environment getCurrentEnvironment() {
193193
* @return true if the application is running in development mode
194194
*/
195195
public static boolean isDevelopmentMode() {
196-
return getCurrent() == DEVELOPMENT && !(Metadata.getCurrent().isWarDeployed()) &&
196+
return getCurrent() == DEVELOPMENT && Metadata.getCurrent().isDevelopmentEnvironmentAvailable() &&
197197
cachedHasGrailsHome;
198198
}
199199

grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,18 @@ public class Metadata extends CodeGenConfig {
238238
* @return true if this application is deployed as a WAR
239239
*/
240240
public boolean isWarDeployed() {
241-
return BuildSettings.IS_DEPLOYED && Boolean.getBoolean(BuildSettings.RUN_EXECUTED);
241+
def loadedLocation = getClass().getClassLoader().getResource("");
242+
if(loadedLocation && loadedLocation.path.contains('/WEB-INF/classes/')) {
243+
return true
244+
}
245+
return false
246+
}
247+
248+
/**
249+
* @return True if the development sources are present
250+
*/
251+
boolean isDevelopmentEnvironmentAvailable() {
252+
return BuildSettings.GRAILS_APP_DIR_PRESENT;
242253
}
243254

244255

grails-core/src/main/groovy/grails/boot/GrailsApp.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class GrailsApp extends SpringApplication {
3939

4040
@Override
4141
ConfigurableApplicationContext run(String... args) {
42-
System.setProperty(BuildSettings.RUN_EXECUTED, "true")
4342
def applicationContext = super.run(args)
4443

4544
grails.util.Environment environment = grails.util.Environment.getCurrent()

grails-core/src/main/groovy/org/grails/plugins/DefaultGrailsPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ private void evaluateOnChangeListener() {
356356
onChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CHANGE);
357357
}
358358

359-
final boolean warDeployed = Metadata.getCurrent().isWarDeployed();
359+
final Metadata metadata = Metadata.getCurrent();
360+
final boolean warDeployed = !metadata.isDevelopmentEnvironmentAvailable();
360361
final boolean reloadEnabled = Environment.getCurrent().isReloadEnabled();
361362

362363
if (!((reloadEnabled || !warDeployed) && onChangeListener != null)) {

grails-gsp/src/main/groovy/org/grails/gsp/io/DefaultGroovyPageLocator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import grails.plugins.PluginManagerAware;
2121
import grails.util.CollectionUtils;
2222
import grails.util.Environment;
23+
import grails.util.Metadata;
2324
import org.apache.commons.logging.Log;
2425
import org.apache.commons.logging.LogFactory;
2526
import org.grails.gsp.GroovyPage;
@@ -334,7 +335,7 @@ protected Resource findResource(List<String> searchPaths) {
334335
}
335336

336337
private boolean isPrecompiledAvailable() {
337-
return precompiledGspMap != null && precompiledGspMap.size() > 0 && warDeployed;
338+
return precompiledGspMap != null && precompiledGspMap.size() > 0 && !Metadata.getCurrent().isDevelopmentEnvironmentAvailable();
338339
}
339340

340341
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/GroovyPagesGrailsPlugin.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import grails.plugins.Plugin
2222
import grails.util.BuildSettings
2323
import grails.util.Environment
2424
import grails.util.GrailsUtil
25+
import grails.util.Metadata
2526
import grails.web.pages.GroovyPagesUriService
2627
import groovy.transform.CompileStatic
2728
import groovy.util.logging.Commons
@@ -100,7 +101,7 @@ class GroovyPagesGrailsPlugin extends Plugin {
100101
Closure doWithSpring() {{->
101102
def application = grailsApplication
102103
Config config = application.config
103-
boolean developmentMode = !application.warDeployed
104+
boolean developmentMode = Metadata.getCurrent().isDevelopmentEnvironmentAvailable()
104105
Environment env = Environment.current
105106

106107
boolean enableReload = env.isReloadEnabled() ||
@@ -158,7 +159,7 @@ class GroovyPagesGrailsPlugin extends Plugin {
158159
}
159160
}
160161

161-
def deployed = application.warDeployed
162+
def deployed = !Metadata.getCurrent().isDevelopmentEnvironmentAvailable()
162163
groovyPageLocator(CachingGrailsConventionGroovyPageLocator) { bean ->
163164
bean.lazyInit = true
164165
if (customResourceLoader) {

grails-web-boot/src/main/groovy/org/grails/compiler/boot/BootInitializerClassInjector.groovy

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
6666
def parameter = new Parameter(springApplicationBuilder, "application")
6767
def methodBody = new BlockStatement()
6868

69-
def setRunArguments = new ArgumentListExpression()
70-
setRunArguments.addExpression(new ConstantExpression(BuildSettings.RUN_EXECUTED))
71-
setRunArguments.addExpression(new ConstantExpression(Boolean.TRUE.toString()))
72-
methodBody.addStatement( new ExpressionStatement( new MethodCallExpression( new ClassExpression(ClassHelper.make(System)), "setProperty", setRunArguments)))
7369
methodBody.addStatement( new ExpressionStatement( new MethodCallExpression( new VariableExpression(parameter), "sources", new ClassExpression(classNode))))
7470
loaderClassNode.addMethod( new MethodNode("configure", Modifier.PROTECTED, springApplicationBuilder, [parameter] as Parameter[], [] as ClassNode[], methodBody))
7571
source.getAST().addClass(

0 commit comments

Comments
 (0)