11/*
2- * Copyright 2004-2005 the original author or authors.
2+ * Copyright 2004-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -57,6 +57,10 @@ enum Environment {
5757 /* * A custom environment */
5858 CUSTOM
5959
60+ /**
61+ * Initialize the Logger lazily because:
62+ * https://github.com/grails/grails-core/issues/11476
63+ */
6064 private static final Supplier<Logger > LOG = SupplierUtil . memoized(() -> LoggerFactory . getLogger(Environment . class))
6165
6266 /**
@@ -120,9 +124,9 @@ enum Environment {
120124
121125 @SuppressWarnings (" unchecked" )
122126 private static Map<String , String > envNameMappings = CollectionUtils . < String , String > newMap(
123- DEVELOPMENT_ENVIRONMENT_SHORT_NAME , Environment . DEVELOPMENT . getName(),
124- PRODUCTION_ENV_SHORT_NAME , Environment . PRODUCTION . getName(),
125- TEST_ENVIRONMENT_SHORT_NAME , Environment . TEST . getName())
127+ DEVELOPMENT_ENVIRONMENT_SHORT_NAME , DEVELOPMENT . getName(),
128+ PRODUCTION_ENV_SHORT_NAME , PRODUCTION . getName(),
129+ TEST_ENVIRONMENT_SHORT_NAME , TEST . getName())
126130 private static Holder<Environment > cachedCurrentEnvironment = new Holder<> (" Environment" )
127131 private static final boolean DEVELOPMENT_MODE = getCurrent() == DEVELOPMENT && BuildSettings . GRAILS_APP_DIR_PRESENT
128132 private static Boolean RELOADING_AGENT_ENABLED = null
@@ -295,14 +299,14 @@ enum Environment {
295299 Environment env = getEnvironment(envName)
296300 if (env == null ) {
297301 try {
298- env = Environment . valueOf(envName. toUpperCase())
302+ env = valueOf(envName. toUpperCase())
299303 }
300304 catch (IllegalArgumentException e) {
301305 // ignore
302306 }
303307 }
304308 if (env == null ) {
305- env = Environment . CUSTOM
309+ env = CUSTOM
306310 env. setName(envName)
307311 }
308312 return env
@@ -355,7 +359,7 @@ enum Environment {
355359 * @return True if the development sources are present
356360 */
357361 static boolean isDevelopmentRun () {
358- Environment env = Environment . getCurrent()
362+ Environment env = getCurrent()
359363 return isDevelopmentEnvironmentAvailable() && Boolean . getBoolean(RUN_ACTIVE ) && (env == Environment . DEVELOPMENT )
360364 }
361365
@@ -368,7 +372,7 @@ enum Environment {
368372 LOG . get(). debug(" Looking for pid file at: {}" , pidFile)
369373 boolean isDevToolsRestart = false
370374 try {
371- if (Environment . isDevelopmentMode()) {
375+ if (isDevelopmentMode()) {
372376 String pid = ManagementFactory . getRuntimeMXBean(). getName()
373377 if (pidFile. exists()) {
374378 if (pid. equals(Files . readAllLines(pidFile. toPath()). get(0 ))) {
@@ -479,10 +483,10 @@ enum Environment {
479483 static Environment getEnvironment (String shortName ) {
480484 final String envName = envNameMappings. get(shortName)
481485 if (envName != null ) {
482- return Environment . valueOf(envName. toUpperCase())
486+ return valueOf(envName. toUpperCase())
483487 } else {
484488 try {
485- return Environment . valueOf(shortName. toUpperCase())
489+ return valueOf(shortName. toUpperCase())
486490 } catch (IllegalArgumentException ise) {
487491 return null
488492 }
@@ -646,7 +650,7 @@ enum Environment {
646650 }
647651 try {
648652 Class . forName(" org.springframework.boot.devtools.RemoteSpringApplication" )
649- RELOADING_AGENT_ENABLED = Environment . getCurrent(). isReloadEnabled()
653+ RELOADING_AGENT_ENABLED = getCurrent(). isReloadEnabled()
650654 LOG . get(). debug(" Found spring-dev-tools on the class path" )
651655 }
652656 catch (ClassNotFoundException e) {
@@ -655,7 +659,7 @@ enum Environment {
655659 Class . forName(" org.springsource.loaded.TypeRegistry" )
656660 String jvmVersion = System . getProperty(" java.specification.version" )
657661 LOG . get(). debug(" Found spring-loaded on the class path" )
658- RELOADING_AGENT_ENABLED = Environment . getCurrent(). isReloadEnabled()
662+ RELOADING_AGENT_ENABLED = getCurrent(). isReloadEnabled()
659663 }
660664 catch (ClassNotFoundException e1) {
661665 RELOADING_AGENT_ENABLED = false
@@ -712,8 +716,8 @@ enum Environment {
712716 }
713717
714718 private static String getEnvironmentInternal () {
715- String envName = System . getProperty(Environment . KEY )
716- return isBlank(envName) ? System . getenv(Environment . ENV_KEY ) : envName
719+ String envName = System . getProperty(KEY )
720+ return isBlank(envName) ? System . getenv(ENV_KEY ) : envName
717721 }
718722
719723}
0 commit comments