sanjana2505006 commented on code in PR #15555:
URL: https://github.com/apache/grails-core/pull/15555#discussion_r3068444196
##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy:
##########
@@ -191,4 +197,88 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
)
}
}
+
+ private static void registerFormattingTasks(Project project) {
+ if (project == project.rootProject) {
+ project.tasks.register('installGitHooks', Copy) {
+ it.group = 'verification'
+ it.description = 'Installs the git pre-commit hook for
automatic code formatting'
+
it.from(project.rootProject.layout.projectDirectory.file('etc/hooks/pre-commit'))
+
it.into(project.rootProject.layout.projectDirectory.dir('.git/hooks'))
+ it.fileMode = 0755
+ }
+ }
+
+ project.tasks.register('formatCode') {
+ it.group = 'verification'
+ it.description = 'Formats Java and Groovy source files using the
IntelliJ command line formatter'
+
+ it.doLast {
+ String ideaHome = (project.findProperty('idea.home') ?:
System.getenv('IDEA_HOME')) as String
+ String executable = Os.isFamily(Os.FAMILY_WINDOWS) ?
'format.bat' : 'format.sh'
+ File formatExec = null
+
+ if (ideaHome) {
+ formatExec = new File(ideaHome, "bin/$executable")
+ } else {
+ // Try common paths on macOS
+ if (Os.isFamily(Os.FAMILY_MAC)) {
Review Comment:
I've simplified the formatter discovery logic to rely on the `idea` command
being on the system `PATH`, as suggested. I removed the redundant
path-searching code and added a reference to the JetBrains help article in the
error message if the command isn't found
--
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]