Skip to content

Commit

Permalink
Grails Boot: Refine GrailsDevelopmentModeWatchApplicationContextIniti…
Browse files Browse the repository at this point in the history
…alizer

* use BuildSettings.GRAILS_APP_PATH
* Simplify log changed file path from base dir
  • Loading branch information
rainboyan committed May 25, 2023
1 parent e7de7f5 commit be8b1ae
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.grails.boot.internal.JavaCompiler;
import org.grails.compiler.injection.AbstractGrailsArtefactTransformer;
import org.grails.compiler.injection.GrailsAwareInjectionOperation;
import org.grails.io.support.GrailsResourceUtils;
import org.grails.io.watch.DirectoryWatcher;
import org.grails.io.watch.FileExtensionFileChangeListener;
import org.grails.plugins.BinaryGrailsPlugin;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void onApplicationEvent(@NonNull ApplicationEvent event) {

if (environment.isReloadEnabled()) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Application reloading status: %s, base directory is [%s]", environment.isReloadEnabled(), BuildSettings.BASE_DIR));
logger.debug(String.format("Application reloading status: %s, base directory is [%s]",
environment.isReloadEnabled(), BuildSettings.BASE_DIR));
}
try {
enableDevelopmentModeWatch(environment, applicationContext);
Expand Down Expand Up @@ -225,7 +227,8 @@ else if (wp.getDirectory() != null && wp.getExtension() != null) {
if (count > 0) {
changedFiles.clear();
for (File changedFile : uniqueChangedFiles) {
logger.debug(String.format("WatchService found file changed [%s]", changedFile));
logger.debug(String.format("WatchService found file changed [%s]",
GrailsResourceUtils.getPathFromBaseDir(changedFile.getAbsolutePath())));

changedFile = changedFile.getCanonicalFile();
// Groovy files within the 'conf' and 'i18n' directory are not compiled
Expand Down Expand Up @@ -282,8 +285,7 @@ private void setDevelopmentModeActive(boolean active) {
private void recompile(File changedFile, CompilerConfiguration compilerConfig, String location) {
String changedPath = changedFile.getPath();

String grailsAppFullPath = BuildSettings.GRAILS_APP_DIR.getAbsolutePath();
String grailsAppPath = grailsAppFullPath.substring(grailsAppFullPath.lastIndexOf(File.separator) + 1);
String grailsAppPath = BuildSettings.GRAILS_APP_PATH;

File appDir = null;
boolean sourceFileChanged = false;
Expand All @@ -303,7 +305,8 @@ private void recompile(File changedFile, CompilerConfiguration compilerConfig, S
String baseFileLocation = appDir.getAbsolutePath();
compilerConfig.setTargetDirectory(new File(baseFileLocation, BuildSettings.BUILD_CLASSES_PATH));

logger.debug(String.format("Recompiling changed file... [%s]%n", changedFile));
logger.debug(String.format("Recompiling changed file... [%s]",
GrailsResourceUtils.getPathFromBaseDir(changedFile.getAbsolutePath())));

if (changedFile.getName().endsWith(".java")) {
if (JavaCompiler.isAvailable()) {
Expand Down Expand Up @@ -362,8 +365,7 @@ public void onNew(File file) {
}

private void configureDirectoryWatcher(DirectoryWatcher directoryWatcher, String location) {
String grailsAppFullPath = BuildSettings.GRAILS_APP_DIR.getAbsolutePath();
String grailsAppPath = grailsAppFullPath.substring(grailsAppFullPath.lastIndexOf(File.separator) + 1);
String grailsAppPath = BuildSettings.GRAILS_APP_PATH;
for (String dir : Arrays.asList(grailsAppPath, SOURCE_MAIN_JAVA, SOURCE_MAIN_GROOVY)) {
directoryWatcher.addWatchDirectory(new File(location, dir), FILE_EXTENSIONS);
}
Expand Down

0 comments on commit be8b1ae

Please sign in to comment.