jdaugherty commented on code in PR #15555:
URL: https://github.com/apache/grails-core/pull/15555#discussion_r3041318796
##########
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:
We should just make it a requirement that `idea` is on the path and
reference the version on the path. IntelliJ has an option to install the
command line tools
(https://www.jetbrains.com/help/idea/working-with-the-ide-features-from-command-line.html)
so let's just reference the help article and not trying to be smart about
locating it (anyone using JetBrains toolbox won't be installing it to
/Applications or to a specific location)
--
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]