jdaugherty commented on code in PR #16472:
URL: https://github.com/apache/grails-core/pull/16472#discussion_r4168465505


##########
grails-gradle/model/src/main/groovy/grails/util/BuildSettings.groovy:
##########
@@ -309,6 +310,7 @@ class BuildSettings {
     }
 
     static {
+        BUILD_RESOURCES_PATH = System.getProperty(PROJECT_RESOURCES_DIR) ?: 
'build/resources/main'

Review Comment:
   `RESOURCES_DIR`, further down this block (line 340, outside the diff), uses 
the property as given: `new File(System.getProperty(PROJECT_RESOURCES_DIR))`. 
Now that the plugin always passes a relative path, `RESOURCES_DIR` is resolved 
against the forked JVM's working directory. Before, it was `new 
File(TARGET_DIR, 'resources/main')`, which `base.dir` ties to the application. 
I ran `BuildSettings` from this branch with `-Dbase.dir=<app>` and the working 
directory set to a directory next to the application:
   
   ```
   property not passed:                      RESOURCES_DIR = 
<app>/build/resources/main        exists=true
   -Dgrails.project.resource.dir=build/...:  RESOURCES_DIR = 
<elsewhere>/build/resources/main  exists=false
   ```
   
   `bootRun` and `test` run in the project directory by default, so the tests 
here can't see the difference. A build that sets `workingDir` on `bootRun` 
does. For example, `I18nGrailsPlugin.onChange` checks `RESOURCES_DIR.exists()` 
before it copies a changed bundle, so in that setup it skips the copy and logs 
nothing.
   
   The provider's Javadoc says the path is relative because it is joined to a 
project directory. Could `RESOURCES_DIR` join a relative value to `BASE_DIR`? 
An absolute value that a build passes itself would keep working as before:
   
   ```groovy
   String resourcesDir = System.getProperty(PROJECT_RESOURCES_DIR)
   File resourcesFile = resourcesDir ? new File(resourcesDir) : null
   RESOURCES_DIR = !GRAILS_APP_DIR_PRESENT ? null :
           (resourcesFile ? (resourcesFile.absolute ? resourcesFile : new 
File(BASE_DIR, resourcesDir)) : new File(TARGET_DIR, 'resources/main'))
   ```
   
   A test for it needs a JVM whose working directory isn't the application's, 
since `BuildSettings` sets these values once, when the class loads.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to